core/smn_player.cpp
author Scott Ehlert <ds@alliedmods.net>
Wed Aug 15 06:19:30 2007 +0000 (2007-08-15)
changeset 1330 ab94316bb52b
parent 1273 9afc766f8e9c
child 1423 e73b3563f254
permissions -rw-r--r--
Updated license headers on virtually all files with extremely minor changes in the name of some sort of strange consistency.
All plugin and include file headers also have been changed to say about GPL3 instead of GPL2.

(This day shall henceforth be known as the Eighty Column Massacre of '07)
dvander@370
     1
/**
ds@653
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
dvander@1231
     5
 * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
dvander@370
     7
 *
ds@1330
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    10
 * Free Software Foundation.
dvander@1231
    11
 * 
ds@1330
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    15
 * details.
dvander@1231
    16
 *
ds@1330
    17
 * You should have received a copy of the GNU General Public License along with
ds@1330
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
ds@1330
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@370
    28
 *
dvander@370
    29
 * Version: $Id$
dvander@370
    30
 */
dvander@370
    31
dvander@591
    32
#include "PlayerManager.h"
dvander@458
    33
#include "AdminCache.h"
faluco@280
    34
#include "sm_stringutil.h"
dvander@910
    35
#include "HalfLife2.h"
dvander@910
    36
#include "sourcemod.h"
dvander@924
    37
#include "ChatTriggers.h"
ds@992
    38
#include <inetchannel.h>
ds@992
    39
#include <iclient.h>
faluco@242
    40
dvander@923
    41
ConVar sm_show_activity("sm_show_activity", "13", FCVAR_SPONLY|FCVAR_PROTECTED, "Activity display setting (see sourcemod.cfg)");
dvander@910
    42
faluco@260
    43
static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params)
faluco@242
    44
{
faluco@242
    45
	if (params[1])
faluco@242
    46
	{
dvander@448
    47
		return g_Players.NumPlayers();
faluco@242
    48
	}
faluco@242
    49
dvander@448
    50
	int maxplayers = g_Players.MaxClients();
faluco@242
    51
	int count = 0;
faluco@242
    52
	for (int i=1; i<=maxplayers; ++i)
faluco@242
    53
	{
dvander@448
    54
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
dvander@435
    55
		if ((pPlayer->IsConnected()) && !(pPlayer->IsInGame()))
faluco@242
    56
		{
faluco@242
    57
			count++;
faluco@242
    58
		}
faluco@242
    59
	}
faluco@242
    60
dvander@448
    61
	return (g_Players.NumPlayers() + count);
faluco@242
    62
}
faluco@242
    63
faluco@260
    64
static cell_t sm_GetMaxClients(IPluginContext *pCtx, const cell_t *params)
faluco@242
    65
{
dvander@448
    66
	return g_Players.MaxClients();
faluco@242
    67
}
faluco@242
    68
faluco@260
    69
static cell_t sm_GetClientName(IPluginContext *pCtx, const cell_t *params)
faluco@242
    70
{
faluco@242
    71
	int index = params[1];
dvander@1049
    72
dvander@1049
    73
	if (index == 0)
dvander@1049
    74
	{
dvander@1049
    75
		static ConVar *hostname = NULL;
dvander@1049
    76
		if (!hostname)
dvander@1049
    77
		{
dvander@1049
    78
			hostname = icvar->FindVar("hostname");
dvander@1049
    79
			if (!hostname)
dvander@1049
    80
			{
dvander@1049
    81
				return pCtx->ThrowNativeError("Could not find \"hostname\" cvar");
dvander@1049
    82
			}
dvander@1049
    83
		}
dvander@1049
    84
		pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), hostname->GetString(), NULL);
dvander@1049
    85
		return 1;
dvander@1049
    86
	}
dvander@1049
    87
dvander@448
    88
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
    89
	{
ds@994
    90
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
    91
	}
faluco@242
    92
dvander@448
    93
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
    94
	if (!pPlayer->IsConnected())
faluco@260
    95
	{
ds@470
    96
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@260
    97
	}
faluco@260
    98
dvander@435
    99
	pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pPlayer->GetName(), NULL);
faluco@242
   100
	return 1;
faluco@242
   101
}
faluco@242
   102
faluco@260
   103
static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params)
faluco@242
   104
{
faluco@242
   105
	int index = params[1];
dvander@448
   106
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   107
	{
ds@994
   108
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
   109
	}
faluco@242
   110
dvander@448
   111
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
   112
	if (!pPlayer->IsConnected())
faluco@260
   113
	{
ds@470
   114
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@260
   115
	}
faluco@260
   116
faluco@280
   117
	char buf[64], *ptr;
dvander@435
   118
	strcpy(buf, pPlayer->GetIPAddress());
faluco@280
   119
faluco@280
   120
	if (params[4] && (ptr = strchr(buf, ':')))
faluco@280
   121
	{
faluco@280
   122
		*ptr = '\0';
faluco@280
   123
	}
faluco@280
   124
faluco@280
   125
	pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), buf);
faluco@242
   126
	return 1;
faluco@242
   127
}
faluco@242
   128
faluco@260
   129
static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params)
faluco@242
   130
{
faluco@242
   131
	int index = params[1];
dvander@448
   132
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   133
	{
ds@994
   134
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
   135
	}
faluco@242
   136
dvander@448
   137
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
   138
	if (!pPlayer->IsConnected())
faluco@260
   139
	{
ds@470
   140
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@260
   141
	}
faluco@260
   142
dvander@449
   143
	if (!pPlayer->IsAuthorized())
dvander@449
   144
	{
dvander@449
   145
		return 0;
dvander@449
   146
	}
dvander@449
   147
dvander@435
   148
	pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), pPlayer->GetAuthString());
dvander@449
   149
faluco@242
   150
	return 1;
faluco@242
   151
}
faluco@242
   152
ds@784
   153
