public void OnSaid(object sender, TasSayEventArgs args) { if (InvokeRequired) Invoke(new SayEvent(OnSaid), sender, args); else { switch (args.Place) { case TasSayEventArgs.Places.Broadcast: case TasSayEventArgs.Places.MessageBox: case TasSayEventArgs.Places.Motd: tServer.AppendText("[" + DateTime.Now.ToString("T") + "] " + args.Text + "\r\n"); break; case TasSayEventArgs.Places.Channel: RichTextBox t = GetTab("#" + args.Channel); t.AppendText(String.Format("[{0}] <{1}> {2}\r\n", DateTime.Now.ToString("T"), args.UserName, args.Text)); break; case TasSayEventArgs.Places.Normal: t = GetTab(args.Channel); t.AppendText(String.Format("[{0}] <{1}> {2}\r\n", DateTime.Now.ToString("T"), args.UserName, args.Text)); break; case TasSayEventArgs.Places.Battle: tBattle.AppendText(String.Format("[{0}] <{1}> {2}\r\n", DateTime.Now.ToString("T"), args.UserName, args.Text)); break; } } }
public override bool Parse(TasSayEventArgs eventArgs, object[] parameters) { if (parameters.Length > 0) { if (!int.TryParse(parameters[0].ToString(), out allyCount)) allyCount = 2; } else allyCount = 2; if (allyCount < 2) allyCount = 2; operationText = string.Format("balance to {0} teams", allyCount); return true; }
public override bool Parse(TasSayEventArgs eventArgs, object[] parameters) { if (base.Parse(eventArgs, parameters)) { if (parameters.Length == 0) operationText = "ring all unready"; else { string rang = ""; foreach (string s in playerNames) { rang += s + ", "; } operationText = "ring " + rang; } return true; } else return false; }
protected bool RegisterVote(TasSayEventArgs e, string[] words, out int vote) { vote = 0; if (words.Length != 1) return false; int.TryParse(words[0], out vote); if (vote > 0 && vote <= options) { // vote within parameters, lets register it int ind = users.IndexOf(e.UserName); if (ind == -1) { votes.Add(vote); users.Add(e.UserName); } else { votes[ind] = vote; } return true; } return false; }
public virtual bool Execute(TasSayEventArgs eventArgs, params object[] parameters) { if (Enabled) { if (Parse(eventArgs, parameters)) { int diff = (int)(DateTime.Now.Subtract(lastExecution).TotalSeconds - Config.Throttling); if (diff >= 0) { lastExecution = DateTime.Now; SayBattle("does {0}", operationText); DoCommand(); return true; } else { Respond(eventArgs, "wait {0} seconds", -diff); return false; } } else { Respond(eventArgs, "usage: !{0} {1}", id, paramDescription); return false; } } else return false; }
protected bool RegisterVote(TasSayEventArgs e, string[] words, out int vote) { vote = 0; 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; }
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 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)); } }
public override bool Parse(TasSayEventArgs eventArgs, object[] parameters) { if (parameters.Length <= playernameStartIndex) { if (allowEmptyArgs) { playerNames = new string[0]; return true; } Respond(eventArgs, "You must specify player name"); return false; } string[] filterWords = new string[parameters.Length - playernameStartIndex]; for (int i = 0; i < parameters.Length; i++) filterWords[i] = parameters[i + playernameStartIndex].ToString(); int[] indexes; handler.AutoHost.FilterUsers(filterWords, out playerNames, out indexes); if (playerNames.Length == 0) { Respond(eventArgs, "Cannot find such player"); return false; } foreach (string s in playerNames) { if (s == handler.TasClient.UserName) { Respond(eventArgs, "Cannot target myself"); return false; } } if (playerNames.Length > 1 && !canTargetMultiple) { Respond(eventArgs, "This matches more than one player"); return false; } return true; }
public void StartVote(IVotable vote, TasSayEventArgs e, string[] words) { if (vote != null) { if (activePoll != null) { Respond(e, "Another poll already in progress, please wait"); return; } if (vote.Init(e, words)) { activePoll = vote; pollTimer.Interval = PollTimeout*1000; pollTimer.Enabled = true; } } }
public static void Respond(TasClient tas, Spring spring, TasSayEventArgs e, string text) { TasClient.SayPlace p = TasClient.SayPlace.User; bool emote = false; if (e.Place == TasSayEventArgs.Places.Battle) { p = TasClient.SayPlace.Battle; emote = true; } if (e.Place == TasSayEventArgs.Places.Game && spring.IsRunning) spring.SayGame(text); else tas.Say(p, e.UserName, text, emote); }
public bool HasRights(string command, TasSayEventArgs e) { if (banList.IsBanned(e.UserName)) { Respond(e, "tough luck, you are banned"); return false; } foreach (CommandConfig c in config.Commands) { if (c.Name == command) { if (c.Throttling > 0) { int diff = (int)DateTime.Now.Subtract(c.lastCall).TotalSeconds; if (diff < c.Throttling) { Respond(e, "AntiSpam - please wait " + (c.Throttling - diff).ToString() + " more seconds"); return false; } } for (int i = 0; i < c.ListenTo.Length; i++) { if (c.ListenTo[i] == e.Place) { int reqLevel = c.Level; int ulevel = GetUserLevel(e); if (ulevel >= reqLevel) { // boss stuff if (bossName != "" && ulevel <= config.DefaulRightsLevel && e.UserName != bossName && config.DefaultRightsLevelWithBoss < reqLevel) { Respond(e, "Sorry, you cannot do this right now, ask boss admin " + bossName); return false; } else { c.lastCall = DateTime.Now; return true; // ALL OK } } else { Respond(e, "Sorry, you do not have rights to execute " + command); return false; } } } return false; // place not allowed for this command = ignore command } } if (e.Place != TasSayEventArgs.Places.Channel) Respond(e, "Sorry, I don't know command '" + command + "'"); return false; }
public void ComListBans(TasSayEventArgs e, string[] words) { Items.RemoveAll(delegate(BannedUser b) { return b.Expired; }); tas.Say(TasClient.SayPlace.User, e.UserName, "---", false); foreach (BannedUser b in Items) { string text = String.Format("{0} --> {1} (banned from:{2} to:{3} (GMT))", b.Name, b.Reason, b.Started.ToUniversalTime(), b.Started.Add(b.Duration).ToUniversalTime()); tas.Say(TasClient.SayPlace.User, e.UserName, text, false); } tas.Say(TasClient.SayPlace.User, e.UserName, "---", false); }
/// <summary> /// Performs map search and says result /// </summary> /// <param name="name">map to search for</param> /// <param name="tas">tasclient to recieve response</param> /// <param name="e">say parameters (for forming response)</param> public void SayResults(string name, FileType type, TasClient tas, TasSayEventArgs e) { SayLines(GetResults(name, type), tas, e); }
public void ComExit(TasSayEventArgs e, string[] words) { if (spring.IsRunning) SayBattle("exiting game"); else Respond(e, "cannot exit, not in game"); spring.ExitGame(); }
public void ComDlMod(TasSayEventArgs e, string[] words) { if (words.Length == 0) { Respond(e, "This command needs 1 parameter (mod name or id)"); return; } string str = Utils.Glue(words); string dump; int dumpi; string res = str; if (!int.TryParse(str, out dumpi) && !FileDownloader.IsFileUrl(str, out dump)) { res = ""; try { dump = linker.GetResults(str, UnknownFilesLinker.FileType.Mod); res = Regex.Match(dump, "file/([0-9]*)").Groups[1].Value; } catch {} } if (res != "") { Respond(e, "Starting mod download"); fileDownloader.DownloadMod(res); } else Respond(e, "I cannot find such mod"); }
public void ComTeam(TasSayEventArgs e, string[] words) { if (words.Length < 2) { Respond(e, "this command needs 2 parameters (team number and player name)"); return; } int teamno = 0; if (!int.TryParse(words[0], out teamno) || --teamno < 0 || teamno >= Spring.MaxTeams) { Respond(e, "invalid team number"); return; } string[] usrs; int[] idx; if (FilterUsers(Utils.ShiftArray(words, -1), out usrs, out idx) == 0) Respond(e, "no such player found"); else { SayBattle("Forcing " + usrs[0] + " to team " + (teamno + 1)); tas.ForceTeam(usrs[0], teamno); } }
public void ComFix(TasSayEventArgs e, string[] words) { Battle b = tas.GetBattle(); int cnt = 0; foreach (UserBattleStatus u in b.Users) { if (!u.IsSpectator) { tas.ForceTeam(u.name, cnt); cnt++; } } SayBattle("team numbers fixed"); }
/************************************************************************/ /* PRIVATE METHODS */ /************************************************************************/ private void SayLines(string text, TasClient tas, TasSayEventArgs e) { string[] lines = text.Split(new char[] {'\n'}, StringSplitOptions.RemoveEmptyEntries); foreach (string l in lines) tas.Say(TasClient.SayPlace.User, e.UserName, l, false); }
public void ComFixColors(TasSayEventArgs e, string[] words) { List<MyCol> cols = new List<MyCol>(); Battle b = tas.GetBattle(); foreach (UserBattleStatus u in b.Users) if (!u.IsSpectator) cols.Add((MyCol)u.TeamColor); MyCol[] arcols = cols.ToArray(); MyCol.FixColors(arcols, 30000); bool changed = false; int cnt = 0; foreach (UserBattleStatus u in b.Users) { if (!u.IsSpectator) { if (u.TeamColor != (int)arcols[cnt]) { tas.ForceColor(u.name, (int)arcols[cnt]); changed = true; } cnt++; } } if (changed) SayBattle("colors fixed"); }
public void ComUnban(TasSayEventArgs e, string[] words) { if (words.Length == 0) { ah.Respond(e, "this command needs 1 argument - user name"); return; } BannedUser b; if (IsBanned(words[0], out b)) { Items.Remove(b); ah.Respond(e, b.Name + " removed from banlist"); Save(); } else ah.Respond(e, "no such user in banlist"); }
public void ComRehost(TasSayEventArgs e, string[] words) { if (words.Length == 0) Start(null, null); else { string[] mods; int[] indexes; if (FilterMods(words, out mods, out indexes) == 0) Respond(e, "cannot find such mod"); else Start(mods[0], null); } }
public int GetUserLevel(TasSayEventArgs e) { return GetUserLevel(e.UserName); }
public void ComRandom(TasSayEventArgs e, string[] words) { ComFix(e, words); Battle b = tas.GetBattle(); List<UserBattleStatus> actUsers = new List<UserBattleStatus>(); foreach (UserBattleStatus u in b.Users) if (!u.IsSpectator) actUsers.Add(u); int teamCount = 0; if (words.Length > 0) int.TryParse(words[0], out teamCount); else teamCount = 2; if (teamCount < 2) teamCount = 2; if (teamCount > actUsers.Count) teamCount = 2; Random r = new Random(); int al = 0; while (actUsers.Count > 0) { int index = r.Next(actUsers.Count); tas.ForceAlly(actUsers[index].name, al); actUsers.RemoveAt(index); al++; al = al%teamCount; } SayBattle("players assigned to " + teamCount + " random teams"); }
public void Respond(TasSayEventArgs e, string text) { Respond(tas, spring, e, text); }
public void ComCBalance(TasSayEventArgs e, string[] words) { int teamCount = 2; if (words.Length > 0) int.TryParse(words[0], out teamCount); else teamCount = 2; ComFix(e, words); BalanceTeams(teamCount, true); }
private void tas_Said(object sender, TasSayEventArgs e) { // check if it's command if (e.Origin == TasSayEventArgs.Origins.Player && !e.IsEmote && e.Text.StartsWith("!")) { if (e.Text.Length < 2) return; string[] allwords = e.Text.Substring(1).Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries); if (allwords.Length < 1) return; string com = allwords[0]; // remove first word (command) string[] words = Utils.ShiftArray(allwords, -1); if (!HasRights(com, e)) return; switch (com) { case "listmaps": ComListMaps(e, words); break; case "listmods": ComListMods(e, words); break; case "help": ComHelp(e, words); break; case "map": ComMap(e, words); break; case "admins": ComAdmins(e, words); break; case "start": ComStart(e, words); break; case "forcestart": ComForceStart(e, words); break; case "force": ComForce(e, words); break; case "split": ComSplit(e, words); break; case "corners": ComCorners(e, words); break; case "maplink": linker.SayResults(Utils.Glue(words), UnknownFilesLinker.FileType.Map, tas, e); break; case "modlink": linker.SayResults(Utils.Glue(words), UnknownFilesLinker.FileType.Mod, tas, e); break; case "ring": ComRing(e, words); break; case "kick": ComKick(e, words); break; case "exit": ComExit(e, words); break; case "lock": tas.ChangeLock(true); break; case "unlock": tas.ChangeLock(false); break; case "vote": RegisterVote(e, words); break; case "votemap": StartVote(new VoteMap(tas, spring, this), e, words); break; case "votekick": StartVote(new VoteKick(tas, spring, this), e, words); break; case "voteforcestart": StartVote(new VoteForceStart(tas, spring, this), e, words); break; case "voteforce": StartVote(new VoteForce(tas, spring, this), e, words); break; case "voteexit": StartVote(new VoteExit(tas, spring, this), e, words); break; case "votepreset": StartVote(new VotePreset(tas, spring, this), e, words); break; case "fix": ComFix(e, words); break; case "rehost": ComRehost(e, words); break; case "voterehost": StartVote(new VoteRehost(tas, spring, this), e, words); break; case "random": ComRandom(e, words); break; case "balance": ComBalance(e, words); break; case "setlevel": ComSetLevel(e, words); break; case "say": ComSay(e, words); break; case "dlmap": ComDlMap(e, words); break; case "dlmod": ComDlMod(e, words); break; case "reload": Respond(e, "reloading mod and map list"); spring.Reload(true, true); Respond(e, "reload finished"); break; case "team": ComTeam(e, words); break; case "ally": ComAlly(e, words); break; case "helpall": ComHelpAll(e, words); break; case "fixcolors": ComFixColors(e, words); break; case "springie": ComSpringie(e, words); break; case "endvote": StopVote(); SayBattle("poll cancelled"); break; case "addbox": ComAddBox(e, words); break; case "clearbox": ComClearBox(e, words); break; case "listpresets": ComListPresets(e, words); break; case "presetdetails": ComPresetDetails(e, words); break; case "preset": ComPreset(e, words); break; case "cbalance": ComCBalance(e, words); break; case "listbans": banList.ComListBans(e, words); break; case "ban": banList.ComBan(e, words); break; case "unban": banList.ComUnban(e, words); break; case "smurfs": RemoteCommand(Stats.smurfScript, e, words); break; case "stats": RemoteCommand(Stats.statsScript, e, words); break; case "kickspec": ComKickSpec(e, words); break; case "manage": ComManage(e, words); break; case "notify": ComNotify(e, words); break; case "votekickspec": StartVote(new VoteKickSpec(tas, spring, this), e, words); break; case "boss": ComBoss(e, words); break; case "voteboss": StartVote(new VoteBoss(tas, spring, this), e, words); break; case "setpassword": ComSetPassword(e, words); break; case "setgametitle": ComSetGameTitle(e, words); break; case "setminrank": ComSetMinRank(e, words); break; case "setmaxplayers": ComSetMaxPlayers(e, words); break; case "mincpuspeed": ComSetMinCpuSpeed(e, words); break; case "autolock": ComAutoLock(e, words); break; case "spec": ComForceSpectator(e, words); break; case "specafk": ComForceSpectatorAfk(e, words); break; case "kickminrank": ComKickMinRank(e, words); break; case "cheats": if (spring.IsRunning) spring.SayGame(".cheats"); break; case "listoptions": ComListOptions(e, words); break; case "setoptions": ComSetOption(e, words); break; case "votesetoptions": StartVote(new VoteSetOptions(tas, spring, this), e, words); break; } } }
public void ComSetLevel(TasSayEventArgs e, string[] words) { if (words.Length != 2) { Respond(e, "This command needs 2 parameters"); return; } int lvl; int.TryParse(words[0], out lvl); config.SetPrivilegedUser(words[1], lvl); SaveConfig(); Respond(e, words[1] + " has rights level " + lvl.ToString()); }
public void RegisterVote(TasSayEventArgs e, string[] words) { if (activePoll != null) { if (activePoll.Vote(e, words)) StopVote(); } else Respond(e, "There is no poll going on, start some first"); }
public void ComSay(TasSayEventArgs e, string[] words) { if (words.Length == 0) { Respond(e, "This command needs 1 parameter (say text)"); return; } SayBattle("[" + e.UserName + "]" + Utils.Glue(words)); }