Beispiel #1
0
        private static bool IsPortBlockedBySDaysTDieServer(int port)
        {
            KeyValuePair <string, SDaysTDieServer> keyValuePair = SDaysTDieServersByUserIds.FirstOrDefault(x =>
                                                                                                           x.Value.ServerSettings.ServerPort == port || x.Value.ServerSettings.TelnetPort == port);

            return(keyValuePair.Key != "" && keyValuePair.Key != null);
        }
Beispiel #2
0
        internal async static Task <StopServerResponse> TryStopServer(ServerSetting serverSetting)
        {
            StopServerResponse response = null;
            KeyValuePair <string, SDaysTDieServer> keyValuePair = SDaysTDieServersByUserIds.FirstOrDefault(x => x.Value.ServerSettings.WorldGenSeed == serverSetting.WorldGenSeed);
            SDaysTDieServer  sDaysTDieServer  = keyValuePair.Value;
            StopServerResult stopServerResult = StopServerResult.STOPPING;

            void SDaysTDieServer_OnSDaysTDieServerStoppedHandler(SDaysTDieServer sender, SDaysTDieServer.OnSDaysTDieServerStoppedEventArgs e)
            {
                if (e.Message == "*** Shutdown successful ***" || e.Message == "*** Server already down! ***")
                {
                    stopServerResult = StopServerResult.SERVER_STOPPED;
                }
                else if (e.Message == "*** Shutdown done with killing process ***")
                {
                    stopServerResult = StopServerResult.SERVER_KILLED;
                }
            }

            sDaysTDieServer.OnSDaysTDieServerStoppedHandler += SDaysTDieServer_OnSDaysTDieServerStoppedHandler;
            keyValuePair.Value.Stop();

            async Task <StopServerResponse> CheckServerStopped()
            {
                for (int tryShutDownCounter = 40; tryShutDownCounter > 0; tryShutDownCounter--)
                {
                    if (stopServerResult != StopServerResult.STOPPING)
                    {
                        SDaysTDieServersByUserIds.Remove(keyValuePair.Key);
                        return(new StopServerResponse(stopServerResult));
                    }
                    await Task.Delay(1000);
                }
                return(new StopServerResponse(StopServerResult.FAILED_UNKNOWN_REASON));
            }

            response = await CheckServerStopped();

            sDaysTDieServer.OnSDaysTDieServerStoppedHandler -= SDaysTDieServer_OnSDaysTDieServerStoppedHandler;

            return(response);
        }
Beispiel #3
0
        internal static bool IsServerRunningBySeed(string worldGenSeed)
        {
            KeyValuePair <string, SDaysTDieServer> keyValuePair = SDaysTDieServersByUserIds.FirstOrDefault(x => x.Value.ServerSettings.WorldGenSeed == worldGenSeed);

            return(keyValuePair.Key != "" && keyValuePair.Key != null);
        }
Beispiel #4
0
        private static bool IsServerOfSettingsRunning(ServerSettings serverSettings)
        {
            KeyValuePair <string, SDaysTDieServer> keyValuePair = SDaysTDieServersByUserIds.FirstOrDefault(x => x.Value.ServerSettings.WorldGenSeed == serverSettings.WorldGenSeed);

            return(keyValuePair.Key != "" && keyValuePair.Key != null);
        }