core/smn_player.cpp
changeset 992 77133031b0d2
parent 924 330f478a2d1d
child 994 a0d587e40030
     1.1 --- a/core/smn_player.cpp	Wed Jun 20 11:03:06 2007 +0000
     1.2 +++ b/core/smn_player.cpp	Wed Jun 20 11:06:58 2007 +0000
     1.3 @@ -17,8 +17,10 @@
     1.4  #include "sm_stringutil.h"
     1.5  #include "HalfLife2.h"
     1.6  #include "sourcemod.h"
     1.7 -#include <inetchannelinfo.h>
     1.8  #include "ChatTriggers.h"
     1.9 +#include "GameConfigs.h"
    1.10 +#include <inetchannel.h>
    1.11 +#include <iclient.h>
    1.12  
    1.13  ConVar sm_show_activity("sm_show_activity", "13", FCVAR_SPONLY|FCVAR_PROTECTED, "Activity display setting (see sourcemod.cfg)");
    1.14  
    1.15 @@ -917,6 +919,40 @@
    1.16  	return 1;
    1.17  }
    1.18  
    1.19 +static cell_t KickClient(IPluginContext *pContext, const cell_t *params)
    1.20 +{
    1.21 +	int client = params[1];
    1.22 +
    1.23 +	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
    1.24 +	if (!pPlayer)
    1.25 +	{
    1.26 +		return pContext->ThrowNativeError("Client %d is invalid", client);
    1.27 +	} else if (!pPlayer->IsConnected()) {
    1.28 +		return pContext->ThrowNativeError("Client %d is not connected", client);
    1.29 +	}
    1.30 +
    1.31 +	if (pPlayer->IsFakeClient())
    1.32 +	{
    1.33 +		char kickcmd[64];
    1.34 +
    1.35 +		/* :TODO: Define BotKickCmd in core.games.txt so that "bot_kick" can be used in CS:S */
    1.36 +		UTIL_Format(kickcmd, sizeof(kickcmd), "kick %s\n", pPlayer->GetName());
    1.37 +
    1.38 +		engine->ServerCommand(kickcmd);
    1.39 +		return 1;
    1.40 +	}
    1.41 +
    1.42 +	INetChannel *pNetChan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(client));
    1.43 +	IClient *pClient = static_cast<IClient *>(pNetChan->GetMsgHandler());
    1.44 +
    1.45 +	char buffer[256];
    1.46 +	g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
    1.47 +
    1.48 +	pClient->Disconnect("%s", buffer);
    1.49 +
    1.50 +	return 1;
    1.51 +}
    1.52 +
    1.53  REGISTER_NATIVES(playernatives)
    1.54  {
    1.55  	{"AddUserFlags",			AddUserFlags},
    1.56 @@ -960,5 +996,6 @@
    1.57  	{"GetClientAvgPackets",		GetAvgPackets},
    1.58  	{"GetClientOfUserId",		GetClientOfUserId},
    1.59  	{"ShowActivity",			ShowActivity},
    1.60 +	{"KickClient",				KickClient},
    1.61  	{NULL,						NULL}
    1.62  };