core/smn_player.cpp
author Borja Ferrer <faluco@alliedmods.net>
Wed Mar 28 23:35:12 2007 +0000 (2007-03-28)
changeset 658 b46ff98c249b
parent 653 ef60870067ff
child 682 a70055d6d3b3
permissions -rw-r--r--
added iplayerinfo natives
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"
faluco@242
    18
faluco@260
    19
static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params)
faluco@242
    20
{
faluco@242
    21
	if (params[1])
faluco@242
    22
	{
dvander@448
    23
		return g_Players.NumPlayers();
faluco@242
    24
	}
faluco@242
    25
dvander@448
    26
	int maxplayers = g_Players.MaxClients();
faluco@242
    27
	int count = 0;
faluco@242
    28
	for (int i=1; i<=maxplayers; ++i)
faluco@242
    29
	{
dvander@448
    30
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
dvander@435
    31
		if ((pPlayer->IsConnected()) && !(pPlayer->IsInGame()))
faluco@242
    32
		{
faluco@242
    33
			count++;
faluco@242
    34
		}
faluco@242
    35
	}
faluco@242
    36
dvander@448
    37
	return (g_Players.NumPlayers() + count);
faluco@242
    38
}
faluco@242
    39
faluco@260
    40
static cell_t sm_GetMaxClients(IPluginContext *pCtx, const cell_t *params)
faluco@242
    41
{
dvander@448
    42
	return g_Players.MaxClients();
faluco@242
    43
}
faluco@242
    44
faluco@260
    45
static cell_t sm_GetClientName(IPluginContext *pCtx, const cell_t *params)
faluco@242
    46
{
faluco@242
    47
	int index = params[1];
dvander@448
    48
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
    49
	{
ds@470
    50
		return pCtx->ThrowNativeError("Invalid client index %d", index);
faluco@242
    51
	}
faluco@242
    52
dvander@448
    53
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
    54
	if (!pPlayer->IsConnected())
faluco@260
    55
	{
ds@470
    56
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@260
    57
	}
faluco@260
    58
dvander@435
    59
	pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pPlayer->GetName(), NULL);
faluco@242
    60
	return 1;
faluco@242
    61
}
faluco@242
    62
faluco@260
    63
static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params)
faluco@242
    64
{
faluco@242
    65
	int index = params[1];
dvander@448
    66
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
    67
	{
ds@470
    68
		return pCtx->ThrowNativeError("Invalid client index %d", index);
faluco@242
    69
	}
faluco@242
    70
dvander@448
    71
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
    72
	if (!pPlayer->IsConnected())
faluco@260
    73
	{
ds@470
    74
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@260
    75
	}
faluco@260
    76
faluco@280
    77
	char buf[64], *ptr;
dvander@435
    78
	strcpy(buf, pPlayer->GetIPAddress());
faluco@280
    79
faluco@280
    80
	if (params[4] && (ptr = strchr(buf, ':')))
faluco@280
    81
	{
faluco@280
    82
		*ptr = '\0';
faluco@280
    83
	}
faluco@280
    84
faluco@280
    85
	pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), buf);
faluco@242
    86
	return 1;
faluco@242
    87
}
faluco@242
    88
faluco@260
    89
static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params)
faluco@242
    90
{
faluco@242
    91
	int index = params[1];
dvander@448
    92
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
    93
	{
ds@470
    94
		return pCtx->ThrowNativeError("Invalid client index %d", index);
faluco@242
    95
	}
faluco@242
    96
dvander@448
    97
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
    98
	if (!pPlayer->IsConnected())
faluco@260
    99
	{
ds@470
   100
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@260
   101
	}
faluco@260
   102
dvander@449
   103
	if (!pPlayer->IsAuthorized())
dvander@449
   104
	{
dvander@449
   105
		return 0;
dvander@449
   106
	}
dvander@449
   107
dvander@435
   108
	pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), pPlayer->GetAuthString());
dvander@449
   109
faluco@242
   110
	return 1;
faluco@242
   111
}
faluco@242
   112
faluco@260
   113
static cell_t sm_IsPlayerConnected(IPluginContext *pCtx, const cell_t *params)
faluco@242
   114
{
faluco@242
   115
	int index = params[1];
dvander@448
   116
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   117
	{
ds@470
   118
		return pCtx->ThrowNativeError("Invalid client index %d", index);
faluco@242
   119
	}
faluco@242
   120
dvander@448
   121
	return (g_Players.GetPlayerByIndex(index)->IsConnected()) ? 1 : 0;
faluco@242
   122
}
faluco@242
   123
