|
faluco@242
|
1 |
#include "CPlayerManager.h" |
|
faluco@242
|
2 |
|
|
faluco@260
|
3 |
static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
4 |
{ |
|
faluco@242
|
5 |
if (params[1]) |
|
faluco@242
|
6 |
{ |
|
faluco@242
|
7 |
return g_PlayerManager.GetPlayerCount(); |
|
faluco@242
|
8 |
} |
|
faluco@242
|
9 |
|
|
faluco@242
|
10 |
int maxplayers = g_PlayerManager.GetMaxClients(); |
|
faluco@242
|
11 |
int count = 0; |
|
faluco@242
|
12 |
for (int i=1; i<=maxplayers; ++i) |
|
faluco@242
|
13 |
{ |
|
faluco@242
|
14 |
CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(i); |
|
faluco@242
|
15 |
if ((pPlayer->IsPlayerConnected()) && !(pPlayer->IsPlayerInGame())) |
|
faluco@242
|
16 |
{ |
|
faluco@242
|
17 |
count++; |
|
faluco@242
|
18 |
} |
|
faluco@242
|
19 |
} |
|
faluco@242
|
20 |
|
|
faluco@242
|
21 |
return (g_PlayerManager.GetPlayerCount() + count); |
|
faluco@242
|
22 |
} |
|
faluco@242
|
23 |
|
|
faluco@260
|
24 |
static cell_t sm_GetMaxClients(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
25 |
{ |
|
faluco@242
|
26 |
return g_PlayerManager.GetMaxClients(); |
|
faluco@242
|
27 |
} |
|
faluco@242
|
28 |
|
|
faluco@260
|
29 |
static cell_t sm_GetClientName(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
30 |
{ |
|
faluco@242
|
31 |
int index = params[1]; |
|
faluco@242
|
32 |
if ((index < 1) || (index > g_PlayerManager.GetMaxClients())) |
|
faluco@242
|
33 |
{ |
|
faluco@260
|
34 |
return pCtx->ThrowNativeError("Invalid client index %d.", index); |
|
faluco@242
|
35 |
} |
|
faluco@242
|
36 |
|
|
faluco@260
|
37 |
CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(index); |
|
faluco@260
|
38 |
if (!pPlayer->IsPlayerConnected()) |
|
faluco@260
|
39 |
{ |
|
faluco@260
|
40 |
return pCtx->ThrowNativeError("Client %d is not connected.", index); |
|
faluco@260
|
41 |
} |
|
faluco@260
|
42 |
|
|
faluco@260
|
43 |
pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pPlayer->PlayerName(), NULL); |
|
faluco@242
|
44 |
return 1; |
|
faluco@242
|
45 |
} |
|
faluco@242
|
46 |
|
|
faluco@260
|
47 |
static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
48 |
{ |
|
faluco@242
|
49 |
int index = params[1]; |
|
faluco@242
|
50 |
if ((index < 1) || (index > g_PlayerManager.GetMaxClients())) |
|
faluco@242
|
51 |
{ |
|
faluco@260
|
52 |
return pCtx->ThrowNativeError("Invalid client index %d.", index); |
|
faluco@242
|
53 |
} |
|
faluco@242
|
54 |
|
|
faluco@260
|
55 |
CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(index); |
|
faluco@260
|
56 |
if (!pPlayer->IsPlayerConnected()) |
|
faluco@260
|
57 |
{ |
|
faluco@260
|
58 |
return pCtx->ThrowNativeError("Client %d is not connected.", index); |
|
faluco@260
|
59 |
} |
|
faluco@260
|
60 |
|
|
faluco@260
|
61 |
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), pPlayer->PlayerIP()); |
|
faluco@242
|
62 |
return 1; |
|
faluco@242
|
63 |
} |
|
faluco@242
|
64 |
|
|
faluco@260
|
65 |
static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
66 |
{ |
|
faluco@242
|
67 |
int index = params[1]; |
|
faluco@242
|
68 |
if ((index < 1) || (index > g_PlayerManager.GetMaxClients())) |
|
faluco@242
|
69 |
{ |
|
faluco@260
|
70 |
return pCtx->ThrowNativeError("Invalid client index %d.", index); |
|
faluco@242
|
71 |
} |
|
faluco@242
|
72 |
|
|
faluco@260
|
73 |
CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(index); |
|
faluco@260
|
74 |
if (!pPlayer->IsPlayerConnected()) |
|
faluco@260
|
75 |
{ |
|
faluco@260
|
76 |
return pCtx->ThrowNativeError("Client %d is not connected.", index); |
|
faluco@260
|
77 |
} |
|
faluco@260
|
78 |
|
|
faluco@260
|
79 |
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), pPlayer->PlayerAuthString()); |
|
faluco@242
|
80 |
return 1; |
|
faluco@242
|
81 |
} |
|
faluco@242
|
82 |
|
|
faluco@260
|
83 |
static cell_t sm_IsPlayerConnected(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
84 |
{ |
|
faluco@242
|
85 |
int index = params[1]; |
|
faluco@242
|
86 |
if ((index < 1) || (index > g_PlayerManager.GetMaxClients())) |
|
faluco@242
|
87 |
{ |
|
faluco@260
|
88 |
return pCtx->ThrowNativeError("Invalid client index %d.", index); |
|
faluco@242
|
89 |
} |
|
faluco@242
|
90 |
|
|
faluco@242
|
91 |
return (g_PlayerManager.GetPlayerByIndex(index)->IsPlayerConnected()) ? 1 : 0; |
|
faluco@242
|
92 |
} |
|
faluco@242
|
93 |
|
|
faluco@260
|
94 |
static cell_t sm_IsPlayerIngame(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
95 |
{ |
|
faluco@242
|
96 |
int index = params[1]; |
|
faluco@242
|
97 |
if ((index < 1) || (index > g_PlayerManager.GetMaxClients())) |
|
faluco@242
|
98 |
{ |
|
faluco@260
|
99 |
return pCtx->ThrowNativeError("Invalid client index %d.", index); |
|
faluco@242
|
100 |
} |
|
faluco@242
|
101 |
|
|
faluco@242
|
102 |
return (g_PlayerManager.GetPlayerByIndex(index)->IsPlayerInGame()) ? 1 : 0; |
|
faluco@242
|
103 |
} |
|
faluco@242
|
104 |
|
|
faluco@260
|
105 |
static cell_t sm_IsPlayerAuthorized(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
106 |
{ |
|
faluco@242
|
107 |
int index = params[1]; |
|
faluco@242
|
108 |
if ((index < 1) || (index > g_PlayerManager.GetMaxClients())) |
|
faluco@242
|
109 |
{ |
|
faluco@260
|
110 |
return pCtx->ThrowNativeError("Invalid client index %d.", index); |
|
faluco@242
|
111 |
} |
|
faluco@242
|
112 |
|
|
faluco@242
|
113 |
return (g_PlayerManager.GetPlayerByIndex(index)->IsPlayerAuthorized()) ? 1 : 0; |
|
faluco@242
|
114 |
} |
|
faluco@242
|
115 |
|
|
faluco@260
|
116 |
static cell_t sm_IsPlayerFakeClient(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
117 |
{ |
|
faluco@242
|
118 |
int index = params[1]; |
|
faluco@242
|
119 |
if ((index < 1) || (index > g_PlayerManager.GetMaxClients())) |
|
faluco@242
|
120 |
{ |
|
faluco@260
|
121 |
return pCtx->ThrowNativeError("Invalid client index %d.", index); |
|
faluco@260
|
122 |
} |
|
faluco@260
|
123 |
|
|
faluco@260
|
124 |
CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(index); |
|
faluco@260
|
125 |
if (!pPlayer->IsPlayerConnected()) |
|
faluco@260
|
126 |
{ |
|
faluco@260
|
127 |
return pCtx->ThrowNativeError("Client %d is not connected.", index); |
|
faluco@242
|
128 |
} |
|
faluco@242
|
129 |
|
|
faluco@260
|
130 |
return (pPlayer->IsPlayerFakeClient()) ? 1 : 0; |
|
faluco@260
|
131 |
} |
|
faluco@260
|
132 |
|
|
faluco@260
|
133 |
REGISTER_NATIVES(playernatives) |
|
faluco@260
|
134 |
{ |
|
faluco@260
|
135 |
{"GetMaxClients", sm_GetMaxClients}, |
|
faluco@260
|
136 |
{"GetClientCount", sm_GetClientCount}, |
|
faluco@260
|
137 |
{"GetClientName", sm_GetClientName}, |
|
faluco@260
|
138 |
{"GetClientIP", sm_GetClientIP}, |
|
faluco@260
|
139 |
{"GetClientAuthString", sm_GetClientAuthStr}, |
|
faluco@260
|
140 |
{"IsPlayerConnected", sm_IsPlayerConnected}, |
|
faluco@260
|
141 |
{"IsPlayerInGame", sm_IsPlayerIngame}, |
|
faluco@260
|
142 |
{"IsPlayerAuthorized", sm_IsPlayerAuthorized}, |
|
faluco@260
|
143 |
{"IsPlayerFakeClient", sm_IsPlayerFakeClient}, |
|
faluco@260
|
144 |
{NULL, NULL} |
|
faluco@260
|
145 |
}; |