예제 #1
0
        void logoutTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            TimeSpan tsAniDBUDPTemp = DateTime.Now - JMMService.LastAniDBUDPMessage;

            if (ExtendPauseSecs.HasValue && tsAniDBUDPTemp.TotalSeconds >= ExtendPauseSecs.Value)
            {
                ResetExtendPause();
            }

            if (!isLoggedOn)
            {
                return;
            }

            // don't ping when anidb is taking a long time to respond
            if (WaitingOnResponse)
            {
                try
                {
                    if (WaitingOnResponseTime.HasValue)
                    {
                        Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(ServerSettings.Culture);

                        TimeSpan ts = DateTime.Now - WaitingOnResponseTime.Value;
                        ServerInfo.Instance.WaitingOnResponseAniDBUDPString =
                            string.Format(JMMServer.Properties.Resources.AniDB_ResponseWaitSeconds, ts.TotalSeconds);
                    }
                }
                catch
                {
                }
                return;
            }

            lock (lockAniDBConnections)
            {
                TimeSpan tsAniDBNonPing = DateTime.Now - JMMService.LastAniDBMessageNonPing;
                TimeSpan tsPing         = DateTime.Now - JMMService.LastAniDBPing;
                TimeSpan tsAniDBUDP     = DateTime.Now - JMMService.LastAniDBUDPMessage;

                // if we haven't sent a command for 45 seconds, send a ping just to keep the connection alive
                if (tsAniDBUDP.TotalSeconds >= Constants.PingFrequency && tsPing.TotalSeconds >= Constants.PingFrequency &&
                    !IsBanned && !ExtendPauseSecs.HasValue)
                {
                    AniDBCommand_Ping ping = new AniDBCommand_Ping();
                    ping.Init();
                    ping.Process(ref soUdp, ref remoteIpEndPoint, curSessionID, new UnicodeEncoding(true, false));
                }

                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(ServerSettings.Culture);

                string msg = string.Format(JMMServer.Properties.Resources.AniDB_LastMessage, tsAniDBUDP.TotalSeconds);

                if (tsAniDBNonPing.TotalSeconds > Constants.ForceLogoutPeriod) // after 10 minutes
                {
                    ForceLogout();
                }
            }
        }
예제 #2
0
        void logoutTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            TimeSpan tsAniDBUDPTemp = DateTime.Now - JMMService.LastAniDBUDPMessage;

            if (ExtendPauseSecs.HasValue && tsAniDBUDPTemp.TotalSeconds >= ExtendPauseSecs.Value)
            {
                ResetExtendPause();
            }

            if (!isLoggedOn)
            {
                return;
            }

            // don't ping when anidb is taking a long time to respond
            if (WaitingOnResponse)
            {
                try
                {
                    if (WaitingOnResponseTime.HasValue)
                    {
                        TimeSpan ts = DateTime.Now - WaitingOnResponseTime.Value;
                        ServerInfo.Instance.WaitingOnResponseAniDBUDPString = string.Format("Waiting on response for {0} seconds...", ts.TotalSeconds);
                    }
                }
                catch { }
                return;
            }

            lock (lockAniDBConnections)
            {
                TimeSpan tsAniDBNonPing = DateTime.Now - JMMService.LastAniDBMessageNonPing;
                TimeSpan tsPing         = DateTime.Now - JMMService.LastAniDBPing;
                TimeSpan tsAniDBUDP     = DateTime.Now - JMMService.LastAniDBUDPMessage;

                // if we haven't sent a command for 20 seconds, send a ping just to keep the connection alive
                if (tsAniDBUDP.TotalSeconds >= 20 && tsPing.TotalSeconds >= 20 && !IsBanned && !ExtendPauseSecs.HasValue)
                {
                    AniDBCommand_Ping ping = new AniDBCommand_Ping();
                    ping.Init();
                    ping.Process(ref soUdp, ref remoteIpEndPoint, curSessionID, new UnicodeEncoding(true, false));
                }

                string msg = string.Format("Last message sent {0} seconds ago", tsAniDBUDP.TotalSeconds);

                if (tsAniDBNonPing.TotalSeconds > 600)                 // after 10 minutes
                {
                    ForceLogout();
                }
            }
        }