/// <summary> /// Determines command permissions /// </summary> /// <param name="battle"></param> /// <param name="userName"></param> /// <returns></returns> public virtual RunPermission GetRunPermissions(ServerBattle battle, string userName) { if (Access == AccessType.NoCheck) return RunPermission.Run; UserBattleStatus user = null; if (userName != null) battle.Users.TryGetValue(userName, out user); var hasAdminRights = userName == battle.FounderName || user?.LobbyUser?.IsAdmin == true; var s = battle.spring; bool isSpectator = IsSpectator(battle, userName, user); int count = 0; if (s.IsRunning) { count = s.LobbyStartContext.Players.Count(x=>!x.IsSpectator); } else { count = battle.Users.Count(x => !x.Value.IsSpectator); } var defPerm = hasAdminRights ? RunPermission.Run : (isSpectator ? RunPermission.None : RunPermission.Vote); if (defPerm == RunPermission.None) return defPerm; if (defPerm == RunPermission.Vote && count<=1) defPerm = RunPermission.Run; if (Access == AccessType.Anywhere) return defPerm; if (Access == AccessType.Ingame && s.IsRunning) return defPerm; if (Access == AccessType.NotIngame && !s.IsRunning) return defPerm; if (Access == AccessType.IngameVote && s.IsRunning) return RunPermission.Vote; return RunPermission.None; }
public override RunPermission GetRunPermissions(ServerBattle battle, string userName) { if (battle.ActivePoll?.Creator?.User == userName) return RunPermission.Run; // can end own poll var ret = base.GetRunPermissions(battle, userName); if (ret == RunPermission.Vote) return RunPermission.None; // do not allow vote (ever) return ret; }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { var b = battle; Dictionary<int, double> grouping; using (var db = new ZkDataContext()) { if (battle.IsInGame) grouping = b.spring.LobbyStartContext?.Players.Where(u => !u.IsSpectator) .GroupBy(u => u.AllyID) .ToDictionary(x => x.Key, x => x.Average(y => Account.AccountByName(db, y.Name).EffectiveMmElo)); else grouping = b.Users.Values.Where(u => !u.IsSpectator) .GroupBy(u => u.AllyNumber) .ToDictionary(x => x.Key, x => x.Average(y => y.LobbyUser.EffectiveMmElo)); } KeyValuePair<int, double>? oldg = null; foreach (var g in grouping) { if (oldg != null) { var t1elo = oldg.Value.Value; var t2elo = g.Value; await battle.Respond(e, $"team {oldg.Value.Key + 1} has {Utils.GetWinChancePercent(t2elo - t1elo)}% chance to win over team {g.Key + 1}"); } oldg = g; } }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { var serv = GlobalConst.GetContentService(); // TODO this can be done directly, we are in server engines = serv.GetEngineList(null); if (!string.IsNullOrEmpty(arguments)) engines = engines.Where(x => x.Contains(arguments)).ToList(); return String.Empty; }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { foreach (var s in userList) { await battle.server.GhostSay(new Say() { User = e.User, Target = s, Text = e.User + " wants your attention", IsEmote = true, Ring = true, Place = SayPlace.User }); } }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { if (battle.spring.IsRunning) { battle.spring.SayGame("/cheat"); await battle.SayBattle("Cheats!"); } }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { if (battle.spring.IsRunning) { battle.spring.SayGame(cmd); await battle.SayBattle($"Host executing {cmd}"); } }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { if (int.TryParse(arguments, out cnt) && cnt > 1) { return $"Change title to {cnt}?"; } else return null; }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { if (battle.spring.IsRunning) { battle.spring.ForceStart(); await battle.SayBattle($"Force starting game"); } }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { if (!battle.IsMatchMakerBattle) { battle.Respond(e, "Not a matchmaker battle, cannot predict"); return null; } return string.Empty; }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { if (map != null) { await battle.SwitchMap(map.InternalName); await battle.SayBattle("changing map to " + map.InternalName); } }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { if (title != null) { await battle.SwitchTitle(title); await battle.SayBattle("Title changed to " + title); } }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { foreach (var grp in ServerBattle.Commands.Values.GroupBy(x => x.Access).OrderBy(x=>x.Key)) { await battle.Respond(e, $"=== {grp.Key} {grp.Key.Description()} ==="); foreach (var com in grp.OrderBy(x=>x.Shortcut)) await battle.Respond(e, $"!{com.Shortcut} {com.Help}"); await battle.Respond(e, $"==="); } }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { if (game != null) { await battle.SwitchGame(game.InternalName); await battle.SayBattle("changing game to " + game.InternalName); } }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { if (engine != null) { await battle.SwitchEngine(engine); await battle.SayBattle("Engine changed to " + engine); } }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { if (cnt > 0) { await battle.SwitchMaxPlayers(cnt); await battle.SayBattle("Max players changed to " + cnt); } }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { if (games.Any()) { await battle.Respond(e, "---"); foreach (var map in games) await battle.Respond(e, map.ResourceID + ": " + map.InternalName); await battle.Respond(e, "---"); } else await battle.Respond(e, "no such game found"); }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { if (engines.Any()) { await battle.Respond(e, "---"); foreach (var eng in engines) await battle.Respond(e, eng); await battle.Respond(e, "---"); } else await battle.Respond(e, "no such engine found"); }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { if (string.IsNullOrEmpty(arguments)) { battle.Respond(e, "You must specify a player name"); return null; } target = battle.GetAllUserNames().FirstOrDefault(x => x.Contains(arguments)); if (target == null) target = arguments; return $"do you want to kick {target}?"; }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { if (string.IsNullOrEmpty(arguments)) { battle.Respond(e, "please specify options"); return null; } optionsAsString = arguments; options = GetOptionsDictionary(battle, e, arguments); if (options.Count == 0) return null; return $"Set options {arguments} ?"; }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { if (target == null) { foreach (var usr in battle.Users.Values.Where(x => !x.IsSpectator && x.LobbyUser.IsAway)) await battle.Spectate(usr.Name); } else { await battle.Spectate(target); } await battle.SayBattle($"forcing {target ?? "AFK"} to spectator"); }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { if (string.IsNullOrEmpty(arguments)) arguments = battle.server.Game ?? "zk:stable"; game = MapPicker.FindResources(ResourceType.Mod, arguments).FirstOrDefault(); if (game == null) { battle.Respond(e, "Cannot find such game."); return null; } return $"Change game to {game.RapidTag} {game.InternalName}?"; }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { map = string.IsNullOrEmpty(arguments) ? MapPicker.GetRecommendedMap(battle.GetContext()) : MapPicker.FindResources(ResourceType.Map, arguments).FirstOrDefault(); if (map == null) { battle.Respond(e, "Cannot find such map."); return null; } return $"Change map to {map.InternalName} {GlobalConst.BaseSiteUrl}/Maps/Detail/{map.ResourceID} ?"; }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { if (battle.Mode != AutohostMode.None) { battle.Respond(e, $"Balance is only for custom hosts, this host is {battle.Mode.Description()}"); return null; } if (arguments != null) { int tc; if (int.TryParse(arguments, out tc)) teamCount = tc; } return $"Do you want to balance {teamCount}"; }
public override RunPermission GetRunPermissions(ServerBattle battle, string userName) { var ret = base.GetRunPermissions(battle, userName); // only people from same team can vote if (ret >= RunPermission.Vote) { if (battle.spring.IsRunning) { var entry = battle.spring.LobbyStartContext.Players.FirstOrDefault(x => x.Name == userName); if (entry != null && !entry.IsSpectator && (alliance == null || entry.AllyID == alliance)) return ret; } } return RunPermission.None; }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { if (string.IsNullOrEmpty(arguments)) { target = null; return $"do you want to spectate AFK?"; } target = battle.GetAllUserNames().FirstOrDefault(x => x.Contains(arguments)); if (target == null) { battle.Respond(e, "Player not found"); return null; } return $"do you want to spectate {target}?"; }
private static Dictionary<string, string> GetOptionsDictionary(ServerBattle battle, Say e, string s) { var ret = new Dictionary<string, string>(); if (battle.HostedModInfo == null) return ret; var pairs = s.Split(new[] { ',' }); if (pairs.Length == 0 || pairs[0].Length == 0) { battle.Respond(e, "requires key=value format"); return ret; } foreach (var pair in pairs) { var parts = pair.Split(new[] { '=' }, 2); if (parts.Length != 2) { battle.Respond(e, "requires key=value format"); return ret; } var key = parts[0].Trim(); //Trim() to make "key = value format" ignore whitespace var val = parts[1].Trim(); var found = false; var mod = battle.HostedModInfo; foreach (var o in mod.Options) { if (o.Key == key) { found = true; string res; if (o.GetPair(val, out res)) { ret[key] = val; } else battle.Respond(e, "Value " + val + " is not valid for this option"); break; } } if (!found) { battle.Respond(e, "No option called " + key + " found"); return ret; } } return ret; }
public bool IsSpectator(ServerBattle battle, string userName, UserBattleStatus user) { if (user == null) { if (userName != null) battle.Users.TryGetValue(userName, out user); } bool isSpectator = true; var s = battle.spring; if (s.IsRunning) { if (s.LobbyStartContext.Players.Any(x => x.Name == userName && !x.IsSpectator)) isSpectator = false; } else { if (user?.IsSpectator == false) isSpectator = false; } return isSpectator; }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { userList = new List<string>(); if (string.IsNullOrEmpty(arguments?.Trim())) { // ringing idle foreach (var p in battle.Users.Values) { if (p.IsSpectator) continue; var ingameEntry = battle.spring.Context.ActualPlayers.FirstOrDefault(x => x.Name == p.Name); if ((p.SyncStatus != SyncStatuses.Synced || p.IsSpectator) || (battle.spring.IsRunning && ingameEntry?.IsSpectator == false && ingameEntry?.IsIngameReady == false)) userList.Add(p.Name); } } else userList = battle.GetAllUserNames().Where(x => x.Contains(arguments)).ToList(); return $"do you want to ring {userList.Count} players?"; }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { if (string.IsNullOrEmpty(arguments)) { battle.Respond(e, "Pick a command to poll, e.g. !poll map tabula"); return null; } var parts = arguments.Split(new[] { ' ' }, 2); var commandName = parts[0] ?? ""; var commandArgs = parts.Length > 1 ? parts[1] : null; commandToRun = battle.GetCommandByName(commandName); if (commandToRun.GetRunPermissions(battle, e.User) >= RunPermission.Vote) { return commandToRun.Arm(battle, e, commandArgs); } battle.Respond(e, "You cannot poll this"); return null; }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { if (string.IsNullOrEmpty(arguments)) { arguments = battle.server.Game ?? GlobalConst.DefaultZkTag; } game = MapPicker.FindResources(ResourceType.Mod, arguments).FirstOrDefault(); if ((battle.Mode != AutohostMode.None || !battle.IsPassworded) && arguments != "zk:stable") { battle.Respond(e, $"You can only do this on custom passworded hosts."); return(null); } if (game == null) { battle.Respond(e, "Cannot find such game."); return(null); } return($"Change game to {game.RapidTag} {game.InternalName}?"); }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { engine = string.IsNullOrEmpty(arguments) ? battle.server.Engine : arguments; if ((battle.Mode != AutohostMode.None || !battle.IsPassworded) && engine != battle.server.Engine) { battle.Respond(e, $"You cannot change engine to version other than {battle.server.Engine} here, use custom passworded room"); return(null); } if (!battle.server.SpringPaths.HasEngineVersion(engine)) { var serv = GlobalConst.GetContentService(); // TODO this can be done directly, we are in server if (!serv.GetEngineList(null).Any(x => x == engine)) { battle.Respond(e, "Engine not found"); return(null); } battle.server.Downloader.GetResource(DownloadType.ENGINE, engine); } return($"Change engine to {engine}?"); }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { var b = battle; Dictionary <int, double> grouping; using (var db = new ZkDataContext()) { if (battle.IsInGame) { grouping = b.spring.LobbyStartContext?.Players.Where(u => !u.IsSpectator) .GroupBy(u => u.AllyID) .ToDictionary(x => x.Key, x => x.Average(y => RatingSystems.DisableRatingSystems ? Account.AccountByName(db, y.Name).BestEffectiveElo : Account.AccountByName(db, y.Name).GetBestRating().Elo)); } else { grouping = b.Users.Values.Where(u => !u.IsSpectator) .GroupBy(u => u.AllyNumber) .ToDictionary(x => x.Key, x => x.Average(y => Math.Max(y.LobbyUser.EffectiveMmElo, y.LobbyUser.EffectiveElo))); } } KeyValuePair <int, double>?oldg = null; foreach (var g in grouping) { if (oldg != null) { var t1elo = oldg.Value.Value; var t2elo = g.Value; await battle.Respond(e, $"team {oldg.Value.Key + 1} has {Utils.GetWinChancePercent(t2elo - t1elo)}% chance to win over team {g.Key + 1}"); } oldg = g; } }
public override RunPermission GetRunPermissions(ServerBattle battle, string userName, out string reason) { var ret = base.GetRunPermissions(battle, userName, out reason); // only people from same team can vote if (ret >= RunPermission.Vote) { if (battle.spring.IsRunning) { var entry = battle.spring.LobbyStartContext.Players.FirstOrDefault(x => x.Name == userName); if (entry != null && !entry.IsSpectator && (alliance == null || entry.AllyID == alliance)) { return(ret); } // if player is dead, he cannot vote if (!battle.spring.Context.ActualPlayers.Any(x => x.Name == userName && x.LoseTime == null)) { return(RunPermission.None); } } } return(RunPermission.None); }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { if (string.IsNullOrEmpty(arguments)) { battle.Respond(e, "You must specify a player name"); return(null); } target = battle.GetAllUserNames().FirstOrDefault(x => x.ToLower().Contains(arguments.ToLower())); if (target == null) { battle.Respond(e, "Player " + arguments + " not found!"); return(null); } if (target == battle.FounderName) { battle.Respond(e, "Cannot kick the host"); return(null); } if (IsAdmin(battle, target)) { battle.Respond(e, "Can't kick an admin (spec him or just ask to leave)"); return(null); } if (e != null && battle.spring.IsRunning && !IsAdmin(battle, e.User) && battle.spring.LobbyStartContext?.Players.Any(x => x.Name == e.User && !x.IsSpectator) == false) { battle.Respond(e, "Only players can invoke this during a game"); return(null); } NotifyAdminChannel(battle, e, false); return($"Do you want to kick {target}?"); }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { cmd = arguments; return($"do you want to host say {cmd} ?"); }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { return("Do you want to enable cheats?"); }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { await battle.SwitchPassword(pwd); await battle.SayBattle(string.IsNullOrEmpty(pwd)? "battle password removed" : "battle room password changed"); }
public override async Task ExecuteArmed(ServerBattle battle, Say e) => await battle.RegisterVote(e, false);
public override string Arm(ServerBattle battle, Say e, string arguments = null) => "Reset game options to default?";
public override async Task ExecuteArmed(ServerBattle battle, Say e) { await commandToRun.ExecuteArmed(battle, e); }
private async Task StartGame(ServerBattle battle) { await battle.RunCommandDirectly <CmdSpecAfk>(null); await battle.StartGame(); }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { games = MapPicker.FindResources(ResourceType.Mod, arguments).Take(200).ToList(); return(String.Empty); }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { await battle.RegisterVote(e, opt != 2); }
/// <summary> /// Execute previously armed command, state stored in class /// </summary> /// <param name="battle"></param> /// <param name="e"></param> public abstract Task ExecuteArmed(ServerBattle battle, Say e = null);
/// <summary> /// Prepares the command /// </summary> /// <param name="battle"></param> /// <param name="e"></param> /// <param name="arguments"></param> /// <returns>poll question, null to abort command</returns> public abstract string Arm(ServerBattle battle, Say e, string arguments = null);
public override async Task ExecuteArmed(ServerBattle battle, Say e) { await InternalCommand.ExecuteArmed(battle, e); }
public CommandPoll(ServerBattle battle) { this.battle = battle; }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { battle.RunCommandDirectly <CmdRing>(e); return($"Start the game?"); }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { await battle.SwitchMinLevel(lvl); await battle.SayBattle("Min level changed to " + lvl); }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { await battle.SetModOptions(new Dictionary<string, string>()); await battle.SayBattle($"options reset to defaults"); }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { return(string.Empty); }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { battle.StopVote(); await battle.SayBattle("poll cancelled"); }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { await battle.RunServerBalance(false, teamCount, null); await battle.SayBattle("Teams were balanced"); }
public override async Task ExecuteArmed(ServerBattle battle, Say e) { await battle.SwitchInviteMmPlayers(minplayers); await battle.SayBattle("Minimum players for automatic MM invites changed to " + minplayers); }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { mode = GetValidTypes().FirstOrDefault(x => x.Description().ToLower().Contains(arguments?.ToLower() ?? "")); return($"Change room to {mode.Description()}?"); }
public override string Arm(ServerBattle battle, Say e, string arguments = null) => String.Empty;
public override async Task ExecuteArmed(ServerBattle battle, Say e) { await battle.SwitchGameType(mode); await battle.SayBattle("Game type changed to " + mode.Description()); }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { return($"do you want to force start?"); }
public override string Arm(ServerBattle battle, Say e, string arguments = null) { maps = MapPicker.FindResources(ResourceType.Map, arguments, battle.MinimalMapSupportLevel).Take(200).ToList(); return(String.Empty); }