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