Added LoginPing project

This commit is contained in:
Anonymous
2014-01-21 05:45:19 -07:00
parent 14488cbe1c
commit 1c391034f9
14 changed files with 511 additions and 1 deletions
+2 -1
View File
@@ -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)
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 2.8)
project(LoginPing)
add_subdirectory(src)
@@ -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()
@@ -0,0 +1,8 @@
#!/bin/sh
#
STATUS=`./LoginPing_d -- @loginPing.cfg`
if [ "$STATUS" != "Ok" ]; then
./LoginServer_d -- @loginServer.cfg &
echo "LoginServer not responding"
fi
@@ -0,0 +1,2 @@
[LoginPing]
passthroughMode=false
@@ -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;
}
@@ -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;
}
//-----------------------------------------------------------------------
@@ -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
@@ -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
//-----------------------------------------------------------------------
@@ -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 <string>
#include <map>
//-----------------------------------------------------------------------
#endif // _INCLUDED_FirstLoginPing_H
@@ -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();
}
}
//-----------------------------------------------------------------------
@@ -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
@@ -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;
}
// ======================================================================
@@ -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