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 a76e4e3

Browse filesBrowse files
Fix ACK/NAK. Not finished yet.
Remove fnbt from NuGet and using my own with bug-fix for lists. Now loading any anvil world should work. Made a pull-reqest for fnbt and will switch back when a new release is in NuGet.
1 parent 91fb516 commit a76e4e3
Copy full SHA for a76e4e3

14 files changed

+138-81Lines changed: 138 additions & 81 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.gitmodules‎

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "external/fNbt"]
2+
path = external/fNbt
3+
url = https://github.com/NiclasOlofsson/fNbt
Collapse file

‎external/fNbt‎

Copy file name to clipboard
Submodule fNbt added at 4973d96
Collapse file

‎src/MiNET/MiNET.Client/MiNET.Client.csproj‎

Copy file name to clipboardExpand all lines: src/MiNET/MiNET.Client/MiNET.Client.csproj
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
<WarningLevel>4</WarningLevel>
3535
</PropertyGroup>
3636
<ItemGroup>
37-
<Reference Include="fNbt, Version=0.6.2.0, Culture=neutral, processorArchitecture=MSIL">
38-
<SpecificVersion>False</SpecificVersion>
39-
<HintPath>..\packages\fNbt.0.6.2.0\lib\net35-Client\fNbt.dll</HintPath>
40-
</Reference>
4137
<Reference Include="log4net">
4238
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
4339
</Reference>
@@ -59,6 +55,10 @@
5955
<None Include="packages.config" />
6056
</ItemGroup>
6157
<ItemGroup>
58+
<ProjectReference Include="..\..\..\external\fNbt\fNbt\fNbt.csproj">
59+
<Project>{4488498D-976D-4DA3-BF72-109531AF0488}</Project>
60+
<Name>fNbt</Name>
61+
</ProjectReference>
6262
<ProjectReference Include="..\MiNET\MiNET.csproj">
6363
<Project>{B7049BF1-2DB0-435D-9791-09AB61018685}</Project>
6464
<Name>MiNET</Name>
Collapse file

‎src/MiNET/MiNET.Test/MiNET.Test.csproj‎

Copy file name to clipboardExpand all lines: src/MiNET/MiNET.Test/MiNET.Test.csproj
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
<Reference Include="Deedle">
4141
<HintPath>..\packages\Deedle.1.0.7\lib\net40\Deedle.dll</HintPath>
4242
</Reference>
43-
<Reference Include="fNbt, Version=0.6.2.0, Culture=neutral, processorArchitecture=MSIL">
44-
<SpecificVersion>False</SpecificVersion>
45-
<HintPath>..\packages\fNbt.0.6.2.0\lib\net35-Client\fNbt.dll</HintPath>
46-
</Reference>
4743
<Reference Include="Moq, Version=4.2.1502.911, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
4844
<SpecificVersion>False</SpecificVersion>
4945
<HintPath>..\packages\Moq.4.2.1502.0911\lib\net40\Moq.dll</HintPath>
@@ -72,6 +68,10 @@
7268
<Compile Include="MinetServerTest.cs" />
7369
</ItemGroup>
7470
<ItemGroup>
71+
<ProjectReference Include="..\..\..\external\fNbt\fNbt\fNbt.csproj">
72+
<Project>{4488498D-976D-4DA3-BF72-109531AF0488}</Project>
73+
<Name>fNbt</Name>
74+
</ProjectReference>
7575
<ProjectReference Include="..\MiNET\MiNET.csproj">
7676
<Project>{B7049BF1-2DB0-435D-9791-09AB61018685}</Project>
7777
<Name>MiNET</Name>
Collapse file

‎src/MiNET/MiNET.Test/MinetAnvilTest.cs‎

Copy file name to clipboardExpand all lines: src/MiNET/MiNET.Test/MinetAnvilTest.cs
+40-5Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public void SaveAnvilChunkTest()
4949

