core/smn_player.cpp
author Borja Ferrer <faluco@alliedmods.net>
Thu Jul 05 14:47:36 2007 +0000 (2007-07-05)
changeset 1041 f7b2073013df
parent 1035 dff088cf776e
child 1049 9891871e223d
permissions -rw-r--r--
added a time stamp argument to FormatTime
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@1035
   382
	if (client == 0)
dvander@1035
   383
	{
dvander@1035
   384
		return 1;
dvander@1035
   385
	}
dvander@1035
   386
dvander@540
   387
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@540
   388
	if (!pPlayer)
dvander@540
   389
	{
ds@994
   390
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@540
   391
	} else if (!pPlayer->IsConnected()) {
ds@994
   392
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@540
   393
	}
dvander@540
   394
dvander@540
   395
	CPlayer *pTarget = g_Players.GetPlayerByIndex(target);
dvander@540
   396
	if (!pTarget)
dvander@540
   397
	{
ds@994
   398
		return pContext->ThrowNativeError("Client index %d is invalid", target);
dvander@540
   399
	} else if (!pTarget->IsConnected()) {
ds@994
   400
		return pContext->ThrowNativeError("Client %d is not connected", target);
dvander@540
   401
	}
dvander@540
   402
dvander@540
   403
	return g_Admins.CanAdminTarget(pPlayer->GetAdminId(), pTarget->GetAdminId()) ? 1 : 0;
dvander@540
   404
}
dvander@540
   405
dvander@644
   406
static cell_t GetClientTeam(IPluginContext *pContext, const cell_t *params)
dvander@644
   407
{
dvander@644
   408
	int client = params[1];
dvander@644
   409
dvander@644
   410
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@644
   411
	if (!pPlayer)
dvander@644
   412
	{
ds@994
   413
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@644
   414
	} else if (!pPlayer->IsInGame()) {
ds@994
   415
		return pContext->ThrowNativeError("Client %d is not in game", client);
dvander@644
   416
	}
dvander@644
   417
dvander@644
   418
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
dvander@644
   419
	if (!pInfo)
dvander@644
   420
	{
dvander@644
   421
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
dvander@644
   422
	}
dvander@644
   423
dvander@644
   424
	return pInfo->GetTeamIndex();
dvander@644
   425
}
dvander@644
   426
faluco@658
   427
static cell_t GetFragCount(IPluginContext *pContext, const cell_t *params)
faluco@658
   428
{
faluco@658
   429
	int client = params[1];
faluco@658
   430
faluco@658
   431
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   432
	if (!pPlayer)
faluco@658
   433
	{
ds@994
   434
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   435
	} else if (!pPlayer->IsInGame()) {
ds@994
   436
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   437
	}
faluco@658
   438
faluco@658
   439
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   440
	if (!pInfo)
faluco@658
   441
	{
faluco@658
   442
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   443
	}
faluco@658
   444
faluco@658
   445
	return pInfo->GetFragCount();
faluco@658
   446
}
faluco@658
   447
faluco@658
   448
static cell_t GetDeathCount(IPluginContext *pContext, const cell_t *params)
faluco@658
   449
{
faluco@658
   450
	int client = params[1];
faluco@658
   451
faluco@658
   452
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   453
	if (!pPlayer)
faluco@658
   454
	{
ds@994
   455
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   456
	} else if (!pPlayer->IsInGame()) {
ds@994
   457
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   458
	}
faluco@658
   459
faluco@658
   460
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   461
	if (!pInfo)
faluco@658
   462
	{
faluco@658
   463
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   464
	}
faluco@658
   465
faluco@658
   466
	return pInfo->GetDeathCount();
faluco@658
   467
}
faluco@658
   468
faluco@658
   469
static cell_t GetArmorValue(IPluginContext *pContext, const cell_t *params)
faluco@658
   470
{
faluco@658
   471
	int client = params[1];
faluco@658
   472
faluco@658
   473
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   474
	if (!pPlayer)
faluco@658
   475
	{
ds@994
   476
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   477
	} else if (!pPlayer->IsInGame()) {
ds@994
   478
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   479
	}
faluco@658
   480
faluco@658
   481
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   482
	if (!pInfo)
faluco@658
   483
	{
faluco@658
   484
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   485
	}
faluco@658
   486
faluco@658
   487
	return pInfo->GetArmorValue();
faluco@658
   488
}
faluco@658
   489
