Esempio n. 1
0
 public virtual bool Vote(TasSayEventArgs e, bool vote)
 {
     if (AllowVote(e))
     {
         userVotes[e.UserName] = vote;
         var yes = userVotes.Count(x => x.Value == true);
         var no  = userVotes.Count(x => x.Value == false);
         ah.SayBattle(string.Format("Poll: {0} [!y={1}/{3}, !n={2}/{3}]", Question, yes, no, CountNoIntoWinCount ? WinCount + no : WinCount));
         if ((!CountNoIntoWinCount && yes >= WinCount) || (CountNoIntoWinCount && yes >= WinCount + no))
         {
             ah.SayBattle(string.Format("Poll: {0} [END:SUCCESS]", Question));
             ended = true;
             SuccessAction();
             return(true);
         }
         else if (no >= WinCount)
         {
             End();
             return(true);
         }
     }
     else
     {
         ah.Respond(e, "You are not allowed to vote");
         return(false);
     }
     return(false);
 }
Esempio n. 2
0
        public bool Vote(TasSayEventArgs e, string[] words)
        {
            int vote;

            if (!RegisterVote(e, words, out vote))
            {
                AutoHost.Respond(tas, spring, e, "You must vote valid option/not be a spectator");
                return(false);
            }

            int winVote;

            if (CheckEnd(out winVote))
            {
                if (winVote == 1)
                {
                    ah.SayBattle("vote successful - appling options " + wordFormat);
                    tas.SetScriptTag(scriptTagsFormat);
                }
                else
                {
                    ah.SayBattle("not enough votes for setoptions");
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
 public void ComTempAdmin(TasSayEventArgs e, string[] words)
 {
     if (words.Length == 0)
     {
         if (tempAdminName == "")
         {
             Respond(e, "there is currently no active temp admin");
             return;
         }
         SayBattle("temp admin " + tempAdminName + " removed");
         tempAdminName = "";
         return;
     }
     else
     {
         string[] usrs;
         int[]    idx;
         if (FilterUsers(words, out usrs, out idx) == 0)
         {
             Respond(e, "no such player found");
         }
         else
         {
             SayBattle("New temp admin is " + usrs[0]);
             tempAdminName = usrs[0];
         }
     }
 }
Esempio n. 4
0
        public bool Init(TasSayEventArgs e, string[] words)
        {
            if (words.Length == 0)
            {
                if (ah.TempAdminName == "")
                {
                    ah.Respond(e, "there is currently no temp admin to remove");
                    return(false);
                }
                else
                {
                    player = "";
                    ah.SayBattle("Do you want to remove current tempadmin " + ah.TempAdminName + "? !vote 1 = yes, !vote 2 = no");
                    return(true);
                }
            }

            string[] players;
            int[]    indexes;
            if (AutoHost.FilterUsers(words, tas, spring, out players, out indexes) > 0)
            {
                player = players[0];
                ah.SayBattle("Do you want to elect " + player + " for tempadmin? !vote 1 = yes, !vote 2 = no");
                return(true);
            }
            else
            {
                AutoHost.Respond(tas, spring, e, "Cannot find such player");
                return(false);
            }
        }
Esempio n. 5
0
        protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
        {
            winCount = (tas.MyBattle != null) ? (tas.MyBattle.Users.Count - 1) : 1;
            question = null;
            if (words.Length < 1)
            {
                ah.Respond(e, "<target hostname>");
                return false;
            }
            host = words[0];

            var target_battle = tas.ExistingBattles.Values.FirstOrDefault(x => x.Founder.Name == host);
            if (target_battle == null)
            {
                ah.Respond(e, string.Format("Host {0} not found", words[0]));
                return false;
            }

            if (target_battle.IsPassworded)
            {
                ah.Respond(e, string.Format("Move forbidden: host {0} is passworded.", words[0]));
                return false;
            }

            question = string.Format("Do you want to join {0}?", host);
            return true;

        }
        protected virtual bool AllowVote(TasSayEventArgs e) {
            if (tas.MyBattle == null) return false;

            if (spring.IsRunning)
            {
                var entry = spring.StartContext.Players.FirstOrDefault(x => x.Name == e.UserName);
                if (entry == null || entry.IsSpectator)
                {
                    ah.Respond(e, string.Format("You must be a player in the game"));
                    return false;
                }
                else return true;
            }
            else
            {
                UserBattleStatus entry;
                tas.MyBattle.Users.TryGetValue(e.UserName, out entry);
                if (entry == null || entry.IsSpectator)
                {
                    ah.Respond(e, string.Format("Only players can vote"));
                    return false;
                }
                else return true;
            }
        }
        protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) {
            if (spring.IsRunning)
            {
                context = spring.StartContext;
                voteStarter = context.Players.FirstOrDefault(x => x.Name == e.UserName && !x.IsSpectator);
                if (voteStarter != null)
                {
                    question = string.Format("Resign team {0}?", voteStarter.AllyID + 1);
                    int cnt = 0, total = 0;
                    foreach (var p in context.Players.Where(x => x.AllyID == voteStarter.AllyID && !x.IsSpectator))
                    {
                        total++;
                        if (p.IsIngame || tas.MyBattle.Users.ContainsKey(p.Name))
                        {
                            //Note: "ExistingUsers" is empty if users disconnected from lobby but still ingame.

                            bool afk = tas.ExistingUsers.ContainsKey(p.Name) && tas.ExistingUsers[p.Name].IsAway;
                            if (!afk) cnt++;
                        }
                    }
                    winCount = (cnt * 3 / 5) + 1;
                    if (total > 1 && winCount == 1) winCount = 2; // prevents most pathological cases (like a falsely AFK partner in 2v2)
                    return true;
                }
            }
            AutoHost.Respond(tas, spring, e, "You cannot resign now");
            question = null;
            winCount = 0;
            return false;
        }
Esempio n. 8
0
        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);
                if (ind == -1)
                {
                    votes.Add(vote);
                    users.Add(e.UserName);
                }
                else
                {
                    votes[ind] = vote;
                }
                return(true);
            }
            return(false);
        }
        public void FindLinks(string[] words, FileType type, TasClient tas, TasSayEventArgs e)
        {
            if (words.Length == 0)
            {
                Battle b = tas.MyBattle;
                if (b == null) return;
                ah.Respond(e, string.Format("Getting Zero-K mirrors for currently hosted {0}", type));
                if (type == FileType.Map) GetLinksAsync(b.MapName, e);
                else GetLinksAsync(b.ModName, e);
            }
            else
            {
                int[] resultIndexes;
                string[] resultVals;
                int cnt;
                if (type == FileType.Map) cnt = ah.FilterMaps(words, out resultVals, out resultIndexes);
                else cnt = ah.FilterMods(words, out resultVals, out resultIndexes);

                if (cnt == 0) ah.Respond(e, string.Format("No such {0} found", type));
                else
                {
                    ah.Respond(e, string.Format("Getting Zero-K mirrors for {0}, please wait", resultVals[0]));
                    GetLinksAsync(resultVals[0], e);
                }
            }
        }
