#ifndef CLIENT_H #define CLIENT_H #include "network/ENet.h" #include "network/Packet.h" #include "utils/StringBuffer.h" class Client final { typedef enet_uint16 Port; typedef StringBuffer<256> Error; private: ENetHost* client; ENetPeer* connection; Error error; public: Client(); Client(const Client&) = delete; Client(Client&&) = delete; ~Client(); Client& operator=(const Client&) = delete; Client& operator=(Client&&) = delete; bool hasError() const; const Error& getError() const; bool connect(const char* server, Port port, int timeout); void disconnect(); template void consumeEvents(T& consumer) { (void)consumer; ENetEvent e; while(enet_host_service(client, &e, 0) > 0) { switch(e.type) { case ENET_EVENT_TYPE_CONNECT: std::cout << "1\n"; break; case ENET_EVENT_TYPE_RECEIVE: std::cout << "2\n"; break; case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT: case ENET_EVENT_TYPE_DISCONNECT: std::cout << "3\n"; break; case ENET_EVENT_TYPE_NONE: std::cout << "4\n"; return; } } } void send(OutPacket& p); }; #endif