core/PlayerManager.h
author Matt Woodrow <pred@alliedmods.net>
Thu May 01 23:48:27 2008 +0000 (2008-05-01)
changeset 2035 941abff6deed
parent 1996 3f0cd604812b
child 2181 7c85684253ed
permissions -rw-r--r--
Added msvc9 Project files to sdktools. Badly.
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod
ds@1952
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     6
 * =============================================================================
ds@1952
     7
 *
ds@1952
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    10
 * Free Software Foundation.
ds@1952
    11
 * 
ds@1952
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    15
 * details.
ds@1952
    16
 *
ds@1952
    17
 * You should have received a copy of the GNU General Public License along with
ds@1952
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    19
 *
ds@1952
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    27
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    28
 *
ds@1952
    29
 * Version: $Id$
ds@1952
    30
 */
ds@1952
    31
ds@1952
    32
#ifndef _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
ds@1952
    33
#define _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
ds@1952
    34
ds@1952
    35
#include "sm_globals.h"
ds@1952
    36
#include <eiface.h>
ds@1952
    37
#include "sourcemm_api.h"
ds@1952
    38
#include <IForwardSys.h>
ds@1952
    39
#include <IPlayerHelpers.h>
ds@1952
    40
#include <IAdminSystem.h>
ds@1952
    41
#include <sh_string.h>
ds@1952
    42
#include <sh_list.h>
ds@1952
    43
#include <sh_vector.h>
ds@1952
    44
ds@1952
    45
using namespace SourceHook;
ds@1952
    46
ds@1952
    47
#define PLAYER_LIFE_UNKNOWN	0
ds@1952
    48
#define PLAYER_LIFE_ALIVE	1
ds@1952
    49
#define PLAYER_LIFE_DEAD	2
ds@1952
    50
ds@1952
    51
#define MIN_API_FOR_ADMINCALLS		7
ds@1952
    52
ds@1952
    53
class CPlayer : public IGamePlayer
ds@1952
    54
{
ds@1952
    55
	friend class PlayerManager;
ds@1952
    56
public:
ds@1952
    57
	CPlayer();
ds@1952
    58
public:
ds@1952
    59
	const char *GetName();
ds@1952
    60
	const char *GetIPAddress();
ds@1952
    61
	const char *GetAuthString();
ds@1952
    62
	edict_t *GetEdict();
ds@1952
    63
	bool IsInGame();
ds@1952
    64
	bool WasCountedAsInGame();
ds@1952
    65
	bool IsConnected();
ds@1952
    66
	bool IsAuthorized();
ds@1952
    67
	bool IsFakeClient();
ds@1952
    68
	void SetAdminId(AdminId id, bool temporary);
ds@1952
    69
	AdminId GetAdminId();
ds@1952
    70
	void Kick(const char *str);
ds@1952
    71
	IPlayerInfo *GetPlayerInfo();
ds@1952
    72
	unsigned int GetLanguageId();
ds@1952
    73
	int GetUserId();
ds@1952
    74
	bool RunAdminCacheChecks();
ds@1952
    75
	void NotifyPostAdminChecks();
ds@1952
    76
public:
ds@1952
    77
	void DoBasicAdminChecks();
ds@1952
    78
	bool IsInKickQueue();
ds@1952
    79
	void MarkAsBeingKicked();
ds@1952
    80
	int GetLifeState();
ds@1952
    81
private:
ds@1952
    82
	void Initialize(const char *name, const char *ip, edict_t *pEntity);
ds@1952
    83
	void Connect();
ds@1952
    84
	void Disconnect();
ds@1952
    85
	void SetName(const char *name);
ds@1952
    86
	void DumpAdmin(bool deleting);
ds@1952
    87
	void Authorize(const char *auth);
ds@1952
    88
	void Authorize_Post();
ds@1952
    89
	void DoPostConnectAuthorization();
ds@1952
    90
private:
ds@1952
    91
	bool m_IsConnected;
ds@1952
    92
	bool m_IsInGame;
ds@1952
    93
	bool m_IsAuthorized;
ds@1952
    94
	bool m_bIsInKickQueue;
ds@1952
    95
	String m_Name;
ds@1952
    96
	String m_Ip;
ds@1952
    97
	String m_IpNoPort;
ds@1952
    98
	String m_AuthID;
ds@1952
    99
	AdminId m_Admin;
ds@1952
   100
	bool m_TempAdmin;
ds@1952
   101
	edict_t *m_pEdict;
ds@1952
   102
	IPlayerInfo *m_Info;
ds@1952
   103
	String m_LastPassword;
ds@1952
   104
	bool m_bAdminCheckSignalled;
ds@1952
   105
	int m_iIndex;
ds@1952
   106
	unsigned int m_LangId;
ds@1952
   107
	int m_UserId;
ds@1952
   108
};
ds@1952
   109
ds@1952
   110
class PlayerManager : 
ds@1952
   111
	public SMGlobalClass,
ds@1952
   112
	public IPlayerManager
