2017-08-08 13:53:47 +02:00
|
|
|
#ifndef __GAMESERVER_H
|
|
|
|
#define __GAMESERVER_H
|
|
|
|
|
2018-03-06 22:22:19 +01:00
|
|
|
#include <Common.h>
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
#include <mutex>
|
|
|
|
#include <map>
|
2018-09-09 23:56:22 +02:00
|
|
|
#include "ForwardsZone.h"
|
2018-12-22 22:25:03 +01:00
|
|
|
#include "Manager/BaseManager.h"
|
2018-09-09 23:56:22 +02:00
|
|
|
|
2018-12-22 22:25:03 +01:00
|
|
|
namespace Sapphire::World
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-12-22 22:25:03 +01:00
|
|
|
class ServerMgr : public Manager::BaseManager
|
2018-11-29 16:55:48 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-12-22 22:25:03 +01:00
|
|
|
ServerMgr( const std::string& configName, FrameworkPtr pFw );
|
2018-11-29 16:55:48 +01:00
|
|
|
|
2018-12-22 22:25:03 +01:00
|
|
|
~ServerMgr() override;
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void run( int32_t argc, char* argv[] );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
bool createSession( uint32_t sessionId );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void removeSession( uint32_t sessionId );
|
|
|
|
void removeSession( const std::string& playerName );
|
2017-10-01 17:58:11 +02:00
|
|
|
|
2018-12-22 22:25:03 +01:00
|
|
|
World::SessionPtr getSession( uint32_t id );
|
|
|
|
World::SessionPtr getSession( const std::string& playerName );
|
2017-10-03 12:09:51 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
size_t getSessionCount() const;
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint16_t getWorldId() const;
|
|
|
|
void setWorldId( uint16_t worldId );
|
2018-11-14 09:22:17 +01:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void mainLoop();
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
bool isRunning() const;
|
2017-10-01 17:58:11 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void printBanner() const;
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
bool loadSettings( int32_t argc, char* argv[] );
|
|
|
|
void loadBNpcTemplates();
|
2018-09-09 23:56:22 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
Entity::BNpcTemplatePtr getBNpcTemplate( const std::string& key );
|
|
|
|
Entity::BNpcTemplatePtr getBNpcTemplate( uint32_t id );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
std::string getPlayerNameFromDb( uint32_t playerId, bool forceDbLoad = false );
|
|
|
|
void updatePlayerName( uint32_t playerId, const std::string& playerNewName );
|
2018-11-13 00:03:09 +01:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
private:
|
|
|
|
uint16_t m_port;
|
|
|
|
std::string m_ip;
|
|
|
|
int64_t m_lastDBPingTime;
|
|
|
|
bool m_bRunning;
|
|
|
|
uint16_t m_worldId;
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
std::string m_configName;
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
std::mutex m_sessionMutex;
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
std::map< uint32_t, SessionPtr > m_sessionMapById;
|
|
|
|
std::map< std::string, SessionPtr > m_sessionMapByName;
|
|
|
|
std::map< uint32_t, std::string > m_playerNameMapById;
|
|
|
|
std::map< uint32_t, uint32_t > m_zones;
|
|
|
|
std::map< std::string, Entity::BNpcTemplatePtr > m_bNpcTemplateMap;
|
2018-09-09 23:56:22 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
};
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|