예제 #1
0
        private void AddServer(Server server)
        {
            var existingDServer = this.Servers.FirstOrDefault(s => s.Rcon.Il2ServerConfig.GameRootFolder == server.Rcon.Il2ServerConfig.GameRootFolder);

            if (existingDServer != null)
            {
                try {
                    var process = Process.GetProcessById((int)existingDServer.Process.Id);
                    //Previous DServer process didn't exit correctly
                    if (process != null)
                    {
                        process.Kill();
                        this.RemoveServer(existingDServer.Process.Id);
                        this.actionManager.RunServerStopScript(server);
                    }
                } catch (Exception ex) {
                    // -- ignore the error
                }
            }

            UI.Dispatch(() => {
                lock (this.lockDservers) {
                    this.Servers.Add(server);
                    this.actionManager.RunServerStartScripts(server);
                }
            });

            // -- set appropriate attributes: (taken out of the async block)

            server.ServerId = GuidUtility.Create(GuidUtility.IsoOidNamespace, server.Name);

            var appConfig = Settings.Default.Config;

            if (appConfig.IsMissionLogMonitorEnabled)
            {
                Log.WriteInfo("Starting MissionLogService for the server {0}", server.Name);
                server.MissionLogService.Start();
            }
            else
            {
                Log.WriteInfo("MissionLogService for the server {0} is NOT started! MissionLogMonitor is DISABLED in the application Settings.", server.Name);
            }

            if (appConfig.IsRConEnabled && this.IsRunning)
            {
                server.Rcon.Start();
            }


            /*
             * Task.Factory.StartNew((obj) => {
             *      if (!(obj is Server srv)) {
             *              return;
             *      }
             *
             *      srv.IsConfigSet = srv.Rcon.Il2ServerConfig.IsConfigReady;
             *      srv.AccountLogin();
             *      srv.IsRconConnected = true;
             * },  server, TaskCreationOptions.LongRunning);
             */
        }