core/PlayerManager.h
author David Anderson <dvander@alliedmods.net>
Sat Feb 16 15:52:11 2013 -0800 (2013-02-16)
changeset 3791 47e1ee9cea86
parent 3502 2c1c30b50acc
child 3808 b5f4ea4d3736
permissions -rw-r--r--
Move filesystem natives from Core to Logic (bug 5606, r=psychonic).
dvander@591
     1
/**
ds@653
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
ds@1947
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
dvander@591
     7
 *
ds@1330
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    10
 * Free Software Foundation.
dvander@1231
    11
 * 
ds@1330
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    15
 * details.
dvander@1231
    16
 *
ds@1330
    17
 * You should have received a copy of the GNU General Public License along with
ds@1330
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
ds@1330
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@591
    28
 *
dvander@591
    29
 * Version: $Id$
dvander@591
    30
 */
dvander@591
    31
dvander@591
    32
#ifndef _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
dvander@591
    33
#define _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
dvander@591
    34
dvander@591
    35
#include "sm_globals.h"
dvander@591
    36
#include <eiface.h>
dvander@591
    37
#include "sourcemm_api.h"
dvander@591
    38
#include <IForwardSys.h>
dvander@591
    39
#include <IPlayerHelpers.h>
dvander@591
    40
#include <IAdminSystem.h>
dvander@591
    41
#include <sh_string.h>
dvander@591
    42
#include <sh_list.h>
dvander@591
    43
#include <sh_vector.h>
pred@2323
    44
#include "ConVarManager.h"
dvander@591
    45
dvander@591
    46
using namespace SourceHook;
dvander@591
    47
dvander@1621
    48
#define PLAYER_LIFE_UNKNOWN	0
dvander@1621
    49
#define PLAYER_LIFE_ALIVE	1
dvander@1621
    50
#define PLAYER_LIFE_DEAD	2
dvander@1621
    51
dvander@1688
    52
#define MIN_API_FOR_ADMINCALLS		7
dvander@1688
    53
pred@2591
    54
union serial_t
pred@2591
    55
{
pred@2591
    56
	uint32_t   value;
pred@2591
    57
	struct
pred@2591
    58
	{
asherkin@3488
    59
		uint32_t index  :  8;
pred@2591
    60
		uint32_t serial : 24;
pred@2591
    61
	} bits;
pred@2591
    62
};
pred@2591
    63
dvander@591
    64
class CPlayer : public IGamePlayer
dvander@591
    65
{
dvander@616
    66
	friend class PlayerManager;
dvander@591
    67
public:
dvander@591
    68
	CPlayer();
dvander@591
    69
public:
dvander@615
    70
	const char *GetName();
dvander@615
    71
	const char *GetIPAddress();
dvander@615
    72
	const char *GetAuthString();
dvander@615
    73
	edict_t *GetEdict();
dvander@615
    74
	bool IsInGame();
dvander@1358
    75
	bool WasCountedAsInGame();
dvander@615
    76
	bool IsConnected();
dvander@615
    77
	bool IsAuthorized();
voidedweasel@3502
    78
#if SOURCE_ENGINE >= SE_ORANGEBOX
voidedweasel@3502
    79
	bool IsAuthedBySteam();
voidedweasel@3502
    80
#endif
dvander@615
    81
	bool IsFakeClient();
skamonkey@3418
    82
	bool IsSourceTV() const;
skamonkey@3418
    83
	bool IsReplay() const;
dvander@591
    84
	void SetAdminId(AdminId id, bool temporary);
dvander@615
    85
	AdminId GetAdminId();
dvander@1161
    86
	void Kick(const char *str);
theY4Kman@2777
    87
	bool IsInKickQueue();
dvander@1273
    88
	IPlayerInfo *GetPlayerInfo();
faluco@1352
    89
	unsigned int GetLanguageId();
skamonkey@3213
    90
	void SetLanguageId(unsigned int id);
dvander@1350
    91
	int GetUserId();
dvander@1688
    92
	bool RunAdminCacheChecks();
dvander@1688
    93
	void NotifyPostAdminChecks();
pred@2591
    94
	unsigned int GetSerial();
dvander@644
    95
public:
dvander@1273
    96
	void DoBasicAdminChecks();
dvander@1509
    97
	void MarkAsBeingKicked();
dvander@1621
    98
	int GetLifeState();
dvander@591
    99
private:
dvander@591
   100
	void Initialize(const char *name, const char *ip, edict_t *pEntity);
dvander@591
   101
	void Connect();
dvander@591
   102
	void Disconnect();
dvander@591
   103
	void SetName(const char *name);
dvander@591
   104
	void DumpAdmin(bool deleting);
dvander@1161
   105
	void Authorize(const char *auth);
dvander@1161
   106
	void Authorize_Post();
dvander@1273
   107
	void DoPostConnectAuthorization();
dvander@591
   108
private:
dvander@591
   109
	bool m_IsConnected;
dvander@591
   110
	bool m_IsInGame;
dvander@591
   111
	bool m_IsAuthorized;
dvander@1509
   112
	bool m_bIsInKickQueue;
dvander@591
   113
	String m_Name;
dvander@591
   114
	String m_Ip;
dvander@1161
   115
	String m_IpNoPort;
dvander@591
   116
	String m_AuthID;
dvander@591
   117
	AdminId m_Admin;
dvander@591
   118
	bool m_TempAdmin;
dvander@591
   119
	edict_t *m_pEdict;
dvander@644
   120
	IPlayerInfo *m_Info;
dvander@1161
   121
	String m_LastPassword;
dvander@1273
   122
	bool m_bAdminCheckSignalled;
dvander@1273
   123
	int m_iIndex;
faluco@1352
   124
	unsigned int m_LangId;
dvander@1350
   125
	int m_UserId;
ds@2238
   126
	bool m_bFakeClient;
skamonkey@3418
   127
	bool m_bIsSourceTV;
skamonkey@3418
   128
	bool m_bIsReplay;
pred@2591
   129
	serial_t m_Serial;
dvander@591
   130
};
dvander@591
   131
