-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
56 lines (54 loc) · 1.86 KB
/
Copy pathProgram.cs
File metadata and controls
56 lines (54 loc) · 1.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
using System.Net;
namespace FMServer;
class Program
{
static void Main()
{
Console.Title = "Fazbear Multiplayer Server";
Console.WriteLine();
int port = 7121;
try {
port = int.Parse(Environment.GetEnvironmentVariable("PORT") ?? port.ToString());
}
catch { }
var server = new GameServer(IPAddress.Any, port)
{
ServerSecret = (Environment.GetEnvironmentVariable("SERVER_SECRET") ?? "").Truncate(32),
AdminName = Environment.GetEnvironmentVariable("ADMIN_NAME") ?? ""
};
if (server.Start())
{
Console.WriteLine($"[{DateTime.Now}] Listening on port {server.Port}");
bool stop = false;
while (true)
{
string? text = Console.ReadLine()?.ToLower();
if ((text == "stop" && !server.ChannelInGame) || (text == "yes" && stop))
break;
if (text == "stop" && server.ChannelInGame)
{
Console.WriteLine("There is one or more lobbies in-game, if you are sure you want to stop the server, type in 'yes'");
stop = true;
}
if(text == "list")
{
var list = server.ChannelList;
if (list.Length == 0)
Console.WriteLine("No lobbies found.");
else
{
Console.WriteLine("Active lobbies:");
foreach(var item in list)
Console.WriteLine($"- {item}");
}
}
}
server.Stop();
}
else
{
Console.WriteLine("Failed to start server. Is the port available?");
Console.ReadLine();
}
}
}