core/smn_player.cpp
author Scott Ehlert <ds@alliedmods.net>
Fri Jun 22 15:37:12 2007 +0000 (2007-06-22)
changeset 1001 8de56a71f200
parent 998 b26df4dd8187
child 1011 b413072540fd
permissions -rw-r--r--
Implemented amb423 - Added IsClientObserver() native
dvander@370
     1
/**
ds@653
     2
 * vim: set ts=4 :
dvander@370
     3
 * ===============================================================
dvander@370
     4
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
dvander@370
     5
 * ===============================================================
dvander@370
     6
 *
dvander@370
     7
 * This file is not open source and may not be copied without explicit
dvander@370
     8
 * written permission of AlliedModders LLC.  This file may not be redistributed 
dvander@370
     9
 * in whole or significant part.
dvander@370
    10
 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
dvander@370
    11
 *
dvander@370
    12
 * Version: $Id$
dvander@370
    13
 */
dvander@370
    14
dvander@591
    15
#include "PlayerManager.h"
dvander@458
    16
#include "AdminCache.h"
faluco@280
    17
#include "sm_stringutil.h"
dvander@910
    18
#include "HalfLife2.h"
dvander@910
    19
#include "sourcemod.h"
dvander@924
    20
#include "ChatTriggers.h"
ds@992
    21
#include <inetchannel.h>
ds@992
    22
#include <iclient.h>
faluco@242
    23
dvander@923
    24
ConVar sm_show_activity("sm_show_activity", "13", FCVAR_SPONLY|FCVAR_PROTECTED, "Activity display setting (see sourcemod.cfg)");
dvander@910
    25
faluco@260
    26
static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params)
faluco@242
    27
{
faluco@242
    28
	if (params[1])
faluco@242
    29
	{
dvander@448
    30
		return g_Players.NumPlayers();
faluco@242
    31
	}
faluco@242
    32
dvander@448
    33
	int maxplayers = g_Players.MaxClients();
faluco@242
    34
	int count = 0;
faluco@242
    35
	for (int i=1; i<=maxplayers; ++i)
faluco@242
    36
	{
dvander@448
    37
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
dvander@435
    38
		if ((pPlayer->IsConnected()) && !(pPlayer->IsInGame()))
faluco@242
    39
		{
faluco@242
    40
			count++;
faluco@242
    41
		}
faluco@242
    42
	}
faluco@242
    43
dvander@448
    44
	return (g_Players.NumPlayers() + count);
faluco@242
    45
}
faluco@242
    46
faluco@260
    47
static cell_t sm_GetMaxClients(IPluginContext *pCtx, const cell_t *params)
faluco@242
    48
{
dvander@448
    49
	return g_Players.MaxClients();
faluco@242
    50
}
faluco@242
    51
faluco@260
    52
static cell_t sm_GetClientName(IPluginContext *pCtx, const cell_t *params)
faluco@242
    53
{
faluco@242
    54
	int index = params[1];
dvander@448
    55
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
    56
	{
ds@994
    57
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
    58
	}
faluco@242
    59
dvander@448
    60
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
    61
	if (!pPlayer->IsConnected())
faluco@260
    62
	{
ds@470
    63
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@260
    64
	}
faluco@260
    65
dvander@435
    66
	pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pPlayer->GetName(), NULL);
faluco@242
    67
	return 1;
faluco@242
    68
}
faluco@242
    69
faluco@260
    70
static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params)
faluco@242
    71
{
faluco@242
    72
	int index = params[1];
dvander@448
    73
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
    74
	{
ds@994
    75
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
    76
	}
faluco@242
    77
dvander@448
    78
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
    79
	if (!pPlayer->IsConnected())
faluco@260
    80
	{
ds@470
    81
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@260
    82
	}
faluco@260
    83
faluco@280
    84
	char buf[64], *ptr;
dvander@435
    85
	strcpy(buf, pPlayer->GetIPAddress());
faluco@280
    86
faluco@280
    87
	if (params[4] && (ptr = strchr(buf, ':')))
faluco@280
    88
	{
faluco@280
    89
		*ptr = '\0';
faluco@280
    90
	}
faluco@280
    91
faluco@280
    92
	pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), buf);
faluco@242
    93
	return 1;
faluco@242
    94
}
faluco@242
    95
faluco@260
    96
static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params)
faluco@242
    97
{
faluco@242
    98
	int index = params[1];
dvander@448
    99
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   100
	{
ds@994
   101
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
   102
	}
faluco@242
   103
dvander@448
   104
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
   105
	if (!pPlayer->IsConnected())
faluco@260
   106
	{
ds@470
   107
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@260
   108
	}
faluco@260
   109
dvander@449
   110
	if (!pPlayer->IsAuthorized())
dvander@449
   111
	{
dvander@449
   112
		return 0;
dvander@449
   113
	}
dvander@449
   114
dvander@435
   115
	pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), pPlayer->GetAuthString());