static cell_t sm_IsClientConnected(IPluginContext *pCtx, const cell_t *params)
faluco@242
   154
{
faluco@242
   155
	int index = params[1];
dvander@448
   156
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   157
	{
ds@994
   158
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
   159
	}
faluco@242
   160
dvander@448
   161
	return (g_Players.GetPlayerByIndex(index)->IsConnected()) ? 1 : 0;
faluco@242
   162
}
faluco@242
   163
ds@784
   164
static cell_t sm_IsClientInGame(IPluginContext *pCtx, const cell_t *params)
faluco@242
   165
{
faluco@242
   166
	int index = params[1];
dvander@448
   167
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   168
	{
ds@994
   169
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
   170
	}
faluco@242
   171
dvander@448
   172
	return (g_Players.GetPlayerByIndex(index)->IsInGame()) ? 1 : 0;
faluco@242
   173
}
faluco@242
   174
ds@784
   175
static cell_t sm_IsClientAuthorized(IPluginContext *pCtx, const cell_t *params)
faluco@242
   176
{
faluco@242
   177
	int index = params[1];
dvander@448
   178
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   179
	{
ds@994
   180
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
   181
	}
faluco@242
   182
dvander@448
   183
	return (g_Players.GetPlayerByIndex(index)->IsAuthorized()) ? 1 : 0;
faluco@242
   184
}
faluco@242
   185
ds@784
   186
static cell_t sm_IsClientFakeClient(IPluginContext *pCtx, const cell_t *params)
faluco@242
   187
{
faluco@242
   188
	int index = params[1];
dvander@448
   189
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   190
	{
ds@994
   191
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@260
   192
	}
faluco@260
   193
dvander@448
   194
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
   195
	if (!pPlayer->IsConnected())
faluco@260
   196
	{
ds@470
   197
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@242
   198
	}
faluco@242
   199
dvander@435
   200
	return (pPlayer->IsFakeClient()) ? 1 : 0;
faluco@260
   201
}
faluco@260
   202
ds@1001
   203
static cell_t IsClientObserver(IPluginContext *pContext, const cell_t *params)
ds@1001
   204
{
ds@1001
   205
	int client = params[1];
ds@1001
   206
ds@1001
   207
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1001
   208
	if (!pPlayer)
ds@1001
   209
	{
ds@1001
   210
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1001
   211
	} else if (!pPlayer->IsInGame()) {
ds@1001
   212
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1001
   213
	}
ds@1001
   214
ds@1001
   215
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1001
   216
	if (!pInfo)
ds@1001
   217
	{
ds@1001
   218
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1001
   219
	}
ds@1001
   220
ds@1001
   221
	return pInfo->IsObserver() ? 1 : 0;
ds@1001
   222
}
ds@1001
   223
dvander@456
   224
static cell_t sm_GetClientInfo(IPluginContext *pContext, const cell_t *params)
dvander@456
   225
{
dvander@456
   226
	int client = params[1];
dvander@456
   227
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@456
   228
	if (!pPlayer)
dvander@456
   229
	{
ds@994
   230
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@456
   231
	}
dvander@456
   232
	if (!pPlayer->IsConnected())
dvander@456
   233
	{
ds@470
   234
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@456
   235
	}
dvander@456
   236
dvander@456
   237
	char *key;
dvander@456
   238
	pContext->LocalToString(params[2], &key);
dvander@456
   239
dvander@456
   240
	const char *val = engine->GetClientConVarValue(client, key);
dvander@456
   241
	if (!val)
dvander@456
   242
	{
dvander@456
   243
		return false;
dvander@456
   244
	}
dvander@456
   245
dvander@456
   246
	pContext->StringToLocalUTF8(params[3], params[4], val, NULL);
dvander@456
   247
	return 1;
dvander@456
   248
}
dvander@456
   249
dvander@458
   250
static cell_t SetUserAdmin(IPluginContext *pContext, const cell_t *params)
dvander@458
   251
{
dvander@458
   252
	int client = params[1];
dvander@458
   253
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   254
	if (!pPlayer)
dvander@458
   255
	{
ds@994
   256
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   257
	}
dvander@458
   258
	if (!pPlayer->IsConnected())
dvander@458
   259
	{
ds@470
   260
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   261
	}
dvander@458
   262
	if (!g_Admins.IsValidAdmin(params[2]))
dvander@458
   263
	{
ds@994
   264
		return pContext->ThrowNativeError("AdminId %x is invalid", params[2]);
dvander@458
   265
	}
dvander@458
   266
dvander@458
   267
	pPlayer->SetAdminId(params[2], params[3] ? true : false);
dvander@458
   268
dvander@458
   269
	return 1;
dvander@458
   270
}
dvander@458
   271
dvander@458
   272
static cell_t GetUserAdmin(IPluginContext *pContext, const cell_t *params)
dvander@458
   273
{
dvander@458
   274
	int client = params[1];
dvander@458
   275
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   276
	if (!pPlayer)
dvander@458
   277
	{
ds@994
   278
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   279
	}
dvander@458
   280
	if (!pPlayer->IsConnected())
dvander@458
   281
	{
ds@470
   282
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   283
	}
dvander@458
   284
dvander@458
   285
	return pPlayer->GetAdminId();
dvander@458
   286
}
dvander@458
   287
dvander@458
   288
static cell_t AddUserFlags(IPluginContext *pContext, const cell_t *params)
dvander@458
   289
{
dvander@458
   290
	int client = params[1];
dvander@458
   291
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   292
	if (!pPlayer)
dvander@458
   293
	{
ds@994
   294
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   295
	}
dvander@458
   296
	if (!pPlayer->IsConnected())
dvander@458
   297
	{
ds@470
   298
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   299
	}
dvander@458
   300
dvander@458
   301
	AdminId id;
dvander@458
   302
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   303
	{
dvander@458
   304
		id = g_Admins.CreateAdmin(NULL);
dvander@458
   305
		pPlayer->SetAdminId(id, true);
dvander@458
   306
	}
dvander@458
   307
dvander@458
   308
	cell_t *addr;
dvander@458
   309
	for (int i=2; i<=params[0]; i++)
dvander@458
   310
	{
dvander@458
   311
		pContext->LocalToPhysAddr(params[i], &addr);
dvander@458
   312
		g_Admins.SetAdminFlag(id, (AdminFlag)*addr, true);
dvander@458
   313
	}
dvander@458
   314
dvander@458
   315
	return 1;
dvander@458
   316
}
dvander@458
   317
