コード例 #1
0
        public async Task StartServer()
        {
            try {
                logService.Log("Starting the Game Server", type: LogType.Initialization);
                using (WebApp.Start(NetworkConstants.ServerUrl)) {
                    logService.Log($"Server running on {NetworkConstants.ServerUrl}", type: LogType.Initialization);

                    SetupStorages();

                    if (configurator.Config.AutoStart)
                    {
                        logService.Log($"Server is configured to auto start and it will start with ServerId from config file: {configurator.Config.ServerId}", type: LogType.Initialization);
                        serverStatus = GameServerStatus.ReadyToStart;
                    }
                    else
                    {
                        serverStatus = GameServerStatus.WaitingForStartRequest;
                        logService.Log($"Server is not configured to auto start. Waiting for the StartGameServer request", type: LogType.Initialization);
                        await WaitForStartRequest();
                    }

                    await StartGameServer(configurator.Config.ServerId);
                }
            }
            catch (Exception e) {
                logService.Log("Server General Exception");
                logService.Log(e.Message);
                throw;
            }
        }
コード例 #2
0
        private async Task StartGameServer(string serverId)
        {
            if (serverStatus == GameServerStatus.ReadyToStart)
            {
                try {
                    if (serverId.Equals(string.Empty))
                    {
                        logService.Log("ServerId is empty - using default server id: fake_server", type: LogType.Initialization);
                        serverId = "fake_server";
                    }

                    serverStatus = GameServerStatus.Initializing;
                    Task initTask = InitializeGameServer(serverId);
                    initTask.Wait();
                }
                catch (AggregateException agg) {
                    logService.Log("Error on initialization. Server is now faulted", type: LogType.Initialization, level: LogLevel.Error);

                    foreach (Exception e in agg.InnerExceptions)
                    {
                        logService.Log(e.Message);
                    }

                    serverStatus = GameServerStatus.Faulted;
                    await Task.Delay(Timeout.Infinite);
                }

                logService.Log("----------------------------", type: LogType.Initialization);
                logService.Log("------- SERVER_START -------", type: LogType.Initialization);
                logService.Log("----------------------------", type: LogType.Initialization);
                serverStatus = GameServerStatus.Started;
                gameLoopSimulator.StartSimulation();
            }
        }
コード例 #3
0
 public void StartServerRequest(string serverId)
 {
     logService.Log("Setting server status to Ready to start", type: LogType.Initialization);
     configurator.Config.ServerId = serverId;
     serverStatus = GameServerStatus.ReadyToStart;
 }