faluco@260
   124
static cell_t sm_IsPlayerIngame(IPluginContext *pCtx, const cell_t *params)
faluco@242
   125
{
faluco@242
   126
	int index = params[1];
dvander@448
   127
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   128
	{
ds@470
   129
		return pCtx->ThrowNativeError("Invalid client index %d", index);
faluco@242
   130
	}
faluco@242
   131
dvander@448
   132
	return (g_Players.GetPlayerByIndex(index)->IsInGame()) ? 1 : 0;
faluco@242
   133
}
faluco@242
   134
faluco@260
   135
static cell_t sm_IsPlayerAuthorized(IPluginContext *pCtx, const cell_t *params)
faluco@242
   136
{
faluco@242
   137
	int index = params[1];
dvander@448
   138
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   139
	{
ds@470
   140
		return pCtx->ThrowNativeError("Invalid client index %d", index);
faluco@242
   141
	}
faluco@242
   142
dvander@448
   143
	return (g_Players.GetPlayerByIndex(index)->IsAuthorized()) ? 1 : 0;
faluco@242
   144
}
faluco@242
   145
faluco@260
   146
static cell_t sm_IsPlayerFakeClient(IPluginContext *pCtx, const cell_t *params)
faluco@242
   147
{
faluco@242
   148
	int index = params[1];
dvander@448
   149
	if ((index < 1) || (index > g_Players.GetMaxClients()))
faluco@242
   150
	{
ds@470
   151
		return pCtx->ThrowNativeError("Invalid client index %d", index);
faluco@260
   152
	}
faluco@260
   153
dvander@448
   154
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
dvander@435
   155
	if (!pPlayer->IsConnected())
faluco@260
   156
	{
ds@470
   157
		return pCtx->ThrowNativeError("Client %d is not connected", index);
faluco@242
   158
	}
faluco@242
   159
dvander@435
   160
	return (pPlayer->IsFakeClient()) ? 1 : 0;
faluco@260
   161
}
faluco@260
   162
dvander@456
   163
static cell_t sm_GetClientInfo(IPluginContext *pContext, const cell_t *params)
dvander@456
   164
{
dvander@456
   165
	int client = params[1];
dvander@456
   166
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@456
   167
	if (!pPlayer)
dvander@456
   168
	{
ds@470
   169
		return pContext->ThrowNativeError("Invalid client index %d", client);
dvander@456
   170
	}
dvander@456
   171
	if (!pPlayer->IsConnected())
dvander@456
   172
	{
ds@470
   173
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@456
   174
	}
dvander@456
   175
dvander@456
   176
	char *key;
dvander@456
   177
	pContext->LocalToString(params[2], &key);
dvander@456
   178
dvander@456
   179
	const char *val = engine->GetClientConVarValue(client, key);
dvander@456
   180
	if (!val)
dvander@456
   181
	{
dvander@456
   182
		return false;
dvander@456
   183
	}
dvander@456
   184
dvander@456
   185
	pContext->StringToLocalUTF8(params[3], params[4], val, NULL);
dvander@456
   186
	return 1;
dvander@456
   187
}
dvander@456
   188
dvander@458
   189
static cell_t SetUserAdmin(IPluginContext *pContext, const cell_t *params)
dvander@458
   190
{
dvander@458
   191
	int client = params[1];
dvander@458
   192
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   193
	if (!pPlayer)
dvander@458
   194
	{
ds@470
   195
		return pContext->ThrowNativeError("Invalid client index %d", client);
dvander@458
   196
	}
dvander@458
   197
	if (!pPlayer->IsConnected())
dvander@458
   198
	{
ds@470
   199
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   200
	}
dvander@458
   201
	if (!g_Admins.IsValidAdmin(params[2]))
dvander@458
   202
	{
ds@470
   203
		return pContext->ThrowNativeError("AdminId %x is not valid", params[2]);
dvander@458
   204
	}
dvander@458
   205
dvander@458
   206
	pPlayer->SetAdminId(params[2], params[3] ? true : false);
dvander@458
   207
dvander@458
   208
	return 1;
dvander@458
   209
}
dvander@458
   210