dvander@449
   116
faluco@242
   117
	return 1;
faluco@242
   118
}
faluco@242
   119
ds@784
   120
static cell_t sm_IsClientConnected(IPluginContext *pCtx, const cell_t *params)
faluco@242
   121
{
faluco@242
   122
	int index = params[1];
dvander@448
   123
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   124
	{
ds@994
   125
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
   126
	}
faluco@242
   127
dvander@448
   128
	return (g_Players.GetPlayerByIndex(index)->IsConnected()) ? 1 : 0;
faluco@242
   129
}
faluco@242
   130
ds@784
   131
static cell_t sm_IsClientInGame(IPluginContext *pCtx, const cell_t *params)
faluco@242
   132
{
faluco@242
   133
	int index = params[1];
dvander@448
   134
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   135
	{
ds@994
   136
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
   137
	}
faluco@242
   138
dvander@448
   139
	return (g_Players.GetPlayerByIndex(index)->IsInGame()) ? 1 : 0;
faluco@242
   140
}
faluco@242
   141
ds@784
   142
static cell_t sm_IsClientAuthorized(IPluginContext *pCtx, const cell_t *params)
faluco@242
   143
{
faluco@242
   144
	int index = params[1];
dvander@448
   145
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   146
	{
ds@994
   147
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
   148
	}
faluco@242
   149
dvander@448
   150
	return (g_Players.GetPlayerByIndex(index)->IsAuthorized()) ? 1 : 0;
faluco@242
   151
}
faluco@242
   152
ds@784
   153
static cell_t sm_IsClientFakeClient(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@260
   159
	}
faluco@260
   160
dvander@448
   161
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
   162
	if (!pPlayer->IsConnected())
faluco@260
   163
	{
ds@470
   164
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@242
   165
	}
faluco@242
   166
dvander@435
   167
	return (pPlayer->IsFakeClient()) ? 1 : 0;
faluco@260
   168
}
faluco@260
   169
ds@1001
   170
static cell_t IsClientObserver(IPluginContext *pContext, const cell_t *params)
ds@1001
   171
{
ds@1001
   172
	int client = params[1];
ds@1001
   173
ds@1001
   174
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1001
   175
	if (!pPlayer)
ds@1001
   176
	{
ds@1001
   177
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1001
   178
	} else if (!pPlayer->IsInGame()) {
ds@1001
   179
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1001
   180
	}
ds@1001
   181
ds@1001
   182
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1001
   183
	if (!pInfo)
ds@1001
   184
	{
ds@1001
   185
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1001
   186
	}
ds@1001
   187
ds@1001
   188
	return pInfo->IsObserver() ? 1 : 0;
ds@1001
   189
}
ds@1001
   190
dvander@456
   191
static cell_t sm_GetClientInfo(IPluginContext *pContext, const cell_t *params)
dvander@456
   192
{
dvander@456
   193
	int client = params[1];
dvander@456
   194
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@456
   195
	if (!pPlayer)
dvander@456
   196
	{
ds@994
   197
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@456
   198
	}
dvander@456
   199
	if (!pPlayer->IsConnected())
dvander@456
   200
	{
ds@470
   201
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@456
   202
	}
dvander@456
   203
dvander@456
   204
	char *key;
dvander@456
   205
	pContext->LocalToString(params[2], &key);
dvander@456
   206
dvander@456
   207
	const char *val = engine->GetClientConVarValue(client, key);
dvander@456
   208
	if (!val)
dvander@456
   209
	{
dvander@456
   210
		return false;
dvander@456
   211
	}
dvander@456
   212
dvander@456
   213
	pContext->StringToLocalUTF8(params[3], params[4], val, NULL);
dvander@456
   214
	return 1;
dvander@456
   215
}
dvander@456
   216
dvander@458
   217
static cell_t SetUserAdmin(IPluginContext *pContext, const cell_t *params)
dvander@458
   218
{
dvander@458
   219
	int client = params[1];
dvander@458
   220
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   221
	if (!pPlayer)
dvander@458
   222
	{
ds@994
   223
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   224
	}
dvander@458
   225
	if (!pPlayer->IsConnected())
dvander@458
   226
	{
ds@470
   227
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   228
	}
dvander@458
   229
	if (!g_Admins.IsValidAdmin(params[2]))
dvander@458
   230
	{
ds@994
   231
		return pContext->ThrowNativeError("AdminId %x is invalid", params[2]);
dvander@458
   232
	}
dvander@458
   233
dvander@458
   234
	pPlayer->SetAdminId(params[2], params[3] ? true : false);
dvander@458
   235
dvander@458
   236
	return 1;
dvander@458
   237
}
dvander@458
   238
dvander@458
   239
