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