Esempio n. 10
0
        private void ComStart(TasSayEventArgs e, string[] words)
        {
            string usname;

            if (!AllReadyAndSynced(out usname))
            {
                SayBattle("cannot start, " + usname + " not ready and synced");
                return;
            }

            if (!AllUniqueTeams(out usname))
            {
                SayBattle("cannot start, " + usname + " is sharing teams. Use !forcestart to override");
                return;
            }

            int allyno;

            if (!BalancedTeams(out allyno))
            {
                SayBattle("cannot start, alliance " + (allyno + 1).ToString() + " not fair. Use !forcestart to override");
                return;
            }
            SayBattle("please wait, game is about to start");

            StopVote();

            tas.ChangeLock(true);
            tas.StartGame();
        }
Esempio n. 11
0
        public void ComAddBox(TasSayEventArgs e, string[] words)
        {
            if (words.Length < 4)
            {
                Respond(e, "This command needs at least 4 parameters");
                return;
            }
            int x, y, w, h;

            if (!int.TryParse(words[0], out x) || !int.TryParse(words[1], out y) || !int.TryParse(words[2], out w) || !int.TryParse(words[3], out h))
            {
                Respond(e, "All parameters must be numbers");
                return;
            }
            int numrect = 0;

            if (words.Length > 4)
            {
                int.TryParse(words[4], out numrect);
            }

            if (numrect == 0)
            {
                numrect = tas.GetBattle().GetFirstEmptyRectangle();
                if (numrect == -1)
                {
                    Respond(e, "Cannot add more boxes");
                    return;
                }
                numrect++;
            }
            tas.AddBattleRectangle(numrect - 1, new BattleRect(x * 2, y * 2, (x + w) * 2, (y + h) * 2));
        }
Esempio n. 12
0
        public void ComKick(TasSayEventArgs e, string[] words)
        {
            if (words.Length == 0)
            {
                Respond(e, "You must specify player name");
                return;
            }

            int[]    indexes;
            string[] usrlist;
            if (FilterUsers(words, out usrlist, out indexes) == 0)
            {
                Respond(e, "Cannot find such player");
                return;
            }

            if (usrlist[0] == tas.UserName)
            {
                Respond(e, "won't kick myself, not in suicidal mood today");
                return;
            }

            if (spring.IsRunning)
            {
                spring.Kick(usrlist[0]);
            }
            tas.Kick(usrlist[0]);
        }
Esempio n. 13
0
        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);

            int cnt = 0;

            foreach (UserBattleStatus u in b.Users)
            {
                if (!u.IsSpectator)
                {
                    tas.ForceColor(u.name, (int)arcols[cnt]);
                    cnt++;
                }
            }

            SayBattle("colors fixed");
        }