dvander@458
   211
static cell_t GetUserAdmin(IPluginContext *pContext, const cell_t *params)
dvander@458
   212
{
dvander@458
   213
	int client = params[1];
dvander@458
   214
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   215
	if (!pPlayer)
dvander@458
   216
	{
ds@470
   217
		return pContext->ThrowNativeError("Invalid client index %d", client);
dvander@458
   218
	}
dvander@458
   219
	if (!pPlayer->IsConnected())
dvander@458
   220
	{
ds@470
   221
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   222
	}
dvander@458
   223
dvander@458
   224
	return pPlayer->GetAdminId();
dvander@458
   225
}
dvander@458
   226
dvander@458
   227
static cell_t AddUserFlags(IPluginContext *pContext, const cell_t *params)
dvander@458
   228
{
dvander@458
   229
	int client = params[1];
dvander@458
   230
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   231
	if (!pPlayer)
dvander@458
   232
	{
ds@470
   233
		return pContext->ThrowNativeError("Invalid client index %d", client);
dvander@458
   234
	}
dvander@458
   235
	if (!pPlayer->IsConnected())
dvander@458
   236
	{
ds@470
   237
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   238
	}
dvander@458
   239
dvander@458
   240
	AdminId id;
dvander@458
   241
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   242
	{
dvander@458
   243
		id = g_Admins.CreateAdmin(NULL);
dvander@458
   244
		pPlayer->SetAdminId(id, true);
dvander@458
   245
	}
dvander@458
   246
dvander@458
   247
	cell_t *addr;
dvander@458
   248
	for (int i=2; i<=params[0]; i++)
dvander@458
   249
	{
dvander@458
   250
		pContext->LocalToPhysAddr(params[i], &addr);
dvander@458
   251
		g_Admins.SetAdminFlag(id, (AdminFlag)*addr, true);
dvander@458
   252
	}
dvander@458
   253
dvander@458
   254
	return 1;
dvander@458
   255
}
dvander@458
   256
dvander@458
   257
static cell_t RemoveUserFlags(IPluginContext *pContext, const cell_t *params)
dvander@458
   258
{
dvander@458
   259
	int client = params[1];
dvander@458
   260
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   261
	if (!pPlayer)
dvander@458
   262
	{
ds@470
   263
		return pContext->ThrowNativeError("Invalid client index %d", client);
dvander@458
   264
	}
dvander@458
   265
	if (!pPlayer->IsConnected())
dvander@458
   266
	{
ds@470
   267
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   268
	}
dvander@458
   269
	
dvander@458
   270
	AdminId id;
dvander@458
   271
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   272
	{
dvander@458
   273
		return 0;
dvander@458
   274
	}
dvander@458
   275
dvander@458
   276
	cell_t *addr;
dvander@458
   277
	for (int i=2; i<=params[0]; i++)
dvander@458
   278
	{
dvander@458
   279
		pContext->LocalToPhysAddr(params[i], &addr);
dvander@458
   280
		g_Admins.SetAdminFlag(id, (AdminFlag)*addr, false);
dvander@458
   281
	}
dvander@458
   282
dvander@458
   283
	return 1;
dvander@458
   284
}
dvander@458
   285
dvander@458
   286
static cell_t SetUserFlagBits(IPluginContext *pContext, const cell_t *params)
dvander@458
   287
{
dvander@458
   288
	int client = params[1];
dvander@458
   289
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   290
	if (!pPlayer)
dvander@458
   291
	{
ds@470
   292
		return pContext->ThrowNativeError("Invalid client index %d", client);
dvander@458
   293
	}
dvander@458
   294
	if (!pPlayer->IsConnected())
dvander@458
   295
	{
ds@470
   296
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   297
	}
dvander@458
   298
dvander@458
   299
	AdminId id;
dvander@458
   300
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   301
	{
dvander@458
   302
		id = g_Admins.CreateAdmin(NULL);
dvander@458
   303
		pPlayer->SetAdminId(id, true);
dvander@458
   304
	}
dvander@458
   305
dvander@458
   306
	g_Admins.SetAdminFlags(id, Access_Effective, params[2]);
dvander@458
   307
dvander@458
   308
	return 1;
dvander@458
   309
}
dvander@458
   310
dvander@458
   311
