コード例 #1
0
        /// <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;
        }
コード例 #2
0
 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;
 }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
 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;
 }
コード例 #5
0
 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 });
     }
 }
コード例 #6
0
 public override async Task ExecuteArmed(ServerBattle battle, Say e)
 {
     if (battle.spring.IsRunning)
     {
         battle.spring.SayGame("/cheat");
         await battle.SayBattle("Cheats!");
     }
 }
コード例 #7
0
 public override async Task ExecuteArmed(ServerBattle battle, Say e)
 {
     if (battle.spring.IsRunning)
     {
         battle.spring.SayGame(cmd);
         await battle.SayBattle($"Host executing {cmd}");
     }
 }
コード例 #8
0
 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;
 }
コード例 #9
0
 public override async Task ExecuteArmed(ServerBattle battle, Say e)
 {
     if (battle.spring.IsRunning)
     {
         battle.spring.ForceStart();
         await battle.SayBattle($"Force starting game");
     }
 }
コード例 #10
0
 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;
 }
コード例 #11
0
 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);
     }
     
 }
コード例 #12
0
        public override async Task ExecuteArmed(ServerBattle battle, Say e)
        {
            if (title != null)
            {
                await battle.SwitchTitle(title);
                await battle.SayBattle("Title changed to " + title);
            }

        }
コード例 #13
0
 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, $"===");
     }
 }
コード例 #14
0
 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);
     }
     
 }
コード例 #15
0
        public override async Task ExecuteArmed(ServerBattle battle, Say e)
        {
            if (engine != null)
            {
                await battle.SwitchEngine(engine);
                await battle.SayBattle("Engine changed to " + engine);
            }

        }
コード例 #16
0
        public override async Task ExecuteArmed(ServerBattle battle, Say e)
        {
            if (cnt > 0)
            {
                await battle.SwitchMaxPlayers(cnt);
                await battle.SayBattle("Max players changed to " + cnt);
            }

        }
コード例 #17
0
 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");
 }
コード例 #18
0
 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");
 }
コード例 #19
0
        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}?";
        }
コード例 #20
0
        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} ?";
        }
コード例 #21
0
        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");
        }
コード例 #22
0
        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}?";
        }
コード例 #23
0
        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} ?";
        }
コード例 #24
0
        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}";
        }
コード例 #25
0
        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;
        }
コード例 #26
0
        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}?";
        }
コード例 #27
0
        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;
        }
コード例 #28
0
 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;
 }
コード例 #29
0
        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?";
        }
コード例 #30
0
 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;
 }
コード例 #31
0
        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}?");
        }
コード例 #32
0
        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}?");
        }
コード例 #33
0
        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;
            }
        }
コード例 #34
0
        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);
        }
コード例 #35
0
ファイル: CmdKick.cs プロジェクト: Sharkgamedev/Zero-K-New-PW
        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}?");
        }
コード例 #36
0
 public override string Arm(ServerBattle battle, Say e, string arguments = null)
 {
     cmd = arguments;
     return($"do you want to host say {cmd} ?");
 }
コード例 #37
0
 public override string Arm(ServerBattle battle, Say e, string arguments = null)
 {
     return("Do you want to enable cheats?");
 }
コード例 #38
0
        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");
        }
コード例 #39
0
ファイル: CmdN.cs プロジェクト: sprangg/Zero-K-Infrastructure
 public override async Task ExecuteArmed(ServerBattle battle, Say e) => await battle.RegisterVote(e, false);
コード例 #40
0
 public override string Arm(ServerBattle battle, Say e, string arguments = null) => "Reset game options to default?";
コード例 #41
0
 public override async Task ExecuteArmed(ServerBattle battle, Say e)
 {
     await commandToRun.ExecuteArmed(battle, e);
 }
コード例 #42
0
        private async Task StartGame(ServerBattle battle)
        {
            await battle.RunCommandDirectly <CmdSpecAfk>(null);

            await battle.StartGame();
        }
コード例 #43
0
 public override string Arm(ServerBattle battle, Say e, string arguments = null)
 {
     games = MapPicker.FindResources(ResourceType.Mod, arguments).Take(200).ToList();
     return(String.Empty);
 }
コード例 #44
0
 public override async Task ExecuteArmed(ServerBattle battle, Say e)
 {
     await battle.RegisterVote(e, opt != 2);
 }
コード例 #45
0
 /// <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);
コード例 #46
0
 /// <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);
コード例 #47
0
 public override async Task ExecuteArmed(ServerBattle battle, Say e)
 {
     await InternalCommand.ExecuteArmed(battle, e);
 }
コード例 #48
0
 public CommandPoll(ServerBattle battle)
 {
     this.battle = battle;
 }
コード例 #49
0
 public override string Arm(ServerBattle battle, Say e, string arguments = null)
 {
     battle.RunCommandDirectly <CmdRing>(e);
     return($"Start the game?");
 }
コード例 #50
0
        public override async Task ExecuteArmed(ServerBattle battle, Say e)
        {
            await battle.SwitchMinLevel(lvl);

            await battle.SayBattle("Min level changed to " + lvl);
        }
コード例 #51
0
 public override async Task ExecuteArmed(ServerBattle battle, Say e)
 {
     await battle.SetModOptions(new Dictionary<string, string>());
     await battle.SayBattle($"options reset to defaults");
 }
コード例 #52
0
 public override string Arm(ServerBattle battle, Say e, string arguments = null)
 {
     return(string.Empty);
 }
コード例 #53
0
 public override async Task ExecuteArmed(ServerBattle battle, Say e)
 {
     battle.StopVote();
     await battle.SayBattle("poll cancelled");
 }
コード例 #54
0
        public override async Task ExecuteArmed(ServerBattle battle, Say e)
        {
            await battle.RunServerBalance(false, teamCount, null);

            await battle.SayBattle("Teams were balanced");
        }
コード例 #55
0
        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);
        }
コード例 #56
0
ファイル: CmdType.cs プロジェクト: se5a/Zero-K-Infrastructure
 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()}?");
 }
コード例 #57
0
ファイル: CmdN.cs プロジェクト: sprangg/Zero-K-Infrastructure
 public override string Arm(ServerBattle battle, Say e, string arguments = null) => String.Empty;
コード例 #58
0
ファイル: CmdType.cs プロジェクト: se5a/Zero-K-Infrastructure
        public override async Task ExecuteArmed(ServerBattle battle, Say e)
        {
            await battle.SwitchGameType(mode);

            await battle.SayBattle("Game type changed to " + mode.Description());
        }
コード例 #59
0
 public override string Arm(ServerBattle battle, Say e, string arguments = null)
 {
     return($"do you want to force start?");
 }
コード例 #60
0
 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);
 }