core/smn_player.cpp
author David Anderson <dvander@alliedmods.net>
Sat Jul 14 00:35:08 2007 +0000 (2007-07-14)
changeset 1103 043baf2d8c96
parent 1049 9891871e223d
child 1104 b9597374d13a
permissions -rw-r--r--
fixed amb582 - private triggers getting fired twice
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@1049
    55
dvander@1049
    56
	if (index == 0)
dvander@1049
    57
	{
dvander@1049
    58
		static ConVar *hostname = NULL;
dvander@1049
    59
		if (!hostname)
dvander@1049
    60
		{
dvander@1049
    61
			hostname = icvar->FindVar("hostname");
dvander@1049
    62
			if (!hostname)
dvander@1049
    63
			{
dvander@1049
    64
				return pCtx->ThrowNativeError("Could not find \"hostname\" cvar");
dvander@1049
    65
			}
dvander@1049
    66
		}
dvander@1049
    67
		pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), hostname->GetString(), NULL);
dvander@1049
    68
		return 1;
dvander@1049
    69
	}
dvander@1049
    70
dvander@448
    71
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
    72
	{
ds@994
    73
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
    74
	}
faluco@242
    75
dvander@448
    76
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
    77
	if (!pPlayer->IsConnected())
faluco@260
    78
	{
ds@470
    79
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@260
    80
	}
faluco@260
    81
dvander@435
    82
	pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pPlayer->GetName(), NULL);
faluco@242
    83
	return 1;
faluco@242
    84
}
faluco@242
    85
faluco@260
    86
static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params)
faluco@242
    87
{
faluco@242
    88
	int index = params[1];
dvander@448
    89
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
    90
	{
ds@994
    91
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
    92
	}
faluco@242
    93
dvander@448
    94
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
    95
	if (!pPlayer->IsConnected())
faluco@260
    96
	{
ds@470
    97
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@260
    98
	}
faluco@260
    99
faluco@280
   100
	char buf[64], *ptr;
dvander@435
   101
	strcpy(buf, pPlayer->GetIPAddress());
faluco@280
   102
faluco@280
   103
	if (params[4] && (ptr = strchr(buf, ':')))
faluco@280
   104
	{
faluco@280
   105
		*ptr = '\0';
faluco@280
   106
	}
faluco@280
   107
faluco@280
   108
	pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), buf);
faluco@242
   109
	return 1;
faluco@242
   110
}
faluco@242
   111
faluco@260
   112
static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params)
faluco@242
   113
{
faluco@242
   114
	int index = params[1];
dvander@448
   115
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   116
	{
ds@994
   117
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
   118
	}
faluco@242
   119
dvander@448
   120
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
   121
	if (!pPlayer->IsConnected())
faluco@260
   122
	{
ds@470
   123
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@260
   124
	}
faluco@260
   125
dvander@449
   126
	if (!pPlayer->IsAuthorized())
dvander@449
   127
	{
dvander@449
   128
		return 0;
dvander@449
   129
	}
dvander@449
   130
dvander@435
   131
	pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), pPlayer->GetAuthString());
dvander@449
   132
faluco@242
   133
	return 1;
faluco@242
   134
}
faluco@242
   135
ds@784
   136
static cell_t sm_IsClientConnected(IPluginContext *pCtx, const cell_t *params)
faluco@242
   137
{
faluco@242
   138
	int index = params[1];
dvander@448
   139
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   140
	{
ds@994
   141
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
   142
	}
faluco@242
   143
dvander@448
   144
	return (g_Players.GetPlayerByIndex(index)->IsConnected()) ? 1 : 0;
faluco@242
   145
}
faluco@242
   146
ds@784
   147
static cell_t sm_IsClientInGame(IPluginContext *pCtx, const cell_t *params)
faluco@242
   148
{
faluco@242
   149
	int index = params[1];
dvander@448
   150
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   151
	{
ds@994
   152
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
   153
	}
faluco@242
   154
dvander@448
   155
	return (g_Players.GetPlayerByIndex(index)->IsInGame()) ? 1 : 0;
faluco@242
   156
}
faluco@242
   157
ds@784
   158
static cell_t sm_IsClientAuthorized(IPluginContext *pCtx, const cell_t *params)
faluco@242
   159
{
faluco@242
   160
	int index = params[1];
dvander@448
   161
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   162
	{
ds@994
   163
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@242
   164
	}
faluco@242
   165
dvander@448
   166
	return (g_Players.GetPlayerByIndex(index)->IsAuthorized()) ? 1 : 0;
faluco@242
   167
}
faluco@242
   168
ds@784
   169
static cell_t sm_IsClientFakeClient(IPluginContext *pCtx, const cell_t *params)
faluco@242
   170
{
faluco@242
   171
	int index = params[1];
dvander@448
   172
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   173
	{
ds@994
   174
		return pCtx->ThrowNativeError("Client index %d is invalid", index);
faluco@260
   175
	}
faluco@260
   176
dvander@448
   177
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
   178
	if (!pPlayer->IsConnected())
faluco@260
   179
	{
ds@470
   180
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@242
   181
	}
faluco@242
   182
dvander@435
   183
	return (pPlayer->IsFakeClient()) ? 1 : 0;
faluco@260
   184
}
faluco@260
   185