dvander@616
   132
class PlayerManager : 
dvander@591
   133
	public SMGlobalClass,
skamonkey@3186
   134
	public IPlayerManager
dvander@591
   135
{
dvander@1688
   136
	friend class CPlayer;
dvander@591
   137
public:
dvander@616
   138
	PlayerManager();
dvander@616
   139
	~PlayerManager();
dvander@591
   140
public: //SMGlobalClass
dvander@591
   141
	void OnSourceModAllInitialized();
dvander@591
   142
	void OnSourceModShutdown();
dvander@916
   143
	void OnSourceModLevelEnd();
dvander@1160
   144
	ConfigResult OnSourceModConfigChanged(const char *key, const char *value, ConfigSource source, char *error, size_t maxlength);
skamonkey@3350
   145
	void OnSourceModMaxPlayersChanged(int newvalue);
dvander@591
   146
public:
dvander@591
   147
	CPlayer *GetPlayerByIndex(int client) const;
dvander@591
   148
	void RunAuthChecks();
dvander@591
   149
	void ClearAdminId(AdminId id);
dvander@591
   150
	void ClearAllAdmins();
dvander@591
   151
public:
dvander@591
   152
	bool OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
dvander@591
   153
	bool OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
dvander@591
   154
	void OnClientPutInServer(edict_t *pEntity, char const *playername);
dvander@591
   155
	void OnClientDisconnect(edict_t *pEntity);
dvander@591
   156
	void OnClientDisconnect_Post(edict_t *pEntity);
ds@2400
   157
#if SOURCE_ENGINE >= SE_ORANGEBOX
faluco@1541
   158
	void OnClientCommand(edict_t *pEntity, const CCommand &args);
faluco@1541
   159
#else
dvander@591
   160
	void OnClientCommand(edict_t *pEntity);
faluco@1541
   161
#endif
dvander@591
   162
	void OnClientSettingsChanged(edict_t *pEntity);
dvander@1161
   163
	//void OnClientSettingsChanged_Pre(edict_t *pEntity);
dvander@591
   164
public: //IPlayerManager
dvander@591
   165
	void AddClientListener(IClientListener *listener);
dvander@591
   166
	void RemoveClientListener(IClientListener *listener);
dvander@591
   167
	IGamePlayer *GetGamePlayer(int client);
dvander@591
   168
	IGamePlayer *GetGamePlayer(edict_t *pEdict);
dvander@591
   169
	int GetMaxClients();
dvander@591
   170
	int GetNumPlayers();
faluco@682
   171
	int GetClientOfUserId(int userid);
skamonkey@3347
   172
	bool IsServerActivated();
dvander@1621
   173
	int FilterCommandTarget(IGamePlayer *pAdmin, IGamePlayer *pTarget, int flags);
dvander@1621
   174
	int InternalFilterCommandTarget(CPlayer *pAdmin, CPlayer *pTarget, int flags);
dvander@1621
   175
	void RegisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
dvander@1621
   176
	void UnregisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
dvander@1621
   177
	void ProcessCommandTarget(cmd_target_info_t *info);
pred@2591
   178
	int GetClientFromSerial(unsigned int serial);
dvander@591
   179
public:
dvander@591
   180
	inline int MaxClients()
dvander@591
   181
	{
skamonkey@3350
   182
		return m_maxClients;
dvander@591
   183
	}
dvander@591
   184
	inline int NumPlayers()
dvander@591
   185
	{
dvander@591
   186
		return m_PlayerCount;
dvander@591
   187
	}
dvander@1996
   188
	inline int ListenClient()
dvander@1996
   189
	{
dvander@1996
   190
		return m_ListenClient;
dvander@1996
   191
	}
dvander@1161
   192
	bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id);
