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