dvander@458
   318
static cell_t RemoveUserFlags(IPluginContext *pContext, const cell_t *params)
dvander@458
   319
{
dvander@458
   320
	int client = params[1];
dvander@458
   321
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   322
	if (!pPlayer)
dvander@458
   323
	{
ds@994
   324
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   325
	}
dvander@458
   326
	if (!pPlayer->IsConnected())
dvander@458
   327
	{
ds@470
   328
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   329
	}
dvander@458
   330
	
dvander@458
   331
	AdminId id;
dvander@458
   332
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   333
	{
dvander@458
   334
		return 0;
dvander@458
   335
	}
dvander@458
   336
dvander@458
   337
	cell_t *addr;
dvander@458
   338
	for (int i=2; i<=params[0]; i++)
dvander@458
   339
	{
dvander@458
   340
		pContext->LocalToPhysAddr(params[i], &addr);
dvander@458
   341
		g_Admins.SetAdminFlag(id, (AdminFlag)*addr, false);
dvander@458
   342
	}
dvander@458
   343
dvander@458
   344
	return 1;
dvander@458
   345
}
dvander@458
   346
dvander@458
   347
static cell_t SetUserFlagBits(IPluginContext *pContext, const cell_t *params)
dvander@458
   348
{
dvander@458
   349
	int client = params[1];
dvander@458
   350
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   351
	if (!pPlayer)
dvander@458
   352
	{
ds@994
   353
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   354
	}
dvander@458
   355
	if (!pPlayer->IsConnected())
dvander@458
   356
	{
ds@470
   357
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   358
	}
dvander@458
   359
dvander@458
   360
	AdminId id;
dvander@458
   361
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   362
	{
dvander@458
   363
		id = g_Admins.CreateAdmin(NULL);
dvander@458
   364
		pPlayer->SetAdminId(id, true);
dvander@458
   365
	}
dvander@458
   366
dvander@458
   367
	g_Admins.SetAdminFlags(id, Access_Effective, params[2]);
dvander@458
   368
dvander@458
   369
	return 1;
dvander@458
   370
}
dvander@458
   371
dvander@458
   372
static cell_t GetUserFlagBits(IPluginContext *pContext, const cell_t *params)
dvander@458
   373
{
dvander@458
   374
	int client = params[1];
dvander@458
   375
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   376
	if (!pPlayer)
dvander@458
   377
	{
ds@994
   378
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   379
	}
dvander@458
   380
	if (!pPlayer->IsConnected())
dvander@458
   381
	{
ds@470
   382
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   383
	}
dvander@458
   384
dvander@458
   385
	AdminId id;
dvander@458
   386
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   387
	{
dvander@458
   388
		return 0;
dvander@458
   389
	}
dvander@458
   390
dvander@458
   391
	return g_Admins.GetAdminFlags(id, Access_Effective);
dvander@458
   392
}
dvander@458
   393
dvander@460
   394
static cell_t GetClientUserId(IPluginContext *pContext, const cell_t *params)
dvander@460
   395
{
dvander@460
   396
	int client = params[1];
dvander@460
   397
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@460
   398
	if (!pPlayer)
dvander@460
   399
	{
ds@994
   400
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@460
   401
	}
dvander@460
   402
	if (!pPlayer->IsConnected())
dvander@460
   403
	{
ds@470
   404
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@460
   405
	}
dvander@460
   406
dvander@460
   407
	return engine->GetPlayerUserId(pPlayer->GetEdict());
dvander@460
   408
}
dvander@460
   409
dvander@540
   410
static cell_t CanUserTarget(IPluginContext *pContext, const cell_t *params)
dvander@540
   411
{
dvander@540
   412
	int client = params[1];
dvander@540
   413
	int target = params[2];
dvander@540
   414
dvander@1035
   415
	if (client == 0)
dvander@1035
   416
	{
dvander@1035
   417
		return 1;
dvander@1035
   418
	}
dvander@1035
   419
dvander@540
   420
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@540
   421
	if (!pPlayer)
dvander@540
   422
	{
ds@994
   423
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@540
   424
	} else if (!pPlayer->IsConnected()) {
ds@994
   425
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@540
   426
	}
dvander@540
   427
dvander@540
   428
	CPlayer *pTarget = g_Players.GetPlayerByIndex(target);
dvander@540
   429
	if (!pTarget)
dvander@540
   430
	{
ds@994
   431
		return pContext->ThrowNativeError("Client index %d is invalid", target);
dvander@540
   432
	} else if (!pTarget->IsConnected()) {
ds@994
   433
		return pContext->ThrowNativeError("Client %d is not connected", target);
dvander@540
   434
	}
dvander@540
   435
dvander@540
   436
	return g_Admins.CanAdminTarget(pPlayer->GetAdminId(), pTarget->GetAdminId()) ? 1 : 0;
dvander@540
   437
}
dvander@540
   438
dvander@644
   439
static cell_t GetClientTeam(IPluginContext *pContext, const cell_t *params)
dvander@644
   440
{
dvander@644
   441
	int client = params[1];
dvander@644
   442
dvander@644
   443
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@644
   444
	if (!pPlayer)
dvander@644
   445
	{
ds@994
   446
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@644
   447
	} else if (!pPlayer->IsInGame()) {
ds@994
   448
		return pContext->ThrowNativeError("Client %d is not in game", client);
dvander@644
   449
	}
dvander@644
   450
dvander@644
   451
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
dvander@644
   452
	if (!pInfo)
dvander@644
   453
	{
dvander@644
   454
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
dvander@644
   455
	}
dvander@644
   456
dvander@644
   457
	return pInfo->GetTeamIndex();
dvander@644
   458
}
dvander@644
   459