5050
AnvilWorldProvider anvil = new AnvilWorldProvider(@"D:\Development\Worlds\KingsLanding\");
5151
anvil.Initialize();
52+
Stopwatch sw = new Stopwatch();
53+
sw.Start();
5254
for (int x = 0; x < 32; x++)
5355
{
5456
for (int z = 0; z < 32; z++)
@@ -61,9 +63,9 @@ public void SaveAnvilChunkTest()
6163
Assert.NotNull(chunk);
6264
}
6365
}
66+
Console.WriteLine("Read {0} chunks in {1}ms", anvil.NumberOfCachedChunks(), sw.ElapsedMilliseconds);
6467

65-
Stopwatch sw = new Stopwatch();
66-
sw.Start();
68+
sw.Restart();
6769

6870
anvil.SaveChunks();
6971

@@ -157,17 +159,50 @@ public void LoadAnvilChunkLoadTest()
157159
Stopwatch sw = new Stopwatch();
158160
sw.Start();
159161

160-
int iterations = 1000000;
162+
int iterations = 1024;
161163
for (int i = 0; i < iterations; i++)
162164
{
163165
AnvilWorldProvider.GetChunk(coordinates, basePath, generator, 30);
164166
}
165167

166168
long ticks = sw.ElapsedTicks;
169+
long ms = sw.ElapsedMilliseconds;
170+
171+
//Assert.Less(ticks/iterations, 100);
172+
173+
Console.WriteLine("Read {0} chunk-columns in {1}ns ({3}ms) at a rate of {2}ns/col", iterations, ticks, ticks / iterations, ms);
174+
}
175+
167176

168-
Assert.Less(ticks/iterations, 100);
177+
[Test, Ignore]
178+
public void LoadFullAnvilRegionLoadTest()
179+
{
180+
int width = 32;
181+
int depth = 32;
169182

170-
Console.WriteLine("Read {0} chunk-columns in {1}ns at a rate of {2}ns/chunk", iterations, ticks, ticks/iterations);
183+
int regionX = 5;
184+
int regionZ = 24;
185+
186+
string basePath = @"D:\Downloads\KingsLanding1";
187+
var generator = new FlatlandWorldProvider();
188+
189+
Stopwatch sw = new Stopwatch();
190+
sw.Start();
191+
int noChunksRead = 0;
192+
for (int x = 0; x < 32; x++)
193+
{
194+
for (int z = 0; z < 32; z++)
195+
{
196+
noChunksRead++;
197+
int cx = (width*regionX) + x;
198+
int cz = (depth*regionZ) + z;
199+
200+
ChunkCoordinates coordinates = new ChunkCoordinates(cx, cz);
201+
ChunkColumn chunk = AnvilWorldProvider.GetChunk(coordinates, basePath, generator, 30);
202+
Assert.NotNull(chunk);
203+
}
204+
}
205+
Console.WriteLine("Read {0} chunks in {1}ms", noChunksRead, sw.ElapsedMilliseconds);
171206
}
172207
}
173208
}
Collapse file

‎src/MiNET/MiNET.sln‎

