From 45c4577df2dd4cfa69b6a2a8b6ff1a385adef91b Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Wed, 17 Mar 2004 13:31:42 +0000 Subject: [PATCH] Clean up --- stepmania/src/NetworkSyncManager.cpp | 27 ++++++++++++--------------- stepmania/src/NetworkSyncManager.h | 10 +++------- stepmania/src/ezsockets.cpp | 12 ++++-------- stepmania/src/ezsockets.h | 4 ++-- 4 files changed, 21 insertions(+), 32 deletions(-) diff --git a/stepmania/src/NetworkSyncManager.cpp b/stepmania/src/NetworkSyncManager.cpp index 8513972fe0..12e07a09e1 100644 --- a/stepmania/src/NetworkSyncManager.cpp +++ b/stepmania/src/NetworkSyncManager.cpp @@ -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 tmp; //Temporary vector used by receive function when waiting diff --git a/stepmania/src/NetworkSyncManager.h b/stepmania/src/NetworkSyncManager.h index 746eea84b5..2bbbf560ee 100644 --- a/stepmania/src/NetworkSyncManager.h +++ b/stepmania/src/NetworkSyncManager.h @@ -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) diff --git a/stepmania/src/ezsockets.cpp b/stepmania/src/ezsockets.cpp index e9543836ac..0593b9d19d 100644 --- a/stepmania/src/ezsockets.cpp +++ b/stepmania/src/ezsockets.cpp @@ -161,7 +161,7 @@ bool EzSockets::receive(std::vector &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() { diff --git a/stepmania/src/ezsockets.h b/stepmania/src/ezsockets.h index b91c2fa374..65926793d9 100644 --- a/stepmania/src/ezsockets.h +++ b/stepmania/src/ezsockets.h @@ -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