Skip to content

Commit

Permalink
added more checks and messages/notifications to kicking player actions
Browse files Browse the repository at this point in the history
  • Loading branch information
TomGrobbe committed May 23, 2018
1 parent 0a83cbf commit 93c8c8d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
56 changes: 33 additions & 23 deletions vMenu/CommonFunctions.cs
Expand Up @@ -329,38 +329,48 @@ public async void TeleportToWp()
/// <param name="reason"></param>
public async void KickPlayer(Player player, bool askUserForReason, string providedReason = "You have been kicked.")
{
// Default kick reason.
var defaultReason = "You have been kicked.";
var cancel = false;
// If we need to ask for the user's input and the default reason is the same as the provided reason, get the user input..
if (askUserForReason && providedReason == defaultReason)
if (player != null)
{
var userInput = await GetUserInput("Enter Kick Message", "", 100);
// If the input is not invalid, set the kick reason to the user's custom message.
if (userInput != "NULL")
// Default kick reason.
string defaultReason = "You have been kicked.";
bool cancel = false;
// If we need to ask for the user's input and the default reason is the same as the provided reason, get the user input..
if (askUserForReason && providedReason == defaultReason)
{
defaultReason += $" Reason: {userInput}";
string userInput = await GetUserInput("Enter Kick Message", "", 100) ?? "NULL";
// If the input is not invalid, set the kick reason to the user's custom message.
if (userInput != "NULL")
{
defaultReason += $" Reason: {userInput}";
}
else
{
cancel = true;
Notify.Error("An invalid kick reason was provided. Action cancelled.", true, true);
return;
}
}
// If the provided reason is not the same as the default reason, set the kick reason to the provided reason.
else if (providedReason != defaultReason)
{
defaultReason = providedReason;
}

// Kick the player using the specified reason.
if (!cancel)
{
TriggerServerEvent("vMenu:KickPlayer", player.ServerId, defaultReason);
Log($"Attempting to kick player {player.Name} (server id: {player.ServerId}, client id: {player.Handle}).");
}
else
{
cancel = true;
return;
Notify.Error("The kick action was cancelled because the kick reason was invalid.", true, true);
}
}
// If the provided reason is not the same as the default reason, set the kick reason to the provided reason.
else if (providedReason != defaultReason)
{
defaultReason = providedReason;
}
// Otherwise, don't change anything.


// Kick the player using the specified reason.
if (!cancel)
else
{
TriggerServerEvent("vMenu:KickPlayer", player.ServerId, defaultReason);
Notify.Error("The selected player is somehow invalid, action aborted.", true, true);
}

}
#endregion

Expand Down
6 changes: 5 additions & 1 deletion vMenuServer/MainServer.cs
Expand Up @@ -577,13 +577,17 @@ private void KickPlayer([FromSource] Player source, int target, string kickReaso
if (!IsPlayerAceAllowed(targetPlayer.Handle, "vMenu.DontKickMe"))
{
TriggerEvent("vMenu:KickSuccessful", source.Name, kickReason, targetPlayer.Name);

KickLog($"Player: {source.Name} has kicked: {targetPlayer.Name} for: {kickReason}.");
TriggerClientEvent(player: source, eventName: "vMenu:Notify", args: $"The target player (<C>{targetPlayer.Name}</C>) has been kicked.");

// Kick the player from the server using the specified reason.
DropPlayer(targetPlayer.Handle, kickReason);
KickLog($"Player: {source.Name} has kicked: {targetPlayer.Name} for: {kickReason}.");
return;
}
// Trigger the client event on the source player to let them know that kicking this player is not allowed.
TriggerClientEvent(player: source, eventName: "vMenu:Notify", args: "Sorry, this player can ~r~not ~w~be kicked.");
return;
}
TriggerClientEvent(player: source, eventName: "vMenu:Notify", args: "An unknown error occurred. Report it here: vespura.com/vmenu");
}
Expand Down

0 comments on commit 93c8c8d

Please sign in to comment.