faluco@658
   490
static cell_t GetAbsOrigin(IPluginContext *pContext, const cell_t *params)
faluco@658
   491
{
faluco@658
   492
	int client = params[1];
faluco@658
   493
faluco@658
   494
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   495
	if (!pPlayer)
faluco@658
   496
	{
ds@994
   497
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   498
	} else if (!pPlayer->IsInGame()) {
ds@994
   499
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   500
	}
faluco@658
   501
faluco@658
   502
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   503
	if (!pInfo)
faluco@658
   504
	{
faluco@658
   505
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   506
	}
faluco@658
   507
faluco@658
   508
	cell_t *pVec;
faluco@658
   509
	pContext->LocalToPhysAddr(params[2], &pVec);
faluco@658
   510
faluco@658
   511
	Vector vec = pInfo->GetAbsOrigin();
faluco@658
   512
	pVec[0] = sp_ftoc(vec.x);
faluco@658
   513
	pVec[1] = sp_ftoc(vec.y);
faluco@658
   514
	pVec[2] = sp_ftoc(vec.z);
faluco@658
   515
faluco@658
   516
	return 1;
faluco@658
   517
}
faluco@658
   518
faluco@658
   519
static cell_t GetAbsAngles(IPluginContext *pContext, const cell_t *params)
faluco@658
   520
{
faluco@658
   521
	int client = params[1];
faluco@658
   522
faluco@658
   523
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   524
	if (!pPlayer)
faluco@658
   525
	{
ds@994
   526
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   527
	} else if (!pPlayer->IsInGame()) {
ds@994
   528
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   529
	}
faluco@658
   530
faluco@658
   531
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   532
	if (!pInfo)
faluco@658
   533
	{
faluco@658
   534
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   535
	}
faluco@658
   536
faluco@658
   537
	cell_t *pAng;
faluco@658
   538
	pContext->LocalToPhysAddr(params[2], &pAng);
faluco@658
   539
faluco@658
   540
	QAngle ang = pInfo->GetAbsAngles();
faluco@658
   541
	pAng[0] = sp_ftoc(ang.x);
faluco@658
   542
	pAng[1] = sp_ftoc(ang.y);
faluco@658
   543
	pAng[2] = sp_ftoc(ang.z);
faluco@658
   544
faluco@658
   545
	return 1;
faluco@658
   546
}
faluco@658
   547
faluco@658
   548
static cell_t GetPlayerMins(IPluginContext *pContext, const cell_t *params)
faluco@658
   549
{
faluco@658
   550
	int client = params[1];
faluco@658
   551
faluco@658
   552
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   553
	if (!pPlayer)
faluco@658
   554
	{
ds@994
   555
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   556
	} else if (!pPlayer->IsInGame()) {
ds@994
   557
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   558
	}
faluco@658
   559
faluco@658
   560
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   561
	if (!pInfo)
faluco@658
   562
	{
faluco@658
   563
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   564
	}
faluco@658
   565
faluco@658
   566
	cell_t *pVec;
faluco@658
   567
	pContext->LocalToPhysAddr(params[2], &pVec);
faluco@658
   568
faluco@658
   569
	Vector vec = pInfo->GetPlayerMins();
faluco@658
   570
	pVec[0] = sp_ftoc(vec.x);
faluco@658
   571
	pVec[1] = sp_ftoc(vec.y);
faluco@658
   572
	pVec[2] = sp_ftoc(vec.z);
faluco@658
   573
faluco@658
   574
	return 1;
faluco@658
   575
}
faluco@658
   576
faluco@658
   577