dvander@1161
   193
	bool CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id);
dvander@1161
   194
	const char *GetPassInfoVar();
dvander@1162
   195
	void RecheckAnyAdmins();
dvander@1519
   196
	unsigned int GetReplyTo();
dvander@1519
   197
	unsigned int SetReplyTo(unsigned int reply);
pred@2323
   198
	void MaxPlayersChanged(int newvalue = -1);
dvander@591
   199
private:
dvander@591
   200
	void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
ds@2181
   201
	void InvalidatePlayer(CPlayer *pPlayer);
dvander@591
   202
private:
dvander@591
   203
	List<IClientListener *> m_hooks;
dvander@591
   204
	IForward *m_clconnect;
asherkin@3177
   205
	IForward *m_clconnect_post;
dvander@591
   206
	IForward *m_cldisconnect;
dvander@591
   207
	IForward *m_cldisconnect_post;
dvander@591
   208
	IForward *m_clputinserver;
dvander@591
   209
	IForward *m_clcommand;
dvander@591
   210
	IForward *m_clinfochanged;
dvander@591
   211
	IForward *m_clauth;
dvander@643
   212
	IForward *m_onActivate;
dvander@717
   213
	IForward *m_onActivate2;
dvander@591
   214
	CPlayer *m_Players;
faluco@682
   215
	int *m_UserIdLookUp;
skamonkey@3350
   216
	int m_maxClients;
dvander@591
   217
	int m_PlayerCount;
skamonkey@3418
   218
	int m_PlayersSinceActive;
dvander@591
   219
	bool m_FirstPass;
dvander@591
   220
	unsigned int *m_AuthQueue;
dvander@1160
   221
	String m_PassInfoVar;
faluco@1352
   222
	bool m_QueryLang;
voidedweasel@3502
   223
	bool m_bUseSteamAdminAuth; // are we validating admins with steam before authorizing?
dvander@1996
   224
	bool m_bIsListenServer;
dvander@1996
   225
	int m_ListenClient;
skamonkey@3418
   226
	bool m_bIsSourceTVActive;
skamonkey@3418
   227
	bool m_bIsReplayActive;
skamonkey@3418
   228
	int m_SourceTVUserId;
skamonkey@3418
   229
	int m_ReplayUserId;
dvander@591
   230
};
dvander@591
   231
ds@2400
   232
#if SOURCE_ENGINE >= SE_ORANGEBOX
pred@2323
   233
void CmdMaxplayersCallback(const CCommand &command);
pred@2323
   234
#else
pred@2323
   235
void CmdMaxplayersCallback();
pred@2323
   236
#endif
pred@2323
   237
dvander@2547
   238
extern void ClientConsolePrint(edict_t *e, const char *fmt, ...);
dvander@2547
   239
dvander@616
   240
extern PlayerManager g_Players;
dvander@848
   241
extern bool g_OnMapStarted;
dvander@1412
   242
extern const unsigned int *g_NumPlayersToAuth;
dvander@591
   243
dvander@591
   244
#endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_