Skip to content

Commit

Permalink
Added ban and temp ban features
Browse files Browse the repository at this point in the history
  • Loading branch information
TomGrobbe committed Apr 13, 2018
1 parent ad82157 commit 0f811cc
Show file tree
Hide file tree
Showing 8 changed files with 434 additions and 13 deletions.
10 changes: 7 additions & 3 deletions PERMISSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
1. __\*__ The `Default (allowed/denied)` values are based on the assumption that you use the default permissions file included with the menu, and you've granted yourself no special permissions or added yourself to any of the admin/moderator groups. If you **DON'T** use the default permissions file, then every option will be **DENIED** by default.
2. __\*\*__ These options are only allowed by default for the "Moderators" / "Admins" groups in the provided permissions file with this resource.
3. __\*\*\*__ When spawning a car using the `Spawn By Name` button, it will always check to see if you have permission for that specific vehicle's class. eg: If you don't have permission to spawn cars from the `Super` class, trying to spawn an `adder` using the `Spawn By Name` button won't work.
4. __\*\*\*\*__ Only admins are allowed to use this by default.

|Permission|Description|Default[\*](#global-permissions)|
|:-|:-|:-|
|`vMenu.Everything`|Grants access to everything, not recommended to give this out.|Denied|
|`vMenu.DontKickMe`|Prevents this player from being kicked.|Denied|
|`vMenu.DontBanMe`|Prevents this player from being banned.|Denied|
|`vMenu.NoClip`|Allows the user to use the NoClip feature.|Allowed|

## Online Players
Expand All @@ -23,9 +25,11 @@
|`vMenu.OnlinePlayers.Teleport`|Allows you to teleport to another player.|Allowed|
|`vMenu.OnlinePlayers.Waypoint`|Allows you to set a waypoint to another player.|Allowed|
|`vMenu.OnlinePlayers.Spectate`|Allows you to spectate another player.|Allowed|
|`vMenu.OnlinePlayers.Summon`|Allows you to summon/teleport another player to you.|Denied|
|`vMenu.OnlinePlayers.Kill`|Allows you to kill another player by pressing a button. Dam, you're very cruel.|Denied|
|`vMenu.OnlinePlayers.Kick`|Allows you to kick another player from the server.|Denied|
|`vMenu.OnlinePlayers.Summon`|Allows you to summon/teleport another player to you. (Default: moderators only)|Denied|
|`vMenu.OnlinePlayers.Kill`|Allows you to kill another player by pressing a button. Dam, you're very cruel. (Default: moderators only)|Denied|
|`vMenu.OnlinePlayers.Kick`|Allows you to kick another player from the server. (Default: moderators only)|Denied|
|`vMenu.OnlinePlayers.TempBan`|Allows you to ban the player from the server for a custom amount of time, max 1 month. (Default: moderators only)|Denied\*|
|`vMenu.OnlinePlayers.PermBan`|Allows you to ban the player from the server forever. (Default: admin only)|Denied\*\*\*\*|

## Player Options

Expand Down
42 changes: 42 additions & 0 deletions vMenu/CommonFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,48 @@ public async void KickPlayer(Player player, bool askUserForReason, string provid
}
#endregion

#region (Temp) Ban Player
/// <summary>
/// Bans the specified player.
/// </summary>
/// <param name="player">Player to ban.</param>
/// <param name="forever">Ban forever or ban temporarily.</param>
public async void BanPlayer(Player player, bool forever)
{
string banReason = await GetUserInput("Enter Ban Reason", "Banned by staff", 200);
if (banReason != "" && banReason != null && banReason.Length > 1)
{
if (forever)
{
TriggerServerEvent("vMenu.PermBanPlayer", player.ServerId, banReason);
}
else
{
string banDurationHours = await GetUserInput("Ban Duration (in hours) Max: 720 (1 month)", "1.5", 10);
if (double.TryParse(banDurationHours, out double banHours))
{
TriggerServerEvent("vMenu.TempBanPlayer", player.ServerId, banHours, banReason);
}
else
{
if (int.TryParse(banDurationHours, out int banHoursInt))
{
TriggerServerEvent("vMenu.TempBanPlayer", player.ServerId, (double)banHoursInt, banReason);
}
else
{
Notify.Error(CommonErrors.InvalidInput);
}
}
}
}
else
{
Notify.Error(CommonErrors.InvalidInput);
}
}
#endregion

#region Kill Player
/// <summary>
/// Kill player
Expand Down
6 changes: 4 additions & 2 deletions vMenu/PermissionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum Permission
DontKickMe,
NoClip,

// Onlie Players
// Online Players
OPMenu,
OPAll,
OPTeleport,
Expand All @@ -23,6 +23,8 @@ public enum Permission
OPSummon,
OPKill,
OPKick,
OPPermBan,
OPTempBan,

// Player Options
POMenu,
Expand Down Expand Up @@ -143,7 +145,7 @@ public enum Permission
MSDeathNotifs,
MSNightVision,
MSThermalVision,



// Voice Chat
Expand Down
28 changes: 25 additions & 3 deletions vMenu/menus/OnlinePlayers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public void UpdatePlayerlist()
Player player = new Player(int.Parse(item.Description.Substring(1, 2).ToString()));
// Create the menu for the player & set the width offset.
UIMenu PlayerMenu = new UIMenu(player.Name, "[" + (player.Handle < 10 ? "0" : "") + player.Handle + "] " + player.Name + " (Server ID: " + player.ServerId + ")", true)
UIMenu PlayerMenu = new UIMenu(player.Name, "[" + (player.Handle < 10 ? "0" : "") + player.Handle + "] " + player.Name +
" (Server ID: " + player.ServerId + ")", true)
{
ScaleWithSafezone = false,
MouseControlsEnabled = false,
Expand All @@ -88,9 +89,14 @@ public void UpdatePlayerlist()
summonBtn.SetRightBadge(UIMenuItem.BadgeStyle.Alert);
UIMenuItem killBtn = new UIMenuItem("Kill Player", "Kill the selected player! Why are you so cruel :(");
killBtn.SetRightBadge(UIMenuItem.BadgeStyle.Alert);
UIMenuItem kickPlayerBtn = new UIMenuItem("~r~Kick Player", "~r~Kick~s~ this player from the server, you need to specify a reason otherwise the kick will be cancelled.");
UIMenuItem kickPlayerBtn = new UIMenuItem("~r~Kick Player", "~r~Kick~s~ this player from the server, you need to specify a reason " +
"otherwise the kick will be cancelled.");
kickPlayerBtn.SetRightBadge(UIMenuItem.BadgeStyle.Alert);
UIMenuItem permBanBtn = new UIMenuItem("~r~Ban Player", "Ban the player from the server forever.");
permBanBtn.SetRightBadge(UIMenuItem.BadgeStyle.Alert);
UIMenuItem tempBanBtn = new UIMenuItem("~r~Tempban Player", "Ban the player from the server for the specified amount of hours. " +
"The player will be able to rejoin after the ban expires.");
tempBanBtn.SetRightBadge(UIMenuItem.BadgeStyle.Alert);
// Add all buttons to the player options submenu. Keeping permissions in mind.
if (cf.IsAllowed(Permission.OPTeleport))
Expand Down Expand Up @@ -118,6 +124,14 @@ public void UpdatePlayerlist()
{
PlayerMenu.AddItem(kickPlayerBtn);
}
if (cf.IsAllowed(Permission.OPTempBan))
{
PlayerMenu.AddItem(tempBanBtn);
}
if (cf.IsAllowed(Permission.OPPermBan))
{
PlayerMenu.AddItem(permBanBtn);
}
// Add the player menu to the menu pool.
Expand Down Expand Up @@ -196,6 +210,14 @@ public void UpdatePlayerlist()
menu.RefreshIndex();
menu.UpdateScaleform();
}
else if (item2 == tempBanBtn)
{
cf.BanPlayer(player: player, forever: false);
}
else if (item2 == permBanBtn)
{
cf.BanPlayer(player: player, forever: true);
}
};
// Reopen the playerlist menu when a player specific menu is closed.
Expand Down
Loading

0 comments on commit 0f811cc

Please sign in to comment.