core/smn_player.cpp
author Matt Woodrow <pred@alliedmods.net>
Fri Aug 08 00:17:37 2008 +0000 (2008-08-08)
changeset 2224 676c3b826f13
parent 2193 db7c6362f3f2
child 2289 44045ead61cd
permissions -rw-r--r--
Initial Import of beta structs extension.
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod
ds@1952
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     6
 * =============================================================================
ds@1952
     7
 *
ds@1952
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    10
 * Free Software Foundation.
ds@1952
    11
 * 
ds@1952
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    15
 * details.
ds@1952
    16
 *
ds@1952
    17
 * You should have received a copy of the GNU General Public License along with
ds@1952
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    19
 *
ds@1952
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    27
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    28
 *
ds@1952
    29
 * Version: $Id$
ds@1952
    30
 */
ds@1952
    31
ds@1952
    32
#include "PlayerManager.h"
ds@1952
    33
#include "AdminCache.h"
ds@1952
    34
#include "sm_stringutil.h"
ds@1952
    35
#include "HalfLife2.h"
ds@1952
    36
#include "sourcemod.h"
ds@1952
    37
#include "ChatTriggers.h"
ds@1952
    38
#include <inetchannel.h>
ds@1952
    39
#include <iclient.h>
ds@1952
    40
ds@1952
    41
ConVar sm_show_activity("sm_show_activity", "13", FCVAR_SPONLY, "Activity display setting (see sourcemod.cfg)");
ds@1952
    42
ds@1952
    43
static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params)
ds@1952
    44
{
ds@1952
    45
	if (params[1])
ds@1952
    46
	{
ds@1952
    47
		return g_Players.NumPlayers();
ds@1952
    48
	}
ds@1952
    49
ds@1952
    50
	int maxplayers = g_Players.MaxClients();
ds@1952
    51
	int count = 0;
ds@1952
    52
	for (int i=1; i<=maxplayers; ++i)
ds@1952
    53
	{
ds@1952
    54
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
ds@1952
    55
		if ((pPlayer->IsConnected()) && !(pPlayer->IsInGame()))
ds@1952
    56
		{
ds@1952
    57
			count++;
ds@1952
    58
		}
ds@1952
    59
	}
ds@1952
    60
ds@1952
    61
	return (g_Players.NumPlayers() + count);
ds@1952
    62
}
ds@1952
    63
ds@1952
    64
static cell_t sm_GetMaxClients(IPluginContext *pCtx, const cell_t *params)
ds@1952
    65
{
ds@1952
    66
	return g_Players.MaxClients();
ds@1952
    67
}
ds@1952
    68
ds@1952
    69
static cell_t sm_GetClientName(IPluginContext *pCtx, const cell_t *params)
ds@1952
    70
{
ds@1952
    71
	int index = params[1];
ds@1952
    72
ds@1952
    73
	if (index == 0)
ds@1952
    74
	{
ds@1952
    75
		static ConVar *hostname = NULL;
ds@1952
    76
		if (!hostname)
ds@1952
    77
		{
ds@1952
    78
			hostname = icvar->FindVar("hostname");
ds@1952
    79
			if (!hostname)
ds@1952
    80
			{
ds@1952
    81
				return pCtx->ThrowNativeError("Could not find \"hostname\" cvar");
ds@1952
    82
			}
ds@1952
    83
		}
ds@1952
    84
		pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), hostname->GetString(), NULL);
ds@1952
    85
		return 1;
ds@1952
    86
	}
ds@1952
    87
ds@1952
    88
	if ((index < 1) || (index > g_Players.GetMaxClients()))
ds@1952
    89
	{
ds@1952
    90
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
ds@1952
    91
	}
ds@1952
    92
ds@1952
    93
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
ds@1952
    94
	if (!pPlayer->IsConnected())
ds@1952
    95
	{
ds@1952
    96
		return pCtx->ThrowNativeError("Client %d is not connected", index);
ds@1952
    97
	}
ds@1952
    98
ds@1952
    99
	pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pPlayer->GetName(), NULL);
ds@1952
   100
	return 1;
ds@1952
   101
}
ds@1952
   102
ds@1952
   103
static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params)
ds@1952
   104
{
ds@1952
   105
	int index = params[1];
ds@1952
   106
	if ((index < 1) || (index > g_Players.GetMaxClients()))
ds@1952
   107
	{
ds@1952
   108
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
ds@1952
   109
	}
ds@1952
   110
ds@1952
   111
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
ds@1952
   112
	if (!pPlayer->IsConnected())
ds@1952
   113
	{
ds@1952
   114
		return pCtx->ThrowNativeError("Client %d is not connected", index);
ds@1952
   115
	}
ds@1952
   116
ds@1952
   117
	char buf[64], *ptr;
ds@1952
   118
	strcpy(buf, pPlayer->GetIPAddress());
ds@1952
   119
ds@1952
   120
	if (params[4] && (ptr = strchr(buf, ':')))
ds@1952
   121
	{
ds@1952
   122
		*ptr = '\0';
ds@1952
   123
	}
ds@1952
   124
ds@1952
   125
	pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), buf);
ds@1952
   126
	return 1;
ds@1952
   127
}
ds@1952
   128
ds@1952
   129
static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params)
ds@1952
   130
{
ds@1952
   131
	int index = params[1];
ds@1952
   132
	if ((index < 1) || (index > g_Players.GetMaxClients()))
ds@1952
   133
	{
ds@1952
   134
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
ds@1952
   135
	}
ds@1952
   136
ds@1952
   137
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
ds@1952
   138
	if (!pPlayer->IsConnected())
ds@1952
   139
	{
ds@1952
   140
		return pCtx->ThrowNativeError("Client %d is not connected", index);
ds@1952
   141
	}
ds@1952
   142
ds@1952
   143
	if (!pPlayer->IsAuthorized())
ds@1952
   144
	{
ds@1952
   145
		return 0;
ds@1952
   146
	}
ds@1952
   147
ds@1952
   148
	pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), pPlayer->GetAuthString());
ds@1952
   149
ds@1952
   150
	return 1;
ds@1952
   151
}
ds@1952
   152
ds@1952
   153
static cell_t sm_IsClientConnected(IPluginContext *pCtx, const cell_t *params)
ds@1952
   154
{
ds@1952
   155
	int index = params[1];
ds@1952
   156
	if ((index < 1) || (index > g_Players.GetMaxClients()))
ds@1952
   157
	{
ds@1952
   158
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
ds@1952
   159
	}
ds@1952
   160
ds@1952
   161
	return (g_Players.GetPlayerByIndex(index)->IsConnected()) ? 1 : 0;
ds@1952
   162
}
ds@1952
   163
ds@1952
   164
static cell_t sm_IsClientInGame(IPluginContext *pCtx, const cell_t *params)
ds@1952
   165
{
ds@1952
   166
	int index = params[1];
ds@1952
   167
	if ((index < 1) || (index > g_Players.GetMaxClients()))
ds@1952
   168
	{
ds@1952
   169
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
ds@1952
   170
	}
ds@1952
   171
ds@1952
   172
	return (g_Players.GetPlayerByIndex(index)->IsInGame()) ? 1 : 0;
ds@1952
   173
}
ds@1952
   174
ds@1952
   175
static cell_t sm_IsClientAuthorized(IPluginContext *pCtx, const cell_t *params)
ds@1952
   176
{
ds@1952
   177
	int index = params[1];
ds@1952
   178
	if ((index < 1) || (index > g_Players.GetMaxClients()))
ds@1952
   179
	{
ds@1952
   180
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
ds@1952
   181
	}
ds@1952
   182
ds@1952
   183
	return (g_Players.GetPlayerByIndex(index)->IsAuthorized()) ? 1 : 0;
ds@1952
   184
}
ds@1952
   185
ds@1952
   186
static cell_t sm_IsClientFakeClient(IPluginContext *pCtx, const cell_t *params)
ds@1952
   187
{
ds@1952
   188
	int index = params[1];
ds@1952
   189
	if ((index < 1) || (index > g_Players.GetMaxClients()))
ds@1952
   190
	{
ds@1952
   191
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
ds@1952
   192
	}
ds@1952
   193
ds@1952
   194
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
ds@1952
   195
	if (!pPlayer->IsConnected())
ds@1952
   196
	{
ds@1952
   197
		return pCtx->ThrowNativeError("Client %d is not connected", index);
ds@1952
   198
	}
ds@1952
   199
ds@1952
   200
	return (pPlayer->IsFakeClient()) ? 1 : 0;
ds@1952
   201
}
ds@1952
   202