static cell_t GetPlayerMaxs(IPluginContext *pContext, const cell_t *params)
faluco@658
   578
{
faluco@658
   579
	int client = params[1];
faluco@658
   580
faluco@658
   581
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   582
	if (!pPlayer)
faluco@658
   583
	{
ds@994
   584
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   585
	} else if (!pPlayer->IsInGame()) {
ds@994
   586
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   587
	}
faluco@658
   588
faluco@658
   589
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   590
	if (!pInfo)
faluco@658
   591
	{
faluco@658
   592
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   593
	}
faluco@658
   594
faluco@658
   595
	cell_t *pVec;
faluco@658
   596
	pContext->LocalToPhysAddr(params[2], &pVec);
faluco@658
   597
faluco@658
   598
	Vector vec = pInfo->GetPlayerMaxs();
faluco@658
   599
	pVec[0] = sp_ftoc(vec.x);
faluco@658
   600
	pVec[1] = sp_ftoc(vec.y);
faluco@658
   601
	pVec[2] = sp_ftoc(vec.z);
faluco@658
   602
faluco@658
   603
	return 1;
faluco@658
   604
}
faluco@658
   605
faluco@658
   606
static cell_t GetWeaponName(IPluginContext *pContext, const cell_t *params)
faluco@658
   607
{
faluco@658
   608
	int client = params[1];
faluco@658
   609
faluco@658
   610
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   611
	if (!pPlayer)
faluco@658
   612
	{
ds@994
   613
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   614
	} else if (!pPlayer->IsInGame()) {
ds@994
   615
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   616
	}
faluco@658
   617
faluco@658
   618
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   619
	if (!pInfo)
faluco@658
   620
	{
faluco@658
   621
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   622
	}
faluco@658
   623
faluco@756
   624
	const char *weapon = pInfo->GetWeaponName();
faluco@756
   625
	pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), weapon ? weapon : "", NULL);
faluco@658
   626
faluco@658
   627
	return 1;
faluco@658
   628
}
faluco@658
   629
faluco@658
   630
static cell_t GetModelName(IPluginContext *pContext, const cell_t *params)
faluco@658
   631
{
faluco@658
   632
	int client = params[1];
faluco@658
   633
faluco@658
   634
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   635
	if (!pPlayer)
faluco@658
   636
	{
ds@994
   637
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   638
	} else if (!pPlayer->IsInGame()) {
ds@994
   639
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   640
	}
faluco@658
   641
faluco@658
   642
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   643
	if (!pInfo)
faluco@658
   644
	{
faluco@658
   645
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   646
	}
faluco@658
   647
faluco@756
   648
	const char *model = pInfo->GetModelName();
faluco@756
   649
	pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), model ? model : "", NULL);
faluco@658
   650
faluco@658
   651
	return 1;
faluco@658
   652
}
faluco@658
   653
faluco@658
   654
static cell_t GetHealth(IPluginContext *pContext, const cell_t *params)
faluco@658
   655
{
faluco@658
   656
	int client = params[1];
faluco@658
   657
faluco@658
   658
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   659
	if (!pPlayer)
faluco@658
   660
	{
ds@994
   661
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   662
	} else if (!pPlayer->IsInGame()) {
ds@994
   663
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   664
	}
faluco@658
   665
faluco@658
   666
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   667
	if (!pInfo)
faluco@658
   668
	{
faluco@658
   669
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   670
	}
faluco@658
   671
faluco@658
   672
	return pInfo->GetHealth();
faluco@658
   673
}
faluco@658
   674
faluco@682
   675
static cell_t GetTimeConnected(IPluginContext *pContext, const cell_t *params)
faluco@682
   676
{
faluco@682
   677
	int client = params[1];
faluco@682
   678
faluco@682
   679
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   680
	if (!pPlayer)
faluco@682
   681
	{
ds@994
   682
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   683
	} else if (!pPlayer->IsInGame()) {
ds@994
   684
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   685
	} else if (pPlayer->IsFakeClient()) {
ds@994
   686
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   687
	}
faluco@682
   688
faluco@682
   689
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   690
faluco@682
   691
	return sp_ftoc(pInfo->GetTimeConnected());
faluco@682
   692
}
faluco@682
   693
faluco@682
   694
