diff --git a/stepmania/src/ezsockets.cpp b/stepmania/src/ezsockets.cpp index e141a1cf38..9c6821046e 100644 --- a/stepmania/src/ezsockets.cpp +++ b/stepmania/src/ezsockets.cpp @@ -1,4 +1,6 @@ -#include "global.h" +//#include "global.h" +//Commented out because there is no StepMania here. + /******************************************* ezsockets.cpp -- Header for sockets.cpp Designed by Josh Allen and Charles @@ -14,10 +16,13 @@ ********************************************/ // We need the WinSock32 Library on Windows -#ifdef _WINDOWS +#if defined(WIN32) #pragma comment(lib,"wsock32.lib") #endif +#include //REMOVE SOON + + #include "ezsockets.h" EzSockets::EzSockets() @@ -77,7 +82,10 @@ bool EzSockets::listen() } // glibc already has socklen_t defined -#if !defined(LINUX) +// to whoever edited this: +// please do not assume LINUX is defined if you're compiling on linux! +// it will not compile properly. +#if defined(WIN32) typedef int socklen_t; #endif @@ -117,6 +125,42 @@ bool EzSockets::receiveLength( int &length ) { return true; } +int EzSockets::receive(char *data, int MAXlength) +{ + int x=0; + if ( !receiveLength(x)) + return false; + + int desc=1; + std::string outData; + char buf[4]; + + outData = ""; + + + + //YES! I know this is a crappy way to do it, but + //until someone tells me better... DON'T COMPLAIN + + while ((outData.length()0)) { + desc = ::recv( sock, buf, 1 , 0 ); + if (desc!=0) + outData+=buf[0]; + } + if (desc==0) + { + return false; + } + if (x>MAXlength) + { + return false; + } + + memcpy (data,outData.c_str(),x); + + return true; +} + bool EzSockets::receive( int &x ) { if ( !receiveLength(x) ) @@ -282,6 +326,45 @@ bool EzSockets::connect( const std::string& host, unsigned short port ) return desc >= 0; } +bool EzSockets::sendFlash (const std::string & inData) +{ + int inDataSize = inData.length(); + int desc = ::send( sock, inData.c_str(), inDataSize+1 , 0 ); + //Over-ride the C-string by one. + if (desc) + return (true); + else + return (false); +} + +std::string EzSockets::recvFlash () +{ + int desc=1; + std::string outData; + char buf[4]; + + outData = ""; + + + + //YES! I know this is a crappy way to do it, but + //until someone tells me better... DON'T COMPLAIN + + buf[0] = '\r'; //Put something in buf to stop while. + while ((buf[0] != '\0') && (desc>0)) { + desc = ::recv( sock, buf, 1 , 0 ); + if (desc!=0) + outData+=buf[0]; + } + if (desc==0) + { + outData = "999Data Failure"; + } + return outData; +} + + + long EzSockets::uAddr() { return addr.sin_addr.s_addr; diff --git a/stepmania/src/ezsockets.h b/stepmania/src/ezsockets.h index 65926793d9..90e96ca251 100644 --- a/stepmania/src/ezsockets.h +++ b/stepmania/src/ezsockets.h @@ -10,6 +10,8 @@ Modified by Charles Lohr for use on windows and Unix. + Modified by Charles Lohr for use with + Macromedia Flash. ********************************************/ #ifndef __EZSOCKETS_H @@ -31,6 +33,8 @@ #include #endif +using namespace std; + class EzSockets { private: @@ -64,6 +68,8 @@ class EzSockets { bool receive(std::vector &data); //Receive structure bool receive(int &x); + //Receive Structure (or other data) + int receive(char *data, int MAXlength); //Send string bool send(const std::string& data); //Send Structure (or other data) @@ -73,7 +79,12 @@ class EzSockets { //Connect to remote host //NOTE: YOU MUST PUT IN IP, NOT NAME bool connect(const std::string& host, unsigned short port); + + //Used for sending and receiving functions from flash + bool sendFlash (const std::string & inData); + std::string recvFlash (); + long uAddr(); //Kill socket void close();