static cell_t GetUserFlagBits(IPluginContext *pContext, const cell_t *params)
dvander@458
   312
{
dvander@458
   313
	int client = params[1];
dvander@458
   314
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@458
   315
	if (!pPlayer)
dvander@458
   316
	{
ds@470
   317
		return pContext->ThrowNativeError("Invalid client index %d", client);
dvander@458
   318
	}
dvander@458
   319
	if (!pPlayer->IsConnected())
dvander@458
   320
	{
ds@470
   321
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@458
   322
	}
dvander@458
   323
dvander@458
   324
	AdminId id;
dvander@458
   325
	if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
dvander@458
   326
	{
dvander@458
   327
		return 0;
dvander@458
   328
	}
dvander@458
   329
dvander@458
   330
	return g_Admins.GetAdminFlags(id, Access_Effective);
dvander@458
   331
}
dvander@458
   332
dvander@460
   333
static cell_t GetClientUserId(IPluginContext *pContext, const cell_t *params)
dvander@460
   334
{
dvander@460
   335
	int client = params[1];
dvander@460
   336
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@460
   337
	if (!pPlayer)
dvander@460
   338
	{
ds@470
   339
		return pContext->ThrowNativeError("Invalid client index %d", client);
dvander@460
   340
	}
dvander@460
   341
	if (!pPlayer->IsConnected())
dvander@460
   342
	{
ds@470
   343
		return pContext->ThrowNativeError("Client %d is not connected", client);
dvander@460
   344
	}
dvander@460
   345
dvander@460
   346
	return engine->GetPlayerUserId(pPlayer->GetEdict());
dvander@460
   347
}
dvander@460
   348
dvander@540
   349
static cell_t CanUserTarget(IPluginContext *pContext, const cell_t *params)
dvander@540
   350
{
dvander@540
   351
	int client = params[1];
dvander@540
   352
	int target = params[2];
dvander@540
   353
dvander@540
   354
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@540
   355
	if (!pPlayer)
dvander@540
   356
	{
dvander@540
   357
		return pContext->ThrowNativeError("Player %d is not a valid client", client);
dvander@540
   358
	} else if (!pPlayer->IsConnected()) {
dvander@540
   359
		return pContext->ThrowNativeError("Player %d is not connected", client);
dvander@540
   360
	}
dvander@540
   361
dvander@540
   362
	CPlayer *pTarget = g_Players.GetPlayerByIndex(target);
dvander@540
   363
	if (!pTarget)
dvander@540
   364
	{
dvander@540
   365
		return pContext->ThrowNativeError("Player %d is not a valid client", target);
dvander@540
   366
	} else if (!pTarget->IsConnected()) {
dvander@540
   367
		return pContext->ThrowNativeError("Player %d is not connected", target);
dvander@540
   368
	}
dvander@540
   369
dvander@540
   370
	return g_Admins.CanAdminTarget(pPlayer->GetAdminId(), pTarget->GetAdminId()) ? 1 : 0;
dvander@540
   371
}
dvander@540
   372
dvander@644
   373
static cell_t GetClientTeam(IPluginContext *pContext, const cell_t *params)
dvander@644
   374
{
dvander@644
   375
	int client = params[1];
dvander@644
   376
dvander@644
   377
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
dvander@644
   378
	if (!pPlayer)
dvander@644
   379
	{
dvander@644
   380
		return pContext->ThrowNativeError("Player %d is not a valid client", client);
dvander@644
   381
	} else if (!pPlayer->IsInGame()) {
dvander@644
   382
		return pContext->ThrowNativeError("Player %d is not in game", client);
dvander@644
   383
	}
dvander@644
   384
dvander@644
   385
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
dvander@644
   386
	if (!pInfo)
dvander@644
   387
	{
dvander@644
   388
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
dvander@644
   389
	}
dvander@644
   390
dvander@644
   391
	return pInfo->GetTeamIndex();
dvander@644
   392
}
dvander@644
   393
faluco@658
   394