ds@1001
   186
static cell_t IsClientObserver(IPluginContext *pContext, const cell_t *params)
ds@1001
   187
{
ds@1001
   188
	int client = params[1];
ds@1001
   189
ds@1001
   190
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1001
   191
	if (!pPlayer)
ds@1001
   192
	{
ds@1001
   193
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@1001
   194
	} else if (!pPlayer->IsInGame()) {
ds@1001
   195
		return pContext->ThrowNativeError("Client %d is not in game", client);
ds@1001
   196
	}
ds@1001
   197
ds@1001
   198
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
ds@1001
   199
	if (!pInfo)
ds@1001
   200
	{
ds@1001
   201
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
ds@1001
   202
	}
ds@1001
   203
ds@1001
   204
	return pInfo->IsObserver() ? 1 : 0;
ds@1001
   205
}
ds@1001
   206
dvander@456
   207
static cell_t sm_GetClientInfo(IPluginContext *pContext, const cell_t *params)
dvander@456
   208
{
dvander@456
   209
	int client = params[1];
dvander@456
   210
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@456
   211
	if (!pPlayer)
dvander@456
   212
	{
ds@994
   213
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@456
   214
	}
dvander@456
   215
	if (!pPlayer->IsConnected())
dvander@456
   216
	{
ds@470
   217
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@456
   218
	}
dvander@456
   219
dvander@456
   220
	char *key;
dvander@456
   221
	pContext->LocalToString(params[2], &key);
dvander@456
   222
dvander@456
   223
	const char *val = engine->GetClientConVarValue(client, key);
dvander@456
   224
	if (!val)
dvander@456
   225
	{
dvander@456
   226
		return false;
dvander@456
   227
	}
dvander@456
   228
dvander@456
   229
	pContext->StringToLocalUTF8(params[3], params[4], val, NULL);
dvander@456
   230
	return 1;
dvander@456
   231
}
dvander@456
   232
dvander@458
   233
static cell_t SetUserAdmin(IPluginContext *pContext, const cell_t *params)
dvander@458
   234
{
dvander@458
   235
	int client = params[1];
dvander@458
   236
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   237
	if (!pPlayer)
dvander@458
   238
	{
ds@994
   239
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   240
	}
dvander@458
   241
	if (!pPlayer->IsConnected())
dvander@458
   242
	{
ds@470
   243
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   244
	}
dvander@458
   245
	if (!g_Admins.IsValidAdmin(params[2]))
dvander@458
   246
	{
ds@994
   247
		return pContext->ThrowNativeError("AdminId %x is invalid", params[2]);
dvander@458
   248
	}
dvander@458
   249
dvander@458
   250
	pPlayer->SetAdminId(params[2], params[3] ? true : false);
dvander@458
   251
dvander@458
   252
	return 1;
dvander@458
   253
}
dvander@458
   254
dvander@458
   255
static cell_t GetUserAdmin(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
	return pPlayer->GetAdminId();
dvander@458
   269
}
dvander@458
   270
dvander@458
   271
static cell_t AddUserFlags(IPluginContext *pContext, const cell_t *params)
dvander@458
   272
{
dvander@458
   273
	int client = params[1];
dvander@458
   274
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   275
	if (!pPlayer)
dvander@458
   276
	{
ds@994
   277
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   278
	}
dvander@458
   279
	if (!pPlayer->IsConnected())
dvander@458
   280
	{
ds@470
   281
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   282
	}
dvander@458
   283
dvander@458
   284
	AdminId id;
dvander@458
   285
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   286
	{
dvander@458
   287
		id = g_Admins.CreateAdmin(NULL);
dvander@458
   288
		pPlayer->SetAdminId(id, true);
dvander@458
   289
	}
dvander@458
   290
dvander@458
   291
	cell_t *addr;
dvander@458
   292
	for (int i=2; i<=params[0]; i++)
dvander@458
   293
	{
dvander@458
   294
		pContext->LocalToPhysAddr(params[i], &addr);
dvander@458
   295
		g_Admins.SetAdminFlag(id, (AdminFlag)*addr, true);
dvander@458
   296
	}
dvander@458
   297
dvander@458
   298
	return 1;
dvander@458
   299
}
dvander@458
   300
dvander@458
   301
static cell_t RemoveUserFlags(IPluginContext *pContext, const cell_t *params)
dvander@458
   302
{
dvander@458
   303
	int client = params[1];
dvander@458
   304
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   305
	if (!pPlayer)
dvander@458
   306
	{
ds@994
   307
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   308
	}
dvander@458
   309
	if (!pPlayer->IsConnected())
dvander@458
   310
	{
ds@470
   311
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   312
	}
dvander@458
   313
	
dvander@458
   314
	AdminId id;
dvander@458
   315
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   316
	{
dvander@458
   317
		return 0;
dvander@458
   318
	}
dvander@458
   319
dvander@458
   320
	cell_t *addr;
dvander@458
   321
	for (int i=2; i<=params[0]; i++)
dvander@458
   322
	{
dvander@458
   323
		pContext->LocalToPhysAddr(params[i], &addr);
dvander@458
   324
		g_Admins.SetAdminFlag(id, (AdminFlag)*addr, false);
dvander@458
   325
	}
dvander@458
   326
dvander@458
   327
	return 1;
dvander@458
   328
}
dvander@458
   329
