Clean up
This commit is contained in:
@@ -32,10 +32,10 @@ NetworkSyncManager::~NetworkSyncManager ()
|
||||
delete NetPlayerClient;
|
||||
}
|
||||
|
||||
int NetworkSyncManager::Connect(char * addy, unsigned short port)
|
||||
bool NetworkSyncManager::Connect(const CString& addy, unsigned short port)
|
||||
{
|
||||
if (port!=8765)
|
||||
return -1;
|
||||
return false;
|
||||
//Make sure using port 8765
|
||||
//This may change in future versions
|
||||
//It is this way now for protocol's purpose.
|
||||
@@ -43,22 +43,19 @@ int NetworkSyncManager::Connect(char * addy, unsigned short port)
|
||||
|
||||
//Since under non-lan conditions, the client
|
||||
//will be connecting to localhost, this port does not matter.
|
||||
|
||||
/* What do you mean it doesn't matter if you are connecting to localhost?
|
||||
* Also, when does it ever connect to localhost?
|
||||
* -- Steve
|
||||
*/
|
||||
|
||||
NetPlayerClient->create(); //Initilize Socket
|
||||
|
||||
if(!NetPlayerClient->connect(addy,port)) {
|
||||
useSMserver = false; //If connection to socket fails, tell
|
||||
//other network functions to not do anything
|
||||
} else {
|
||||
useSMserver = 1; //Utilize other network funtions
|
||||
}
|
||||
return 1;
|
||||
useSMserver = NetPlayerClient->connect(addy, port);
|
||||
|
||||
return useSMserver;
|
||||
}
|
||||
|
||||
void NetworkSyncManager::ReportScore(int playerID, int step, int score, int combo)
|
||||
{
|
||||
if (useSMserver!=1) //Make sure that we are using the network
|
||||
if (!useSMserver) //Make sure that we are using the network
|
||||
return;
|
||||
|
||||
netHolder SendNetPack; //Create packet to send to server
|
||||
@@ -74,7 +71,7 @@ void NetworkSyncManager::ReportScore(int playerID, int step, int score, int comb
|
||||
|
||||
void NetworkSyncManager::ReportSongOver()
|
||||
{
|
||||
if (useSMserver!=1) //Make sure that we are using the network
|
||||
if (!useSMserver) //Make sure that we are using the network
|
||||
return ;
|
||||
|
||||
netHolder SendNetPack; //Create packet to send to server
|
||||
@@ -90,7 +87,7 @@ void NetworkSyncManager::ReportSongOver()
|
||||
|
||||
void NetworkSyncManager::StartRequest()
|
||||
{
|
||||
if (useSMserver!=1)
|
||||
if (!useSMserver)
|
||||
return ;
|
||||
|
||||
vector <char> tmp; //Temporary vector used by receive function when waiting
|
||||
|
||||
@@ -21,16 +21,13 @@ public:
|
||||
NetworkSyncManager(int argc, char **argv);
|
||||
~NetworkSyncManager();
|
||||
|
||||
//If "useSMserver" then send score to server
|
||||
void ReportScore(int playerID, int step, int score, int combo);
|
||||
//If "useSMserver" then send score to server
|
||||
|
||||
void ReportSongOver(); //Report to server that song is over
|
||||
|
||||
void StartRequest(); //Request a start. Block until granted.
|
||||
bool Connect(const CString& addy, unsigned short port); // Connect to SM Server
|
||||
|
||||
int Connect(char * addy, unsigned short port);
|
||||
//Connect to SM Server
|
||||
|
||||
private:
|
||||
int m_playerID; //these are currently unused, but need to stay
|
||||
int m_step;
|
||||
int m_score;
|
||||
@@ -38,7 +35,6 @@ public:
|
||||
bool useSMserver;
|
||||
EzSockets *NetPlayerClient;
|
||||
|
||||
private:
|
||||
struct netHolder //Data structure used for sending data to server
|
||||
{
|
||||
int m_playerID; //PID (also used for Commands)
|
||||
|
||||
@@ -161,7 +161,7 @@ bool EzSockets::receive(std::vector<char> &data) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EzSockets::send(std::string data) {
|
||||
bool EzSockets::send(const std::string& data) {
|
||||
/* First send send the length of the data to the
|
||||
server. Then if the length is less than or equal
|
||||
to the 1024 then send data in one sendData()
|
||||
@@ -257,10 +257,9 @@ bool EzSockets::sendData(char data[1024], int size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EzSockets::connect(std::string host, unsigned short port) {
|
||||
if (!check()) {
|
||||
bool EzSockets::connect(const std::string& host, unsigned short port) {
|
||||
if (!check())
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(WIN32)
|
||||
struct hostent* phe;
|
||||
@@ -278,10 +277,7 @@ bool EzSockets::connect(std::string host, unsigned short port) {
|
||||
int desc = ::connect(sock,(struct sockaddr *)&addr,sizeof(addr));
|
||||
#endif
|
||||
|
||||
if (desc < 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return desc >= 0;
|
||||
}
|
||||
|
||||
long EzSockets::uAddr() {
|
||||
|
||||
@@ -65,14 +65,14 @@ class EzSockets {
|
||||
//Receive structure
|
||||
bool receive(int &x);
|
||||
//Send string
|
||||
bool send(std::string data);
|
||||
bool send(const std::string& data);
|
||||
//Send Structure (or other data)
|
||||
bool send(char *data, int length);
|
||||
//Send Integer
|
||||
bool send(int x);
|
||||
//Connect to remote host
|
||||
//NOTE: YOU MUST PUT IN IP, NOT NAME
|
||||
bool connect(std::string host, unsigned short port);
|
||||
bool connect(const std::string& host, unsigned short port);
|
||||
|
||||
long uAddr();
|
||||
//Kill socket
|
||||
|
||||
Reference in New Issue
Block a user