Exemple #1
0
        /// <summary>
        /// Handles error messages thrown by erroneous / lack of parameters by checking a player's group permissions.
        /// </summary>
        /// <param name="ply">The player executing the command.</param>
        /// <returns>A string matching the error message.</returns>
        public static string ErrorMessage(TSPlayer ply)
        {
            string error;
            var list = new List<string>()
            {
                ply.HasPermission("key.change") ? "change" : null,
                ply.HasPermission("key.reload") ? "reload" : null,
                ply.HasPermission("key.mode") ? "mode" : null,
                "list"
            };

            string valid = String.Join("/", list.FindAll(i => i != null));
            error = String.Format("Invalid syntax! Proper syntax: {0}key <{1}> [type]", Commands.Specifier, valid);
            return error;
        }
Exemple #2
0
 /// <summary>
 /// Bans and kicks a player from the server.
 /// </summary>
 /// <param name="player">TSPlayer player</param>
 /// <param name="reason">string reason</param>
 /// <param name="force">bool force (default: false)</param>
 /// <param name="adminUserName">string adminUserName (default: null)</param>
 public bool Ban(TSPlayer player, string reason, bool force = false, string adminUserName = null)
 {
     if (!player.ConnectionAlive)
     {
         return(true);
     }
     if (force || !player.HasPermission(Permissions.immunetoban))
     {
         string ip         = player.IP;
         string uuid       = player.UUID;
         string playerName = player.Name;
         TShock.Bans.AddBan(ip, playerName, uuid, reason, false, adminUserName);
         player.Disconnect(string.Format("Banned: {0}", reason));
         string verb = force ? "force " : "";
         if (string.IsNullOrWhiteSpace(adminUserName))
         {
             TSPlayer.All.SendInfoMessage("{0} was {1}banned for '{2}'.", playerName, verb, reason);
         }
         else
         {
             TSPlayer.All.SendInfoMessage("{0} {1}banned {2} for '{3}'.", adminUserName, verb, playerName, reason);
         }
         return(true);
     }
     return(false);
 }
Exemple #3
0
 /// <summary>
 /// Kicks a player from the server..
 /// </summary>
 /// <param name="player">TSPlayer player</param>
 /// <param name="reason">string reason</param>
 /// <param name="force">bool force (default: false)</param>
 /// <param name="silent">bool silent (default: false)</param>
 /// <param name="adminUserName">string adminUserName (default: null)</param>
 /// <param name="saveSSI">bool saveSSI (default: false)</param>
 public bool Kick(TSPlayer player, string reason, bool force = false, bool silent = false, string adminUserName = null, bool saveSSI = false)
 {
     if (!player.ConnectionAlive)
     {
         return(true);
     }
     if (force || !player.HasPermission(Permissions.immunetokick))
     {
         string playerName = player.Name;
         player.SilentKickInProgress = silent;
         if (player.IsLoggedIn && saveSSI)
         {
             player.SaveServerCharacter();
         }
         player.Disconnect(string.Format("Kicked: {0}", reason));
         TShock.Log.ConsoleInfo(string.Format("Kicked {0} for : '{1}'", playerName, reason));
         string verb = force ? "force " : "";
         if (!silent)
         {
             if (string.IsNullOrWhiteSpace(adminUserName))
             {
                 Broadcast(string.Format("{0} was {1}kicked for '{2}'", playerName, verb, reason.ToLower()), Color.Green);
             }
             else
             {
                 Broadcast(string.Format("{0} {1}kicked {2} for '{3}'", adminUserName, verb, playerName, reason.ToLower()), Color.Green);
             }
         }
         return(true);
     }
     return(false);
 }
 public static bool CheckPermissions(this TShockAPI.TSPlayer player, List <string> perms)
 {
     foreach (var perm in perms)
     {
         if (player.HasPermission(perm))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #5
0
        /// <summary>CheckTilePermission - Checks to see if a player has the ability to modify a tile at a given position.</summary>
        /// <param name="player">player - The TSPlayer object.</param>
        /// <param name="tileX">tileX - The x coordinate of the tile.</param>
        /// <param name="tileY">tileY - The y coordinate of the tile.</param>
        /// <param name="paint">paint - Whether or not the tile is paint.</param>
        /// <returns>bool - True if the player should not be able to modify the tile.</returns>
        public static bool CheckTilePermission(TSPlayer player, int tileX, int tileY, bool paint = false)
        {
            if ((!paint && !player.HasPermission(Permissions.canbuild)) ||
                (paint && !player.HasPermission(Permissions.canpaint)))
            {
                if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.BPm) > 2000)
                {
                    if (paint)
                    {
                        player.SendErrorMessage("You do not have permission to paint!");
                    }
                    else
                    {
                        player.SendErrorMessage("You do not have permission to build!");
                    }
                    player.BPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                }
                return true;
            }

            if (!Regions.CanBuild(tileX, tileY, player))
            {
                if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.RPm) > 2000)
                {
                    player.SendErrorMessage("This region is protected from changes.");
                    player.RPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                }
                return true;
            }

            if (Config.DisableBuild)
            {
                if (!player.HasPermission(Permissions.antibuild))
                {
                    if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.WPm) > 2000)
                    {
                        player.SendErrorMessage("The world is protected from changes.");
                        player.WPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                    }
                    return true;
                }
            }

            if (Config.SpawnProtection)
            {
                if (!player.HasPermission(Permissions.editspawn))
                {
                    if (CheckSpawn(tileX, tileY))
                    {
                        if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.SPm) > 1000)
                        {
                            player.SendErrorMessage("Spawn is protected from changes.");
                            player.SPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                        }
                        return true;
                    }
                }
            }
            return false;
        }
