Example #1
0
        private void loadCleanUp()
        {
            //load any extra stuff, announce any thing after every things has been loaded

            ml = new MainLoop("server");
            #region updatetimer
            ml.Queue(delegate
            {
                keepAliveTimer.Elapsed += delegate
                {
                    Player.players.ForEach(delegate(Player p) { p.SendKeepAlive(); });
                }; keepAliveTimer.Start();
            });
            ml.Queue(delegate
            {
                updateTimer.Elapsed += delegate
                {
                    Player.GlobalUpdate();
                }; updateTimer.Start();
            });
            ml.Queue(delegate
            {
                playerlisttimer.Elapsed += delegate
                {
                    Player.PlayerlistUpdate();
                }; playerlisttimer.Start();
            });
            ml.Queue(delegate
            {
                worldsavetimer.Elapsed += delegate
                {
                    World.worlds.ForEach(delegate(World w)
                    {
                        w.SaveLVL(true);
                    });
                }; worldsavetimer.Start();
            });
            ml.Queue(delegate
            {
                entityUpdateThread = new Thread(new ThreadStart(delegate
                {
                    int wait = 0, speed = 50;
                    while (!Server.s.shuttingDown)
                    {
                        try
                        {
                            if (wait > 0)
                            {
                                Thread.Sleep(wait);
                            }

                            DateTime Start = DateTime.Now;
                            Entity.EntityPhysics();
                            TimeSpan Took = DateTime.Now - Start;
                            wait          = speed - (int)Took.TotalMilliseconds;
                        }
                        catch { wait = speed; }
                    }
                })); entityUpdateThread.Start();
            });
            ml.Queue(delegate
            {
                devupdatetimer.Elapsed += delegate
                {
                    UpdateDevs();
                }; devupdatetimer.Start();
            });
            ml.Queue(delegate
            {
                World.chunker.Start();
            });
            #endregion
            //TODO AI Update Timer

            //Setup();

            //new Creeper(new Point3(0, 72, 0), mainlevel);


            Logger.Log("Setting up on port: " + port);
            Logger.Log("Server Started");
        }