Copy file name to clipboardExpand all lines: src/MiNET/MiNET.sln
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestPlugin", "TestPlugin\Te
3434
EndProject
3535
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiNET.Client", "MiNET.Client\MiNET.Client.csproj", "{2BFFD5A4-DAC0-47D3-946F-1A8EE2ACCB46}"
3636
EndProject
37+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fNbt", "..\..\external\fNbt\fNbt\fNbt.csproj", "{4488498D-976D-4DA3-BF72-109531AF0488}"
38+
EndProject
3739
Global
3840
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3941
Debug|Any CPU = Debug|Any CPU
@@ -106,10 +108,27 @@ Global
106108
{2BFFD5A4-DAC0-47D3-946F-1A8EE2ACCB46}.Release|ARM.ActiveCfg = Release|Any CPU
107109
{2BFFD5A4-DAC0-47D3-946F-1A8EE2ACCB46}.Release|x64.ActiveCfg = Release|Any CPU
108110
{2BFFD5A4-DAC0-47D3-946F-1A8EE2ACCB46}.Release|x86.ActiveCfg = Release|Any CPU
111+
{4488498D-976D-4DA3-BF72-109531AF0488}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
112+
{4488498D-976D-4DA3-BF72-109531AF0488}.Debug|Any CPU.Build.0 = Debug|Any CPU
113+
{4488498D-976D-4DA3-BF72-109531AF0488}.Debug|ARM.ActiveCfg = Debug|Any CPU
114+
{4488498D-976D-4DA3-BF72-109531AF0488}.Debug|x64.ActiveCfg = Debug|x64
115+
{4488498D-976D-4DA3-BF72-109531AF0488}.Debug|x64.Build.0 = Debug|x64
116+
{4488498D-976D-4DA3-BF72-109531AF0488}.Debug|x86.ActiveCfg = Debug|x86
117+
{4488498D-976D-4DA3-BF72-109531AF0488}.Debug|x86.Build.0 = Debug|x86
118+
{4488498D-976D-4DA3-BF72-109531AF0488}.Release|Any CPU.ActiveCfg = Release|Any CPU
119+
{4488498D-976D-4DA3-BF72-109531AF0488}.Release|Any CPU.Build.0 = Release|Any CPU
120+
{4488498D-976D-4DA3-BF72-109531AF0488}.Release|ARM.ActiveCfg = Release|Any CPU
121+
{4488498D-976D-4DA3-BF72-109531AF0488}.Release|x64.ActiveCfg = Release|x64
122+
{4488498D-976D-4DA3-BF72-109531AF0488}.Release|x64.Build.0 = Release|x64
123+
{4488498D-976D-4DA3-BF72-109531AF0488}.Release|x86.ActiveCfg = Release|x86
124+
{4488498D-976D-4DA3-BF72-109531AF0488}.Release|x86.Build.0 = Release|x86
109125
EndGlobalSection
110126
GlobalSection(SolutionProperties) = preSolution
111127
HideSolutionNode = FALSE
112128
EndGlobalSection
129+
GlobalSection(NestedProjects) = preSolution
130+
{4488498D-976D-4DA3-BF72-109531AF0488} = {F6653226-F844-4287-B966-DB9FA32A81FD}
131+
EndGlobalSection
113132
GlobalSection(MonoDevelopProperties) = preSolution
114133
StartupItem = MiNET.Service\MiNET.Service.csproj
115134
Policies = $0
Collapse file

‎src/MiNET/MiNET/MiNET.csproj‎

Copy file name to clipboardExpand all lines: src/MiNET/MiNET/MiNET.csproj
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
<Reference Include="Deedle">
3636
<HintPath>..\packages\Deedle.1.0.7\lib\net40\Deedle.dll</HintPath>
3737
</Reference>
38-
<Reference Include="fNbt, Version=0.6.2.0, Culture=neutral, processorArchitecture=MSIL">
39-
<SpecificVersion>False</SpecificVersion>
40-
<HintPath>..\packages\fNbt.0.6.2.0\lib\net35-Client\fNbt.dll</HintPath>
41-
</Reference>
4238
<Reference Include="LibNoise">
4339
<HintPath>..\packages\LibNoise.0.2\lib\NET45\LibNoise.dll</HintPath>
4440
</Reference>
@@ -280,6 +276,15 @@
280276
<ItemGroup>
281277
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
282278
</ItemGroup>
279+
<ItemGroup>
280+
<WCFMetadata Include="Service References\" />
281+
</ItemGroup>
282+
<ItemGroup>
283+
<ProjectReference Include="..\..\..\external\fNbt\fNbt\fNbt.csproj">
284+
<Project>{4488498d-976d-4da3-bf72-109531af0488}</Project>
285+
<Name>fNbt</Name>
286+
</ProjectReference>
287+
</ItemGroup>
283288
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
284289
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
285290
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Collapse file

‎src/MiNET/MiNET/MiNetServer.cs‎

Copy file name to clipboardExpand all lines: src/MiNET/MiNET/MiNetServer.cs
+46-60Lines changed: 46 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -444,46 +444,31 @@ private void HandleAck(byte[] receiveBytes, IPEndPoint senderEndpoint)
444444
PlayerNetworkSession session = _playerSessions[senderEndpoint];
445445
session.LastUpdatedTime = DateTime.UtcNow;
446446