faluco@658
   460
static cell_t GetFragCount(IPluginContext *pContext, const cell_t *params)
faluco@658
   461
{
faluco@658
   462
	int client = params[1];
faluco@658
   463
faluco@658
   464
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   465
	if (!pPlayer)
faluco@658
   466
	{
ds@994
   467
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   468
	} else if (!pPlayer->IsInGame()) {
ds@994
   469
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   470
	}
faluco@658
   471
faluco@658
   472
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   473
	if (!pInfo)
faluco@658
   474
	{
faluco@658
   475
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   476
	}
faluco@658
   477
faluco@658
   478
	return pInfo->GetFragCount();
faluco@658
   479
}
faluco@658
   480
faluco@658
   481
static cell_t GetDeathCount(IPluginContext *pContext, const cell_t *params)
faluco@658
   482
{
faluco@658
   483
	int client = params[1];
faluco@658
   484
faluco@658
   485
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   486
	if (!pPlayer)
faluco@658
   487
	{
ds@994
   488
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   489
	} else if (!pPlayer->IsInGame()) {
ds@994
   490
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   491
	}
faluco@658
   492
faluco@658
   493
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   494
	if (!pInfo)
faluco@658
   495
	{
faluco@658
   496
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   497
	}
faluco@658
   498
faluco@658
   499
	return pInfo->GetDeathCount();
faluco@658
   500
}
faluco@658
   501
faluco@658
   502
static cell_t GetArmorValue(IPluginContext *pContext, const cell_t *params)
faluco@658
   503
{
faluco@658
   504
	int client = params[1];
faluco@658
   505
faluco@658
   506
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   507
	if (!pPlayer)
faluco@658
   508
	{
ds@994
   509
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   510
	} else if (!pPlayer->IsInGame()) {
ds@994
   511
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   512
	}
faluco@658
   513
faluco@658
   514
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   515
	if (!pInfo)
faluco@658
   516
	{
faluco@658
   517
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   518
	}
faluco@658
   519
faluco@658
   520
	return pInfo->GetArmorValue();
faluco@658
   521
}
faluco@658
   522
faluco@658
   523
static cell_t GetAbsOrigin(IPluginContext *pContext, const cell_t *params)
faluco@658
   524
{
faluco@658
   525
	int client = params[1];
faluco@658
   526
faluco@658
   527
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   528
	if (!pPlayer)
faluco@658
   529
	{
ds@994
   530
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   531
	} else if (!pPlayer->IsInGame()) {
ds@994
   532
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   533
	}
faluco@658
   534
faluco@658
   535
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   536
	if (!pInfo)
faluco@658
   537
	{
faluco@658
   538
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   539
	}
faluco@658
   540
faluco@658
   541
	cell_t *pVec;
faluco@658
   542
	pContext->LocalToPhysAddr(params[2], &pVec);
faluco@658
   543
faluco@658
   544
	Vector vec = pInfo->GetAbsOrigin();
faluco@658
   545
	pVec[0] = sp_ftoc(vec.x);
faluco@658
   546
	pVec[1] = sp_ftoc(vec.y);
faluco@658
   547
	pVec[2] = sp_ftoc(vec.z);
faluco@658
   548
faluco@658
   549
	return 1;
faluco@658
   550
}
faluco@658
   551
faluco@658
   552
static cell_t GetAbsAngles(IPluginContext *pContext, const cell_t *params)
faluco@658
   553
{
faluco@658
   554
	int client = params[1];
faluco@658
   555
faluco@658
   556
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   557
	if (!pPlayer)
faluco@658
   558
	{
ds@994
   559
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   560
	} else if (!pPlayer->IsInGame()) {
ds@994
   561
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   562
	}
faluco@658
   563
faluco@658
   564
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   565
	if (!pInfo)
faluco@658
   566
	{
faluco@658
   567
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   568
	}
faluco@658
   569
faluco@658
   570
	cell_t *pAng;
faluco@658
   571
	pContext->LocalToPhysAddr(params[2], &pAng);
faluco@658
   572
faluco@658
   573
	QAngle ang = pInfo->GetAbsAngles();
faluco@658
   574
	pAng[0] = sp_ftoc(ang.x);
faluco@658
   575
	pAng[1] = sp_ftoc(ang.y);
faluco@658
   576
	pAng[2] = sp_ftoc(ang.z);
faluco@658
   577
faluco@658
   578
	return 1;
faluco@658
   579
}
faluco@658
   580
faluco@658
   581
static cell_t GetPlayerMins(IPluginContext *pContext, const cell_t *params)
faluco@658
   582
{
faluco@658
   583
	int client = params[1];
faluco@658
   584
faluco@658
   585
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   586
	if (!pPlayer)
faluco@658
   587
	{
ds@994
   588
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   589
	} else if (!pPlayer->IsInGame()) {
ds@994
   590
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   591
	}
faluco@658
   592
faluco@658
   593
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   594
	if (!pInfo)
faluco@658
   595
	{
faluco@658
   596
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   597
	}
faluco@658
   598
faluco@658
   599
	cell_t *pVec;
faluco@658
   600
	pContext->LocalToPhysAddr(params[2], &pVec);
faluco@658
   601
faluco@658
   602
	Vector vec = pInfo->GetPlayerMins();
faluco@658
   603
	pVec[0] = sp_ftoc(vec.x);
faluco@658
   604
	pVec[1] = sp_ftoc(vec.y);
faluco@658
   605
	pVec[2] = sp_ftoc(vec.z);
faluco@658
   606
faluco@658
   607
	return 1;
faluco@658
   608
}
faluco@658
   609
faluco@658
   610
