示例#1
0
        private void Reboot()
        {
            if (_rebooting)
            {
                return;
            }

            _rebooting = true;

            WorldTimer tmr = null;
            var        s   = 30;
            Func <World, RealmTime, bool> rebootTick = (w, t) =>
            {
                s -= 1;

                if (s == 15)
                {
                    _manager.Chat.Announce("Server rebooting in 15 seconds...", true);
                }
                else if (s == 5)
                {
                    _manager.Chat.Announce("Server rebooting in 5 seconds...", true);
                }
                else if (s == 0)
                {
                    // this could help avoid unfinished transactions when rebooting
                    foreach (var world in _manager.Worlds.Values)
                    {
                        world.Closed = true;
                        foreach (var p in world.Players.Values)
                        {
                            p.Client?.Disconnect();
                        }
                    }
                    Program.Stop();
                    return(true);
                }


                tmr.Reset();
                return(false);
            };

            tmr = new WorldTimer(1000, rebootTick);
            _manager.Chat.Announce("Server rebooting in 30 seconds...", true);
            _manager.GetWorld(World.Realm).Timers.Add(tmr);
        }
示例#2
0
        public void UpdateGuildHall()
        {
            WorldTimer ghallTimer = null;

            UpgradeInProgress = true;
            GuildHall.Timers.Add(ghallTimer = new WorldTimer(60 * 1000, (w, t) =>
            {
                if (w.Players.Count > 0)
                {
                    ghallTimer.Reset();
                    GuildHall.Manager.Logic.AddPendingAction(_ => w.Timers.Add(ghallTimer), PendingPriority.Creation);
                }
                else
                {
                    RealmManager manager = GuildHall.Manager;
                    GuildHall.Manager.RemoveWorld(GuildHall);
                    GuildHall         = manager.AddWorld(new GuildHall(Name));
                    UpgradeInProgress = false;
                }
            }));
        }
示例#3
0
        public virtual void Tick(RealmTime time)
        {
            if (dungeon)
            {
                if (Players.Count < 1 && !DisposingWorld)
                {
                    DisposingWorld = true;
                    log.InfoFormat("World {0}, ID:{1} has no players and is beginning the removal countdown of {2}MS.", Name, Id, WorldDisposeMS);
                    WorldTimer timer = new WorldTimer(WorldDisposeMS, (w, t) =>
                    {
                        RemoveFromTimer(w);
                    });
                    Timers.Add(timer);
                }
                else if (DisposingWorld && Players.Count > 0)
                {
                    DisposingWorld = false;
                    log.InfoFormat("World {0}, ID:{1} has cancelled removal.", Name, Id);
                }
            }

            try
            {
                if (IsLimbo)
                {
                    return;
                }

                if (Timers != null)
                {
                    for (int i = 0; i < Timers.Count; i++)
                    {
                        if (Timers[i].Tick(this, time) && Timers.Count > 0)
                        {
                            Timers.RemoveAt(i);
                            i--;
                        }
                    }
                }

                foreach (var i in Players)
                {
                    i.Value.Tick(time);
                }

                //if (EnemiesCollision != null)
                //{
                //    foreach (Entity i in EnemiesCollision.GetActiveChunks(PlayersCollision))
                //        i.Tick(time);
                //    foreach (var i in StaticObjects.Where(x => x.Value is Decoy))
                //        i.Value.Tick(time);
                //}
                //else
                //{
                //    foreach (var i in Enemies)
                //        i.Value.Tick(time);
                //    foreach (var i in StaticObjects)
                //        i.Value.Tick(time);
                //}
                foreach (var i in Projectiles)
                {
                    i.Value.Tick(time);
                }
            }
            catch (Exception e)
            {
                log.Error(e);
            }
        }
示例#4
0
        public virtual void Tick(RealmTime time)
        {
            if (IsLimbo)
            {
                return;
            }

            if (disposable)
            {
                if (Players.Count <= 0 && !isDisposing)
                {
                    isDisposing = true;
                    if (RemovalMS < 25000)
                    {
                        //    log.WarnFormat("World \"{0}\" does not have a valid RemovalMS: {1}! Please allow at least 25 seconds. Default: 25000 ms", Name, RemovalMS);
                        RemovalMS = 25000;
                    }
                    //  log.InfoFormat("World {0}, ID:{1} is unused and will dispose in {2}MS.", Name, Id, RemovalMS);
                    WorldTimer timer = new WorldTimer(RemovalMS, (w, t) =>
                    {
                        manager.RemoveWorld(w);
                    });
                    Timers.Add(timer);
                }
                else if (isDisposing && Players.Count >= 1)
                {
                    isDisposing = false;
                    //      log.InfoFormat("World {0}, ID:{1} is in use and has cancelled disposal.", Name, Id);
                }
            }

            if (Timers != null && Timers.Count > 0)
            {
                for (int i = 0; i < Timers.Count; i++)
                {
                    if (Timers[i].Tick(this, time) && Timers.Count > 0)
                    {
                        Timers.RemoveAt(i);
                        i--;
                    }
                }
            }

            try //entity ticking now, possible huge range of issues that i can't yet remove the try catch - jade
            {
                foreach (var i in Players)
                {
                    i.Value.Tick(time);
                }

                if (isDisposing)
                {
                    return;
                }

                if (EnemiesCollision != null)
                {
                    foreach (Entity i in EnemiesCollision.GetActiveChunks(PlayersCollision))
                    {
                        i.Tick(time);
                    }
                    foreach (var i in StaticObjects.Where(x => x.Value is Decoy))
                    {
                        i.Value.Tick(time);
                    }
                }
                else
                {
                    foreach (var i in Enemies)
                    {
                        i.Value.Tick(time);
                    }
                    foreach (var i in StaticObjects)
                    {
                        i.Value.Tick(time);
                    }
                }
                foreach (var i in Projectiles)
                {
                    i.Value.Tick(time);
                }
            }
            catch (Exception e)
            {
                log.Error(e);
            }
        }