Exemple #6
0
        /// <summary>CheckTilePermission - Checks to see if a player has permission to modify a tile in general.</summary>
        /// <param name="player">player - The TSPlayer object.</param>
        /// <param name="tileX">tileX - The x coordinate of the tile.</param>
        /// <param name="tileY">tileY - The y coordinate of the tile.</param>
        /// <param name="tileType">tileType - The tile type.</param>
        /// <param name="actionType">actionType - The type of edit that took place.</param>
        /// <returns>bool - True if the player should not be able to modify a tile.</returns>
        public static bool CheckTilePermission(TSPlayer player, int tileX, int tileY, short tileType, GetDataHandlers.EditAction actionType)
        {
            if (!player.HasPermission(Permissions.canbuild))
            {
                if (TShock.Config.AllowIce && actionType != GetDataHandlers.EditAction.PlaceTile)
                {
                    foreach (Point p in player.IceTiles)
                    {
                        if (p.X == tileX && p.Y == tileY && (Main.tile[p.X, p.Y].type == 0 || Main.tile[p.X, p.Y].type == 127))
                        {
                            player.IceTiles.Remove(p);
                            return false;
                        }
                    }

                    if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.BPm) > 2000)
                    {
                        player.SendErrorMessage("You do not have permission to build!");
                        player.BPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                    }
                    return true;
                }

                if (TShock.Config.AllowIce && actionType == GetDataHandlers.EditAction.PlaceTile && tileType == 127)
                {
                    player.IceTiles.Add(new Point(tileX, tileY));
                    return false;
                }

                if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.BPm) > 2000)
                {
                    player.SendErrorMessage("You do not have permission to build!");
                    player.BPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                }
                return true;
            }

            if (!Regions.CanBuild(tileX, tileY, player))
            {
                if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.RPm) > 2000)
                {
                    player.SendErrorMessage("This region is protected from changes.");
                    player.RPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                }
                return true;
            }

            if (Config.DisableBuild)
            {
                if (!player.HasPermission(Permissions.antibuild))
                {
                    if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.WPm) > 2000)
                    {
                        player.SendErrorMessage("The world is protected from changes.");
                        player.WPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                    }
                    return true;
                }
            }

            if (Config.SpawnProtection)
            {
                if (!player.HasPermission(Permissions.editspawn))
                {
                    if (CheckSpawn(tileX, tileY))
                    {
                        if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.SPm) > 2000)
                        {
                            player.SendErrorMessage("Spawn is protected from changes.");
                            player.SPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                        }
                        return true;
                    }
                }
            }
            return false;
        }