ds@1952
   113
{
ds@1952
   114
	friend class CPlayer;
ds@1952
   115
public:
ds@1952
   116
	PlayerManager();
ds@1952
   117
	~PlayerManager();
ds@1952
   118
public: //SMGlobalClass
ds@1952
   119
	void OnSourceModAllInitialized();
ds@1952
   120
	void OnSourceModShutdown();
ds@1952
   121
	void OnSourceModLevelEnd();
ds@1952
   122
	ConfigResult OnSourceModConfigChanged(const char *key, const char *value, ConfigSource source, char *error, size_t maxlength);
ds@1952
   123
public:
ds@1952
   124
	CPlayer *GetPlayerByIndex(int client) const;
ds@1952
   125
	void RunAuthChecks();
ds@1952
   126
	void ClearAdminId(AdminId id);
ds@1952
   127
	void ClearAllAdmins();
ds@1952
   128
public:
ds@1952
   129
	bool OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
ds@1952
   130
	bool OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
ds@1952
   131
	void OnClientPutInServer(edict_t *pEntity, char const *playername);
ds@1952
   132
	void OnClientDisconnect(edict_t *pEntity);
ds@1952
   133
	void OnClientDisconnect_Post(edict_t *pEntity);
ds@1952
   134
#if defined ORANGEBOX_BUILD
ds@1952
   135
	void OnClientCommand(edict_t *pEntity, const CCommand &args);
ds@1952
   136
#else
ds@1952
   137
	void OnClientCommand(edict_t *pEntity);
ds@1952
   138
#endif
ds@1952
   139
	void OnClientSettingsChanged(edict_t *pEntity);
ds@1952
   140
	//void OnClientSettingsChanged_Pre(edict_t *pEntity);
ds@1952
   141
public: //IPlayerManager
ds@1952
   142
	void AddClientListener(IClientListener *listener);
ds@1952
   143
	void RemoveClientListener(IClientListener *listener);
ds@1952
   144
	IGamePlayer *GetGamePlayer(int client);
ds@1952
   145
	IGamePlayer *GetGamePlayer(edict_t *pEdict);
ds@1952
   146
	int GetMaxClients();
ds@1952
   147
	int GetNumPlayers();
ds@1952
   148
	int GetClientOfUserId(int userid);
ds@1952
   149
	bool IsServerActivated();
ds@1952
   150
	int FilterCommandTarget(IGamePlayer *pAdmin, IGamePlayer *pTarget, int flags);
ds@1952
   151
	int InternalFilterCommandTarget(CPlayer *pAdmin, CPlayer *pTarget, int flags);
ds@1952
   152
	void RegisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
ds@1952
   153
	void UnregisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
ds@1952
   154
	void ProcessCommandTarget(cmd_target_info_t *info);
ds@1952
   155
public:
ds@1952
   156
	inline int MaxClients()
ds@1952
   157
	{
ds@1952
   158
		return m_maxClients;
ds@1952
   159
	}
ds@1952
   160
	inline int NumPlayers()
ds@1952
   161
	{
ds@1952
   162
		return m_PlayerCount;
ds@1952
   163
	}
dvander@1996
   164
	inline int ListenClient()
dvander@1996
   165
	{
dvander@1996
   166
		return m_ListenClient;
dvander@1996
   167
	}
ds@1952
   168
	bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id);
ds@1952
   169
	bool CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id);
ds@1952
   170
	const char *GetPassInfoVar();
ds@1952
   171
	void RecheckAnyAdmins();
ds@1952
   172
	unsigned int GetReplyTo();
ds@1952
   173
	unsigned int SetReplyTo(unsigned int reply);
ds@1952
   174
private:
ds@1952
   175
	void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
ds@1952
   176
private:
ds@1952
   177
	List<IClientListener *> m_hooks;
ds@1952
   178
	IForward *m_clconnect;
ds@1952
   179
	IForward *m_cldisconnect;
ds@1952
   180
	IForward *m_cldisconnect_post;
ds@1952
   181
	IForward *m_clputinserver;
ds@1952
   182
	IForward *m_clcommand;
ds@1952
   183
	IForward *m_clinfochanged;
ds@1952
   184
	IForward *m_clauth;
ds@1952
   185
	IForward *m_onActivate;
ds@1952
   186
	IForward *m_onActivate2;
ds@1952
   187
	CPlayer *m_Players;
ds@1952
   188
	int *m_UserIdLookUp;
ds@1952
   189
	int m_maxClients;
ds@1952
   190
	int m_PlayerCount;
ds@1952
   191
	bool m_FirstPass;
ds@1952
   192
	unsigned int *m_AuthQueue;
ds@1952
   193
	String m_PassInfoVar;
ds@1952
   194
	bool m_QueryLang;
dvander@1996
   195
	bool m_bIsListenServer;
dvander@1996
   196
	int m_ListenClient;
ds@1952
   197
};
ds@1952
   198
ds@1952
   199
extern PlayerManager g_Players;
ds@1952
   200
extern bool g_OnMapStarted;
ds@1952
   201
extern const unsigned int *g_NumPlayersToAuth;
ds@1952
   202
ds@1952
   203
#endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_