core/smn_player.cpp
author David Anderson <dvander@alliedmods.net>
Tue Jan 02 01:44:46 2007 +0000 (2007-01-02)
changeset 259 ca9b124a2544
parent 249 72c84d08c45d
child 260 110d1d014b0c
permissions -rw-r--r--
fixed various issues in the handle system with cloning
fixed plugins being able to free each other's handles
     1 #include "CPlayerManager.h"
     2 
     3 //:TODO: register these and use the same capitalization conventions as the natives
     4 
     5 static cell_t sm_getclientcount(IPluginContext *pCtx, const cell_t *params)
     6 {
     7 	if (params[1])
     8 	{
     9 		return g_PlayerManager.GetPlayerCount();
    10 	}
    11 
    12 	int maxplayers = g_PlayerManager.GetMaxClients();
    13 	int count = 0;
    14 	for (int i=1; i<=maxplayers; ++i)
    15 	{
    16 		CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(i);
    17 		if ((pPlayer->IsPlayerConnected()) && !(pPlayer->IsPlayerInGame()))
    18 		{
    19 			count++;
    20 		}
    21 	}
    22 
    23 	return (g_PlayerManager.GetPlayerCount() + count);
    24 }
    25 
    26 static cell_t sm_getmaxclients(IPluginContext *pCtx, const cell_t *params)
    27 {
    28 	return g_PlayerManager.GetMaxClients();
    29 }
    30 
    31 static cell_t sm_getclientname(IPluginContext *pCtx, const cell_t *params)
    32 {
    33 	int index = params[1];
    34 	if ((index < 1) || (index > g_PlayerManager.GetMaxClients()))
    35 	{
    36 		//:TODO: runtime error
    37 	}
    38 
    39 	pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), g_PlayerManager.GetPlayerByIndex(index)->PlayerName(), NULL);
    40 	return 1;
    41 }
    42 
    43 static cell_t sm_getclientip(IPluginContext *pCtx, const cell_t *params)
    44 {
    45 	int index = params[1];
    46 	if ((index < 1) || (index > g_PlayerManager.GetMaxClients()))
    47 	{
    48 		//:TODO: runtime error
    49 	}
    50 
    51 	pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), g_PlayerManager.GetPlayerByIndex(index)->PlayerIP());
    52 	return 1;
    53 }
    54 
    55 static cell_t sm_getclientauthstr(IPluginContext *pCtx, const cell_t *params)
    56 {
    57 	int index = params[1];
    58 	if ((index < 1) || (index > g_PlayerManager.GetMaxClients()))
    59 	{
    60 		//:TODO: runtime error
    61 	}
    62 
    63 	pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), g_PlayerManager.GetPlayerByIndex(index)->PlayerAuthString());
    64 	return 1;
    65 }
    66 
    67 static cell_t sm_isplayerconnected(IPluginContext *pCtx, const cell_t *params)
    68 {
    69 	int index = params[1];
    70 	if ((index < 1) || (index > g_PlayerManager.GetMaxClients()))
    71 	{
    72 		//:TODO: runtime error
    73 	}
    74 
    75 	return (g_PlayerManager.GetPlayerByIndex(index)->IsPlayerConnected()) ? 1 : 0;
    76 }
    77 
    78 static cell_t sm_isplayeringame(IPluginContext *pCtx, const cell_t *params)
    79 {
    80 	int index = params[1];
    81 	if ((index < 1) || (index > g_PlayerManager.GetMaxClients()))
    82 	{
    83 		//:TODO: runtime error
    84 	}
    85 
    86 	return (g_PlayerManager.GetPlayerByIndex(index)->IsPlayerInGame()) ? 1 : 0;
    87 }
    88 
    89 static cell_t sm_isplayerauthorized(IPluginContext *pCtx, const cell_t *params)
    90 {
    91 	int index = params[1];
    92 	if ((index < 1) || (index > g_PlayerManager.GetMaxClients()))
    93 	{
    94 		//:TODO: runtime error
    95 	}
    96 
    97 	return (g_PlayerManager.GetPlayerByIndex(index)->IsPlayerAuthorized()) ? 1 : 0;
    98 }
    99 
   100 static cell_t sm_isplayerfakeclient(IPluginContext *pCtx, const cell_t *params)
   101 {
   102 	int index = params[1];
   103 	if ((index < 1) || (index > g_PlayerManager.GetMaxClients()))
   104 	{
   105 		//:TODO: runtime error
   106 	}
   107 
   108 	return (g_PlayerManager.GetPlayerByIndex(index)->IsPlayerFakeClient()) ? 1 : 0;
   109 }