static cell_t GetDataRate(IPluginContext *pContext, const cell_t *params)
faluco@682
   695
{
faluco@682
   696
	int client = params[1];
faluco@682
   697
faluco@682
   698
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   699
	if (!pPlayer)
faluco@682
   700
	{
ds@994
   701
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   702
	} else if (!pPlayer->IsInGame()) {
ds@994
   703
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   704
	} else if (pPlayer->IsFakeClient()) {
ds@994
   705
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   706
	}
faluco@682
   707
faluco@682
   708
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   709
faluco@682
   710
	return pInfo->GetDataRate();
faluco@682
   711
}
faluco@682
   712
faluco@682
   713
static cell_t IsTimingOut(IPluginContext *pContext, const cell_t *params)
faluco@682
   714
{
faluco@682
   715
	int client = params[1];
faluco@682
   716
faluco@682
   717
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   718
	if (!pPlayer)
faluco@682
   719
	{
ds@994
   720
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   721
	} else if (!pPlayer->IsInGame()) {
ds@994
   722
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   723
	} else if (pPlayer->IsFakeClient()) {
ds@994
   724
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   725
	}
faluco@682
   726
faluco@682
   727
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   728
faluco@682
   729
	return pInfo->IsTimingOut() ? 1 : 0;
faluco@682
   730
}
faluco@682
   731
faluco@682
   732
static cell_t GetLatency(IPluginContext *pContext, const cell_t *params)
faluco@682
   733
{
faluco@682
   734
	int client = params[1];
faluco@682
   735
faluco@682
   736
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   737
	if (!pPlayer)
faluco@682
   738
	{
ds@994
   739
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   740
	} else if (!pPlayer->IsInGame()) {
ds@994
   741
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   742
	} else if (pPlayer->IsFakeClient()) {
ds@994
   743
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   744
	}
faluco@682
   745
faluco@682
   746
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   747
faluco@682
   748
	return sp_ftoc(pInfo->GetLatency(params[2]));
faluco@682
   749
}
faluco@682
   750
faluco@682
   751
static cell_t GetAvgLatency(IPluginContext *pContext, const cell_t *params)
faluco@682
   752
{
faluco@682
   753
	int client = params[1];
faluco@682
   754
faluco@682
   755
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   756
	if (!pPlayer)
faluco@682
   757
	{
ds@994
   758
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   759
	} else if (!pPlayer->IsInGame()) {
ds@994
   760
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   761
	} else if (pPlayer->IsFakeClient()) {
ds@994
   762
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   763
	}
faluco@682
   764
faluco@682
   765
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   766
faluco@682
   767
	return sp_ftoc(pInfo->GetAvgLatency(params[2]));
faluco@682
   768
}
faluco@682
   769
faluco@682
   770
static cell_t GetAvgLoss(IPluginContext *pContext, const cell_t *params)
faluco@682
   771
{
faluco@682
   772
	int client = params[1];
faluco@682
   773
faluco@682
   774
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   775
	if (!pPlayer)
faluco@682
   776
	{
ds@994
   777
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   778
	} else if (!pPlayer->IsInGame()) {
ds@994
   779
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   780
	} else if (pPlayer->IsFakeClient()) {
ds@994
   781
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   782
	}
faluco@682
   783
faluco@682
   784
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   785
faluco@682
   786
	return sp_ftoc(pInfo->GetAvgLoss(params[2]));
faluco@682
   787
}
faluco@682
   788
faluco@682
   789
static cell_t GetAvgChoke(IPluginContext *pContext, const cell_t *params)
faluco@682
   790
{
faluco@682
   791
	int client = params[1];
faluco@682
   792
faluco@682
   793
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   794
	if (!pPlayer)
faluco@682
   795
	{
ds@994
   796
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   797
	} else if (!pPlayer->IsInGame()) {
ds@994
   798
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   799
	} else if (pPlayer->IsFakeClient()) {
ds@994
   800
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   801
	}
faluco@682
   802
faluco@682
   803
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   804
faluco@682
   805
	return sp_ftoc(pInfo->GetAvgChoke(params[2]));
faluco@682
   806
}
faluco@682
   807
faluco@682
   808
