Stop() public méthode

public Stop ( ) : void
Résultat void
Exemple #1
0
        static void WebServerOnDisconnect(int id)
        {
            _connectedIds.Remove(id);
            _playerDatas.Remove(id);

            // Tell other players about the disconnection
            _bitBuffer.Clear();
            _bitBuffer.AddByte(4);
            _bitBuffer.AddUShort((ushort)id);
            _bitBuffer.ToArray(_buffer);
            _webServer.SendAll(_connectedIds, new ArraySegment <byte>(_buffer, 0, 3));

            // Check if we have less than 2 players and should cancel the game
            if (_currentState != GameState.Waiting && _connectedIds.Count < 2)
            {
                beginTimer?.Stop();
                _currentState = GameState.Waiting;
                SendStateUpdate(_currentState);
            }
        }
Exemple #2
0
 public static void Stop(this ISerializable entity, Timer timer)
 {
     timer?.Stop();
     entity.MarkDirty();
 }
Exemple #3
0
        private void HandleInput(string str)
        {
            try
            {
                if (str == null)
                {
                    return;
                }

                BroadcastRaw(str);

                if (str.IndexOf("PONG") != -1 || str.IndexOf("PING") != -1)
                {
                    PingPong(str);
                    return;
                }

                if (str.IndexOf("353") != -1)
                {
                    BroadcastRaw(General.Local(109));

                    int index = str.ToLower().IndexOf(Data.IrcRoom.ToLower()) + Data.IrcRoom.Length + 2;

                    if (index == 1)
                    {
                        return;
                    }

                    string strList = str.Substring(index, str.Length - index);

                    string[] strs = strList.Trim().Split(' ');

                    Data.IrcList.Clear();
                    Data.IrcList.AddRange(strs);
                    Data.IrcList.Remove(Data.IrcNick);
                }

                if (str.IndexOf("001") != -1 && c_Connecting)
                {
                    c_Connected  = true;
                    c_Connecting = false;

                    if (c_ConnectTimer != null)
                    {
                        c_ConnectTimer.Stop();
                    }

                    BroadcastSystem(General.Local(108));
                    c_Attempts = 1;

                    SendMessage(String.Format("JOIN {0}", Data.IrcRoom));

                    foreach (Data data in Data.Datas.Values)
                    {
                        if (data.Mobile.HasGump(typeof(IrcGump)))
                        {
                            GumpPlus.RefreshGump(data.Mobile, typeof(IrcGump));
                        }
                    }
                }

                if (str.Length > 300)
                {
                    return;
                }

                if (str.IndexOf("PRIVMSG") != -1)
                {
                    string parOne = str.Substring(1, str.IndexOf("!") - 1);

                    string parThree = str.Substring(str.IndexOf("!") + 1, str.Length - str.IndexOf("!") - (str.Length - str.IndexOf("PRIVMSG")) - 1);

                    int index = 0;

                    index = str.ToLower().IndexOf(Data.IrcRoom.ToLower()) + Data.IrcRoom.Length + 2;

                    if (index == 1)
                    {
                        return;
                    }

                    string parTwo = str.Substring(index, str.Length - index);

                    if (parTwo.IndexOf("ACTION") != -1)
                    {
                        index  = parTwo.IndexOf("ACTION") + 7;
                        parTwo = parTwo.Substring(index, parTwo.Length - index);
                        str    = String.Format("<{0}> {1} {2}", Data.IrcRoom, parOne, parTwo);
                    }
                    else
                    {
                        str = String.Format("<{0}> {1}: {2}", Data.IrcRoom, parOne, parTwo);
                    }

                    Broadcast(parOne, str);

                    if (str.ToLower().IndexOf("!status") != -1 && c_NextStatus < DateTime.Now)
                    {
                        c_NextStatus = DateTime.Now + TimeSpan.FromSeconds(15);
                        s_Connection.SendMessage(String.Format("PRIVMSG {0} : {1}", Data.IrcRoom, Status));
                        BroadcastSystem(Status);
                    }
                }
            }
            catch (Exception e)
            {
                Errors.Report(General.Local(267), e);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Message);
            }
        }
