core/smn_player.cpp
changeset 280 f2a82da2facc
parent 260 110d1d014b0c
child 351 7c219cde57e7
     1.1 --- a/core/smn_player.cpp	Sun Jan 07 08:55:02 2007 +0000
     1.2 +++ b/core/smn_player.cpp	Wed Jan 10 23:49:22 2007 +0000
     1.3 @@ -1,4 +1,5 @@
     1.4  #include "CPlayerManager.h"
     1.5 +#include "sm_stringutil.h"
     1.6  
     1.7  static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params)
     1.8  {
     1.9 @@ -58,7 +59,15 @@
    1.10  		return pCtx->ThrowNativeError("Client %d is not connected.", index);
    1.11  	}
    1.12  
    1.13 -	pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), pPlayer->PlayerIP());
    1.14 +	char buf[64], *ptr;
    1.15 +	strcpy(buf, pPlayer->PlayerIP());
    1.16 +
    1.17 +	if (params[4] && (ptr = strchr(buf, ':')))
    1.18 +	{
    1.19 +		*ptr = '\0';
    1.20 +	}
    1.21 +
    1.22 +	pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), buf);
    1.23  	return 1;
    1.24  }
    1.25  
    1.26 @@ -130,6 +139,52 @@
    1.27  	return (pPlayer->IsPlayerFakeClient()) ? 1 : 0;
    1.28  }
    1.29  
    1.30 +static cell_t sm_PrintToServer(IPluginContext *pCtx, const cell_t *params)
    1.31 +{
    1.32 +	char buffer[1024];
    1.33 +	char *fmt;
    1.34 +	int arg = 2;
    1.35 +
    1.36 +	pCtx->LocalToString(params[1], &fmt);
    1.37 +	size_t res = atcprintf(buffer, sizeof(buffer)-2, fmt, pCtx, params, &arg);
    1.38 +
    1.39 +	buffer[res++] = '\n';
    1.40 +	buffer[res] = '\0';
    1.41 +
    1.42 +	META_CONPRINT(buffer);
    1.43 +
    1.44 +	return 1;
    1.45 +}
    1.46 +
    1.47 +static cell_t sm_PrintToConsole(IPluginContext *pCtx, const cell_t *params)
    1.48 +{
    1.49 +	int index = params[1];
    1.50 +	if ((index < 1) || (index > g_PlayerManager.GetMaxClients()))
    1.51 +	{
    1.52 +		return pCtx->ThrowNativeError("Invalid client index %d.", index);
    1.53 +	}
    1.54 +
    1.55 +	CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(index);
    1.56 +	if (!pPlayer->IsPlayerInGame())
    1.57 +	{
    1.58 +		return pCtx->ThrowNativeError("Client %d is not in game.", index);
    1.59 +	}
    1.60 +
    1.61 +	char buffer[1024];
    1.62 +	char *fmt;
    1.63 +	int arg = 3;
    1.64 +
    1.65 +	pCtx->LocalToString(params[2], &fmt);
    1.66 +	size_t res = atcprintf(buffer, sizeof(buffer)-2, fmt, pCtx, params, &arg);
    1.67 +
    1.68 +	buffer[res++] = '\n';
    1.69 +	buffer[res] = '\0';
    1.70 +
    1.71 +	engine->ClientPrintf(pPlayer->GetPlayerEdict(), buffer);
    1.72 +
    1.73 +	return 1;
    1.74 +}
    1.75 +
    1.76  REGISTER_NATIVES(playernatives)
    1.77  {
    1.78  	{"GetMaxClients",			sm_GetMaxClients},
    1.79 @@ -141,5 +196,7 @@
    1.80  	{"IsPlayerInGame",			sm_IsPlayerIngame},
    1.81  	{"IsPlayerAuthorized",		sm_IsPlayerAuthorized},
    1.82  	{"IsPlayerFakeClient",		sm_IsPlayerFakeClient},
    1.83 +	{"PrintToServer",			sm_PrintToServer},
    1.84 +	{"PrintToConsole",			sm_PrintToConsole},
    1.85  	{NULL,						NULL}
    1.86  };
    1.87 \ No newline at end of file