From 1c391034f94bc565a9a13d39c6fa8c1f3c95db28 Mon Sep 17 00:00:00 2001 From: Anonymous Date: Tue, 21 Jan 2014 05:45:19 -0700 Subject: [PATCH] Added LoginPing project --- engine/server/application/CMakeLists.txt | 3 +- .../application/LoginPing/CMakeLists.txt | 6 ++ .../application/LoginPing/src/CMakeLists.txt | 79 +++++++++++++++ .../LoginPing/src/linux/checkLoginServer.sh | 8 ++ .../LoginPing/src/linux/loginPing.cfg | 2 + .../application/LoginPing/src/linux/main.cpp | 53 ++++++++++ .../LoginPing/src/shared/ConfigLoginPing.cpp | 43 ++++++++ .../LoginPing/src/shared/ConfigLoginPing.h | 60 ++++++++++++ .../LoginPing/src/shared/FirstLoginPing.cpp | 11 +++ .../LoginPing/src/shared/FirstLoginPing.h | 17 ++++ .../LoginPing/src/shared/LoginConnection.cpp | 60 ++++++++++++ .../LoginPing/src/shared/LoginConnection.h | 33 +++++++ .../LoginPing/src/shared/LoginPing.cpp | 97 +++++++++++++++++++ .../LoginPing/src/shared/LoginPing.h | 40 ++++++++ 14 files changed, 511 insertions(+), 1 deletion(-) create mode 100644 engine/server/application/LoginPing/CMakeLists.txt create mode 100644 engine/server/application/LoginPing/src/CMakeLists.txt create mode 100644 engine/server/application/LoginPing/src/linux/checkLoginServer.sh create mode 100644 engine/server/application/LoginPing/src/linux/loginPing.cfg create mode 100644 engine/server/application/LoginPing/src/linux/main.cpp create mode 100644 engine/server/application/LoginPing/src/shared/ConfigLoginPing.cpp create mode 100644 engine/server/application/LoginPing/src/shared/ConfigLoginPing.h create mode 100644 engine/server/application/LoginPing/src/shared/FirstLoginPing.cpp create mode 100644 engine/server/application/LoginPing/src/shared/FirstLoginPing.h create mode 100644 engine/server/application/LoginPing/src/shared/LoginConnection.cpp create mode 100644 engine/server/application/LoginPing/src/shared/LoginConnection.h create mode 100644 engine/server/application/LoginPing/src/shared/LoginPing.cpp create mode 100644 engine/server/application/LoginPing/src/shared/LoginPing.h diff --git a/engine/server/application/CMakeLists.txt b/engine/server/application/CMakeLists.txt index 8219918a..e4b54b09 100644 --- a/engine/server/application/CMakeLists.txt +++ b/engine/server/application/CMakeLists.txt @@ -2,8 +2,9 @@ add_subdirectory(CentralServer) add_subdirectory(ChatServer) add_subdirectory(ConnectionServer) -add_subdirectory(LoginServer) add_subdirectory(LogServer) +add_subdirectory(LoginPing) +add_subdirectory(LoginServer) add_subdirectory(MetricsServer) add_subdirectory(PlanetServer) add_subdirectory(TaskManager) diff --git a/engine/server/application/LoginPing/CMakeLists.txt b/engine/server/application/LoginPing/CMakeLists.txt new file mode 100644 index 00000000..51cc7d35 --- /dev/null +++ b/engine/server/application/LoginPing/CMakeLists.txt @@ -0,0 +1,6 @@ + +cmake_minimum_required(VERSION 2.8) + +project(LoginPing) + +add_subdirectory(src) diff --git a/engine/server/application/LoginPing/src/CMakeLists.txt b/engine/server/application/LoginPing/src/CMakeLists.txt new file mode 100644 index 00000000..676ee679 --- /dev/null +++ b/engine/server/application/LoginPing/src/CMakeLists.txt @@ -0,0 +1,79 @@ + +set(SHARED_SOURCES + shared/ConfigLoginPing.cpp + shared/ConfigLoginPing.h + shared/FirstLoginPing.cpp + shared/FirstLoginPing.h + shared/LoginConnection.cpp + shared/LoginConnection.h + shared/LoginPing.cpp + shared/LoginPing.h +) + +if(WIN32) + set(PLATFORM_SOURCES + win32/WinMain.cpp + ) +else() + set(PLATFORM_SOURCES + linux/main.cpp + ) +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/sharedRandom/include/public + ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedThread/include/public + ${SWG_ENGINE_SOURCE_DIR}/server/library/serverNetworkMessages/include/public + ${SWG_EXTERNALS_SOURCE_DIR}/ours/library/archive/include +) + +link_directories(${STLPORT_LIBDIR}) + +add_executable(LoginPing + ${SHARED_SOURCES} + ${PLATFORM_SOURCES} +) + +target_link_libraries(LoginPing + sharedCompression + sharedDebug + sharedFile + sharedFoundation + #sharedLog + #sharedMath + sharedMemoryManager + sharedMessageDispatch + sharedNetwork + sharedNetworkMessages + sharedRandom + sharedSynchronization + sharedThread + #sharedUtility + serverNetworkMessages + #serverUtility + archive + #fileInterface + #localization + #localizationArchive + #unicode + #unicodeArchive + #udplibrary + ${STLPORT_LIBRARIES} + ${ZLIB_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${CMAKE_DL_LIBS} +) + +if(WIN32) + target_link_libraries(LoginPing mswsock ws2_32) +endif() diff --git a/engine/server/application/LoginPing/src/linux/checkLoginServer.sh b/engine/server/application/LoginPing/src/linux/checkLoginServer.sh new file mode 100644 index 00000000..0bfc2251 --- /dev/null +++ b/engine/server/application/LoginPing/src/linux/checkLoginServer.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# + +STATUS=`./LoginPing_d -- @loginPing.cfg` +if [ "$STATUS" != "Ok" ]; then + ./LoginServer_d -- @loginServer.cfg & + echo "LoginServer not responding" +fi diff --git a/engine/server/application/LoginPing/src/linux/loginPing.cfg b/engine/server/application/LoginPing/src/linux/loginPing.cfg new file mode 100644 index 00000000..6fb93795 --- /dev/null +++ b/engine/server/application/LoginPing/src/linux/loginPing.cfg @@ -0,0 +1,2 @@ +[LoginPing] +passthroughMode=false diff --git a/engine/server/application/LoginPing/src/linux/main.cpp b/engine/server/application/LoginPing/src/linux/main.cpp new file mode 100644 index 00000000..5ad679c1 --- /dev/null +++ b/engine/server/application/LoginPing/src/linux/main.cpp @@ -0,0 +1,53 @@ +#include "sharedFoundation/FirstSharedFoundation.h" + +#include "ConfigLoginPing.h" +#include "LoginPing.h" + +#include "sharedCompression/SetupSharedCompression.h" +#include "sharedDebug/SetupSharedDebug.h" +#include "sharedFile/SetupSharedFile.h" +#include "sharedFoundation/ConfigFile.h" +#include "sharedFoundation/SetupSharedFoundation.h" +#include "sharedNetwork/NetworkHandler.h" +#include "sharedNetworkMessages/SetupSharedNetworkMessages.h" +#include "sharedRandom/SetupSharedRandom.h" +#include "sharedThread/SetupSharedThread.h" + +// ====================================================================== + +int main(int argc, char ** argv) +{ + SetupSharedThread::install(); + SetupSharedDebug::install(1024); + + //-- setup foundation + SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game); + setupFoundationData.lpCmdLine = ConvertCommandLine(argc,argv); + setupFoundationData.configFile = "loginPing.cfg"; + SetupSharedFoundation::install (setupFoundationData); + + SetupSharedCompression::install(); + + SetupSharedNetworkMessages::install(); + + //setup the ping + ConfigLoginPing::install(); + + //-- run game + NetworkHandler::install(); + bool result = LoginPing::ping(); + if (result) + { + printf("Ok\n"); + } + else + { + printf("Ping failed\n"); + } + NetworkHandler::remove(); + ConfigLoginPing::remove(); + SetupSharedFoundation::remove(); + SetupSharedThread::remove(); + + return 0; +} diff --git a/engine/server/application/LoginPing/src/shared/ConfigLoginPing.cpp b/engine/server/application/LoginPing/src/shared/ConfigLoginPing.cpp new file mode 100644 index 00000000..7c3fb980 --- /dev/null +++ b/engine/server/application/LoginPing/src/shared/ConfigLoginPing.cpp @@ -0,0 +1,43 @@ +// ConfigLoginPing.cpp +// Copyright 2000-01, Sony Online Entertainment Inc., all rights reserved. + +//----------------------------------------------------------------------- + +#include "FirstLoginPing.h" +#include "sharedFoundation/ConfigFile.h" +#include "sharedNetwork/SetupSharedNetwork.h" +#include "ConfigLoginPing.h" + +//----------------------------------------------------------------------- + +ConfigLoginPing::Data * ConfigLoginPing::data = 0; + +#define KEY_INT(a,b) (data->a = ConfigFile::getKeyInt("LoginPing", #a, b)) +#define KEY_BOOL(a,b) (data->a = ConfigFile::getKeyBool("LoginPing", #a, b)) +#define KEY_REAL(a,b) (data->a = ConfigFile::getKeyReal("LoginPing", #a, b)) +#define KEY_STRING(a,b) (data->a = ConfigFile::getKeyString("LoginPing", #a, b)) + +//----------------------------------------------------------------------- + +void ConfigLoginPing::install(void) +{ + SetupSharedNetwork::SetupData networkSetupData; + SetupSharedNetwork::getDefaultServerSetupData(networkSetupData); + SetupSharedNetwork::install(networkSetupData); + + data = new ConfigLoginPing::Data; + KEY_BOOL(passthroughMode, false); + KEY_STRING(loginServerAddress, "localhost"); + KEY_INT(loginServerPingServicePort, 44460); + KEY_STRING(rcFileName, "loginPing.cfg"); +} + +//----------------------------------------------------------------------- + +void ConfigLoginPing::remove(void) +{ + delete data; + data = 0; +} + +//----------------------------------------------------------------------- diff --git a/engine/server/application/LoginPing/src/shared/ConfigLoginPing.h b/engine/server/application/LoginPing/src/shared/ConfigLoginPing.h new file mode 100644 index 00000000..a067a24f --- /dev/null +++ b/engine/server/application/LoginPing/src/shared/ConfigLoginPing.h @@ -0,0 +1,60 @@ +// ConfigLoginPing.h +// Copyright 2000-01, Sony Online Entertainment Inc., all rights reserved. + +#ifndef _ConfigLoginPing_H +#define _ConfigLoginPing_H + +//----------------------------------------------------------------------- + +class ConfigLoginPing +{ + public: + struct Data + { + const char * rcFileName; + bool passthroughMode; + const char * loginServerAddress; + uint16 loginServerPingServicePort; + }; + + static const char * getRcFileName (); + static bool getPassthroughMode (); + static const char * getLoginServerAddress (); + static uint16 getLoginServerPingServicePort (); + static void install (); + static void remove (); + + private: + static Data * data; +}; + +//----------------------------------------------------------------------- + +inline const char * ConfigLoginPing::getRcFileName() +{ + return data->rcFileName; +} + +//----------------------------------------------------------------------- + +inline bool ConfigLoginPing::getPassthroughMode() +{ + return data->passthroughMode; +} + +//----------------------------------------------------------------------- + +inline const char * ConfigLoginPing::getLoginServerAddress() +{ + return data->loginServerAddress; +} +//----------------------------------------------------------------------- + +inline uint16 ConfigLoginPing::getLoginServerPingServicePort() +{ + return data->loginServerPingServicePort; +} + +//----------------------------------------------------------------------- + +#endif // _ConfigLoginPing_H diff --git a/engine/server/application/LoginPing/src/shared/FirstLoginPing.cpp b/engine/server/application/LoginPing/src/shared/FirstLoginPing.cpp new file mode 100644 index 00000000..bb1b1820 --- /dev/null +++ b/engine/server/application/LoginPing/src/shared/FirstLoginPing.cpp @@ -0,0 +1,11 @@ +// FirstLoginPing.cpp +// Copyright 2000-01, Sony Online Entertainment Inc., all rights reserved. + +//----------------------------------------------------------------------- + +#include "FirstLoginPing.h" + +void FirstLoginPingFoo(){} //lint !e714 // enable #pragma warning disable + +//----------------------------------------------------------------------- + diff --git a/engine/server/application/LoginPing/src/shared/FirstLoginPing.h b/engine/server/application/LoginPing/src/shared/FirstLoginPing.h new file mode 100644 index 00000000..06bb6428 --- /dev/null +++ b/engine/server/application/LoginPing/src/shared/FirstLoginPing.h @@ -0,0 +1,17 @@ +// FirstLoginPing.h +// Copyright 2000-01, Sony Online Entertainment Inc., all rights reserved. + +#ifndef _INCLUDED_FirstLoginPing_H +#define _INCLUDED_FirstLoginPing_H + +//----------------------------------------------------------------------- +#pragma warning ( disable : 4786 ) + +#include "sharedFoundation/FirstSharedFoundation.h" +#include "sharedFoundationTypes/FoundationTypes.h" +#include +#include + +//----------------------------------------------------------------------- + +#endif // _INCLUDED_FirstLoginPing_H diff --git a/engine/server/application/LoginPing/src/shared/LoginConnection.cpp b/engine/server/application/LoginPing/src/shared/LoginConnection.cpp new file mode 100644 index 00000000..a985883e --- /dev/null +++ b/engine/server/application/LoginPing/src/shared/LoginConnection.cpp @@ -0,0 +1,60 @@ +// LoginConnection.cpp +// Copyright 2000-01, Sony Online Entertainment Inc., all rights reserved. + +//----------------------------------------------------------------------- + +#include "FirstLoginPing.h" +#include "LoginPing.h" +#include "LoginConnection.h" +#include "serverNetworkMessages/TaskEnumCluster.h" +#include "sharedNetwork/NetworkSetupData.h" + +//----------------------------------------------------------------------- + +LoginConnection::LoginConnection(const std::string & a, const unsigned short p) : +Connection(a, p, NetworkSetupData()) +{ + REPORT_LOG(true, ("Waiting for loginserver connection %s:%d\n", a.c_str(), p)); +} + +//----------------------------------------------------------------------- + +LoginConnection::~LoginConnection() +{ + LoginPing::onLoginConnectionDestroyed(this); +} + +//----------------------------------------------------------------------- + +void LoginConnection::onConnectionClosed() +{ +} + +//----------------------------------------------------------------------- + +void LoginConnection::onConnectionOpened() +{ + REPORT_LOG(true, ("Connection with loginserver opened\n")); +} + +//----------------------------------------------------------------------- + +void LoginConnection::onConnectionOverflowing(const unsigned int ) +{ +} + +//----------------------------------------------------------------------- + +void LoginConnection::onReceive(const Archive::ByteStream & message ) +{ + Archive::ReadIterator r(message); + GameNetworkMessage g(r); + + if (g.isType("LoginPingMessage")) + { + LoginPing::receiveReplyMessage(); + } +} + +//----------------------------------------------------------------------- + diff --git a/engine/server/application/LoginPing/src/shared/LoginConnection.h b/engine/server/application/LoginPing/src/shared/LoginConnection.h new file mode 100644 index 00000000..8ebbc340 --- /dev/null +++ b/engine/server/application/LoginPing/src/shared/LoginConnection.h @@ -0,0 +1,33 @@ +// LoginConnection.h +// Copyright 2000-01, Sony Online Entertainment Inc., all rights reserved. +// Author: Justin Randall + +#ifndef _INCLUDED_LoginConnection_H +#define _INCLUDED_LoginConnection_H + +//----------------------------------------------------------------------- + +#include "sharedNetwork/Connection.h" + +//----------------------------------------------------------------------- + +class LoginConnection : public Connection +{ +public: + LoginConnection(const std::string & remoteAddress, const unsigned short port); + ~LoginConnection(); + + virtual void onConnectionClosed (); + virtual void onConnectionOpened (); + virtual void onConnectionOverflowing (const unsigned int bytesPending); + virtual void onReceive (const Archive::ByteStream & message); + +private: + LoginConnection & operator = (const LoginConnection & rhs); + LoginConnection(const LoginConnection & source); + +}; //lint !e1712 + +//----------------------------------------------------------------------- + +#endif // _INCLUDED_LoginConnection_H diff --git a/engine/server/application/LoginPing/src/shared/LoginPing.cpp b/engine/server/application/LoginPing/src/shared/LoginPing.cpp new file mode 100644 index 00000000..7551494e --- /dev/null +++ b/engine/server/application/LoginPing/src/shared/LoginPing.cpp @@ -0,0 +1,97 @@ +// ====================================================================== +// +// LoginPing.cpp +// +// Copyright 2000-01, Sony Online Entertainment Inc., all rights reserved. +// +// ====================================================================== + +#include "FirstLoginPing.h" +#include "LoginPing.h" +#include "ConfigLoginPing.h" +#include "LoginConnection.h" +#include "sharedFoundation/Clock.h" +#include "sharedNetworkMessages/GameNetworkMessage.h" + +// ====================================================================== + +LoginPing::LoginPing() : + m_loginConnection(new LoginConnection(ConfigLoginPing::getLoginServerAddress(), ConfigLoginPing::getLoginServerPingServicePort())), + m_waitingForResponse(true) +{ +} + +// ---------------------------------------------------------------------- + +LoginPing::~LoginPing() +{ + if (m_loginConnection) + m_loginConnection->disconnect(); +} + +// ---------------------------------------------------------------------- + +LoginPing & LoginPing::instance() +{ + static LoginPing l; + return l; +} + +// ---------------------------------------------------------------------- + +bool LoginPing::ping() +{ + if (ConfigLoginPing::getPassthroughMode()) + { + return true; + } + if (!instance().m_loginConnection) + { + return false; + } + GameNetworkMessage m("LoginPingMessage"); + Archive::ByteStream b; + m.pack(b); + instance().m_loginConnection->send(b, true); + int numTries = 0; + while(instance().m_waitingForResponse) + { + LoginPing::update(); + numTries++; + if (numTries > 100) + { + break; + } + } + return !instance().m_waitingForResponse; +} + +// ---------------------------------------------------------------------- + +void LoginPing::update() +{ + NetworkHandler::update(); + NetworkHandler::dispatch(); + Clock::setFrameRateLimit(4.0f); + + Clock::update(); + Clock::limitFrameRate(); +} + +// ---------------------------------------------------------------------- + +void LoginPing::receiveReplyMessage() +{ + instance().m_waitingForResponse = false; +} + +// ---------------------------------------------------------------------- + +void LoginPing::onLoginConnectionDestroyed(LoginConnection const *loginConnection) +{ + if (loginConnection == instance().m_loginConnection) + instance().m_loginConnection = 0; +} + +// ====================================================================== + diff --git a/engine/server/application/LoginPing/src/shared/LoginPing.h b/engine/server/application/LoginPing/src/shared/LoginPing.h new file mode 100644 index 00000000..852b144b --- /dev/null +++ b/engine/server/application/LoginPing/src/shared/LoginPing.h @@ -0,0 +1,40 @@ +// ====================================================================== +// +// LoginPing.h +// +// Copyright 2000-01, Sony Online Entertainment Inc., all rights reserved. +// +// ====================================================================== + +#ifndef _LoginPing_H +#define _LoginPing_H + +// ====================================================================== + +class LoginConnection; + +// ====================================================================== + +class LoginPing +{ +public: + LoginPing(); + ~LoginPing(); + + static bool ping(); + static void update(); + + static void receiveReplyMessage(); + static void onLoginConnectionDestroyed(LoginConnection const *loginConnection); + +private: + static LoginPing &instance(); + + LoginConnection *m_loginConnection; + bool m_waitingForResponse; +}; + +// ====================================================================== + +#endif // _LoginPing_H +