From aebef8d9f505da21a44f705c0bab679189edc174 Mon Sep 17 00:00:00 2001 From: Anonymous Date: Tue, 21 Jan 2014 06:08:34 -0700 Subject: [PATCH] Added ServerConsole application --- engine/server/application/CMakeLists.txt | 1 + .../application/ServerConsole/CMakeLists.txt | 6 ++ .../ServerConsole/src/CMakeLists.txt | 66 ++++++++++++++ .../ServerConsole/src/linux/main.cpp | 60 +++++++++++++ .../src/shared/ConfigServerConsole.cpp | 68 ++++++++++++++ .../src/shared/ConfigServerConsole.h | 29 ++++++ .../src/shared/FirstServerConsole.cpp | 9 ++ .../src/shared/FirstServerConsole.h | 14 +++ .../src/shared/ServerConsole.cpp | 89 +++++++++++++++++++ .../ServerConsole/src/shared/ServerConsole.h | 26 ++++++ .../src/shared/ServerConsoleConnection.cpp | 69 ++++++++++++++ .../src/shared/ServerConsoleConnection.h | 34 +++++++ .../ServerConsole/src/win32/main.cpp | 59 ++++++++++++ 13 files changed, 530 insertions(+) create mode 100644 engine/server/application/ServerConsole/CMakeLists.txt create mode 100644 engine/server/application/ServerConsole/src/CMakeLists.txt create mode 100644 engine/server/application/ServerConsole/src/linux/main.cpp create mode 100644 engine/server/application/ServerConsole/src/shared/ConfigServerConsole.cpp create mode 100644 engine/server/application/ServerConsole/src/shared/ConfigServerConsole.h create mode 100644 engine/server/application/ServerConsole/src/shared/FirstServerConsole.cpp create mode 100644 engine/server/application/ServerConsole/src/shared/FirstServerConsole.h create mode 100644 engine/server/application/ServerConsole/src/shared/ServerConsole.cpp create mode 100644 engine/server/application/ServerConsole/src/shared/ServerConsole.h create mode 100644 engine/server/application/ServerConsole/src/shared/ServerConsoleConnection.cpp create mode 100644 engine/server/application/ServerConsole/src/shared/ServerConsoleConnection.h create mode 100644 engine/server/application/ServerConsole/src/win32/main.cpp diff --git a/engine/server/application/CMakeLists.txt b/engine/server/application/CMakeLists.txt index e4b54b09..0cc28aff 100644 --- a/engine/server/application/CMakeLists.txt +++ b/engine/server/application/CMakeLists.txt @@ -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) diff --git a/engine/server/application/ServerConsole/CMakeLists.txt b/engine/server/application/ServerConsole/CMakeLists.txt new file mode 100644 index 00000000..d71a8286 --- /dev/null +++ b/engine/server/application/ServerConsole/CMakeLists.txt @@ -0,0 +1,6 @@ + +cmake_minimum_required(VERSION 2.8) + +project(ServerConsole) + +add_subdirectory(src) diff --git a/engine/server/application/ServerConsole/src/CMakeLists.txt b/engine/server/application/ServerConsole/src/CMakeLists.txt new file mode 100644 index 00000000..b114e829 --- /dev/null +++ b/engine/server/application/ServerConsole/src/CMakeLists.txt @@ -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() diff --git a/engine/server/application/ServerConsole/src/linux/main.cpp b/engine/server/application/ServerConsole/src/linux/main.cpp new file mode 100644 index 00000000..a5e291a0 --- /dev/null +++ b/engine/server/application/ServerConsole/src/linux/main.cpp @@ -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; +} + +//----------------------------------------------------------------------- + diff --git a/engine/server/application/ServerConsole/src/shared/ConfigServerConsole.cpp b/engine/server/application/ServerConsole/src/shared/ConfigServerConsole.cpp new file mode 100644 index 00000000..53955275 --- /dev/null +++ b/engine/server/application/ServerConsole/src/shared/ConfigServerConsole.cpp @@ -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(serverPort); +} + +//----------------------------------------------------------------------- + +void ConfigServerConsole::install() +{ + KEY_STRING(serverAddress, "127.0.0.1"); + KEY_INT(serverPort, 61000); +} + +//----------------------------------------------------------------------- + +void ConfigServerConsole::remove() +{ +} + +//----------------------------------------------------------------------- + diff --git a/engine/server/application/ServerConsole/src/shared/ConfigServerConsole.h b/engine/server/application/ServerConsole/src/shared/ConfigServerConsole.h new file mode 100644 index 00000000..d1e84199 --- /dev/null +++ b/engine/server/application/ServerConsole/src/shared/ConfigServerConsole.h @@ -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 diff --git a/engine/server/application/ServerConsole/src/shared/FirstServerConsole.cpp b/engine/server/application/ServerConsole/src/shared/FirstServerConsole.cpp new file mode 100644 index 00000000..76529478 --- /dev/null +++ b/engine/server/application/ServerConsole/src/shared/FirstServerConsole.cpp @@ -0,0 +1,9 @@ +// FirstServerConsole.cpp +// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved. +// Author: Justin Randall + +//----------------------------------------------------------------------- + +#include "FirstServerConsole.h" + +//----------------------------------------------------------------------- diff --git a/engine/server/application/ServerConsole/src/shared/FirstServerConsole.h b/engine/server/application/ServerConsole/src/shared/FirstServerConsole.h new file mode 100644 index 00000000..7d8c22ed --- /dev/null +++ b/engine/server/application/ServerConsole/src/shared/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 diff --git a/engine/server/application/ServerConsole/src/shared/ServerConsole.cpp b/engine/server/application/ServerConsole/src/shared/ServerConsole.cpp new file mode 100644 index 00000000..28a8a888 --- /dev/null +++ b/engine/server/application/ServerConsole/src/shared/ServerConsole.cpp @@ -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 +#include + +//----------------------------------------------------------------------- + +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"); + } + } +} + +//----------------------------------------------------------------------- + diff --git a/engine/server/application/ServerConsole/src/shared/ServerConsole.h b/engine/server/application/ServerConsole/src/shared/ServerConsole.h new file mode 100644 index 00000000..025b6ec0 --- /dev/null +++ b/engine/server/application/ServerConsole/src/shared/ServerConsole.h @@ -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 diff --git a/engine/server/application/ServerConsole/src/shared/ServerConsoleConnection.cpp b/engine/server/application/ServerConsole/src/shared/ServerConsoleConnection.cpp new file mode 100644 index 00000000..1816a580 --- /dev/null +++ b/engine/server/application/ServerConsole/src/shared/ServerConsoleConnection.cpp @@ -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); +} + +//----------------------------------------------------------------------- + diff --git a/engine/server/application/ServerConsole/src/shared/ServerConsoleConnection.h b/engine/server/application/ServerConsole/src/shared/ServerConsoleConnection.h new file mode 100644 index 00000000..9a881141 --- /dev/null +++ b/engine/server/application/ServerConsole/src/shared/ServerConsoleConnection.h @@ -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 diff --git a/engine/server/application/ServerConsole/src/win32/main.cpp b/engine/server/application/ServerConsole/src/win32/main.cpp new file mode 100644 index 00000000..3de57087 --- /dev/null +++ b/engine/server/application/ServerConsole/src/win32/main.cpp @@ -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; +} + +//----------------------------------------------------------------------- +