Пример #1
0
        public AutoHost(MetaDataCache cache, AhConfig config, int hostingPort, SpawnConfig spawn)
        {
            this.config      = config;
            Commands         = new CommandList(config);
            this.cache       = cache;
            SpawnConfig      = spawn;
            this.hostingPort = hostingPort;

            string version = config.SpringVersion ?? Program.main.Config.SpringVersion ?? tas.ServerSpringVersion; // tas empty at this point! Possible null exception

            springPaths = new SpringPaths(Program.main.paths.GetEngineFolderByVersion(version), writableFolderOverride: Program.main.Config.DataDir);

            Program.main.paths.SpringVersionChanged += (s, e) =>
            {
                if (!String.IsNullOrEmpty(requestedEngineChange) && requestedEngineChange == Program.main.paths.SpringVersion)
                {
                    config.SpringVersion = requestedEngineChange;
                    springPaths.SetEnginePath(Program.main.paths.GetEngineFolderByVersion(requestedEngineChange));
                    requestedEngineChange = null;

                    tas.Say(TasClient.SayPlace.Battle, "", "rehosting to engine version " + springPaths.SpringVersion, true);
                    ComRehost(TasSayEventArgs.Default, new string[] { });
                }
            };

            spring = new Spring(springPaths)
            {
                UseDedicatedServer = true
            };
            bool isManaged = SpawnConfig == null && config.Mode != AutohostMode.None;

            tas = new TasClient(null,
                                MainConfig.SpringieVersion,
                                isManaged ? GlobalConst.ZkSpringieManagedCpu : GlobalConst.ZkLobbyUserCpu,
                                false,
                                Program.main.Config.IpOverride);

            pollTimer           = new Timer(PollTimeout * 1000);
            pollTimer.Enabled   = false;
            pollTimer.AutoReset = false;
            pollTimer.Elapsed  += pollTimer_Elapsed;

            spring.SpringExited += spring_SpringExited;
            spring.GameOver     += spring_GameOver;

            spring.SpringExited  += spring_SpringExited;
            spring.SpringStarted += spring_SpringStarted;
            spring.PlayerSaid    += spring_PlayerSaid;
            spring.BattleStarted += spring_BattleStarted;

            tas.BattleUserLeft          += tas_BattleUserLeft;
            tas.UserStatusChanged       += tas_UserStatusChanged;
            tas.BattleUserStatusChanged += TasOnBattleUserStatusChanged;
            tas.BattleUserJoined        += tas_BattleUserJoined;
            tas.MyBattleMapChanged      += tas_MyBattleMapChanged;
            tas.BattleLockChanged       += tas_BattleLockChanged;
            tas.BattleOpened            += tas_BattleOpened;
            tas.UserAdded += (o, u) => { if (u.Data.Name == GetAccountName())
                                         {
                                             Start(null, null);
                                         }
            };

            tas.RegistrationDenied += (s, e) =>
            {
                ErrorHandling.HandleException(null, "Registration denied: " + e.ServerParams[0]);
                CloneNumber++;
                tas.Login(GetAccountName(), config.Password);
            };

            tas.RegistrationAccepted += (s, e) => tas.Login(GetAccountName(), config.Password);

            tas.AgreementRecieved += (s, e) =>
            {
                tas.AcceptAgreement();

                PlasmaShared.Utils.SafeThread(() =>
                {
                    Thread.Sleep(7000);
                    tas.Login(GetAccountName(), config.Password);
                }).Start();
            };

            tas.ConnectionLost  += tas_ConnectionLost;
            tas.Connected       += tas_Connected;
            tas.LoginDenied     += tas_LoginDenied;
            tas.LoginAccepted   += tas_LoginAccepted;
            tas.Said            += tas_Said;
            tas.MyBattleStarted += tas_MyStatusChangedToInGame;

            linkProvider = new ResourceLinkProvider(this);

            tas.Connect(Program.main.Config.ServerHost, Program.main.Config.ServerPort);

            Program.main.Downloader.PackagesChanged += Downloader_PackagesChanged;

            timer          = new Timer(15000);
            timer.Elapsed += (s, e) =>
            {
                try {
                    timer.Stop();
                    timerTick++;

                    // auto update engine branch
                    if (!String.IsNullOrEmpty(config.AutoUpdateSpringBranch) && timerTick % 4 == 0)
                    {
                        CheckEngineBranch();
                    }

                    // auto verify pw map
                    if (!spring.IsRunning && config.Mode != AutohostMode.None)
                    {
                        if (SpawnConfig == null && config.Mode == AutohostMode.Planetwars)
                        {
                            ServerVerifyMap(false);
                        }
                    }

                    // auto start split vote
                    if (!spring.IsRunning && config.SplitBiggerThan != null && tas.MyBattle != null && config.SplitBiggerThan < tas.MyBattle.NonSpectatorCount)
                    {
                        if (DateTime.Now.Subtract(spring.GameExited).TotalSeconds >= GameExitSplitDelay)
                        {
                            ComSplitPlayers(TasSayEventArgs.Default, new string[] {});
                        }

                        /*
                         * int cnt = tas.MyBattle.NonSpectatorCount;
                         * if (cnt > lastSplitPlayersCountCalled && cnt%2 == 0) {
                         *  StartVote(new VoteSplitPlayers(tas, spring, this), TasSayEventArgs.Default, new string[] { });
                         *  lastSplitPlayersCountCalled = cnt;
                         * }*/
                    }

                    // auto rehost to latest mod version
                    if (!string.IsNullOrEmpty(config.AutoUpdateRapidTag) && SpawnConfig == null)
                    {
                        UpdateRapidMod(config.AutoUpdateRapidTag);
                    }

                    if (lockedUntil != DateTime.MinValue && lockedUntil < DateTime.Now)
                    {
                        ComUnlock(TasSayEventArgs.Default, new string[] {});
                    }
                } catch (Exception ex) {
                    Trace.TraceError(ex.ToString());
                } finally {
                    timer.Start();
                }
            };
            timer.Start();
        }