static cell_t GetPlayerMaxs(IPluginContext *pContext, const cell_t *params)
faluco@658
   611
{
faluco@658
   612
	int client = params[1];
faluco@658
   613
faluco@658
   614
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   615
	if (!pPlayer)
faluco@658
   616
	{
ds@994
   617
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   618
	} else if (!pPlayer->IsInGame()) {
ds@994
   619
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   620
	}
faluco@658
   621
faluco@658
   622
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   623
	if (!pInfo)
faluco@658
   624
	{
faluco@658
   625
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   626
	}
faluco@658
   627
faluco@658
   628
	cell_t *pVec;
faluco@658
   629
	pContext->LocalToPhysAddr(params[2], &pVec);
faluco@658
   630
faluco@658
   631
	Vector vec = pInfo->GetPlayerMaxs();
faluco@658
   632
	pVec[0] = sp_ftoc(vec.x);
faluco@658
   633
	pVec[1] = sp_ftoc(vec.y);
faluco@658
   634
	pVec[2] = sp_ftoc(vec.z);
faluco@658
   635
faluco@658
   636
	return 1;
faluco@658
   637
}
faluco@658
   638
faluco@658
   639
static cell_t GetWeaponName(IPluginContext *pContext, const cell_t *params)
faluco@658
   640
{
faluco@658
   641
	int client = params[1];
faluco@658
   642
faluco@658
   643
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   644
	if (!pPlayer)
faluco@658
   645
	{
ds@994
   646
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   647
	} else if (!pPlayer->IsInGame()) {
ds@994
   648
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   649
	}
faluco@658
   650
faluco@658
   651
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   652
	if (!pInfo)
faluco@658
   653
	{
faluco@658
   654
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   655
	}
faluco@658
   656
faluco@756
   657
	const char *weapon = pInfo->GetWeaponName();
faluco@756
   658
	pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), weapon ? weapon : "", NULL);
faluco@658
   659
faluco@658
   660
	return 1;
faluco@658
   661
}
faluco@658
   662
faluco@658
   663
static cell_t GetModelName(IPluginContext *pContext, const cell_t *params)
faluco@658
   664
{
faluco@658
   665
	int client = params[1];
faluco@658
   666
faluco@658
   667
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   668
	if (!pPlayer)
faluco@658
   669
	{
ds@994
   670
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   671
	} else if (!pPlayer->IsInGame()) {
ds@994
   672
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   673
	}
faluco@658
   674
faluco@658
   675
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   676
	if (!pInfo)
faluco@658
   677
	{
faluco@658
   678
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   679
	}
faluco@658
   680
faluco@756
   681
	const char *model = pInfo->GetModelName();
faluco@756
   682
	pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), model ? model : "", NULL);
faluco@658
   683
faluco@658
   684
	return 1;
faluco@658
   685
}
faluco@658
   686
faluco@658
   687
static cell_t GetHealth(IPluginContext *pContext, const cell_t *params)
faluco@658
   688
{
faluco@658
   689
	int client = params[1];
faluco@658
   690
faluco@658
   691
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   692
	if (!pPlayer)
faluco@658
   693
	{
ds@994
   694
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   695
	} else if (!pPlayer->IsInGame()) {
ds@994
   696
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   697
	}
faluco@658
   698
faluco@658
   699
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   700
	if (!pInfo)
faluco@658
   701
	{
faluco@658
   702
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   703
	}
faluco@658
   704
faluco@658
   705
	return pInfo->GetHealth();
faluco@658
   706
}
faluco@658
   707
faluco@682
   708
static cell_t GetTimeConnected(IPluginContext *pContext, const cell_t *params)
faluco@682
   709
{
faluco@682
   710
	int client = params[1];
faluco@682
   711
faluco@682
   712
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   713
	if (!pPlayer)
faluco@682
   714
	{
ds@994
   715
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   716
	} else if (!pPlayer->IsInGame()) {
ds@994
   717
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   718
	} else if (pPlayer->IsFakeClient()) {
ds@994
   719
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   720
	}
faluco@682
   721
faluco@682
   722
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   723
faluco@682
   724
	return sp_ftoc(pInfo->GetTimeConnected());
faluco@682
   725
}
faluco@682
   726
faluco@682
   727
static cell_t GetDataRate(IPluginContext *pContext, const cell_t *params)
faluco@682
   728
{
faluco@682
   729
	int client = params[1];
faluco@682
   730
faluco@682
   731
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   732
	if (!pPlayer)
faluco@682
   733
	{
ds@994
   734
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   735
	} else if (!pPlayer->IsInGame()) {
ds@994
   736
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   737
	} else if (pPlayer->IsFakeClient()) {
ds@994
   738
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   739
	}
faluco@682
   740
faluco@682
   741
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   742
faluco@682
   743
	return pInfo->GetDataRate();
faluco@682
   744
}
faluco@682
   745
faluco@682
   746
static cell_t IsTimingOut(IPluginContext *pContext, const cell_t *params)
faluco@682
   747
{
faluco@682
   748
	int client = params[1];
faluco@682
   749
faluco@682
   750
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   751
	if (!pPlayer)
faluco@682
   752
	{
ds@994
   753
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   754
	} else if (!pPlayer->IsInGame()) {
ds@994
   755
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   756
	} else if (pPlayer->IsFakeClient()) {
ds@994
   757
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   758
	}
faluco@682
   759
faluco@682
   760
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   761
faluco@682
   762
	return pInfo->IsTimingOut() ? 1 : 0;
faluco@682
   763
}
faluco@682
   764
faluco@682
   765
static cell_t GetLatency(IPluginContext *pContext, const cell_t *params)
faluco@682
   766
{
faluco@682
   767
	int client = params[1];
faluco@682
   768
faluco@682
   769
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   770
	if (!pPlayer)
faluco@682
   771
	{
ds@994
   772
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   773
	} else if (!pPlayer->IsInGame()) {
ds@994
   774
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   775
	} else if (pPlayer->IsFakeClient()) {
ds@994
   776
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   777
	}
faluco@682
   778
faluco@682
   779
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   780
faluco@682
   781
	return sp_ftoc(pInfo->GetLatency(params[2]));
faluco@682
   782
}
faluco@682
   783