static cell_t GetAvgData(IPluginContext *pContext, const cell_t *params)
faluco@682
   809
{
faluco@682
   810
	int client = params[1];
faluco@682
   811
faluco@682
   812
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   813
	if (!pPlayer)
faluco@682
   814
	{
ds@994
   815
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   816
	} else if (!pPlayer->IsInGame()) {
ds@994
   817
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   818
	} else if (pPlayer->IsFakeClient()) {
ds@994
   819
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   820
	}
faluco@682
   821
faluco@682
   822
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   823
faluco@682
   824
	return sp_ftoc(pInfo->GetAvgData(params[2]));
faluco@682
   825
}
faluco@682
   826
faluco@682
   827
static cell_t GetAvgPackets(IPluginContext *pContext, const cell_t *params)
faluco@682
   828
{
faluco@682
   829
	int client = params[1];
faluco@682
   830
faluco@682
   831
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   832
	if (!pPlayer)
faluco@682
   833
	{
ds@994
   834
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   835
	} else if (!pPlayer->IsInGame()) {
ds@994
   836
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   837
	} else if (pPlayer->IsFakeClient()) {
ds@994
   838
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   839
	}
faluco@682
   840
faluco@682
   841
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   842
faluco@682
   843
	return sp_ftoc(pInfo->GetAvgPackets(params[2]));
faluco@682
   844
}
faluco@682
   845
faluco@682
   846
static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params)
faluco@682
   847
{
faluco@682
   848
	return g_Players.GetClientOfUserId(params[1]);
faluco@682
   849
}
faluco@682
   850
dvander@910
   851
