Added KickClient() native. This is so that the "Kicked from console" string doesn't appear in the disconnect reason.
authorScott Ehlert <ds@alliedmods.net>
Wed Jun 20 11:06:58 2007 +0000 (2007-06-20)
changeset 99277133031b0d2
parent 991 097ac66fb60f
child 993 05bbbe7ca77e
Added KickClient() native. This is so that the "Kicked from console" string doesn't appear in the disconnect reason.
core/smn_player.cpp
plugins/include/clients.inc
     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  };
     2.1 --- a/plugins/include/clients.inc	Wed Jun 20 11:03:06 2007 +0000
     2.2 +++ b/plugins/include/clients.inc	Wed Jun 20 11:06:58 2007 +0000
     2.3 @@ -494,3 +494,15 @@
     2.4   * @error				Returns 0 if invalid userid.
     2.5   */
     2.6  native GetClientOfUserId(userid);
     2.7 +
     2.8 +/**
     2.9 + * Disconnects a client from the server.
    2.10 + *
    2.11 + * @param client		Client index.
    2.12 + * @param format		Optional formatting rules for disconnect reason.
    2.13 + *                      Note that a period is automatically appended to the string by the engine.
    2.14 + * @param ...			Variable number of format parameters.
    2.15 + * @noreturn
    2.16 + * @error				Invalid client index, or client not connected.
    2.17 + */
    2.18 +native DisconnectClient(client, const String:format[]="", any:...);