CEngineSharp_Server.GameLogic.ServerLoop.Start C# (CSharp) Method

Start() public method

public Start ( ) : void
return void
        public void Start()
        {
            long lastConsoleTitleUpdateTime = 0;
            long lastCpsCheck = 0;
            int cps = 0;
            int cpsCount = 0;

            // Continue processing the server-logic until it's time to shut things down.
            while (!Server.ShuttingDown)
            {
                if (lastConsoleTitleUpdateTime <= GameTime.GetTotalTimeElapsed())
                {
                    var serverWindowTitle = ServerConfiguration.GameName + " - " + ServerConfiguration.ServerIP + ":" +
                                               ServerConfiguration.ServerPort + " - Player Count: " +
                                               ContentManager.Instance.PlayerManager.PlayerCount + " - Debug Mode: " +
                                               (ServerConfiguration.SupressionLevel == ErrorHandler.ErrorLevels.Debug
                                                   ? "On"
                                                   : "Off") + " - Cps: " + cps + "/sec";

                    Console.Title = serverWindowTitle;

                    lastConsoleTitleUpdateTime = GameTime.GetTotalTimeElapsed() + 500;
                }

                NetServiceLocator.Singleton.GetService().Update();

                if (lastCpsCheck <= GameTime.GetTotalTimeElapsed())
                {
                    cps = cpsCount;
                    cpsCount = 0;
                    lastCpsCheck = GameTime.GetTotalTimeElapsed() + 1000;
                }
                else
                    cpsCount++;
            }

            // Save the game world.
            ContentManager.Instance.PlayerManager.SavePlayers();
            // Terminate the server.
            Environment.Exit(0);
        }

Usage Example

Example #1
0
        private static void Main(string[] args)
        {
            NetServiceLocator.Singleton.SetService(new Networking.NetManager());

            ServerConfiguration.LoadConfig();
            ContentManager.Instance.LoadContent();
            NetServiceLocator.Singleton.GetService().Start();
            var serverLoop = new ServerLoop();
            serverLoop.Start();
        }