New Protocol, but still buggy.
Removed SendSongsToServer.
This commit is contained in:
@@ -12,7 +12,6 @@ bool NetworkSyncManager::Connect(const CString& addy, unsigned short port) { ret
|
|||||||
void NetworkSyncManager::ReportScore(int playerID, int step, int score, int combo) { }
|
void NetworkSyncManager::ReportScore(int playerID, int step, int score, int combo) { }
|
||||||
void NetworkSyncManager::ReportSongOver() { }
|
void NetworkSyncManager::ReportSongOver() { }
|
||||||
void NetworkSyncManager::StartRequest() { }
|
void NetworkSyncManager::StartRequest() { }
|
||||||
void NetworkSyncManager::SendSongs() { }
|
|
||||||
void NetworkSyncManager::DisplayStartupStatus() { }
|
void NetworkSyncManager::DisplayStartupStatus() { }
|
||||||
void NetworkSyncManager::Update( float fDeltaTime ) { }
|
void NetworkSyncManager::Update( float fDeltaTime ) { }
|
||||||
|
|
||||||
@@ -33,6 +32,7 @@ void NetworkSyncManager::Update( float fDeltaTime ) { }
|
|||||||
#include "SongManager.h"
|
#include "SongManager.h"
|
||||||
#include "GameState.h"
|
#include "GameState.h"
|
||||||
#include "StageStats.h"
|
#include "StageStats.h"
|
||||||
|
#include "String.h"
|
||||||
#include "Steps.h"
|
#include "Steps.h"
|
||||||
|
|
||||||
NetworkSyncManager::NetworkSyncManager()
|
NetworkSyncManager::NetworkSyncManager()
|
||||||
@@ -83,46 +83,39 @@ void NetworkSyncManager::PostStartUp(CString ServerIP)
|
|||||||
LOG->Warn( "Listen() failed" );
|
LOG->Warn( "Listen() failed" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useSMserver = true;
|
useSMserver = true;
|
||||||
|
|
||||||
m_startupStatus = 1; //Connection attepmpt sucessful
|
m_startupStatus = 1; //Connection attepmpt sucessful
|
||||||
LOG->Info("CNConnected!");
|
|
||||||
int ClientCommand=3;
|
|
||||||
NetPlayerClient->SendPack((char*) &ClientCommand, 4);
|
|
||||||
LOG->Info("CNCHECKPOINT");
|
|
||||||
|
|
||||||
NetPlayerClient->ReadData((char*)&m_ServerVersion, 4);
|
|
||||||
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
|
||||||
|
|
||||||
|
ClearPacket(m_packet);
|
||||||
|
|
||||||
|
Write1(m_packet,2); //Hello Packet
|
||||||
|
|
||||||
|
Write1(m_packet,NETPROTOCOLVERSION);
|
||||||
|
int ctr = 2 * 16 + 0;
|
||||||
|
Write1(m_packet,ctr);
|
||||||
|
|
||||||
vector <CString> ProfileNames;
|
vector <CString> ProfileNames;
|
||||||
PROFILEMAN->GetLocalProfileNames(ProfileNames);
|
PROFILEMAN->GetLocalProfileNames(ProfileNames);
|
||||||
|
|
||||||
netName PlayerName;
|
|
||||||
if( ProfileNames.size() > 0 )
|
if( ProfileNames.size() > 0 )
|
||||||
{
|
WriteNT(m_packet,ProfileNames[0]);
|
||||||
PlayerName.m_packID = 30;
|
|
||||||
unsigned i;
|
|
||||||
for( i=0; i < strlen(ProfileNames[0]); i++ )
|
|
||||||
PlayerName.m_data[i] = ProfileNames[0][i];
|
|
||||||
PlayerName.m_data[i] = 0;
|
|
||||||
NetPlayerClient->SendPack((char*)&PlayerName, 20);
|
|
||||||
}
|
|
||||||
if( ProfileNames.size() > 1 )
|
if( ProfileNames.size() > 1 )
|
||||||
{
|
WriteNT(m_packet,ProfileNames[0]);
|
||||||
PlayerName.m_packID = 31;
|
|
||||||
unsigned i=0;
|
|
||||||
for( i=0; i < strlen(ProfileNames[1]); i++ )
|
|
||||||
PlayerName.m_data[i] = ProfileNames[1][i];
|
|
||||||
PlayerName.m_data[i] = 0;
|
|
||||||
NetPlayerClient->SendPack( (char*)&PlayerName, 20 );
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG->Info("Server Version: %d", m_ServerVersion);
|
NetPlayerClient->SendPack((char*)m_packet.Data,m_packet.Position);
|
||||||
|
|
||||||
|
NetPlayerClient->ReadPack((char*)m_packet.Data,NETMAXBUFFERSIZE);
|
||||||
|
|
||||||
|
m_ServerVersion = Read1(m_packet);
|
||||||
|
CString m_ServerName = ReadNT(m_packet);
|
||||||
|
|
||||||
|
LOG->Info("Server Version: %d %s", m_ServerVersion, m_ServerName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -193,20 +186,23 @@ void NetworkSyncManager::ReportScore(int playerID, int step, int score, int comb
|
|||||||
if (!useSMserver) //Make sure that we are using the network
|
if (!useSMserver) //Make sure that we are using the network
|
||||||
return;
|
return;
|
||||||
|
|
||||||
netHolder SendNetPack; //Create packet to send to server
|
ClearPacket(m_packet);
|
||||||
|
|
||||||
SendNetPack.m_playerID = playerID;
|
Write1(m_packet,5);
|
||||||
SendNetPack.m_combo=combo;
|
unsigned char ctr = playerID * 16 + step - 1;
|
||||||
SendNetPack.m_score=score; //Load packet with appropriate info
|
Write1(m_packet,ctr);
|
||||||
SendNetPack.m_step=step-1;
|
|
||||||
|
|
||||||
int CurGrade = g_CurStageStats.GetGrade((PlayerNumber)playerID);
|
ctr = g_CurStageStats.GetGrade((PlayerNumber)playerID)*16;
|
||||||
|
|
||||||
//Should be cleaned up
|
Write1(m_packet,ctr);
|
||||||
SendNetPack.m_life=m_playerLife[playerID] + CurGrade*65536;
|
|
||||||
|
|
||||||
//Send packet to server
|
Write4(m_packet,score);
|
||||||
NetPlayerClient->SendPack((char*)&SendNetPack, sizeof(netHolder));
|
|
||||||
|
Write2(m_packet,combo);
|
||||||
|
|
||||||
|
Write2(m_packet,m_playerLife[playerID]);
|
||||||
|
|
||||||
|
NetPlayerClient->SendPack((char*)m_packet.Data, m_packet.Position);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,18 +212,11 @@ void NetworkSyncManager::ReportSongOver()
|
|||||||
if (!useSMserver) //Make sure that we are using the network
|
if (!useSMserver) //Make sure that we are using the network
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
netHolder SendNetPack; //Create packet to send to server
|
ClearPacket(m_packet);
|
||||||
|
|
||||||
SendNetPack.m_playerID = 21; // Song over Packet player ID
|
Write1(m_packet,4);
|
||||||
|
|
||||||
|
NetPlayerClient->SendPack((char*)&m_packet.Data, m_packet.Position);
|
||||||
SendNetPack.m_step=0;
|
|
||||||
SendNetPack.m_score=0;
|
|
||||||
SendNetPack.m_combo=0;
|
|
||||||
SendNetPack.m_life=0;
|
|
||||||
|
|
||||||
|
|
||||||
NetPlayerClient->SendPack((char*)&SendNetPack, sizeof(netHolder));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,99 +225,43 @@ void NetworkSyncManager::StartRequest()
|
|||||||
if (!useSMserver)
|
if (!useSMserver)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
//If it's going into demonstration (or jukebox) mode, do not
|
|
||||||
//bother to sync.
|
|
||||||
if (GAMESTATE->m_bDemonstrationOrJukebox)
|
if (GAMESTATE->m_bDemonstrationOrJukebox)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
|
|
||||||
char tmp[4]; //Temporary vector used by receive function when waiting
|
|
||||||
|
|
||||||
LOG->Trace("Requesting Start from Server.");
|
LOG->Trace("Requesting Start from Server.");
|
||||||
|
|
||||||
netHolder SendNetPack;
|
ClearPacket(m_packet);
|
||||||
|
|
||||||
SendNetPack.m_playerID = 20; // Song Start Request Packet player ID
|
Write1(m_packet,3);
|
||||||
|
|
||||||
//Report Step difficulties
|
unsigned char ctr=0;
|
||||||
|
|
||||||
Steps * tSteps;
|
Steps * tSteps;
|
||||||
SendNetPack.m_step = 0;
|
|
||||||
tSteps = g_CurStageStats.pSteps[PLAYER_1];
|
tSteps = g_CurStageStats.pSteps[PLAYER_1];
|
||||||
if (tSteps!=NULL)
|
if (tSteps!=NULL)
|
||||||
{
|
ctr = ctr+tSteps->GetMeter()*16;
|
||||||
SendNetPack.m_step = tSteps->GetMeter();
|
|
||||||
}
|
|
||||||
|
|
||||||
tSteps = g_CurStageStats.pSteps[PLAYER_2];
|
tSteps = g_CurStageStats.pSteps[PLAYER_2];
|
||||||
if (tSteps!=NULL)
|
if (tSteps!=NULL)
|
||||||
{
|
ctr = ctr+tSteps->GetMeter();
|
||||||
SendNetPack.m_step += tSteps->GetMeter()*256;
|
|
||||||
}
|
|
||||||
SendNetPack.m_score = 0;
|
|
||||||
SendNetPack.m_life = 0;
|
|
||||||
SendNetPack.m_combo = 0;
|
|
||||||
|
|
||||||
NetPlayerClient->SendPack((char*)&SendNetPack, sizeof(netHolder));
|
Write1(m_packet,ctr);
|
||||||
|
|
||||||
|
WriteNT(m_packet,GAMESTATE->m_pCurSong->m_sMainTitle);
|
||||||
|
WriteNT(m_packet,GAMESTATE->m_pCurSong->m_sSubTitle);
|
||||||
|
WriteNT(m_packet,GAMESTATE->m_pCurSong->m_sArtist);
|
||||||
|
|
||||||
|
NetPlayerClient->SendPack((char*)&m_packet.Data, m_packet.Position);
|
||||||
|
|
||||||
LOG->Trace("Waiting for RECV");
|
LOG->Trace("Waiting for RECV");
|
||||||
|
|
||||||
|
ClearPacket(m_packet);
|
||||||
//Block until go is recieved.
|
//Block until go is recieved.
|
||||||
NetPlayerClient->ReadData((char *)tmp, 4);
|
NetPlayerClient->ReadPack((char *)&m_packet, NETMAXBUFFERSIZE);
|
||||||
|
|
||||||
LOG->Trace("Starting Game.");
|
//Ignore this packet for now
|
||||||
}
|
}
|
||||||
|
|
||||||
//This must be executed after NSMAN was started.
|
|
||||||
|
|
||||||
//this is for use with SMOnline.
|
|
||||||
//In order to gaurentee song title and group names
|
|
||||||
//line up, SM will be started and load, and then
|
|
||||||
//send all info to the local client.
|
|
||||||
//This information will be then relayed to the
|
|
||||||
//SMOnline server.
|
|
||||||
void NetworkSyncManager::SendSongs()
|
|
||||||
{
|
|
||||||
if (!useSMserver)
|
|
||||||
return ;
|
|
||||||
|
|
||||||
vector <Song *> LogSongs;
|
|
||||||
LogSongs = SONGMAN->GetAllSongs();
|
|
||||||
unsigned i,j;
|
|
||||||
CString SongInfo;
|
|
||||||
char toSend[1020]; //Standard buffer is 1024 and
|
|
||||||
//we have to include 4 size bytes
|
|
||||||
for (i=0; i<LogSongs.size(); i++)
|
|
||||||
{
|
|
||||||
Song * CSong = LogSongs[i];
|
|
||||||
SongInfo = char(1) + CSong->m_sGroupName;
|
|
||||||
SongInfo += char(2) + CSong->GetTranslitMainTitle();
|
|
||||||
SongInfo += char(3) + CSong->GetTranslitSubTitle();
|
|
||||||
SongInfo += char(4) + CSong->GetTranslitArtist();
|
|
||||||
|
|
||||||
for (j=4;j<SongInfo.length()+4;j++)
|
|
||||||
toSend[j] = SongInfo.c_str()[j-4];
|
|
||||||
toSend[0] = char(35);
|
|
||||||
toSend[1] = char(0);
|
|
||||||
toSend[2] = char(0);
|
|
||||||
toSend[3] = char(0);
|
|
||||||
|
|
||||||
NetPlayerClient->SendPack(toSend, SongInfo.length() + 4);
|
|
||||||
}
|
|
||||||
toSend[0] = char(36);
|
|
||||||
NetPlayerClient->SendPack(toSend, 4);
|
|
||||||
|
|
||||||
//Exit because this is ONLY for use with SMOnline
|
|
||||||
//If admins feel strongly, this can be exported
|
|
||||||
//to another command line, like "--exitfirst"
|
|
||||||
exit(0);
|
|
||||||
|
|
||||||
//NOTE TO ADMINS: I do not actually know the
|
|
||||||
//safe way to exit stepmania, if you can, either tell me
|
|
||||||
//or do it, please?
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void NetworkSyncManager::DisplayStartupStatus()
|
void NetworkSyncManager::DisplayStartupStatus()
|
||||||
{
|
{
|
||||||
CString sMessage("");
|
CString sMessage("");
|
||||||
@@ -351,8 +284,90 @@ void NetworkSyncManager::DisplayStartupStatus()
|
|||||||
void NetworkSyncManager::Update(float fDeltaTime)
|
void NetworkSyncManager::Update(float fDeltaTime)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned char NetworkSyncManager::Read1(NetPacket &Packet)
|
||||||
|
{
|
||||||
|
if (Packet.Position>=NETMAXBUFFERSIZE)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return Packet.Data[Packet.Position++];
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned short int NetworkSyncManager::Read2(NetPacket &Packet)
|
||||||
|
{
|
||||||
|
if (Packet.Position>=NETMAXBUFFERSIZE-1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
unsigned short int Temp;
|
||||||
|
memcpy((void *)&Temp,(void *)*(&Packet.Data + Packet.Position),2);
|
||||||
|
Packet.Position+=2;
|
||||||
|
return ntohs(Temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int NetworkSyncManager::Read4(NetPacket &Packet)
|
||||||
|
{
|
||||||
|
if (Packet.Position>=NETMAXBUFFERSIZE-3)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
unsigned int Temp;
|
||||||
|
memcpy((void *)&Temp,(void *)(&Packet.Data + Packet.Position),4);
|
||||||
|
Packet.Position+=2;
|
||||||
|
return ntohl(Temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
CString NetworkSyncManager::ReadNT(NetPacket &Packet)
|
||||||
|
{
|
||||||
|
int Orig=Packet.Position;
|
||||||
|
CString TempStr;
|
||||||
|
while ((Packet.Position<NETMAXBUFFERSIZE)&& (((char*)Packet.Data)[Packet.Position]!=0))
|
||||||
|
TempStr+=(char)Packet.Data[Packet.Position++];
|
||||||
|
|
||||||
|
Packet.Position++;
|
||||||
|
return TempStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void NetworkSyncManager::Write1(NetPacket &Packet, unsigned char Data)
|
||||||
|
{
|
||||||
|
if (Packet.Position>=NETMAXBUFFERSIZE)
|
||||||
|
return;
|
||||||
|
memcpy((void*)(&Packet.Data[Packet.Position]),(void *)&Data,1);
|
||||||
|
Packet.Position++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkSyncManager::Write2(NetPacket &Packet, unsigned short int Data)
|
||||||
|
{
|
||||||
|
if (Packet.Position>=NETMAXBUFFERSIZE-1)
|
||||||
|
return;
|
||||||
|
Data = htons(Data);
|
||||||
|
memcpy((void*)(&Packet.Data[Packet.Position]),(void *)&Data,2);
|
||||||
|
Packet.Position+=2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkSyncManager::Write4(NetPacket &Packet, unsigned long Data)
|
||||||
|
{
|
||||||
|
if (Packet.Position>=NETMAXBUFFERSIZE-3)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
Data = htonl(Data);
|
||||||
|
memcpy((void*)(&Packet.Data[Packet.Position]),(void *)&Data,4);
|
||||||
|
Packet.Position+=4;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkSyncManager::WriteNT(NetPacket &Packet, CString Data)
|
||||||
|
{
|
||||||
|
int index=0;
|
||||||
|
while ((Packet.Position<NETMAXBUFFERSIZE)&&(index<Data.GetLength()))
|
||||||
|
Packet.Data[Packet.Position++] = (unsigned char)(Data.c_str()[index++]);
|
||||||
|
//Is it proper to do "(unsigned char)(Data.c_str()[index++])"?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (c) 2003-2004 Charles Lohr, Joshua Allen
|
* (c) 2003-2004 Charles Lohr, Joshua Allen
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
|
|
||||||
#include "PlayerNumber.h"
|
#include "PlayerNumber.h"
|
||||||
|
|
||||||
|
const int NETPROTOCOLVERSION=1;
|
||||||
|
const int NETMAXBUFFERSIZE=1020; //1024 - 4 bytes for EzSockets
|
||||||
|
|
||||||
class EzSockets;
|
class EzSockets;
|
||||||
|
|
||||||
class NetworkSyncManager
|
class NetworkSyncManager
|
||||||
@@ -18,7 +21,6 @@ public:
|
|||||||
void ReportSongOver(); //Report to server that song is over
|
void ReportSongOver(); //Report to server that song is over
|
||||||
void StartRequest(); //Request a start. Block until granted.
|
void StartRequest(); //Request a start. Block until granted.
|
||||||
bool Connect(const CString& addy, unsigned short port); // Connect to SM Server
|
bool Connect(const CString& addy, unsigned short port); // Connect to SM Server
|
||||||
void SendSongs(); //Send song list to server (And exit)
|
|
||||||
|
|
||||||
void PostStartUp(CString ServerIP);
|
void PostStartUp(CString ServerIP);
|
||||||
|
|
||||||
@@ -28,11 +30,12 @@ public:
|
|||||||
|
|
||||||
int m_playerLife[NUM_PLAYERS]; //Life
|
int m_playerLife[NUM_PLAYERS]; //Life
|
||||||
|
|
||||||
|
|
||||||
void Update(float fDeltaTime);
|
void Update(float fDeltaTime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if !defined(WITHOUT_NETWORKING)
|
#if !defined(WITHOUT_NETWORKING)
|
||||||
|
|
||||||
|
|
||||||
void StartUp();
|
void StartUp();
|
||||||
|
|
||||||
int m_playerID; //these are currently unused, but need to stay
|
int m_playerID; //these are currently unused, but need to stay
|
||||||
@@ -42,6 +45,8 @@ private:
|
|||||||
|
|
||||||
int m_startupStatus; //Used to see if attempt was sucessful or not.
|
int m_startupStatus; //Used to see if attempt was sucessful or not.
|
||||||
|
|
||||||
|
CString m_ServerName;
|
||||||
|
|
||||||
bool useSMserver;
|
bool useSMserver;
|
||||||
|
|
||||||
EzSockets *NetPlayerClient;
|
EzSockets *NetPlayerClient;
|
||||||
@@ -51,29 +56,32 @@ private:
|
|||||||
bool Listen(unsigned short port);
|
bool Listen(unsigned short port);
|
||||||
|
|
||||||
|
|
||||||
struct netHolder //Data structure used for sending data to server
|
//This is it's own type, so that more info can
|
||||||
|
//be put at the end of it; after the data.
|
||||||
|
struct NetPacket
|
||||||
{
|
{
|
||||||
|
unsigned char Data[NETMAXBUFFERSIZE]; //Data
|
||||||
|
|
||||||
//NOTICE: Order of variables in this struct matters
|
int Position; //Other info
|
||||||
//if order is changed, server would need to be re-written
|
|
||||||
int m_playerID; //PID (also used for Commands)
|
|
||||||
int m_step; //SID (StepID, 0-6 for Miss to Marv, 7,8 for boo and ok)
|
|
||||||
int m_score; //Player's Score
|
|
||||||
int m_combo; //Player's Current Combo
|
|
||||||
int m_life; //Player's Life (AND GRADE)
|
|
||||||
//m_life = [16-bit int life] <- LSB [16-bit int grade] <-MSB
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct netName //Data structure used for 16-character strings.
|
//We only want to create this once per instance.
|
||||||
{
|
//No need to allocate and deallocate one all the time.
|
||||||
int m_packID;
|
NetPacket m_packet;
|
||||||
char m_data[16];
|
|
||||||
};
|
//Commands used to operate on NetPackets
|
||||||
|
unsigned char Read1(NetPacket &Packet);
|
||||||
|
unsigned short int Read2(NetPacket &Packet);
|
||||||
|
unsigned int Read4(NetPacket &Packet);
|
||||||
|
CString ReadNT(NetPacket &Packet);
|
||||||
|
|
||||||
|
void Write1(NetPacket &Packet, unsigned char Data);
|
||||||
|
void Write2(NetPacket &Packet, unsigned short int Data);
|
||||||
|
void Write4(NetPacket &Packet, unsigned long Data);
|
||||||
|
void WriteNT(NetPacket &Packet, CString Data);
|
||||||
|
|
||||||
|
inline void ClearPacket(NetPacket &Packet) { memset((void*)(&Packet),0, sizeof(NetPacket)); }
|
||||||
|
|
||||||
struct netHolderFlash
|
|
||||||
{
|
|
||||||
char data[73];
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user