-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIndividualServer.cs
More file actions
105 lines (81 loc) · 2.86 KB
/
IndividualServer.cs
File metadata and controls
105 lines (81 loc) · 2.86 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
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Net;
using RainMeadow.Shared;
namespace RainMeadow.IndividualServer
{
static partial class IndividualServer
{
// networking
[CommandLineArgument]
public static ushort port = 8720;
[CommandLineArgument]
public static ulong heartbeatTime = 50;
[CommandLineArgument]
public static ulong timeoutTime = 3000;
// lobby info
[CommandLineArgument]
public static int maxplayers = 4;
[CommandLineArgument]
public static bool passwordprotected = false;
[CommandLineArgument]
public static string name = "Router Lobby";
[CommandLineArgument]
public static string mode = "Meadow";
[CommandLineArgument]
public static string mods = "";
[CommandLineArgument]
public static string bannedMods = "";
static UDPPeerManager? peerManager = null;
static void Main(string[] args)
{
SharedCodeLogger.DebugInner += RainMeadow.Debug;
SharedCodeLogger.DebugMeInner += RainMeadow.DebugMe;
SharedCodeLogger.ErrorInner += RainMeadow.Error;
RainMeadow.Debug("Hello world!");
try
{
CommandLineArgumentAttribute.InitializeCommandLine();
peerManager = new(port, 10000);
RainMeadow.Debug($"Hosting on port {peerManager.port}");
peerManager.OnPeerForgotten += x =>
{
RainMeadow.Debug($"{x} was forgotten");
};
SetupClientEvents();
}
catch (Exception except)
{
RainMeadow.Error(except);
throw;
}
RainMeadow.Debug(Stopwatch.Frequency);
// Todo: Alert matchmaking server that we've successfully started listening on a new port
// Main Lobby
while (true)
{
peerManager.Update();
if (peerManager.IsPacketAvailable() && peerManager.Recieve(out var sender) is byte[] data)
{
try
{
if (sender is null) throw new InvalidProgrammerException("sender is null");
using (MemoryStream stream = new(data))
using (BinaryReader reader = new(stream))
{
Packet.Decode(reader, (IPEndPoint)sender);
}
}
catch (Exception except)
{
RainMeadow.Error(except);
RainMeadow.Stacktrace();
}
}
}
}
}
}