|
@@ -12,6 +12,8 @@ struct Server final {
|
|
|
typedef StringBuffer<256> Error;
|
|
|
|
|
|
class Client final {
|
|
|
+ friend class Server;
|
|
|
+
|
|
|
ENetPeer* peer;
|
|
|
int id;
|
|
|
|
|
@@ -27,6 +29,7 @@ struct Server final {
|
|
|
~Client();
|
|
|
|
|
|
int getId() const;
|
|
|
+ void send(OutPacket& p);
|
|
|
};
|
|
|
|
|
|
private:
|
|
@@ -53,7 +56,7 @@ public:
|
|
|
switch(e.type) {
|
|
|
case ENET_EVENT_TYPE_CONNECT: onConnect(e, consumer); break;
|
|
|
case ENET_EVENT_TYPE_RECEIVE:
|
|
|
- onPackage(e, consumer);
|
|
|
+ onPacket(e, consumer);
|
|
|
enet_packet_destroy(e.packet);
|
|
|
break;
|
|
|
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT:
|
|
@@ -65,6 +68,9 @@ public:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ void send(OutPacket& p);
|
|
|
+ void disconnect(Client& client);
|
|
|
+
|
|
|
private:
|
|
|
template<typename T>
|
|
|
void onConnect(ENetEvent& e, T& consumer) {
|
|
@@ -78,14 +84,14 @@ private:
|
|
|
memcpy(&(e.peer->data), &id, sizeof(id));
|
|
|
Client* client = clients.search(id);
|
|
|
if(client != nullptr) {
|
|
|
- consumer.onConnection(*client);
|
|
|
+ consumer.onConnect(*client);
|
|
|
} else {
|
|
|
error.clear().append("cannot find added client");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
template<typename T>
|
|
|
- void onPackage(ENetEvent& e, T& consumer) {
|
|
|
+ void onPacket(ENetEvent& e, T& consumer) {
|
|
|
if(e.peer->data == nullptr) {
|
|
|
error.clear().append("client without data sent package");
|
|
|
return;
|
|
@@ -95,7 +101,7 @@ private:
|
|
|
Client* client = clients.search(id);
|
|
|
if(client != nullptr) {
|
|
|
InPacket in(e.packet);
|
|
|
- consumer.onPackage(*client, in);
|
|
|
+ consumer.onPacket(*client, in);
|
|
|
} else {
|
|
|
error.clear().append("client with invalid id sent package");
|
|
|
}
|