Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OnKickClient() forward #1749

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions core/PlayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ bool g_OnMapStarted = false;
IForward *PreAdminCheck = NULL;
IForward *PostAdminCheck = NULL;
IForward *PostAdminFilter = NULL;
IForward *OnKickClient = NULL;

const unsigned int *g_NumPlayersToAuth = NULL;
int lifestate_offset = -1;
Expand Down Expand Up @@ -203,6 +204,8 @@ void PlayerManager::OnSourceModAllInitialized()
PreAdminCheck = forwardsys->CreateForward("OnClientPreAdminCheck", ET_Event, 1, p1);
PostAdminCheck = forwardsys->CreateForward("OnClientPostAdminCheck", ET_Ignore, 1, p1);
PostAdminFilter = forwardsys->CreateForward("OnClientPostAdminFilter", ET_Ignore, 1, p1);

OnKickClient = forwardsys->CreateForward("OnKickClient", ET_Event, 2, NULL, Param_Cell, Param_String);

m_bIsListenServer = !engine->IsDedicatedServer();
m_ListenClient = 0;
Expand Down Expand Up @@ -254,6 +257,8 @@ void PlayerManager::OnSourceModShutdown()
forwardsys->ReleaseForward(PreAdminCheck);
forwardsys->ReleaseForward(PostAdminCheck);
forwardsys->ReleaseForward(PostAdminFilter);

forwardsys->ReleaseForward(OnKickClient);

delete [] m_Players;

Expand Down Expand Up @@ -2468,25 +2473,40 @@ void CPlayer::DumpAdmin(bool deleting)

void CPlayer::Kick(const char *str)
{
MarkAsBeingKicked();
IClient *pClient = GetIClient();
if (pClient == nullptr)

int userid = GetUserId();

cell_t handled = 0;

if (OnKickClient->GetFunctionCount() > 0)
{
int userid = GetUserId();
if (userid > 0)
{
char buffer[255];
ke::SafeSprintf(buffer, sizeof(buffer), "kickid %d %s\n", userid, str);
engine->ServerCommand(buffer);
}
OnKickClient->PushCell(g_Players.GetClientOfUserId(userid));
OnKickClient->PushString(str);
OnKickClient->Execute(&handled);
}
else

if (!handled)
{
MarkAsBeingKicked();

if (pClient == nullptr)
{
if (userid > 0)
{
char buffer[255];
ke::SafeSprintf(buffer, sizeof(buffer), "kickid %d %s\n", userid, str);
engine->ServerCommand(buffer);
}
}
else
{
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE
pClient->Disconnect(str);
pClient->Disconnect(str);
#else
pClient->Disconnect("%s", str);
pClient->Disconnect("%s", str);
#endif
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/basevotes.sp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public int Handler_VoteCallback(Menu menu, MenuAction action, int param1, int pa
PrintToChatAll("[SM] %t", "Kicked target", "_s", g_voteInfo[VOTE_NAME]);
LogAction(-1, voteTarget, "Vote kick successful, kicked \"%L\" (reason \"%s\")", voteTarget, g_voteArg);

ServerCommand("kickid %d \"%s\"", g_voteTarget, g_voteArg);
KickClient(voteTarget, "%s", g_voteArg);
}
}

Expand Down
9 changes: 9 additions & 0 deletions plugins/include/clients.inc
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ forward void OnClientPostAdminCheck(int client);
*/
forward void OnClientLanguageChanged(int client, int language);

/**
* Called for calls to KickClient().
*
* @param client Client being kicked.
* @param reason Reason passed via KickClient().
* @return Plugin_Handled to block the actual server kicking.
*/
forward Action OnKickClient(int client, const char[] reason);

/**
* This function is deprecated. Use the MaxClients variable instead.
*
Expand Down