Exemple #4
0
		public static void RequestVersion()
		{
			if (_Timeout != null && _Timeout.Running)
			{
				CSOptions.ToConsole("Previous request has not been handled yet.");
				return;
			}

			CSOptions.ToConsole("Requesting remote version...");

			NotifyStaff("Checking for updates...", false);

			_Timeout = Timer.DelayCall(
				TimeSpan.FromMilliseconds(CSOptions.Timeout.TotalMilliseconds + 1000),
				() =>
				{
					CSOptions.ToConsole("Request timed-out.");

					NotifyStaff("Update request failed, the connection timed-out.", true, 1.0, 10.0);
				});

			VitaNexCore.TryCatch(
				() =>
				HttpService.SendRequest(
					URL != null ? URL.ToString() : DefaultURL,
					(int)CSOptions.Timeout.TotalMilliseconds,
					(i, send, receive) =>
					{
						if (URL == null)
						{
							URL = i.URL;
						}

						string rcv = String.Join(String.Empty, receive.GetContent());

						OnDataReceived(rcv);

						if (_Timeout == null)
						{
							return;
						}

						_Timeout.Stop();
						_Timeout = null;
					}),
				CSOptions.ToConsole);
		}
Exemple #5
0
            /*private static void ProcessAddQueue()
             * {
             *      while ( m_AddQueue.Count != 0 )
             *      {
             *              Timer t = (Timer)m_AddQueue.Dequeue();
             *              t.m_Next = DateTime.Now + t.m_Delay;
             *              t.m_Index = 0;
             *              m_Timers[(int)t.Priority].Add( t );
             *      }//while !empty
             * }
             *
             * private static void ProcessRemoveQueue()
             * {
             *      while ( m_RemoveQueue.Count != 0 )
             *      {
             *              Timer t = (Timer)m_RemoveQueue.Dequeue();
             *              m_Timers[(int)t.Priority].Remove( t );
             *      }//while !empty
             * }
             *
             * private static void ProcessPriorityQueue()
             * {
             *      while ( m_PriQueue.Count != 0 )
             *      {
             *              PriChangeEntry e = (PriChangeEntry)m_PriQueue.Dequeue();
             *
             *              Timer t = e.m_Timer;
             *              TimerPriority oldPri = e.m_OldPri;
             *
             *              m_Timers[(int)oldPri].Remove( t );
             *              m_Timers[(int)t.Priority].Add( t );
             *
             *              e.Free();
             *      }//while !empty
             * }*/

            public void TimerMain()
            {
                DateTime now;
                int      i, j;

                while (!Core.Closing)
                {
                    now = DateTime.UtcNow;

                    /*ProcessAddQueue();
                     * ProcessRemoveQueue();
                     * ProcessPriorityQueue();*/
                    lock (m_ChangeQueue.SyncRoot)
                        ProcessChangeQueue(now);

                    bool queued = false;

                    for (i = 0; i < m_Timers.Length; i++)
                    {
                        if (now < m_NextPriorities[i])
                        {
                            break;
                        }

                        m_NextPriorities[i] = now + m_PriorityDelays[i];

                        for (j = 0; j < m_Timers[i].Count; j++)
                        {
                            Timer t = (Timer)m_Timers[i][j];

                            if (!t.m_Queued && now > t.m_Next)
                            {
                                t.m_Queued = true;

                                lock (m_Queue)
                                    m_Queue.Enqueue(t);

                                queued = true;

                                if (t.m_Count != 0 && (++t.m_Index >= t.m_Count))
                                {
                                    t.Stop();
                                }
                                else
                                {
                                    t.m_Next = now + t.m_Interval;
                                }
                            }
                        }                //for timers.Count
                    }                    //for Timer.Timers.Length

                    /* notify the core of new timers in the queue */
                    if (queued)
                    {
                        Core.WakeUp();
                    }

                    /* find the earliest timer class which needs another check */
                    DateTime earliest = DateTime.MaxValue;

                    for (i = 0; i < m_Timers.Length; i++)
                    {
                        if (m_Timers[i].Count > 0 &&
                            m_NextPriorities[i] < earliest)
                        {
                            earliest = m_NextPriorities[i];
                        }
                    }

                    /* sleep until there is a signal or until the next
                     * timer must be activated */
                    now = DateTime.UtcNow;

                    TimeSpan sleep = earliest <= now
                                                ? TimeSpan.FromMilliseconds(10)
                                                : (earliest == DateTime.MaxValue
                                                   ? TimeSpan.FromSeconds(1)
                                                   : earliest - now);

                    m_Signal.WaitOne(sleep, false);
                    //Thread.Sleep(sleep);
                    //Thread.Sleep(10);
                }        //while (true)
            }            //TimerMain