diff options
Diffstat (limited to 'src/network/room.cpp')
| -rw-r--r-- | src/network/room.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/network/room.cpp b/src/network/room.cpp index 8c63b255b..dc5dbce7f 100644 --- a/src/network/room.cpp +++ b/src/network/room.cpp | |||
| @@ -212,6 +212,12 @@ public: | |||
| 212 | void HandleProxyPacket(const ENetEvent* event); | 212 | void HandleProxyPacket(const ENetEvent* event); |
| 213 | 213 | ||
| 214 | /** | 214 | /** |
| 215 | * Broadcasts this packet to all members except the sender. | ||
| 216 | * @param event The ENet event containing the data | ||
| 217 | */ | ||
| 218 | void HandleLdnPacket(const ENetEvent* event); | ||
| 219 | |||
| 220 | /** | ||
| 215 | * Extracts a chat entry from a received ENet packet and adds it to the chat queue. | 221 | * Extracts a chat entry from a received ENet packet and adds it to the chat queue. |
| 216 | * @param event The ENet event that was received. | 222 | * @param event The ENet event that was received. |
| 217 | */ | 223 | */ |
| @@ -247,6 +253,9 @@ void Room::RoomImpl::ServerLoop() { | |||
| 247 | case IdProxyPacket: | 253 | case IdProxyPacket: |
| 248 | HandleProxyPacket(&event); | 254 | HandleProxyPacket(&event); |
| 249 | break; | 255 | break; |
| 256 | case IdLdnPacket: | ||
| 257 | HandleLdnPacket(&event); | ||
| 258 | break; | ||
| 250 | case IdChatMessage: | 259 | case IdChatMessage: |
| 251 | HandleChatPacket(&event); | 260 | HandleChatPacket(&event); |
| 252 | break; | 261 | break; |
| @@ -861,6 +870,60 @@ void Room::RoomImpl::HandleProxyPacket(const ENetEvent* event) { | |||
| 861 | enet_host_flush(server); | 870 | enet_host_flush(server); |
| 862 | } | 871 | } |
| 863 | 872 | ||
| 873 | void Room::RoomImpl::HandleLdnPacket(const ENetEvent* event) { | ||
| 874 | Packet in_packet; | ||
| 875 | in_packet.Append(event->packet->data, event->packet->dataLength); | ||
| 876 | |||
| 877 | in_packet.IgnoreBytes(sizeof(u8)); // Message type | ||
| 878 | |||
| 879 | in_packet.IgnoreBytes(sizeof(u8)); // LAN packet type | ||
| 880 | in_packet.IgnoreBytes(sizeof(IPv4Address)); // Local IP | ||
| 881 | |||
| 882 | IPv4Address remote_ip; | ||
| 883 | in_packet.Read(remote_ip); // Remote IP | ||
| 884 | |||
| 885 | bool broadcast; | ||
| 886 | in_packet.Read(broadcast); // Broadcast | ||
| 887 | |||
| 888 | Packet out_packet; | ||
| 889 | out_packet.Append(event->packet->data, event->packet->dataLength); | ||
| 890 | ENetPacket* enet_packet = enet_packet_create(out_packet.GetData(), out_packet.GetDataSize(), | ||
| 891 | ENET_PACKET_FLAG_RELIABLE); | ||
| 892 | |||
| 893 | const auto& destination_address = remote_ip; | ||
| 894 | if (broadcast) { // Send the data to everyone except the sender | ||
| 895 | std::lock_guard lock(member_mutex); | ||
| 896 | bool sent_packet = false; | ||
| 897 | for (const auto& member : members) { | ||
| 898 | if (member.peer != event->peer) { | ||
| 899 | sent_packet = true; | ||
| 900 | enet_peer_send(member.peer, 0, enet_packet); | ||
| 901 | } | ||
| 902 | } | ||
| 903 | |||
| 904 | if (!sent_packet) { | ||
| 905 | enet_packet_destroy(enet_packet); | ||
| 906 | } | ||
| 907 | } else { | ||
| 908 | std::lock_guard lock(member_mutex); | ||
| 909 | auto member = std::find_if(members.begin(), members.end(), | ||
| 910 | [destination_address](const Member& member_entry) -> bool { | ||
| 911 | return member_entry.fake_ip == destination_address; | ||
| 912 | }); | ||
| 913 | if (member != members.end()) { | ||
| 914 | enet_peer_send(member->peer, 0, enet_packet); | ||
| 915 | } else { | ||
| 916 | LOG_ERROR(Network, | ||
| 917 | "Attempting to send to unknown IP address: " | ||
| 918 | "{}.{}.{}.{}", | ||
| 919 | destination_address[0], destination_address[1], destination_address[2], | ||
| 920 | destination_address[3]); | ||
| 921 | enet_packet_destroy(enet_packet); | ||
| 922 | } | ||
| 923 | } | ||
| 924 | enet_host_flush(server); | ||
| 925 | } | ||
| 926 | |||
| 864 | void Room::RoomImpl::HandleChatPacket(const ENetEvent* event) { | 927 | void Room::RoomImpl::HandleChatPacket(const ENetEvent* event) { |
| 865 | Packet in_packet; | 928 | Packet in_packet; |
| 866 | in_packet.Append(event->packet->data, event->packet->dataLength); | 929 | in_packet.Append(event->packet->data, event->packet->dataLength); |