aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/server/playerinfomanager.cpp
diff options
context:
space:
mode:
authorJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
committerJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
commit39ed87570bdb2f86969d4be821c94b722dc71179 (patch)
treeabc53757f75f40c80278e87650ea92808274aa59 /mp/src/game/server/playerinfomanager.cpp
downloadsource-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz
source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip
First version of the SOurce SDK 2013
Diffstat (limited to 'mp/src/game/server/playerinfomanager.cpp')
-rw-r--r--mp/src/game/server/playerinfomanager.cpp134
1 files changed, 134 insertions, 0 deletions
diff --git a/mp/src/game/server/playerinfomanager.cpp b/mp/src/game/server/playerinfomanager.cpp
new file mode 100644
index 00000000..798f6c74
--- /dev/null
+++ b/mp/src/game/server/playerinfomanager.cpp
@@ -0,0 +1,134 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: implementation of player info manager
+//
+//=============================================================================//
+
+#include "cbase.h"
+#include "player.h"
+#include "playerinfomanager.h"
+#include "edict.h"
+
+extern CGlobalVars *gpGlobals;
+static CPlayerInfoManager s_PlayerInfoManager;
+static CPluginBotManager s_BotManager;
+
+namespace
+{
+
+ //
+ // Old version support
+ //
+ abstract_class IPlayerInfo_V1
+ {
+ public:
+ // returns the players name (UTF-8 encoded)
+ virtual const char *GetName() = 0;
+ // returns the userid (slot number)
+ virtual int GetUserID() = 0;
+ // returns the string of their network (i.e Steam) ID
+ virtual const char *GetNetworkIDString() = 0;
+ // returns the team the player is on
+ virtual int GetTeamIndex() = 0;
+ // changes the player to a new team (if the game dll logic allows it)
+ virtual void ChangeTeam( int iTeamNum ) = 0;
+ // returns the number of kills this player has (exact meaning is mod dependent)
+ virtual int GetFragCount() = 0;
+ // returns the number of deaths this player has (exact meaning is mod dependent)
+ virtual int GetDeathCount() = 0;
+ // returns if this player slot is actually valid
+ virtual bool IsConnected() = 0;
+ // returns the armor/health of the player (exact meaning is mod dependent)
+ virtual int GetArmorValue() = 0;
+ };
+
+ abstract_class IPlayerInfoManager_V1
+ {
+ public:
+ virtual IPlayerInfo_V1 *GetPlayerInfo( edict_t *pEdict ) = 0;
+ };
+
+
+ class CPlayerInfoManager_V1: public IPlayerInfoManager_V1
+ {
+ public:
+ virtual IPlayerInfo_V1 *GetPlayerInfo( edict_t *pEdict );
+ };
+
+ static CPlayerInfoManager_V1 s_PlayerInfoManager_V1;
+
+
+ IPlayerInfo_V1 *CPlayerInfoManager_V1::GetPlayerInfo( edict_t *pEdict )
+ {
+ CBasePlayer *pPlayer = ( ( CBasePlayer * )CBaseEntity::Instance( pEdict ));
+ if ( pPlayer )
+ {
+ return (IPlayerInfo_V1 *)pPlayer->GetPlayerInfo();
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+
+ EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CPlayerInfoManager_V1, IPlayerInfoManager_V1, "PlayerInfoManager001", s_PlayerInfoManager_V1);
+}
+
+IPlayerInfo *CPlayerInfoManager::GetPlayerInfo( edict_t *pEdict )
+{
+ CBasePlayer *pPlayer = ( ( CBasePlayer * )CBaseEntity::Instance( pEdict ));
+ if ( pPlayer )
+ {
+ return pPlayer->GetPlayerInfo();
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+CGlobalVars *CPlayerInfoManager::GetGlobalVars()
+{
+ return gpGlobals;
+}
+
+
+
+IBotController *CPluginBotManager::GetBotController( edict_t *pEdict )
+{
+ CBasePlayer *pPlayer = ( ( CBasePlayer * )CBaseEntity::Instance( pEdict ));
+ if ( pPlayer && pPlayer->IsBot() )
+ {
+ return pPlayer->GetBotController();
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+edict_t *CPluginBotManager::CreateBot( const char *botname )
+{
+ edict_t *pEdict = engine->CreateFakeClient( botname );
+ if (!pEdict)
+ {
+ Msg( "Failed to create Bot.\n");
+ return NULL;
+ }
+
+ // Allocate a player entity for the bot, and call spawn
+ CBasePlayer *pPlayer = ((CBasePlayer*)CBaseEntity::Instance( pEdict ));
+
+ pPlayer->ClearFlags();
+ pPlayer->AddFlag( FL_CLIENT | FL_FAKECLIENT );
+
+ pPlayer->ChangeTeam( TEAM_UNASSIGNED );
+ pPlayer->RemoveAllItems( true );
+ pPlayer->Spawn();
+
+ return pEdict;
+}
+
+EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CPlayerInfoManager, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER, s_PlayerInfoManager);
+EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CPluginBotManager, IBotManager, INTERFACEVERSION_PLAYERBOTMANAGER, s_BotManager);
+