clean up commandline handling, make network stuff more self-contained
This commit is contained in:
@@ -17,9 +17,9 @@
|
|||||||
#include "ProfileManager.h"
|
#include "ProfileManager.h"
|
||||||
#include "ezsockets.h"
|
#include "ezsockets.h"
|
||||||
#include "RageLog.h"
|
#include "RageLog.h"
|
||||||
|
#include "StepMania.h"
|
||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
//String compare functions for command line args
|
|
||||||
|
|
||||||
NetworkSyncManager::NetworkSyncManager()
|
NetworkSyncManager::NetworkSyncManager()
|
||||||
{
|
{
|
||||||
@@ -28,9 +28,7 @@ NetworkSyncManager::NetworkSyncManager()
|
|||||||
|
|
||||||
useSMserver = false;
|
useSMserver = false;
|
||||||
|
|
||||||
|
StartUp();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkSyncManager::~NetworkSyncManager ()
|
NetworkSyncManager::~NetworkSyncManager ()
|
||||||
@@ -41,53 +39,56 @@ NetworkSyncManager::~NetworkSyncManager ()
|
|||||||
delete NetPlayerClient;
|
delete NetPlayerClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkSyncManager::StartUp (CString ServerIP)
|
void NetworkSyncManager::StartUp()
|
||||||
{
|
{
|
||||||
LOG->Trace ("Network Sync IP:%s",ServerIP.c_str());
|
CString ServerIP;
|
||||||
|
if( GetCommandlineArgument( "netip", &ServerIP ) )
|
||||||
if (!ServerIP.CompareNoCase("LISTEN"))
|
|
||||||
if (Listen(8765)) {
|
|
||||||
useSMserver = true;
|
|
||||||
} else
|
|
||||||
useSMserver = false;
|
|
||||||
else
|
|
||||||
if (Connect(ServerIP.c_str(),8765) == true)
|
|
||||||
{
|
{
|
||||||
|
if( !Connect(ServerIP.c_str(),8765) )
|
||||||
|
{
|
||||||
|
LOG->Warn( "Network Sync Manager failed to connect" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if( GetCommandlineArgument( "listen" ) )
|
||||||
|
{
|
||||||
|
if( !Listen(8765) )
|
||||||
|
{
|
||||||
|
LOG->Warn( "Listen() failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
useSMserver = true;
|
useSMserver = true;
|
||||||
} else
|
|
||||||
useSMserver = false;
|
|
||||||
|
|
||||||
|
|
||||||
if (useSMserver) {
|
|
||||||
int ClientCommand=3;
|
int ClientCommand=3;
|
||||||
NetPlayerClient->send((char*) &ClientCommand, 4);
|
NetPlayerClient->send((char*) &ClientCommand, 4);
|
||||||
|
|
||||||
NetPlayerClient->receive(m_ServerVersion);
|
NetPlayerClient->receive(m_ServerVersion);
|
||||||
//If network play is desired
|
// If network play is desired and the connection works,
|
||||||
//AND the connection works
|
// halt until we know what server version we're dealing with
|
||||||
//Halt until we know what server
|
|
||||||
//version we're dealing with
|
|
||||||
vector <CString> ProfileNames;
|
vector <CString> ProfileNames;
|
||||||
PROFILEMAN->GetLocalProfileNames(ProfileNames);
|
PROFILEMAN->GetLocalProfileNames(ProfileNames);
|
||||||
|
|
||||||
netName PlayerName;
|
netName PlayerName;
|
||||||
int i;
|
if( ProfileNames.size() > 0 )
|
||||||
|
{
|
||||||
if (ProfileNames.size()>0) {
|
|
||||||
PlayerName.m_packID = 30;
|
PlayerName.m_packID = 30;
|
||||||
for (i=0;i<strlen(ProfileNames[0]);i++)
|
for( unsigned i=0; i < strlen(ProfileNames[0]); i++ )
|
||||||
PlayerName.m_data[i] = ProfileNames[0][i];
|
PlayerName.m_data[i] = ProfileNames[0][i];
|
||||||
NetPlayerClient->send((char*) &PlayerName,20);
|
NetPlayerClient->send((char*) &PlayerName,20);
|
||||||
}
|
}
|
||||||
if (ProfileNames.size()>1) {
|
if( ProfileNames.size() > 1 )
|
||||||
|
{
|
||||||
PlayerName.m_packID = 31;
|
PlayerName.m_packID = 31;
|
||||||
for (i=0;i<strlen(ProfileNames[1]);i++)
|
for( unsigned i=0; i < strlen(ProfileNames[1]); i++ )
|
||||||
PlayerName.m_data[i] = ProfileNames[1][i];
|
PlayerName.m_data[i] = ProfileNames[1][i];
|
||||||
NetPlayerClient->send((char*) &PlayerName,20);
|
NetPlayerClient->send( (char*) &PlayerName,20 );
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG->Info("Server Version: %d",m_ServerVersion);
|
LOG->Info("Server Version: %d",m_ServerVersion);
|
||||||
} else
|
|
||||||
LOG->Info("Network Sync Manager failed to connect");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ public:
|
|||||||
NetworkSyncManager();
|
NetworkSyncManager();
|
||||||
~NetworkSyncManager();
|
~NetworkSyncManager();
|
||||||
|
|
||||||
void StartUp (CString ServerIP);
|
|
||||||
|
|
||||||
//If "useSMserver" then send score to server
|
//If "useSMserver" then send score to server
|
||||||
void ReportScore(int playerID, int step, int score, int combo);
|
void ReportScore(int playerID, int step, int score, int combo);
|
||||||
void ReportSongOver(); //Report to server that song is over
|
void ReportSongOver(); //Report to server that song is over
|
||||||
@@ -34,6 +32,8 @@ public:
|
|||||||
int m_playerLife[NUM_PLAYERS]; //Life
|
int m_playerLife[NUM_PLAYERS]; //Life
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void StartUp();
|
||||||
|
|
||||||
int m_playerID; //these are currently unused, but need to stay
|
int m_playerID; //these are currently unused, but need to stay
|
||||||
int m_step;
|
int m_step;
|
||||||
int m_score;
|
int m_score;
|
||||||
|
|||||||
@@ -857,7 +857,7 @@ static void ApplyLogPreferences()
|
|||||||
* --foo; short arguments (-x) are not supported. (As commandline arguments
|
* --foo; short arguments (-x) are not supported. (As commandline arguments
|
||||||
* are not intended for common, general use, having short options isn't
|
* are not intended for common, general use, having short options isn't
|
||||||
* needed.) If argument is non-NULL, accept an argument. */
|
* needed.) If argument is non-NULL, accept an argument. */
|
||||||
bool GetCommandlineArgument( const CString &option, CString *argument=NULL )
|
bool GetCommandlineArgument( const CString &option, CString *argument )
|
||||||
{
|
{
|
||||||
const CString optstr = "--" + option;
|
const CString optstr = "--" + option;
|
||||||
|
|
||||||
@@ -890,8 +890,6 @@ bool GetCommandlineArgument( const CString &option, CString *argument=NULL )
|
|||||||
static void ProcessArgsFirst()
|
static void ProcessArgsFirst()
|
||||||
{
|
{
|
||||||
CString Argument;
|
CString Argument;
|
||||||
if( GetCommandlineArgument( "netip", &Argument ) )
|
|
||||||
NSMAN->StartUp( Argument );
|
|
||||||
if( GetCommandlineArgument( "test", &Argument ) )
|
if( GetCommandlineArgument( "test", &Argument ) )
|
||||||
LOG->Info ("Test: \"%s\"", Argument.c_str() );
|
LOG->Info ("Test: \"%s\"", Argument.c_str() );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,5 +31,6 @@ extern HWND g_hWndMain;
|
|||||||
|
|
||||||
extern int g_argc;
|
extern int g_argc;
|
||||||
extern char **g_argv;
|
extern char **g_argv;
|
||||||
|
bool GetCommandlineArgument( const CString &option, CString *argument=NULL );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user