447-
int ackSeqNo;
448-
{
449-
Ack ack = Ack.CreateObject();
450-
ack.Decode(receiveBytes);
451-
ackSeqNo = ack.sequenceNumber.IntValue();
452-
ack.PutPool();
453-
}
447+
Ack ack = Ack.CreateObject();
448+
ack.Decode(receiveBytes);
449+
int ackSeqNo = ack.sequenceNumber.IntValue();
450+
int toAckSeqNo = ack.toSequenceNumber.IntValue();
451+
if (ack.onlyOneSequence == 1) toAckSeqNo = ackSeqNo;
452+
ack.PutPool();
454453

455-
var queue = session.PlayerWaitingForAcksQueue;
454+
var queue = session.WaitingForAcksQueue;
456455

457-
int lenght = queue.Count;
458-
for (int i = 0; i < lenght; i++)
456+
for (int i = ackSeqNo; i <= toAckSeqNo; i++)
459457
{
460458
Datagram datagram;
461-
if (queue.TryPeek(out datagram))
459+
if (queue.TryRemove(i, out datagram))
462460
{
463-
int datagramSeqNo = datagram.Header.datagramSequenceNumber.IntValue();
464-
465-
if (datagramSeqNo <= ackSeqNo)
461+
foreach (MessagePart part in datagram.MessageParts)
466462
{
467-
if (queue.TryDequeue(out datagram))
468-
{
469-
foreach (MessagePart part in datagram.MessageParts)
470-
{
471-
part.Buffer = null;
472-
part.PutPool();
473-
}
474-
datagram.PutPool();
475-
}
476-
477-
if (datagramSeqNo == ackSeqNo)
478-
{
479-
break;
480-
}
481-
482-
continue;
463+
part.Buffer = null;
464+
part.PutPool();
483465
}
484-
485-
Log.DebugFormat("Failed to remove ACK #{0}, ACK in queue is #{1} and queue size={2}", ackSeqNo, datagramSeqNo, queue.Count);
486-
break;
466+
datagram.PutPool();
467+
Log.DebugFormat("Remove ACK #{0}. Queue size={1}", i, queue.Count);
468+
}
469+
else
470+
{
471+
Log.DebugFormat("Failed to remove ACK #{0}. Queue size={1}", i, queue.Count);
487472
}
488473
}
489474
}
@@ -496,21 +481,25 @@ private void HandleNak(byte[] receiveBytes, IPEndPoint senderEndpoint)
496481
nak.Decode(receiveBytes);
497482

498483
int ackSeqNo = nak.sequenceNumber.IntValue();
499-
Log.WarnFormat("--> NAK from Player {2} Count {0} #{1}", nak.count, ackSeqNo, session.Player.Username);
484+
int toAckSeqNo = nak.toSequenceNumber.IntValue();
485+
if (nak.onlyOneSequence == 1) toAckSeqNo = ackSeqNo;
486+
487+
var queue = session.WaitingForAcksQueue;
500488

501-
bool found = false;
502-
foreach (Datagram datagram in session.PlayerWaitingForAcksQueue)
489+
for (int i = ackSeqNo; i <= toAckSeqNo; i++)
503490
{
504-
if (datagram.Header.datagramSequenceNumber.IntValue() == ackSeqNo)
491+
Log.DebugFormat("NAK from Player {1} #{0}", i, session.Player.Username);
492+
493+
Datagram datagram;
494+
if (queue.TryGetValue(i, out datagram))
505495
{
506-
found = true;
507496
SendDatagram(senderEndpoint, datagram, true);
508-
Log.DebugFormat("Resent #{0}", ackSeqNo);
497+
Log.DebugFormat("Resent #{0}", i);
498+
}
499+
else
500+
{
501+
Log.WarnFormat("No datagram #{0} to resend", i);
509502
}
510-
}
511-
if (!found)
512-
{
513-
Log.WarnFormat("No datagram #{0}", ackSeqNo);
514503
}
515504

