clean up commandline handling, make network stuff more self-contained

This commit is contained in:
Glenn Maynard
2004-04-15 20:21:39 +00:00
parent 8a45506bca
commit 585f92c5f3
4 changed files with 52 additions and 52 deletions
+48 -47
View File
@@ -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 <CString> 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 <CString> ProfileNames;
PROFILEMAN->GetLocalProfileNames(ProfileNames);
if (ProfileNames.size()>0) {
PlayerName.m_packID = 30;
for (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 (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);
} 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);
}
+2 -2
View File
@@ -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;
+1 -3
View File
@@ -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() );
}
+1
View File
@@ -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