Пример #2
0
        public AutoHost(MetaDataCache cache, AhConfig config, int hostingPort, SpawnConfig spawn) {
            this.config = config;
            Commands = new CommandList(config);
            this.cache = cache;
            SpawnConfig = spawn;
            this.hostingPort = hostingPort;

            
            string version = config.SpringVersion ?? Program.main.Config.SpringVersion ?? GlobalConst.DefaultEngineOverride;
            springPaths = new SpringPaths(Program.main.paths.GetEngineFolderByVersion(version), Program.main.Config.DataDir);
            
            springPaths.SpringVersionChanged += (s, e) =>
                {
                    if (!String.IsNullOrEmpty(requestedEngineChange) && requestedEngineChange == springPaths.SpringVersion) {
                        config.SpringVersion = requestedEngineChange;
                        springPaths.SetEnginePath(Program.main.paths.GetEngineFolderByVersion(requestedEngineChange));
                        requestedEngineChange = null;

                        tas.Say(SayPlace.Battle, "", "rehosting to engine version " + springPaths.SpringVersion, true);
                        ComRehost(TasSayEventArgs.Default, new string[] { });
                    }
                };

            spring = new Spring(springPaths) { UseDedicatedServer = true };
            bool isManaged = SpawnConfig == null && config.Mode != AutohostMode.None;

            tas = new TasClient(MainConfig.SpringieVersion,
                                isManaged ? Login.ClientTypes.SpringieManaged : Login.ClientTypes.Springie,
                                Program.main.Config.IpOverride);

            pollTimer = new Timer(PollTimeout*1000);
            pollTimer.Enabled = false;
            pollTimer.AutoReset = false;
            pollTimer.Elapsed += pollTimer_Elapsed;

            spring.SpringExited += spring_SpringExited;
            spring.GameOver += spring_GameOver;

            spring.SpringExited += spring_SpringExited;
            spring.SpringStarted += spring_SpringStarted;
            spring.PlayerSaid += spring_PlayerSaid;
            spring.BattleStarted += spring_BattleStarted;

            tas.BattleUserLeft += tas_BattleUserLeft;
            tas.UserStatusChanged += tas_UserStatusChanged;
            tas.BattleUserJoined += tas_BattleUserJoined;
            tas.MyBattleMapChanged += tas_MyBattleMapChanged;
            tas.BattleOpened += tas_BattleOpened;
            tas.UserAdded += (o, u) => { if (u.Name == GetAccountName()) OpenBattleRoom(null, null); };

            tas.RegistrationDenied += (s, e) =>
                {
                    Trace.TraceWarning("Registration denied: {0} {1}", e.ResultCode.Description(), e.Reason);
                    CloneNumber++;
                    tas.Login(GetAccountName(), config.Password);
                };

            tas.RegistrationAccepted += (s, e) => tas.Login(GetAccountName(), config.Password);

            tas.ConnectionLost += tas_ConnectionLost;
            tas.Connected += tas_Connected;
            tas.LoginDenied += tas_LoginDenied;
            tas.LoginAccepted += tas_LoginAccepted;
            tas.Said += tas_Said;
            tas.MyBattleStarted += tas_MyStatusChangedToInGame;

            linkSpringieClient = new ResourceLinkSpringieClient(this);

            // queue autohost
            if (config != null && config.MinToJuggle != null && SpawnConfig == null)
            {
                queue = new MatchMakerQueue(this);
            }

            
            Program.main.Downloader.PackagesChanged += Downloader_PackagesChanged;

            timer = new Timer(15000);
            timer.Elapsed += (s, e) =>
                {
                    try {
                        timer.Stop();
                        timerTick++;

                        // auto update engine branch
                        if (!String.IsNullOrEmpty(config.AutoUpdateSpringBranch) && timerTick%4 == 0) CheckEngineBranch();

                        // auto verify pw map
                        if (!spring.IsRunning && config.Mode != AutohostMode.None) if (SpawnConfig == null && config.Mode == AutohostMode.Planetwars) ServerVerifyMap(false);

                        // auto start split vote
                        if (!spring.IsRunning && config.SplitBiggerThan != null && tas.MyBattle != null && config.SplitBiggerThan < tas.MyBattle.NonSpectatorCount) {
                            if (DateTime.Now.Subtract(spring.GameExited).TotalSeconds >= GameExitSplitDelay) ComSplitPlayers(TasSayEventArgs.Default, new string[]{});
                            /*
                            int cnt = tas.MyBattle.NonSpectatorCount;
                            if (cnt > lastSplitPlayersCountCalled && cnt%2 == 0) {
                                StartVote(new VoteSplitPlayers(tas, spring, this), TasSayEventArgs.Default, new string[] { });
                                lastSplitPlayersCountCalled = cnt;
                            }*/
                        }

                        // auto rehost to latest mod version
                        if (!string.IsNullOrEmpty(config.AutoUpdateRapidTag) && SpawnConfig == null) UpdateRapidMod(config.AutoUpdateRapidTag);


                    } catch (Exception ex) {
                        Trace.TraceError(ex.ToString());
                    } finally {
                        timer.Start();
                    }
                };
            timer.Start();
           
        }
