summaryrefslogtreecommitdiffstats
path: root/src/network/room_member.cpp
diff options
context:
space:
mode:
authorB3n30 <benediktthomas@gmail.com>2017-07-09 10:40:11 +0200
committerB3n30 <benediktthomas@gmail.com>2017-07-16 21:29:34 +0200
commit641346c15c0091d59259f6acc5f8789efe16c937 (patch)
treedb87a00159c0feb35bb663b2e49ca8348451e4fe /src/network/room_member.cpp
parentNetwork: Init Network in SDL and QT (diff)
downloadyuzu-641346c15c0091d59259f6acc5f8789efe16c937.tar
yuzu-641346c15c0091d59259f6acc5f8789efe16c937.tar.gz
yuzu-641346c15c0091d59259f6acc5f8789efe16c937.tar.bz2
yuzu-641346c15c0091d59259f6acc5f8789efe16c937.tar.lz
yuzu-641346c15c0091d59259f6acc5f8789efe16c937.tar.xz
yuzu-641346c15c0091d59259f6acc5f8789efe16c937.tar.zst
yuzu-641346c15c0091d59259f6acc5f8789efe16c937.zip
Diffstat (limited to '')
-rw-r--r--src/network/room_member.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/network/room_member.cpp b/src/network/room_member.cpp
index 09573ee43..f919e4de0 100644
--- a/src/network/room_member.cpp
+++ b/src/network/room_member.cpp
@@ -62,6 +62,12 @@ public:
* @param event The ENet event that was received.
*/
void HandleRoomInformationPacket(const ENetEvent* event);
+
+ /**
+ * Extracts a WifiPacket from a received ENet packet.
+ * @param event The ENet event that was received.
+ */
+ void HandleWifiPackets(const ENetEvent* event);
};
// RoomMemberImpl
@@ -174,6 +180,34 @@ void RoomMember::RoomMemberImpl::HandleJoinPacket(const ENetEvent* event) {
// TODO(B3N30): Invoke callbacks
}
+void RoomMember::RoomMemberImpl::HandleWifiPackets(const ENetEvent* event) {
+ WifiPacket wifi_packet{};
+ Packet packet;
+ packet.Append(event->packet->data, event->packet->dataLength);
+
+ // Ignore the first byte, which is the message id.
+ packet.IgnoreBytes(sizeof(MessageID));
+
+ // Parse the WifiPacket from the BitStream
+ uint8_t frame_type;
+ packet >> frame_type;
+ WifiPacket::PacketType type = static_cast<WifiPacket::PacketType>(frame_type);
+
+ wifi_packet.type = type;
+ packet >> wifi_packet.channel;
+ packet >> wifi_packet.transmitter_address;
+ packet >> wifi_packet.destination_address;
+
+ uint32_t data_length;
+ packet >> data_length;
+
+ std::vector<uint8_t> data(data_length);
+ packet >> data;
+
+ wifi_packet.data = std::move(data);
+ // TODO(B3N30): Invoke callbacks
+}
+
// RoomMember
RoomMember::RoomMember() : room_member_impl{std::make_unique<RoomMemberImpl>()} {
room_member_impl->client = enet_host_create(nullptr, 1, NumChannels, 0, 0);
@@ -227,6 +261,18 @@ bool RoomMember::IsConnected() const {
return room_member_impl->IsConnected();
}
+void RoomMember::SendWifiPacket(const WifiPacket& wifi_packet) {
+ Packet packet;
+ packet << static_cast<MessageID>(IdWifiPacket);
+ packet << static_cast<uint8_t>(wifi_packet.type);
+ packet << wifi_packet.channel;
+ packet << wifi_packet.transmitter_address;
+ packet << wifi_packet.destination_address;
+ packet << static_cast<uint32_t>(wifi_packet.data.size());
+ packet << wifi_packet.data;
+ room_member_impl->Send(packet);
+}
+
void RoomMember::Leave() {
ASSERT_MSG(room_member_impl->receive_thread != nullptr, "Must be in a room to leave it.");
{