Ejemplo n.º 1
0
        public static TCPStatus getTCPStatus()
        {
            if (status == null)
            {
                status = new TCPStatus();
                status.start();
            }

            return(status);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            initFolders();
            loadServerConfig();
            initClientModule();

            TCPStatus.getTCPStatus();
            TCPStatus.getTCPStatus().addInfo("servername", serverOptions.ServerName);
            TCPStatus.getTCPStatus().addInfo("serverlanguage", "");
            TCPStatus.getTCPStatus().addInfo("maxslots", "" + serverOptions.Slots);

            try
            {
                server = new Network.Server();
                server.Start((ushort)serverOptions.Port, (ushort)serverOptions.Slots, serverOptions.password);
                //ModuleLoader.loadAllModules();

                scriptManager = new Scripting.ScriptManager();
                scriptManager.Init();
                scriptManager.Startup();
                long lastInfoUpdates = 0;

                long startUpdate      = 0;
                int  updatesPerSecond = 100;
                while (true)
                {
                    long ticks = DateTime.Now.Ticks;
                    startUpdate = ticks;
                    Player.sUpdateNPCList(ticks);

                    if (lastInfoUpdates < ticks)
                    {
                        TCPStatus.getTCPStatus().addInfo("players", "" + sWorld.PlayerList.Count);

                        lastInfoUpdates = ticks + 10000 * 1000 * 5;
                    }


                    //ModuleLoader.updateAllModules();
                    scriptManager.Update();
                    server.Update();
                    updateNPCController(ticks);

                    //limit update intervals
                    float elapsedTimeMs   = (DateTime.Now.Ticks - startUpdate) / TimeSpan.TicksPerMillisecond;
                    float timePerUpdateMs = 1000 / updatesPerSecond;
                    if (elapsedTimeMs < timePerUpdateMs)
                    {
                        int restMs = (int)(timePerUpdateMs - elapsedTimeMs);
                        if (restMs > 0)
                        {
                            Thread.Sleep(restMs);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Log.Logger.log(Log.Logger.LOG_ERROR, ex.Message);
                Log.Logger.log(Log.Logger.LOG_ERROR, ex.Source);
                Log.Logger.log(Log.Logger.LOG_ERROR, ex.StackTrace);
            }
            Console.Read();
        }