コード例 #1
0
        /// <summary>
        /// Process our maintenance schedule.
        /// </summary>
        internal static void Process()
        {
            try
            {
                if (IsScheduled == true)
                {
                    TimeSpan span = NextSceduledMaintenance - DateTime.Now;
                    if (span.TotalMinutes > 0 && span.TotalMinutes < 50)
                    {
                        TimeSpan span2 = DateTime.Now - LastBroadCast;
                        if (span2.TotalMinutes > 10)
                        {
                            LastBroadCast = DateTime.Now;

                            //GENERATE BROADCAST
                            SMSG_SENDCHAT spkt = new SMSG_SENDCHAT();
                            spkt.Name        = "GM";
                            spkt.MessageType = SMSG_SENDCHAT.MESSAGE_TYPE.SYSTEM_MESSAGE_RED;
                            spkt.Message     = String.Format(CultureInfo.InvariantCulture, "Maintenance starting at: {0}", NextSceduledMaintenance.ToShortTimeString());

                            //FORWARD THE BROADCAST
                            foreach (Character characterTarget in LifeCycle.Characters)
                            {
                                if (characterTarget.client.isloaded == false)
                                {
                                    continue;
                                }
                                spkt.SessionId = characterTarget.id;
                                characterTarget.client.Send((byte[])spkt);
                            }
                        }
                    }
                    else if (span.TotalMinutes < 0)
                    {
                        Saga.Managers.NetworkService.InterNetwork.MAINTENANCE_ENTER();
                        IsScheduled = false;

                        while (LifeCycle.Count > 0)
                        {
                            try
                            {
                                foreach (Character characterTarget in LifeCycle.Characters)
                                {
                                    characterTarget.client.Close();
                                    //LifeCycle.ListOfUsersByName.Remove(pair.Key);
                                    LifeCycle.Unsubscribe(characterTarget);
                                }
                            }
                            catch (Exception)
                            {
                                //Do nothing
                            }
                        }

                        //Wait half a minute
                        Thread.Sleep(30000);

                        //Exit's the process
                        Environment.Exit(2);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.Message);
            }
        }
コード例 #2
0
        /// <summary>
        /// Processes all AI threads.
        /// </summary>
        /// <remarks>
        /// If the qeuee get's to big reprioritize the
        /// AI thread with higher priviledges.
        /// </remarks>
        internal static void Process()
        {
            try
            {
                //SET PRIORITY OF THE THREAD
                int count = ProcessingQueuee.Count;
                lock (synclock)
                {
                    if (count > 200)
                    {
                        Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
                    }
                    else if (count > 20)
                    {
                        Thread.CurrentThread.Priority = ThreadPriority.Lowest;
                    }
                }

                int i = 0;
                while (ProcessingQueuee.Count > 0)
                {
                    //HELPER VARIABLES
                    Character character;
                    KeyValuePair <string, uint> pair = ProcessingQueuee.Dequeue();

                    //CHECK IF THE USER IS ONLINE
                    if (LifeCycle.TryGetByName(pair.Key, out character))
                    {
                        Common.Internal.MailArrived(character, pair.Value);
                    }

                    //CLEARS THE PENDING MAIL
                    Singleton.Database.ClearPendingMails(pair.Key);
                    i++;
                    if (i > 10000)
                    {
                        break;
                    }
                }

                //REFRESHES THE MAILING QUEUEE
                if (Environment.TickCount - LastRefreshTick > 6000)
                {
                    ProcessingQueuee.Clear();
                    LastRefreshTick = Environment.TickCount;

                    foreach (KeyValuePair <string, uint> pair in Singleton.Database.GetPendingMails())
                    {
                        ProcessingQueuee.Enqueue(pair);
                    }
                }
            }
            catch (ThreadAbortException ex)
            {
                throw ex;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }