123456789101112131415161718192021222324252627282930313233343536373839
#ifndef __NETWORK_H__ #define __NETWORK_H__ #include <SDL/SDL_types.h> #include <SDL/SDL_net.h> #include "btree.h" #include <string> // For easy packet parsing #define GET_UINT32(x) (SDL_SwapBE32(*(Uint32*)(x))) #define GET_UINT16(x) (SDL_SwapBE16(*(Uint16*)(x))) #define GET_UINT8(x) (*(Uint8*)(x)) #define GET_SINT8(x) (*(Sint8*)(x)) class Network { public: Network(); ~Network(); void connect(string &host,Uint16 port); void connect(Uint32 ip,Uint16 port); void disconnect(); int ready(); int read(Uint8 *pvOut,int len); void write(Uint8 *pvIn,int len); TCPsocket uo; /**< Our socket to the server */ bool readCrypto; /**< whether or not we're decompressing */ private: bTree tree, /**< The big bTree for decompression */ *readCur; /**< Current location in the bTree */ SDLNet_SocketSet sockets; /**< Socket Set for testing activity */ int readBits; /**< Current bit read */ Uint16 readValue; /**< Current value read */ }; #endif