1
0
mirror of https://github.com/Mauler125/r5sdk.git synced 2025-02-09 19:15:03 +01:00

Add reason parameter to kick/ban commands

Reason parameters are optional. For scripts, to use the default message, pass in an empty string. The function for the script system should be centralized soon to avoid more duplicate code.
This commit is contained in:
Amos 2023-06-20 08:44:03 +02:00
parent 6361e64b5c
commit ac4ab6aa1a
4 changed files with 44 additions and 16 deletions
r5dev
common
game/shared
networksystem
vscript

@ -118,7 +118,8 @@ void Host_Kick_f(const CCommand& args)
return;
}
g_pBanSystem->KickPlayerByName(args.Arg(1));
g_pBanSystem->KickPlayerByName(args.Arg(1),
args.ArgC() > 2 ? args.Arg(2) : nullptr);
}
/*
@ -133,7 +134,8 @@ void Host_KickID_f(const CCommand& args)
return;
}
g_pBanSystem->KickPlayerById(args.Arg(1));
g_pBanSystem->KickPlayerById(args.Arg(1),
args.ArgC() > 2 ? args.Arg(2) : nullptr);
}
/*
@ -148,7 +150,8 @@ void Host_Ban_f(const CCommand& args)
return;
}
g_pBanSystem->BanPlayerByName(args.Arg(1));
g_pBanSystem->BanPlayerByName(args.Arg(1),
args.ArgC() > 2 ? args.Arg(2) : nullptr);
}
/*
@ -161,7 +164,8 @@ void Host_BanID_f(const CCommand& args)
if (args.ArgC() < 2)
return;
g_pBanSystem->BanPlayerById(args.Arg(1));
g_pBanSystem->BanPlayerById(args.Arg(1),
args.ArgC() > 2 ? args.Arg(2) : nullptr);
}
/*

@ -110,7 +110,13 @@ namespace VScriptCode
SQRESULT KickPlayerByName(HSQUIRRELVM v)
{
SQChar* playerName = sq_getstring(v, 1);
g_pBanSystem->KickPlayerByName(playerName);
SQChar* reason = sq_getstring(v, 2);
// Discard empty strings, this will use the default message instead.
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->KickPlayerByName(playerName, reason);
return SQ_OK;
}
@ -121,7 +127,13 @@ namespace VScriptCode
SQRESULT KickPlayerById(HSQUIRRELVM v)
{
SQChar* playerHandle = sq_getstring(v, 1);
g_pBanSystem->KickPlayerById(playerHandle);
SQChar* reason = sq_getstring(v, 2);
// Discard empty strings, this will use the default message instead.
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->KickPlayerById(playerHandle, reason);
return SQ_OK;
}
@ -132,7 +144,13 @@ namespace VScriptCode
SQRESULT BanPlayerByName(HSQUIRRELVM v)
{
SQChar* playerName = sq_getstring(v, 1);
g_pBanSystem->BanPlayerByName(playerName);
SQChar* reason = sq_getstring(v, 2);
// Discard empty strings, this will use the default message instead.
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->BanPlayerByName(playerName, reason);
return SQ_OK;
}
@ -143,7 +161,13 @@ namespace VScriptCode
SQRESULT BanPlayerById(HSQUIRRELVM v)
{
SQChar* playerHandle = sq_getstring(v, 1);
g_pBanSystem->BanPlayerById(playerHandle);
SQChar* reason = sq_getstring(v, 2);
// Discard empty strings, this will use the default message instead.
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->BanPlayerById(playerHandle, reason);
return SQ_OK;
}

@ -200,7 +200,7 @@ void CBanSystem::KickPlayerByName(const char* playerName, const char* reason)
if (!VALID_CHARSTAR(playerName))
return;
AuthorPlayerByName(playerName, false);
AuthorPlayerByName(playerName, false, reason);
}
//-----------------------------------------------------------------------------
@ -213,7 +213,7 @@ void CBanSystem::KickPlayerById(const char* playerHandle, const char* reason)
if (!VALID_CHARSTAR(playerHandle))
return;
AuthorPlayerById(playerHandle, false);
AuthorPlayerById(playerHandle, false, reason);
}
//-----------------------------------------------------------------------------
@ -226,7 +226,7 @@ void CBanSystem::BanPlayerByName(const char* playerName, const char* reason)
if (!VALID_CHARSTAR(playerName))
return;
AuthorPlayerByName(playerName, true);
AuthorPlayerByName(playerName, true, reason);
}
//-----------------------------------------------------------------------------
@ -239,7 +239,7 @@ void CBanSystem::BanPlayerById(const char* playerHandle, const char* reason)
if (!VALID_CHARSTAR(playerHandle))
return;
AuthorPlayerById(playerHandle, true);
AuthorPlayerById(playerHandle, true, reason);
}
//-----------------------------------------------------------------------------

@ -27,13 +27,13 @@ void Script_RegisterServerFunctions(CSquirrelVM* s)
s->RegisterFunction("GetAvailableMaps", "Script_GetAvailableMaps", "Gets an array of all available maps", "array< string >", "", &VScriptCode::SHARED::GetAvailableMaps);
s->RegisterFunction("GetAvailablePlaylists", "Script_GetAvailablePlaylists", "Gets an array of all available playlists", "array< string >", "", &VScriptCode::SHARED::GetAvailablePlaylists);
s->RegisterFunction("KickPlayerByName", "Script_KickPlayerByName", "Kicks a player from the server by name", "void", "string", &VScriptCode::SHARED::KickPlayerByName);
s->RegisterFunction("KickPlayerById", "Script_KickPlayerById", "Kicks a player from the server by handle or nucleus id", "void", "string", &VScriptCode::SHARED::KickPlayerById);
s->RegisterFunction("KickPlayerByName", "Script_KickPlayerByName", "Kicks a player from the server by name", "void", "string, string", &VScriptCode::SHARED::KickPlayerByName);
s->RegisterFunction("KickPlayerById", "Script_KickPlayerById", "Kicks a player from the server by handle or nucleus id", "void", "string, string", &VScriptCode::SHARED::KickPlayerById);
s->RegisterFunction("BanPlayerByName", "Script_BanPlayerByName", "Bans a player from the server by name", "void", "string", &VScriptCode::SHARED::BanPlayerByName);
s->RegisterFunction("BanPlayerById", "Script_BanPlayerById", "Bans a player from the server by handle or nucleus id", "void", "string", &VScriptCode::SHARED::BanPlayerById);
s->RegisterFunction("BanPlayerById", "Script_BanPlayerById", "Bans a player from the server by handle or nucleus id", "void", "string, string", &VScriptCode::SHARED::BanPlayerById);
s->RegisterFunction("UnbanPlayer", "Script_UnbanPlayer", "Unbans a player from the server by nucleus id or ip address", "void", "string", &VScriptCode::SHARED::UnbanPlayer);
s->RegisterFunction("UnbanPlayer", "Script_UnbanPlayer", "Unbans a player from the server by nucleus id or ip address", "void", "string, string", &VScriptCode::SHARED::UnbanPlayer);
s->RegisterFunction("ShutdownHostGame", "Script_ShutdownHostGame", "Shuts the local host game down", "void", "", &VScriptCode::SHARED::ShutdownHostGame);