faluco@242: #include "CPlayerManager.h" faluco@242: faluco@260: static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params) faluco@242: { faluco@242: if (params[1]) faluco@242: { faluco@242: return g_PlayerManager.GetPlayerCount(); faluco@242: } faluco@242: faluco@242: int maxplayers = g_PlayerManager.GetMaxClients(); faluco@242: int count = 0; faluco@242: for (int i=1; i<=maxplayers; ++i) faluco@242: { faluco@242: CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(i); faluco@242: if ((pPlayer->IsPlayerConnected()) && !(pPlayer->IsPlayerInGame())) faluco@242: { faluco@242: count++; faluco@242: } faluco@242: } faluco@242: faluco@242: return (g_PlayerManager.GetPlayerCount() + count); faluco@242: } faluco@242: faluco@260: static cell_t sm_GetMaxClients(IPluginContext *pCtx, const cell_t *params) faluco@242: { faluco@242: return g_PlayerManager.GetMaxClients(); faluco@242: } faluco@242: faluco@260: static cell_t sm_GetClientName(IPluginContext *pCtx, const cell_t *params) faluco@242: { faluco@242: int index = params[1]; faluco@242: if ((index < 1) || (index > g_PlayerManager.GetMaxClients())) faluco@242: { faluco@260: return pCtx->ThrowNativeError("Invalid client index %d.", index); faluco@242: } faluco@242: faluco@260: CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(index); faluco@260: if (!pPlayer->IsPlayerConnected()) faluco@260: { faluco@260: return pCtx->ThrowNativeError("Client %d is not connected.", index); faluco@260: } faluco@260: faluco@260: pCtx->StringToLocalUTF8(params[2], static_cast(params[3]), pPlayer->PlayerName(), NULL); faluco@242: return 1; faluco@242: } faluco@242: faluco@260: static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params) faluco@242: { faluco@242: int index = params[1]; faluco@242: if ((index < 1) || (index > g_PlayerManager.GetMaxClients())) faluco@242: { faluco@260: return pCtx->ThrowNativeError("Invalid client index %d.", index); faluco@242: } faluco@242: faluco@260: CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(index); faluco@260: if (!pPlayer->IsPlayerConnected()) faluco@260: { faluco@260: return pCtx->ThrowNativeError("Client %d is not connected.", index); faluco@260: } faluco@260: faluco@260: pCtx->StringToLocal(params[2], static_cast(params[3]), pPlayer->PlayerIP()); faluco@242: return 1; faluco@242: } faluco@242: faluco@260: static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) faluco@242: { faluco@242: int index = params[1]; faluco@242: if ((index < 1) || (index > g_PlayerManager.GetMaxClients())) faluco@242: { faluco@260: return pCtx->ThrowNativeError("Invalid client index %d.", index); faluco@242: } faluco@242: faluco@260: CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(index); faluco@260: if (!pPlayer->IsPlayerConnected()) faluco@260: { faluco@260: return pCtx->ThrowNativeError("Client %d is not connected.", index); faluco@260: } faluco@260: faluco@260: pCtx->StringToLocal(params[2], static_cast(params[3]), pPlayer->PlayerAuthString()); faluco@242: return 1; faluco@242: } faluco@242: faluco@260: static cell_t sm_IsPlayerConnected(IPluginContext *pCtx, const cell_t *params) faluco@242: { faluco@242: int index = params[1]; faluco@242: if ((index < 1) || (index > g_PlayerManager.GetMaxClients())) faluco@242: { faluco@260: return pCtx->ThrowNativeError("Invalid client index %d.", index); faluco@242: } faluco@242: faluco@242: return (g_PlayerManager.GetPlayerByIndex(index)->IsPlayerConnected()) ? 1 : 0; faluco@242: } faluco@242: faluco@260: static cell_t sm_IsPlayerIngame(IPluginContext *pCtx, const cell_t *params) faluco@242: { faluco@242: int index = params[1]; faluco@242: if ((index < 1) || (index > g_PlayerManager.GetMaxClients())) faluco@242: { faluco@260: return pCtx->ThrowNativeError("Invalid client index %d.", index); faluco@242: } faluco@242: faluco@242: return (g_PlayerManager.GetPlayerByIndex(index)->IsPlayerInGame()) ? 1 : 0; faluco@242: } faluco@242: faluco@260: static cell_t sm_IsPlayerAuthorized(IPluginContext *pCtx, const cell_t *params) faluco@242: { faluco@242: int index = params[1]; faluco@242: if ((index < 1) || (index > g_PlayerManager.GetMaxClients())) faluco@242: { faluco@260: return pCtx->ThrowNativeError("Invalid client index %d.", index); faluco@242: } faluco@242: faluco@242: return (g_PlayerManager.GetPlayerByIndex(index)->IsPlayerAuthorized()) ? 1 : 0; faluco@242: } faluco@242: faluco@260: static cell_t sm_IsPlayerFakeClient(IPluginContext *pCtx, const cell_t *params) faluco@242: { faluco@242: int index = params[1]; faluco@242: if ((index < 1) || (index > g_PlayerManager.GetMaxClients())) faluco@242: { faluco@260: return pCtx->ThrowNativeError("Invalid client index %d.", index); faluco@260: } faluco@260: faluco@260: CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(index); faluco@260: if (!pPlayer->IsPlayerConnected()) faluco@260: { faluco@260: return pCtx->ThrowNativeError("Client %d is not connected.", index); faluco@242: } faluco@242: faluco@260: return (pPlayer->IsPlayerFakeClient()) ? 1 : 0; faluco@260: } faluco@260: faluco@260: REGISTER_NATIVES(playernatives) faluco@260: { faluco@260: {"GetMaxClients", sm_GetMaxClients}, faluco@260: {"GetClientCount", sm_GetClientCount}, faluco@260: {"GetClientName", sm_GetClientName}, faluco@260: {"GetClientIP", sm_GetClientIP}, faluco@260: {"GetClientAuthString", sm_GetClientAuthStr}, faluco@260: {"IsPlayerConnected", sm_IsPlayerConnected}, faluco@260: {"IsPlayerInGame", sm_IsPlayerIngame}, faluco@260: {"IsPlayerAuthorized", sm_IsPlayerAuthorized}, faluco@260: {"IsPlayerFakeClient", sm_IsPlayerFakeClient}, faluco@260: {NULL, NULL} faluco@260: };