516505
nak.PutPool();
@@ -573,30 +562,27 @@ private void Update(object state)
573562
session.Player.DetectLostConnection();
574563
}
575564

576-
var queue = session.PlayerWaitingForAcksQueue;
565+
var queue = session.WaitingForAcksQueue;
577566

578567
int lenght = queue.Count;
579-
for (int i = 0; i < lenght; i++)
568+
foreach (var datagram in queue.Values)
580569
{
581-
Datagram datagram;
582-
if (queue.TryPeek(out datagram))
570+
if (!datagram.Timer.IsRunning)
583571
{
584-
if (!datagram.Timer.IsRunning)
585-
{
586-
Log.DebugFormat("Timer not running for #{0}", datagram.Header.datagramSequenceNumber);
587-
}
572+
Log.DebugFormat("Timer not running for #{0}", datagram.Header.datagramSequenceNumber);
573+
}
588574

589-
if (datagram.Timer.ElapsedMilliseconds > 200)
575+
if (datagram.Timer.ElapsedMilliseconds > 5000)
576+
{
577+
Datagram deleted;
578+
if (queue.TryRemove(datagram.Header.datagramSequenceNumber, out deleted))
590579
{
591-
if (queue.TryDequeue(out datagram))
580+
Log.DebugFormat("Cleaned #{0}", deleted.Header.datagramSequenceNumber.IntValue());
581+
foreach (MessagePart part in deleted.MessageParts)
592582
{
593-
Log.DebugFormat("Cleaned #{0}", datagram.Header.datagramSequenceNumber.IntValue());
594-
foreach (MessagePart part in datagram.MessageParts)
595-
{
596-
part.PutPool();
597-
}
598-
datagram.PutPool();
583+
part.PutPool();
599584
}
585+
deleted.PutPool();
600586
}
601587
}
602588
}
@@ -671,7 +657,7 @@ private void SendDatagram(IPEndPoint senderEndpoint, Datagram datagram, bool isR
671657
if (_playerSessions.ContainsKey(senderEndpoint) && !isResend && !_performanceTest)
672658
{
673659
PlayerNetworkSession session = _playerSessions[senderEndpoint];
674-
session.PlayerWaitingForAcksQueue.Enqueue(datagram);
660+
session.WaitingForAcksQueue.TryAdd(datagram.Header.datagramSequenceNumber, datagram);
675661
}
676662
}
677663

Collapse file

‎src/MiNET/MiNET/Net/Ack.cs‎

Copy file name to clipboardExpand all lines: src/MiNET/MiNET/Net/Ack.cs
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public class Ack : Package<Ack>
106106
public short count; // = null;
107107
public byte onlyOneSequence; // = null;
108108
public Int24 sequenceNumber; // = null;
109+
public Int24 toSequenceNumber; // = null;
109110

110111
public Ack()
111112
{
@@ -128,6 +129,8 @@ protected override void DecodePackage()
128129
count = ReadShort();
129130
onlyOneSequence = ReadByte();
130131
sequenceNumber = ReadLittle();
132+
if (onlyOneSequence == 0)
133+
toSequenceNumber = ReadLittle();
131134
}
132135
}
133136
}
Collapse file

‎src/MiNET/MiNET/Net/Nak.cs‎

Copy file name to clipboardExpand all lines: src/MiNET/MiNET/Net/Nak.cs
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public partial class Nak : Package<Nak>
77
public short count; // = null;
88
public byte onlyOneSequence; // = null;
99
public Int24 sequenceNumber; // = null;
10+
public Int24 toSequenceNumber; // = null;
1011

1112
public Nak()
1213
{
@@ -38,6 +39,8 @@ protected override void DecodePackage()
3839
count = ReadShort();
3940
onlyOneSequence = ReadByte();
4041
sequenceNumber = ReadLittle();
42+
if (onlyOneSequence == 0)
43+
toSequenceNumber = ReadLittle();
4144

4245
AfterDecode();
4346
}

0 commit comments

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