Registered player and float natives.
Added error strings to these natives. --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40265
This commit is contained in:
+59
-23
@@ -1,8 +1,6 @@
|
||||
#include "CPlayerManager.h"
|
||||
|
||||
//:TODO: register these and use the same capitalization conventions as the natives
|
||||
|
||||
static cell_t sm_getclientcount(IPluginContext *pCtx, const cell_t *params)
|
||||
static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
if (params[1])
|
||||
{
|
||||
@@ -23,87 +21,125 @@ static cell_t sm_getclientcount(IPluginContext *pCtx, const cell_t *params)
|
||||
return (g_PlayerManager.GetPlayerCount() + count);
|
||||
}
|
||||
|
||||
static cell_t sm_getmaxclients(IPluginContext *pCtx, const cell_t *params)
|
||||
static cell_t sm_GetMaxClients(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
return g_PlayerManager.GetMaxClients();
|
||||
}
|
||||
|
||||
static cell_t sm_getclientname(IPluginContext *pCtx, const cell_t *params)
|
||||
static cell_t sm_GetClientName(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
int index = params[1];
|
||||
if ((index < 1) || (index > g_PlayerManager.GetMaxClients()))
|
||||
{
|
||||
//:TODO: runtime error
|
||||
return pCtx->ThrowNativeError("Invalid client index %d.", index);
|
||||
}
|
||||
|
||||
pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), g_PlayerManager.GetPlayerByIndex(index)->PlayerName(), NULL);
|
||||
CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(index);
|
||||
if (!pPlayer->IsPlayerConnected())
|
||||
{
|
||||
return pCtx->ThrowNativeError("Client %d is not connected.", index);
|
||||
}
|
||||
|
||||
pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pPlayer->PlayerName(), NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t sm_getclientip(IPluginContext *pCtx, const cell_t *params)
|
||||
static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
int index = params[1];
|
||||
if ((index < 1) || (index > g_PlayerManager.GetMaxClients()))
|
||||
{
|
||||
//:TODO: runtime error
|
||||
return pCtx->ThrowNativeError("Invalid client index %d.", index);
|
||||
}
|
||||
|
||||
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), g_PlayerManager.GetPlayerByIndex(index)->PlayerIP());
|
||||
CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(index);
|
||||
if (!pPlayer->IsPlayerConnected())
|
||||
{
|
||||
return pCtx->ThrowNativeError("Client %d is not connected.", index);
|
||||
}
|
||||
|
||||
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), pPlayer->PlayerIP());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t sm_getclientauthstr(IPluginContext *pCtx, const cell_t *params)
|
||||
static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
int index = params[1];
|
||||
if ((index < 1) || (index > g_PlayerManager.GetMaxClients()))
|
||||
{
|
||||
//:TODO: runtime error
|
||||
return pCtx->ThrowNativeError("Invalid client index %d.", index);
|
||||
}
|
||||
|
||||
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), g_PlayerManager.GetPlayerByIndex(index)->PlayerAuthString());
|
||||
CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(index);
|
||||
if (!pPlayer->IsPlayerConnected())
|
||||
{
|
||||
return pCtx->ThrowNativeError("Client %d is not connected.", index);
|
||||
}
|
||||
|
||||
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), pPlayer->PlayerAuthString());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t sm_isplayerconnected(IPluginContext *pCtx, const cell_t *params)
|
||||
static cell_t sm_IsPlayerConnected(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
int index = params[1];
|
||||
if ((index < 1) || (index > g_PlayerManager.GetMaxClients()))
|
||||
{
|
||||
//:TODO: runtime error
|
||||
return pCtx->ThrowNativeError("Invalid client index %d.", index);
|
||||
}
|
||||
|
||||
return (g_PlayerManager.GetPlayerByIndex(index)->IsPlayerConnected()) ? 1 : 0;
|
||||
}
|
||||
|
||||
static cell_t sm_isplayeringame(IPluginContext *pCtx, const cell_t *params)
|
||||
static cell_t sm_IsPlayerIngame(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
int index = params[1];
|
||||
if ((index < 1) || (index > g_PlayerManager.GetMaxClients()))
|
||||
{
|
||||
//:TODO: runtime error
|
||||
return pCtx->ThrowNativeError("Invalid client index %d.", index);
|
||||
}
|
||||
|
||||
return (g_PlayerManager.GetPlayerByIndex(index)->IsPlayerInGame()) ? 1 : 0;
|
||||
}
|
||||
|
||||
static cell_t sm_isplayerauthorized(IPluginContext *pCtx, const cell_t *params)
|
||||
static cell_t sm_IsPlayerAuthorized(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
int index = params[1];
|
||||
if ((index < 1) || (index > g_PlayerManager.GetMaxClients()))
|
||||
{
|
||||
//:TODO: runtime error
|
||||
return pCtx->ThrowNativeError("Invalid client index %d.", index);
|
||||
}
|
||||
|
||||
return (g_PlayerManager.GetPlayerByIndex(index)->IsPlayerAuthorized()) ? 1 : 0;
|
||||
}
|
||||
|
||||
static cell_t sm_isplayerfakeclient(IPluginContext *pCtx, const cell_t *params)
|
||||
static cell_t sm_IsPlayerFakeClient(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
int index = params[1];
|
||||
if ((index < 1) || (index > g_PlayerManager.GetMaxClients()))
|
||||
{
|
||||
//:TODO: runtime error
|
||||
return pCtx->ThrowNativeError("Invalid client index %d.", index);
|
||||
}
|
||||
|
||||
return (g_PlayerManager.GetPlayerByIndex(index)->IsPlayerFakeClient()) ? 1 : 0;
|
||||
}
|
||||
CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(index);
|
||||
if (!pPlayer->IsPlayerConnected())
|
||||
{
|
||||
return pCtx->ThrowNativeError("Client %d is not connected.", index);
|
||||
}
|
||||
|
||||
return (pPlayer->IsPlayerFakeClient()) ? 1 : 0;
|
||||
}
|
||||
|
||||
REGISTER_NATIVES(playernatives)
|
||||
{
|
||||
{"GetMaxClients", sm_GetMaxClients},
|
||||
{"GetClientCount", sm_GetClientCount},
|
||||
{"GetClientName", sm_GetClientName},
|
||||
{"GetClientIP", sm_GetClientIP},
|
||||
{"GetClientAuthString", sm_GetClientAuthStr},
|
||||
{"IsPlayerConnected", sm_IsPlayerConnected},
|
||||
{"IsPlayerInGame", sm_IsPlayerIngame},
|
||||
{"IsPlayerAuthorized", sm_IsPlayerAuthorized},
|
||||
{"IsPlayerFakeClient", sm_IsPlayerFakeClient},
|
||||
{NULL, NULL}
|
||||
};
|
||||
Reference in New Issue
Block a user