static cell_t GetUserAdmin(IPluginContext *pContext, const cell_t *params)
dvander@458
   240
{
dvander@458
   241
	int client = params[1];
dvander@458
   242
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   243
	if (!pPlayer)
dvander@458
   244
	{
ds@994
   245
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   246
	}
dvander@458
   247
	if (!pPlayer->IsConnected())
dvander@458
   248
	{
ds@470
   249
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   250
	}
dvander@458
   251
dvander@458
   252
	return pPlayer->GetAdminId();
dvander@458
   253
}
dvander@458
   254
dvander@458
   255
static cell_t AddUserFlags(IPluginContext *pContext, const cell_t *params)
dvander@458
   256
{
dvander@458
   257
	int client = params[1];
dvander@458
   258
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   259
	if (!pPlayer)
dvander@458
   260
	{
ds@994
   261
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   262
	}
dvander@458
   263
	if (!pPlayer->IsConnected())
dvander@458
   264
	{
ds@470
   265
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   266
	}
dvander@458
   267
dvander@458
   268
	AdminId id;
dvander@458
   269
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   270
	{
dvander@458
   271
		id = g_Admins.CreateAdmin(NULL);
dvander@458
   272
		pPlayer->SetAdminId(id, true);
dvander@458
   273
	}
dvander@458
   274
dvander@458
   275
	cell_t *addr;
dvander@458
   276
	for (int i=2; i<=params[0]; i++)
dvander@458
   277
	{
dvander@458
   278
		pContext->LocalToPhysAddr(params[i], &addr);
dvander@458
   279
		g_Admins.SetAdminFlag(id, (AdminFlag)*addr, true);
dvander@458
   280
	}
dvander@458
   281
dvander@458
   282
	return 1;
dvander@458
   283
}
dvander@458
   284
dvander@458
   285
static cell_t RemoveUserFlags(IPluginContext *pContext, const cell_t *params)
dvander@458
   286
{
dvander@458
   287
	int client = params[1];
dvander@458
   288
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   289
	if (!pPlayer)
dvander@458
   290
	{
ds@994
   291
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   292
	}
dvander@458
   293
	if (!pPlayer->IsConnected())
dvander@458
   294
	{
ds@470
   295
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   296
	}
dvander@458
   297
	
dvander@458
   298
	AdminId id;
dvander@458
   299
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   300
	{
dvander@458
   301
		return 0;
dvander@458
   302
	}
dvander@458
   303
dvander@458
   304
	cell_t *addr;
dvander@458
   305
	for (int i=2; i<=params[0]; i++)
dvander@458
   306
	{
dvander@458
   307
		pContext->LocalToPhysAddr(params[i], &addr);
dvander@458
   308
		g_Admins.SetAdminFlag(id, (AdminFlag)*addr, false);
dvander@458
   309
	}
dvander@458
   310
dvander@458
   311
	return 1;
dvander@458
   312
}
dvander@458
   313
dvander@458
   314
static cell_t SetUserFlagBits(IPluginContext *pContext, const cell_t *params)
dvander@458
   315
{
dvander@458
   316
	int client = params[1];
dvander@458
   317
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   318
	if (!pPlayer)
dvander@458
   319
	{
ds@994
   320
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   321
	}
dvander@458
   322
	if (!pPlayer->IsConnected())
dvander@458
   323
	{
ds@470
   324
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   325
	}
dvander@458
   326
dvander@458
   327
	AdminId id;
dvander@458
   328
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   329
	{
dvander@458
   330
		id = g_Admins.CreateAdmin(NULL);
dvander@458
   331
		pPlayer->SetAdminId(id, true);
dvander@458
   332
	}
dvander@458
   333
dvander@458
   334
	g_Admins.SetAdminFlags(id, Access_Effective, params[2]);
dvander@458
   335
dvander@458
   336
	return 1;
dvander@458
   337
}
dvander@458
   338
dvander@458
   339
static cell_t GetUserFlagBits(IPluginContext *pContext, const cell_t *params)
dvander@458
   340
{
dvander@458
   341
	int client = params[1];
dvander@458
   342
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   343
	if (!pPlayer)
dvander@458
   344
	{
ds@994
   345
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   346
	}
dvander@458
   347
	if (!pPlayer->IsConnected())
dvander@458
   348
	{
ds@470
   349
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   350
	}
dvander@458
   351
dvander@458
   352
	AdminId id;
dvander@458
   353
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   354
	{
dvander@458
   355
		return 0;
dvander@458
   356
	}
dvander@458
   357
dvander@458
   358
	return g_Admins.GetAdminFlags(id, Access_Effective);
dvander@458
   359
}
dvander@458
   360
dvander@460
   361