ds@1952
   203
static cell_t IsClientObserver(IPluginContext *pContext, const cell_t *params)
ds@1952
   204
{
ds@1952
   205
	int client = params[1];
ds@1952
   206
ds@1952
   207
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   208
	if (!pPlayer)
ds@1952
   209
	{
ds@1952
   210
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   211
	} else if (!pPlayer->IsInGame()) {
ds@1952
   212
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
   213
	}
ds@1952
   214
ds@1952
   215
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1952
   216
	if (!pInfo)
ds@1952
   217
	{
ds@1952
   218
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1952
   219
	}
ds@1952
   220
ds@1952
   221
	return pInfo->IsObserver() ? 1 : 0;
ds@1952
   222
}
ds@1952
   223
ds@1952
   224
static cell_t sm_GetClientInfo(IPluginContext *pContext, const cell_t *params)
ds@1952
   225
{
ds@1952
   226
	int client = params[1];
ds@1952
   227
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   228
	if (!pPlayer)
ds@1952
   229
	{
ds@1952
   230
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   231
	}
ds@1952
   232
	if (!pPlayer->IsConnected())
ds@1952
   233
	{
ds@1952
   234
		return pContext->ThrowNativeError("Client %d is not connected", client);
ds@1952
   235
	}
ds@1952
   236
ds@1952
   237
	char *key;
ds@1952
   238
	pContext->LocalToString(params[2], &key);
ds@1952
   239
ds@1952
   240
	const char *val = engine->GetClientConVarValue(client, key);
ds@1952
   241
	if (!val)
ds@1952
   242
	{
ds@1952
   243
		return false;
ds@1952
   244
	}
ds@1952
   245
ds@1952
   246
	pContext->StringToLocalUTF8(params[3], params[4], val, NULL);
ds@1952
   247
	return 1;
ds@1952
   248
}
ds@1952
   249
ds@1952
   250
static cell_t SetUserAdmin(IPluginContext *pContext, const cell_t *params)
ds@1952
   251
{
ds@1952
   252
	int client = params[1];
ds@1952
   253
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   254
	if (!pPlayer)
ds@1952
   255
	{
ds@1952
   256
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   257
	}
ds@1952
   258
	if (!pPlayer->IsConnected())
ds@1952
   259
	{
ds@1952
   260
		return pContext->ThrowNativeError("Client %d is not connected", client);
ds@1952
   261
	}
ds@1952
   262
	if (!g_Admins.IsValidAdmin(params[2]) && params[2] != INVALID_ADMIN_ID)
ds@1952
   263
	{
ds@1952
   264
		return pContext->ThrowNativeError("AdminId %x is invalid", params[2]);
ds@1952
   265
	}
ds@1952
   266
ds@1952
   267
	pPlayer->SetAdminId(params[2], params[3] ? true : false);
ds@1952
   268
ds@1952
   269
	return 1;
ds@1952
   270
}
ds@1952
   271
ds@1952
   272
static cell_t GetUserAdmin(IPluginContext *pContext, const cell_t *params)
ds@1952
   273
{
ds@1952
   274
	int client = params[1];
ds@1952
   275
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   276
	if (!pPlayer)
ds@1952
   277
	{
ds@1952
   278
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   279
	}
ds@1952
   280
	if (!pPlayer->IsConnected())
ds@1952
   281
	{
ds@1952
   282
		return pContext->ThrowNativeError("Client %d is not connected", client);
ds@1952
   283
	}
ds@1952
   284
ds@1952
   285
	return pPlayer->GetAdminId();
ds@1952
   286
}
ds@1952
   287
ds@1952
   288
static cell_t AddUserFlags(IPluginContext *pContext, const cell_t *params)
ds@1952
   289
{
ds@1952
   290
	int client = params[1];
ds@1952
   291
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   292
	if (!pPlayer)
ds@1952
   293
	{
ds@1952
   294
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   295
	}
ds@1952
   296
	if (!pPlayer->IsConnected())
ds@1952
   297
	{
ds@1952
   298
		return pContext->ThrowNativeError("Client %d is not connected", client);
ds@1952
   299
	}
ds@1952
   300
ds@1952
   301
	AdminId id;
ds@1952
   302
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
ds@1952
   303
	{
ds@1952
   304
		id = g_Admins.CreateAdmin(NULL);
ds@1952
   305
		pPlayer->SetAdminId(id, true);
ds@1952
   306
	}
ds@1952
   307
ds@1952
   308
	cell_t *addr;
ds@1952
   309
	for (int i=2; i<=params[0]; i++)
ds@1952
   310
	{
ds@1952
   311
		pContext->LocalToPhysAddr(params[i], &addr);
ds@1952
   312
		g_Admins.SetAdminFlag(id, (AdminFlag)*addr, true);
ds@1952
   313
	}
ds@1952
   314
ds@1952
   315
	return 1;
ds@1952
   316
}
ds@1952
   317
ds@1952
   318
static cell_t RemoveUserFlags(IPluginContext *pContext, const cell_t *params)
ds@1952
   319
{
ds@1952
   320
	int client = params[1];
ds@1952
   321
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   322
	if (!pPlayer)
ds@1952
   323
	{
ds@1952
   324
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   325
	}
ds@1952
   326
	if (!pPlayer->IsConnected())
ds@1952
   327
	{
ds@1952
   328
		return pContext->ThrowNativeError("Client %d is not connected", client);
ds@1952
   329
	}
ds@1952
   330
	
ds@1952
   331
	AdminId id;
ds@1952
   332
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
ds@1952
   333
	{
ds@1952
   334
		return 0;
ds@1952
   335
	}
ds@1952
   336
ds@1952
   337
	cell_t *addr;
ds@1952
   338
	for (int i=2; i<=params[0]; i++)
ds@1952
   339
	{
ds@1952
   340
		pContext->LocalToPhysAddr(params[i], &addr);
ds@1952
   341
		g_Admins.SetAdminFlag(id, (AdminFlag)*addr, false);
ds@1952
   342
	}
ds@1952
   343
ds@1952
   344
	return 1;
ds@1952
   345
}
ds@1952
   346
ds@1952
   347
static cell_t SetUserFlagBits(IPluginContext *pContext, const cell_t *params)
ds@1952
   348
{
ds@1952
   349
	int client = params[1];
ds@1952
   350
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   351
	if (!pPlayer)
ds@1952
   352
	{
ds@1952
   353
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   354
	}
ds@1952
   355
	if (!pPlayer->IsConnected())
ds@1952
   356
	{
ds@1952
   357
		return pContext->ThrowNativeError("Client %d is not connected", client);
ds@1952
   358
	}
ds@1952
   359
ds@1952
   360
	AdminId id;
ds@1952
   361
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
ds@1952
   362
	{
ds@1952
   363
		id = g_Admins.CreateAdmin(NULL);
ds@1952
   364
		pPlayer->SetAdminId(id, true);
ds@1952
   365
	}
ds@1952
   366
ds@1952
   367
	g_Admins.SetAdminFlags(id, Access_Effective, params[2]);
ds@1952
   368
ds@1952
   369
	return 1;
ds@1952
   370
}
ds@1952
   371
ds@1952
   372
static cell_t GetUserFlagBits(IPluginContext *pContext, const cell_t *params)
ds@1952
   373
{
ds@1952
   374
	int client = params[1];
ds@1952
   375
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   376
	if (!pPlayer)
ds@1952
   377
	{
ds@1952
   378
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   379
	}
ds@1952
   380
	if (!pPlayer->IsConnected())
ds@1952
   381
	{
ds@1952
   382
		return pContext->ThrowNativeError("Client %d is not connected", client);
ds@1952
   383
	}
ds@1952
   384
ds@1952
   385
	AdminId id;
ds@1952
   386
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
ds@1952
   387
	{
ds@1952
   388
		return 0;
ds@1952
   389
	}
ds@1952
   390
ds@1952
   391
	return g_Admins.GetAdminFlags(id, Access_Effective);
ds@1952
   392
}
ds@1952
   393
ds@1952
   394
