Пример #1
0
        public string SetRights(Session session, String[] parms)
        {
            bool         help       = false;
            string       playerName = string.Empty;
            PlayerRights?rights     = null;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "p=|player=", v => playerName = v.TrimMatchingQuotes() },
                    {
                        "rights=",
                        v =>
                        rights = (PlayerRights?)Enum.Parse(typeof(PlayerRights), v.TrimMatchingQuotes(), true)
                    }
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help || string.IsNullOrEmpty(playerName) || !rights.HasValue)
            {
                return(String.Format("setrights --player=player --rights={0}",
                                     String.Join("|", Enum.GetNames(typeof(PlayerRights)))));
            }

            // Kick user out if they are logged in
            uint playerId;

            if (world.FindPlayerId(playerName, out playerId))
            {
                IPlayer player;
                locker.Lock(playerId, out player).Do(() =>
                {
                    if (player != null && player.Session != null)
                    {
                        try
                        {
                            player.Session.CloseSession();
                        }
                        catch
                        {
                        }
                    }
                });
            }

            ApiResponse <dynamic> response = ApiCaller.SetPlayerRights(playerName, rights.GetValueOrDefault());

            return(response.Success ? "OK!" : response.AllErrorMessages);
        }
Пример #2
0
        public string GiveSupporterAchievement(Session session, string[] parms)
        {
            bool            help       = false;
            string          playerName = string.Empty;
            AchievementTier?tier       = null;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "p=|player=", v => playerName = v.TrimMatchingQuotes() },
                    { "tier=", v => tier = EnumExtension.Parse <AchievementTier>(v.TrimMatchingQuotes()) },
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help ||
                string.IsNullOrEmpty(playerName) ||
                !tier.HasValue)
            {
                return(String.Format("givesupporterachievement --player=player --tier={0}",
                                     String.Join("|", Enum.GetNames(typeof(AchievementTier)))));
            }

            var type        = "SUPPORTER";
            var icon        = "coins";
            var title       = "Supporter";
            var description = "Helped Improve Tribal Hero";

            ApiResponse <dynamic> response = ApiCaller.GiveAchievement(playerName, tier.Value, type, icon, title, description);

            if (response.Success)
            {
                uint playerId;
                if (world.FindPlayerId(playerName, out playerId))
                {
                    IPlayer player;
                    locker.Lock(playerId, out player).Do(() =>
                    {
                        chat.SendSystemChat("ACHIEVEMENT_NOTIFICATION", playerId.ToString(CultureInfo.InvariantCulture), player.Name, tier.ToString().ToLowerInvariant());

                        player.SendSystemMessage(null, "Achievement", "Hello, I've given you an achievement for supporting us. Your money will help us improve and cover the operating costs of the game. Make sure to refresh the game to see your new achievement. Thanks for your help!");
                    });
                }
            }

            return(response.Success ? "OK!" : response.AllErrorMessages);
        }
Пример #3
0
        public string Info(Session session, String[] parms)
        {
            bool   help       = false;
            string playerName = null;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "p=|player=", v => playerName = v.TrimMatchingQuotes() },
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help || (string.IsNullOrEmpty(playerName)))
            {
                return(String.Format("playerinfo --player=name|emailaddress"));
            }

            ApiResponse <dynamic> response = ApiCaller.PlayerInfo(playerName);

            if (!response.Success)
            {
                return(response.AllErrorMessages);
            }

            try
            {
                return
                    (String.Format(
                         "id[{0}] created[{1}] name[{7}] emailAddress[{2}] lastLogin[{3}] ipAddress[{4}] banned[{5}] deleted[{6}]",
                         response.Data.id,
                         response.Data.created,
                         session.Player.Rights > PlayerRights.Moderator ? response.Data.emailAddress : "N/A",
                         session.Player.Rights > PlayerRights.Moderator ? response.Data.lastLogin : "******",
                         session.Player.Rights > PlayerRights.Moderator ? response.Data.ipAddress : "N/A",
                         response.Data.banned == "1" ? "YES" : "NO",
                         response.Data.deleted == "1" ? "YES" : "NO",
                         response.Data.name));
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Пример #4
0
        public string UnbanPlayer(Session session, string[] parms)
        {
            bool   help       = false;
            string playerName = string.Empty;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "p=|player=", v => playerName = v.TrimMatchingQuotes() }
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help || string.IsNullOrEmpty(playerName))
            {
                return("unban --player=player");
            }

            uint playerId;

            if (!world.FindPlayerId(playerName, out playerId))
            {
                return("Player not found");
            }

            IPlayer player;

            locker.Lock(playerId, out player).Do(() =>
            {
                if (player != null)
                {
                    player.Banned = false;
                    dbManager.Save(player);
                }
            });

            ApiResponse <dynamic> response = ApiCaller.Unban(playerName);

            return(response.Success ? "OK!" : response.AllErrorMessages);
        }