static cell_t GetClientUserId(IPluginContext *pContext, const cell_t *params)
dvander@460
   362
{
dvander@460
   363
	int client = params[1];
dvander@460
   364
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@460
   365
	if (!pPlayer)
dvander@460
   366
	{
ds@994
   367
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@460
   368
	}
dvander@460
   369
	if (!pPlayer->IsConnected())
dvander@460
   370
	{
ds@470
   371
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@460
   372
	}
dvander@460
   373
dvander@460
   374
	return engine->GetPlayerUserId(pPlayer->GetEdict());
dvander@460
   375
}
dvander@460
   376
dvander@540
   377
static cell_t CanUserTarget(IPluginContext *pContext, const cell_t *params)
dvander@540
   378
{
dvander@540
   379
	int client = params[1];
dvander@540
   380
	int target = params[2];
dvander@540
   381
dvander@540
   382
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@540
   383
	if (!pPlayer)
dvander@540
   384
	{
ds@994
   385
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@540
   386
	} else if (!pPlayer->IsConnected()) {
ds@994
   387
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@540
   388
	}
dvander@540
   389
dvander@540
   390
	CPlayer *pTarget = g_Players.GetPlayerByIndex(target);
dvander@540
   391
	if (!pTarget)
dvander@540
   392
	{
ds@994
   393
		return pContext->ThrowNativeError("Client index %d is invalid", target);
dvander@540
   394
	} else if (!pTarget->IsConnected()) {
ds@994
   395
		return pContext->ThrowNativeError("Client %d is not connected", target);
dvander@540
   396
	}
dvander@540
   397
dvander@540
   398
	return g_Admins.CanAdminTarget(pPlayer->GetAdminId(), pTarget->GetAdminId()) ? 1 : 0;
dvander@540
   399
}
dvander@540
   400
dvander@644
   401
static cell_t GetClientTeam(IPluginContext *pContext, const cell_t *params)
dvander@644
   402
{
dvander@644
   403
	int client = params[1];
dvander@644
   404
dvander@644
   405
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@644
   406
	if (!pPlayer)
dvander@644
   407
	{
ds@994
   408
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@644
   409
	} else if (!pPlayer->IsInGame()) {
ds@994
   410
		return pContext->ThrowNativeError("Client %d is not in game", client);
dvander@644
   411
	}
dvander@644
   412
dvander@644
   413
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
dvander@644
   414
	if (!pInfo)
dvander@644
   415
	{
dvander@644
   416
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
dvander@644
   417
	}
dvander@644
   418
dvander@644
   419
	return pInfo->GetTeamIndex();
dvander@644
   420
}
dvander@644
   421
faluco@658
   422
static cell_t GetFragCount(IPluginContext *pContext, const cell_t *params)
faluco@658
   423
{
faluco@658
   424
	int client = params[1];
faluco@658
   425
faluco@658
   426
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   427
	if (!pPlayer)
faluco@658
   428
	{
ds@994
   429
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   430
	} else if (!pPlayer->IsInGame()) {
ds@994
   431
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   432
	}
faluco@658
   433
faluco@658
   434
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   435
	if (!pInfo)
faluco@658
   436
	{
faluco@658
   437
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   438
	}
faluco@658
   439
faluco@658
   440
	return pInfo->GetFragCount();
faluco@658
   441
}
faluco@658
   442
faluco@658
   443
static cell_t GetDeathCount(IPluginContext *pContext, const cell_t *params)
faluco@658
   444
{
faluco@658
   445
	int client = params[1];
faluco@658
   446
faluco@658
   447
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   448
	if (!pPlayer)
faluco@658
   449
	{
ds@994
   450
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   451
	} else if (!pPlayer->IsInGame()) {
ds@994
   452
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   453
	}
faluco@658
   454
faluco@658
   455
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   456
	if (!pInfo)
faluco@658
   457
	{
faluco@658
   458
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   459
	}
faluco@658
   460
faluco@658
   461
	return pInfo->GetDeathCount();
faluco@658
   462
}
faluco@658
   463
faluco@658
   464
static cell_t GetArmorValue(IPluginContext *pContext, const cell_t *params)
faluco@658
   465
{
faluco@658
   466
	int client = params[1];
faluco@658
   467
faluco@658
   468
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   469
	if (!pPlayer)
faluco@658
   470
	{
ds@994
   471
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   472
	} else if (!pPlayer->IsInGame()) {
ds@994
   473
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   474
	}
faluco@658
   475
faluco@658
   476
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   477
	if (!pInfo)
faluco@658
   478
	{
faluco@658
   479
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   480
	}
faluco@658
   481
faluco@658
   482
	return pInfo->GetArmorValue();
faluco@658
   483
}
faluco@658
   484
faluco@658
   485
