Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7d00c85

Browse filesBrowse files
May break!
1 parent 3fe2a5c commit 7d00c85
Copy full SHA for 7d00c85

26 files changed

+1,241-1,336Lines changed: 1241 additions & 1336 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/MiNET/MiNET.Client/MiNetClient.cs‎

Copy file name to clipboardExpand all lines: src/MiNET/MiNET.Client/MiNetClient.cs
+50-41Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#endregion
2525

2626
using System;
27+
using System.Buffers;
2728
using System.CodeDom.Compiler;
2829
using System.Collections;
2930
using System.Collections.Concurrent;
@@ -81,7 +82,7 @@ public class MiNetClient
8182
public Vector3 SpawnPoint { get; set; }
8283
public long EntityId { get; set; }
8384
public long NetworkEntityId { get; set; }
84-
public PlayerNetworkSession Session { get; set; }
85+
public RakSession Session { get; set; }
8586
private Thread _mainProcessingThread;
8687
public int ChunkRadius { get; set; } = 5;
8788

@@ -157,7 +158,7 @@ public void StartClient()
157158
////
158159
}
159160

160-
Session = new PlayerNetworkSession(null, null, ClientEndpoint, _mtuSize);
161+
Session = new RakSession(null, null, ClientEndpoint, _mtuSize);
161162