static cell_t GetFragCount(IPluginContext *pContext, const cell_t *params)
faluco@658
   395
{
faluco@658
   396
	int client = params[1];
faluco@658
   397
faluco@658
   398
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   399
	if (!pPlayer)
faluco@658
   400
	{
faluco@658
   401
		return pContext->ThrowNativeError("Player %d is not a valid client", client);
faluco@658
   402
	} else if (!pPlayer->IsInGame()) {
faluco@658
   403
		return pContext->ThrowNativeError("Player %d is not in game", client);
faluco@658
   404
	}
faluco@658
   405
faluco@658
   406
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   407
	if (!pInfo)
faluco@658
   408
	{
faluco@658
   409
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   410
	}
faluco@658
   411
faluco@658
   412
	return pInfo->GetFragCount();
faluco@658
   413
}
faluco@658
   414
faluco@658
   415
static cell_t GetDeathCount(IPluginContext *pContext, const cell_t *params)
faluco@658
   416
{
faluco@658
   417
	int client = params[1];
faluco@658
   418
faluco@658
   419
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   420
	if (!pPlayer)
faluco@658
   421
	{
faluco@658
   422
		return pContext->ThrowNativeError("Player %d is not a valid client", client);
faluco@658
   423
	} else if (!pPlayer->IsInGame()) {
faluco@658
   424
		return pContext->ThrowNativeError("Player %d is not in game", client);
faluco@658
   425
	}
faluco@658
   426
faluco@658
   427
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   428
	if (!pInfo)
faluco@658
   429
	{
faluco@658
   430
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   431
	}
faluco@658
   432
faluco@658
   433
	return pInfo->GetDeathCount();
faluco@658
   434
}
faluco@658
   435
faluco@658
   436
static cell_t GetArmorValue(IPluginContext *pContext, const cell_t *params)
faluco@658
   437
{
faluco@658
   438
	int client = params[1];
faluco@658
   439
faluco@658
   440
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   441
	if (!pPlayer)
faluco@658
   442
	{
faluco@658
   443
		return pContext->ThrowNativeError("Player %d is not a valid client", client);
faluco@658
   444
	} else if (!pPlayer->IsInGame()) {
faluco@658
   445
		return pContext->ThrowNativeError("Player %d is not in game", client);
faluco@658
   446
	}
faluco@658
   447
faluco@658
   448
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   449
	if (!pInfo)
faluco@658
   450
	{
faluco@658
   451
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   452
	}
faluco@658
   453
faluco@658
   454
	return pInfo->GetArmorValue();
faluco@658
   455
}
faluco@658
   456
faluco@658
   457
static cell_t GetAbsOrigin(IPluginContext *pContext, const cell_t *params)
faluco@658
   458
{
faluco@658
   459
	int client = params[1];
faluco@658
   460
faluco@658
   461
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   462
	if (!pPlayer)
faluco@658
   463
	{
faluco@658
   464
		return pContext->ThrowNativeError("Player %d is not a valid client", client);
faluco@658
   465
	} else if (!pPlayer->IsInGame()) {
faluco@658
   466
		return pContext->ThrowNativeError("Player %d is not in game", client);
faluco@658
   467
	}
faluco@658
   468
faluco@658
   469
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   470
	if (!pInfo)
faluco@658
   471
	{
faluco@658
   472
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   473
	}
faluco@658
   474
faluco@658
   475
	cell_t *pVec;
faluco@658
   476
	pContext->LocalToPhysAddr(params[2], &pVec);
faluco@658
   477
faluco@658
   478
	Vector vec = pInfo->GetAbsOrigin();
faluco@658
   479
	pVec[0] = sp_ftoc(vec.x);
faluco@658
   480
	pVec[1] = sp_ftoc(vec.y);
faluco@658
   481
	pVec[2] = sp_ftoc(vec.z);
faluco@658
   482
faluco@658
   483
	return 1;
faluco@658
   484
}
faluco@658
   485
faluco@658
   486
static cell_t GetAbsAngles(IPluginContext *pContext, const cell_t *params)
faluco@658
   487
{
faluco@658
   488
	int client = params[1];
faluco@658
   489
faluco@658
   490
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   491
	if (!pPlayer)
faluco@658
   492
	{
faluco@658
   493
		return pContext->ThrowNativeError("Player %d is not a valid client", client);
faluco@658
   494
	} else if (!pPlayer->IsInGame()) {
faluco@658
   495
		return pContext->ThrowNativeError("Player %d is not in game", client);
faluco@658
   496
	}
faluco@658
   497
faluco@658
   498
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   499
	if (!pInfo)
faluco@658
   500
	{
faluco@658
   501
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   502
	}
faluco@658
   503
faluco@658
   504
	cell_t *pAng;
faluco@658
   505
	pContext->LocalToPhysAddr(params[2], &pAng);
faluco@658
   506
faluco@658
   507
	QAngle ang = pInfo->GetAbsAngles();
faluco@658
   508
	pAng[0] = sp_ftoc(ang.x);
faluco@658
   509
	pAng[1] = sp_ftoc(ang.y);
faluco@658
   510
	pAng[2] = sp_ftoc(ang.z);
faluco@658
   511
faluco@658
   512
	return 1;
faluco@658
   513
}
faluco@658
   514