Esempio n. 14
0
        public bool Vote(TasSayEventArgs e, string[] words)
        {
            int vote;

            if (!RegisterVote(e, words, out vote))
            {
                AutoHost.Respond(tas, spring, e, "You must vote valid option");
                return(false);
            }

            int winVote;

            if (CheckEnd(out winVote))
            {
                if (winVote == 1)
                {
                    ah.SayBattle("vote successful - appling preset " + presetName);
                    ah.presets[presetId].Apply(tas);
                }
                else
                {
                    ah.SayBattle("not enough votes for preset");
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 15
0
 private void ComSetMinCpuSpeed(TasSayEventArgs e, string[] words)
 {
     if (words.Length == 0)
     {
         Respond(e, "this command needs one parameter - minimal CPU speed");
     }
     else
     {
         System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
         double minCpu;
         double.TryParse(words[0], out minCpu);
         minCpuSpeed = minCpu;
         SayBattle("minimal CPU speed is now " + minCpuSpeed + "GHz");
         if (minCpuSpeed > 0)
         {
             Battle b = tas.GetBattle();
             if (b != null)
             {
                 foreach (UserBattleStatus ubs in b.Users)
                 {
                     User u;
                     if (ubs.name != tas.UserName && tas.GetExistingUser(ubs.name, out u))
                     {
                         if (u.cpu > 0 && u.cpu < minCpuSpeed * 1000)
                         {
                             ComKick(e, new string[] { u.name });
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 16
0
        protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) {
            winCount = 0;
            question = null;
            if (spring.IsRunning)
            {
                question = "Exit this game?";
                int cnt = 0;
                context = spring.StartContext;
                foreach (var p in context.Players.Where(x => !x.IsSpectator))
                {
                    if (p.IsIngame || tas.MyBattle.Users.ContainsKey(p.Name))
                    {
                        //Note: "ExistingUsers" is empty if users disconnected from lobby but still ingame.

                        bool afk = tas.ExistingUsers.ContainsKey(p.Name) && tas.ExistingUsers[p.Name].IsAway;
                        if (!afk) cnt++;
                    }
                }
                winCount = cnt / 2 + 1;
                return true;
            }
            else
            {
                AutoHost.Respond(tas, spring, e, "game not running");
                return false;
            }
        }
Esempio n. 17
0
 public void ComBoss(TasSayEventArgs e, string[] words)
 {
     if (words.Length == 0)
     {
         if (bossName == "")
         {
             Respond(e, "there is currently no active boss");
             return;
         }
         SayBattle("boss " + bossName + " removed");
         bossName = "";
         return;
     }
     else
     {
         string[] usrs;
         int[]    idx;
         if (FilterUsers(words, out usrs, out idx) == 0)
         {
             Respond(e, "no such player found");
         }
         else
         {
             SayBattle("New boss is " + usrs[0]);
             bossName = usrs[0];
         }
     }
 }
Esempio n. 18
0
        public bool Vote(TasSayEventArgs e, string[] words)
        {
            int vote;

            if (!RegisterVote(e, words, out vote))
            {
                AutoHost.Respond(tas, spring, e, "You must vote valid option");
                return(false);
            }

            int winVote;

            if (CheckEnd(out winVote))
            {
                if (winVote == 1)
                {
                    ah.SayBattle("vote successful - kicking " + player);
                    ah.ComKick(TasSayEventArgs.Default, new string[] { player });
                }
                else
                {
                    ah.SayBattle("not enough votes, player stays");
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 19
0
 private void SayLines(TasSayEventArgs e, string what)
 {
     foreach (string line in what.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
     {
         tas.Say(TasClient.SayPlace.User, e.UserName, line, false);
     }
 }
Esempio n. 20
0
        public bool Setup(TasSayEventArgs e, string[] words)
        {
            string question;
            int    winCount;

            if (PerformInit(e, words, out question, out winCount))
            {
                WinCount = winCount;
                Question = question;
                if (WinCount <= 0)
                {
                    WinCount = tas.MyBattle != null ? (tas.MyBattle.NonSpectatorCount / 2 + 1) : 1;
                }
                if (WinCount <= 0)
                {
                    WinCount = 1;
                }
                // If vote is started by a spec while there are players present don't let the number go below 2.
                if (WinCount <= 1 && tas.MyBattle.NonSpectatorCount != 0 &&
                    tas.MyBattle.Users.All(u => u.Name != e.UserName || u.IsSpectator))
                {
                    WinCount = 2;
                }
                ah.SayBattle(string.Format("Poll: {0} [!y=0/{1}, !n=0/{1}]", Question, WinCount));
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 21
0
        public void ComManage(TasSayEventArgs e, string[] words)
        {
            if (words.Length < 1)
            {
                Respond(e, "this command needs 1 parameters (minimum number of players to manage for)");
                return;
            }
            int min = 0;

            int.TryParse(words[0], out min);
            int max = min;

            if (words.Length > 1)
            {
                int.TryParse(words[1], out max);
            }
            if (min == 0)
            {
                Respond(e, "managing disabled");
            }
            else
            {
                Respond(e, "auto managing for " + min + " to " + max + " players");
            }
            manager.Manage(min, max);
        }
Esempio n. 22
0
 private void tas_Said(object sender, TasSayEventArgs e)
 {
     if (config.RedirectGameChat && e.Place == TasSayEventArgs.Places.Battle && e.Origin == TasSayEventArgs.Origins.Player && e.UserName != tas.UserName && e.IsEmote == false && !Program.main.config.AllowInGameJoin)
     {
         spring.SayGame("[" + e.UserName + "]" + e.Text);
     }
 }
Esempio n. 23
0
        protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
        {
            winCount = (tas.MyBattle != null) ? tas.MyBattle.Users.Count : 1;
            question = null;
            if (words.Length < 1)
            {
                ah.Respond(e, "<target hostname>");
                return(false);
            }
            host = words[0];

            var target_battle = tas.ExistingBattles.Values.FirstOrDefault(x => x.Founder.Name == host);

            if (target_battle == null)
            {
                ah.Respond(e, string.Format("Host {0} not found", words[0]));
                return(false);
            }

            if (target_battle.IsPassworded)
            {
                ah.Respond(e, string.Format("Move forbidden: host {0} is passworded.", words[0]));
                return(false);
            }

            question = string.Format("Do you want to join {0}?", host);
            return(true);
        }
Esempio n. 24
0
        private void ComDlMod(TasSayEventArgs e, string[] words)
        {
            if (words.Length == 0)
            {
                Respond(e, "This command needs 1 parameter (mod name or id)");
                return;
            }
            string res = linker.GetResults(Utils.Glue(words), UnknownFilesLinker.FileType.Mod);
            string id  = "";
            int    iid = -1;

            if (int.TryParse(res, out iid)) // check if it's UF mod id
            {
                id = iid.ToString();
            }
            else
            {
                try {
                    id = Regex.Match(res, "file/([0-9]*)").Groups[1].Value;
                } catch { }
            }

            if (id != "")
            {
                Respond(e, "Mod download is being prepared");
                modDownloader.DownloadMod(id);
            }
            else
            {
                Respond(e, "I cannot find such mod");
            }
        }
Esempio n. 25
0
        public void ComAlly(TasSayEventArgs e, string[] words)
        {
            if (words.Length < 2)
            {
                Respond(e, "this command needs 2 parameters (ally number and player name)");
                return;
            }
            int allyno = 0;

            if (!int.TryParse(words[0], out allyno) || --allyno < 0 || allyno >= Spring.MaxAllies)
            {
                Respond(e, "invalid ally 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 alliance " + (allyno + 1));
                tas.ForceAlly(usrs[0], allyno);
            }
        }
Esempio n. 26
0
 protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
 {
     if (spring.IsRunning)
     {
         context     = spring.StartContext;
         voteStarter = context.Players.FirstOrDefault(x => x.Name == e.UserName && !x.IsSpectator);
         if (voteStarter != null)
         {
             question = string.Format("Resign team {0}?", voteStarter.AllyID + 1);
             int cnt = 0;
             foreach (var p in context.Players.Where(x => x.AllyID == voteStarter.AllyID && !x.IsSpectator))
             {
                 if (p.IsIngame || tas.MyBattle.Users.Any(x => x.Name == p.Name))
                 {
                     if (!tas.ExistingUsers[p.Name].IsAway)
                     {
                         cnt++;
                     }
                 }
             }
             winCount = cnt / 2 + 1;
             return(true);
         }
     }
     AutoHost.Respond(tas, spring, e, "You cannot resign now");
     question = null;
     winCount = 0;
     return(false);
 }
Esempio n. 27
0
        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);
            }
        }
Esempio n. 28
0
        public bool Vote(TasSayEventArgs e, string[] words)
        {
            int vote;

            if (!RegisterVote(e, words, out vote))
            {
                AutoHost.Respond(tas, spring, e, "You must vote valid option/not be a spectator");
                return(false);
            }

            int winVote;

            if (CheckEnd(out winVote))
            {
                if (winVote == 1)
                {
                    ah.SayBattle("vote successful - force exiting");
                    ah.ComExit(e, words);
                }
                else
                {
                    ah.SayBattle("not enough votes");
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 29
0
        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");
            }
        }
Esempio n. 30
0
        public bool Vote(TasSayEventArgs e, string[] words)
        {
            int vote;

            if (!RegisterVote(e, words, out vote))
            {
                AutoHost.Respond(tas, spring, e, "You must vote valid option");
                return(false);
            }

            int winVote;

            if (CheckEnd(out winVote))
            {
                if (winVote == 1)
                {
                    ah.SayBattle("vote successful");
                    ah.ComKickSpec(e, new string[] { stateAfter ? "1" : "0" });
                }
                else
                {
                    ah.SayBattle("not enough votes to " + (stateAfter ? "ENABLE" : "DISABLE") + " kickspec");
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 31
0
        void client_Said(object sender, TasSayEventArgs e)
        {
            if (e.Channel != ChannelName)
            {
                return;
            }
            if (e.Origin == TasSayEventArgs.Origins.Player)
            {
                if (e.Place == TasSayEventArgs.Places.Channel)
                {
                    if (e.Text.Contains(Program.Conf.LobbyPlayerName) && e.UserName != GlobalConst.NightwatchName)
                    {
                        Program.MainWindow.NotifyUser("chat/channel/" + e.Channel, string.Format("{0}: {1}", e.UserName, e.Text), false, true);
                    }

                    if (!e.IsEmote)
                    {
                        AddLine(new SaidLine(e.UserName, e.Text));
                    }
                    else
                    {
                        AddLine(new SaidExLine(e.UserName, e.Text));
                    }
                }
            }
            else if (e.Origin == TasSayEventArgs.Origins.Server && e.Place == TasSayEventArgs.Places.Channel)
            {
                AddLine(new ChannelMessageLine(e.Text));
            }
        }
Esempio n. 32
0
        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();
        }
Esempio n. 33
0
        protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
        {
            question = null;
            winCount = 0;
            if (words.Length == 0)
            {
                ah.Respond(e, "You must specify player name");
                return false;
            }

            string[] players;
            int[] indexes;
            if (AutoHost.FilterUsers(new[] {words[0]}, tas, spring, out players, out indexes) > 0)
            {
                player = players[0];
                if (player == tas.UserName)
                {
                    ah.Respond(e, "won't kick myself, not in suicidal mood today");
                    return false;
                }
                else
                {
                    string reason = (words.Length > 1 && words[1] != "for") ? " for" : "";
                    for (var i = 1; i < words.Length; i++) reason += " " + words[i];
                    question = "Kick " + player + reason + "?";
                    return true;
                }
            }
            else
            {
                AutoHost.Respond(tas, spring, e, "Cannot find such player");
                return false;
            }
        }
Esempio n. 34
0
        public bool Vote(TasSayEventArgs e, string[] words)
        {
            int vote;

            if (!RegisterVote(e, words, out vote))
            {
                AutoHost.Respond(tas, spring, e, "You must vote valid option");
                return(false);
            }

            int winVote;

            if (CheckEnd(out winVote))
            {
                if (winVote == 1)
                {
                    ah.SayBattle("vote successful - rehosting");

                    ah.ComRehost(e, new string[] { modname });
                }
                else
                {
                    ah.SayBattle("not enough votes");
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
 protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) {
     winCount = 0;
     question = null;
     if (ah.config.Mode == PlasmaShared.AutohostMode.Serious)
     {
         AutoHost.Respond(tas, spring, e, "Serious host, no custom options");
         return false;
     }
     if (spring.IsRunning)
     {
         AutoHost.Respond(tas, spring, e, "Cannot set options while the game is running");
         return false;
     }
     else
     {
         var wordFormat = Utils.Glue(words);
         scriptTagsFormat = ah.GetOptionsDictionary(e, words);
         if (scriptTagsFormat.Count==0) return false;
         else
         {
             question  = "Set option " + wordFormat + "?";
             return true;
         }
     }
 }
Esempio n. 36
0
        public bool Vote(TasSayEventArgs e, string[] words)
        {
            int vote;

            if (!RegisterVote(e, words, out vote))
            {
                AutoHost.Respond(tas, spring, e, "You must vote valid option");
                return(false);
            }

            int winVote;

            if (CheckEnd(out winVote))
            {
                if (winVote == 1)
                {
                    ah.SayBattle("vote successful - changing map to " + map);
                    tas.ChangeMap(spring.UnitSync.MapList[map]);
                }
                else
                {
                    ah.SayBattle("not enough votes, map stays");
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 37
0
        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;
                }
            }
        }
Esempio n. 38
0
 void OnSaid(object sender, TasSayEventArgs args)
 {
     var tas = (TasClient)sender;
     if (args.Place == SayPlace.Channel && channels.Contains(args.Channel) && args.UserName != tas.UserName) {
         var otherTas = springTas;
         otherTas.Say(LobbyClient.Legacy.TasClient.SayPlace.Channel, args.Channel, string.Format("<{0}> {1}", args.UserName, args.Text), args.IsEmote);
     }
 }
 protected override bool AllowVote(TasSayEventArgs e)
 {
     if (tas.MyBattle == null) return false;
     var entry = tas.MyBattle.Users.Values.FirstOrDefault(x => x.Name == e.UserName);
     if (entry == null || entry.IsSpectator)
     {
         ah.Respond(e, string.Format("Only players can vote"));
         return false;
     }
     else return true;
 }
Esempio n. 40
0
 protected override bool AllowVote(TasSayEventArgs e)
 {
     if (tas.MyBattle == null) return false;
     UserBattleStatus entry;
     tas.MyBattle.Users.TryGetValue(e.UserName, out entry);
     if (entry == null || entry.IsSpectator)
     {
         ah.Respond(e, string.Format("Only players can vote"));
         return false;
     }
     else return true;
 }
        void tas_Said(object sender, TasSayEventArgs e)
        {
            if (e.UserName.Contains("Nightwatch")) return;

            if (e.Place == SayPlace.User)
            {
                if (e.Text.StartsWith("!move"))
                {
                    var db = new ZkDataContext();
                    var acc = db.Accounts.Find(tas.ExistingUsers[e.UserName].AccountID);
                    if (acc.IsZeroKAdmin)
                    {
                        var parts = e.Text.Split(' ');
                        if (parts.Length != 3) tas.Say(SayPlace.User, e.UserName, "!move [from] [to]", false);
                        else
                        {
                            var from = tas.ExistingBattles.Values.FirstOrDefault(x => x.Founder.Name == parts[1]);
                            var to = tas.ExistingBattles.Values.FirstOrDefault(x => x.Founder.Name == parts[2]);
                            if (from != null && to != null)
                            {
                                foreach (var b in from.Users.Values) if (!b.LobbyUser.IsInGame && b.Name != from.Founder.Name) tas.ForceJoinBattle(b.Name, to.BattleID);
                            }
                            else tas.Say(SayPlace.User, e.UserName, "Not a valid battle host name", false);
                        }
                    }
                }
                // split players evenly into two games by median elo -> expand to specify proportion to shunt?
                // TODO: split players and specs separately
                else if (e.Text.StartsWith("!splitplayers"))
                {
                    var db = new ZkDataContext();
                    var acc = db.Accounts.Find(tas.ExistingUsers[e.UserName].AccountID);
                    if (acc.IsZeroKAdmin)
                    {
                        var parts = e.Text.Split(' ');
                        if (parts.Length != 3) tas.Say(SayPlace.User, e.UserName, "!splitplayers [from] [to]", false);
                        else
                        {
                            var from = tas.ExistingBattles.Values.FirstOrDefault(x => x.Founder.Name == parts[1]);
                            var to = tas.ExistingBattles.Values.FirstOrDefault(x => x.Founder.Name == parts[2]);
                            if (from != null && to != null)
                            {
                                var list = from.Users.Values.Where(x=>!x.LobbyUser.IsInGame && x.Name != from.Founder.Name && !x.IsSpectator).OrderBy(x => x.LobbyUser.EffectiveElo);
                                var toMove = list.Take(list.Count() / 2);
                                foreach (var b in toMove) tas.ForceJoinBattle(b.Name, to.BattleID);
                            }
                            else tas.Say(SayPlace.User, e.UserName, "Not a valid battle host name", false);
                        }
                    }
                }
            }
        }
Esempio n. 42
0
 protected override bool AllowVote(TasSayEventArgs e)
 {
     if (spring.IsRunning)
     {
         var entry = spring.StartContext.Players.FirstOrDefault(x => x.Name == e.UserName);
         if (entry == null || entry.IsSpectator || entry.AllyID != voteStarter.AllyID)
         {
             ah.Respond(e, string.Format("Only team {0} can vote", voteStarter.AllyID + 1));
             return false;
         }
         else return true;
     }
     return false;
 }
Esempio n. 43
0
 protected override bool AllowVote(TasSayEventArgs e)
 {
     if (spring.IsRunning)
     {
         var entry = context.Players.FirstOrDefault(x => x.Name == e.UserName);
         if (entry == null || entry.IsSpectator)
         {
             ah.Respond(e, string.Format("You must be a player in the game"));
             return false;
         }
         else return true;
     }
     return false;
 }
Esempio n. 44
0
 override protected bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
 {
     winCount = 0;
     question = null;
     if (spring.IsRunning)
     {
         question = "Force game?";
         return true;
     }
     else
     {
         AutoHost.Respond(tas, spring, e, "battle not started yet");
         return false;
     }
 }
 protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) {
     winCount = 0;
     question = null;
     if (!spring.IsRunning)
     {
         question = "Force start game?";
         winCount = tas.MyBattle.Users.Values.Count(x => !x.IsSpectator) / 2 + 1;
         return true;
     }
     else
     {
         AutoHost.Respond(tas, spring, e, "battle already started");
         return false;
     }
 }
 private void GetLinksAsync(string name, TasSayEventArgs e)
 {
     Task.Factory.StartNew(() => {
         DownloadFileResult ret;
         try {
             ret = plasmaService.DownloadFile(name);
         } catch (Exception ex) {
             Trace.TraceError(ex.ToString());
             return;
         }
     
         if (ret.links != null && ret.links.Count > 0) {
             foreach (string s in ret.links) ah.Respond(e, s.Replace(" ", "%20"));
         } else {
             ah.Respond(e,"No links found");
         }
     });
 }
Esempio n. 47
0
 protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
 {
     winCount = 0;
     question = null;
     if (spring.IsRunning)
     {
         AutoHost.Respond(tas, spring, e, "Cannot attack a different planet while the game is running");
         return false;
     }
     else
     {
         if (words.Length > 0)
         {
             // FIXME get list of valid planets
             //string[] vals;
             //int[] indexes;
             //ah.FilterMaps(words, out vals, out indexes);
             if (true)   //(vals.Length > 0)
             {
                 try
                 {
                     planetID = System.Convert.ToInt32(words[0]);
                     question = string.Format("Attack planet {0} {2}/Planetwars/Planet/{1} ?", planetID, planetID, GlobalConst.BaseSiteUrl);   // FIXME get planet name
                     return true;
                 }
                 catch (System.FormatException ex)
                 {
                     AutoHost.Respond(tas, spring, e, "Invalid planet ID");
                     return false;
                 }
             }
             else
             {
                 AutoHost.Respond(tas, spring, e, "Invalid planet for attack");
                 return false;
             }
         }
         else
         {
             AutoHost.Respond(tas, spring, e, "Please specify a planet");    // FIXME list possible planets
             return false;
         }
     }
 }
Esempio n. 48
0
        protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
        {
            winCount = 0;
            question = null;
            CountNoIntoWinCount = false;

            if (!spring.IsRunning) {

                var invalid = tas.MyBattle.Users.Values.Where(x => !x.IsSpectator && (x.SyncStatus != SyncStatuses.Synced || x.LobbyUser.IsAway)).ToList();
                if (invalid.Count > 0) foreach (var inv in invalid) ah.ComRing(e, new[] { inv.Name }); // ring invalids ot notify them

                // people wihtout map and spring map changed in last 2 minutes, dont allow start yet
                if (tas.MyBattle.Users.Values.Any(x=>!x.IsSpectator && x.SyncStatus != SyncStatuses.Synced) && DateTime.Now.Subtract(ah.lastMapChange).TotalSeconds < MainConfig.MapChangeDownloadWait) {
                    var waitTime = (int)(MainConfig.MapChangeDownloadWait - DateTime.Now.Subtract(ah.lastMapChange).TotalSeconds);
                    AutoHost.Respond(tas, spring, e, string.Format("Map was changed and some players don't have it yet, please wait {0} more seconds", waitTime));
                    return false;
                }

                question = "Start game? ";

                if (invalid.Count > 0) {
                    var invalids = string.Join(",", invalid);
                    ah.SayBattle(invalids + " will be forced spectators if they don't download their maps and stop being afk when vote ends");
                    question += string.Format("WARNING, SPECTATES: {0}", invalids);
                }
                if (tas.MyBattle.Users.Values.Count(x => !x.IsSpectator) >= 2)
                {
                  winCount = (tas.MyBattle.Users.Values.Count(x => !x.IsSpectator) + 1) / 2 + 1;
                }
                else
                {
                  winCount = 1;
                }
                return true;
            }
            else
            {
                AutoHost.Respond(tas, spring, e, "battle already started");
                return false;
            }
        }
        public bool Setup(TasSayEventArgs e, string[] words) {
            string question;
            int winCount;
            if (PerformInit(e, words, out question, out winCount)) {
                WinCount = winCount;
                Question = question;
                if (WinCount <= 0) WinCount = tas.MyBattle != null ? (tas.MyBattle.NonSpectatorCount/2 + 1) : 1;
                if (WinCount <= 0) WinCount = 1;
                // If vote is started by a spec while there are players present don't let the number go below 2.
                if (WinCount <= 1 && tas.MyBattle.NonSpectatorCount != 0 &&
                        tas.MyBattle.Users.Values.All(u => u.Name != e.UserName || u.IsSpectator))
                    WinCount = 2;

                if (WinCount == 1) {
                    SuccessAction();
                    return false;
                } else if (!Vote(e, true)) {
                    ah.SayBattle(string.Format("Poll: {0} [!y=0/{1}, !n=0/{1}]", Question, WinCount));
                }
                return true;
            }
            else return false;
        }
Esempio n. 50
0
        protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) {
            winCount = 0;
            question = null;
            if (words.Length == 0)
            {
                AutoHost.Respond(tas, spring, e, "You must specify player name");
                return false;
            }

            string[] players;
            int[] indexes;
            if (AutoHost.FilterUsers(words, tas, spring, out players, out indexes) > 0)
            {
                player = players[0];
                question = "Spectate " + player + "?";
                return true;
            }
            else
            {
                AutoHost.Respond(tas, spring, e, "Cannot find such player");
                return false;
            }
        }
 public virtual bool Vote(TasSayEventArgs e, bool vote) {
     if (AllowVote(e)) {
         userVotes[e.UserName] = vote;
         var yes = userVotes.Count(x => x.Value == true);
         var no = userVotes.Count(x => x.Value == false);
         ah.SayBattle(string.Format("Poll: {0} [!y={1}/{3}, !n={2}/{3}]", Question, yes, no, CountNoIntoWinCount ? WinCount + no : WinCount));
         if ((!CountNoIntoWinCount && yes >= WinCount) || (CountNoIntoWinCount && yes >= WinCount + no)) {
             ah.SayBattle(string.Format("Poll: {0} [END:SUCCESS]", Question));
             ended = true;
             SuccessAction();
             return true;
         }
         else if (no >= WinCount) {
             End();
             return true;
         }
     }
     else {
         ah.Respond(e, "You are not allowed to vote");
         return false;
     }
     return false;
 }
Esempio n. 52
0
        void client_Said(object sender, TasSayEventArgs e)
        {
            var tas = (TasClient)sender;
            if (Program.Conf.IgnoredUsers.Contains(e.UserName))
            {
                return;
            }

            if (e.Place == SayPlace.Battle && !e.IsEmote && !Program.TasClient.MyUser.IsInGame) Program.MainWindow.NotifyUser("chat/battle", null);
            if (e.Place == SayPlace.Channel && !IsIgnoredChannel(e.Channel)) Program.MainWindow.NotifyUser("chat/channel/" + e.Channel, null);
            else if (e.Place == SayPlace.User)
            {
                var otherUserName = e.UserName == tas.UserName ? e.Channel : e.UserName;

                // support for offline pm and persistent channels 
                if (otherUserName == GlobalConst.NightwatchName && e.Text.StartsWith("!pm"))
                {
                    // message received
                    if (e.UserName == GlobalConst.NightwatchName)
                    {
                        var regex = Regex.Match(e.Text, "!pm\\|([^\\|]*)\\|([^\\|]+)\\|([^\\|]+)\\|([^\\|]+)");
                        if (regex.Success)
                        {
                            var chan = regex.Groups[1].Value;
                            var name = regex.Groups[2].Value;
                            var time = DateTime.Parse(regex.Groups[3].Value, CultureInfo.InvariantCulture).ToLocalTime();
                            var text = regex.Groups[4].Value;

                            if (string.IsNullOrEmpty(chan))
                            {
                                var pmControl = GetPrivateMessageControl(name) ?? CreatePrivateMessageControl(name);
                                pmControl.AddLine(new SaidLine(name, text, time));
                                MainWindow.Instance.NotifyUser("chat/user/" + name, string.Format("{0}: {1}", name, text), false, true);
                            }
                            else
                            {
                                var chatControl = GetChannelControl(chan) ?? CreateChannelControl(chan);
                                chatControl.AddLine(new SaidLine(name, text, time));
                                Program.MainWindow.NotifyUser("chat/channel/" + chan, null);
                            }
                        }
                        else
                        {
                            Trace.TraceWarning("Incomprehensible Nightwatch message: {0}", e.Text);
                        }
                    }
                    else // message sent to nightwatch
                    {
                        var regex = Regex.Match(e.Text, "!pm ([^ ]+) (.*)");
                        if (regex.Success)
                        {
                            var name = regex.Groups[1].Value;
                            var text = regex.Groups[2].Value;
                            var pmControl = GetPrivateMessageControl(name) ?? CreatePrivateMessageControl(name);
                            pmControl.AddLine(new SaidLine(Program.Conf.LobbyPlayerName, text));
                        }
                    }
                }
                else
                {

                    var pmControl = GetPrivateMessageControl(otherUserName);
                    // block non friend messages 
                    if (pmControl == null && Program.Conf.BlockNonFriendPm && !Program.FriendManager.Friends.Contains(otherUserName) && !Program.TasClient.ExistingUsers[e.UserName].IsBot)
                    {
                        if (e.UserName != Program.TasClient.UserName)
                            Program.TasClient.Say(SayPlace.User,
                                                  otherUserName,
                                                  "Sorry, I'm busy and do not receive messages. If you want to ask something, use #zk channel. If you have issue to report use http://code.google.com/p/zero-k/issues/list",
                                                  false);
                    }
                    else
                    {
                        pmControl = pmControl ?? CreatePrivateMessageControl(otherUserName);
                        if (!e.IsEmote) pmControl.AddLine(new SaidLine(e.UserName, e.Text));
                        else pmControl.AddLine(new SaidExLine(e.UserName, e.Text));
                        if (e.UserName != Program.TasClient.MyUser.Name)
                        {
                            MainWindow.Instance.NotifyUser("chat/user/" + otherUserName,
                                                           string.Format("{0}: {1}", otherUserName, e.Text),
                                                           false,
                                                           true);
                        }
                    }
                }

            }
            else if (e.Place == SayPlace.MessageBox) Trace.TraceInformation("TASC: {0}", e.Text);
            if (e.Place == SayPlace.MessageBox) WarningBar.DisplayWarning(e.Text, "Message from server");
        }
Esempio n. 53
0
        void client_Said(object sender, TasSayEventArgs e) {
            if (e.Channel != ChannelName) return;
            if (!string.IsNullOrEmpty(e.UserName)) {
                if (e.Place == SayPlace.Channel) {
                    if (e.Text.Contains(Program.Conf.LobbyPlayerName) && e.UserName != GlobalConst.NightwatchName) Program.MainWindow.NotifyUser("chat/channel/" + e.Channel, string.Format("{0}: {1}", e.UserName, e.Text), false, true);

                    if (!e.IsEmote) AddLine(new SaidLine(e.UserName, e.Text, e.Time));
                    else AddLine(new SaidExLine(e.UserName, e.Text, e.Time));
                }
            }
            else if (e.Place == SayPlace.Channel) AddLine(new ChannelMessageLine(e.Text));
        }
        object DecodeJson(string data, TasSayEventArgs e) {
            try {
                var parts = data.Split(new[] { ' ' }, 3);
                if (parts[0] != "!JSON") return null;
                var payload = parts[2];
                var tname = parts[1];

                Type type;
                if (!typeCache.TryGetValue(tname, out type)) {
                    
                    type = Type.GetType(tname);
                    if (type == null) {
                        //We going to check if current application have the Class that we need. Reference: http://www.codeproject.com/Articles/38870/Examining-an-Assembly-at-Runtime
                        //If we do: "type = Assembly.GetExecutingAssembly().GetTypes().FirstOrDefault(x => x.Name == tname)"
                        //it will return exception "ReflectionTypeLoadException" in ZKL Linux because it doesn't like when
                        //referenced module (like TextToSpeech) is mentioned but not loaded.
                        foreach (Module namespace_obj in Assembly.GetExecutingAssembly().GetModules(false)) {
                            Type[] class_obj = namespace_obj.FindTypes(Module.FilterTypeName, tname);
                            if (class_obj != null && class_obj.Length > 0 && class_obj[0] != null) {
                                type = class_obj[0];
                                break;
                            }
                        }
                    }
                    if (type == null) type = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()).FirstOrDefault(x => x.Name == tname);

                    typeCache[tname] = type;
                }

                if (type != null) {
                    var decoded = JsonConvert.DeserializeObject(payload, type);
                    if (decoded != null) JsonDataReceived(e, decoded);
                }
            } catch (Exception ex) {
                Trace.TraceError(ex.ToString());
            }
            return null;
        }
Esempio n. 55
0
        protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount)
        {
            winCount = 0;
            question = null;
            if (spring.IsRunning)
            {
                AutoHost.Respond(tas, spring, e, "Cannot change map while the game is running");
                return false;
            }
            else
            {
                string[] vals;
                int[] indexes;
                if (words.Length > 0)
                {
                    ah.FilterMaps(words, out vals, out indexes);
                    if (vals.Length > 0)
                    {
                    	bool serious = ah.mode == AutohostMode.Serious;
                        foreach (string possibleMap in vals)
                        {
                            map = possibleMap;
                            var resourceList = ah.cache.FindResourceData(new string[] { map }, ResourceType.Map);
                            if (resourceList != null)
                            {
                            	var resource = resourceList[0];
                            	if (serious && (resource.MapIsSpecial == true || resource.FeaturedOrder == null)) continue;
                                question = string.Format(
                                    "Change map to {0} {2}/Maps/Detail/{1} ?",
                                    map,
                                    resource.ResourceID,
                                    GlobalConst.BaseSiteUrl);
                                return true;
                            }
                        }
                        AutoHost.Respond(tas, spring, e, String.Format("Cannot find such {0}map",serious ? "(non-special) " : ""));
                        return false;
                    }
                    else
                    {
                        AutoHost.Respond(tas, spring, e, "Cannot find such map");
                        return false;
                    }
                }
                else
                {
                    try
                    {
                        if (tas.MyBattle != null && !spring.IsRunning)
                        {
                            var serv = GlobalConst.GetSpringieService();
                            Task.Factory.StartNew(() => {
                                RecommendedMapResult foundMap;
                                try {
                                    foundMap = serv.GetRecommendedMap(tas.MyBattle.GetContext(), true);
                                } catch (Exception ex) {
                                    Trace.TraceError(ex.ToString());
                                    return;
                                }
                                if (foundMap != null && foundMap.MapName != null && tas.MyBattle != null) {
                                    if (tas.MyBattle.MapName != foundMap.MapName) {
                                        map = foundMap.MapName;
                                    }
                                }
                            });

                            
                            // I have no idea why it can't just work like the above way
                            var resourceList = ah.cache.FindResourceData(new string[] { map }, ResourceType.Map);
                            var resource = resourceList.Find(x => x.InternalName == map);
                            if (resource != null)
                            {
                                question = string.Format("Change map to {0} {2}/Maps/Detail/{1} ?", map, resource.ResourceID, GlobalConst.BaseSiteUrl);
                                return true;
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        AutoHost.Respond(tas, spring, e, ex.ToString());
                        //System.Diagnostics.Trace.TraceError(ex.ToString());
                    }
                    return false;
                }
            }
        }
 protected abstract bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount);
Esempio n. 57
0
        void client_Said(object sender, TasSayEventArgs e)
        {
            var tas = (TasClient)sender;
            if (Program.TasClient.Ignores.Contains(e.UserName))
            {
                return;
            }

            if (e.Place == SayPlace.Battle && !e.IsEmote && !Program.TasClient.MyUser.IsInGame) Program.MainWindow.NotifyUser("chat/battle", null);
            if (e.Place == SayPlace.Channel) Program.MainWindow.NotifyUser("chat/channel/" + e.Channel, null);
            else if (e.Place == SayPlace.User)
            {
                var otherUserName = e.UserName == tas.UserName ? e.Channel : e.UserName;

                var pmControl = GetPrivateMessageControl(otherUserName);
                // block non friend messages 
                if (pmControl == null && Program.Conf.BlockNonFriendPm && !Program.TasClient.Friends.Contains(otherUserName) && !Program.TasClient.ExistingUsers[e.UserName].IsBot)
                {
                    if (e.UserName != Program.TasClient.UserName)
                        Program.TasClient.Say(SayPlace.User,
                                              otherUserName,
                                              "Sorry, I'm busy and do not receive messages. If you want to ask something, use #zk channel. If you have issue to report use https://github.com/ZeroK-RTS/Zero-K/issues",
                                              false);
                }
                else
                {
                    pmControl = pmControl ?? CreatePrivateMessageControl(otherUserName);
                    if (!e.IsEmote) pmControl.AddLine(new SaidLine(e.UserName, e.Text, e.Time));
                    else pmControl.AddLine(new SaidExLine(e.UserName, e.Text, e.Time));
                    if (e.UserName != Program.TasClient.MyUser.Name)
                    {
                        MainWindow.Instance.NotifyUser("chat/user/" + otherUserName,
                                                       string.Format("{0}: {1}", otherUserName, e.Text),
                                                       false,
                                                       true);
                    }
                }


            }
            else if (e.Place == SayPlace.MessageBox) Trace.TraceInformation("TASC: {0}", e.Text);
            if (e.Place == SayPlace.MessageBox) WarningBar.DisplayWarning(e.Text);
        }
 void ComSaveBoxes(TasSayEventArgs e, string[] words)
 {
     try
     {
         var serv = GlobalConst.GetSpringieService();
         serv.StoreBoxes(tas.MyBattle.GetContext(),
                         tas.MyBattle.Rectangles.Select(x =>
                             {
                                 double left;
                                 double top;
                                 double right;
                                 double bottom;
                                 x.Value.ToFractions(out left, out top, out right, out bottom);
                                 return new RectInfo()
                                        {
                                            Number = x.Key,
                                            X = (int)(left * 100),
                                            Y = (int)(top * 100),
                                            Width = (int)((right - left) * 100),
                                            Height = (int)((bottom - top) * 100)
                                        };
                             }).ToList());
         Respond(e, "Saved");
     }
     catch (Exception ex)
     {
         Respond(e, ex.ToString());
     }
 }
		void TasClient_Said(object sender, TasSayEventArgs e)
		{
			if (e.Place == SayPlace.Battle || e.Place == SayPlace.BattlePrivate)
			{
				if (e.Text.Contains(Program.Conf.LobbyPlayerName) && !Program.TasClient.MyUser.IsInGame && !e.IsEmote && e.UserName != GlobalConst.NightwatchName &&
					!e.Text.StartsWith(string.Format("[{0}]", Program.TasClient.UserName)))
				{
					Program.MainWindow.NotifyUser("chat/battle", string.Format("{0}: {1}", e.UserName, e.Text), false, true);
				}
				if (!e.IsEmote) AddLine(new SaidLine(e.UserName, e.Text, e.Time));
				else AddLine(new SaidExLine(e.UserName, e.Text, e.Time));
			}
		}
 protected override bool AllowVote(TasSayEventArgs e)
 {
     return true;
 }