From 92e540aaa60ab8fcf4c431e188fe3389ab27e6c1 Mon Sep 17 00:00:00 2001 From: "Robin C. Ladiges" Date: Mon, 5 Sep 2022 03:56:21 +0200 Subject: [PATCH] only start listening for clients once everything is initialized Otherwise clients might connect to the server before everything is ready for them. E.g. when restarting the server, the clients will immediately try to reconnect. Clients might connect before the `PacketHandler` is initialized, which results in some packets not being processed by the server. Same goes for the commands: Discord or the JsonApi might send in commands before all commands were added to the `CommandHandler`. Without the `ClientJoined` action, clients might even be allowed connect if they are on the banlist. --- Server/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/Program.cs b/Server/Program.cs index 8015550..962f38f 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -12,7 +12,6 @@ Server.Server server = new Server.Server(); HashSet shineBag = new HashSet(); CancellationTokenSource cts = new CancellationTokenSource(); bool restartRequested = false; -Task listenTask = server.Listen(cts.Token); Logger consoleLogger = new Logger("Console"); DiscordBot bot = new DiscordBot(); await bot.Run(); @@ -655,7 +654,8 @@ Task.Run(() => { }).ContinueWith(x => { if (x.Exception != null) { consoleLogger.Error(x.Exception.ToString()); } }); #pragma warning restore CS4014 -await listenTask; +await server.Listen(cts.Token); + if (restartRequested) //need to do this here because this needs to happen after the listener closes, and there isn't an //easy way to sync in the restartserver command without it exiting Main() {