Пример #3
0
        public AutoHost(MetaDataCache cache, AhConfig config, int hostingPort, SpawnConfig spawn)
        {
            this.config      = config;
            Commands         = new CommandList(config);
            this.cache       = cache;
            SpawnConfig      = spawn;
            this.hostingPort = hostingPort;


            string version = config.SpringVersion ?? Program.main.Config.SpringVersion ?? GlobalConst.DefaultEngineOverride;

            springPaths = new SpringPaths(Program.main.paths.GetEngineFolderByVersion(version), Program.main.Config.DataDir);

            springPaths.SpringVersionChanged += (s, e) =>
            {
                if (!String.IsNullOrEmpty(requestedEngineChange) && requestedEngineChange == springPaths.SpringVersion)
                {
                    config.SpringVersion = requestedEngineChange;
                    springPaths.SetEnginePath(Program.main.paths.GetEngineFolderByVersion(requestedEngineChange));
                    requestedEngineChange = null;

                    tas.Say(SayPlace.Battle, "", "rehosting to engine version " + springPaths.SpringVersion, true);
                    ComRehost(TasSayEventArgs.Default, new string[] { });
                }
            };

            spring = new Spring(springPaths)
            {
                UseDedicatedServer = true
            };
            bool isManaged = SpawnConfig == null && config.Mode != AutohostMode.None;

            tas = new TasClient(MainConfig.SpringieVersion,
                                isManaged ? Login.ClientTypes.SpringieManaged : Login.ClientTypes.Springie,
                                Program.main.Config.IpOverride);

            pollTimer           = new Timer(PollTimeout * 1000);
            pollTimer.Enabled   = false;
            pollTimer.AutoReset = false;
            pollTimer.Elapsed  += pollTimer_Elapsed;

            spring.SpringExited += spring_SpringExited;
            spring.GameOver     += spring_GameOver;

            spring.SpringExited  += spring_SpringExited;
            spring.SpringStarted += spring_SpringStarted;
            spring.PlayerSaid    += spring_PlayerSaid;
            spring.BattleStarted += spring_BattleStarted;

            tas.BattleUserLeft     += tas_BattleUserLeft;
            tas.UserStatusChanged  += tas_UserStatusChanged;
            tas.BattleUserJoined   += tas_BattleUserJoined;
            tas.MyBattleMapChanged += tas_MyBattleMapChanged;
            tas.BattleOpened       += tas_BattleOpened;
            tas.UserAdded          += (o, u) => { if (u.Name == GetAccountName())
                                                  {
                                                      OpenBattleRoom(null, null);
                                                  }
            };

            tas.RegistrationDenied += (s, e) =>
            {
                Trace.TraceWarning("Registration denied: {0} {1}", e.ResultCode.Description(), e.Reason);
                CloneNumber++;
                tas.Login(GetAccountName(), config.Password);
            };

            tas.RegistrationAccepted += (s, e) => tas.Login(GetAccountName(), config.Password);

            tas.ConnectionLost  += tas_ConnectionLost;
            tas.Connected       += tas_Connected;
            tas.LoginDenied     += tas_LoginDenied;
            tas.LoginAccepted   += tas_LoginAccepted;
            tas.Said            += tas_Said;
            tas.MyBattleStarted += tas_MyStatusChangedToInGame;

            linkSpringieClient = new ResourceLinkSpringieClient(this);

            // queue autohost
            if (config != null && config.MinToJuggle != null && SpawnConfig == null)
            {
                queue = new MatchMakerQueue(this);
            }


            Program.main.Downloader.PackagesChanged += Downloader_PackagesChanged;

            timer          = new Timer(15000);
            timer.Elapsed += (s, e) =>
            {
                try {
                    timer.Stop();
                    timerTick++;

                    // auto update engine branch
                    if (!String.IsNullOrEmpty(config.AutoUpdateSpringBranch) && timerTick % 4 == 0)
                    {
                        CheckEngineBranch();
                    }

                    // auto verify pw map
                    if (!spring.IsRunning && config.Mode != AutohostMode.None)
                    {
                        if (SpawnConfig == null && config.Mode == AutohostMode.Planetwars)
                        {
                            ServerVerifyMap(false);
                        }
                    }

                    // auto start split vote
                    if (!spring.IsRunning && config.SplitBiggerThan != null && tas.MyBattle != null && config.SplitBiggerThan < tas.MyBattle.NonSpectatorCount)
                    {
                        if (DateTime.Now.Subtract(spring.GameExited).TotalSeconds >= GameExitSplitDelay)
                        {
                            ComSplitPlayers(TasSayEventArgs.Default, new string[] {});
                        }

                        /*
                         * int cnt = tas.MyBattle.NonSpectatorCount;
                         * if (cnt > lastSplitPlayersCountCalled && cnt%2 == 0) {
                         *  StartVote(new VoteSplitPlayers(tas, spring, this), TasSayEventArgs.Default, new string[] { });
                         *  lastSplitPlayersCountCalled = cnt;
                         * }*/
                    }

                    // auto rehost to latest mod version
                    if (!string.IsNullOrEmpty(config.AutoUpdateRapidTag) && SpawnConfig == null)
                    {
                        UpdateRapidMod(config.AutoUpdateRapidTag);
                    }
                } catch (Exception ex) {
                    Trace.TraceError(ex.ToString());
                } finally {
                    timer.Start();
                }
            };
            timer.Start();
        }