faluco@682
   784
static cell_t GetAvgLatency(IPluginContext *pContext, const cell_t *params)
faluco@682
   785
{
faluco@682
   786
	int client = params[1];
faluco@682
   787
faluco@682
   788
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   789
	if (!pPlayer)
faluco@682
   790
	{
ds@994
   791
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   792
	} else if (!pPlayer->IsInGame()) {
ds@994
   793
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   794
	} else if (pPlayer->IsFakeClient()) {
ds@994
   795
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   796
	}
faluco@682
   797
faluco@682
   798
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   799
faluco@682
   800
	return sp_ftoc(pInfo->GetAvgLatency(params[2]));
faluco@682
   801
}
faluco@682
   802
faluco@682
   803
static cell_t GetAvgLoss(IPluginContext *pContext, const cell_t *params)
faluco@682
   804
{
faluco@682
   805
	int client = params[1];
faluco@682
   806
faluco@682
   807
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   808
	if (!pPlayer)
faluco@682
   809
	{
ds@994
   810
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   811
	} else if (!pPlayer->IsInGame()) {
ds@994
   812
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   813
	} else if (pPlayer->IsFakeClient()) {
ds@994
   814
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   815
	}
faluco@682
   816
faluco@682
   817
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   818
faluco@682
   819
	return sp_ftoc(pInfo->GetAvgLoss(params[2]));
faluco@682
   820
}
faluco@682
   821
faluco@682
   822
static cell_t GetAvgChoke(IPluginContext *pContext, const cell_t *params)
faluco@682
   823
{
faluco@682
   824
	int client = params[1];
faluco@682
   825
faluco@682
   826
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   827
	if (!pPlayer)
faluco@682
   828
	{
ds@994
   829
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   830
	} else if (!pPlayer->IsInGame()) {
ds@994
   831
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   832
	} else if (pPlayer->IsFakeClient()) {
ds@994
   833
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   834
	}
faluco@682
   835
faluco@682
   836
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   837
faluco@682
   838
	return sp_ftoc(pInfo->GetAvgChoke(params[2]));
faluco@682
   839
}
faluco@682
   840
faluco@682
   841
static cell_t GetAvgData(IPluginContext *pContext, const cell_t *params)
faluco@682
   842
{
faluco@682
   843
	int client = params[1];
faluco@682
   844
faluco@682
   845
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   846
	if (!pPlayer)
faluco@682
   847
	{
ds@994
   848
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   849
	} else if (!pPlayer->IsInGame()) {
ds@994
   850
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   851
	} else if (pPlayer->IsFakeClient()) {
ds@994
   852
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   853
	}
faluco@682
   854
faluco@682
   855
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   856
faluco@682
   857
	return sp_ftoc(pInfo->GetAvgData(params[2]));
faluco@682
   858
}
faluco@682
   859
faluco@682
   860
static cell_t GetAvgPackets(IPluginContext *pContext, const cell_t *params)
faluco@682
   861
{
faluco@682
   862
	int client = params[1];
faluco@682
   863
faluco@682
   864
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   865
	if (!pPlayer)
faluco@682
   866
	{
ds@994
   867
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   868
	} else if (!pPlayer->IsInGame()) {
ds@994
   869
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   870
	} else if (pPlayer->IsFakeClient()) {
ds@994
   871
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   872
	}
faluco@682
   873
faluco@682
   874
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   875
faluco@682
   876
	return sp_ftoc(pInfo->GetAvgPackets(params[2]));
faluco@682
   877
}
faluco@682
   878
faluco@682
   879
static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params)
faluco@682
   880
{
faluco@682
   881
	return g_Players.GetClientOfUserId(params[1]);
faluco@682
   882
}
faluco@682
   883
dvander@1104
   884
