mirror of
https://bitbucket.org/seefoe/src.git
synced 2026-09-11 21:45:09 -04:00
Added serverBase library
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
|
||||
add_subdirectory(serverBase)
|
||||
add_subdirectory(serverDatabase)
|
||||
add_subdirectory(serverGame)
|
||||
add_subdirectory(serverKeyShare)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(serverBase)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/public)
|
||||
|
||||
add_subdirectory(src)
|
||||
@@ -0,0 +1 @@
|
||||
#include "../../src/shared/core/ConfigServerBase.h"
|
||||
@@ -0,0 +1 @@
|
||||
#include "../../src/shared/FirstServerBase.h"
|
||||
@@ -0,0 +1 @@
|
||||
#include "../../src/shared/core/ServerBase.h"
|
||||
@@ -0,0 +1 @@
|
||||
#include "../../src/shared/core/ServerBaseImpl.h"
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
set(SHARED_SOURCES
|
||||
shared/FirstServerBase.h
|
||||
|
||||
shared/core/ServerBase.cpp
|
||||
shared/core/ServerBase.h
|
||||
shared/core/ConfigServerBase.cpp
|
||||
shared/core/ConfigServerBase.h
|
||||
shared/core/ServerBaseImpl.cpp
|
||||
shared/core/ServerBaseImpl.h
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shared
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDebug/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundation/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedLog/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMemoryManager/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMessageDispatch/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedNetwork/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedNetworkMessages/include/public
|
||||
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/archive/include
|
||||
)
|
||||
|
||||
add_library(serverBase STATIC
|
||||
${SHARED_SOURCES}
|
||||
${PLATFORM_SOURCES}
|
||||
)
|
||||
@@ -0,0 +1,32 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// FirstServerBase.h
|
||||
// copyright (c) 2004 Sony Online Entertainment
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef INCLUDED_FirstServerBase_H
|
||||
#define INCLUDED_FirstServerBase_H
|
||||
|
||||
// ======================================================================
|
||||
|
||||
#include "sharedFoundation/FirstSharedFoundation.h"
|
||||
#include "sharedNetworkMessages/GameNetworkMessage.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#ifdef WIN32
|
||||
// need to boost type_info into the std namespace, as the boost libraries expect it.
|
||||
#include <typeinfo>
|
||||
namespace std
|
||||
{
|
||||
typedef ::type_info type_info; //lint !e36 !e18 // error 36: (Error -- redefining the storage class of symbol '_STL::type_info' (type vs. using declaration), conflicts with line 47, file D:\work\swg\current\src\external\3rd\library\stlport453\stlport\typeinfo) // error 18: (Error -- Symbol '_STL::type_info' redeclared (void/nonvoid) conflicts with line 47, file D:\work\swg\current\src\external\3rd\library\stlport453\stlport\typeinfo) // @todo: look into this.
|
||||
};
|
||||
#endif
|
||||
|
||||
// ======================================================================
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// ConfigServerBase.cpp
|
||||
// Copyright 2004, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Doug Mellencamp
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "serverBase/FirstServerBase.h"
|
||||
#include "sharedFoundation/ConfigFile.h"
|
||||
#include "ConfigServerBase.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ConfigServerBase::Data * ConfigServerBase::data = 0;
|
||||
|
||||
#define KEY_INT(a,b) (data->a = ConfigFile::getKeyInt("GameServer", #a, b))
|
||||
#define KEY_BOOL(a,b) (data->a = ConfigFile::getKeyBool("GameServer", #a, b))
|
||||
#define KEY_FLOAT(a,b) (data->a = ConfigFile::getKeyFloat("GameServer", #a, b))
|
||||
#define KEY_STRING(a,b) (data->a = ConfigFile::getKeyString("GameServer", #a, b))
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ConfigServerBase::install(void)
|
||||
{
|
||||
data = new ConfigServerBase::Data;
|
||||
|
||||
KEY_STRING (serverName, "BaseServer");
|
||||
KEY_INT (sleepTimePerFrameMs, 10);
|
||||
KEY_INT (defaultFrameRateLimit, 10);
|
||||
KEY_BOOL (showAllDebugInfo, true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
const char * ConfigServerBase::getServerName()
|
||||
{
|
||||
return data->serverName;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int ConfigServerBase::getSleepTimePerFrameMs()
|
||||
{
|
||||
return data->sleepTimePerFrameMs;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int ConfigServerBase::getDefaultFrameRateLimit()
|
||||
{
|
||||
return data->defaultFrameRateLimit;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
void ConfigServerBase::remove(void)
|
||||
{
|
||||
delete data;
|
||||
data = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
const bool ConfigServerBase::getShowAllDebugInfo()
|
||||
{
|
||||
return (data->showAllDebugInfo);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@@ -0,0 +1,39 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// ConfigServerBase.h
|
||||
// Copyright 2004, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Doug Mellencamp
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef _ConfigServerBase_H
|
||||
#define _ConfigServerBase_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class ConfigServerBase
|
||||
{
|
||||
public:
|
||||
struct Data
|
||||
{
|
||||
const char * serverName;
|
||||
int sleepTimePerFrameMs;
|
||||
int defaultFrameRateLimit;
|
||||
bool showAllDebugInfo; // show detailed debugging logging info
|
||||
};
|
||||
|
||||
static const char * getServerName ();
|
||||
static int getSleepTimePerFrameMs ();
|
||||
static int getDefaultFrameRateLimit ();
|
||||
static const bool getShowAllDebugInfo ();
|
||||
|
||||
static void install ();
|
||||
static void remove ();
|
||||
|
||||
private:
|
||||
static Data * data;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#endif // _ConfigServerBase_H
|
||||
@@ -0,0 +1,156 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// ServerBase.cpp
|
||||
// Copyright 2005, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Doug Mellencamp
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include "serverBase/ServerBase.h"
|
||||
|
||||
#include "ServerBaseImpl.h"
|
||||
|
||||
//======================================================================
|
||||
|
||||
ServerBaseImpl *ServerBase::s_implementation = 0;
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void ServerBase::install ()
|
||||
{
|
||||
install(new ServerBaseImpl());
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void ServerBase::install (ServerBaseImpl* implementation)
|
||||
{
|
||||
REPORT_LOG(true, ("\t[serverBase] : ServerBase::install() - begin\n"));
|
||||
|
||||
DEBUG_FATAL (s_implementation, ("ServerBase already installed"));
|
||||
s_implementation = implementation;
|
||||
|
||||
ConfigServerBase::install();
|
||||
SetupSharedNetwork::SetupData networkSetupData;
|
||||
SetupSharedNetwork::getDefaultServerSetupData(networkSetupData);
|
||||
SetupSharedNetwork::install(networkSetupData);
|
||||
Os::setProgramName(ConfigServerBase::getServerName());
|
||||
NetworkHandler::install();
|
||||
char tmp[128] = {"\0"};
|
||||
IGNORE_RETURN(snprintf(tmp, sizeof(tmp), "%s:%d", ConfigServerBase::getServerName() ,Os::getProcessId()));
|
||||
SetupSharedLog::install(tmp);
|
||||
|
||||
ExitChain::add(remove, "ServerBase::remove");
|
||||
|
||||
REPORT_LOG(true, ("\t[serverBase] : ServerBase::install() - end\n"));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void ServerBase::remove ()
|
||||
{
|
||||
DEBUG_FATAL( !s_implementation, ("ServerBase implementation not set"));
|
||||
|
||||
REPORT_LOG(true, ("\t[serverBase] : ServerBase::remove.\n"));
|
||||
|
||||
SetupSharedLog::remove();
|
||||
NetworkHandler::remove();
|
||||
ConfigServerBase::remove();
|
||||
|
||||
delete s_implementation;
|
||||
s_implementation = 0;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
const uint32 ServerBase::getServerId()
|
||||
{
|
||||
DEBUG_FATAL( !s_implementation, ("ServerBase implementation not set"));
|
||||
return (s_implementation->getServerId());
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void ServerBase::setServerId(const uint32 id)
|
||||
{
|
||||
DEBUG_FATAL( !s_implementation, ("ServerBase implementation not set"));
|
||||
s_implementation->setServerId(id);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
bool ServerBase::isDone()
|
||||
{
|
||||
DEBUG_FATAL( !s_implementation, ("ServerBase implementation not set"));
|
||||
return(s_implementation->isDone());
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void ServerBase::setDone(const bool isDone)
|
||||
{
|
||||
DEBUG_FATAL( !s_implementation, ("ServerBase implementation not set"));
|
||||
s_implementation->setDone(isDone);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void ServerBase::setSleepTimePerFrameMs(int sleepTimePerFrameMs)
|
||||
{
|
||||
DEBUG_FATAL( !s_implementation, ("ServerBase implementation not set"));
|
||||
s_implementation->setSleepTimePerFrameMs(sleepTimePerFrameMs);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void ServerBase::run()
|
||||
{
|
||||
DEBUG_FATAL( !s_implementation, ("ServerBase implementation not set"));
|
||||
s_implementation->run();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void ServerBase::update(real time)
|
||||
{
|
||||
DEBUG_FATAL( !s_implementation, ("ServerBase implementation not set"));
|
||||
s_implementation->update(time);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void ServerBase::setupConnections()
|
||||
{
|
||||
DEBUG_FATAL( !s_implementation, ("ServerBase implementation not set"));
|
||||
s_implementation->setupConnections();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void ServerBase::unsetupConnections()
|
||||
{
|
||||
DEBUG_FATAL( !s_implementation, ("ServerBase implementation not set"));
|
||||
s_implementation->unsetupConnections();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void ServerBase::preMainLoopInit()
|
||||
{
|
||||
DEBUG_FATAL( !s_implementation, ("ServerBase implementation not set"));
|
||||
s_implementation->preMainLoopInit();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void ServerBase::postMainLoopCleanup()
|
||||
{
|
||||
DEBUG_FATAL( !s_implementation, ("ServerBase implementation not set"));
|
||||
s_implementation->postMainLoopCleanup();
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// ServerBase.h
|
||||
// Copyright 2005, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Doug Mellencamp
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef INCLUDED_ServerBase_H
|
||||
#define INCLUDED_ServerBase_H
|
||||
|
||||
#include "serverBase/FirstServerBase.h"
|
||||
#include "serverBase/ConfigServerBase.h"
|
||||
#include "sharedNetwork/SetupSharedNetwork.h"
|
||||
#include "sharedNetwork/NetworkHandler.h"
|
||||
#include "sharedDebug/Profiler.h"
|
||||
#include "sharedFoundation/Clock.h"
|
||||
#include "sharedFoundation/Os.h"
|
||||
#include "sharedFoundation/ExitChain.h"
|
||||
#include "sharedFoundation/Timer.h"
|
||||
#include "sharedLog/Log.h"
|
||||
#include "sharedLog/LogManager.h"
|
||||
#include "sharedLog/SetupSharedLog.h"
|
||||
|
||||
//======================================================================
|
||||
|
||||
class ServerBaseImpl;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class ServerBase
|
||||
{
|
||||
public:
|
||||
|
||||
static void install ();
|
||||
static void remove ();
|
||||
static const uint32 getServerId ();
|
||||
static void setServerId (const uint32 id);
|
||||
static bool isDone ();
|
||||
static void setDone (const bool isDone);
|
||||
static void setSleepTimePerFrameMs (int sleepTimePerFrameMs);
|
||||
static void run ();
|
||||
static void update (real time);
|
||||
static void setupConnections ();
|
||||
static void unsetupConnections ();
|
||||
static void preMainLoopInit ();
|
||||
static void postMainLoopCleanup ();
|
||||
|
||||
protected:
|
||||
|
||||
static void install ( ServerBaseImpl *impl );
|
||||
|
||||
static ServerBaseImpl* s_implementation;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//======================================================================
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,143 @@
|
||||
//======================================================================
|
||||
//
|
||||
// ServerBaseImpl.cpp
|
||||
// copyright (c) 2005 Sony Online Entertainment
|
||||
// Author: Doug Mellencamp
|
||||
//
|
||||
//======================================================================
|
||||
|
||||
#include "serverBase/ServerBaseImpl.h"
|
||||
|
||||
//======================================================================
|
||||
|
||||
namespace ServerBaseImplNamespace
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
using namespace ServerBaseImplNamespace;
|
||||
|
||||
//======================================================================
|
||||
|
||||
ServerBaseImpl::ServerBaseImpl() :
|
||||
m_serverId(0),
|
||||
m_done(false),
|
||||
m_sleepTimePerFrameMs(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
ServerBaseImpl::~ServerBaseImpl()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
const uint32 ServerBaseImpl::getServerId( void )
|
||||
{
|
||||
return m_serverId;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ServerBaseImpl::setServerId( const uint32 id )
|
||||
{
|
||||
m_serverId = id;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ServerBaseImpl::setDone(const bool done)
|
||||
{
|
||||
m_done = done;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool ServerBaseImpl::isDone()
|
||||
{
|
||||
return m_done;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ServerBaseImpl::run()
|
||||
{
|
||||
LOG("ServerStartup",("%s starting on %s", ConfigServerBase::getServerName(), NetworkHandler::getHostName().c_str())); // no process id yet
|
||||
|
||||
REPORT_LOG(true, ("\t[ServerBase] : ServerBaseImpl::run() - setting up connections.\n"));
|
||||
setupConnections();
|
||||
|
||||
REPORT_LOG(true, ("\t[ServerBase] : ServerBaseImpl::run() - Performing pre main loop initializations.\n"));
|
||||
preMainLoopInit();
|
||||
|
||||
REPORT_LOG(true, ("\t[ServerBase] : ServerBaseImpl::run() - Entering main loop.\n"));
|
||||
PROFILER_BLOCK_DEFINE(profileBlockMainLoop, "main loop");
|
||||
PROFILER_BLOCK_ENTER(profileBlockMainLoop);
|
||||
|
||||
while (!isDone())
|
||||
{
|
||||
NetworkHandler::update();
|
||||
NetworkHandler::dispatch();
|
||||
update(time(0));
|
||||
NetworkHandler::clearBytesThisFrame();
|
||||
Os::sleep(m_sleepTimePerFrameMs);
|
||||
}
|
||||
|
||||
PROFILER_BLOCK_LEAVE(profileBlockMainLoop);
|
||||
|
||||
REPORT_LOG(true, ("\t[ServerBase] : ServerBaseImpl::run() - Performing post main loop cleanup.\n"));
|
||||
postMainLoopCleanup();
|
||||
|
||||
REPORT_LOG(true, ("\t[ServerBase] : ServerBaseImpl::run() - un setting up connections.\n"));
|
||||
unsetupConnections();
|
||||
|
||||
LOG("ServerStartup",("%s %lu exiting", ConfigServerBase::getServerName(), Os::getProcessId()));
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ServerBaseImpl::setupConnections()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ServerBaseImpl::unsetupConnections ()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ServerBaseImpl::preMainLoopInit()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ServerBaseImpl::postMainLoopCleanup ()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ServerBaseImpl::update(real time)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
void ServerBaseImpl::setSleepTimePerFrameMs(int sleepTimePerFrameMs)
|
||||
{
|
||||
m_sleepTimePerFrameMs = sleepTimePerFrameMs;
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
//======================================================================
|
||||
//
|
||||
// ServerBaseImpl.h
|
||||
// copyright (c) 2005 Sony Online Entertainment
|
||||
// Author: Doug Mellencamp
|
||||
//
|
||||
//======================================================================
|
||||
|
||||
#ifndef INCLUDED_ServerBaseImpl_H
|
||||
#define INCLUDED_ServerBaseImpl_H
|
||||
|
||||
//======================================================================
|
||||
|
||||
#include "serverBase/FirstServerBase.h"
|
||||
#include "serverBase/ConfigServerBase.h"
|
||||
#include "sharedNetwork/SetupSharedNetwork.h"
|
||||
#include "sharedNetwork/NetworkHandler.h"
|
||||
#include "sharedDebug/Profiler.h"
|
||||
#include "sharedFoundation/Clock.h"
|
||||
#include "sharedFoundation/Os.h"
|
||||
#include "sharedFoundation/ExitChain.h"
|
||||
#include "sharedFoundation/Timer.h"
|
||||
#include "sharedLog/Log.h"
|
||||
#include "sharedLog/LogManager.h"
|
||||
#include "sharedLog/SetupSharedLog.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class ServerBaseImpl
|
||||
{
|
||||
public:
|
||||
ServerBaseImpl();
|
||||
virtual ~ServerBaseImpl();
|
||||
|
||||
// All implementations of ServerBase interface are here as public methods
|
||||
public:
|
||||
|
||||
virtual const uint32 getServerId ();
|
||||
virtual void setServerId (const uint32 id);
|
||||
virtual bool isDone ();
|
||||
virtual void setDone (const bool isDone);
|
||||
virtual void setSleepTimePerFrameMs (int sleepTimePerFrameMs);
|
||||
virtual void run ();
|
||||
virtual void update (real time);
|
||||
virtual void setupConnections ();
|
||||
virtual void unsetupConnections ();
|
||||
virtual void preMainLoopInit ();
|
||||
virtual void postMainLoopCleanup ();
|
||||
|
||||
|
||||
// all implementation details are here as protected members, so subclasses have full access.
|
||||
protected:
|
||||
|
||||
uint32 m_serverId;
|
||||
bool m_done;
|
||||
int m_sleepTimePerFrameMs;
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user