private void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (!Config.Enabled || DDBridge == null)
            {
                return;
            }

            if (Torch.CurrentSession == null)
            {
                DDBridge.SendStatus(Config.StatusPre);
            }
            else
            {
                if (timerStart.Ticks == 0)
                {
                    timerStart = e.SignalTime;
                }

                string   status = Config.Status;
                DateTime upTime = new DateTime(e.SignalTime.Subtract(timerStart).Ticks);

                Regex regex = new Regex(@"{uptime@(.*?)}");
                if (regex.IsMatch(status))
                {
                    var    match  = regex.Match(status);
                    string format = match.Groups[0].ToString().Replace("{uptime@", "").Replace("}", "");
                    status = Regex.Replace(status, "{uptime@(.*?)}", upTime.ToString(format));
                }

                DDBridge.SendStatus(status
                                    .Replace("{p}", MySession.Static.Players.GetOnlinePlayers().Count.ToString())
                                    .Replace("{mp}", MySession.Static.MaxPlayers.ToString())
                                    .Replace("{mc}", MySession.Static.Mods.Count.ToString())
                                    .Replace("{ss}", torchServer.SimulationRatio.ToString("0.00")));

                string players = MySession.Static.Players.GetOnlinePlayers().Count.ToString();
                string sim     = torchServer.SimulationRatio.ToString("0.00");
                if (Config.DataCollect)
                {
                    try
                    {
                        using (WebClient client = new WebClient())
                        {
                            NameValueCollection postData = new NameValueCollection()
                            {
                                //order: {"parameter name", "parameter value"}
                                { "currentSim", sim }, { "players", players }
                            };
                            client.UploadValuesAsync(new Uri("http://captainjackyt.com/SE/staff/globaltracking.php"), postData);
                        }
                    }
                    catch
                    {
                        Log.Warn("Cannot connect to database.");
                    }
                }
            }
        }
Пример #2
0
 private void _timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     DDBridge.SendStatus(Config.Status
                         .Replace("{p}", MySession.Static.Players.GetOnlinePlayers().Count.ToString())
                         .Replace("{mp}", MySession.Static.MaxPlayers.ToString())
                         .Replace("{mc}", MySession.Static.Mods.Count.ToString())
                         .Replace("{ss}", torchServer.SimulationRatio.ToString("0.00")));
 }
Пример #3
0
        private void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (!Config.Enabled || DDBridge == null)
            {
                return;
            }

            if (Torch.CurrentSession == null)
            {
                DDBridge.SendStatus(Config.StatusPre);
            }
            else
            {
                if (timerStart.Ticks == 0)
                {
                    timerStart = e.SignalTime;
                }

                string   status = Config.Status;
                DateTime upTime = new DateTime(e.SignalTime.Subtract(timerStart).Ticks);

                Regex regex = new Regex(@"{uptime@(.*?)}");
                if (regex.IsMatch(status))
                {
                    var    match  = regex.Match(status);
                    string format = match.Groups[0].ToString().Replace("{uptime@", "").Replace("}", "");
                    status = Regex.Replace(status, "{uptime@(.*?)}", upTime.ToString(format));
                }

                DDBridge.SendStatus(status
                                    .Replace("{p}", MySession.Static.Players.GetOnlinePlayers().Count.ToString())
                                    .Replace("{mp}", MySession.Static.MaxPlayers.ToString())
                                    .Replace("{mc}", MySession.Static.Mods.Count.ToString())
                                    .Replace("{ss}", torchServer.SimulationRatio.ToString("0.00")));
            }
        }
        private void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (!Config.Enabled || DDBridge == null)
            {
                return;
            }

            if (Torch.CurrentSession == null)
            {
                DDBridge.SendStatus(Config.StatusPre);
            }
            else
            {
                if (timerStart.Ticks == 0)
                {
                    timerStart = e.SignalTime;
                }

                string   status = Config.Status;
                DateTime upTime = new DateTime(e.SignalTime.Subtract(timerStart).Ticks);

                Regex regex = new Regex(@"{uptime@(.*?)}");
                if (regex.IsMatch(status))
                {
                    var    match  = regex.Match(status);
                    string format = match.Groups[0].ToString().Replace("{uptime@", "").Replace("}", "");
                    status = Regex.Replace(status, "{uptime@(.*?)}", upTime.ToString(format));
                }

                DDBridge.SendStatus(status
                                    .Replace("{p}", MySession.Static.Players.GetOnlinePlayers().Where(p => p.IsRealPlayer).Count().ToString())
                                    .Replace("{mp}", MySession.Static.MaxPlayers.ToString())
                                    .Replace("{mc}", MySession.Static.Mods.Count.ToString())
                                    .Replace("{ss}", torchServer.SimulationRatio.ToString("0.00")));

                if (Config.SimPing)
                {
                    if (torchServer.SimulationRatio < float.Parse(Config.SimThresh))
                    {
                        //condition
                        if (i == DiscordBridge.MinIncrement && DiscordBridge.Locked != 1 && MySession.Static.Players.GetOnlinePlayerCount() > 0)
                        {
                            Task.Run(() => DDBridge.SendSimMessage(Config.SimMessage));
                            i = 0;
                            DiscordBridge.Locked          = 1;
                            DiscordBridge.FirstWarning    = 1;
                            DiscordBridge.CooldownNeutral = 0;
                            Log.Warn("Simulation warning sent!");
                        }
                        if (DiscordBridge.FirstWarning == 1 && DiscordBridge.CooldownNeutral.ToString("00") == "60" && MySession.Static.Players.GetOnlinePlayerCount() > 0)
                        {
                            Task.Run(() => DDBridge.SendSimMessage(Config.SimMessage));
                            Log.Warn("Simulation warning sent!");
                            DiscordBridge.CooldownNeutral = 0;
                            i = 0;
                        }
                        DiscordBridge.CooldownNeutral += (60 / DiscordBridge.Factor);
                        i++;
                    }
                    else
                    {
                        //reset counter whenever Sim speed warning threshold is not met meaning that sim speed has to stay below
                        //the set threshold for a consecutive minuete to trigger warning
                        i = 0;
                        DiscordBridge.CooldownNeutral = 0;
                    }
                }
            }
        }
