cleanup
This commit is contained in:
@@ -12,7 +12,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include <cstring>
|
|
||||||
#include "NetworkSyncManager.h"
|
#include "NetworkSyncManager.h"
|
||||||
#include "ProfileManager.h"
|
#include "ProfileManager.h"
|
||||||
#include "ezsockets.h"
|
#include "ezsockets.h"
|
||||||
@@ -68,7 +67,7 @@ void NetworkSyncManager::PostStartUp(CString ServerIP)
|
|||||||
CloseConnection();
|
CloseConnection();
|
||||||
if( ServerIP!="LISTEN" )
|
if( ServerIP!="LISTEN" )
|
||||||
{
|
{
|
||||||
if( !Connect(ServerIP.c_str(),8765) )
|
if( !Connect(ServerIP.c_str(), 8765) )
|
||||||
{
|
{
|
||||||
m_startupStatus = 2;
|
m_startupStatus = 2;
|
||||||
LOG->Warn( "Network Sync Manager failed to connect" );
|
LOG->Warn( "Network Sync Manager failed to connect" );
|
||||||
@@ -79,7 +78,7 @@ void NetworkSyncManager::PostStartUp(CString ServerIP)
|
|||||||
if( !Listen(8765) )
|
if( !Listen(8765) )
|
||||||
{
|
{
|
||||||
m_startupStatus = 2;
|
m_startupStatus = 2;
|
||||||
LOG->Warn( "Listen() failed");
|
LOG->Warn( "Listen() failed" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,8 +92,8 @@ void NetworkSyncManager::PostStartUp(CString ServerIP)
|
|||||||
NetPlayerClient->SendPack((char*) &ClientCommand, 4);
|
NetPlayerClient->SendPack((char*) &ClientCommand, 4);
|
||||||
LOG->Info("CNCHECKPOINT");
|
LOG->Info("CNCHECKPOINT");
|
||||||
|
|
||||||
NetPlayerClient->ReadData((char*)&m_ServerVersion,4);
|
NetPlayerClient->ReadData((char*)&m_ServerVersion, 4);
|
||||||
LOG->Info("CNCHECKPOINT:%d",NetPlayerClient->inBuffer.length());
|
LOG->Info("CNCHECKPOINT:%d", int(NetPlayerClient->inBuffer.length()));
|
||||||
|
|
||||||
// If network play is desired and the connection works,
|
// If network play is desired 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
|
||||||
@@ -109,7 +108,7 @@ void NetworkSyncManager::PostStartUp(CString ServerIP)
|
|||||||
for( i=0; i < strlen(ProfileNames[0]); i++ )
|
for( i=0; i < strlen(ProfileNames[0]); i++ )
|
||||||
PlayerName.m_data[i] = ProfileNames[0][i];
|
PlayerName.m_data[i] = ProfileNames[0][i];
|
||||||
PlayerName.m_data[i] = 0;
|
PlayerName.m_data[i] = 0;
|
||||||
NetPlayerClient->SendPack((char*) &PlayerName,20);
|
NetPlayerClient->SendPack((char*)&PlayerName, 20);
|
||||||
}
|
}
|
||||||
if( ProfileNames.size() > 1 )
|
if( ProfileNames.size() > 1 )
|
||||||
{
|
{
|
||||||
@@ -118,10 +117,10 @@ void NetworkSyncManager::PostStartUp(CString ServerIP)
|
|||||||
for( i=0; i < strlen(ProfileNames[1]); i++ )
|
for( i=0; i < strlen(ProfileNames[1]); i++ )
|
||||||
PlayerName.m_data[i] = ProfileNames[1][i];
|
PlayerName.m_data[i] = ProfileNames[1][i];
|
||||||
PlayerName.m_data[i] = 0;
|
PlayerName.m_data[i] = 0;
|
||||||
NetPlayerClient->SendPack( (char*) &PlayerName,20 );
|
NetPlayerClient->SendPack( (char*)&PlayerName, 20 );
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG->Info("Server Version: %d",m_ServerVersion);
|
LOG->Info("Server Version: %d", m_ServerVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -130,20 +129,16 @@ void NetworkSyncManager::StartUp()
|
|||||||
CString ServerIP;
|
CString ServerIP;
|
||||||
|
|
||||||
if( GetCommandlineArgument( "netip", &ServerIP ) )
|
if( GetCommandlineArgument( "netip", &ServerIP ) )
|
||||||
{
|
|
||||||
PostStartUp(ServerIP);
|
PostStartUp(ServerIP);
|
||||||
}
|
|
||||||
else if( GetCommandlineArgument( "listen" ) )
|
else if( GetCommandlineArgument( "listen" ) )
|
||||||
{
|
|
||||||
PostStartUp("LISTEN");
|
PostStartUp("LISTEN");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool NetworkSyncManager::Connect(const CString& addy, unsigned short port)
|
bool NetworkSyncManager::Connect(const CString& addy, unsigned short port)
|
||||||
{
|
{
|
||||||
LOG->Info("Beginning to connect");
|
LOG->Info("Beginning to connect");
|
||||||
if (port!=8765)
|
if (port != 8765)
|
||||||
return false;
|
return false;
|
||||||
//Make sure using port 8765
|
//Make sure using port 8765
|
||||||
//This may change in future versions
|
//This may change in future versions
|
||||||
@@ -163,7 +158,7 @@ bool NetworkSyncManager::Connect(const CString& addy, unsigned short port)
|
|||||||
bool NetworkSyncManager::Listen(unsigned short port)
|
bool NetworkSyncManager::Listen(unsigned short port)
|
||||||
{
|
{
|
||||||
LOG->Info("Beginning to Listen");
|
LOG->Info("Beginning to Listen");
|
||||||
if (port!=8765)
|
if (port != 8765)
|
||||||
return false;
|
return false;
|
||||||
//Make sure using port 8765
|
//Make sure using port 8765
|
||||||
//This may change in future versions
|
//This may change in future versions
|
||||||
@@ -179,7 +174,7 @@ bool NetworkSyncManager::Listen(unsigned short port)
|
|||||||
EZListener->bind(8765);
|
EZListener->bind(8765);
|
||||||
|
|
||||||
useSMserver = EZListener->listen();
|
useSMserver = EZListener->listen();
|
||||||
useSMserver = EZListener->accept( *NetPlayerClient); //Wait for someone to connect
|
useSMserver = EZListener->accept( *NetPlayerClient ); //Wait for someone to connect
|
||||||
|
|
||||||
EZListener->close(); //Kill Listener
|
EZListener->close(); //Kill Listener
|
||||||
delete EZListener;
|
delete EZListener;
|
||||||
@@ -260,17 +255,17 @@ void NetworkSyncManager::StartRequest()
|
|||||||
tSteps = g_CurStageStats.pSteps[PLAYER_1];
|
tSteps = g_CurStageStats.pSteps[PLAYER_1];
|
||||||
if (tSteps!=NULL)
|
if (tSteps!=NULL)
|
||||||
{
|
{
|
||||||
SendNetPack.m_step=tSteps->GetMeter();
|
SendNetPack.m_step = tSteps->GetMeter();
|
||||||
}
|
}
|
||||||
|
|
||||||
tSteps = g_CurStageStats.pSteps[PLAYER_2];
|
tSteps = g_CurStageStats.pSteps[PLAYER_2];
|
||||||
if (tSteps!=NULL)
|
if (tSteps!=NULL)
|
||||||
{
|
{
|
||||||
SendNetPack.m_step+=tSteps->GetMeter()*256;
|
SendNetPack.m_step += tSteps->GetMeter()*256;
|
||||||
}
|
}
|
||||||
SendNetPack.m_score = 0;
|
SendNetPack.m_score = 0;
|
||||||
SendNetPack.m_life=0;
|
SendNetPack.m_life = 0;
|
||||||
SendNetPack.m_combo=0;
|
SendNetPack.m_combo = 0;
|
||||||
|
|
||||||
NetPlayerClient->SendPack((char*)&SendNetPack, sizeof(netHolder));
|
NetPlayerClient->SendPack((char*)&SendNetPack, sizeof(netHolder));
|
||||||
|
|
||||||
@@ -301,30 +296,30 @@ void NetworkSyncManager::SendSongs()
|
|||||||
CString SongInfo;
|
CString SongInfo;
|
||||||
char toSend[1020]; //Standard buffer is 1024 and
|
char toSend[1020]; //Standard buffer is 1024 and
|
||||||
//we have to include 4 size bytes
|
//we have to include 4 size bytes
|
||||||
for (i=0;i<LogSongs.size();i++)
|
for (i=0; i<LogSongs.size(); i++)
|
||||||
{
|
{
|
||||||
Song * CSong = LogSongs[i];
|
Song * CSong = LogSongs[i];
|
||||||
SongInfo=char(1) + CSong->m_sGroupName;
|
SongInfo = char(1) + CSong->m_sGroupName;
|
||||||
SongInfo+=char(2) + CSong->GetTranslitMainTitle();
|
SongInfo += char(2) + CSong->GetTranslitMainTitle();
|
||||||
SongInfo+=char(3) + CSong->GetTranslitSubTitle();
|
SongInfo += char(3) + CSong->GetTranslitSubTitle();
|
||||||
SongInfo+=char(4) + CSong->GetTranslitArtist();
|
SongInfo += char(4) + CSong->GetTranslitArtist();
|
||||||
|
|
||||||
for (j=4;j<SongInfo.length()+4;j++)
|
for (j=4;j<SongInfo.length()+4;j++)
|
||||||
toSend[j] = SongInfo.c_str()[j-4];
|
toSend[j] = SongInfo.c_str()[j-4];
|
||||||
toSend[0]=char(35);
|
toSend[0] = char(35);
|
||||||
toSend[1]=char(0);
|
toSend[1] = char(0);
|
||||||
toSend[2]=char(0);
|
toSend[2] = char(0);
|
||||||
toSend[3]=char(0);
|
toSend[3] = char(0);
|
||||||
|
|
||||||
NetPlayerClient->SendPack (toSend,SongInfo.length()+4);
|
NetPlayerClient->SendPack(toSend, SongInfo.length() + 4);
|
||||||
}
|
}
|
||||||
toSend[0]=char(36);
|
toSend[0] = char(36);
|
||||||
NetPlayerClient->SendPack (toSend,4);
|
NetPlayerClient->SendPack(toSend, 4);
|
||||||
|
|
||||||
//Exit because this is ONLY for use with SMOnline
|
//Exit because this is ONLY for use with SMOnline
|
||||||
//If admins feel strongly, this can be exported
|
//If admins feel strongly, this can be exported
|
||||||
//to another command line, like "--exitfirst"
|
//to another command line, like "--exitfirst"
|
||||||
exit (0);
|
exit(0);
|
||||||
|
|
||||||
//NOTE TO ADMINS: I do not actually know the
|
//NOTE TO ADMINS: I do not actually know the
|
||||||
//safe way to exit stepmania, if you can, either tell me
|
//safe way to exit stepmania, if you can, either tell me
|
||||||
@@ -341,7 +336,6 @@ void NetworkSyncManager::DisplayStartupStatus()
|
|||||||
case 0:
|
case 0:
|
||||||
//Networking wasn't attepmpted
|
//Networking wasn't attepmpted
|
||||||
return;
|
return;
|
||||||
break;
|
|
||||||
case 1:
|
case 1:
|
||||||
sMessage = "Connect to server successful.";
|
sMessage = "Connect to server successful.";
|
||||||
break;
|
break;
|
||||||
@@ -354,9 +348,7 @@ void NetworkSyncManager::DisplayStartupStatus()
|
|||||||
|
|
||||||
void NetworkSyncManager::Update(float fDeltaTime)
|
void NetworkSyncManager::Update(float fDeltaTime)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Global and accessable from anywhere
|
//Global and accessable from anywhere
|
||||||
NetworkSyncManager *NSMAN;
|
NetworkSyncManager *NSMAN;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user