I have added some command-line processing. Look at the bottom of
StepMania.cpp for it. I have also moved the connect stuff out of the NetworkSyncManager constructor, so it doens't do ANYTHING unless it's in the command-line args. Also, now NSMAN works by the '--NETIP=' flag.
This commit is contained in:
@@ -21,45 +21,41 @@
|
|||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
//String compare functions for command line args
|
//String compare functions for command line args
|
||||||
|
|
||||||
NetworkSyncManager::NetworkSyncManager(int argc, char **argv)
|
NetworkSyncManager::NetworkSyncManager()
|
||||||
{
|
{
|
||||||
NetPlayerClient = new EzSockets;
|
NetPlayerClient = new EzSockets;
|
||||||
m_ServerVersion = 0;
|
m_ServerVersion = 0;
|
||||||
|
|
||||||
if (argc > 1) {
|
useSMserver = false;
|
||||||
LOG->Trace("Multiple arguements were entered.");
|
|
||||||
int argCtr = 1;
|
|
||||||
|
|
||||||
while (argCtr<argc) {
|
|
||||||
CString tempargv(argv[argCtr]);
|
|
||||||
CString Checking(tempargv.substr(0,8));
|
|
||||||
Checking.MakeUpper();
|
|
||||||
if (strcmp(Checking.c_str(),"--NETIP:")==0)
|
|
||||||
{
|
|
||||||
CString IPAddy (tempargv.substr(8,tempargv.GetLength()-8));
|
|
||||||
|
|
||||||
LOG->Trace ("NetIP Found:%s",IPAddy.c_str());
|
|
||||||
|
|
||||||
if (!IPAddy.CompareNoCase("LISTEN"))
|
|
||||||
if (Listen(8765)) {
|
|
||||||
useSMserver = true;
|
|
||||||
} else
|
|
||||||
useSMserver = false;
|
|
||||||
else
|
|
||||||
if (Connect(IPAddy.c_str(),8765) == true)
|
|
||||||
{
|
|
||||||
useSMserver = true;
|
|
||||||
} else
|
|
||||||
useSMserver = false;
|
|
||||||
|
|
||||||
break;//Once connected, break outta loop.
|
}
|
||||||
}
|
|
||||||
argCtr++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
useSMserver = false;
|
|
||||||
|
|
||||||
|
NetworkSyncManager::~NetworkSyncManager ()
|
||||||
|
{
|
||||||
|
//Close Connection to server nicely.
|
||||||
|
if (useSMserver)
|
||||||
|
NetPlayerClient->close();
|
||||||
|
delete NetPlayerClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkSyncManager::StartUp (CString ServerIP)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
useSMserver = true;
|
||||||
|
} else
|
||||||
|
useSMserver = false;
|
||||||
|
|
||||||
|
|
||||||
if (useSMserver) {
|
if (useSMserver) {
|
||||||
@@ -90,17 +86,10 @@ NetworkSyncManager::NetworkSyncManager(int argc, char **argv)
|
|||||||
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkSyncManager::~NetworkSyncManager ()
|
|
||||||
{
|
|
||||||
//Close Connection to server nicely.
|
|
||||||
if (useSMserver)
|
|
||||||
NetPlayerClient->close();
|
|
||||||
delete NetPlayerClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NetworkSyncManager::Connect(const CString& addy, unsigned short port)
|
bool NetworkSyncManager::Connect(const CString& addy, unsigned short port)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,9 +20,11 @@ class EzSockets;
|
|||||||
class NetworkSyncManager
|
class NetworkSyncManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NetworkSyncManager(int argc, char **argv);
|
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
|
||||||
|
|||||||
@@ -989,7 +989,12 @@ int main(int argc, char* argv[])
|
|||||||
MODELMAN = new ModelManager;
|
MODELMAN = new ModelManager;
|
||||||
delete loading_window; // destroy this before init'ing Display
|
delete loading_window; // destroy this before init'ing Display
|
||||||
|
|
||||||
NSMAN = new NetworkSyncManager(argc, argv);
|
NSMAN = new NetworkSyncManager;
|
||||||
|
//Load Network Sync manager, but do not connect
|
||||||
|
|
||||||
|
ProcessArgsFirst(argc,argv);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DISPLAY = CreateDisplay();
|
DISPLAY = CreateDisplay();
|
||||||
|
|
||||||
@@ -1036,6 +1041,9 @@ int main(int argc, char* argv[])
|
|||||||
/* Initialize which courses are ranking courses here. */
|
/* Initialize which courses are ranking courses here. */
|
||||||
SONGMAN->UpdateRankingCourses();
|
SONGMAN->UpdateRankingCourses();
|
||||||
|
|
||||||
|
/* Run the second argcheck, you can do your other options here */
|
||||||
|
ProcessArgsSecond(argc, argv);
|
||||||
|
|
||||||
/* Run the main loop. */
|
/* Run the main loop. */
|
||||||
GameLoop();
|
GameLoop();
|
||||||
|
|
||||||
@@ -1474,3 +1482,65 @@ static void GameLoop()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Process args first, put command line options that
|
||||||
|
//have to run before the SM window loads here
|
||||||
|
void ProcessArgsFirst(int argc, char ** argv)
|
||||||
|
{
|
||||||
|
int argCtr = 1,i; //argv[0] is exe
|
||||||
|
while (argCtr<argc)
|
||||||
|
{
|
||||||
|
CString Arguement(argv[argCtr]);
|
||||||
|
|
||||||
|
// StepMaina.exe argbase=argparameter
|
||||||
|
//Where argparameter can contain = signs
|
||||||
|
|
||||||
|
CString ArgBase;
|
||||||
|
CString ArgParameter;
|
||||||
|
|
||||||
|
for (i=0;i<Arguement.GetLength();i++)
|
||||||
|
if (Arguement.at(i) == '=')
|
||||||
|
break;
|
||||||
|
ArgBase = Arguement.substr(0,i);
|
||||||
|
if (Arguement.GetLength()>i)
|
||||||
|
ArgParameter = Arguement.substr(i+1,Arguement.GetLength()-i-1);
|
||||||
|
|
||||||
|
//For now using an IF/ELSEIF clause
|
||||||
|
if (ArgBase.CompareNoCase("--TESTARGS") == 0)
|
||||||
|
LOG->Info ("Test of arguements requested. Now in First argcheck");
|
||||||
|
else if (ArgBase.CompareNoCase("--NETIP") == 0)
|
||||||
|
NSMAN->StartUp(ArgParameter.c_str());
|
||||||
|
|
||||||
|
|
||||||
|
argCtr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ProcessArgsSecond(int argc, char ** argv)
|
||||||
|
{
|
||||||
|
int argCtr = 1,i; //argv[0] is exe
|
||||||
|
while (argCtr<argc)
|
||||||
|
{
|
||||||
|
CString Arguement(argv[argCtr]);
|
||||||
|
|
||||||
|
// StepMaina.exe argbase=argparameter
|
||||||
|
//Where argparameter can contain = signs
|
||||||
|
|
||||||
|
CString ArgBase;
|
||||||
|
CString ArgParameter;
|
||||||
|
|
||||||
|
for (i=0;i<Arguement.GetLength();i++)
|
||||||
|
if (Arguement.at(i) == '=')
|
||||||
|
break;
|
||||||
|
ArgBase = Arguement.substr(0,i);
|
||||||
|
if (Arguement.GetLength()>i)
|
||||||
|
ArgParameter = Arguement.substr(i+1,Arguement.GetLength()-i-1);
|
||||||
|
|
||||||
|
//For now using an IF/ELSEIF clause
|
||||||
|
|
||||||
|
if (ArgBase.CompareNoCase("--TESTARGS") == 0)
|
||||||
|
LOG->Info ("Test of arguements requested. Now in Second argcheck");
|
||||||
|
|
||||||
|
|
||||||
|
argCtr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,11 @@ void ReadGamePrefsFromDisk( bool bSwitchToLastPlayedGame=true );
|
|||||||
void SaveGamePrefsToDisk();
|
void SaveGamePrefsToDisk();
|
||||||
void ChangeCurrentGame( Game g );
|
void ChangeCurrentGame( Game g );
|
||||||
|
|
||||||
|
void ProcessArgsFirst(int argc, char ** argv);
|
||||||
|
//First wave of arguements, before display actually loads
|
||||||
|
void ProcessArgsSecond(int argc, char ** argv);
|
||||||
|
//Second wave of arguements, after display loads
|
||||||
|
|
||||||
// If successful, return filename of screenshot in sDir, else return ""
|
// If successful, return filename of screenshot in sDir, else return ""
|
||||||
CString SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature, int iIndex = -1 );
|
CString SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature, int iIndex = -1 );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user