summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorB3n30 <benediktthomas@gmail.com>2017-07-09 10:43:53 +0200
committerB3n30 <benediktthomas@gmail.com>2017-07-16 21:29:41 +0200
commit35a0b32553a3bb3a7d66694511350fdc2ef698d9 (patch)
tree1c195d0ea4146640785daeeca0fc98e7684059a1 /src/network
parentNetwork: Enable to send WifiPackets (diff)
downloadyuzu-35a0b32553a3bb3a7d66694511350fdc2ef698d9.tar
yuzu-35a0b32553a3bb3a7d66694511350fdc2ef698d9.tar.gz
yuzu-35a0b32553a3bb3a7d66694511350fdc2ef698d9.tar.bz2
yuzu-35a0b32553a3bb3a7d66694511350fdc2ef698d9.tar.lz
yuzu-35a0b32553a3bb3a7d66694511350fdc2ef698d9.tar.xz
yuzu-35a0b32553a3bb3a7d66694511350fdc2ef698d9.tar.zst
yuzu-35a0b32553a3bb3a7d66694511350fdc2ef698d9.zip
Diffstat (limited to 'src/network')
-rw-r--r--src/network/room.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/network/room.cpp b/src/network/room.cpp
index 3caa3aeae..6dc7db341 100644
--- a/src/network/room.cpp
+++ b/src/network/room.cpp
@@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include <algorithm>
#include <atomic>
#include <random>
#include <thread>
@@ -104,6 +105,12 @@ public:
* @param event The ENet event containing the data
*/
void HandleWifiPacket(const ENetEvent* event);
+
+ /**
+ * Removes the client from the members list if it was in it and announces the change
+ * to all other clients.
+ */
+ void HandleClientDisconnection(ENetPeer* client);
};
// RoomImpl
@@ -125,7 +132,7 @@ void Room::RoomImpl::ServerLoop() {
enet_packet_destroy(event.packet);
break;
case ENET_EVENT_TYPE_DISCONNECT:
- // TODO(B3N30): Handle the disconnect from a client
+ HandleClientDisconnection(event.peer);
break;
}
}
@@ -264,6 +271,16 @@ void Room::RoomImpl::HandleWifiPacket(const ENetEvent* event) {
enet_host_flush(server);
}
+void Room::RoomImpl::HandleClientDisconnection(ENetPeer* client) {
+ // Remove the client from the members list.
+ members.erase(std::remove_if(members.begin(), members.end(),
+ [&](const Member& member) { return member.peer == client; }),
+ members.end());
+
+ // Announce the change to all clients.
+ BroadcastRoomInformation();
+}
+
// Room
Room::Room() : room_impl{std::make_unique<RoomImpl>()} {}