static cell_t GetAbsOrigin(IPluginContext *pContext, const cell_t *params)
faluco@658
   486
{
faluco@658
   487
	int client = params[1];
faluco@658
   488
faluco@658
   489
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   490
	if (!pPlayer)
faluco@658
   491
	{
ds@994
   492
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   493
	} else if (!pPlayer->IsInGame()) {
ds@994
   494
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   495
	}
faluco@658
   496
faluco@658
   497
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   498
	if (!pInfo)
faluco@658
   499
	{
faluco@658
   500
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   501
	}
faluco@658
   502
faluco@658
   503
	cell_t *pVec;
faluco@658
   504
	pContext->LocalToPhysAddr(params[2], &pVec);
faluco@658
   505
faluco@658
   506
	Vector vec = pInfo->GetAbsOrigin();
faluco@658
   507
	pVec[0] = sp_ftoc(vec.x);
faluco@658
   508
	pVec[1] = sp_ftoc(vec.y);
faluco@658
   509
	pVec[2] = sp_ftoc(vec.z);
faluco@658
   510
faluco@658
   511
	return 1;
faluco@658
   512
}
faluco@658
   513
faluco@658
   514
static cell_t GetAbsAngles(IPluginContext *pContext, const cell_t *params)
faluco@658
   515
{
faluco@658
   516
	int client = params[1];
faluco@658
   517
faluco@658
   518
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   519
	if (!pPlayer)
faluco@658
   520
	{
ds@994
   521
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   522
	} else if (!pPlayer->IsInGame()) {
ds@994
   523
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   524
	}
faluco@658
   525
faluco@658
   526
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   527
	if (!pInfo)
faluco@658
   528
	{
faluco@658
   529
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   530
	}
faluco@658
   531
faluco@658
   532
	cell_t *pAng;
faluco@658
   533
	pContext->LocalToPhysAddr(params[2], &pAng);
faluco@658
   534
faluco@658
   535
	QAngle ang = pInfo->GetAbsAngles();
faluco@658
   536
	pAng[0] = sp_ftoc(ang.x);
faluco@658
   537
	pAng[1] = sp_ftoc(ang.y);
faluco@658
   538
	pAng[2] = sp_ftoc(ang.z);
faluco@658
   539
faluco@658
   540
	return 1;
faluco@658
   541
}
faluco@658
   542
faluco@658
   543
static cell_t GetPlayerMins(IPluginContext *pContext, const cell_t *params)
faluco@658
   544
{
faluco@658
   545
	int client = params[1];
faluco@658
   546
faluco@658
   547
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   548
	if (!pPlayer)
faluco@658
   549
	{
ds@994
   550
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   551
	} else if (!pPlayer->IsInGame()) {
ds@994
   552
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   553
	}
faluco@658
   554
faluco@658
   555
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   556
	if (!pInfo)
faluco@658
   557
	{
faluco@658
   558
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   559
	}
faluco@658
   560
faluco@658
   561
	cell_t *pVec;
faluco@658
   562
	pContext->LocalToPhysAddr(params[2], &pVec);
faluco@658
   563
faluco@658
   564
	Vector vec = pInfo->GetPlayerMins();
faluco@658
   565
	pVec[0] = sp_ftoc(vec.x);
faluco@658
   566
	pVec[1] = sp_ftoc(vec.y);
faluco@658
   567
	pVec[2] = sp_ftoc(vec.z);
faluco@658
   568
faluco@658
   569
	return 1;
faluco@658
   570
}
faluco@658
   571
faluco@658
   572
static cell_t GetPlayerMaxs(IPluginContext *pContext, const cell_t *params)
faluco@658
   573
{
faluco@658
   574
	int client = params[1];
faluco@658
   575
faluco@658
   576
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   577
	if (!pPlayer)
faluco@658
   578
	{
ds@994
   579
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   580
	} else if (!pPlayer->IsInGame()) {
ds@994
   581
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   582
	}
faluco@658
   583
faluco@658
   584
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   585
	if (!pInfo)
faluco@658
   586
	{
faluco@658
   587
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   588
	}
faluco@658
   589
faluco@658
   590
	cell_t *pVec;
faluco@658
   591
	pContext->LocalToPhysAddr(params[2], &pVec);
faluco@658
   592
faluco@658
   593
	Vector vec = pInfo->GetPlayerMaxs();
faluco@658
   594
	pVec[0] = sp_ftoc(vec.x);
faluco@658
   595
	pVec[1] = sp_ftoc(vec.y);
faluco@658
   596
	pVec[2] = sp_ftoc(vec.z);
faluco@658
   597
faluco@658
   598
	return 1;
faluco@658
   599
}
faluco@658
   600
faluco@658
   601
