From 585f92c5f3fb5e9aad6eb090a0d20e6b87fbda18 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 15 Apr 2004 20:21:39 +0000 Subject: [PATCH] clean up commandline handling, make network stuff more self-contained --- stepmania/src/NetworkSyncManager.cpp | 95 ++++++++++++++-------------- stepmania/src/NetworkSyncManager.h | 4 +- stepmania/src/StepMania.cpp | 4 +- stepmania/src/StepMania.h | 1 + 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/stepmania/src/NetworkSyncManager.cpp b/stepmania/src/NetworkSyncManager.cpp index 91eb110183..148677df37 100644 --- a/stepmania/src/NetworkSyncManager.cpp +++ b/stepmania/src/NetworkSyncManager.cpp @@ -17,9 +17,9 @@ #include "ProfileManager.h" #include "ezsockets.h" #include "RageLog.h" - +#include "StepMania.h" #include "RageUtil.h" - //String compare functions for command line args + NetworkSyncManager::NetworkSyncManager() { @@ -28,9 +28,7 @@ NetworkSyncManager::NetworkSyncManager() useSMserver = false; - - - + StartUp(); } NetworkSyncManager::~NetworkSyncManager () @@ -41,53 +39,56 @@ NetworkSyncManager::~NetworkSyncManager () delete NetPlayerClient; } -void NetworkSyncManager::StartUp (CString ServerIP) +void NetworkSyncManager::StartUp() { - LOG->Trace ("Network Sync IP:%s",ServerIP.c_str()); - - if (!ServerIP.CompareNoCase("LISTEN")) - if (Listen(8765)) { - useSMserver = true; - } else - useSMserver = false; - else - if (Connect(ServerIP.c_str(),8765) == true) + CString ServerIP; + if( GetCommandlineArgument( "netip", &ServerIP ) ) + { + if( !Connect(ServerIP.c_str(),8765) ) { - useSMserver = true; - } else - useSMserver = false; - + LOG->Warn( "Network Sync Manager failed to connect" ); + return; + } - if (useSMserver) { - int ClientCommand=3; - NetPlayerClient->send((char*) &ClientCommand, 4); + } + else if( GetCommandlineArgument( "listen" ) ) + { + if( !Listen(8765) ) + { + LOG->Warn( "Listen() failed"); + return; + } - NetPlayerClient->receive(m_ServerVersion); - //If network play is desired - //AND the connection works - //Halt until we know what server - //version we're dealing with - vector ProfileNames; - PROFILEMAN->GetLocalProfileNames(ProfileNames); - - netName PlayerName; - int i; + } + + useSMserver = true; + + int ClientCommand=3; + NetPlayerClient->send((char*) &ClientCommand, 4); + + NetPlayerClient->receive(m_ServerVersion); + // If network play is desired and the connection works, + // halt until we know what server version we're dealing with + vector ProfileNames; + PROFILEMAN->GetLocalProfileNames(ProfileNames); - if (ProfileNames.size()>0) { - PlayerName.m_packID = 30; - for (i=0;isend((char*) &PlayerName,20); - } - if (ProfileNames.size()>1) { - PlayerName.m_packID = 31; - for (i=0;isend((char*) &PlayerName,20); - } - LOG->Info("Server Version: %d",m_ServerVersion); - } else - LOG->Info("Network Sync Manager failed to connect"); + netName PlayerName; + if( ProfileNames.size() > 0 ) + { + PlayerName.m_packID = 30; + for( unsigned i=0; i < strlen(ProfileNames[0]); i++ ) + PlayerName.m_data[i] = ProfileNames[0][i]; + NetPlayerClient->send((char*) &PlayerName,20); + } + if( ProfileNames.size() > 1 ) + { + PlayerName.m_packID = 31; + for( unsigned i=0; i < strlen(ProfileNames[1]); i++ ) + PlayerName.m_data[i] = ProfileNames[1][i]; + NetPlayerClient->send( (char*) &PlayerName,20 ); + } + + LOG->Info("Server Version: %d",m_ServerVersion); } diff --git a/stepmania/src/NetworkSyncManager.h b/stepmania/src/NetworkSyncManager.h index 2cf73c4fa1..24d9b93522 100644 --- a/stepmania/src/NetworkSyncManager.h +++ b/stepmania/src/NetworkSyncManager.h @@ -23,8 +23,6 @@ public: NetworkSyncManager(); ~NetworkSyncManager(); - void StartUp (CString ServerIP); - //If "useSMserver" then send score to server void ReportScore(int playerID, int step, int score, int combo); void ReportSongOver(); //Report to server that song is over @@ -34,6 +32,8 @@ public: int m_playerLife[NUM_PLAYERS]; //Life private: + void StartUp(); + int m_playerID; //these are currently unused, but need to stay int m_step; int m_score; diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 01e9f41e61..79a9469c0f 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -857,7 +857,7 @@ static void ApplyLogPreferences() * --foo; short arguments (-x) are not supported. (As commandline arguments * are not intended for common, general use, having short options isn't * 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; @@ -890,8 +890,6 @@ bool GetCommandlineArgument( const CString &option, CString *argument=NULL ) static void ProcessArgsFirst() { CString Argument; - if( GetCommandlineArgument( "netip", &Argument ) ) - NSMAN->StartUp( Argument ); if( GetCommandlineArgument( "test", &Argument ) ) LOG->Info ("Test: \"%s\"", Argument.c_str() ); } diff --git a/stepmania/src/StepMania.h b/stepmania/src/StepMania.h index 1f5028ab19..288f06b8a0 100644 --- a/stepmania/src/StepMania.h +++ b/stepmania/src/StepMania.h @@ -31,5 +31,6 @@ extern HWND g_hWndMain; extern int g_argc; extern char **g_argv; +bool GetCommandlineArgument( const CString &option, CString *argument=NULL ); #endif