static cell_t _ShowActivity(IPluginContext *pContext, const cell_t *params, const char *tag, cell_t fmt_param)
dvander@910
   885
{
dvander@924
   886
	char message[255];
dvander@924
   887
	char buffer[255];
dvander@910
   888
	int value = sm_show_activity.GetInt();
dvander@924
   889
	unsigned int replyto = g_ChatTriggers.GetReplyTo();
dvander@910
   890
	int client = params[1];
dvander@910
   891
dvander@910
   892
	const char *name = "Console";
dvander@910
   893
	const char *sign = "ADMIN";
dvander@924
   894
	bool display_in_chat = false;
dvander@910
   895
	if (client != 0)
dvander@910
   896
	{
dvander@910
   897
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@910
   898
		if (!pPlayer || !pPlayer->IsConnected())
dvander@910
   899
		{
dvander@910
   900
			return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@910
   901
		}
dvander@910
   902
		name = pPlayer->GetName();
dvander@910
   903
		AdminId id = pPlayer->GetAdminId();
dvander@910
   904
		if (id == INVALID_ADMIN_ID
dvander@910
   905
			|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
dvander@910
   906
		{
dvander@910
   907
			sign = "PLAYER";
dvander@910
   908
		}
dvander@924
   909
dvander@924
   910
		/* Display the message to the client? */
dvander@924
   911
		if (replyto == SM_REPLY_CONSOLE)
dvander@924
   912
		{
dvander@924
   913
			g_SourceMod.SetGlobalTarget(client);
dvander@1104
   914
			g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
dvander@1104
   915
			UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
dvander@924
   916
			engine->ClientPrintf(pPlayer->GetEdict(), message);
dvander@924
   917
			display_in_chat = true;
dvander@924
   918
		}
dvander@924
   919
	} else {
dvander@924
   920
		g_SourceMod.SetGlobalTarget(LANG_SERVER);
dvander@1104
   921
		g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
dvander@1104
   922
		UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
dvander@924
   923
		META_CONPRINT(message);
dvander@910
   924
	}
dvander@910
   925
dvander@924
   926
	if (!value)
dvander@924
   927
	{
dvander@924
   928
		return 1;
dvander@924
   929
	}
dvander@924
   930
dvander@910
   931
	int maxClients = g_Players.GetMaxClients();
dvander@910
   932
	for (int i=1; i<=maxClients; i++)
dvander@910
   933
	{
dvander@910
   934
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
dvander@924
   935
		if (!pPlayer->IsInGame() 
dvander@924
   936
			|| pPlayer->IsFakeClient()
dvander@924
   937
			|| (display_in_chat && i == client))
dvander@910
   938
		{
dvander@910
   939
			continue;
dvander@910
   940
		}
dvander@910
   941
		AdminId id = pPlayer->GetAdminId();
dvander@910
   942
		g_SourceMod.SetGlobalTarget(i);
dvander@910
   943
		if (id == INVALID_ADMIN_ID
dvander@910
   944
			|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
dvander@910
   945
		{
dvander@910
   946
			/* Treat this as a normal user */
dvander@910
   947
			if ((value & 1) || (value & 2))
dvander@910
   948
			{
dvander@910
   949
				const char *newsign = sign;
dvander@910
   950
				if (value & 2)
dvander@910
   951
				{
dvander@910
   952
					newsign = name;
dvander@910
   953
				}
dvander@1104
   954
				g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
dvander@1104
   955
				UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
dvander@910
   956
				g_HL2.TextMsg(i, HUD_PRINTTALK, message);
dvander@910
   957
			}
dvander@910
   958
		} else {
dvander@910
   959
			/* Treat this as an admin user */
dvander@910
   960
			bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective);
dvander@910
   961
			if ((value & 4) 
dvander@910
   962
				|| (value & 8)
dvander@910
   963
				|| ((value & 16) && is_root))
dvander@910
   964
			{
dvander@910
   965
				const char *newsign = sign;
dvander@910
   966
				if ((value & 8) || ((value & 16) && is_root))
dvander@910
   967
				{
dvander@910
   968
					newsign = name;
dvander@910
   969
				}
dvander@1104
   970
				g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
dvander@1104
   971
				UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
dvander@910
   972
				g_HL2.TextMsg(i, HUD_PRINTTALK, message);
dvander@910
   973
			}
dvander@910
   974
		}
dvander@910
   975
	}
dvander@910
   976
dvander@910
   977
	return 1;
dvander@910
   978
}
dvander@910
   979
dvander@1104
   980
static cell_t ShowActivity(IPluginContext *pContext, const cell_t *params)
dvander@1104
   981
{
dvander@1104
   982
	return _ShowActivity(pContext, params, "[SM] ", 2);
dvander@1104
   983
}
dvander@1104
   984
dvander@1104
   985
static cell_t ShowActivityEx(IPluginContext *pContext, const cell_t *params)
dvander@1104
   986
{
dvander@1104
   987
	char *str;
dvander@1104
   988
	pContext->LocalToString(params[2], &str);
dvander@1104
   989
dvander@1104
   990
	return _ShowActivity(pContext, params, str, 3);
dvander@1104
   991
}
dvander@1104
   992
ds@992
   993
static cell_t KickClient(IPluginContext *pContext, const cell_t *params)
ds@992
   994
{
ds@992
   995
	int client = params[1];
ds@992
   996
ds@992
   997
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@992
   998
	if (!pPlayer)
ds@992
   999
	{
ds@994
  1000
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@992
  1001
	} else if (!pPlayer->IsConnected()) {
ds@992
  1002
		return pContext->ThrowNativeError("Client %d is not connected", client);
ds@992
  1003
	}
ds@992
  1004
ds@992
  1005
	if (pPlayer->IsFakeClient())
ds@992
  1006
	{
ds@998
  1007
		char kickcmd[40];
ds@992
  1008
		UTIL_Format(kickcmd, sizeof(kickcmd), "kick %s\n", pPlayer->GetName());
ds@992
  1009
ds@992
  1010
		engine->ServerCommand(kickcmd);
ds@992
  1011
		return 1;
ds@992
  1012
	}
ds@992
  1013
ds@992
  1014
	INetChannel *pNetChan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(client));
ds@992
  1015
	IClient *pClient = static_cast<IClient *>(pNetChan->GetMsgHandler());
ds@992
  1016
dvander@1011
  1017
	g_SourceMod.SetGlobalTarget(client);
dvander@1011
  1018
ds@992
  1019
	char buffer[256];
ds@992
  1020
	g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
ds@992
  1021
dvander@1273
  1022
	if (pContext->GetContext()->n_err != SP_ERROR_NONE)
dvander@1273
  1023
	{
dvander@1273
  1024
		return 0;
dvander@1273
  1025
	}
dvander@1273
  1026
ds@992
  1027
	pClient->Disconnect("%s", buffer);
ds@992
  1028
ds@992
  1029
	return 1;
ds@992
  1030
}
ds@992
  1031
dvander@1033
  1032
static cell_t ChangeClientTeam(IPluginContext *pContext, const cell_t *params)
dvander@1033
  1033
{
dvander@1033
  1034
	int client = params[1];
dvander@1033
  1035
dvander@1033
  1036
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@1033
  1037
	if (!pPlayer)
dvander@1033
  1038
	{
dvander@1033
  1039
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@1033
  1040
	} else if (!pPlayer->IsInGame()) {
dvander@1033
  1041
		return pContext->ThrowNativeError("Client %d is not in game", client);
dvander@1033
  1042
	}
dvander@1033
  1043
dvander@1033
  1044
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
dvander@1033
  1045
	if (!pInfo)
dvander@1033
  1046
	{
dvander@1033
  1047
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
dvander@1033
  1048
	}
dvander@1033
  1049
dvander@1033
  1050
	pInfo->ChangeTeam(params[2]);
dvander@1033
  1051
dvander@1033
  1052
	return 1;
dvander@1033
  1053
}
dvander@1033
  1054
dvander@1273
  1055
