diff options
| author | 2017-07-09 10:43:53 +0200 | |
|---|---|---|
| committer | 2017-07-16 21:29:41 +0200 | |
| commit | 35a0b32553a3bb3a7d66694511350fdc2ef698d9 (patch) | |
| tree | 1c195d0ea4146640785daeeca0fc98e7684059a1 | |
| parent | Network: Enable to send WifiPackets (diff) | |
| download | yuzu-35a0b32553a3bb3a7d66694511350fdc2ef698d9.tar.gz yuzu-35a0b32553a3bb3a7d66694511350fdc2ef698d9.tar.xz yuzu-35a0b32553a3bb3a7d66694511350fdc2ef698d9.zip | |
Network: Handle the disconnect of a client
Diffstat (limited to '')
| -rw-r--r-- | src/network/room.cpp | 19 |
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 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 5 | #include <atomic> | 6 | #include <atomic> |
| 6 | #include <random> | 7 | #include <random> |
| 7 | #include <thread> | 8 | #include <thread> |
| @@ -104,6 +105,12 @@ public: | |||
| 104 | * @param event The ENet event containing the data | 105 | * @param event The ENet event containing the data |
| 105 | */ | 106 | */ |
| 106 | void HandleWifiPacket(const ENetEvent* event); | 107 | void HandleWifiPacket(const ENetEvent* event); |
| 108 | |||
| 109 | /** | ||
| 110 | * Removes the client from the members list if it was in it and announces the change | ||
| 111 | * to all other clients. | ||
| 112 | */ | ||
| 113 | void HandleClientDisconnection(ENetPeer* client); | ||
| 107 | }; | 114 | }; |
| 108 | 115 | ||
| 109 | // RoomImpl | 116 | // RoomImpl |
| @@ -125,7 +132,7 @@ void Room::RoomImpl::ServerLoop() { | |||
| 125 | enet_packet_destroy(event.packet); | 132 | enet_packet_destroy(event.packet); |
| 126 | break; | 133 | break; |
| 127 | case ENET_EVENT_TYPE_DISCONNECT: | 134 | case ENET_EVENT_TYPE_DISCONNECT: |
| 128 | // TODO(B3N30): Handle the disconnect from a client | 135 | HandleClientDisconnection(event.peer); |
| 129 | break; | 136 | break; |
| 130 | } | 137 | } |
| 131 | } | 138 | } |
| @@ -264,6 +271,16 @@ void Room::RoomImpl::HandleWifiPacket(const ENetEvent* event) { | |||
| 264 | enet_host_flush(server); | 271 | enet_host_flush(server); |
| 265 | } | 272 | } |
| 266 | 273 | ||
| 274 | void Room::RoomImpl::HandleClientDisconnection(ENetPeer* client) { | ||
| 275 | // Remove the client from the members list. | ||
| 276 | members.erase(std::remove_if(members.begin(), members.end(), | ||
| 277 | [&](const Member& member) { return member.peer == client; }), | ||
| 278 | members.end()); | ||
| 279 | |||
| 280 | // Announce the change to all clients. | ||
| 281 | BroadcastRoomInformation(); | ||
| 282 | } | ||
| 283 | |||
| 267 | // Room | 284 | // Room |
| 268 | Room::Room() : room_impl{std::make_unique<RoomImpl>()} {} | 285 | Room::Room() : room_impl{std::make_unique<RoomImpl>()} {} |
| 269 | 286 | ||