static cell_t GetClientUserId(IPluginContext *pContext, const cell_t *params)
ds@1952
   395
{
ds@1952
   396
	int client = params[1];
ds@1952
   397
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   398
	if (!pPlayer)
ds@1952
   399
	{
ds@1952
   400
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   401
	}
ds@1952
   402
	if (!pPlayer->IsConnected())
ds@1952
   403
	{
ds@1952
   404
		return pContext->ThrowNativeError("Client %d is not connected", client);
ds@1952
   405
	}
ds@1952
   406
ds@1952
   407
	return engine->GetPlayerUserId(pPlayer->GetEdict());
ds@1952
   408
}
ds@1952
   409
ds@1952
   410
static cell_t CanUserTarget(IPluginContext *pContext, const cell_t *params)
ds@1952
   411
{
ds@1952
   412
	int client = params[1];
ds@1952
   413
	int target = params[2];
ds@1952
   414
ds@1952
   415
	if (client == 0)
ds@1952
   416
	{
ds@1952
   417
		return 1;
ds@1952
   418
	}
ds@1952
   419
ds@1952
   420
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   421
	if (!pPlayer)
ds@1952
   422
	{
ds@1952
   423
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   424
	} else if (!pPlayer->IsConnected()) {
ds@1952
   425
		return pContext->ThrowNativeError("Client %d is not connected", client);
ds@1952
   426
	}
ds@1952
   427
ds@1952
   428
	CPlayer *pTarget = g_Players.GetPlayerByIndex(target);
ds@1952
   429
	if (!pTarget)
ds@1952
   430
	{
ds@1952
   431
		return pContext->ThrowNativeError("Client index %d is invalid", target);
ds@1952
   432
	} else if (!pTarget->IsConnected()) {
ds@1952
   433
		return pContext->ThrowNativeError("Client %d is not connected", target);
ds@1952
   434
	}
ds@1952
   435
ds@1952
   436
	return g_Admins.CanAdminTarget(pPlayer->GetAdminId(), pTarget->GetAdminId()) ? 1 : 0;
ds@1952
   437
}
ds@1952
   438
ds@1952
   439
static cell_t GetClientTeam(IPluginContext *pContext, const cell_t *params)
ds@1952
   440
{
ds@1952
   441
	int client = params[1];
ds@1952
   442
ds@1952
   443
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   444
	if (!pPlayer)
ds@1952
   445
	{
ds@1952
   446
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   447
	} else if (!pPlayer->IsInGame()) {
ds@1952
   448
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
   449
	}
ds@1952
   450
ds@1952
   451
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1952
   452
	if (!pInfo)
ds@1952
   453
	{
ds@1952
   454
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1952
   455
	}
ds@1952
   456
ds@1952
   457
	return pInfo->GetTeamIndex();
ds@1952
   458
}
ds@1952
   459
ds@1952
   460
static cell_t GetFragCount(IPluginContext *pContext, const cell_t *params)
ds@1952
   461
{
ds@1952
   462
	int client = params[1];
ds@1952
   463
ds@1952
   464
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   465
	if (!pPlayer)
ds@1952
   466
	{
ds@1952
   467
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   468
	} else if (!pPlayer->IsInGame()) {
ds@1952
   469
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
   470
	}
ds@1952
   471
ds@1952
   472
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1952
   473
	if (!pInfo)
ds@1952
   474
	{
ds@1952
   475
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1952
   476
	}
ds@1952
   477
ds@1952
   478
	return pInfo->GetFragCount();
ds@1952
   479
}
ds@1952
   480
ds@1952
   481
static cell_t GetDeathCount(IPluginContext *pContext, const cell_t *params)
ds@1952
   482
{
ds@1952
   483
	int client = params[1];
ds@1952
   484
ds@1952
   485
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   486
	if (!pPlayer)
ds@1952
   487
	{
ds@1952
   488
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   489
	} else if (!pPlayer->IsInGame()) {
ds@1952
   490
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
   491
	}
ds@1952
   492
ds@1952
   493
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1952
   494
	if (!pInfo)
ds@1952
   495
	{
ds@1952
   496
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1952
   497
	}
ds@1952
   498
ds@1952
   499
	return pInfo->GetDeathCount();
ds@1952
   500
}
ds@1952
   501
ds@1952
   502
static cell_t GetArmorValue(IPluginContext *pContext, const cell_t *params)
ds@1952
   503
{
ds@1952
   504
	int client = params[1];
ds@1952
   505
ds@1952
   506
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   507
	if (!pPlayer)
ds@1952
   508
	{
ds@1952
   509
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   510
	} else if (!pPlayer->IsInGame()) {
ds@1952
   511
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
   512
	}
ds@1952
   513
ds@1952
   514
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1952
   515
	if (!pInfo)
ds@1952
   516
	{
ds@1952
   517
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1952
   518
	}
ds@1952
   519
ds@1952
   520
	return pInfo->GetArmorValue();
ds@1952
   521
}
ds@1952
   522
ds@1952
   523
static cell_t GetAbsOrigin(IPluginContext *pContext, const cell_t *params)
ds@1952
   524
{
ds@1952
   525
	int client = params[1];
ds@1952
   526
ds@1952
   527
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   528
	if (!pPlayer)
ds@1952
   529
	{
ds@1952
   530
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   531
	} else if (!pPlayer->IsInGame()) {
ds@1952
   532
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
   533
	}
ds@1952
   534
ds@1952
   535
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1952
   536
	if (!pInfo)
ds@1952
   537
	{
ds@1952
   538
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1952
   539
	}
ds@1952
   540
ds@1952
   541
	cell_t *pVec;
ds@1952
   542
	pContext->LocalToPhysAddr(params[2], &pVec);
ds@1952
   543
ds@1952
   544
	Vector vec = pInfo->GetAbsOrigin();
ds@1952
   545
	pVec[0] = sp_ftoc(vec.x);
ds@1952
   546
	pVec[1] = sp_ftoc(vec.y);
ds@1952
   547
	pVec[2] = sp_ftoc(vec.z);
ds@1952
   548
ds@1952
   549
	return 1;
ds@1952
   550
}
ds@1952
   551
ds@1952
   552
static cell_t GetAbsAngles(IPluginContext *pContext, const cell_t *params)
ds@1952
   553
{
ds@1952
   554
	int client = params[1];
ds@1952
   555
ds@1952
   556
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   557
	if (!pPlayer)
ds@1952
   558
	{
ds@1952
   559
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   560
	} else if (!pPlayer->IsInGame()) {
ds@1952
   561
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
   562
	}
ds@1952
   563
ds@1952
   564
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1952
   565
	if (!pInfo)
ds@1952
   566
	{
ds@1952
   567
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1952
   568
	}
ds@1952
   569
ds@1952
   570
	cell_t *pAng;
ds@1952
   571
	pContext->LocalToPhysAddr(params[2], &pAng);
ds@1952
   572
ds@1952
   573
	QAngle ang = pInfo->GetAbsAngles();
ds@1952
   574
	pAng[0] = sp_ftoc(ang.x);
ds@1952
   575
	pAng[1] = sp_ftoc(ang.y);
ds@1952
   576
	pAng[2] = sp_ftoc(ang.z);
ds@1952
   577
ds@1952
   578
	return 1;
ds@1952
   579
}
ds@1952
   580
ds@1952
   581
static cell_t GetPlayerMins(IPluginContext *pContext, const cell_t *params)
ds@1952
   582
{
ds@1952
   583
	int client = params[1];
ds@1952
   584
ds@1952
   585
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   586
	if (!pPlayer)
ds@1952
   587
	{
ds@1952
   588
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   589
	} else if (!pPlayer->IsInGame()) {
ds@1952
   590
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
   591
	}
ds@1952
   592
ds@1952
   593
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1952
   594
	if (!pInfo)
ds@1952
   595
	{
ds@1952
   596
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1952
   597
	}
ds@1952
   598
ds@1952
   599
	cell_t *pVec;
ds@1952
   600
	pContext->LocalToPhysAddr(params[2], &pVec);
ds@1952
   601
ds@1952
   602
	Vector vec = pInfo->GetPlayerMins();
ds@1952
   603
	pVec[0] = sp_ftoc(vec.x);
ds@1952
   604
	pVec[1] = sp_ftoc(vec.y);
ds@1952
   605
	pVec[2] = sp_ftoc(vec.z);
ds@1952
   606
ds@1952
   607
	return 1;
ds@1952
   608
}
ds@1952
   609
ds@1952
   610
