Exemple #1
0
        private async void Start()
        {
            //Let's start the listener on our listen port. Allow all IPs from the server list.
            _            = _logHandler.LogMessage($"Starting SRCDSLogService on {_port}", channel: false);
            _logReceiver = new LogReceiver(_port, CreateIpEndPoints());

            await Task.Run(() =>
            {
                if (_dataService.RSettings.ProgramSettings.Debug)
                {
                    _logReceiver.ListenRaw(msg => { Console.WriteLine($"RAW LOG FROM {_logReceiver.lastServer.Address}: " + msg); });
                }

                _logReceiver.Listen <GenericCommand>(genericCommand => { HandleIngameCommand(_logReceiver.lastServer, genericCommand); });
            });

            //We are going to use this loop to make sure log services are still running. Should they fail, we will tear
            //down and rebuild.
            while (true)
            {
                bool portBound = IPGlobalProperties.GetIPGlobalProperties()
                                 .GetActiveUdpListeners().Any(p => p.Port == _port);

                if (!portBound)
                {
                    if (_restartCount < RESTART_LIMIT)
                    {
                        try
                        {
                            _logReceiver.Dispose();
                        }
                        catch (Exception e)
                        {
                            await _logHandler.LogMessage($"Attempted dispose, but had an issue.\n{e}", alert : true, color : LOG_COLOR);
                        }

                        _restartCount++;

                        //Restart the service
                        Start();
                        await _logHandler.LogMessage($"Log service has been restarted {_restartCount} times!", color : LOG_COLOR);

                        //Reset the retry count in 15 minutes after the first issue
                        //I expect the log service to die sometimes for whatever reason.
                        if (_restartCount == 0)
                        {
                            _ = Task.Run(async() =>
                            {
                                await Task.Delay(TimeSpan.FromMinutes(15));
                                _restartCount = 0;
                            });
                        }
                    }
                    else
                    {
                        await _logHandler.LogMessage($"The SrcdsLogService has restarted over {RESTART_LIMIT} in the last 15 minutes. " +
                                                     $"I will not restart the service again.", alert : true, color : LOG_COLOR);
                    }
                    return;
                }

                //Hol up for a bit before rechecking
                await Task.Delay(5000);
            }
        }
        private void StartListeners(LogReceiver logReceiver)
        {
            logReceiver.Listen <ChatMessage>(chat =>
            {
                ProcessChatMessage(chat);
            });

            logReceiver.Listen <RoundEndScores>(roundEndScore =>
            {
                if (Match.IsLive)
                {
                    Match.CTScore = roundEndScore.CTScore + Match.CtSwapScore;
                    Match.TScore  = roundEndScore.TScore + Match.TSwapScore;

                    if (Match.CTScore + Match.TScore == 15 || ((Match.CTScore + Match.TScore) > 29 && (Match.CTScore + Match.TScore) % 3 == 0))
                    {
                        Match.CtSwapScore = Match.TScore;
                        Match.TSwapScore  = Match.CTScore;
                    }

                    if ((Match.CTScore + Match.TScore) == 15 || Match.ShouldSwapSides(Match.CTScore + Match.TScore))
                    {
                        Match.SwapSides();
                        Match.Paused = true;
                        ProcessSwapSides();
                    }

                    ProcessScoreUpdate();
                }
            });

            logReceiver.ListenRaw(result => { ProcessRaw(result); });

            logReceiver.Listen <KillFeed>(e =>
            {
            });

            logReceiver.Listen <MatchLive>(live =>
            {
                Match.MapName = live.MapName;

                Match.IsLive = true;

                ProcessMatchStarting(Match);
            });

            logReceiver.Listen <CTTeamName>(ctSide =>
            {
                Match.CTName = ctSide.CTName;
            });

            logReceiver.Listen <TTeamName>(tSide =>
            {
                Match.TName = tSide.TName;
            });

            logReceiver.Listen <StartFreezeTime>(startfreezeTime =>
            {
                Match.IsFreezeTime = true;
            });

            logReceiver.Listen <EndFreezeTime>(endFreezeTime =>
            {
                if (Match.Paused == true)
                {
                    ProcessUnpauseMatch();
                }
                Match.IsFreezeTime = false;
                Match.Paused       = false;
            });

            logReceiver.Listen <MatchEnd>(matchEnd =>
            {
                Console.WriteLine(matchEnd.MatchId);

                ProcessMatchEnd(matchEnd.MatchId);

                Match.EndMatch();
            });
        }