Ejemplo n.º 1
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 });
     }
 }
Ejemplo n.º 2
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;
            }
        }
        void OnZkServerSaid(object sender, Say say)
        {
            try
            {
                if (say.Text?.StartsWith("!") == true)
                {
                    ConnectedUser conus;
                    if (server.ConnectedUsers.TryGetValue(say.User, out conus) && conus.User.IsAdmin)
                    {
                        var parts = say.Text.Split(new[] {' '}, 2);
                        var command = parts.FirstOrDefault();
                        var argument = parts.Skip(1).FirstOrDefault();

                        switch (command)
                        {
                            case "!announce":
                                server.GhostSay(new Say() { Text = argument, User = say.User, Place = SayPlace.MessageBox, Ring = true, });
                            break;

                            case "!topic":
                                if (say.Place == SayPlace.Channel && !string.IsNullOrEmpty(say.Target))
                                {
                                    server.SetTopic(say.Target, argument, say.User);
                                }
                            break;
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                Trace.TraceWarning("Error processing message  {0} {1} : {2}", say?.User, say?.Text, ex);
            }
        }
 public Task StoreChatHistoryAsync(Say say)
 {
     return Task.Run(async () =>
     {
         await storeHistorySemaphore.WaitAsync();
         try
         {
             using (var db = new ZkDataContext())
             {
                 var historyEntry = new LobbyChatHistory();
                 historyEntry.SetFromSay(say);
                 db.LobbyChatHistories.Add(historyEntry);
                 db.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             Trace.TraceError("Error saving chat history: {0}", ex);
         }
         finally
         {
             storeHistorySemaphore.Release();
         }
     });
 }
        public async Task<bool> Vote(Say e, bool vote)
        {
            if (command.GetRunPermissions(battle, e.User) >= BattleCommand.RunPermission.Vote && !ended)
            {
                userVotes[e.User] = vote;
                var yes = userVotes.Count(x => x.Value == true);
                var no = userVotes.Count(x => x.Value == false);

                if (yes >= winCount) ended = true;

                await battle.SayBattle(string.Format("Poll: {0} [!y={1}/{3}, !n={2}/{3}]", question, yes, no, winCount));

                if (yes >= winCount)
                {
                    ended = true;
                    await battle.SayBattle($"Poll: {question} [END:SUCCESS]");
                    if (command.Access == BattleCommand.AccessType.NotIngame && battle.spring.IsRunning) return true;
                    if (command.Access == BattleCommand.AccessType.Ingame && !battle.spring.IsRunning) return true;
                    await command.ExecuteArmed(battle, Creator);
                    return true;
                }
                else if (no >= winCount)
                {
                    await End();
                    return true;
                }
            }
            else
            {
                await battle.Respond(e, "You are not allowed to vote");
                return false;
            }
            return false;
        }
 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;
 }
Ejemplo n.º 7
0
 public override async Task ExecuteArmed(ServerBattle battle, Say e)
 {
     if (battle.spring.IsRunning)
     {
         battle.spring.SayGame("/cheat");
         await battle.SayBattle("Cheats!");
     }
 }
Ejemplo n.º 8
0
 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;
 }
Ejemplo n.º 10
0
 public override async Task ExecuteArmed(ServerBattle battle, Say e)
 {
     if (battle.spring.IsRunning)
     {
         battle.spring.ForceStart();
         await battle.SayBattle($"Force starting game");
     }
 }
Ejemplo n.º 11
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);
     }
     
 }
        public override async Task ExecuteArmed(ServerBattle battle, Say e)
        {
            if (cnt > 0)
            {
                await battle.SwitchMaxPlayers(cnt);
                await battle.SayBattle("Max players changed to " + cnt);
            }

        }
Ejemplo n.º 13
0
        public override async Task ExecuteArmed(ServerBattle battle, Say e)
        {
            if (title != null)
            {
                await battle.SwitchTitle(title);
                await battle.SayBattle("Title changed to " + title);
            }

        }
Ejemplo n.º 14
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;
 }
 public async Task StoreChatHistory(Say say)
 {
     using (var db = new ZkDataContext()) {
         var historyEntry = new LobbyChatHistory();
         historyEntry.SetFromSay(say);
         db.LobbyChatHistories.Add(historyEntry);
         await db.SaveChangesAsync();
     }
 }
Ejemplo n.º 16
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, $"===");
     }
 }
Ejemplo n.º 17
0
        public override async Task ExecuteArmed(ServerBattle battle, Say e)
        {
            if (engine != null)
            {
                await battle.SwitchEngine(engine);
                await battle.SayBattle("Engine changed to " + engine);
            }

        }
Ejemplo n.º 18
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);
     }
     
 }
 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 void SetFromSay(Say say)
 {
     this.IsEmote = say.IsEmote;
     this.SayPlace = say.Place;
     this.User = say.User;
     this.Ring = say.Ring;
     this.Target = say.Target;
     this.Text = say.Text;
     this.Time = say.Time ?? DateTime.UtcNow;
 }
 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");
 }
Ejemplo n.º 22
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}?";
        }
Ejemplo n.º 23
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");
        }
Ejemplo n.º 24
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}?";
        }
        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} ?";
        }
Ejemplo n.º 26
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} ?";
        }
Ejemplo n.º 27
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}";
        }
Ejemplo n.º 28
0
 void OnZkServerSaid(object sender, Say say)
 {
     try
     {
         if (say.AllowRelay && say.Place == SayPlace.Channel && channels.Contains(say.Target))
         {
             if (say.Text.StartsWith("!names")) zkServer.GhostPm(say.User, string.Join(", ", springTas.JoinedChannels[say.Target].ChannelUsers));
             else springTas.Say(TasClient.SayPlace.Channel, say.Target, string.Format("<{0}> {1}", say.User, say.Text), say.IsEmote);
         }
     }
     catch (Exception ex)
     {
         Trace.TraceWarning("Error relaying message  {0} {1} {2} : {3}", say?.Target, say?.User, say?.Text, ex);
     }
 }
Ejemplo n.º 29
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}?";
        }
        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;
        }