static cell_t GetPlayerMaxs(IPluginContext *pContext, const cell_t *params)
ds@1952
   611
{
ds@1952
   612
	int client = params[1];
ds@1952
   613
ds@1952
   614
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   615
	if (!pPlayer)
ds@1952
   616
	{
ds@1952
   617
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   618
	} else if (!pPlayer->IsInGame()) {
ds@1952
   619
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
   620
	}
ds@1952
   621
ds@1952
   622
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1952
   623
	if (!pInfo)
ds@1952
   624
	{
ds@1952
   625
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1952
   626
	}
ds@1952
   627
ds@1952
   628
	cell_t *pVec;
ds@1952
   629
	pContext->LocalToPhysAddr(params[2], &pVec);
ds@1952
   630
ds@1952
   631
	Vector vec = pInfo->GetPlayerMaxs();
ds@1952
   632
	pVec[0] = sp_ftoc(vec.x);
ds@1952
   633
	pVec[1] = sp_ftoc(vec.y);
ds@1952
   634
	pVec[2] = sp_ftoc(vec.z);
ds@1952
   635
ds@1952
   636
	return 1;
ds@1952
   637
}
ds@1952
   638
ds@1952
   639
static cell_t GetWeaponName(IPluginContext *pContext, const cell_t *params)
ds@1952
   640
{
ds@1952
   641
	int client = params[1];
ds@1952
   642
ds@1952
   643
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   644
	if (!pPlayer)
ds@1952
   645
	{
ds@1952
   646
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   647
	} else if (!pPlayer->IsInGame()) {
ds@1952
   648
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
   649
	}
ds@1952
   650
ds@1952
   651
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1952
   652
	if (!pInfo)
ds@1952
   653
	{
ds@1952
   654
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1952
   655
	}
ds@1952
   656
ds@1952
   657
	const char *weapon = pInfo->GetWeaponName();
ds@1952
   658
	pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), weapon ? weapon : "", NULL);
ds@1952
   659
ds@1952
   660
	return 1;
ds@1952
   661
}
ds@1952
   662
ds@1952
   663
static cell_t GetModelName(IPluginContext *pContext, const cell_t *params)
ds@1952
   664
{
ds@1952
   665
	int client = params[1];
ds@1952
   666
ds@1952
   667
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   668
	if (!pPlayer)
ds@1952
   669
	{
ds@1952
   670
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   671
	} else if (!pPlayer->IsInGame()) {
ds@1952
   672
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
   673
	}
ds@1952
   674
ds@1952
   675
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1952
   676
	if (!pInfo)
ds@1952
   677
	{
ds@1952
   678
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1952
   679
	}
ds@1952
   680
ds@1952
   681
	const char *model = pInfo->GetModelName();
ds@1952
   682
	pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), model ? model : "", NULL);
ds@1952
   683
ds@1952
   684
	return 1;
ds@1952
   685
}
ds@1952
   686
ds@1952
   687
static cell_t GetHealth(IPluginContext *pContext, const cell_t *params)
ds@1952
   688
{
ds@1952
   689
	int client = params[1];
ds@1952
   690
ds@1952
   691
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   692
	if (!pPlayer)
ds@1952
   693
	{
ds@1952
   694
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   695
	} else if (!pPlayer->IsInGame()) {
ds@1952
   696
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
   697
	}
ds@1952
   698
ds@1952
   699
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1952
   700
	if (!pInfo)
ds@1952
   701
	{
ds@1952
   702
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1952
   703
	}
ds@1952
   704
ds@1952
   705
	return pInfo->GetHealth();
ds@1952
   706
}
ds@1952
   707
ds@1952
   708
static cell_t GetTimeConnected(IPluginContext *pContext, const cell_t *params)
ds@1952
   709
{
ds@1952
   710
	int client = params[1];
ds@1952
   711
ds@1952
   712
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   713
	if (!pPlayer)
ds@1952
   714
	{
ds@1952
   715
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   716
	} else if (!pPlayer->IsInGame()) {
ds@1952
   717
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
   718
	} else if (pPlayer->IsFakeClient()) {
ds@1952
   719
		return pContext->ThrowNativeError("Client %d is a bot", client);
ds@1952
   720
	}
ds@1952
   721
ds@1952
   722
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
ds@1952
   723
ds@1952
   724
	return sp_ftoc(pInfo->GetTimeConnected());
ds@1952
   725
}
ds@1952
   726
ds@1952
   727
static cell_t GetDataRate(IPluginContext *pContext, const cell_t *params)
ds@1952
   728
{
ds@1952
   729
	int client = params[1];
ds@1952
   730
ds@1952
   731
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   732
	if (!pPlayer)
ds@1952
   733
	{
ds@1952
   734
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   735
	} else if (!pPlayer->IsInGame()) {
ds@1952
   736
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
   737
	} else if (pPlayer->IsFakeClient()) {
ds@1952
   738
		return pContext->ThrowNativeError("Client %d is a bot", client);
ds@1952
   739
	}
ds@1952
   740
ds@1952
   741
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
ds@1952
   742
ds@1952
   743
	return pInfo->GetDataRate();
ds@1952
   744
}
ds@1952
   745
ds@1952
   746
static cell_t IsTimingOut(IPluginContext *pContext, const cell_t *params)
ds@1952
   747
{
ds@1952
   748
	int client = params[1];
ds@1952
   749
ds@1952
   750
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   751
	if (!pPlayer)
ds@1952
   752
	{
ds@1952
   753
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   754
	} else if (!pPlayer->IsInGame()) {
ds@1952
   755
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
   756
	} else if (pPlayer->IsFakeClient()) {
ds@1952
   757
		return pContext->ThrowNativeError("Client %d is a bot", client);
ds@1952
   758
	}
ds@1952
   759
ds@1952
   760
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
ds@1952
   761
ds@1952
   762
	return pInfo->IsTimingOut() ? 1 : 0;
ds@1952
   763
}
ds@1952
   764
ds@1952
   765
static cell_t GetLatency(IPluginContext *pContext, const cell_t *params)
ds@1952
   766
{
ds@1952
   767
	int client = params[1];
dvander@2054
   768
	float value;
ds@1952
   769
ds@1952
   770
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   771
	if (!pPlayer)
ds@1952
   772
	{
ds@1952
   773
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@2054
   774
	}
dvander@2054
   775
	else if (!pPlayer->IsInGame())
dvander@2054
   776
	{
ds@1952
   777
		return pContext->ThrowNativeError("Client %d is not in game", client);
dvander@2054
   778
	}
dvander@2054
   779
	else if (pPlayer->IsFakeClient())
dvander@2054
   780
	{
ds@1952
   781
		return pContext->ThrowNativeError("Client %d is a bot", client);
ds@1952
   782
	}
ds@1952
   783
ds@1952
   784
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
ds@1952
   785
dvander@2054
   786
	if (params[2] == MAX_FLOWS)
dvander@2054
   787
	{
dvander@2054
   788
		value = pInfo->GetLatency(FLOW_INCOMING) + pInfo->GetLatency(FLOW_OUTGOING);
dvander@2054
   789
	}
dvander@2054
   790
	else
dvander@2054
   791
	{
dvander@2054
   792
		value = pInfo->GetLatency(params[2]);
dvander@2054
   793
	}
dvander@2054
   794
dvander@2054
   795
	return sp_ftoc(value);
ds@1952
   796
}
ds@1952
   797
ds@1952
   798
static cell_t GetAvgLatency(IPluginContext *pContext, const cell_t *params)
ds@1952
   799
{
ds@1952
   800
	int client = params[1];
dvander@2054
   801
	float value;
ds@1952
   802
ds@1952
   803
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   804
	if (!pPlayer)
ds@1952
   805
	{
ds@1952
   806
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@2054
   807
	}
dvander@2054
   808
	else if (!pPlayer->IsInGame())
dvander@2054
   809
	{
ds@1952
   810
		return pContext->ThrowNativeError("Client %d is not in game", client);
dvander@2054
   811
	}
dvander@2054
   812
	else if (pPlayer->IsFakeClient())
dvander@2054
   813
	{
ds@1952
   814
		return pContext->ThrowNativeError("Client %d is a bot", client);
ds@1952
   815
	}
ds@1952
   816
ds@1952
   817
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
ds@1952
   818
dvander@2054
   819
	if (params[2] == MAX_FLOWS)
dvander@2054
   820
	{
dvander@2054
   821
		value = pInfo->GetAvgLatency(FLOW_INCOMING) + pInfo->GetAvgLatency(FLOW_OUTGOING);
dvander@2054
   822
	}
dvander@2054
   823
	else
dvander@2054
   824
	{
dvander@2054
   825
		value = pInfo->GetAvgLatency(params[2]);
dvander@2054
   826
	}
dvander@2054
   827
dvander@2054
   828
	return sp_ftoc(value);
ds@1952
   829
}
ds@1952
   830