dvander@458
   330
static cell_t SetUserFlagBits(IPluginContext *pContext, const cell_t *params)
dvander@458
   331
{
dvander@458
   332
	int client = params[1];
dvander@458
   333
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   334
	if (!pPlayer)
dvander@458
   335
	{
ds@994
   336
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   337
	}
dvander@458
   338
	if (!pPlayer->IsConnected())
dvander@458
   339
	{
ds@470
   340
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   341
	}
dvander@458
   342
dvander@458
   343
	AdminId id;
dvander@458
   344
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   345
	{
dvander@458
   346
		id = g_Admins.CreateAdmin(NULL);
dvander@458
   347
		pPlayer->SetAdminId(id, true);
dvander@458
   348
	}
dvander@458
   349
dvander@458
   350
	g_Admins.SetAdminFlags(id, Access_Effective, params[2]);
dvander@458
   351
dvander@458
   352
	return 1;
dvander@458
   353
}
dvander@458
   354
dvander@458
   355
static cell_t GetUserFlagBits(IPluginContext *pContext, const cell_t *params)
dvander@458
   356
{
dvander@458
   357
	int client = params[1];
dvander@458
   358
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   359
	if (!pPlayer)
dvander@458
   360
	{
ds@994
   361
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@458
   362
	}
dvander@458
   363
	if (!pPlayer->IsConnected())
dvander@458
   364
	{
ds@470
   365
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   366
	}
dvander@458
   367
dvander@458
   368
	AdminId id;
dvander@458
   369
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   370
	{
dvander@458
   371
		return 0;
dvander@458
   372
	}
dvander@458
   373
dvander@458
   374
	return g_Admins.GetAdminFlags(id, Access_Effective);
dvander@458
   375
}
dvander@458
   376
dvander@460
   377
static cell_t GetClientUserId(IPluginContext *pContext, const cell_t *params)
dvander@460
   378
{
dvander@460
   379
	int client = params[1];
dvander@460
   380
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@460
   381
	if (!pPlayer)
dvander@460
   382
	{
ds@994
   383
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@460
   384
	}
dvander@460
   385
	if (!pPlayer->IsConnected())
dvander@460
   386
	{
ds@470
   387
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@460
   388
	}
dvander@460
   389
dvander@460
   390
	return engine->GetPlayerUserId(pPlayer->GetEdict());
dvander@460
   391
}
dvander@460
   392
dvander@540
   393
static cell_t CanUserTarget(IPluginContext *pContext, const cell_t *params)
dvander@540
   394
{
dvander@540
   395
	int client = params[1];
dvander@540
   396
	int target = params[2];
dvander@540
   397
dvander@1035
   398
	if (client == 0)
dvander@1035
   399
	{
dvander@1035
   400
		return 1;
dvander@1035
   401
	}
dvander@1035
   402
dvander@540
   403
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@540
   404
	if (!pPlayer)
dvander@540
   405
	{
ds@994
   406
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@540
   407
	} else if (!pPlayer->IsConnected()) {
ds@994
   408
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@540
   409
	}
dvander@540
   410
dvander@540
   411
	CPlayer *pTarget = g_Players.GetPlayerByIndex(target);
dvander@540
   412
	if (!pTarget)
dvander@540
   413
	{
ds@994
   414
		return pContext->ThrowNativeError("Client index %d is invalid", target);
dvander@540
   415
	} else if (!pTarget->IsConnected()) {
ds@994
   416
		return pContext->ThrowNativeError("Client %d is not connected", target);
dvander@540
   417
	}
dvander@540
   418
dvander@540
   419
	return g_Admins.CanAdminTarget(pPlayer->GetAdminId(), pTarget->GetAdminId()) ? 1 : 0;
dvander@540
   420
}
dvander@540
   421
dvander@644
   422
static cell_t GetClientTeam(IPluginContext *pContext, const cell_t *params)
dvander@644
   423
{
dvander@644
   424
	int client = params[1];
dvander@644
   425
dvander@644
   426
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@644
   427
	if (!pPlayer)
dvander@644
   428
	{
ds@994
   429
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@644
   430
	} else if (!pPlayer->IsInGame()) {
ds@994
   431
		return pContext->ThrowNativeError("Client %d is not in game", client);
dvander@644
   432
	}
dvander@644
   433
dvander@644
   434
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
dvander@644
   435
	if (!pInfo)
dvander@644
   436
	{
dvander@644
   437
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
dvander@644
   438
	}
dvander@644
   439
dvander@644
   440
	return pInfo->GetTeamIndex();
dvander@644
   441
}
dvander@644
   442