faluco@658
   515
static cell_t GetPlayerMins(IPluginContext *pContext, const cell_t *params)
faluco@658
   516
{
faluco@658
   517
	int client = params[1];
faluco@658
   518
faluco@658
   519
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   520
	if (!pPlayer)
faluco@658
   521
	{
faluco@658
   522
		return pContext->ThrowNativeError("Player %d is not a valid client", client);
faluco@658
   523
	} else if (!pPlayer->IsInGame()) {
faluco@658
   524
		return pContext->ThrowNativeError("Player %d is not in game", client);
faluco@658
   525
	}
faluco@658
   526
faluco@658
   527
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   528
	if (!pInfo)
faluco@658
   529
	{
faluco@658
   530
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   531
	}
faluco@658
   532
faluco@658
   533
	cell_t *pVec;
faluco@658
   534
	pContext->LocalToPhysAddr(params[2], &pVec);
faluco@658
   535
faluco@658
   536
	Vector vec = pInfo->GetPlayerMins();
faluco@658
   537
	pVec[0] = sp_ftoc(vec.x);
faluco@658
   538
	pVec[1] = sp_ftoc(vec.y);
faluco@658
   539
	pVec[2] = sp_ftoc(vec.z);
faluco@658
   540
faluco@658
   541
	return 1;
faluco@658
   542
}
faluco@658
   543
faluco@658
   544
static cell_t GetPlayerMaxs(IPluginContext *pContext, const cell_t *params)
faluco@658
   545
{
faluco@658
   546
	int client = params[1];
faluco@658
   547
faluco@658
   548
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   549
	if (!pPlayer)
faluco@658
   550
	{
faluco@658
   551
		return pContext->ThrowNativeError("Player %d is not a valid client", client);
faluco@658
   552
	} else if (!pPlayer->IsInGame()) {
faluco@658
   553
		return pContext->ThrowNativeError("Player %d is not in game", client);
faluco@658
   554
	}
faluco@658
   555
faluco@658
   556
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   557
	if (!pInfo)
faluco@658
   558
	{
faluco@658
   559
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   560
	}
faluco@658
   561
faluco@658
   562
	cell_t *pVec;
faluco@658
   563
	pContext->LocalToPhysAddr(params[2], &pVec);
faluco@658
   564
faluco@658
   565
	Vector vec = pInfo->GetPlayerMaxs();
faluco@658
   566
	pVec[0] = sp_ftoc(vec.x);
faluco@658
   567
	pVec[1] = sp_ftoc(vec.y);
faluco@658
   568
	pVec[2] = sp_ftoc(vec.z);
faluco@658
   569
faluco@658
   570
	return 1;
faluco@658
   571
}
faluco@658
   572
faluco@658
   573
static cell_t GetWeaponName(IPluginContext *pContext, const cell_t *params)
faluco@658
   574
{
faluco@658
   575
	int client = params[1];
faluco@658
   576
faluco@658
   577
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   578
	if (!pPlayer)
faluco@658
   579
	{
faluco@658
   580
		return pContext->ThrowNativeError("Player %d is not a valid client", client);
faluco@658
   581
	} else if (!pPlayer->IsInGame()) {
faluco@658
   582
		return pContext->ThrowNativeError("Player %d is not in game", client);
faluco@658
   583
	}
faluco@658
   584
faluco@658
   585
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   586
	if (!pInfo)
faluco@658
   587
	{
faluco@658
   588
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   589
	}
faluco@658
   590
faluco@658
   591
	pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pInfo->GetWeaponName(), NULL);
faluco@658
   592
faluco@658
   593
	return 1;
faluco@658
   594
}
faluco@658
   595
faluco@658
   596