ds@1952
   831
static cell_t GetAvgLoss(IPluginContext *pContext, const cell_t *params)
ds@1952
   832
{
ds@1952
   833
	int client = params[1];
dvander@2054
   834
	float value;
ds@1952
   835
ds@1952
   836
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   837
	if (!pPlayer)
ds@1952
   838
	{
ds@1952
   839
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@2054
   840
	}
dvander@2054
   841
	else if (!pPlayer->IsInGame())
dvander@2054
   842
	{
ds@1952
   843
		return pContext->ThrowNativeError("Client %d is not in game", client);
dvander@2054
   844
	}
dvander@2054
   845
	else if (pPlayer->IsFakeClient())
dvander@2054
   846
	{
ds@1952
   847
		return pContext->ThrowNativeError("Client %d is a bot", client);
ds@1952
   848
	}
ds@1952
   849
ds@1952
   850
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
ds@1952
   851
dvander@2054
   852
	if (params[2] == MAX_FLOWS)
dvander@2054
   853
	{
dvander@2054
   854
		value = pInfo->GetAvgLoss(FLOW_INCOMING) + pInfo->GetAvgLoss(FLOW_OUTGOING);
dvander@2054
   855
	}
dvander@2054
   856
	else
dvander@2054
   857
	{
dvander@2054
   858
		value = pInfo->GetAvgLoss(params[2]);
dvander@2054
   859
	}
dvander@2054
   860
dvander@2054
   861
	return sp_ftoc(value);
ds@1952
   862
}
ds@1952
   863
ds@1952
   864
static cell_t GetAvgChoke(IPluginContext *pContext, const cell_t *params)
ds@1952
   865
{
ds@1952
   866
	int client = params[1];
dvander@2054
   867
	float value;
ds@1952
   868
ds@1952
   869
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   870
	if (!pPlayer)
ds@1952
   871
	{
ds@1952
   872
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@2054
   873
	}
dvander@2054
   874
	else if (!pPlayer->IsInGame())
dvander@2054
   875
	{
ds@1952
   876
		return pContext->ThrowNativeError("Client %d is not in game", client);
dvander@2054
   877
	}
dvander@2054
   878
	else if (pPlayer->IsFakeClient())
dvander@2054
   879
	{
ds@1952
   880
		return pContext->ThrowNativeError("Client %d is a bot", client);
ds@1952
   881
	}
ds@1952
   882
ds@1952
   883
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
ds@1952
   884
dvander@2054
   885
	if (params[2] == MAX_FLOWS)
dvander@2054
   886
	{
dvander@2054
   887
		value = pInfo->GetAvgChoke(FLOW_INCOMING) + pInfo->GetAvgChoke(FLOW_OUTGOING);
dvander@2054
   888
	}
dvander@2054
   889
	else
dvander@2054
   890
	{
dvander@2054
   891
		value = pInfo->GetAvgChoke(params[2]);
dvander@2054
   892
	}
dvander@2054
   893
dvander@2054
   894
	return sp_ftoc(value);
ds@1952
   895
}
ds@1952
   896
ds@1952
   897
static cell_t GetAvgData(IPluginContext *pContext, const cell_t *params)
ds@1952
   898
{
ds@1952
   899
	int client = params[1];
dvander@2054
   900
	float value;
ds@1952
   901
ds@1952
   902
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   903
	if (!pPlayer)
ds@1952
   904
	{
ds@1952
   905
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@2054
   906
	}
dvander@2054
   907
	else if (!pPlayer->IsInGame())
dvander@2054
   908
	{
ds@1952
   909
		return pContext->ThrowNativeError("Client %d is not in game", client);
dvander@2054
   910
	}
dvander@2054
   911
	else if (pPlayer->IsFakeClient())
dvander@2054
   912
	{
ds@1952
   913
		return pContext->ThrowNativeError("Client %d is a bot", client);
ds@1952
   914
	}
ds@1952
   915
ds@1952
   916
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
ds@1952
   917
dvander@2054
   918
	if (params[2] == MAX_FLOWS)
dvander@2054
   919
	{
dvander@2054
   920
		value = pInfo->GetAvgData(FLOW_INCOMING) + pInfo->GetAvgData(FLOW_OUTGOING);
dvander@2054
   921
	}
dvander@2054
   922
	else
dvander@2054
   923
	{
dvander@2054
   924
		value = pInfo->GetAvgData(params[2]);
dvander@2054
   925
	}
dvander@2054
   926
dvander@2054
   927
	return sp_ftoc(value);
ds@1952
   928
}
ds@1952
   929
ds@1952
   930
static cell_t GetAvgPackets(IPluginContext *pContext, const cell_t *params)
ds@1952
   931
{
ds@1952
   932
	int client = params[1];
dvander@2054
   933
	float value;
ds@1952
   934
ds@1952
   935
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   936
	if (!pPlayer)
ds@1952
   937
	{
ds@1952
   938
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@2054
   939
	}
dvander@2054
   940
	else if (!pPlayer->IsInGame())
dvander@2054
   941
	{
ds@1952
   942
		return pContext->ThrowNativeError("Client %d is not in game", client);
dvander@2054
   943
	}
dvander@2054
   944
	else if (pPlayer->IsFakeClient())
dvander@2054
   945
	{
ds@1952
   946
		return pContext->ThrowNativeError("Client %d is a bot", client);
ds@1952
   947
	}
ds@1952
   948
ds@1952
   949
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
ds@1952
   950
dvander@2054
   951
	if (params[2] == MAX_FLOWS)
dvander@2054
   952
	{
dvander@2054
   953
		value = pInfo->GetAvgPackets(FLOW_INCOMING) + pInfo->GetAvgPackets(FLOW_OUTGOING);
dvander@2054
   954
	}
dvander@2054
   955
	else
dvander@2054
   956
	{
dvander@2054
   957
		value = pInfo->GetAvgPackets(params[2]);
dvander@2054
   958
	}
dvander@2054
   959
dvander@2054
   960
	return sp_ftoc(value);
ds@1952
   961
}
ds@1952
   962
ds@1952
   963
static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params)
ds@1952
   964
{
ds@1952
   965
	return g_Players.GetClientOfUserId(params[1]);
ds@1952
   966
}
ds@1952
   967
ds@1952
   968
static cell_t _ShowActivity(IPluginContext *pContext,
ds@1952
   969
							const cell_t *params,
ds@1952
   970
							const char *tag,
ds@1952
   971
							cell_t fmt_param)