faluco@658
   443
static cell_t GetFragCount(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->GetFragCount();
faluco@658
   462
}
faluco@658
   463
faluco@658
   464
static cell_t GetDeathCount(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->GetDeathCount();
faluco@658
   483
}
faluco@658
   484
faluco@658
   485
static cell_t GetArmorValue(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
	return pInfo->GetArmorValue();
faluco@658
   504
}
faluco@658
   505
faluco@658
   506
static cell_t GetAbsOrigin(IPluginContext *pContext, const cell_t *params)
faluco@658
   507
{
faluco@658
   508
	int client = params[1];
faluco@658
   509
faluco@658
   510
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   511
	if (!pPlayer)
faluco@658
   512
	{
ds@994
   513
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   514
	} else if (!pPlayer->IsInGame()) {
ds@994
   515
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   516
	}
faluco@658
   517
faluco@658
   518
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   519
	if (!pInfo)
faluco@658
   520
	{
faluco@658
   521
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   522
	}
faluco@658
   523
faluco@658
   524
	cell_t *pVec;
faluco@658
   525
	pContext->LocalToPhysAddr(params[2], &pVec);
faluco@658
   526
faluco@658
   527
	Vector vec = pInfo->GetAbsOrigin();
faluco@658
   528
	pVec[0] = sp_ftoc(vec.x);
faluco@658
   529
	pVec[1] = sp_ftoc(vec.y);
faluco@658
   530
	pVec[2] = sp_ftoc(vec.z);
faluco@658
   531
faluco@658
   532
	return 1;
faluco@658
   533
}
faluco@658
   534
faluco@658
   535
static cell_t GetAbsAngles(IPluginContext *pContext, const cell_t *params)
faluco@658
   536
{
faluco@658
   537
	int client = params[1];
faluco@658
   538
faluco@658
   539
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   540
	if (!pPlayer)
faluco@658
   541
	{
ds@994
   542
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   543
	} else if (!pPlayer->IsInGame()) {
ds@994
   544
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   545
	}
faluco@658
   546
faluco@658
   547
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   548
	if (!pInfo)
faluco@658
   549
	{
faluco@658
   550
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   551
	}
faluco@658
   552
faluco@658
   553
	cell_t *pAng;
faluco@658
   554
	pContext->LocalToPhysAddr(params[2], &pAng);
faluco@658
   555
faluco@658
   556
	QAngle ang = pInfo->GetAbsAngles();
faluco@658
   557
	pAng[0] = sp_ftoc(ang.x);
faluco@658
   558
	pAng[1] = sp_ftoc(ang.y);
faluco@658
   559
	pAng[2] = sp_ftoc(ang.z);
faluco@658
   560
faluco@658
   561
	return 1;
faluco@658
   562
}
faluco@658
   563
faluco@658
   564
static cell_t GetPlayerMins(IPluginContext *pContext, const cell_t *params)
faluco@658
   565
{
faluco@658
   566
	int client = params[1];
faluco@658
   567
faluco@658
   568
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   569
	if (!pPlayer)
faluco@658
   570
	{
ds@994
   571
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   572
	} else if (!pPlayer->IsInGame()) {
ds@994
   573
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   574
	}
faluco@658
   575
faluco@658
   576
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   577
	if (!pInfo)
faluco@658
   578
	{
faluco@658
   579
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   580
	}
faluco@658
   581
faluco@658
   582
	cell_t *pVec;
faluco@658
   583
	pContext->LocalToPhysAddr(params[2], &pVec);
faluco@658
   584
faluco@658
   585
	Vector vec = pInfo->GetPlayerMins();
faluco@658
   586
	pVec[0] = sp_ftoc(vec.x);
faluco@658
   587
	pVec[1] = sp_ftoc(vec.y);
faluco@658
   588
	pVec[2] = sp_ftoc(vec.z);
faluco@658
   589
faluco@658
   590
	return 1;
faluco@658
   591
}
faluco@658
   592
faluco@658
   593
static cell_t GetPlayerMaxs(IPluginContext *pContext, const cell_t *params)
faluco@658
   594
{
faluco@658
   595
	int client = params[1];
faluco@658
   596
faluco@658
   597
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   598
	if (!pPlayer)
faluco@658
   599
	{
ds@994
   600
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   601
	} else if (!pPlayer->IsInGame()) {
ds@994
   602
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   603
	}
faluco@658
   604
faluco@658
   605
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   606
	if (!pInfo)
faluco@658
   607
	{
faluco@658
   608
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   609
	}
faluco@658
   610
faluco@658
   611
	cell_t *pVec;
faluco@658
   612
	pContext->LocalToPhysAddr(params[2], &pVec);
faluco@658
   613
faluco@658
   614
	Vector vec = pInfo->GetPlayerMaxs();
faluco@658
   615
	pVec[0] = sp_ftoc(vec.x);
faluco@658
   616
	pVec[1] = sp_ftoc(vec.y);
faluco@658
   617
	pVec[2] = sp_ftoc(vec.z);
faluco@658
   618
faluco@658
   619
	return 1;
faluco@658
   620
}
faluco@658
   621
