public void ComBan(TasSayEventArgs e, string[] words) { if (words.Length == 0) { ah.Respond(e, "this command needs at least 1 argument - exact user name"); return; } int duration = 0; if (words.Length > 1) { if (!int.TryParse(words[1], out duration)) { ah.Respond(e, "second argument must be a number - ban time in minutes or 0 - forever"); return; } } if (IsBanned(words[0])) { ah.Respond(e, "this user is already banned"); return; } if (duration < 0) { duration = 0; } TimeSpan dur; if (duration == 0) { dur = TimeSpan.FromDays(365 * 1000); } else { dur = TimeSpan.FromMinutes(duration); } var b = new BannedUser(words[0]); b.Duration = dur; b.Reason = Utils.Glue(words, 2); var battle = tas.GetBattle(); UserBattleStatus ubs; if (battle.ContainsUser(b.Name, out ubs)) { if (ubs.ip != IPAddress.None) { b.ipAddresses.Add(ubs.ip.ToString()); } } Items.Add(b); tas.Say(TasClient.SayPlace.Battle, "", b.Name + " banned - " + b.Reason, true); tas.Kick(b.Name); Save(); }
public AbstractPoll(TasClient tas, Spring spring, AutoHost ah) { this.tas = tas; this.spring = spring; this.ah = ah; initialUserCount = 0; Battle b = tas.GetBattle(); if (b != null) { foreach (UserBattleStatus us in b.Users) { if (us.name != tas.UserName) { users.Add(us.name); votes.Add(0); if (!us.IsSpectator) { initialUserCount++; } } } } }
public void Apply(TasClient tas, Ladder ladder) { var b = tas.GetBattle(); if (b == null) { return; } var d = b.Details; int mint, maxt; if (ladder != null) { d = ladder.CheckBattleDetails(d, out mint, out maxt); } tas.UpdateBattleDetails(d); if (enableAllUnits) { tas.EnableAllUnits(); } if (disabledUnits.Length > 0) { tas.DisableUnits(UnitInfo.ToStringList(disabledUnits)); } foreach (var s in perform) { tas.Say(TasClient.SayPlace.Battle, "", s, false); } }
public VotePlanet(TasClient tas, Spring spring, AutoHost ah) : base(tas, spring, ah) { this.tas = tas; this.spring = spring; this.ah = ah; var pw = Program.main.PlanetWars; var fact = pw.GetOffensiveFaction(); faction = fact.Name; users.Clear(); votes.Clear(); initialUserCount = 0; var b = tas.GetBattle(); if (b != null) { foreach (var us in b.Users) { if (us.name != tas.UserName && !us.IsSpectator && pw.GetPlayerInfo(us.name).FactionName == faction) { users.Add(us.name); votes.Add(0); initialUserCount++; } } } }
public void Apply(TasClient tas) { Battle b = tas.GetBattle(); if (b == null) { return; } BattleDetails d = b.Details; if (startingMetal.HasValue) { d.StartingMetal = startingMetal.Value; } if (startingEnergy.HasValue) { d.StartingEnergy = startingEnergy.Value; } if (maxUnits.HasValue) { d.MaxUnits = maxUnits.Value; } if (startPos.HasValue) { d.StartPos = startPos.Value; } if (endCondition.HasValue) { d.EndCondition = endCondition.Value; } if (limitDgun.HasValue) { d.LimitDgun = limitDgun.Value; } if (diminishingMM.HasValue) { d.DiminishingMM = diminishingMM.Value; } if (ghostedBuildings.HasValue) { d.GhostedBuildings = ghostedBuildings.Value; } d.Validate(); tas.UpdateBattleDetails(d); if (enableAllUnits) { tas.EnableAllUnits(); } if (disabledUnits.Length > 0) { tas.DisableUnits(UnitInfo.ToStringList(disabledUnits)); } }
internal static int FilterUsers(string[] words, TasClient tas, Spring spring, out string[] vals, out int[] indexes) { TasClient.Battle b = tas.GetBattle(); string[] temp = new string[b.Users.Count]; int i = 0; foreach (TasClient.UserBattleStatus u in b.Users) { temp[i++] = u.name; } return(Filter(temp, words, out vals, out indexes)); }
public bool IsBanned(string name, out BannedUser b) { Battle bat = tas.GetBattle(); if (GetByName(name, out b)) { return(true); } if (bat != null) { UserBattleStatus ubs; if (bat.ContainsUser(name, out ubs)) { string ip = ubs.ip.ToString(); if (GetByIp(ip, out b)) { return(true); } } } return(false); }
protected void KickUnsynced(TasClient tas) { for (int i = 0; i < users.Count; ++i) { UserBattleStatus u; if (tas.IsConnected && tas.GetBattle().ContainsUser(users[i], out u)) { if (u.SyncStatus == SyncStatuses.Unknown && (DateTime.Now - times[i]) > TimeSpan.FromSeconds(timeout)) { tas.Kick(users[i]); } } } }
public void FindLinks(string[] words, FileType type, TasClient tas, TasSayEventArgs e) { if (words.Length == 0) { var b = tas.GetBattle(); if (b == null) { return; } Program.main.AutoHost.Respond(e, string.Format("Getting SpringDownloader mirrors for currently hosted {0}", type)); if (type == FileType.Map) { RequestLink(new LinkRequest(b.Map.Checksum, e)); } else { RequestLink(new LinkRequest(b.Mod.Checksum, e)); } } else { List <string> items; if (type == FileType.Map) { items = new List <string>(Program.main.Spring.UnitSyncWrapper.MapList.Keys); } else { items = new List <string>(Program.main.Spring.UnitSyncWrapper.ModList.Keys); } int[] resultIndexes; string[] resultVals; int cnt = AutoHost.Filter(items.ToArray(), words, out resultVals, out resultIndexes); if (cnt == 0) { Program.main.AutoHost.Respond(e, string.Format("No such {0} found", type)); } Program.main.AutoHost.Respond(e, string.Format("Getting SpringDownloader mirrors for {0}, please wait", resultVals[0])); int hash = type == FileType.Map ? Program.main.Spring.UnitSyncWrapper.MapList[resultVals[0]].Checksum : Program.main.Spring.UnitSyncWrapper.ModList[resultVals[0]].Checksum; RequestLink(new LinkRequest(hash, e)); } }
protected bool RegisterVote(TasSayEventArgs e, string[] words, out int vote) { vote = 0; if (hackEndTimeVote) { return(true); } if (words.Length != 1) { return(false); } int.TryParse(words[0], out vote); if (vote > 0 && vote <= options) { // vote within parameters, lets register it lastVote = vote; int ind = users.IndexOf(e.UserName); Battle b = tas.GetBattle(); if (b != null) { int bidx = b.GetUserIndex(e.UserName); if (bidx > -1) { if (b.Users[bidx].IsSpectator) { return(false); } } if (ind == -1) { votes.Add(vote); users.Add(e.UserName); } else { votes[ind] = vote; } return(true); } } return(false); }
private void UpdateCa() { if (Program.main.config.CaUpdating == MainConfig.CaUpdateMode.None) { return; } var b = tas.GetBattle(); if (b != null) { spring.Reload(true, false); string selMod = b.Mod.Name; int vers = int.MinValue; foreach (var s in spring.UnitSync.ModList.Keys) { if (s.Contains("Complete Annihilation")) { if ((Program.main.config.CaUpdating == MainConfig.CaUpdateMode.Stable && s.Contains("stable")) || Program.main.config.CaUpdating == MainConfig.CaUpdateMode.Latest) { int nv = ExtractVersionNumber(s); if (nv > vers) { vers = nv; selMod = s; } } } } if (b.Mod.Name != selMod) { tas.Say(TasClient.SayPlace.Battle, "", "Springie is now rehosting to new version of CA - " + selMod, true); Program.main.AutoHost.ComRehost(TasSayEventArgs.Default, new[] { selMod }); } } }
private void tas_MyStatusChangedToInGame(object sender, TasEventArgs e) { spring.StartGame(tas.GetBattle()); }
public void ComPlanet(TasSayEventArgs e, string[] words) { if (words.Length == 0) { autoHost.Respond(e, "You must specify planet name"); return; } string[] vals; int[] indexes; if (FilterPlanets(words, out vals, out indexes) > 0) { var info = server.GetPlayerInfo(account, e.UserName); var fact = server.GetOffensiveFaction(account); bool canset = false; string bestPlayer = ""; if (info != null) { if (info.IsCommanderInChief) { canset = true; } else { canset = true; int bestRank = info.RankOrder; foreach (var u in tas.GetBattle().Users) { if (!u.IsSpectator && u.name != e.UserName && tas.GetBattle().Mod.Sides[u.Side].ToLower() == info.FactionName.ToLower()) { var pi = server.GetPlayerInfo(account, u.name); if (pi != null && pi.RankOrder < bestRank) { // someone sle with better rank exists bestPlayer = pi.Name; bestRank = pi.RankOrder; canset = false; } } } } } if (canset) { if (info.FactionName == fact.Name) { string pname = vals[0].Split('|')[0]; autoHost.SayBattle(string.Format("changing planet to {0} by {1}", pname, e.UserName)); var planet = server.GetAttackOptions(account).Where(m => m.Name == pname).Single(); tas.ChangeMap(Program.main.Spring.UnitSyncWrapper.MapList[planet.MapName]); } else { autoHost.Respond(e, string.Format("It's currently {0} turn", fact.Name)); } } else { autoHost.Respond(e, string.Format("You are not first in command here, {0} must do it!", bestPlayer)); } } else { autoHost.Respond(e, "Cannot find such planet."); } }
void tas_BattleLockChanged(object sender, TasEventArgs e) { tas.Say(TasClient.SayPlace.Battle, "", "game " + (tas.GetBattle().IsLocked ? "locked" : "unlocked"), true); }
private void timer_Elapsed(object sender, ElapsedEventArgs e) { lock (timer) { timer.Stop(); try { if (from > 0 && !spring.IsRunning) { var b = tas.GetBattle(); if (b != null) { int plrCnt = b.CountPlayers(); if (plrCnt >= from) { List <string> notReady; if (!ah.AllUniqueTeams(out notReady)) { ah.ComFix(TasSayEventArgs.Default, new string[] {}); return; } bool isReady = ah.AllReadyAndSynced(out notReady); if (plrCnt % 2 == 0) { int allyno; if (!ah.BalancedTeams(out allyno)) { //teams are not balanced but even number - fix colors and balance ah.ComFixColors(TasSayEventArgs.Default, new string[] {}); ah.BalanceTeams(2, false); } } if (isReady) { Thread.Sleep(1000); if (!spring.IsRunning) { ah.ComStart(TasSayEventArgs.Default, new string[] {}); } } else { var now = DateTime.Now; // we have enough people, but its odd number and server locked = unlock for more if (plrCnt > from && plrCnt % 2 == 1 && b.IsLocked) { ah.ComAutoLock(TasSayEventArgs.Default, new[] { (plrCnt + 1).ToString() }); } if (plrCnt % 2 == 0) { // even number of players if (now.Subtract(lastRing).TotalSeconds > RingEvery) { // we ring them lastRing = now; ah.ComRing(TasSayEventArgs.Default, new string[] {}); } var worstTime = DateTime.MaxValue; String worstName = ""; foreach (var s in notReady) { // find longest offending player if (!problemSince.ContainsKey(s)) { problemSince[s] = DateTime.Now; } if (problemSince[s] < worstTime) { worstTime = problemSince[s]; worstName = s; } } foreach (var s in new List <string>(problemSince.Keys)) { // delete not offending plaeyrs if (!notReady.Contains(s)) { problemSince.Remove(s); } } if (now.Subtract(worstTime).TotalSeconds > SpecForceAfter) { ah.ComForceSpectator(TasSayEventArgs.Default, new[] { worstName }); // spec longest offending person } if (now.Subtract(worstTime).TotalSeconds > KickAfter) { ah.ComKick(TasSayEventArgs.Default, new[] { worstName }); // kick longest offending } } else { // teams are not even delet offender list problemSince.Clear(); } } } else { // not enough players, make sure we unlock and clear offenders if (b.IsLocked && plrCnt < from) { ah.ComAutoLock(TasSayEventArgs.Default, new[] { to.ToString() }); } problemSince.Clear(); } } } else { // spring running, reset timer and delete offenders lastRing = DateTime.Now; problemSince.Clear(); } } finally { timer.Start(); } } }
private void CheckForBattleExit() { if ((DateTime.Now - spring.GameStarted) > TimeSpan.FromSeconds(20)) { if (spring.IsRunning) { var b = tas.GetBattle(); int count = 0; foreach (var p in b.Users) { if (p.IsSpectator) { continue; } User u; if (!tas.GetExistingUser(p.name, out u)) { continue; } if (u.isInGame) { count++; } } if (count < 1) { SayBattle("closing game, " + count + " active player left in game"); spring.ExitGame(); } } // kontrola pro pripad ze by se nevypl spring User us; if (!spring.IsRunning && tas.GetExistingUser(tas.UserName, out us) && us.isInGame) { tas.ChangeMyStatus(false, false); } } }
private void timer_Elapsed(object sender, ElapsedEventArgs e) { lock (timer) { timer.Stop(); try { if (from > 0 && !spring.IsRunning) { Battle b = tas.GetBattle(); if (b != null) { int plrCnt = b.CountPlayers(); if (plrCnt >= from && plrCnt <= to) { string notReady; bool isReady = ah.AllReadyAndSynced(out notReady); if (plrCnt % 2 == 0) { int allyno; if (!ah.BalancedTeams(out allyno)) { ah.ComFix(TasSayEventArgs.Default, new string[] {}); ah.ComFixColors(TasSayEventArgs.Default, new string[] {}); ah.BalanceTeams(2, false); } } if (isReady) { Thread.Sleep(1000); if (!spring.IsRunning) { ah.ComStart(TasSayEventArgs.Default, new string[] {}); } } else { DateTime now = DateTime.Now; if (!waitReady) { waitReady = true; waitForReadySince = now; } if (plrCnt > from && plrCnt % 2 == 1 && b.IsLocked) { ah.ComAutoLock(TasSayEventArgs.Default, new string[] { (plrCnt + 1).ToString() }); } if (now.Subtract(lastRing).TotalSeconds > RingEvery) { lastRing = now; ah.ComRing(TasSayEventArgs.Default, new string[] {}); } if (plrCnt > from && now.Subtract(waitForReadySince).TotalSeconds > SpecForceAfter) { ah.ComForceSpectator(TasSayEventArgs.Default, new string[] { notReady }); } if (now.Subtract(waitForReadySince).TotalSeconds > SpecAfkAfter) { ah.ComForceSpectatorAfk(TasSayEventArgs.Default, new string[] {}); } if (now.Subtract(waitForReadySince).TotalSeconds > KickAfter) { ah.ComKick(TasSayEventArgs.Default, new string[] { notReady }); } } } else { if (b.IsLocked && plrCnt < from) { ah.ComAutoLock(TasSayEventArgs.Default, new string[] { to.ToString() }); } else if (plrCnt > to) { string notready; if (!ah.AllReadyAndSynced(out notready)) { ah.ComForceSpectator(TasSayEventArgs.Default, new string[] { notready }); } } waitReady = false; } } } else { lastRing = DateTime.Now; waitReady = false; } } finally { timer.Start(); } } }
void tas_BattleLockChanged(object sender, TasEventArgs e) { SayBattle("game " + (tas.GetBattle().IsLocked ? "locked" : "unlocked")); }
public void Apply(TasClient tas, Ladder ladder) { Battle b = tas.GetBattle(); if (b == null) { return; } BattleDetails d = b.Details; if (startingMetal.HasValue) { d.StartingMetal = startingMetal.Value; } if (startingEnergy.HasValue) { d.StartingEnergy = startingEnergy.Value; } if (maxUnits.HasValue) { d.MaxUnits = maxUnits.Value; } if (startPos.HasValue) { d.StartPos = startPos.Value; } if (endCondition.HasValue) { d.EndCondition = endCondition.Value; } if (limitDgun.HasValue) { d.LimitDgun = limitDgun.Value; } if (diminishingMM.HasValue) { d.DiminishingMM = diminishingMM.Value; } if (ghostedBuildings.HasValue) { d.GhostedBuildings = ghostedBuildings.Value; } d.Validate(); int mint, maxt; if (ladder != null) { d = ladder.CheckBattleDetails(d, out mint, out maxt); } tas.UpdateBattleDetails(d); if (enableAllUnits) { tas.EnableAllUnits(); } if (disabledUnits.Length > 0) { tas.DisableUnits(UnitInfo.ToStringList(disabledUnits)); } foreach (string s in perform) { tas.Say(TasClient.SayPlace.Battle, "", s, false); } }