static cell_t GetWeaponName(IPluginContext *pContext, const cell_t *params)
faluco@658
   602
{
faluco@658
   603
	int client = params[1];
faluco@658
   604
faluco@658
   605
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   606
	if (!pPlayer)
faluco@658
   607
	{
ds@994
   608
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   609
	} else if (!pPlayer->IsInGame()) {
ds@994
   610
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   611
	}
faluco@658
   612
faluco@658
   613
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   614
	if (!pInfo)
faluco@658
   615
	{
faluco@658
   616
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   617
	}
faluco@658
   618
faluco@756
   619
	const char *weapon = pInfo->GetWeaponName();
faluco@756
   620
	pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), weapon ? weapon : "", NULL);
faluco@658
   621
faluco@658
   622
	return 1;
faluco@658
   623
}
faluco@658
   624
faluco@658
   625
static cell_t GetModelName(IPluginContext *pContext, const cell_t *params)
faluco@658
   626
{
faluco@658
   627
	int client = params[1];
faluco@658
   628
faluco@658
   629
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   630
	if (!pPlayer)
faluco@658
   631
	{
ds@994
   632
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   633
	} else if (!pPlayer->IsInGame()) {
ds@994
   634
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   635
	}
faluco@658
   636
faluco@658
   637
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   638
	if (!pInfo)
faluco@658
   639
	{
faluco@658
   640
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   641
	}
faluco@658
   642
faluco@756
   643
	const char *model = pInfo->GetModelName();
faluco@756
   644
	pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), model ? model : "", NULL);
faluco@658
   645
faluco@658
   646
	return 1;
faluco@658
   647
}
faluco@658
   648
faluco@658
   649
static cell_t GetHealth(IPluginContext *pContext, const cell_t *params)
faluco@658
   650
{
faluco@658
   651
	int client = params[1];
faluco@658
   652
faluco@658
   653
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   654
	if (!pPlayer)
faluco@658
   655
	{
ds@994
   656
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   657
	} else if (!pPlayer->IsInGame()) {
ds@994
   658
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   659
	}
faluco@658
   660
faluco@658
   661
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   662
	if (!pInfo)
faluco@658
   663
	{
faluco@658
   664
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   665
	}
faluco@658
   666
faluco@658
   667
	return pInfo->GetHealth();
faluco@658
   668
}
faluco@658
   669
faluco@682
   670
static cell_t GetTimeConnected(IPluginContext *pContext, const cell_t *params)
faluco@682
   671
{
faluco@682
   672
	int client = params[1];
faluco@682
   673
faluco@682
   674
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   675
	if (!pPlayer)
faluco@682
   676
	{
ds@994
   677
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   678
	} else if (!pPlayer->IsInGame()) {
ds@994
   679
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   680
	} else if (pPlayer->IsFakeClient()) {
ds@994
   681
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   682
	}
faluco@682
   683
faluco@682
   684
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   685
faluco@682
   686
	return sp_ftoc(pInfo->GetTimeConnected());
faluco@682
   687
}
faluco@682
   688
faluco@682
   689
static cell_t GetDataRate(IPluginContext *pContext, const cell_t *params)
faluco@682
   690
{
faluco@682
   691
	int client = params[1];
faluco@682
   692
faluco@682
   693
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   694
	if (!pPlayer)
faluco@682
   695
	{
ds@994
   696
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   697
	} else if (!pPlayer->IsInGame()) {
ds@994
   698
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   699
	} else if (pPlayer->IsFakeClient()) {
ds@994
   700
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   701
	}
faluco@682
   702
faluco@682
   703
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   704
faluco@682
   705
	return pInfo->GetDataRate();
faluco@682
   706
}
faluco@682
   707
faluco@682
   708
static cell_t IsTimingOut(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 pInfo->IsTimingOut() ? 1 : 0;
faluco@682
   725
}
faluco@682
   726
faluco@682
   727
static cell_t GetLatency(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 sp_ftoc(pInfo->GetLatency(params[2]));
faluco@682
   744
}
faluco@682
   745
faluco@682
   746
static cell_t GetAvgLatency(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 sp_ftoc(pInfo->GetAvgLatency(params[2]));
faluco@682
   763
}
faluco@682
   764
faluco@682
   765
static cell_t GetAvgLoss(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->GetAvgLoss(params[2]));
faluco@682
   782
}
faluco@682
   783
faluco@682
   784
static cell_t GetAvgChoke(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->GetAvgChoke(params[2]));
faluco@682
   801
}
faluco@682
   802
faluco@682
   803
static cell_t GetAvgData(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->GetAvgData(params[2]));
faluco@682
   820
}
faluco@682
   821
faluco@682
   822
static cell_t GetAvgPackets(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->GetAvgPackets(params[2]));
faluco@682
   839
}
faluco@682
   840
faluco@682
   841
static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params)
faluco@682
   842
{
faluco@682
   843
	return g_Players.GetClientOfUserId(params[1]);
faluco@682
   844
}
faluco@682
   845
dvander@910
   846