Пример #5
0
        public string GiveAchievement(Session session, String[] parms)
        {
            bool            help        = false;
            string          playerName  = string.Empty;
            string          icon        = string.Empty;
            string          title       = string.Empty;
            string          type        = string.Empty;
            string          description = string.Empty;
            AchievementTier?tier        = null;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "p=|player=", v => playerName = v.TrimMatchingQuotes() },
                    { "title=", v => title = v.TrimMatchingQuotes() },
                    { "description=", v => description = v.TrimMatchingQuotes() },
                    { "icon=", v => icon = v.TrimMatchingQuotes() },
                    { "type=", v => type = v.TrimMatchingQuotes() },
                    { "tier=", v => tier = EnumExtension.Parse <AchievementTier>(v.TrimMatchingQuotes()) },
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help ||
                string.IsNullOrEmpty(playerName) ||
                string.IsNullOrEmpty(icon) ||
                string.IsNullOrEmpty(title) ||
                string.IsNullOrEmpty(description) ||
                string.IsNullOrEmpty(type) ||
                tier == null ||
                !tier.HasValue)
            {
                return(String.Format("giveachievement --player=player --type=type --tier={0} --icon=icon --title=title --description=description",
                                     String.Join("|", Enum.GetNames(typeof(AchievementTier)))));
            }

            ApiResponse <dynamic> response = ApiCaller.GiveAchievement(playerName, tier.Value, type, icon, title, description);

            return(response.Success ? "OK!" : response.AllErrorMessages);
        }
Пример #6
0
        public string Search(Session session, String[] parms)
        {
            bool   help       = false;
            string playerName = null;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "o|player=", v => playerName = v.TrimMatchingQuotes() },
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help || (string.IsNullOrEmpty(playerName)))
            {
                return(String.Format("playersearch --player=name|emailaddress"));
            }

            ApiResponse <dynamic> response = ApiCaller.PlayerSearch(playerName);

            if (!response.Success)
            {
                return(response.AllErrorMessages);
            }

            try
            {
                return(String.Join("\n", response.Data.players));
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Пример #7
0
        public string RenamePlayer(Session session, string[] parms)
        {
            bool   help          = false;
            string playerName    = string.Empty;
            string newPlayerName = string.Empty;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "player=", v => playerName = v.TrimMatchingQuotes() },
                    { "newname=", v => newPlayerName = v.TrimMatchingQuotes() }
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help || string.IsNullOrEmpty(playerName) || string.IsNullOrEmpty(newPlayerName))
            {
                return("renameplayer --player=player --newname=name");
            }

            uint playerId;
            var  foundLocally = world.FindPlayerId(playerName, out playerId);

            ApiResponse <dynamic> response = ApiCaller.RenamePlayer(playerName, newPlayerName);

            if (!response.Success)
            {
                return(response.AllErrorMessages);
            }

            if (!foundLocally)
            {
                return("Player not found on this server but renamed on main site");
            }

            IPlayer player;

            return(locker.Lock(playerId, out player).Do(() =>
            {
                if (player == null)
                {
                    return "Player not found";
                }

                if (player.Session != null)
                {
                    try
                    {
                        player.Session.CloseSession();
                    }
                    catch (Exception)
                    {
                    }
                }

                player.Name = newPlayerName;
                dbManager.Save(player);

                return "OK!";
            }));
        }