static cell_t GetModelName(IPluginContext *pContext, const cell_t *params)
faluco@658
   597
{
faluco@658
   598
	int client = params[1];
faluco@658
   599
faluco@658
   600
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   601
	if (!pPlayer)
faluco@658
   602
	{
faluco@658
   603
		return pContext->ThrowNativeError("Player %d is not a valid client", client);
faluco@658
   604
	} else if (!pPlayer->IsInGame()) {
faluco@658
   605
		return pContext->ThrowNativeError("Player %d is not in game", client);
faluco@658
   606
	}
faluco@658
   607
faluco@658
   608
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   609
	if (!pInfo)
faluco@658
   610
	{
faluco@658
   611
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   612
	}
faluco@658
   613
faluco@658
   614
	pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pInfo->GetModelName(), NULL);
faluco@658
   615
faluco@658
   616
	return 1;
faluco@658
   617
}
faluco@658
   618
faluco@658
   619
static cell_t GetHealth(IPluginContext *pContext, const cell_t *params)
faluco@658
   620
{
faluco@658
   621
	int client = params[1];
faluco@658
   622
faluco@658
   623
	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
faluco@658
   624
	if (!pPlayer)
faluco@658
   625
	{
faluco@658
   626
		return pContext->ThrowNativeError("Player %d is not a valid client", client);
faluco@658
   627
	} else if (!pPlayer->IsInGame()) {
faluco@658
   628
		return pContext->ThrowNativeError("Player %d is not in game", client);
faluco@658
   629
	}
faluco@658
   630
faluco@658
   631
	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
faluco@658
   632
	if (!pInfo)
faluco@658
   633
	{
faluco@658
   634
		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
faluco@658
   635
	}
faluco@658
   636
faluco@658
   637
	return pInfo->GetHealth();
faluco@658
   638
}
faluco@658
   639
faluco@260
   640
REGISTER_NATIVES(playernatives)
faluco@260
   641
{
dvander@644
   642
	{"AddUserFlags",			AddUserFlags},
dvander@644
   643
	{"CanUserTarget",			CanUserTarget},
dvander@644
   644
	{"GetClientAuthString",		sm_GetClientAuthStr},
faluco@260
   645
	{"GetClientCount",			sm_GetClientCount},
dvander@644
   646
	{"GetClientInfo",			sm_GetClientInfo},
faluco@260
   647
	{"GetClientIP",				sm_GetClientIP},
dvander@644
   648
	{"GetClientName",			sm_GetClientName},
dvander@644
   649
	{"GetClientTeam",			GetClientTeam},
dvander@644
   650
	{"GetClientUserId",			GetClientUserId},
dvander@644
   651
	{"GetMaxClients",			sm_GetMaxClients},
dvander@644
   652
	{"GetUserAdmin",			GetUserAdmin},
dvander@644
   653
	{"GetUserFlagBits",			GetUserFlagBits},
dvander@644
   654
	{"IsClientAuthorized",		sm_IsPlayerAuthorized},
dvander@492
   655
	{"IsClientConnected",		sm_IsPlayerConnected},
dvander@492
   656
	{"IsFakeClient",			sm_IsPlayerFakeClient},
dvander@644
   657
	{"IsPlayerInGame",			sm_IsPlayerIngame},
dvander@458
   658
	{"RemoveUserFlags",			RemoveUserFlags},
dvander@644
   659
	{"SetUserAdmin",			SetUserAdmin},
dvander@458
   660
	{"SetUserFlagBits",			SetUserFlagBits},
faluco@658
   661
	{"GetClientDeaths",			GetDeathCount},
faluco@658
   662
	{"GetClientFrags",			GetFragCount},
faluco@658
   663
	{"GetClientArmor",			GetArmorValue},
faluco@658
   664
	{"GetClientAbsOrigin",		GetAbsOrigin},
faluco@658
   665
	{"GetClientAbsAngles",		GetAbsAngles},
faluco@658
   666
	{"GetClientMins",			GetPlayerMins},
faluco@658
   667
	{"GetClientMaxs",			GetPlayerMaxs},
faluco@658
   668
	{"GetClientWeapon",			GetWeaponName},
faluco@658
   669
	{"GetClientModel",			GetModelName},
faluco@658
   670
	{"GetClientHealth",			GetHealth},
faluco@260
   671
	{NULL,						NULL}
dvander@351
   672
};