Skip to content

Commit

Permalink
added kick logging, requires enabled convar:
Browse files Browse the repository at this point in the history
`set vMenuLogKickActions "true"`
logs kick actions to "/resources/vMenu/vmenu.log" (bans will now also be logged to that file)
  • Loading branch information
TomGrobbe committed May 7, 2018
1 parent eb7e3d8 commit 88e55e2
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions vMenuServer/MainServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ public MainServer()
{
new PlayerList()[source].TriggerEvent("chatMessage", $"vMenu Debug mode is now set to: {DebugMode}.");
}
}
}
else
Expand All @@ -323,7 +322,8 @@ public MainServer()

if (GetCurrentResourceName() != "vMenu")
{
Exception InvalidNameException = new Exception("\r\n\r\n[vMenu] INSTALLATION ERROR!\r\nThe name of the resource is not valid. Please change the folder name from '" + GetCurrentResourceName() + "' to 'vMenu' (case sensitive) instead!\r\n\r\n\r\n");
Exception InvalidNameException = new Exception("\r\n\r\n[vMenu] INSTALLATION ERROR!\r\nThe name of the resource is not valid. " +
"Please change the folder name from '" + GetCurrentResourceName() + "' to 'vMenu' (case sensitive) instead!\r\n\r\n\r\n");
try
{
throw InvalidNameException;
Expand Down Expand Up @@ -566,20 +566,16 @@ private void KickPlayer([FromSource] Player source, int target, string kickReaso
TriggerEvent("vMenu:KickSuccessful", source.Name, kickReason, targetPlayer.Name);
// 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:KickCallback", args: "Sorry, this player can ~r~not ~w~be kicked.");

return;
}
else
{
BanManager.BanCheater(new PlayerList()[target]);
}
//// If this happens, the person who thinks they're funny knows exactly what this is for.
//TriggerClientEvent(player: source, eventName: "vMenu:KickCallback", args: "Have a nice day :)");
//// todo: Make sure they enjoy their day.
}

/// <summary>
Expand Down Expand Up @@ -725,5 +721,28 @@ private string GetRealAceName(string inputString)
return outputString;
}
#endregion


/// <summary>
/// If enabled using convars, will log all kick actions to the server console as well as an external file.
/// </summary>
/// <param name="kickLogMesage"></param>
private static void KickLog(string kickLogMesage)
{
if (GetConvar("vMenuLogKickActions", "false") == "true")
{
string file = LoadResourceFile(GetCurrentResourceName(), "vmenu.log") ?? "";
DateTime date = DateTime.Now;
string formattedDate = (date.Day < 10 ? "0" : "") + date.Day + "-" +
(date.Month < 10 ? "0" : "") + date.Month + "-" +
(date.Year < 10 ? "0" : "") + date.Year + " " +
(date.Hour < 10 ? "0" : "") + date.Hour + ":" +
(date.Minute < 10 ? "0" : "") + date.Minute + ":" +
(date.Second < 10 ? "0" : "") + date.Second;
string outputFile = file + $"[\t{formattedDate}\t] [KICK ACTION] {kickLogMesage}\n";
SaveResourceFile(GetCurrentResourceName(), "vmenu.log", outputFile, outputFile.Length);
Debug.Write(kickLogMesage + "\n");
}
}
}
}

0 comments on commit 88e55e2

Please sign in to comment.