162163
_mainProcessingThread = new Thread(ProcessDatagram) {IsBackground = true};
163164
_mainProcessingThread.Start(UdpClient);
@@ -342,7 +343,7 @@ private void ProcessMessage(ReadOnlyMemory<byte> receiveBytes, IPEndPoint sender
342343

343344
{
344345
var ack = Acks.CreateObject();
345-
ack.acks.Add(packet._datagramSequenceNumber);
346+
ack.acks.Add(packet._datagramHeader.DatagramSequenceNumber);
346347
byte[] data = ack.Encode();
347348
ack.PutPool();
348349
SendData(data, senderEndpoint);
@@ -402,7 +403,7 @@ private void HandleConnectedPacket(ConnectedPacket packet)
402403

403404
public void AddToProcessing(Packet message)
404405
{
405-
if (message.Reliability != Reliability.ReliableOrdered)
406+
if (message.ReliabilityHeader.Reliability != Reliability.ReliableOrdered)
406407
{
407408
HandlePacket(message);
408409
return;
@@ -412,10 +413,10 @@ public void AddToProcessing(Packet message)
412413

413414
lock (_eventSync)
414415
{
415-
if (_queue.Count == 0 && message.OrderingIndex == _lastSequenceNumber + 1)
416+
if (_queue.Count == 0 && message.ReliabilityHeader.OrderingIndex == _lastSequenceNumber + 1)
416417
{
417418
HandlePacket(message);
418-
_lastSequenceNumber = message.OrderingIndex;
419+
_lastSequenceNumber = message.ReliabilityHeader.OrderingIndex;
419420
return;
420421
}
421422

@@ -426,7 +427,7 @@ public void AddToProcessing(Packet message)
426427
_processingThread.Start();
427428
}
428429

429-
_queue.Enqueue(message.OrderingIndex, message);
430+
_queue.Enqueue(message.ReliabilityHeader.OrderingIndex, message);
430431
WaitHandle.SignalAndWait(_waitEvent, _mainWaitEvent);
431432
}
432433
}
@@ -529,17 +530,11 @@ public virtual void HandleNak(ReadOnlyMemory<byte> receiveBytes, IPEndPoint send
529530
if (Log.IsDebugEnabled) Log.Warn("!! WHAT THE FUK NAK NAK NAK");
530531
}
531532

532-
private void HandleSplitMessage(PlayerNetworkSession playerSession, SplitPartPacket splitMessage)
533+
private void HandleSplitMessage(RakSession playerSession, SplitPartPacket splitPart)
533534
{
534-
int spId = splitMessage.SplitId;
535-
int spIdx = splitMessage.SplitIdx;
536-
int spCount = splitMessage.SplitCount;
537-
538-
Int24 sequenceNumber = splitMessage.DatagramSequenceNumber;
539-
Reliability reliability = splitMessage.Reliability;
540-
Int24 reliableMessageNumber = splitMessage.ReliableMessageNumber;
541-
Int24 orderingIndex = splitMessage.OrderingIndex;
542-
byte orderingChannel = splitMessage.OrderingChannel;
535+
int spId = splitPart.ReliabilityHeader.PartId;
536+
int spIdx = splitPart.ReliabilityHeader.PartIndex;
537+
int spCount = splitPart.ReliabilityHeader.PartCount;
543538

544539
SplitPartPacket[] spPackets;
545540
bool haveEmpty = false;
@@ -559,7 +554,7 @@ private void HandleSplitMessage(PlayerNetworkSession playerSession, SplitPartPac
559554
Log.Debug("Already had splitpart (resent). Ignore this part.");
560555
return;
561556
}
562-
spPackets[spIdx] = splitMessage;
557+
spPackets[spIdx] = splitPart;
563558

564559
for (int i = 0; i < spPackets.Length; i++)
565560
{
@@ -571,6 +566,12 @@ private void HandleSplitMessage(PlayerNetworkSession playerSession, SplitPartPac
571566
{
572567
Log.DebugFormat("Got all {0} split packets for split ID: {1}", spCount, spId);
573568

569+
570+
Reliability reliability = splitPart.ReliabilityHeader.Reliability;
571+
Int24 reliableMessageNumber = splitPart.ReliabilityHeader.ReliableMessageNumber;
572+
Int24 orderingIndex = splitPart.ReliabilityHeader.OrderingIndex;
573+
byte orderingChannel = splitPart.ReliabilityHeader.OrderingChannel;
574+
574575
SplitPartPacket[] waste;
575576
playerSession.Splits.TryRemove(spId, out waste);
576577

@@ -593,25 +594,27 @@ private void HandleSplitMessage(PlayerNetworkSession playerSession, SplitPartPac
593594
byte[] buffer = stream.ToArray();
594595
try
595596
{
596-
ConnectedPacket newPacket = ConnectedPacket.CreateObject();
597-
newPacket._datagramSequenceNumber = sequenceNumber;
598-
newPacket._reliability = reliability;
599-
newPacket._reliableMessageNumber = reliableMessageNumber;
600-
newPacket._orderingIndex = orderingIndex;
601-
newPacket._orderingChannel = (byte) orderingChannel;
602-
newPacket._hasSplit = false;
597+
var newPacket = ConnectedPacket.CreateObject();
598+
newPacket.ReliabilityHeader = new ReliabilityHeader()
599+
{
600+
Reliability = reliability,
601+
ReliableMessageNumber = reliableMessageNumber,
602+
OrderingChannel = orderingChannel,
603+
OrderingIndex = orderingIndex,
604+
};
603605

604606
Packet fullMessage = PacketFactory.Create(buffer[0], buffer, "raknet") ?? new UnknownPacket(buffer[0], buffer);
605-
fullMessage.DatagramSequenceNumber = sequenceNumber;
606-
fullMessage.Reliability = reliability;
607-
fullMessage.ReliableMessageNumber = reliableMessageNumber;
608-
fullMessage.OrderingIndex = orderingIndex;
609-
fullMessage.OrderingChannel = orderingChannel;
610-
607+
fullMessage.ReliabilityHeader = new ReliabilityHeader()
608+
{
609+
Reliability = reliability,
610+
ReliableMessageNumber = reliableMessageNumber,
611+
OrderingChannel = orderingChannel,
612+
OrderingIndex = orderingIndex,
613+
};
611614
newPacket.Messages = new List<Packet>();
612615
newPacket.Messages.Add(fullMessage);
613616

614-
Log.Debug($"Assembled split packet {newPacket._reliability} message #{newPacket._reliableMessageNumber}, Chan: #{newPacket._orderingChannel}, OrdIdx: #{newPacket._orderingIndex}");
617+
//Log.Debug($"Assembled split packet {newPacket._reliability} message #{newPacket._reliableMessageNumber}, Chan: #{newPacket._orderingChannel}, OrdIdx: #{newPacket._orderingIndex}");
615618
HandleConnectedPacket(newPacket);
616619
newPacket.PutPool();
617620
}
@@ -1192,9 +1195,13 @@ public virtual void HandleBatch(McpeWrapper batch)
11921195

11931196
foreach (var msg in messages)
11941197
{
1195-
msg.DatagramSequenceNumber = batch.DatagramSequenceNumber;
1196-
msg.OrderingChannel = batch.OrderingChannel;
1197-
msg.OrderingIndex = batch.OrderingIndex;
1198+
msg.ReliabilityHeader = new ReliabilityHeader()
1199+
{
1200+
Reliability = batch.ReliabilityHeader.Reliability,
1201+
ReliableMessageNumber = batch.ReliabilityHeader.ReliableMessageNumber,
1202+
OrderingChannel = batch.ReliabilityHeader.OrderingChannel,
1203+
OrderingIndex = batch.ReliabilityHeader.OrderingIndex,
1204+
};
11981205
HandlePacket(msg);
11991206
msg.PutPool();
12001207
}
@@ -1214,13 +1221,15 @@ public async Task SendPacketAsync(Packet message)
12141221

12151222
private async Task SendDatagramAsync(Datagram datagram)
12161223
{
1217-
if (datagram.MessageParts.Count != 0)
1224+
if (datagram.MessageParts.Count > 0)
12181225
{
12191226
datagram.Header.DatagramSequenceNumber = Interlocked.Increment(ref Session.DatagramSequenceNumber);
1220-
byte[] data = datagram.Encode();
1221-
datagram.PutPool();
12221227

1223-
await SendDataAsync(data, ServerEndpoint);
1228+
byte[] buffer = ArrayPool<byte>.Shared.Rent(1600);
1229+
int length = (int) datagram.GetEncoded(ref buffer);
1230+
1231+
await SendDataAsync(buffer, length, ServerEndpoint);
1232+
ArrayPool<byte>.Shared.Return(buffer);
12241233
}
12251234
}
12261235

@@ -1247,14 +1256,14 @@ private void SendData(byte[] data, IPEndPoint targetEndpoint)
12471256
}
12481257
}
12491258

1250-
private async Task SendDataAsync(byte[] data, IPEndPoint targetEndpoint)
1259+
private async Task SendDataAsync(byte[] data, int length, IPEndPoint targetEndpoint)
12511260
{
12521261
if (UdpClient == null)
12531262
return;
12541263

12551264
try
12561265
{
1257-
await UdpClient.SendAsync(data, data.Length, targetEndpoint);
1266+
await UdpClient.SendAsync(data, length, targetEndpoint);
12581267
}
12591268
catch (Exception e)
12601269
{
Collapse file

‎src/MiNET/MiNET.Console/Startup.cs‎

Copy file name to clipboardExpand all lines: src/MiNET/MiNET.Console/Startup.cs
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#endregion
2525

26+
using System;
27+
using System.Diagnostics;
2628
using System.IO;
2729
using System.Reflection;
2830
using log4net;
@@ -37,6 +39,9 @@ class Startup
3739

3840
static void Main(string[] args)
3941
{
42+
var currentProcess = Process.GetCurrentProcess();
43+
currentProcess.ProcessorAffinity = (IntPtr) Config.GetProperty("ProcessorAffinity", (int) currentProcess.ProcessorAffinity);
44+
4045
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
4146
XmlConfigurator.Configure(logRepository, new FileInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "log4net.xml")));
4247

Collapse file

‎src/MiNET/MiNET.Console/log4net.xml‎

Copy file name to clipboardExpand all lines: src/MiNET/MiNET.Console/log4net.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
</appender>
108108

109109
<root>
110-
<level value="INFO" />
110+
<level value="DEBUG" />
111111
<appender-ref ref="Console" />
112112
<appender-ref ref="RollingFile" />
113113
<!--<appender-ref ref="DebuggerAppender"/>-->
Collapse file

‎src/MiNET/MiNET.Console/server.nicke.conf‎

Copy file name to clipboardExpand all lines: src/MiNET/MiNET.Console/server.nicke.conf
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#DO NOT REMOVE THIS LINE - MiNET Config
22

3+
#ProcessorAffinity=3
34
serverid=4080284420030544738
45
MaxNumberOfPlayers=5000
5-
UseEncryption=true
6+
UseEncryption=false
67
UseEncryptionForAll=false
78
#ForceOrderingForAll=false
89
ForceXBLAuthentication=false
@@ -58,7 +59,7 @@ LevelDBWorldFolder=C:\Users\nicke_000\AppData\Local\Temp\My World.mcworld
5859
#PCWorldFolder=C:\Downloads\broken_lobby\lobby
5960

6061
# DEVELOPMENT
61-
PCWorldFolder=C:\Development\DOES NOT EXIST
62+
#PCWorldFolder=C:\Development\DOES NOT EXIST
6263

6364
#Save.Enabled=true
6465
#Save.Interval=30
@@ -80,7 +81,7 @@ PCWorldFolder=C:\Development\DOES NOT EXIST
8081

8182
# Cool worlds for testing
8283
#PCWorldFolder=C:\Development\Worlds\Waka_Islands_2_v0.4\WAKA ISLANDS 2 - V0.4
83-
#PCWorldFolder=C:\Development\Worlds\TerrainControlGenerated
84+
PCWorldFolder=C:\Development\Worlds\TerrainControlGenerated
8485
#PCWorldFolder=C:\Temp\UHCr1000
8586
#PCWorldFolder=C:\Development\Worlds\SkyWarsBrokenLight\SkyWars
8687
#PCWorldFolder=C:\Downloads\KingsLanding1\KingsLanding1
@@ -108,13 +109,13 @@ EnableCommands=true
108109
PluginDirectory=../../../../TestPlugin/bin/Debug/netcoreapp3.1;../../../../MiNET.BuilderBase/bin/Debug/netcoreapp3.1;../../../../MiNET.Plotter/bin/Debug/netcoreapp3.1
109110
#PluginDirectory=C:\Development\Other\MiNET.GameFramework\src\MiNET.GameFramework\MiNET.GameFramework.Plugin\bin\Debug\netcoreapp3.1;
110111

111-
PluginDisabled=true
112+
#PluginDisabled=true
112113
#NiceLobby.Enabled=false
113114
#CoreCommands.Enabled=false
114115
#CommandsTest.Enabled=false
115116
SurvivalCraft.Enabled=false
116117
Plotter.Enabled=false
117-
BuilderBase.Enabled=false
118+
#BuilderBase.Enabled=false
118119
Pets.Enabled=false
119120
PushToTheLimit.Enabled=false
120121
Code4Fun.Enabled=false
Collapse file

‎src/MiNET/MiNET.ServiceKiller/Emulator.cs‎

Copy file name to clipboardExpand all lines: src/MiNET/MiNET.ServiceKiller/Emulator.cs
+30-27Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
using MiNET.Net;
3737
using MiNET.Utils;
3838

39+
#pragma warning disable 1591
40+
3941
namespace MiNET.ServiceKiller
4042
{
4143
public class Emulator
@@ -48,27 +50,38 @@ public class Emulator
4850
//private const int RequestChunkRadius = 8;
4951

5052

51-
private const int TimeBetweenSpawns = 0;
52-
private static readonly TimeSpan DurationOfConnection = TimeSpan.FromMinutes(15);
53-
private const int NumberOfBots = 500;
54-
private const int RanSleepMin = 40;
55-
private const int RanSleepMax = 100;
56-
private const int RequestChunkRadius = 5;
57-
private const bool ConcurrentSpawn = true;
58-
private const int ConcurrentBatchSize = 10;
53+
private static int TimeBetweenSpawns = 0;
54+
private static TimeSpan DurationOfConnection = TimeSpan.FromMinutes(15);
55+
private static int NumberOfBots = 100;
56+
private static int RanSleepMin = 40;
57+
private static int RanSleepMax = 100;
58+
private static int RequestChunkRadius = 5;
59+
private static bool ConcurrentSpawn = true;
60+
private static int ConcurrentBatchSize = 5;
5961

6062
public AutoResetEvent ConcurrentSpawnWaitHandle = new AutoResetEvent(false);
6163

62-
private static bool _running = true;
63-
64-
public bool Running
64+
public bool Running { get; set; } = true;
65+
66+
/// <summary>
67+
/// </summary>
68+
/// <param name="numberOfBots">The number of bots to spawn.</param>
69+
/// <param name="durationOfConnection">How long (in seconds) should each individual bots stay connected.</param>
70+
/// <param name="concurrentSpawn">Should the emulator spawn bots in parallel.</param>
71+
/// <param name="batchSize">If parallel spawn, how many in each batch.</param>
72+
/// <param name="chunkRadius">The chunk radius the bots will request. Server may override.</param>
73+
/// <param name="processorAffinity">Processor affinity mask represented as an integer.</param>
74+
private static void Main(int numberOfBots = 500, int durationOfConnection = 900, bool concurrentSpawn = true, int batchSize = 5, int chunkRadius = 5, int processorAffinity = 0)
6575
{
66-
get { return _running; }
67-
set { _running = value; }
68-
}
76+
NumberOfBots = numberOfBots;
77+
DurationOfConnection = TimeSpan.FromSeconds(durationOfConnection);
78+
ConcurrentSpawn = concurrentSpawn;
79+
ConcurrentBatchSize = batchSize;
80+
RequestChunkRadius = chunkRadius;
81+
82+
var currentProcess = Process.GetCurrentProcess();
83+
currentProcess.ProcessorAffinity = processorAffinity <= 0 ? currentProcess.ProcessorAffinity : (IntPtr) processorAffinity;
6984

70-
private static void Main(string[] args)
71-
{
7285
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
7386
XmlConfigurator.Configure(logRepository, new FileInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "log4net.xml")));
7487

@@ -85,17 +98,7 @@ private static void Main(string[] args)
8598
Console.WriteLine("Press <Enter> to start emulation...");
8699
Console.ReadLine();
87100

88-
//int threads;
89-
//int iothreads;
90-
91-
//ThreadPool.GetMaxThreads(out threads, out iothreads);
92-
//ThreadPool.SetMaxThreads(threads, 4000);
93-
94-
//ThreadPool.GetMinThreads(out threads, out iothreads);
95-
//ThreadPool.SetMinThreads(4000, 4000);
96-
97-
//DedicatedThreadPool threadPool = new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount));
98-
var threadPool = new DedicatedThreadPool(new DedicatedThreadPoolSettings(4000));
101+
var threadPool = new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount));
99102

100103
var emulator = new Emulator {Running = true};
101104
long start = DateTime.UtcNow.Ticks;
Collapse file

‎src/MiNET/MiNET.ServiceKiller/MiNET.ServiceKiller.csproj‎

Copy file name to clipboardExpand all lines: src/MiNET/MiNET.ServiceKiller/MiNET.ServiceKiller.csproj
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
</Content>
2222
</ItemGroup>
2323

24+
<ItemGroup>
25+
<PackageReference Include="System.CommandLine.DragonFruit" Version="0.3.0-alpha.20158.1" />
26+
</ItemGroup>
27+
2428
<ItemGroup>
2529
<ProjectReference Include="..\MiNET.Client\MiNET.Client.csproj" />
2630
<ProjectReference Include="..\MiNET\MiNET.csproj" />

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.