ds@1952
   972
{
ds@1952
   973
	char message[255];
ds@1952
   974
	char buffer[255];
ds@1952
   975
	int value = sm_show_activity.GetInt();
ds@1952
   976
	unsigned int replyto = g_ChatTriggers.GetReplyTo();
ds@1952
   977
	int client = params[1];
ds@1952
   978
ds@1952
   979
	const char *name = "Console";
ds@1952
   980
	const char *sign = "ADMIN";
ds@1952
   981
	bool display_in_chat = false;
ds@1952
   982
	if (client != 0)
ds@1952
   983
	{
ds@1952
   984
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   985
		if (!pPlayer || !pPlayer->IsConnected())
ds@1952
   986
		{
ds@1952
   987
			return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
   988
		}
ds@1952
   989
		name = pPlayer->GetName();
ds@1952
   990
		AdminId id = pPlayer->GetAdminId();
ds@1952
   991
		if (id == INVALID_ADMIN_ID
ds@1952
   992
			|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
ds@1952
   993
		{
ds@1952
   994
			sign = "PLAYER";
ds@1952
   995
		}
ds@1952
   996
ds@1952
   997
		/* Display the message to the client? */
ds@1952
   998
		if (replyto == SM_REPLY_CONSOLE)
ds@1952
   999
		{
ds@1952
  1000
			g_SourceMod.SetGlobalTarget(client);
ds@1952
  1001
			g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
ds@1952
  1002
dvander@2193
  1003
			if (pContext->GetLastNativeError() != SP_ERROR_NONE)
ds@1952
  1004
			{
ds@1952
  1005
				return 0;
ds@1952
  1006
			}
ds@1952
  1007
ds@1952
  1008
			UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
ds@1952
  1009
			engine->ClientPrintf(pPlayer->GetEdict(), message);
ds@1952
  1010
			display_in_chat = true;
ds@1952
  1011
		}
ds@1952
  1012
	}
ds@1952
  1013
	else
ds@1952
  1014
	{
dvander@2042
  1015
		g_SourceMod.SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
ds@1952
  1016
		g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
ds@1952
  1017
dvander@2193
  1018
		if (pContext->GetLastNativeError() != SP_ERROR_NONE)
ds@1952
  1019
		{
ds@1952
  1020
			return 0;
ds@1952
  1021
		}
ds@1952
  1022
ds@1952
  1023
		UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
ds@1952
  1024
		META_CONPRINT(message);
ds@1952
  1025
	}
ds@1952
  1026
ds@1952
  1027
	if (!value)
ds@1952
  1028
	{
ds@1952
  1029
		return 1;
ds@1952
  1030
	}
ds@1952
  1031
ds@1952
  1032
	int maxClients = g_Players.GetMaxClients();
ds@1952
  1033
	for (int i=1; i<=maxClients; i++)
ds@1952
  1034
	{
ds@1952
  1035
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
ds@1952
  1036
		if (!pPlayer->IsInGame() 
ds@1952
  1037
			|| pPlayer->IsFakeClient()
ds@1952
  1038
			|| (display_in_chat && i == client))
ds@1952
  1039
		{
ds@1952
  1040
			continue;
ds@1952
  1041
		}
ds@1952
  1042
		AdminId id = pPlayer->GetAdminId();
ds@1952
  1043
		g_SourceMod.SetGlobalTarget(i);
ds@1952
  1044
		if (id == INVALID_ADMIN_ID
ds@1952
  1045
			|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
ds@1952
  1046
		{
ds@1952
  1047
			/* Treat this as a normal user */
ds@1952
  1048
			if ((value & 1) || (value & 2))
ds@1952
  1049
			{
ds@1952
  1050
				const char *newsign = sign;
ds@1952
  1051
				if ((value & 2) || (i == client))
ds@1952
  1052
				{
ds@1952
  1053
					newsign = name;
ds@1952
  1054
				}
ds@1952
  1055
				g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
ds@1952
  1056
dvander@2193
  1057
				if (pContext->GetLastNativeError() != SP_ERROR_NONE)
ds@1952
  1058
				{
ds@1952
  1059
					return 0;
ds@1952
  1060
				}
ds@1952
  1061
ds@1952
  1062
				UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
ds@1952
  1063
				g_HL2.TextMsg(i, HUD_PRINTTALK, message);
ds@1952
  1064
			}
ds@1952
  1065
		}
ds@1952
  1066
		else
ds@1952
  1067
		{
ds@1952
  1068
			/* Treat this as an admin user */
ds@1952
  1069
			bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective);
ds@1952
  1070
			if ((value & 4) 
ds@1952
  1071
				|| (value & 8)
ds@1952
  1072
				|| ((value & 16) && is_root))
ds@1952
  1073
			{
ds@1952
  1074
				const char *newsign = sign;
ds@1952
  1075
				if ((value & 8) || ((value & 16) && is_root) || (i == client))
ds@1952
  1076
				{
ds@1952
  1077
					newsign = name;
ds@1952
  1078
				}
ds@1952
  1079
				g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
ds@1952
  1080
dvander@2193
  1081
				if (pContext->GetLastNativeError() != SP_ERROR_NONE)
ds@1952
  1082
				{
ds@1952
  1083
					return 0;
ds@1952
  1084
				}
ds@1952
  1085
ds@1952
  1086
				UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
ds@1952
  1087
				g_HL2.TextMsg(i, HUD_PRINTTALK, message);
ds@1952
  1088
			}
ds@1952
  1089
		}
ds@1952
  1090
	}
ds@1952
  1091
ds@1952
  1092
	return 1;
ds@1952
  1093
}
ds@1952
  1094
ds@1952
  1095
static cell_t _ShowActivity2(IPluginContext *pContext,
ds@1952
  1096
							 const cell_t *params,
ds@1952
  1097
							 const char *tag,
ds@1952
  1098
							 cell_t fmt_param)
ds@1952
  1099
{
ds@1952
  1100
	char message[255];
ds@1952
  1101
	char buffer[255];
ds@1952
  1102
	int value = sm_show_activity.GetInt();
ds@1952
  1103
	unsigned int replyto = g_ChatTriggers.GetReplyTo();
ds@1952
  1104
	int client = params[1];
ds@1952
  1105
ds@1952
  1106
	const char *name = "Console";
ds@1952
  1107
	const char *sign = "ADMIN";
ds@1952
  1108
	if (client != 0)
ds@1952
  1109
	{
ds@1952
  1110
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
  1111
		if (!pPlayer || !pPlayer->IsConnected())
ds@1952
  1112
		{
ds@1952
  1113
			return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
  1114
		}
ds@1952
  1115
		name = pPlayer->GetName();
ds@1952
  1116
		AdminId id = pPlayer->GetAdminId();
ds@1952
  1117
		if (id == INVALID_ADMIN_ID
ds@1952
  1118
			|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
ds@1952
  1119
		{
ds@1952
  1120
			sign = "PLAYER";
ds@1952
  1121
		}
ds@1952
  1122
ds@1952
  1123
		g_SourceMod.SetGlobalTarget(client);
ds@1952
  1124
		g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
ds@1952
  1125
dvander@2193
  1126
		if (pContext->GetLastNativeError() != SP_ERROR_NONE)
ds@1952
  1127
		{
ds@1952
  1128
			return 0;
ds@1952
  1129
		}
ds@1952
  1130
ds@1952
  1131
		/* We don't display directly to the console because the chat text 
ds@1952
  1132
		 * simply gets added to the console, so we don't want it to print 
ds@1952
  1133
		 * twice.
ds@1952
  1134
		 */
ds@1952
  1135
		if (replyto == SM_REPLY_CONSOLE)
ds@1952
  1136
		{
ds@1952
  1137
#if 0
ds@1952
  1138
			UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
ds@1952
  1139
			engine->ClientPrintf(pPlayer->GetEdict(), message);
ds@1952
  1140
#endif
ds@1952
  1141
			UTIL_Format(message, sizeof(message), "%s%s", tag, buffer);
ds@1952
  1142
			g_HL2.TextMsg(client, HUD_PRINTTALK, message);
ds@1952
  1143
		}
ds@1952
  1144
		else
ds@1952
  1145
		{
ds@1952
  1146
			UTIL_Format(message, sizeof(message), "%s%s", tag, buffer);
ds@1952
  1147
			g_HL2.TextMsg(client, HUD_PRINTTALK, message);
ds@1952
  1148
		}
ds@1952
  1149
	}
ds@1952
  1150
	else
ds@1952
  1151
	{
dvander@2042
  1152
		g_SourceMod.SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
ds@1952
  1153
		g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
ds@1952
  1154
dvander@2193
  1155
		if (pContext->GetLastNativeError() != SP_ERROR_NONE)
ds@1952
  1156
		{
ds@1952
  1157
			return 0;
ds@1952
  1158
		}
ds@1952
  1159
ds@1952
  1160
		UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
ds@1952
  1161
		META_CONPRINT(message);
ds@1952
  1162
	}
ds@1952
  1163
ds@1952
  1164
	if (!value)
ds@1952
  1165
	{
ds@1952
  1166
		return 1;
ds@1952
  1167
	}
ds@1952
  1168
ds@1952
  1169
	int maxClients = g_Players.GetMaxClients();
ds@1952
  1170
	for (int i=1; i<=maxClients; i++)
ds@1952
  1171
	{
ds@1952
  1172
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
ds@1952
  1173
		if (!pPlayer->IsInGame() 
ds@1952
  1174
			|| pPlayer->IsFakeClient()
ds@1952
  1175
			|| i == client)
ds@1952
  1176
		{
ds@1952
  1177
			continue;
ds@1952
  1178
		}
ds@1952
  1179
		AdminId id = pPlayer->GetAdminId();
ds@1952
  1180
		g_SourceMod.SetGlobalTarget(i);
ds@1952
  1181
		if (id == INVALID_ADMIN_ID
ds@1952
  1182
			|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
ds@1952
  1183
		{
ds@1952
  1184
			/* Treat this as a normal user */
ds@1952
  1185
			if ((value & 1) || (value & 2))
ds@1952
  1186
			{
ds@1952
  1187
				const char *newsign = sign;
ds@1952
  1188
				if ((value & 2))
ds@1952
  1189
				{
ds@1952
  1190
					newsign = name;
ds@1952
  1191
				}
ds@1952
  1192
				g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
ds@1952
  1193
dvander@2193
  1194
				if (pContext->GetLastNativeError() != SP_ERROR_NONE)
ds@1952
  1195
				{
ds@1952
  1196
					return 0;
ds@1952
  1197
				}
ds@1952
  1198
ds@1952
  1199
				UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
ds@1952
  1200
				g_HL2.TextMsg(i, HUD_PRINTTALK, message);
ds@1952
  1201
			}
ds@1952
  1202
		}
ds@1952
  1203
		else
ds@1952
  1204
		{
ds@1952
  1205
			/* Treat this as an admin user */
ds@1952
  1206
			bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective);
ds@1952
  1207
			if ((value & 4) 
ds@1952
  1208
				|| (value & 8)
ds@1952
  1209
				|| ((value & 16) && is_root))
ds@1952
  1210
			{
ds@1952
  1211
				const char *newsign = sign;
ds@1952
  1212
				if ((value & 8) || ((value & 16) && is_root))
ds@1952
  1213
				{
ds@1952
  1214
					newsign = name;
ds@1952
  1215
				}
ds@1952
  1216
				g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
ds@1952
  1217
dvander@2193
  1218
				if (pContext->GetLastNativeError() != SP_ERROR_NONE)
ds@1952
  1219
				{
ds@1952
  1220
					return 0;
ds@1952
  1221
				}
ds@1952
  1222
ds@1952
  1223
				UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
ds@1952
  1224
				g_HL2.TextMsg(i, HUD_PRINTTALK, message);
ds@1952
  1225
			}
ds@1952
  1226
		}
ds@1952
  1227
	}
ds@1952
  1228
ds@1952
  1229
	return 1;
ds@1952
  1230
}
ds@1952
  1231
ds@1952
  1232
static cell_t ShowActivity(IPluginContext *pContext, const cell_t *params)
ds@1952
  1233
{
ds@1952
  1234
	return _ShowActivity(pContext, params, "[SM] ", 2);
ds@1952
  1235
}
ds@1952
  1236
ds@1952
  1237
static cell_t ShowActivityEx(IPluginContext *pContext, const cell_t *params)
ds@1952
  1238
{
ds@1952
  1239
	char *str;
ds@1952
  1240
	pContext->LocalToString(params[2], &str);
ds@1952
  1241
ds@1952
  1242
	return _ShowActivity(pContext, params, str, 3);
ds@1952
  1243
}
ds@1952
  1244
ds@1952
  1245
static cell_t ShowActivity2(IPluginContext *pContext, const cell_t *params)
ds@1952
  1246
{
ds@1952
  1247
	char *str;
ds@1952
  1248
	pContext->LocalToString(params[2], &str);
ds@1952
  1249
ds@1952
  1250
	return _ShowActivity2(pContext, params, str, 3);
ds@1952
  1251
}
ds@1952
  1252
ds@1952
  1253
static cell_t KickClient(IPluginContext *pContext, const cell_t *params)
ds@1952
  1254
{
ds@1952
  1255
	int client = params[1];
ds@1952
  1256
ds@1952
  1257
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
  1258
	if (!pPlayer)
ds@1952
  1259
	{
ds@1952
  1260
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@2162
  1261
	}
dvander@2162
  1262
	else if (!pPlayer->IsConnected())
dvander@2162
  1263
	{
ds@1952
  1264
		return pContext->ThrowNativeError("Client %d is not connected", client);
ds@1952
  1265
	}
ds@1952
  1266
dvander@2162
  1267
	/* Ignore duplicate kicks */
dvander@2162
  1268
	if (pPlayer->IsInKickQueue())
dvander@2162
  1269
	{
dvander@2162
  1270
		return 1;
dvander@2162
  1271
	}
dvander@2162
  1272
dvander@2162
  1273
	pPlayer->MarkAsBeingKicked();
dvander@2162
  1274
dvander@2162
  1275
	if (pPlayer->IsFakeClient())
dvander@2162
  1276
	{
dvander@2162
  1277
		char kickcmd[40];
dvander@2162
  1278
		UTIL_Format(kickcmd, sizeof(kickcmd), "kick %s\n", pPlayer->GetName());
dvander@2162
  1279
dvander@2162
  1280
		engine->ServerCommand(kickcmd);
dvander@2162
  1281
		return 1;
dvander@2162
  1282
	}
dvander@2162
  1283
dvander@2162
  1284
	g_SourceMod.SetGlobalTarget(client);
dvander@2162
  1285
dvander@2162
  1286
	char buffer[256];
dvander@2162
  1287
	g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
dvander@2162
  1288
dvander@2193
  1289
	if (pContext->GetLastNativeError() != SP_ERROR_NONE)
dvander@2162
  1290
	{
dvander@2162
  1291
		return 0;
dvander@2162
  1292
	}
dvander@2162
  1293
dvander@2162
  1294
	g_HL2.AddDelayedKick(client, pPlayer->GetUserId(), buffer);
dvander@2162
  1295
dvander@2162
  1296
	return 1;
dvander@2162
  1297
}
dvander@2162
  1298
dvander@2162
  1299
static cell_t KickClientEx(IPluginContext *pContext, const cell_t *params)
dvander@2162
  1300
{
dvander@2162
  1301
	int client = params[1];
dvander@2162
  1302
dvander@2162
  1303
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@2162
  1304
	if (!pPlayer)
dvander@2162
  1305
	{
dvander@2162
  1306
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@2162
  1307
	}
dvander@2162
  1308
	else if (!pPlayer->IsConnected())
dvander@2162
  1309
	{
dvander@2162
  1310
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@2162
  1311
	}
dvander@2162
  1312
dvander@2162
  1313
	/* Ignore duplicate kicks */
dvander@2162
  1314
	if (pPlayer->IsInKickQueue())
dvander@2162
  1315
	{
dvander@2162
  1316
		return 1;
dvander@2162
  1317
	}
dvander@2162
  1318
ds@1952
  1319
	pPlayer->MarkAsBeingKicked();
ds@1952
  1320
ds@1952
  1321
	if (pPlayer->IsFakeClient())
ds@1952
  1322
	{
ds@1952
  1323
		char kickcmd[40];
ds@1952
  1324
		UTIL_Format(kickcmd, sizeof(kickcmd), "kick %s\n", pPlayer->GetName());
ds@1952
  1325
ds@1952
  1326
		engine->ServerCommand(kickcmd);
ds@1952
  1327
		return 1;
ds@1952
  1328
	}
ds@1952
  1329
ds@1952
  1330
	g_SourceMod.SetGlobalTarget(client);
ds@1952
  1331
ds@1952
  1332
	char buffer[256];
ds@1952
  1333
	g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
ds@1952
  1334
dvander@2193
  1335
	if (pContext->GetLastNativeError() != SP_ERROR_NONE)
ds@1952
  1336
	{
ds@1952
  1337
		return 0;
ds@1952
  1338
	}
ds@1952
  1339
ds@1952
  1340
	pPlayer->Kick(buffer);
ds@1952
  1341
ds@1952
  1342
	return 1;
ds@1952
  1343
}
ds@1952
  1344
ds@1952
  1345
static cell_t ChangeClientTeam(IPluginContext *pContext, const cell_t *params)
ds@1952
  1346
{
ds@1952
  1347
	int client = params[1];
ds@1952
  1348
ds@1952
  1349
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
  1350
	if (!pPlayer)
ds@1952
  1351
	{
ds@1952
  1352
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
  1353
	}
ds@1952
  1354
	else if (!pPlayer->IsInGame())
ds@1952
  1355
	{
ds@1952
  1356
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
  1357
	}
ds@1952
  1358
ds@1952
  1359
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1952
  1360
	if (!pInfo)
ds@1952
  1361
	{
ds@1952
  1362
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1952
  1363
	}
ds@1952
  1364
ds@1952
  1365
	pInfo->ChangeTeam(params[2]);
ds@1952
  1366
ds@1952
  1367
	return 1;
ds@1952
  1368
}
ds@1952
  1369
ds@1952
  1370
static cell_t RunAdminCacheChecks(IPluginContext *pContext, const cell_t *params)
ds@1952
  1371
{
ds@1952
  1372
	int client = params[1];
ds@1952
  1373
ds@1952
  1374
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
  1375
	if (!pPlayer)
ds@1952
  1376
	{
ds@1952
  1377
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
  1378
	}
ds@1952
  1379
	else if (!pPlayer->IsInGame())
ds@1952
  1380
	{
ds@1952
  1381
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
  1382
	}
ds@1952
  1383
	else if (!pPlayer->IsAuthorized())
ds@1952
  1384
	{
ds@1952
  1385
		return pContext->ThrowNativeError("Client %d is not authorized", client);
ds@1952
  1386
	}
ds@1952
  1387
ds@1952
  1388
	AdminId id = pPlayer->GetAdminId();
ds@1952
  1389
	pPlayer->DoBasicAdminChecks();
ds@1952
  1390
ds@1952
  1391
	return (id != pPlayer->GetAdminId()) ? 1 : 0;
ds@1952
  1392
}
ds@1952
  1393
ds@1952
  1394
static cell_t NotifyPostAdminCheck(IPluginContext *pContext, const cell_t *params)
ds@1952
  1395
{
ds@1952
  1396
	int client = params[1];
ds@1952
  1397
ds@1952
  1398
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
  1399
	if (!pPlayer)
ds@1952
  1400
	{
ds@1952
  1401
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
  1402
	}
ds@1952
  1403
	else if (!pPlayer->IsInGame()) {
ds@1952
  1404
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
  1405
	}
ds@1952
  1406
	else if (!pPlayer->IsAuthorized())
ds@1952
  1407
	{
ds@1952
  1408
		return pContext->ThrowNativeError("Client %d is not authorized", client);
ds@1952
  1409
	}
ds@1952
  1410
ds@1952
  1411
	pPlayer->NotifyPostAdminChecks();
ds@1952
  1412
ds@1952
  1413
	return 1;
ds@1952
  1414
}
ds@1952
  1415
ds@1952
  1416
static cell_t IsClientInKickQueue(IPluginContext *pContext, const cell_t *params)
ds@1952
  1417
{
ds@1952
  1418
	int client = params[1];
ds@1952
  1419
ds@1952
  1420
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
  1421
ds@1952
  1422
	if (!pPlayer)
ds@1952
  1423
	{
ds@1952
  1424
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1952
  1425
	}
ds@1952
  1426
	else if (!pPlayer->IsConnected())
ds@1952
  1427
	{
ds@1952
  1428
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1952
  1429
	}
ds@1952
  1430
ds@1952
  1431
	return pPlayer->IsInKickQueue() ? 1 : 0;
ds@1952
  1432
}
ds@1952
  1433
ds@1952
  1434
static cell_t ProcessTargetString(IPluginContext *pContext, const cell_t *params)
ds@1952
  1435
{
ds@1952
  1436
	cmd_target_info_t info;
ds@1952
  1437
ds@1952
  1438
	pContext->LocalToString(params[1], (char **)&info.pattern);
ds@1952
  1439
	info.admin = params[2];
ds@1952
  1440
	pContext->LocalToPhysAddr(params[3], &info.targets);
ds@1952
  1441
	info.max_targets = params[4];
ds@1952
  1442
	info.flags = params[5];
ds@1952
  1443
	pContext->LocalToString(params[6], &info.target_name);
ds@1952
  1444
	info.target_name_maxlength = params[7];
ds@1952
  1445
ds@1952
  1446
	cell_t *tn_is_ml;
ds@1952
  1447
	pContext->LocalToPhysAddr(params[8], &tn_is_ml);
ds@1952
  1448
ds@1952
  1449
	g_Players.ProcessCommandTarget(&info);
ds@1952
  1450
ds@1952
  1451
	if (info.target_name_style == COMMAND_TARGETNAME_ML)
ds@1952
  1452
	{
ds@1952
  1453
		*tn_is_ml = 1;
ds@1952
  1454
	}
ds@1952
  1455
	else
ds@1952
  1456
	{
ds@1952
  1457
		*tn_is_ml = 0;
ds@1952
  1458
	}
ds@1952
  1459
ds@1952
  1460
	if (info.num_targets == 0)
ds@1952
  1461
	{
ds@1952
  1462
		return info.reason;
ds@1952
  1463
	}
ds@1952
  1464
	else
ds@1952
  1465
	{
ds@1952
  1466
		return info.num_targets;
ds@1952
  1467
	}
ds@1952
  1468
}
ds@1952
  1469
ds@1952
  1470
REGISTER_NATIVES(playernatives)
ds@1952
  1471
{
ds@1952
  1472
	{"AddUserFlags",			AddUserFlags},
ds@1952
  1473
	{"CanUserTarget",			CanUserTarget},
ds@1952
  1474
	{"ChangeClientTeam",		ChangeClientTeam},
ds@1952
  1475
	{"GetClientAuthString",		sm_GetClientAuthStr},
ds@1952
  1476
	{"GetClientCount",			sm_GetClientCount},
ds@1952
  1477
	{"GetClientInfo",			sm_GetClientInfo},
ds@1952
  1478
	{"GetClientIP",				sm_GetClientIP},
ds@1952
  1479
	{"GetClientName",			sm_GetClientName},
ds@1952
  1480
	{"GetClientTeam",			GetClientTeam},
ds@1952
  1481
	{"GetClientUserId",			GetClientUserId},
ds@1952
  1482
	{"GetMaxClients",			sm_GetMaxClients},
ds@1952
  1483
	{"GetUserAdmin",			GetUserAdmin},
ds@1952
  1484
	{"GetUserFlagBits",			GetUserFlagBits},
ds@1952
  1485
	{"IsClientAuthorized",		sm_IsClientAuthorized},
ds@1952
  1486
	{"IsClientConnected",		sm_IsClientConnected},
ds@1952
  1487
	{"IsFakeClient",			sm_IsClientFakeClient},
ds@1952
  1488
	{"IsClientInGame",			sm_IsClientInGame},
ds@1952
  1489
	{"IsClientObserver",		IsClientObserver},
ds@1952
  1490
	{"RemoveUserFlags",			RemoveUserFlags},
ds@1952
  1491
	{"SetUserAdmin",			SetUserAdmin},
ds@1952
  1492
	{"SetUserFlagBits",			SetUserFlagBits},
ds@1952
  1493
	{"GetClientDeaths",			GetDeathCount},
ds@1952
  1494
	{"GetClientFrags",			GetFragCount},
ds@1952
  1495
	{"GetClientArmor",			GetArmorValue},
ds@1952
  1496
	{"GetClientAbsOrigin",		GetAbsOrigin},
ds@1952
  1497
	{"GetClientAbsAngles",		GetAbsAngles},
ds@1952
  1498
	{"GetClientMins",			GetPlayerMins},
ds@1952
  1499
	{"GetClientMaxs",			GetPlayerMaxs},
ds@1952
  1500
	{"GetClientWeapon",			GetWeaponName},
ds@1952
  1501
	{"GetClientModel",			GetModelName},
ds@1952
  1502
	{"GetClientHealth",			GetHealth},
ds@1952
  1503
	{"GetClientTime",			GetTimeConnected},
ds@1952
  1504
	{"GetClientDataRate",		GetDataRate},
ds@1952
  1505
	{"IsClentTimingOut",		IsTimingOut},
ds@1952
  1506
	{"GetClientLatency",		GetLatency},
ds@1952
  1507
	{"GetClientAvgLatency",		GetAvgLatency},
ds@1952
  1508
	{"GetClientAvgLoss",		GetAvgLoss},
ds@1952
  1509
	{"GetClientAvgChoke",		GetAvgChoke},
ds@1952
  1510
	{"GetClientAvgData",		GetAvgData},
ds@1952
  1511
	{"GetClientAvgPackets",		GetAvgPackets},
ds@1952
  1512
	{"GetClientOfUserId",		GetClientOfUserId},
ds@1952
  1513
	{"ShowActivity",			ShowActivity},
ds@1952
  1514
	{"ShowActivityEx",			ShowActivityEx},
ds@1952
  1515
	{"ShowActivity2",			ShowActivity2},
ds@1952
  1516
	{"KickClient",				KickClient},
dvander@2162
  1517
	{"KickClientEx",			KickClientEx},
ds@1952
  1518
	{"RunAdminCacheChecks",		RunAdminCacheChecks},
ds@1952
  1519
	{"NotifyPostAdminCheck",	NotifyPostAdminCheck},
ds@1952
  1520
	{"IsClientInKickQueue",		IsClientInKickQueue},
ds@1952
  1521
	{"ProcessTargetString",		ProcessTargetString},
ds@1952
  1522
	{NULL,						NULL}
ds@1952
  1523
};
ds@1952
  1524