faluco@658
   622
static cell_t GetWeaponName(IPluginContext *pContext, const cell_t *params)
faluco@658
   623
{
faluco@658
   624
	int client = params[1];
faluco@658
   625
faluco@658
   626
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   627
	if (!pPlayer)
faluco@658
   628
	{
ds@994
   629
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   630
	} else if (!pPlayer->IsInGame()) {
ds@994
   631
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   632
	}
faluco@658
   633
faluco@658
   634
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   635
	if (!pInfo)
faluco@658
   636
	{
faluco@658
   637
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   638
	}
faluco@658
   639
faluco@756
   640
	const char *weapon = pInfo->GetWeaponName();
faluco@756
   641
	pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), weapon ? weapon : "", NULL);
faluco@658
   642
faluco@658
   643
	return 1;
faluco@658
   644
}
faluco@658
   645
faluco@658
   646
static cell_t GetModelName(IPluginContext *pContext, const cell_t *params)
faluco@658
   647
{
faluco@658
   648
	int client = params[1];
faluco@658
   649
faluco@658
   650
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   651
	if (!pPlayer)
faluco@658
   652
	{
ds@994
   653
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   654
	} else if (!pPlayer->IsInGame()) {
ds@994
   655
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   656
	}
faluco@658
   657
faluco@658
   658
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   659
	if (!pInfo)
faluco@658
   660
	{
faluco@658
   661
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   662
	}
faluco@658
   663
faluco@756
   664
	const char *model = pInfo->GetModelName();
faluco@756
   665
	pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), model ? model : "", NULL);
faluco@658
   666
faluco@658
   667
	return 1;
faluco@658
   668
}
faluco@658
   669
faluco@658
   670
static cell_t GetHealth(IPluginContext *pContext, const cell_t *params)
faluco@658
   671
{
faluco@658
   672
	int client = params[1];
faluco@658
   673
faluco@658
   674
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   675
	if (!pPlayer)
faluco@658
   676
	{
ds@994
   677
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@658
   678
	} else if (!pPlayer->IsInGame()) {
ds@994
   679
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@658
   680
	}
faluco@658
   681
faluco@658
   682
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   683
	if (!pInfo)
faluco@658
   684
	{
faluco@658
   685
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   686
	}
faluco@658
   687
faluco@658
   688
	return pInfo->GetHealth();
faluco@658
   689
}
faluco@658
   690
faluco@682
   691
static cell_t GetTimeConnected(IPluginContext *pContext, const cell_t *params)
faluco@682
   692
{
faluco@682
   693
	int client = params[1];
faluco@682
   694
faluco@682
   695
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   696
	if (!pPlayer)
faluco@682
   697
	{
ds@994
   698
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   699
	} else if (!pPlayer->IsInGame()) {
ds@994
   700
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   701
	} else if (pPlayer->IsFakeClient()) {
ds@994
   702
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   703
	}
faluco@682
   704
faluco@682
   705
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   706
faluco@682
   707
	return sp_ftoc(pInfo->GetTimeConnected());
faluco@682
   708
}
faluco@682
   709
faluco@682
   710
static cell_t GetDataRate(IPluginContext *pContext, const cell_t *params)
faluco@682
   711
{
faluco@682
   712
	int client = params[1];
faluco@682
   713
faluco@682
   714
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   715
	if (!pPlayer)
faluco@682
   716
	{
ds@994
   717
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   718
	} else if (!pPlayer->IsInGame()) {
ds@994
   719
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   720
	} else if (pPlayer->IsFakeClient()) {
ds@994
   721
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   722
	}
faluco@682
   723
faluco@682
   724
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   725
faluco@682
   726
	return pInfo->GetDataRate();
faluco@682
   727
}
faluco@682
   728
faluco@682
   729
static cell_t IsTimingOut(IPluginContext *pContext, const cell_t *params)
faluco@682
   730
{
faluco@682
   731
	int client = params[1];
faluco@682
   732
faluco@682
   733
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   734
	if (!pPlayer)
faluco@682
   735
	{
ds@994
   736
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   737
	} else if (!pPlayer->IsInGame()) {
ds@994
   738
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   739
	} else if (pPlayer->IsFakeClient()) {
ds@994
   740
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   741
	}
faluco@682
   742
faluco@682
   743
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   744
faluco@682
   745
	return pInfo->IsTimingOut() ? 1 : 0;
faluco@682
   746
}
faluco@682
   747
faluco@682
   748
static cell_t GetLatency(IPluginContext *pContext, const cell_t *params)
faluco@682
   749
{
faluco@682
   750
	int client = params[1];
faluco@682
   751
faluco@682
   752
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   753
	if (!pPlayer)
faluco@682
   754
	{
ds@994
   755
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   756
	} else if (!pPlayer->IsInGame()) {
ds@994
   757
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   758
	} else if (pPlayer->IsFakeClient()) {
ds@994
   759
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   760
	}
faluco@682
   761
faluco@682
   762
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   763
faluco@682
   764
	return sp_ftoc(pInfo->GetLatency(params[2]));
faluco@682
   765
}
faluco@682
   766