Пример #5
0
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (!Config.Enabled || DDBridge == null)
            {
                return;
            }

            if (!DDBridge.Ready)
            {
                if (TickRetry >= 3 && DiscordBridge.Discord.CurrentUser == null)
                {
                    DiscordBridge.Discord.ConnectAsync();
                    TickRetry = 0;
                }
                else
                {
                    if (TickRetry > 10)
                    {
                        DiscordBridge.Discord.DisconnectAsync();
                        DiscordBridge.Discord.Dispose();
                        DDBridge  = new DiscordBridge(this);
                        TickRetry = 0;
                    }
                }

                TickRetry++;
            }
            else if (DiscordBridge.Discord.CurrentUser == null || DiscordBridge.Discord.CurrentUser.Id == 0L ||
                     DiscordBridge.Discord.Presences == null ||
                     DiscordBridge.Discord.Presences.Count == 0)
            {
                DDBridge.Ready = false;
                DiscordBridge.Discord.DisconnectAsync();
                DiscordBridge.Discord.Dispose();
                DDBridge  = new DiscordBridge(this);
                TickRetry = 0;
            }

            if (Torch.CurrentSession == null || torchServer.SimulationRatio <= 0f)
            {
                DDBridge.SendStatus(Config.StatusPre, UserStatus.DoNotDisturb);
            }
            else
            {
                if (timerStart.Ticks == 0)
                {
                    timerStart = e.SignalTime;
                }

                string   status = Config.Status;
                DateTime upTime = new DateTime(e.SignalTime.Subtract(timerStart).Ticks);

                Regex regex = new Regex(@"{uptime@(.*?)}");
                if (regex.IsMatch(status))
                {
                    var    match  = regex.Match(status);
                    string format = match.Groups[0].ToString().Replace("{uptime@", "").Replace("}", "");
                    status = Regex.Replace(status, "{uptime@(.*?)}", upTime.ToString(format));
                }

                var playersCount = MySession.Static.Players.GetOnlinePlayers().Where(p => p.IsRealPlayer).Count();
                var maxPlayers   = MySession.Static.MaxPlayers;
                var simSpeed     = torchServer.SimulationRatio.ToString("0.00");

                DDBridge.SendStatus(status
                                    .Replace("{p}", playersCount.ToString())
                                    .Replace("{mp}", maxPlayers.ToString())
                                    .Replace("{mc}", MySession.Static.Mods.Count.ToString())
                                    .Replace("{ss}", simSpeed), playersCount > 0? UserStatus.Online : UserStatus.Idle);

                if (Config.SimPing)
                {
                    if (torchServer.SimulationRatio < Config.SimThresh)
                    {
                        //condition
                        if (i == DiscordBridge.MinIncrement && DiscordBridge.Locked != 1 && playersCount > 0)
                        {
                            Task.Run(() => DDBridge.SendSimMessage(Config.SimMessage));
                            i = 0;
                            DiscordBridge.Locked          = 1;
                            DiscordBridge.FirstWarning    = 1;
                            DiscordBridge.CooldownNeutral = 0;
                            Log.Warn("Simulation warning sent!");
                        }
                        if (DiscordBridge.FirstWarning == 1 && DiscordBridge.CooldownNeutral.ToString("00") == "60" && playersCount > 0)
                        {
                            Task.Run(() => DDBridge.SendSimMessage(Config.SimMessage));
                            Log.Warn("Simulation warning sent!");
                            DiscordBridge.CooldownNeutral = 0;
                            i = 0;
                        }
                        DiscordBridge.CooldownNeutral += (60 / DiscordBridge.Factor);
                        i++;
                    }
                    else
                    {
                        //reset counter whenever Sim speed warning threshold is not met meaning that sim speed has to stay below
                        //the set threshold for a consecutive minuete to trigger warning
                        i = 0;
                        DiscordBridge.CooldownNeutral = 0;
                    }
                }
            }
        }