#pragma once #if _MSC_VER > 1000 #pragma warning(disable:4146) #endif // _MSC_VER > 1000 #include #include #include #include class ENet_implementation { public: ENet_implementation(); ~ENet_implementation(); enum role {SERVER, CLIENT}; bool init( ENet_implementation::role role_, unsigned short port_, int maxClients_=10, int maxChannels_=2, int maxInBandwidth_=0, int maxOutBandwidth_=0 ); // client & server // Done bool connectTo( const char* remoteAddr_, int connectTimeout_ms_, int clientInfo_=0, int channelToAlloc_=2 ); // only as client // Done void sendPacket( ENetPacket* packet_, enet_uint8 channelID_, unsigned int peerID_=0, bool autoFlush_=false ); // by PeerID // Done void sendPacket( ENetPacket* packet_, enet_uint8 channelID_, std::string peerName_, bool autoFlush_=false ); // by peer name // Done void broadcastPacket( enet_uint8 channelID_, ENetPacket* packet_, bool autoFlush_=false ); // only as server. // Done void processEvents( int timeout_ms_ = 0 ); // Done virtual inline void onReceivePacket(ENetEvent* event_); virtual inline void onConnect(ENetEvent* event_); // This function will be called only by the host waiting for the connection. virtual inline void onDisconnect(ENetEvent* event_); protected: unsigned short port; ENet_implementation::role currentRole; static int activeENetInstances; bool serverInitialized; // shows if the complete server is initialized. (After init()) ENetAddress address; ENetHost* host; std::vector peerList; // client: only one peer to server, Server: multiple peers for all clients ENetEvent event; };