static cell_t ShowActivity(IPluginContext *pContext, const cell_t *params)
dvander@910
   847
{
dvander@924
   848
	char message[255];
dvander@924
   849
	char buffer[255];
dvander@910
   850
	int value = sm_show_activity.GetInt();
dvander@924
   851
	unsigned int replyto = g_ChatTriggers.GetReplyTo();
dvander@910
   852
	int client = params[1];
dvander@910
   853
dvander@910
   854
	const char *name = "Console";
dvander@910
   855
	const char *sign = "ADMIN";
dvander@924
   856
	bool display_in_chat = false;
dvander@910
   857
	if (client != 0)
dvander@910
   858
	{
dvander@910
   859
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@910
   860
		if (!pPlayer || !pPlayer->IsConnected())
dvander@910
   861
		{
dvander@910
   862
			return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@910
   863
		}
dvander@910
   864
		name = pPlayer->GetName();
dvander@910
   865
		AdminId id = pPlayer->GetAdminId();
dvander@910
   866
		if (id == INVALID_ADMIN_ID
dvander@910
   867
			|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
dvander@910
   868
		{
dvander@910
   869
			sign = "PLAYER";
dvander@910
   870
		}
dvander@924
   871
dvander@924
   872
		/* Display the message to the client? */
dvander@924
   873
		if (replyto == SM_REPLY_CONSOLE)
dvander@924
   874
		{
dvander@924
   875
			g_SourceMod.SetGlobalTarget(client);
dvander@924
   876
			g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
dvander@924
   877
			UTIL_Format(message, sizeof(message), "[SM] %s\n", buffer);
dvander@924
   878
			engine->ClientPrintf(pPlayer->GetEdict(), message);
dvander@924
   879
			display_in_chat = true;
dvander@924
   880
		}
dvander@924
   881
	} else {
dvander@924
   882
		g_SourceMod.SetGlobalTarget(LANG_SERVER);
dvander@924
   883
		g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
dvander@924
   884
		UTIL_Format(message, sizeof(message), "[SM] %s\n", buffer);
dvander@924
   885
		META_CONPRINT(message);
dvander@910
   886
	}
dvander@910
   887
dvander@924
   888
	if (!value)
dvander@924
   889
	{
dvander@924
   890
		return 1;
dvander@924
   891
	}
dvander@924
   892
dvander@910
   893
	int maxClients = g_Players.GetMaxClients();
dvander@910
   894
	for (int i=1; i<=maxClients; i++)
dvander@910
   895
	{
dvander@910
   896
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
dvander@924
   897
		if (!pPlayer->IsInGame() 
dvander@924
   898
			|| pPlayer->IsFakeClient()
dvander@924
   899
			|| (display_in_chat && i == client))
dvander@910
   900
		{
dvander@910
   901
			continue;
dvander@910
   902
		}
dvander@910
   903
		AdminId id = pPlayer->GetAdminId();
dvander@910
   904
		g_SourceMod.SetGlobalTarget(i);
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
			/* Treat this as a normal user */
dvander@910
   909
			if ((value & 1) || (value & 2))
dvander@910
   910
			{
dvander@910
   911
				const char *newsign = sign;
dvander@910
   912
				if (value & 2)
dvander@910
   913
				{
dvander@910
   914
					newsign = name;
dvander@910
   915
				}
dvander@910
   916
				g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
dvander@910
   917
				UTIL_Format(message, sizeof(message), "[SM] %s: %s", newsign, buffer);
dvander@910
   918
				g_HL2.TextMsg(i, HUD_PRINTTALK, message);
dvander@910
   919
			}
dvander@910
   920
		} else {
dvander@910
   921
			/* Treat this as an admin user */
dvander@910
   922
			bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective);
dvander@910
   923
			if ((value & 4) 
dvander@910
   924
				|| (value & 8)
dvander@910
   925
				|| ((value & 16) && is_root))
dvander@910
   926
			{
dvander@910
   927
				const char *newsign = sign;
dvander@910
   928
				if ((value & 8) || ((value & 16) && is_root))
dvander@910
   929
				{
dvander@910
   930
					newsign = name;
dvander@910
   931
				}
dvander@910
   932
				g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
dvander@910
   933
				UTIL_Format(message, sizeof(message), "[SM] %s: %s", newsign, buffer);
dvander@910
   934
				g_HL2.TextMsg(i, HUD_PRINTTALK, message);
dvander@910
   935
			}
dvander@910
   936
		}
dvander@910
   937
	}
dvander@910
   938
dvander@910
   939
	return 1;
dvander@910
   940
}
dvander@910
   941
ds@992
   942