faluco@682
   767
static cell_t GetAvgLatency(IPluginContext *pContext, const cell_t *params)
faluco@682
   768
{
faluco@682
   769
	int client = params[1];
faluco@682
   770
faluco@682
   771
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   772
	if (!pPlayer)
faluco@682
   773
	{
ds@994
   774
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   775
	} else if (!pPlayer->IsInGame()) {
ds@994
   776
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   777
	} else if (pPlayer->IsFakeClient()) {
ds@994
   778
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   779
	}
faluco@682
   780
faluco@682
   781
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   782
faluco@682
   783
	return sp_ftoc(pInfo->GetAvgLatency(params[2]));
faluco@682
   784
}
faluco@682
   785
faluco@682
   786
static cell_t GetAvgLoss(IPluginContext *pContext, const cell_t *params)
faluco@682
   787
{
faluco@682
   788
	int client = params[1];
faluco@682
   789
faluco@682
   790
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   791
	if (!pPlayer)
faluco@682
   792
	{
ds@994
   793
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   794
	} else if (!pPlayer->IsInGame()) {
ds@994
   795
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   796
	} else if (pPlayer->IsFakeClient()) {
ds@994
   797
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   798
	}
faluco@682
   799
faluco@682
   800
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   801
faluco@682
   802
	return sp_ftoc(pInfo->GetAvgLoss(params[2]));
faluco@682
   803
}
faluco@682
   804
faluco@682
   805
static cell_t GetAvgChoke(IPluginContext *pContext, const cell_t *params)
faluco@682
   806
{
faluco@682
   807
	int client = params[1];
faluco@682
   808
faluco@682
   809
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   810
	if (!pPlayer)
faluco@682
   811
	{
ds@994
   812
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   813
	} else if (!pPlayer->IsInGame()) {
ds@994
   814
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   815
	} else if (pPlayer->IsFakeClient()) {
ds@994
   816
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   817
	}
faluco@682
   818
faluco@682
   819
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   820
faluco@682
   821
	return sp_ftoc(pInfo->GetAvgChoke(params[2]));
faluco@682
   822
}
faluco@682
   823
faluco@682
   824
static cell_t GetAvgData(IPluginContext *pContext, const cell_t *params)
faluco@682
   825
{
faluco@682
   826
	int client = params[1];
faluco@682
   827
faluco@682
   828
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   829
	if (!pPlayer)
faluco@682
   830
	{
ds@994
   831
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   832
	} else if (!pPlayer->IsInGame()) {
ds@994
   833
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   834
	} else if (pPlayer->IsFakeClient()) {
ds@994
   835
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   836
	}
faluco@682
   837
faluco@682
   838
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   839
faluco@682
   840
	return sp_ftoc(pInfo->GetAvgData(params[2]));
faluco@682
   841
}
faluco@682
   842
faluco@682
   843
static cell_t GetAvgPackets(IPluginContext *pContext, const cell_t *params)
faluco@682
   844
{
faluco@682
   845
	int client = params[1];
faluco@682
   846
faluco@682
   847
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@682
   848
	if (!pPlayer)
faluco@682
   849
	{
ds@994
   850
		return pContext->ThrowNativeError("Client index %d is invalid", client);
faluco@682
   851
	} else if (!pPlayer->IsInGame()) {
ds@994
   852
		return pContext->ThrowNativeError("Client %d is not in game", client);
faluco@682
   853
	} else if (pPlayer->IsFakeClient()) {
ds@994
   854
		return pContext->ThrowNativeError("Client %d is a bot", client);
faluco@682
   855
	}
faluco@682
   856
faluco@682
   857
	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
faluco@682
   858
faluco@682
   859
	return sp_ftoc(pInfo->GetAvgPackets(params[2]));
faluco@682
   860
}
faluco@682
   861
faluco@682
   862
static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params)
faluco@682
   863
{
faluco@682
   864
	return g_Players.GetClientOfUserId(params[1]);
faluco@682
   865
}
faluco@682
   866
dvander@910
   867