static cell_t ShowActivity(IPluginContext *pContext, const cell_t *params)
dvander@910
   852
{
dvander@924
   853
	char message[255];
dvander@924
   854
	char buffer[255];
dvander@910
   855
	int value = sm_show_activity.GetInt();
dvander@924
   856
	unsigned int replyto = g_ChatTriggers.GetReplyTo();
dvander@910
   857
	int client = params[1];
dvander@910
   858
dvander@910
   859
	const char *name = "Console";
dvander@910
   860
	const char *sign = "ADMIN";
dvander@924
   861
	bool display_in_chat = false;
dvander@910
   862
	if (client != 0)
dvander@910
   863
	{
dvander@910
   864
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@910
   865
		if (!pPlayer || !pPlayer->IsConnected())
dvander@910
   866
		{
dvander@910
   867
			return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@910
   868
		}
dvander@910
   869
		name = pPlayer->GetName();
dvander@910
   870
		AdminId id = pPlayer->GetAdminId();
dvander@910
   871
		if (id == INVALID_ADMIN_ID
dvander@910
   872
			|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
dvander@910
   873
		{
dvander@910
   874
			sign = "PLAYER";
dvander@910
   875
		}
dvander@924
   876
dvander@924
   877
		/* Display the message to the client? */
dvander@924
   878
		if (replyto == SM_REPLY_CONSOLE)
dvander@924
   879
		{
dvander@924
   880
			g_SourceMod.SetGlobalTarget(client);
dvander@924
   881
			g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
dvander@924
   882
			UTIL_Format(message, sizeof(message), "[SM] %s\n", buffer);
dvander@924
   883
			engine->ClientPrintf(pPlayer->GetEdict(), message);
dvander@924
   884
			display_in_chat = true;
dvander@924
   885
		}
dvander@924
   886
	} else {
dvander@924
   887
		g_SourceMod.SetGlobalTarget(LANG_SERVER);
dvander@924
   888
		g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
dvander@924
   889
		UTIL_Format(message, sizeof(message), "[SM] %s\n", buffer);
dvander@924
   890
		META_CONPRINT(message);
dvander@910
   891
	}
dvander@910
   892
dvander@924
   893
	if (!value)
dvander@924
   894
	{
dvander@924
   895
		return 1;
dvander@924
   896
	}
dvander@924
   897
dvander@910
   898
	int maxClients = g_Players.GetMaxClients();
dvander@910
   899
	for (int i=1; i<=maxClients; i++)
dvander@910
   900
	{
dvander@910
   901
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
dvander@924
   902
		if (!pPlayer->IsInGame() 
dvander@924
   903
			|| pPlayer->IsFakeClient()
dvander@924
   904
			|| (display_in_chat && i == client))
dvander@910
   905
		{
dvander@910
   906
			continue;
dvander@910
   907
		}
dvander@910
   908
		AdminId id = pPlayer->GetAdminId();
dvander@910
   909
		g_SourceMod.SetGlobalTarget(i);
dvander@910
   910
		if (id == INVALID_ADMIN_ID
dvander@910
   911
			|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
dvander@910
   912
		{
dvander@910
   913
			/* Treat this as a normal user */
dvander@910
   914
			if ((value & 1) || (value & 2))
dvander@910
   915
			{
dvander@910
   916
				const char *newsign = sign;
dvander@910
   917
				if (value & 2)
dvander@910
   918
				{
dvander@910
   919
					newsign = name;
dvander@910
   920
				}
dvander@910
   921
				g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
dvander@910
   922
				UTIL_Format(message, sizeof(message), "[SM] %s: %s", newsign, buffer);
dvander@910
   923
				g_HL2.TextMsg(i, HUD_PRINTTALK, message);
dvander@910
   924
			}
dvander@910
   925
		} else {
dvander@910
   926
			/* Treat this as an admin user */
dvander@910
   927
			bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective);
dvander@910
   928
			if ((value & 4) 
dvander@910
   929
				|| (value & 8)
dvander@910
   930
				|| ((value & 16) && is_root))
dvander@910
   931
			{
dvander@910
   932
				const char *newsign = sign;
dvander@910
   933
				if ((value & 8) || ((value & 16) && is_root))
dvander@910
   934
				{
dvander@910
   935
					newsign = name;
dvander@910
   936
				}
dvander@910
   937
				g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
dvander@910
   938
				UTIL_Format(message, sizeof(message), "[SM] %s: %s", newsign, buffer);
dvander@910
   939
				g_HL2.TextMsg(i, HUD_PRINTTALK, message);
dvander@910
   940
			}
dvander@910
   941
		}
dvander@910
   942
	}
dvander@910
   943
dvander@910
   944
	return 1;
dvander@910
   945
}
dvander@910
   946
ds@992
   947
static cell_t KickClient(IPluginContext *pContext, const cell_t *params)
ds@992
   948
{
ds@992
   949
	int client = params[1];
ds@992
   950
ds@992
   951
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@992
   952
	if (!pPlayer)
ds@992
   953
	{
ds@994
   954
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@992
   955
	} else if (!pPlayer->IsConnected()) {
ds@992
   956
		return pContext->ThrowNativeError("Client %d is not connected", client);
ds@992
   957
	}
ds@992
   958
ds@992
   959
	if (pPlayer->IsFakeClient())
ds@992
   960
	{
ds@998
   961
		char kickcmd[40];
ds@992
   962
		UTIL_Format(kickcmd, sizeof(kickcmd), "kick %s\n", pPlayer->GetName());
ds@992
   963
ds@992
   964
		engine->ServerCommand(kickcmd);
ds@992
   965
		return 1;
ds@992
   966
	}
ds@992
   967
ds@992
   968
	INetChannel *pNetChan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(client));
ds@992
   969
	IClient *pClient = static_cast<IClient *>(pNetChan->GetMsgHandler());
ds@992
   970
dvander@1011
   971
	g_SourceMod.SetGlobalTarget(client);
dvander@1011
   972
ds@992
   973
	char buffer[256];
ds@992
   974
	g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
ds@992
   975
ds@992
   976
	pClient->Disconnect("%s", buffer);
ds@992
   977
ds@992
   978
	return 1;
ds@992
   979
}
ds@992
   980
dvander@1033
   981
static cell_t ChangeClientTeam(IPluginContext *pContext, const cell_t *params)
dvander@1033
   982
{
dvander@1033
   983
	int client = params[1];
dvander@1033
   984
dvander@1033
   985
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@1033
   986
	if (!pPlayer)
dvander@1033
   987
	{
dvander@1033
   988
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@1033
   989
	} else if (!pPlayer->IsInGame()) {
dvander@1033
   990
		return pContext->ThrowNativeError("Client %d is not in game", client);
dvander@1033
   991
	}
dvander@1033
   992
dvander@1033
   993
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
dvander@1033
   994
	if (!pInfo)
dvander@1033
   995
	{
dvander@1033
   996
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
dvander@1033
   997
	}
dvander@1033
   998
dvander@1033
   999
	pInfo->ChangeTeam(params[2]);
dvander@1033
  1000
dvander@1033
  1001
	return 1;
dvander@1033
  1002
}
dvander@1033
  1003
