This repository was archived by the owner on Jun 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
94 lines (78 loc) · 2.77 KB
/
Copy pathProgram.cs
File metadata and controls
94 lines (78 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
namespace netcode.io.example.server
{
public static class Program
{
private static byte[] privateKey = new byte[]
{
0x60, 0x6a, 0xbe, 0x6e, 0xc9, 0x19, 0x10, 0xea,
0x9a, 0x65, 0x62, 0xf6, 0x6f, 0x2b, 0x30, 0xe4,
0x43, 0x71, 0xd6, 0x2c, 0xd1, 0x99, 0x27, 0x26,
0x6b, 0x3c, 0x60, 0xf4, 0xb7, 0x15, 0xab, 0xa1
};
public static void Main(string[] args)
{
const UInt64 testProtocolId = 0x1122334455667788L;
double time = 0f;
double deltaTime = 1.0 / 60.0;
bool quit = false;
Console.CancelKeyPress += (sender, a) =>
{
quit = true;
};
NetcodeLibrary.SetLogLevel(NetcodeLogLevel.Info);
var server = new Server(
"127.0.0.1:40000",
testProtocolId,
privateKey,
time);
var maxPacketSize = NetcodeLibrary.GetMaxPacketSize();
var packetData = new byte[maxPacketSize];
for (var i = 0; i < maxPacketSize; i++)
{
packetData[i] = (byte)i;
}
server.Start(NetcodeLibrary.GetMaxClients());
while (!quit)
{
server.Update(time);
if (server.ClientConnected(0))
{
server.SendPacket(0, packetData);
}
for (var clientIndex = 0; clientIndex < NetcodeLibrary.GetMaxClients(); ++clientIndex)
{
while (true)
{
var packet = server.ReceivePacket(clientIndex);
if (packet == null)
{
break;
}
if (packet.Length != packetData.Length)
{
Console.Error.WriteLine("Packet doesn't have expected length!");
}
else
{
for (var i = 0; i < maxPacketSize; i++)
{
if (packet[i] != packetData[i])
{
Console.Error.WriteLine($"Packet differs at index {i}!");
}
}
}
}
}
NetcodeLibrary.Sleep(deltaTime);
time += deltaTime;
}
if (quit)
{
Console.WriteLine("Shutting down");
}
server.Dispose();
}
}
}