static cell_t ShowActivity(IPluginContext *pContext, const cell_t *params)
dvander@910
   868
{
dvander@924
   869
	char message[255];
dvander@924
   870
	char buffer[255];
dvander@910
   871
	int value = sm_show_activity.GetInt();
dvander@924
   872
	unsigned int replyto = g_ChatTriggers.GetReplyTo();
dvander@910
   873
	int client = params[1];
dvander@910
   874
dvander@910
   875
	const char *name = "Console";
dvander@910
   876
	const char *sign = "ADMIN";
dvander@924
   877
	bool display_in_chat = false;
dvander@910
   878
	if (client != 0)
dvander@910
   879
	{
dvander@910
   880
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@910
   881
		if (!pPlayer || !pPlayer->IsConnected())
dvander@910
   882
		{
dvander@910
   883
			return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@910
   884
		}
dvander@910
   885
		name = pPlayer->GetName();
dvander@910
   886
		AdminId id = pPlayer->GetAdminId();
dvander@910
   887
		if (id == INVALID_ADMIN_ID
dvander@910
   888
			|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
dvander@910
   889
		{
dvander@910
   890
			sign = "PLAYER";
dvander@910
   891
		}
dvander@924
   892
dvander@924
   893
		/* Display the message to the client? */
dvander@924
   894
		if (replyto == SM_REPLY_CONSOLE)
dvander@924
   895
		{
dvander@924
   896
			g_SourceMod.SetGlobalTarget(client);
dvander@924
   897
			g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
dvander@924
   898
			UTIL_Format(message, sizeof(message), "[SM] %s\n", buffer);
dvander@924
   899
			engine->ClientPrintf(pPlayer->GetEdict(), message);
dvander@924
   900
			display_in_chat = true;
dvander@924
   901
		}
dvander@924
   902
	} else {
dvander@924
   903
		g_SourceMod.SetGlobalTarget(LANG_SERVER);
dvander@924
   904
		g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
dvander@924
   905
		UTIL_Format(message, sizeof(message), "[SM] %s\n", buffer);
dvander@924
   906
		META_CONPRINT(message);
dvander@910
   907
	}
dvander@910
   908
dvander@924
   909
	if (!value)
dvander@924
   910
	{
dvander@924
   911
		return 1;
dvander@924
   912
	}
dvander@924
   913
dvander@910
   914
	int maxClients = g_Players.GetMaxClients();
dvander@910
   915
	for (int i=1; i<=maxClients; i++)
dvander@910
   916
	{
dvander@910
   917
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
dvander@924
   918
		if (!pPlayer->IsInGame() 
dvander@924
   919
			|| pPlayer->IsFakeClient()
dvander@924
   920
			|| (display_in_chat && i == client))
dvander@910
   921
		{
dvander@910
   922
			continue;
dvander@910
   923
		}
dvander@910
   924
		AdminId id = pPlayer->GetAdminId();
dvander@910
   925
		g_SourceMod.SetGlobalTarget(i);
dvander@910
   926
		if (id == INVALID_ADMIN_ID
dvander@910
   927
			|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
dvander@910
   928
		{
dvander@910
   929
			/* Treat this as a normal user */
dvander@910
   930
			if ((value & 1) || (value & 2))
dvander@910
   931
			{
dvander@910
   932
				const char *newsign = sign;
dvander@910
   933
				if (value & 2)
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
		} else {
dvander@910
   942
			/* Treat this as an admin user */
dvander@910
   943
			bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective);
dvander@910
   944
			if ((value & 4) 
dvander@910
   945
				|| (value & 8)
dvander@910
   946
				|| ((value & 16) && is_root))
dvander@910
   947
			{
dvander@910
   948
				const char *newsign = sign;
dvander@910
   949
				if ((value & 8) || ((value & 16) && is_root))
dvander@910
   950
				{
dvander@910
   951
					newsign = name;
dvander@910
   952
				}
dvander@910
   953
				g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
dvander@910
   954
				UTIL_Format(message, sizeof(message), "[SM] %s: %s", newsign, buffer);
dvander@910
   955
				g_HL2.TextMsg(i, HUD_PRINTTALK, message);
dvander@910
   956
			}
dvander@910
   957
		}
dvander@910
   958
	}
dvander@910
   959
dvander@910
   960
	return 1;
dvander@910
   961
}
dvander@910
   962
ds@992
   963
static cell_t KickClient(IPluginContext *pContext, const cell_t *params)
ds@992
   964
{
ds@992
   965
	int client = params[1];
ds@992
   966
ds@992
   967
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@992
   968
	if (!pPlayer)
ds@992
   969
	{
ds@994
   970
		return pContext->ThrowNativeError("Client index %d is invalid", client);
ds@992
   971
	} else if (!pPlayer->IsConnected()) {
ds@992
   972
		return pContext->ThrowNativeError("Client %d is not connected", client);
ds@992
   973
	}
ds@992
   974
ds@992
   975
	if (pPlayer->IsFakeClient())
ds@992
   976
	{
ds@998
   977
		char kickcmd[40];
ds@992
   978
		UTIL_Format(kickcmd, sizeof(kickcmd), "kick %s\n", pPlayer->GetName());
ds@992
   979
ds@992
   980
		engine->ServerCommand(kickcmd);
ds@992
   981
		return 1;
ds@992
   982
	}
ds@992
   983
ds@992
   984
	INetChannel *pNetChan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(client));
ds@992
   985
	IClient *pClient = static_cast<IClient *>(pNetChan->GetMsgHandler());
ds@992
   986
dvander@1011
   987
	g_SourceMod.SetGlobalTarget(client);
dvander@1011
   988
ds@992
   989
	char buffer[256];
ds@992
   990
	g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
ds@992
   991
ds@992
   992
	pClient->Disconnect("%s", buffer);
ds@992
   993
ds@992
   994
	return 1;
ds@992
   995
}
ds@992
   996
dvander@1033
   997
static cell_t ChangeClientTeam(IPluginContext *pContext, const cell_t *params)
dvander@1033
   998
{
dvander@1033
   999
	int client = params[1];
dvander@1033
  1000
dvander@1033
  1001
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@1033
  1002
	if (!pPlayer)
dvander@1033
  1003
	{
dvander@1033
  1004
		return pContext->ThrowNativeError("Client index %d is invalid", client);
dvander@1033
  1005
	} else if (!pPlayer->IsInGame()) {
dvander@1033
  1006
		return pContext->ThrowNativeError("Client %d is not in game", client);
dvander@1033
  1007
	}
dvander@1033
  1008
dvander@1033
  1009
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
dvander@1033
  1010
	if (!pInfo)
dvander@1033
  1011
	{
dvander@1033
  1012
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
dvander@1033
  1013
	}
dvander@1033
  1014
dvander@1033
  1015
	pInfo->ChangeTeam(params[2]);
dvander@1033
  1016
dvander@1033
  1017
	return 1;
dvander@1033
  1018
}
dvander@1033
  1019
faluco@260
  1020
REGISTER_NATIVES(playernatives)
faluco@260
  1021
{
dvander@644
  1022
	{"AddUserFlags",			AddUserFlags},
dvander@644
  1023
	{"CanUserTarget",			CanUserTarget},
dvander@1033
  1024
	{"ChangeClientTeam",		ChangeClientTeam},
dvander@644
  1025
	{"GetClientAuthString",		sm_GetClientAuthStr},
faluco@260
  1026
	{"GetClientCount",			sm_GetClientCount},
dvander@644
  1027
	{"GetClientInfo",			sm_GetClientInfo},
faluco@260
  1028
	{"GetClientIP",				sm_GetClientIP},
dvander@644
  1029
	{"GetClientName",			sm_GetClientName},
dvander@644
  1030
	{"GetClientTeam",			GetClientTeam},
dvander@644
  1031
	{"GetClientUserId",			GetClientUserId},
dvander@644
  1032
	{"GetMaxClients",			sm_GetMaxClients},
dvander@644
  1033
	{"GetUserAdmin",			GetUserAdmin},
dvander@644
  1034
	{"GetUserFlagBits",			GetUserFlagBits},
ds@784
  1035
	{"IsClientAuthorized",		sm_IsClientAuthorized},
ds@784
  1036
	{"IsClientConnected",		sm_IsClientConnected},
ds@784
  1037
	{"IsFakeClient",			sm_IsClientFakeClient},
ds@784
  1038
	{"IsPlayerInGame",			sm_IsClientInGame},			/* Backwards compat shim */
ds@784
  1039
	{"IsClientInGame",			sm_IsClientInGame},
ds@1001
  1040
	{"IsClientObserver",		IsClientObserver},
dvander@458
  1041
	{"RemoveUserFlags",			RemoveUserFlags},
dvander@644
  1042
	{"SetUserAdmin",			SetUserAdmin},
dvander@458
  1043
	{"SetUserFlagBits",			SetUserFlagBits},
faluco@658
  1044
	{"GetClientDeaths",			GetDeathCount},
faluco@658
  1045
	{"GetClientFrags",			GetFragCount},
faluco@658
  1046
	{"GetClientArmor",			GetArmorValue},
faluco@658
  1047
	{"GetClientAbsOrigin",		GetAbsOrigin},
faluco@658
  1048
	{"GetClientAbsAngles",		GetAbsAngles},
faluco@658
  1049
	{"GetClientMins",			GetPlayerMins},
faluco@658
  1050
	{"GetClientMaxs",			GetPlayerMaxs},
faluco@658
  1051
	{"GetClientWeapon",			GetWeaponName},
faluco@658
  1052
	{"GetClientModel",			GetModelName},
faluco@658
  1053
	{"GetClientHealth",			GetHealth},
dvander@691
  1054
	{"GetClientTime",			GetTimeConnected},
dvander@691
  1055
	{"GetClientDataRate",		GetDataRate},
dvander@691
  1056
	{"IsClentTimingOut",		IsTimingOut},
dvander@691
  1057
	{"GetClientLatency",		GetLatency},
dvander@691
  1058
	{"GetClientAvgLatency",		GetAvgLatency},
dvander@691
  1059
	{"GetClientAvgLoss",		GetAvgLoss},
dvander@691
  1060
	{"GetClientAvgChoke",		GetAvgChoke},
dvander@691
  1061
	{"GetClientAvgData",		GetAvgData},
dvander@691
  1062
	{"GetClientAvgPackets",		GetAvgPackets},
faluco@682
  1063
	{"GetClientOfUserId",		GetClientOfUserId},
dvander@910
  1064
	{"ShowActivity",			ShowActivity},
ds@992
  1065
	{"KickClient",				KickClient},
faluco@260
  1066
	{NULL,						NULL}
dvander@351
  1067
};