public AutoHost SpawnAutoHost(AhConfig config, SpawnConfig spawnData) { AutoHost ah; lock (autoHosts) { ah = new AutoHost(MetaCache, config, GetFreeHostingPort(), spawnData); autoHosts.Add(ah); } return ah; }
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(); }
public CommandList(AhConfig config) { AddMissing(new CommandConfig("help", 0, " - lists all commands available specifically to you", 5) { AllowSpecs = true}); AddMissing(new CommandConfig("random", 1, "<allycount> - assigns people to <allycount> random alliances, e.g. !random - makes 2 random alliances", 10)); AddMissing(new CommandConfig("balance", 1, "<allycount> - assigns people to <allycount> rank balanced alliances, e.g. !balance - makes 2 random but balanced alliances", 10)); AddMissing(new CommandConfig("start", 1, " - starts game", 5)); AddMissing(new CommandConfig("ring", 1, "[<filters>..] - rings all unready or specific player(s), e.g. !ring - rings unready, !ring icho - rings Licho", 5, new[] { SayPlace.User, SayPlace.Battle, SayPlace.Game }) { AllowSpecs = true}); AddMissing(new CommandConfig("listmaps", 1, "[<filters>..] - lists maps on server, e.g. !listmaps altor div", 10)); AddMissing(new CommandConfig("listmods", 1, "[<filters>..] - lists games on server, e.g. !listmods absolute 2.23", 5)); AddMissing(new CommandConfig("map", 3, "[<filters>..] - changes server map, eg. !map altor div")); AddMissing(new CommandConfig("mapremote", 0, "[<filters>..] - changes server map, eg. !map altor div")); // see https://github.com/ZeroK-RTS/Zero-K-Infrastructure/issues/756 AddMissing(new CommandConfig("forcestart", 3, " - starts game forcibly (ignoring warnings)", 5)); AddMissing(new CommandConfig("say", 3, "<text> - says something in game", 0, new[] { SayPlace.User, SayPlace.Battle, SayPlace.Game })); AddMissing(new CommandConfig("force", 3, " - forces game start inside game", 8, new[] { SayPlace.User, SayPlace.Battle, SayPlace.Game })); AddMissing(new CommandConfig("kick", 3, "[<filters>..] - kicks a player", 0, new[] { SayPlace.User, SayPlace.Battle, SayPlace.Game })); AddMissing(new CommandConfig("split", 1, "<\"h\"/\"v\"> <percent> - draws with given direction and percentual size, e.g. !split h 15")); AddMissing(new CommandConfig("transmit", 0, "Internal command transfer to ingame") { AllowSpecs = true}); AddMissing(new CommandConfig("corners", 1, "<\"a\"/\"b\"> <percent> - draws corners (a or b mode differ in ordering), e.g. !corners a 15")); AddMissing(new CommandConfig("exit", 3, " - exits the game", 0, new[] { SayPlace.User, SayPlace.Battle, SayPlace.Game })); AddMissing(new CommandConfig("votemap", 1, "[<mapname>..] - starts vote for new map, e.g. !votemap altored div")); AddMissing(new CommandConfig("votekick", 2, "[<playerame>..] - starts vote to kick a player, e.g. !votekick Licho", 0, new[] { SayPlace.User, SayPlace.Battle, SayPlace.Game })); AddMissing(new CommandConfig("votespec", 2, "[<playername>..] - starts vote to spectate player, e.g. !votespec Licho", 0, new[] { SayPlace.User, SayPlace.Battle, SayPlace.Game })); AddMissing(new CommandConfig("votesplitplayers", 2, "- starts vote to split the game into 2", 0, new[] { SayPlace.User, SayPlace.Battle, SayPlace.Game }) { AllowSpecs = true}); AddMissing(new CommandConfig("voteforcestart", 2, " - starts vote to force game to start in lobby")); AddMissing(new CommandConfig("voteforce", 2, " - starts vote to force game to start from game", 0, new[] { SayPlace.User, SayPlace.Battle, SayPlace.Game })); AddMissing(new CommandConfig("voteexit", 2, " - starts vote to exit game", 0, new[] { SayPlace.User, SayPlace.Battle, SayPlace.Game })); AddMissing(new CommandConfig("voteresign", 0, " - starts a vote to resign game", 0, new[] { SayPlace.User, SayPlace.Battle, SayPlace.Game })); AddMissing(new CommandConfig("vote", 0, "<number> - votes for given option (works from battle only), e.g. !vote 1", 0, new[] { SayPlace.Battle, SayPlace.Game })); AddMissing(new CommandConfig("y", 0, "- votes for given option 1 (works from battle only), e.g. !y; !vote 1", 0, new[] { SayPlace.Battle, SayPlace.Game })); AddMissing(new CommandConfig("n", 0, "- votes for given option 2 (works from battle only), e.g. !n; !vote 2", 0, new[] { SayPlace.Battle, SayPlace.Game })); AddMissing(new CommandConfig("rehost", 3, "[<modname>..] - rehosts game, e.g. !rehost abosol 2.23 - rehosts AA2.23")); AddMissing(new CommandConfig("updaterapidmod", 3, "[<tag>..] - force update host to mod with specified rapid tag")); AddMissing(new CommandConfig("maplink", 0, "[<mapname>..] - looks for maplinks at unknown-files", 5, new[] { SayPlace.Battle, SayPlace.User })); AddMissing(new CommandConfig("modlink", 0, "[<modname>..] - looks for modlinks at unknown-files", 5, new[] { SayPlace.Battle, SayPlace.User })); AddMissing(new CommandConfig("team", 3, "<teamnumber> [<playername>..] - forces given player to a team")); AddMissing(new CommandConfig("adduser", 0, "<pw> - technical command used for mid-game spectator join", 0, new[] { SayPlace.Battle, SayPlace.User }) { AllowSpecs = true}); AddMissing(new CommandConfig("helpall", 0, "- lists all commands known to Springie (sorted by command level)", 5) { AllowSpecs = true}); AddMissing(new CommandConfig("setengine", 3, "[version] - sets a new spring version", 2)); AddMissing(new CommandConfig("springie", 0, "- responds with basic springie information", 5, new[] { SayPlace.User, SayPlace.Battle, SayPlace.Channel }) { AllowSpecs = true}); AddMissing(new CommandConfig("endvote", 1, "- ends current poll")); AddMissing(new CommandConfig("addbox", 1, "<left> <top> <width> <height> [<number>] - adds a new box rectangle")); AddMissing(new CommandConfig("clearbox", 1, "[<number>] - removes a box (or removes all boxes if number not specified)")); AddMissing(new CommandConfig("listoptions", 1, " - lists all mod/map options", 5)); AddMissing(new CommandConfig("setoptions", 3, "<name>=<value>[,<name>=<value>] - applies mod/map options", 0)); AddMissing(new CommandConfig("votesetoptions", 1, "<name>=<value>[,<name>=<value>] - starts a vote to apply mod/map options", 0)); AddMissing(new CommandConfig("resetoptions", 3, " - sets default mod/map options", 0)); AddMissing(new CommandConfig("voteresetoptions", 1, " - starts a vote to set default mod/map options", 0)); AddMissing(new CommandConfig("cbalance", 1, "[<allycount>] - assigns people to allycount random balanced alliances but attempts to put clanmates to same teams", 10)); AddMissing(new CommandConfig("spawn", -2, "<configs> - creates new autohost. Example: !spawn mod=ca:stable,title=My PWN game,password=secret. The following parameters can be specified: map, mod, title, password, maxplayers, owner, handle, mode. Possible values for mode: 0 - none, 3 - 1v1, 4 - FFA, 5 - coop, 6 - teams, 10 - serious.", 0) { AllowSpecs = true}); AddMissing(new CommandConfig("setpassword", 3, "<newpassword> - sets server password (needs !rehost to apply)")); AddMissing(new CommandConfig("setmaxplayers", 3, "<maxplayers> - sets server size (needs !rehost to apply)")); AddMissing(new CommandConfig("setgametitle", 3, "<new title> - sets server game title (needs !rehost to apply)")); AddMissing(new CommandConfig("boss", 3, "<name> - sets <name> as a new boss, use w5ithout parameter to remove any current boss. If there is a boss on server, other non-admin people have their rights reduced")); AddMissing(new CommandConfig("spec", 3, "<username> - forces player to become spectator", 0)); AddMissing(new CommandConfig("predict", 0, "predicts chances of victory", 0) { AllowSpecs = true}); AddMissing(new CommandConfig("specafk", 2, "forces all AFK player to become spectators", 0)); AddMissing(new CommandConfig("cheats", 3, "enables/disables .cheats in game", 0, new[] { SayPlace.User, SayPlace.Battle, SayPlace.Game })); AddMissing(new CommandConfig("hostsay", 3, "says something as host, useful for /nocost etc", 0, new[] { SayPlace.User, SayPlace.Battle, SayPlace.Game })); AddMissing(new CommandConfig("notify", 0, "springie notifies you when game ends", 0, new[] { SayPlace.User, SayPlace.Battle, SayPlace.Game, //SayPlace.Channel // this does silly stuff with !notify in #zk }) { AllowSpecs = true}); AddMissing(new CommandConfig("saveboxes", 4, "- saves boxes for current map")); AddMissing(new CommandConfig("move", 4, "<where> - moves players to a new host")); AddMissing(new CommandConfig("votemove", 2, "<where> - moves players to a new host") { AllowSpecs = true}); if (config != null && config.CommandLevels != null) { foreach (var c in config.CommandLevels) { var entry = Commands.FirstOrDefault(x => x.Name == c.Command); if (entry != null) entry.Level = c.Level; } } }
public AutoHost SpawnAutoHost(AhConfig config, SpawnConfig spawnData) { AutoHost ah; lock (autoHosts) { ah = new AutoHost(MetaCache, config, GetFreeHostingPort(), spawnData); var otherClone = autoHosts.Where(x => x.config.Login == config.Login).Max(x => (int?)x.CloneNumber); if (otherClone.HasValue) ah.CloneNumber = otherClone.Value + 1; autoHosts.Add(ah); } return ah; }