static cell_t KickClient(IPluginContext *pContext, const cell_t *params)
ds@992
   943
{
ds@992
   944
	int client = params[1];
ds@992
   945
ds@992
   946
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@992
   947
	if (!pPlayer)
ds@992
   948
	{
ds@994
   949
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@992
   950
	} else if (!pPlayer->IsConnected()) {
ds@992
   951
		return pContext->ThrowNativeError("Client %d is not connected", client);
ds@992
   952
	}
ds@992
   953
ds@992
   954
	if (pPlayer->IsFakeClient())
ds@992
   955
	{
ds@998
   956
		char kickcmd[40];
ds@992
   957
		UTIL_Format(kickcmd, sizeof(kickcmd), "kick %s\n", pPlayer->GetName());
ds@992
   958
ds@992
   959
		engine->ServerCommand(kickcmd);
ds@992
   960
		return 1;
ds@992
   961
	}
ds@992
   962
ds@992
   963
	INetChannel *pNetChan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(client));
ds@992
   964
	IClient *pClient = static_cast<IClient *>(pNetChan->GetMsgHandler());
ds@992
   965
ds@992
   966
	char buffer[256];
ds@992
   967
	g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
ds@992
   968
ds@992
   969
	pClient->Disconnect("%s", buffer);
ds@992
   970
ds@992
   971
	return 1;
ds@992
   972
}
ds@992
   973
faluco@260
   974
REGISTER_NATIVES(playernatives)
faluco@260
   975
{
dvander@644
   976
	{"AddUserFlags",			AddUserFlags},
dvander@644
   977
	{"CanUserTarget",			CanUserTarget},
dvander@644
   978
	{"GetClientAuthString",		sm_GetClientAuthStr},
faluco@260
   979
	{"GetClientCount",			sm_GetClientCount},
dvander@644
   980
	{"GetClientInfo",			sm_GetClientInfo},
faluco@260
   981
	{"GetClientIP",				sm_GetClientIP},
dvander@644
   982
	{"GetClientName",			sm_GetClientName},
dvander@644
   983
	{"GetClientTeam",			GetClientTeam},
dvander@644
   984
	{"GetClientUserId",			GetClientUserId},
dvander@644
   985
	{"GetMaxClients",			sm_GetMaxClients},
dvander@644
   986
	{"GetUserAdmin",			GetUserAdmin},
dvander@644
   987
	{"GetUserFlagBits",			GetUserFlagBits},
ds@784
   988
	{"IsClientAuthorized",		sm_IsClientAuthorized},
ds@784
   989
	{"IsClientConnected",		sm_IsClientConnected},
ds@784
   990
	{"IsFakeClient",			sm_IsClientFakeClient},
ds@784
   991
	{"IsPlayerInGame",			sm_IsClientInGame},			/* Backwards compat shim */
ds@784
   992
	{"IsClientInGame",			sm_IsClientInGame},
ds@1001
   993
	{"IsClientObserver",		IsClientObserver},
dvander@458
   994
	{"RemoveUserFlags",			RemoveUserFlags},
dvander@644
   995
	{"SetUserAdmin",			SetUserAdmin},
dvander@458
   996
	{"SetUserFlagBits",			SetUserFlagBits},
faluco@658
   997
	{"GetClientDeaths",			GetDeathCount},
faluco@658
   998
	{"GetClientFrags",			GetFragCount},
faluco@658
   999
	{"GetClientArmor",			GetArmorValue},
faluco@658
  1000
	{"GetClientAbsOrigin",		GetAbsOrigin},
faluco@658
  1001
	{"GetClientAbsAngles",		GetAbsAngles},
faluco@658
  1002
	{"GetClientMins",			GetPlayerMins},
faluco@658
  1003
	{"GetClientMaxs",			GetPlayerMaxs},
faluco@658
  1004
	{"GetClientWeapon",			GetWeaponName},
faluco@658
  1005
	{"GetClientModel",			GetModelName},
faluco@658
  1006
	{"GetClientHealth",			GetHealth},
dvander@691
  1007
	{"GetClientTime",			GetTimeConnected},
dvander@691
  1008
	{"GetClientDataRate",		GetDataRate},
dvander@691
  1009
	{"IsClentTimingOut",		IsTimingOut},
dvander@691
  1010
	{"GetClientLatency",		GetLatency},
dvander@691
  1011
	{"GetClientAvgLatency",		GetAvgLatency},
dvander@691
  1012
	{"GetClientAvgLoss",		GetAvgLoss},
dvander@691
  1013
	{"GetClientAvgChoke",		GetAvgChoke},
dvander@691
  1014
	{"GetClientAvgData",		GetAvgData},
dvander@691
  1015
	{"GetClientAvgPackets",		GetAvgPackets},
faluco@682
  1016
	{"GetClientOfUserId",		GetClientOfUserId},
dvander@910
  1017
	{"ShowActivity",			ShowActivity},
ds@992
  1018
	{"KickClient",				KickClient},
faluco@260
  1019
	{NULL,						NULL}
dvander@351
  1020
};