static cell_t RunAdminCacheChecks(IPluginContext *pContext, const cell_t *params)
dvander@1273
  1056
{
dvander@1273
  1057
	int client = params[1];
dvander@1273
  1058
dvander@1273
  1059
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@1273
  1060
	if (!pPlayer)
dvander@1273
  1061
	{
dvander@1273
  1062
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@1273
  1063
	} else if (!pPlayer->IsInGame()) {
dvander@1273
  1064
		return pContext->ThrowNativeError("Client %d is not in game", client);
dvander@1273
  1065
	} else if (!pPlayer->IsAuthorized()) {
dvander@1273
  1066
		return pContext->ThrowNativeError("Client %d is not authorized", client);
dvander@1273
  1067
	}
dvander@1273
  1068
dvander@1273
  1069
	AdminId id = pPlayer->GetAdminId();
dvander@1273
  1070
	pPlayer->DoBasicAdminChecks();
dvander@1273
  1071
dvander@1273
  1072
	return (id != pPlayer->GetAdminId()) ? 1 : 0;
dvander@1273
  1073
}
dvander@1273
  1074
dvander@1273
  1075
static cell_t NotifyPostAdminCheck(IPluginContext *pContext, const cell_t *params)
dvander@1273
  1076
{
dvander@1273
  1077
	int client = params[1];
dvander@1273
  1078
dvander@1273
  1079
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@1273
  1080
	if (!pPlayer)
dvander@1273
  1081
	{
dvander@1273
  1082
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@1273
  1083
	} else if (!pPlayer->IsInGame()) {
dvander@1273
  1084
		return pContext->ThrowNativeError("Client %d is not in game", client);
dvander@1273
  1085
	} else if (!pPlayer->IsAuthorized()) {
dvander@1273
  1086
		return pContext->ThrowNativeError("Client %d is not authorized", client);
dvander@1273
  1087
	}
dvander@1273
  1088
dvander@1273
  1089
	pPlayer->NotifyPostAdminChecks();
dvander@1273
  1090
dvander@1273
  1091
	return 1;
dvander@1273
  1092
}
dvander@1273
  1093
faluco@260
  1094
REGISTER_NATIVES(playernatives)
faluco@260
  1095
{
dvander@644
  1096
	{"AddUserFlags",			AddUserFlags},
dvander@644
  1097
	{"CanUserTarget",			CanUserTarget},
dvander@1033
  1098
	{"ChangeClientTeam",		ChangeClientTeam},
dvander@644
  1099
	{"GetClientAuthString",		sm_GetClientAuthStr},
faluco@260
  1100
	{"GetClientCount",			sm_GetClientCount},
dvander@644
  1101
	{"GetClientInfo",			sm_GetClientInfo},
faluco@260
  1102
	{"GetClientIP",				sm_GetClientIP},
dvander@644
  1103
	{"GetClientName",			sm_GetClientName},
dvander@644
  1104
	{"GetClientTeam",			GetClientTeam},
dvander@644
  1105
	{"GetClientUserId",			GetClientUserId},
dvander@644
  1106
	{"GetMaxClients",			sm_GetMaxClients},
dvander@644
  1107
	{"GetUserAdmin",			GetUserAdmin},
dvander@644
  1108
	{"GetUserFlagBits",			GetUserFlagBits},
ds@784
  1109
	{"IsClientAuthorized",		sm_IsClientAuthorized},
ds@784
  1110
	{"IsClientConnected",		sm_IsClientConnected},
ds@784
  1111
	{"IsFakeClient",			sm_IsClientFakeClient},
ds@784
  1112
	{"IsPlayerInGame",			sm_IsClientInGame},			/* Backwards compat shim */
ds@784
  1113
	{"IsClientInGame",			sm_IsClientInGame},
ds@1001
  1114
	{"IsClientObserver",		IsClientObserver},
dvander@458
  1115
	{"RemoveUserFlags",			RemoveUserFlags},
dvander@644
  1116
	{"SetUserAdmin",			SetUserAdmin},
dvander@458
  1117
	{"SetUserFlagBits",			SetUserFlagBits},
faluco@658
  1118
	{"GetClientDeaths",			GetDeathCount},
faluco@658
  1119
	{"GetClientFrags",			GetFragCount},
faluco@658
  1120
	{"GetClientArmor",			GetArmorValue},
faluco@658
  1121
	{"GetClientAbsOrigin",		GetAbsOrigin},
faluco@658
  1122
	{"GetClientAbsAngles",		GetAbsAngles},
faluco@658
  1123
	{"GetClientMins",			GetPlayerMins},
faluco@658
  1124
	{"GetClientMaxs",			GetPlayerMaxs},
faluco@658
  1125
	{"GetClientWeapon",			GetWeaponName},
faluco@658
  1126
	{"GetClientModel",			GetModelName},
faluco@658
  1127
	{"GetClientHealth",			GetHealth},
dvander@691
  1128
	{"GetClientTime",			GetTimeConnected},
dvander@691
  1129
	{"GetClientDataRate",		GetDataRate},
dvander@691
  1130
	{"IsClentTimingOut",		IsTimingOut},
dvander@691
  1131
	{"GetClientLatency",		GetLatency},
dvander@691
  1132
	{"GetClientAvgLatency",		GetAvgLatency},
dvander@691
  1133
	{"GetClientAvgLoss",		GetAvgLoss},
dvander@691
  1134
	{"GetClientAvgChoke",		GetAvgChoke},
dvander@691
  1135
	{"GetClientAvgData",		GetAvgData},
dvander@691
  1136
	{"GetClientAvgPackets",		GetAvgPackets},
faluco@682
  1137
	{"GetClientOfUserId",		GetClientOfUserId},
dvander@910
  1138
	{"ShowActivity",			ShowActivity},
dvander@1110
  1139
	{"ShowActivityEx",			ShowActivityEx},
ds@992
  1140
	{"KickClient",				KickClient},
dvander@1273
  1141
	{"RunAdminCacheChecks",		RunAdminCacheChecks},
dvander@1273
  1142
	{"NotifyPostAdminCheck",	NotifyPostAdminCheck},
faluco@260
  1143
	{NULL,						NULL}
dvander@351
  1144
};