faluco@260
  1004
REGISTER_NATIVES(playernatives)
faluco@260
  1005
{
dvander@644
  1006
	{"AddUserFlags",			AddUserFlags},
dvander@644
  1007
	{"CanUserTarget",			CanUserTarget},
dvander@1033
  1008
	{"ChangeClientTeam",		ChangeClientTeam},
dvander@644
  1009
	{"GetClientAuthString",		sm_GetClientAuthStr},
faluco@260
  1010
	{"GetClientCount",			sm_GetClientCount},
dvander@644
  1011
	{"GetClientInfo",			sm_GetClientInfo},
faluco@260
  1012
	{"GetClientIP",				sm_GetClientIP},
dvander@644
  1013
	{"GetClientName",			sm_GetClientName},
dvander@644
  1014
	{"GetClientTeam",			GetClientTeam},
dvander@644
  1015
	{"GetClientUserId",			GetClientUserId},
dvander@644
  1016
	{"GetMaxClients",			sm_GetMaxClients},
dvander@644
  1017
	{"GetUserAdmin",			GetUserAdmin},
dvander@644
  1018
	{"GetUserFlagBits",			GetUserFlagBits},
ds@784
  1019
	{"IsClientAuthorized",		sm_IsClientAuthorized},
ds@784
  1020
	{"IsClientConnected",		sm_IsClientConnected},
ds@784
  1021
	{"IsFakeClient",			sm_IsClientFakeClient},
ds@784
  1022
	{"IsPlayerInGame",			sm_IsClientInGame},			/* Backwards compat shim */
ds@784
  1023
	{"IsClientInGame",			sm_IsClientInGame},
ds@1001
  1024
	{"IsClientObserver",		IsClientObserver},
dvander@458
  1025
	{"RemoveUserFlags",			RemoveUserFlags},
dvander@644
  1026
	{"SetUserAdmin",			SetUserAdmin},
dvander@458
  1027
	{"SetUserFlagBits",			SetUserFlagBits},
faluco@658
  1028
	{"GetClientDeaths",			GetDeathCount},
faluco@658
  1029
	{"GetClientFrags",			GetFragCount},
faluco@658
  1030
	{"GetClientArmor",			GetArmorValue},
faluco@658
  1031
	{"GetClientAbsOrigin",		GetAbsOrigin},
faluco@658
  1032
	{"GetClientAbsAngles",		GetAbsAngles},
faluco@658
  1033
	{"GetClientMins",			GetPlayerMins},
faluco@658
  1034
	{"GetClientMaxs",			GetPlayerMaxs},
faluco@658
  1035
	{"GetClientWeapon",			GetWeaponName},
faluco@658
  1036
	{"GetClientModel",			GetModelName},
faluco@658
  1037
	{"GetClientHealth",			GetHealth},
dvander@691
  1038
	{"GetClientTime",			GetTimeConnected},
dvander@691
  1039
	{"GetClientDataRate",		GetDataRate},
dvander@691
  1040
	{"IsClentTimingOut",		IsTimingOut},
dvander@691
  1041
	{"GetClientLatency",		GetLatency},
dvander@691
  1042
	{"GetClientAvgLatency",		GetAvgLatency},
dvander@691
  1043
	{"GetClientAvgLoss",		GetAvgLoss},
dvander@691
  1044
	{"GetClientAvgChoke",		GetAvgChoke},
dvander@691
  1045
	{"GetClientAvgData",		GetAvgData},
dvander@691
  1046
	{"GetClientAvgPackets",		GetAvgPackets},
faluco@682
  1047
	{"GetClientOfUserId",		GetClientOfUserId},
dvander@910
  1048
	{"ShowActivity",			ShowActivity},
ds@992
  1049
	{"KickClient",				KickClient},
faluco@260
  1050
	{NULL,						NULL}
dvander@351
  1051
};