Added ServerConsole application

This commit is contained in:
Anonymous
2014-01-21 06:08:34 -07:00
parent 24eb9956f8
commit aebef8d9f5
13 changed files with 530 additions and 0 deletions
+1
View File
@@ -7,5 +7,6 @@ add_subdirectory(LoginPing)
add_subdirectory(LoginServer)
add_subdirectory(MetricsServer)
add_subdirectory(PlanetServer)
add_subdirectory(ServerConsole)
add_subdirectory(TaskManager)
add_subdirectory(TransferServer)
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 2.8)
project(ServerConsole)
add_subdirectory(src)
@@ -0,0 +1,66 @@
set(SHARED_SOURCES
shared/ConfigServerConsole.cpp
shared/ConfigServerConsole.h
shared/FirstServerConsole.cpp
shared/FirstServerConsole.h
shared/ServerConsoleConnection.cpp
shared/ServerConsoleConnection.h
shared/ServerConsole.cpp
shared/ServerConsole.h
)
if(WIN32)
set(PLATFORM_SOURCES
win32/main.cpp
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/win32)
else()
set(PLATFORM_SOURCES
linux/main.cpp
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/linux)
endif()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/shared
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedCompression/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDebug/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFile/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/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_ENGINE_SOURCE_DIR}/shared/library/sharedThread/include/public
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/archive/include
)
link_directories(${STLPORT_LIBDIR})
add_executable(ServerConsole
${SHARED_SOURCES}
${PLATFORM_SOURCES}
)
target_link_libraries(ServerConsole
sharedCompression
sharedDebug
sharedFile
sharedFoundation
sharedMemoryManager
sharedMessageDispatch
sharedNetwork
sharedNetworkMessages
sharedThread
${STLPORT_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS}
)
if(WIN32)
target_link_libraries(ServerConsole mswsock ws2_32)
endif()
@@ -0,0 +1,60 @@
// main.cpp
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
//-----------------------------------------------------------------------
#include "FirstServerConsole.h"
#include "sharedFoundation/FirstSharedFoundation.h"
#include "sharedCompression/SetupSharedCompression.h"
#include "sharedDebug/SetupSharedDebug.h"
#include "sharedFile/SetupSharedFile.h"
#include "sharedFoundation/ConfigFile.h"
#include "sharedFoundation/Os.h"
#include "sharedFoundation/SetupSharedFoundation.h"
#include "sharedNetwork/SetupSharedNetwork.h"
#include "sharedNetwork/NetworkHandler.h"
#include "sharedNetworkMessages/SetupSharedNetworkMessages.h"
#include "sharedThread/SetupSharedThread.h"
#include "ServerConsole.h"
#include "ConfigServerConsole.h"
//-----------------------------------------------------------------------
int main(int argc, char ** argv)
{
SetupSharedThread::install();
SetupSharedDebug::install(1024);
//-- setup foundation
SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game);
setupFoundationData.argc = argc;
setupFoundationData.argv = argv;
setupFoundationData.runInBackground = true;
SetupSharedFoundation::install (setupFoundationData);
SetupSharedCompression::install();
SetupSharedNetworkMessages::install();
SetupSharedNetwork::SetupData networkSetupData;
SetupSharedNetwork::getDefaultServerSetupData(networkSetupData);
SetupSharedNetwork::install(networkSetupData);
NetworkHandler::install();
Os::setProgramName("ServerConsole");
ConfigServerConsole::install();
//-- run server
SetupSharedFoundation::callbackWithExceptionHandling(ServerConsole::run);
NetworkHandler::remove();
SetupSharedFoundation::remove();
SetupSharedThread::remove();
return 0;
}
//-----------------------------------------------------------------------
@@ -0,0 +1,68 @@
// ConfigServerConsole.cpp
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
//-----------------------------------------------------------------------
#include "FirstServerConsole.h"
#include "sharedFoundation/ConfigFile.h"
#include "ConfigServerConsole.h"
//-----------------------------------------------------------------------
namespace ConfigServerConsoleNamespace
{
const char * serverAddress;
int serverPort;
}
using namespace ConfigServerConsoleNamespace;
#define KEY_INT(a,b) (a = ConfigFile::getKeyInt("ServerConsole", #a, b))
#define KEY_BOOL(a,b) (a = ConfigFile::getKeyBool("ServerConsole", #a, b))
// #define KEY_REAL(a,b) (data->a = ConfigFile::getKeyReal("LoginServer", #a, b))
#define KEY_STRING(a,b) (a = ConfigFile::getKeyString("ServerConsole", #a, b))
//-----------------------------------------------------------------------
ConfigServerConsole::ConfigServerConsole()
{
}
//-----------------------------------------------------------------------
ConfigServerConsole::~ConfigServerConsole()
{
}
//-----------------------------------------------------------------------
const char * const ConfigServerConsole::getServerAddress()
{
return serverAddress;
}
//-----------------------------------------------------------------------
unsigned short ConfigServerConsole::getServerPort()
{
return static_cast<unsigned short>(serverPort);
}
//-----------------------------------------------------------------------
void ConfigServerConsole::install()
{
KEY_STRING(serverAddress, "127.0.0.1");
KEY_INT(serverPort, 61000);
}
//-----------------------------------------------------------------------
void ConfigServerConsole::remove()
{
}
//-----------------------------------------------------------------------
@@ -0,0 +1,29 @@
// ConfigServerConsole.h
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
#ifndef _INCLUDED_ConfigServerConsole_H
#define _INCLUDED_ConfigServerConsole_H
//-----------------------------------------------------------------------
class ConfigServerConsole
{
public:
ConfigServerConsole();
~ConfigServerConsole();
static const char * const getServerAddress ();
static unsigned short getServerPort ();
static void install();
static void remove();
private:
ConfigServerConsole & operator = (const ConfigServerConsole & rhs);
ConfigServerConsole(const ConfigServerConsole & source);
};
//-----------------------------------------------------------------------
#endif // _INCLUDED_ConfigServerConsole_H
@@ -0,0 +1,9 @@
// FirstServerConsole.cpp
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
//-----------------------------------------------------------------------
#include "FirstServerConsole.h"
//-----------------------------------------------------------------------
@@ -0,0 +1,14 @@
// FirstServerConsole.h
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
#ifndef _INCLUDED_FirstServerConsole_H
#define _INCLUDED_FirstServerConsole_H
//-----------------------------------------------------------------------
#include "sharedFoundation/FirstSharedFoundation.h"
//-----------------------------------------------------------------------
#endif // _INCLUDED_FirstServerConsole_H
@@ -0,0 +1,89 @@
// ServerConsole.cpp
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
//-----------------------------------------------------------------------
#include "FirstServerConsole.h"
#include "ConfigServerConsole.h"
#include "sharedFoundation/Os.h"
#include "sharedNetwork/Connection.h"
#include "sharedNetworkMessages/ConsoleChannelMessages.h"
#include "ServerConsole.h"
#include "ServerConsoleConnection.h"
#include <cstdio>
#include <string>
//-----------------------------------------------------------------------
namespace ServerConsoleNamespace
{
ServerConsoleConnection * s_serverConnection = 0;
bool s_done = false;
}
using namespace ServerConsoleNamespace;
//-----------------------------------------------------------------------
ServerConsole::ServerConsole()
{
}
//-----------------------------------------------------------------------
ServerConsole::~ServerConsole()
{
}
//-----------------------------------------------------------------------
void ServerConsole::done()
{
s_done = true;
}
//-----------------------------------------------------------------------
void ServerConsole::run()
{
if(!ConfigServerConsole::getServerAddress())
return;
if(!ConfigServerConsole::getServerPort())
return;
if(stdin)
{
std::string input;
char inBuf[1024] = {"\0"};
while(! feof(stdin))
{
fread(inBuf, 1024, 1, stdin);
input += inBuf;
memset(inBuf, 0, sizeof(inBuf));
}
if(input.length() > 0)
{
// connect to the server
s_serverConnection = new ServerConsoleConnection(ConfigServerConsole::getServerAddress(), ConfigServerConsole::getServerPort());
ConGenericMessage msg(input);
s_serverConnection->send(msg);
while(! s_done)
{
NetworkHandler::update();
NetworkHandler::dispatch();
Os::sleep(1);
}
}
else
{
fprintf(stderr, "Nothing to send to the server. Aborting");
}
}
}
//-----------------------------------------------------------------------
@@ -0,0 +1,26 @@
// ServerConsole.h
// Copyright 2000-03, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
#ifndef _INCLUDED_ServerConsole_H
#define _INCLUDED_ServerConsole_H
//-----------------------------------------------------------------------
class ServerConsole
{
public:
ServerConsole();
~ServerConsole();
static void run();
static void done();
private:
ServerConsole & operator = (const ServerConsole & rhs);
ServerConsole(const ServerConsole & source);
};
//-----------------------------------------------------------------------
#endif // _INCLUDED_ServerConsole_H
@@ -0,0 +1,69 @@
// ServerConsoleConnection.cpp
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
//-----------------------------------------------------------------------
#include "FirstServerConsole.h"
#include "ServerConsole.h"
#include "ServerConsoleConnection.h"
#include "sharedNetwork/NetworkSetupData.h"
#include "sharedNetworkMessages/ConsoleChannelMessages.h"
//-----------------------------------------------------------------------
ServerConsoleConnection::ServerConsoleConnection(const std::string & address, const unsigned short port) :
Connection(address, port, NetworkSetupData())
{
}
//-----------------------------------------------------------------------
ServerConsoleConnection::~ServerConsoleConnection()
{
}
//-----------------------------------------------------------------------
void ServerConsoleConnection::onConnectionClosed()
{
ServerConsole::done();
}
//-----------------------------------------------------------------------
void ServerConsoleConnection::onConnectionOpened()
{
}
//-----------------------------------------------------------------------
void ServerConsoleConnection::onReceive(const Archive::ByteStream & bs)
{
Archive::ReadIterator ri = bs.begin();
GameNetworkMessage m(ri);
ri = bs.begin();
if(m.isType("ConGenericMessage"))
{
ConGenericMessage msg(ri);
fprintf(stdout, "%s", msg.getMsg().c_str());
}
else if(m.isType("RequestDisconnect"))
{
disconnect();
}
}
//-----------------------------------------------------------------------
void ServerConsoleConnection::send(const GameNetworkMessage & msg)
{
Archive::ByteStream bs;
msg.pack(bs);
Connection::send(bs, true);
}
//-----------------------------------------------------------------------
@@ -0,0 +1,34 @@
// ServerConsoleConnection.h
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
#ifndef _INCLUDED_ServerConsoleConnection_H
#define _INCLUDED_ServerConsoleConnection_H
//-----------------------------------------------------------------------
#include "sharedNetwork/Connection.h"
#include "sharedNetworkMessages/GameNetworkMessage.h"
//-----------------------------------------------------------------------
class ServerConsoleConnection : public Connection
{
public:
ServerConsoleConnection(const std::string & address, const unsigned short port);
~ServerConsoleConnection();
void onConnectionClosed ();
void onConnectionOpened ();
void onReceive (const Archive::ByteStream & bs);
void send (const GameNetworkMessage &);
private:
ServerConsoleConnection & operator = (const ServerConsoleConnection & rhs);
ServerConsoleConnection(const ServerConsoleConnection & source);
};
//-----------------------------------------------------------------------
#endif // _INCLUDED_ServerConsoleConnection_H
@@ -0,0 +1,59 @@
// main.cpp
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
//-----------------------------------------------------------------------
#include "FirstServerConsole.h"
#include "sharedFoundation/FirstSharedFoundation.h"
#include "sharedCompression/SetupSharedCompression.h"
#include "sharedDebug/SetupSharedDebug.h"
#include "sharedFile/SetupSharedFile.h"
#include "sharedFoundation/ConfigFile.h"
#include "sharedFoundation/SetupSharedFoundation.h"
#include "sharedNetwork/SetupSharedNetwork.h"
#include "sharedNetwork/NetworkHandler.h"
#include "sharedNetworkMessages/SetupSharedNetworkMessages.h"
#include "sharedThread/SetupSharedThread.h"
#include "ServerConsole.h"
#include "ConfigServerConsole.h"
//-----------------------------------------------------------------------
int main(int argc, char ** argv)
{
SetupSharedThread::install();
SetupSharedDebug::install(1024);
//-- setup foundation
SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game);
setupFoundationData.argc = argc;
setupFoundationData.argv = argv;
setupFoundationData.clockUsesSleep = true;
setupFoundationData.createWindow = false;
SetupSharedFoundation::install (setupFoundationData);
SetupSharedCompression::install();
SetupSharedNetworkMessages::install();
SetupSharedNetwork::SetupData networkSetupData;
SetupSharedNetwork::getDefaultClientSetupData(networkSetupData);
SetupSharedNetwork::install(networkSetupData);
NetworkHandler::install();
ConfigServerConsole::install();
//-- run server
SetupSharedFoundation::callbackWithExceptionHandling(ServerConsole::run);
NetworkHandler::remove();
SetupSharedFoundation::remove();
SetupSharedThread::remove();
return 0;
}
//-----------------------------------------------------------------------