1 | #pragma once |
---|
2 | #if _MSC_VER > 1000 |
---|
3 | #pragma warning(disable:4146) |
---|
4 | #endif // _MSC_VER > 1000 |
---|
5 | |
---|
6 | #include <enet/enet.h> |
---|
7 | #include <iostream> |
---|
8 | #include <string> |
---|
9 | #include <vector> |
---|
10 | |
---|
11 | |
---|
12 | |
---|
13 | class ENet_implementation |
---|
14 | { |
---|
15 | public: |
---|
16 | ENet_implementation(); |
---|
17 | ~ENet_implementation(); |
---|
18 | |
---|
19 | enum role {SERVER, CLIENT}; |
---|
20 | |
---|
21 | bool init( ENet_implementation::role role_, unsigned short port_, int maxClients_=10, int maxChannels_=2, int maxInBandwidth_=0, int maxOutBandwidth_=0 ); // client & server // Done |
---|
22 | bool connectTo( const char* remoteAddr_, int connectTimeout_ms_, int clientInfo_=0, int channelToAlloc_=2 ); // only as client // Done |
---|
23 | void sendPacket( ENetPacket* packet_, enet_uint8 channelID_, unsigned int peerID_=0, bool autoFlush_=false ); // by PeerID // Done |
---|
24 | void sendPacket( ENetPacket* packet_, enet_uint8 channelID_, std::string peerName_, bool autoFlush_=false ); // by peer name // Done |
---|
25 | void broadcastPacket( enet_uint8 channelID_, ENetPacket* packet_, bool autoFlush_=false ); // only as server. // Done |
---|
26 | void processEvents( int timeout_ms_ = 0 ); // Done |
---|
27 | |
---|
28 | virtual inline void onReceivePacket(ENetEvent* event_); |
---|
29 | virtual inline void onConnect(ENetEvent* event_); // This function will be called only by the host waiting for the connection. |
---|
30 | virtual inline void onDisconnect(ENetEvent* event_); |
---|
31 | |
---|
32 | protected: |
---|
33 | unsigned short port; |
---|
34 | ENet_implementation::role currentRole; |
---|
35 | static int activeENetInstances; |
---|
36 | bool serverInitialized; // shows if the complete server is initialized. (After init()) |
---|
37 | ENetAddress address; |
---|
38 | ENetHost* host; |
---|
39 | std::vector<ENetPeer*> peerList; // client: only one peer to server, Server: multiple peers for all clients |
---|
40 | ENetEvent event; |
---|
41 | }; |
---|