diff options
Diffstat (limited to '')
| -rw-r--r-- | src/network/room.cpp | 21 | ||||
| -rw-r--r-- | src/network/room_member.cpp | 7 | ||||
| -rw-r--r-- | src/network/room_member.h | 3 |
3 files changed, 28 insertions, 3 deletions
diff --git a/src/network/room.cpp b/src/network/room.cpp index da1679312..3f72d7cbe 100644 --- a/src/network/room.cpp +++ b/src/network/room.cpp | |||
| @@ -85,6 +85,11 @@ public: | |||
| 85 | void SendJoinSuccess(ENetPeer* client, MacAddress mac_address); | 85 | void SendJoinSuccess(ENetPeer* client, MacAddress mac_address); |
| 86 | 86 | ||
| 87 | /** | 87 | /** |
| 88 | * Notifies the members that the room is closed, | ||
| 89 | */ | ||
| 90 | void SendCloseMessage(); | ||
| 91 | |||
| 92 | /** | ||
| 88 | * Sends the information about the room, along with the list of members | 93 | * Sends the information about the room, along with the list of members |
| 89 | * to every connected client in the room. | 94 | * to every connected client in the room. |
| 90 | * The packet has the structure: | 95 | * The packet has the structure: |
| @@ -159,6 +164,8 @@ void Room::RoomImpl::ServerLoop() { | |||
| 159 | } | 164 | } |
| 160 | } | 165 | } |
| 161 | } | 166 | } |
| 167 | // Close the connection to all members: | ||
| 168 | SendCloseMessage(); | ||
| 162 | } | 169 | } |
| 163 | 170 | ||
| 164 | void Room::RoomImpl::StartLoop() { | 171 | void Room::RoomImpl::StartLoop() { |
| @@ -266,6 +273,20 @@ void Room::RoomImpl::SendJoinSuccess(ENetPeer* client, MacAddress mac_address) { | |||
| 266 | enet_host_flush(server); | 273 | enet_host_flush(server); |
| 267 | } | 274 | } |
| 268 | 275 | ||
| 276 | void Room::RoomImpl::SendCloseMessage() { | ||
| 277 | Packet packet; | ||
| 278 | packet << static_cast<MessageID>(IdCloseRoom); | ||
| 279 | ENetPacket* enet_packet = | ||
| 280 | enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE); | ||
| 281 | for (auto& member : members) { | ||
| 282 | enet_peer_send(member.peer, 0, enet_packet); | ||
| 283 | } | ||
| 284 | enet_host_flush(server); | ||
| 285 | for (auto& member : members) { | ||
| 286 | enet_peer_disconnect(member.peer, 0); | ||
| 287 | } | ||
| 288 | } | ||
| 289 | |||
| 269 | void Room::RoomImpl::BroadcastRoomInformation() { | 290 | void Room::RoomImpl::BroadcastRoomInformation() { |
| 270 | Packet packet; | 291 | Packet packet; |
| 271 | packet << static_cast<MessageID>(IdRoomInformation); | 292 | packet << static_cast<MessageID>(IdRoomInformation); |
diff --git a/src/network/room_member.cpp b/src/network/room_member.cpp index f6f8b0475..8fd226ba5 100644 --- a/src/network/room_member.cpp +++ b/src/network/room_member.cpp | |||
| @@ -127,6 +127,9 @@ void RoomMember::RoomMemberImpl::MemberLoop() { | |||
| 127 | case IdVersionMismatch: | 127 | case IdVersionMismatch: |
| 128 | SetState(State::WrongVersion); | 128 | SetState(State::WrongVersion); |
| 129 | break; | 129 | break; |
| 130 | case IdCloseRoom: | ||
| 131 | SetState(State::LostConnection); | ||
| 132 | break; | ||
| 130 | default: | 133 | default: |
| 131 | break; | 134 | break; |
| 132 | } | 135 | } |
| @@ -307,7 +310,7 @@ RoomInformation RoomMember::GetRoomInformation() const { | |||
| 307 | } | 310 | } |
| 308 | 311 | ||
| 309 | void RoomMember::Join(const std::string& nick, const char* server_addr, u16 server_port, | 312 | void RoomMember::Join(const std::string& nick, const char* server_addr, u16 server_port, |
| 310 | u16 client_port) { | 313 | u16 client_port, const MacAddress& preferred_mac) { |
| 311 | // If the member is connected, kill the connection first | 314 | // If the member is connected, kill the connection first |
| 312 | if (room_member_impl->loop_thread && room_member_impl->loop_thread->joinable()) { | 315 | if (room_member_impl->loop_thread && room_member_impl->loop_thread->joinable()) { |
| 313 | room_member_impl->SetState(State::Error); | 316 | room_member_impl->SetState(State::Error); |
| @@ -336,7 +339,7 @@ void RoomMember::Join(const std::string& nick, const char* server_addr, u16 serv | |||
| 336 | room_member_impl->nickname = nick; | 339 | room_member_impl->nickname = nick; |
| 337 | room_member_impl->SetState(State::Joining); | 340 | room_member_impl->SetState(State::Joining); |
| 338 | room_member_impl->StartLoop(); | 341 | room_member_impl->StartLoop(); |
| 339 | room_member_impl->SendJoinRequest(nick); | 342 | room_member_impl->SendJoinRequest(nick, preferred_mac); |
| 340 | } else { | 343 | } else { |
| 341 | room_member_impl->SetState(State::CouldNotConnect); | 344 | room_member_impl->SetState(State::CouldNotConnect); |
| 342 | } | 345 | } |
diff --git a/src/network/room_member.h b/src/network/room_member.h index 6522f053c..fce608c82 100644 --- a/src/network/room_member.h +++ b/src/network/room_member.h | |||
| @@ -97,7 +97,8 @@ public: | |||
| 97 | * This may fail if the username is already taken. | 97 | * This may fail if the username is already taken. |
| 98 | */ | 98 | */ |
| 99 | void Join(const std::string& nickname, const char* server_addr = "127.0.0.1", | 99 | void Join(const std::string& nickname, const char* server_addr = "127.0.0.1", |
| 100 | const u16 serverPort = DefaultRoomPort, const u16 clientPort = 0); | 100 | const u16 serverPort = DefaultRoomPort, const u16 clientPort = 0, |
| 101 | const MacAddress& preferred_mac = NoPreferredMac); | ||
| 101 | 102 | ||
| 102 | /** | 103 | /** |
| 103 | * Sends a WiFi packet to the room. | 104 | * Sends a WiFi packet to the room. |