diff options
| -rw-r--r-- | src/network/packet.h | 10 | ||||
| -rw-r--r-- | src/network/room.cpp | 26 | ||||
| -rw-r--r-- | src/network/room.h | 3 | ||||
| -rw-r--r-- | src/network/room_member.cpp | 52 | ||||
| -rw-r--r-- | src/network/room_member.h | 2 |
5 files changed, 50 insertions, 43 deletions
diff --git a/src/network/packet.h b/src/network/packet.h index 026271701..94b351ab1 100644 --- a/src/network/packet.h +++ b/src/network/packet.h | |||
| @@ -115,6 +115,12 @@ private: | |||
| 115 | 115 | ||
| 116 | template <typename T> | 116 | template <typename T> |
| 117 | Packet& Packet::operator>>(std::vector<T>& out_data) { | 117 | Packet& Packet::operator>>(std::vector<T>& out_data) { |
| 118 | // First extract the size | ||
| 119 | u32 size = 0; | ||
| 120 | *this >> size; | ||
| 121 | out_data.resize(size); | ||
| 122 | |||
| 123 | // Then extract the data | ||
| 118 | for (std::size_t i = 0; i < out_data.size(); ++i) { | 124 | for (std::size_t i = 0; i < out_data.size(); ++i) { |
| 119 | T character = 0; | 125 | T character = 0; |
| 120 | *this >> character; | 126 | *this >> character; |
| @@ -135,6 +141,10 @@ Packet& Packet::operator>>(std::array<T, S>& out_data) { | |||
| 135 | 141 | ||
| 136 | template <typename T> | 142 | template <typename T> |
| 137 | Packet& Packet::operator<<(const std::vector<T>& in_data) { | 143 | Packet& Packet::operator<<(const std::vector<T>& in_data) { |
| 144 | // First insert the size | ||
| 145 | *this << static_cast<u32>(in_data.size()); | ||
| 146 | |||
| 147 | // Then insert the data | ||
| 138 | for (std::size_t i = 0; i < in_data.size(); ++i) { | 148 | for (std::size_t i = 0; i < in_data.size(); ++i) { |
| 139 | *this << in_data[i]; | 149 | *this << in_data[i]; |
| 140 | } | 150 | } |
diff --git a/src/network/room.cpp b/src/network/room.cpp index 3f72d7cbe..8b7915bb7 100644 --- a/src/network/room.cpp +++ b/src/network/room.cpp | |||
| @@ -74,7 +74,7 @@ public: | |||
| 74 | void SendMacCollision(ENetPeer* client); | 74 | void SendMacCollision(ENetPeer* client); |
| 75 | 75 | ||
| 76 | /** | 76 | /** |
| 77 | * Sends a ID_ROOM_VERSION_MISMATCH message telling the client that the MAC is invalid. | 77 | * Sends a ID_ROOM_VERSION_MISMATCH message telling the client that the version is invalid. |
| 78 | */ | 78 | */ |
| 79 | void SendVersionMismatch(ENetPeer* client); | 79 | void SendVersionMismatch(ENetPeer* client); |
| 80 | 80 | ||
| @@ -139,7 +139,7 @@ public: | |||
| 139 | void Room::RoomImpl::ServerLoop() { | 139 | void Room::RoomImpl::ServerLoop() { |
| 140 | while (state != State::Closed) { | 140 | while (state != State::Closed) { |
| 141 | ENetEvent event; | 141 | ENetEvent event; |
| 142 | if (enet_host_service(server, &event, 1000) > 0) { | 142 | if (enet_host_service(server, &event, 100) > 0) { |
| 143 | switch (event.type) { | 143 | switch (event.type) { |
| 144 | case ENET_EVENT_TYPE_RECEIVE: | 144 | case ENET_EVENT_TYPE_RECEIVE: |
| 145 | switch (event.packet->data[0]) { | 145 | switch (event.packet->data[0]) { |
| @@ -175,7 +175,7 @@ void Room::RoomImpl::StartLoop() { | |||
| 175 | void Room::RoomImpl::HandleJoinRequest(const ENetEvent* event) { | 175 | void Room::RoomImpl::HandleJoinRequest(const ENetEvent* event) { |
| 176 | Packet packet; | 176 | Packet packet; |
| 177 | packet.Append(event->packet->data, event->packet->dataLength); | 177 | packet.Append(event->packet->data, event->packet->dataLength); |
| 178 | packet.IgnoreBytes(sizeof(MessageID)); | 178 | packet.IgnoreBytes(sizeof(u8)); // Igonore the message type |
| 179 | std::string nickname; | 179 | std::string nickname; |
| 180 | packet >> nickname; | 180 | packet >> nickname; |
| 181 | 181 | ||
| @@ -234,7 +234,7 @@ bool Room::RoomImpl::IsValidMacAddress(const MacAddress& address) const { | |||
| 234 | 234 | ||
| 235 | void Room::RoomImpl::SendNameCollision(ENetPeer* client) { | 235 | void Room::RoomImpl::SendNameCollision(ENetPeer* client) { |
| 236 | Packet packet; | 236 | Packet packet; |
| 237 | packet << static_cast<MessageID>(IdNameCollision); | 237 | packet << static_cast<u8>(IdNameCollision); |
| 238 | 238 | ||
| 239 | ENetPacket* enet_packet = | 239 | ENetPacket* enet_packet = |
| 240 | enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE); | 240 | enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE); |
| @@ -244,7 +244,7 @@ void Room::RoomImpl::SendNameCollision(ENetPeer* client) { | |||
| 244 | 244 | ||
| 245 | void Room::RoomImpl::SendMacCollision(ENetPeer* client) { | 245 | void Room::RoomImpl::SendMacCollision(ENetPeer* client) { |
| 246 | Packet packet; | 246 | Packet packet; |
| 247 | packet << static_cast<MessageID>(IdMacCollision); | 247 | packet << static_cast<u8>(IdMacCollision); |
| 248 | 248 | ||
| 249 | ENetPacket* enet_packet = | 249 | ENetPacket* enet_packet = |
| 250 | enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE); | 250 | enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE); |
| @@ -254,7 +254,7 @@ void Room::RoomImpl::SendMacCollision(ENetPeer* client) { | |||
| 254 | 254 | ||
| 255 | void Room::RoomImpl::SendVersionMismatch(ENetPeer* client) { | 255 | void Room::RoomImpl::SendVersionMismatch(ENetPeer* client) { |
| 256 | Packet packet; | 256 | Packet packet; |
| 257 | packet << static_cast<MessageID>(IdVersionMismatch); | 257 | packet << static_cast<u8>(IdVersionMismatch); |
| 258 | packet << network_version; | 258 | packet << network_version; |
| 259 | 259 | ||
| 260 | ENetPacket* enet_packet = | 260 | ENetPacket* enet_packet = |
| @@ -265,7 +265,7 @@ void Room::RoomImpl::SendVersionMismatch(ENetPeer* client) { | |||
| 265 | 265 | ||
| 266 | void Room::RoomImpl::SendJoinSuccess(ENetPeer* client, MacAddress mac_address) { | 266 | void Room::RoomImpl::SendJoinSuccess(ENetPeer* client, MacAddress mac_address) { |
| 267 | Packet packet; | 267 | Packet packet; |
| 268 | packet << static_cast<MessageID>(IdJoinSuccess); | 268 | packet << static_cast<u8>(IdJoinSuccess); |
| 269 | packet << mac_address; | 269 | packet << mac_address; |
| 270 | ENetPacket* enet_packet = | 270 | ENetPacket* enet_packet = |
| 271 | enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE); | 271 | enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE); |
| @@ -275,7 +275,7 @@ void Room::RoomImpl::SendJoinSuccess(ENetPeer* client, MacAddress mac_address) { | |||
| 275 | 275 | ||
| 276 | void Room::RoomImpl::SendCloseMessage() { | 276 | void Room::RoomImpl::SendCloseMessage() { |
| 277 | Packet packet; | 277 | Packet packet; |
| 278 | packet << static_cast<MessageID>(IdCloseRoom); | 278 | packet << static_cast<u8>(IdCloseRoom); |
| 279 | ENetPacket* enet_packet = | 279 | ENetPacket* enet_packet = |
| 280 | enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE); | 280 | enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE); |
| 281 | for (auto& member : members) { | 281 | for (auto& member : members) { |
| @@ -289,7 +289,7 @@ void Room::RoomImpl::SendCloseMessage() { | |||
| 289 | 289 | ||
| 290 | void Room::RoomImpl::BroadcastRoomInformation() { | 290 | void Room::RoomImpl::BroadcastRoomInformation() { |
| 291 | Packet packet; | 291 | Packet packet; |
| 292 | packet << static_cast<MessageID>(IdRoomInformation); | 292 | packet << static_cast<u8>(IdRoomInformation); |
| 293 | packet << room_information.name; | 293 | packet << room_information.name; |
| 294 | packet << room_information.member_slots; | 294 | packet << room_information.member_slots; |
| 295 | 295 | ||
| @@ -321,7 +321,7 @@ MacAddress Room::RoomImpl::GenerateMacAddress() { | |||
| 321 | void Room::RoomImpl::HandleWifiPacket(const ENetEvent* event) { | 321 | void Room::RoomImpl::HandleWifiPacket(const ENetEvent* event) { |
| 322 | Packet in_packet; | 322 | Packet in_packet; |
| 323 | in_packet.Append(event->packet->data, event->packet->dataLength); | 323 | in_packet.Append(event->packet->data, event->packet->dataLength); |
| 324 | in_packet.IgnoreBytes(sizeof(MessageID)); | 324 | in_packet.IgnoreBytes(sizeof(u8)); // Message type |
| 325 | in_packet.IgnoreBytes(sizeof(u8)); // WifiPacket Type | 325 | in_packet.IgnoreBytes(sizeof(u8)); // WifiPacket Type |
| 326 | in_packet.IgnoreBytes(sizeof(u8)); // WifiPacket Channel | 326 | in_packet.IgnoreBytes(sizeof(u8)); // WifiPacket Channel |
| 327 | in_packet.IgnoreBytes(sizeof(MacAddress)); // WifiPacket Transmitter Address | 327 | in_packet.IgnoreBytes(sizeof(MacAddress)); // WifiPacket Transmitter Address |
| @@ -354,7 +354,7 @@ void Room::RoomImpl::HandleChatPacket(const ENetEvent* event) { | |||
| 354 | Packet in_packet; | 354 | Packet in_packet; |
| 355 | in_packet.Append(event->packet->data, event->packet->dataLength); | 355 | in_packet.Append(event->packet->data, event->packet->dataLength); |
| 356 | 356 | ||
| 357 | in_packet.IgnoreBytes(sizeof(MessageID)); | 357 | in_packet.IgnoreBytes(sizeof(u8)); // Igonore the message type |
| 358 | std::string message; | 358 | std::string message; |
| 359 | in_packet >> message; | 359 | in_packet >> message; |
| 360 | auto CompareNetworkAddress = [event](const Member member) -> bool { | 360 | auto CompareNetworkAddress = [event](const Member member) -> bool { |
| @@ -366,7 +366,7 @@ void Room::RoomImpl::HandleChatPacket(const ENetEvent* event) { | |||
| 366 | } | 366 | } |
| 367 | 367 | ||
| 368 | Packet out_packet; | 368 | Packet out_packet; |
| 369 | out_packet << static_cast<MessageID>(IdChatMessage); | 369 | out_packet << static_cast<u8>(IdChatMessage); |
| 370 | out_packet << sending_member->nickname; | 370 | out_packet << sending_member->nickname; |
| 371 | out_packet << message; | 371 | out_packet << message; |
| 372 | 372 | ||
| @@ -383,7 +383,7 @@ void Room::RoomImpl::HandleGameNamePacket(const ENetEvent* event) { | |||
| 383 | Packet in_packet; | 383 | Packet in_packet; |
| 384 | in_packet.Append(event->packet->data, event->packet->dataLength); | 384 | in_packet.Append(event->packet->data, event->packet->dataLength); |
| 385 | 385 | ||
| 386 | in_packet.IgnoreBytes(sizeof(MessageID)); | 386 | in_packet.IgnoreBytes(sizeof(u8)); // Igonore the message type |
| 387 | std::string game_name; | 387 | std::string game_name; |
| 388 | in_packet >> game_name; | 388 | in_packet >> game_name; |
| 389 | auto member = | 389 | auto member = |
diff --git a/src/network/room.h b/src/network/room.h index ffa17599d..54cccf0ae 100644 --- a/src/network/room.h +++ b/src/network/room.h | |||
| @@ -30,8 +30,7 @@ const MacAddress NoPreferredMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; | |||
| 30 | constexpr MacAddress BroadcastMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; | 30 | constexpr MacAddress BroadcastMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
| 31 | 31 | ||
| 32 | // The different types of messages that can be sent. The first byte of each packet defines the type | 32 | // The different types of messages that can be sent. The first byte of each packet defines the type |
| 33 | using MessageID = u8; | 33 | enum RoomMessageTypes : u8 { |
| 34 | enum RoomMessageTypes { | ||
| 35 | IdJoinRequest = 1, | 34 | IdJoinRequest = 1, |
| 36 | IdJoinSuccess, | 35 | IdJoinSuccess, |
| 37 | IdRoomInformation, | 36 | IdRoomInformation, |
diff --git a/src/network/room_member.cpp b/src/network/room_member.cpp index 8fd226ba5..dac9bacae 100644 --- a/src/network/room_member.cpp +++ b/src/network/room_member.cpp | |||
| @@ -38,13 +38,15 @@ public: | |||
| 38 | std::mutex send_list_mutex; ///< Mutex that controls access to the `send_list` variable. | 38 | std::mutex send_list_mutex; ///< Mutex that controls access to the `send_list` variable. |
| 39 | std::list<Packet> send_list; ///< A list that stores all packets to send the async | 39 | std::list<Packet> send_list; ///< A list that stores all packets to send the async |
| 40 | void MemberLoop(); | 40 | void MemberLoop(); |
| 41 | |||
| 41 | void StartLoop(); | 42 | void StartLoop(); |
| 42 | 43 | ||
| 43 | /** | 44 | /** |
| 44 | * Sends data to the room. It will be send on channel 0 with flag RELIABLE | 45 | * Sends data to the room. It will be send on channel 0 with flag RELIABLE |
| 45 | * @param packet The data to send | 46 | * @param packet The data to send |
| 46 | */ | 47 | */ |
| 47 | void Send(Packet& packet); | 48 | void Send(Packet&& packet); |
| 49 | |||
| 48 | /** | 50 | /** |
| 49 | * Sends a request to the server, asking for permission to join a room with the specified | 51 | * Sends a request to the server, asking for permission to join a room with the specified |
| 50 | * nickname and preferred mac. | 52 | * nickname and preferred mac. |
| @@ -99,11 +101,13 @@ void RoomMember::RoomMemberImpl::MemberLoop() { | |||
| 99 | while (IsConnected()) { | 101 | while (IsConnected()) { |
| 100 | std::lock_guard<std::mutex> lock(network_mutex); | 102 | std::lock_guard<std::mutex> lock(network_mutex); |
| 101 | ENetEvent event; | 103 | ENetEvent event; |
| 102 | if (enet_host_service(client, &event, 1000) > 0) { | 104 | if (enet_host_service(client, &event, 100) > 0) { |
| 103 | switch (event.type) { | 105 | switch (event.type) { |
| 104 | case ENET_EVENT_TYPE_RECEIVE: | 106 | case ENET_EVENT_TYPE_RECEIVE: |
| 105 | switch (event.packet->data[0]) { | 107 | switch (event.packet->data[0]) { |
| 106 | // TODO(B3N30): Handle the other message types | 108 | case IdWifiPacket: |
| 109 | HandleWifiPackets(&event); | ||
| 110 | break; | ||
| 107 | case IdChatMessage: | 111 | case IdChatMessage: |
| 108 | HandleChatPacket(&event); | 112 | HandleChatPacket(&event); |
| 109 | break; | 113 | break; |
| @@ -130,8 +134,6 @@ void RoomMember::RoomMemberImpl::MemberLoop() { | |||
| 130 | case IdCloseRoom: | 134 | case IdCloseRoom: |
| 131 | SetState(State::LostConnection); | 135 | SetState(State::LostConnection); |
| 132 | break; | 136 | break; |
| 133 | default: | ||
| 134 | break; | ||
| 135 | } | 137 | } |
| 136 | enet_packet_destroy(event.packet); | 138 | enet_packet_destroy(event.packet); |
| 137 | break; | 139 | break; |
| @@ -158,7 +160,7 @@ void RoomMember::RoomMemberImpl::StartLoop() { | |||
| 158 | loop_thread = std::make_unique<std::thread>(&RoomMember::RoomMemberImpl::MemberLoop, this); | 160 | loop_thread = std::make_unique<std::thread>(&RoomMember::RoomMemberImpl::MemberLoop, this); |
| 159 | } | 161 | } |
| 160 | 162 | ||
| 161 | void RoomMember::RoomMemberImpl::Send(Packet& packet) { | 163 | void RoomMember::RoomMemberImpl::Send(Packet&& packet) { |
| 162 | std::lock_guard<std::mutex> lock(send_list_mutex); | 164 | std::lock_guard<std::mutex> lock(send_list_mutex); |
| 163 | send_list.push_back(std::move(packet)); | 165 | send_list.push_back(std::move(packet)); |
| 164 | } | 166 | } |
| @@ -166,11 +168,11 @@ void RoomMember::RoomMemberImpl::Send(Packet& packet) { | |||
| 166 | void RoomMember::RoomMemberImpl::SendJoinRequest(const std::string& nickname, | 168 | void RoomMember::RoomMemberImpl::SendJoinRequest(const std::string& nickname, |
| 167 | const MacAddress& preferred_mac) { | 169 | const MacAddress& preferred_mac) { |
| 168 | Packet packet; | 170 | Packet packet; |
| 169 | packet << static_cast<MessageID>(IdJoinRequest); | 171 | packet << static_cast<u8>(IdJoinRequest); |
| 170 | packet << nickname; | 172 | packet << nickname; |
| 171 | packet << preferred_mac; | 173 | packet << preferred_mac; |
| 172 | packet << network_version; | 174 | packet << network_version; |
| 173 | Send(packet); | 175 | Send(std::move(packet)); |
| 174 | } | 176 | } |
| 175 | 177 | ||
| 176 | void RoomMember::RoomMemberImpl::HandleRoomInformationPacket(const ENetEvent* event) { | 178 | void RoomMember::RoomMemberImpl::HandleRoomInformationPacket(const ENetEvent* event) { |
| @@ -178,7 +180,7 @@ void RoomMember::RoomMemberImpl::HandleRoomInformationPacket(const ENetEvent* ev | |||
| 178 | packet.Append(event->packet->data, event->packet->dataLength); | 180 | packet.Append(event->packet->data, event->packet->dataLength); |
| 179 | 181 | ||
| 180 | // Ignore the first byte, which is the message id. | 182 | // Ignore the first byte, which is the message id. |
| 181 | packet.IgnoreBytes(sizeof(MessageID)); | 183 | packet.IgnoreBytes(sizeof(u8)); // Igonore the message type |
| 182 | 184 | ||
| 183 | RoomInformation info{}; | 185 | RoomInformation info{}; |
| 184 | packet >> info.name; | 186 | packet >> info.name; |
| @@ -203,9 +205,9 @@ void RoomMember::RoomMemberImpl::HandleJoinPacket(const ENetEvent* event) { | |||
| 203 | packet.Append(event->packet->data, event->packet->dataLength); | 205 | packet.Append(event->packet->data, event->packet->dataLength); |
| 204 | 206 | ||
| 205 | // Ignore the first byte, which is the message id. | 207 | // Ignore the first byte, which is the message id. |
| 206 | packet.IgnoreBytes(sizeof(MessageID)); | 208 | packet.IgnoreBytes(sizeof(u8)); // Igonore the message type |
| 207 | 209 | ||
| 208 | // Parse the MAC Address from the BitStream | 210 | // Parse the MAC Address from the packet |
| 209 | packet >> mac_address; | 211 | packet >> mac_address; |
| 210 | // TODO(B3N30): Invoke callbacks | 212 | // TODO(B3N30): Invoke callbacks |
| 211 | } | 213 | } |
| @@ -216,9 +218,9 @@ void RoomMember::RoomMemberImpl::HandleWifiPackets(const ENetEvent* event) { | |||
| 216 | packet.Append(event->packet->data, event->packet->dataLength); | 218 | packet.Append(event->packet->data, event->packet->dataLength); |
| 217 | 219 | ||
| 218 | // Ignore the first byte, which is the message id. | 220 | // Ignore the first byte, which is the message id. |
| 219 | packet.IgnoreBytes(sizeof(MessageID)); | 221 | packet.IgnoreBytes(sizeof(u8)); // Igonore the message type |
| 220 | 222 | ||
| 221 | // Parse the WifiPacket from the BitStream | 223 | // Parse the WifiPacket from the packet |
| 222 | u8 frame_type; | 224 | u8 frame_type; |
| 223 | packet >> frame_type; | 225 | packet >> frame_type; |
| 224 | WifiPacket::PacketType type = static_cast<WifiPacket::PacketType>(frame_type); | 226 | WifiPacket::PacketType type = static_cast<WifiPacket::PacketType>(frame_type); |
| @@ -231,10 +233,8 @@ void RoomMember::RoomMemberImpl::HandleWifiPackets(const ENetEvent* event) { | |||
| 231 | u32 data_length; | 233 | u32 data_length; |
| 232 | packet >> data_length; | 234 | packet >> data_length; |
| 233 | 235 | ||
| 234 | std::vector<u8> data(data_length); | 236 | packet >> wifi_packet.data; |
| 235 | packet >> data; | ||
| 236 | 237 | ||
| 237 | wifi_packet.data = std::move(data); | ||
| 238 | // TODO(B3N30): Invoke callbacks | 238 | // TODO(B3N30): Invoke callbacks |
| 239 | } | 239 | } |
| 240 | 240 | ||
| @@ -243,7 +243,7 @@ void RoomMember::RoomMemberImpl::HandleChatPacket(const ENetEvent* event) { | |||
| 243 | packet.Append(event->packet->data, event->packet->dataLength); | 243 | packet.Append(event->packet->data, event->packet->dataLength); |
| 244 | 244 | ||
| 245 | // Ignore the first byte, which is the message id. | 245 | // Ignore the first byte, which is the message id. |
| 246 | packet.IgnoreBytes(sizeof(MessageID)); | 246 | packet.IgnoreBytes(sizeof(u8)); |
| 247 | 247 | ||
| 248 | ChatEntry chat_entry{}; | 248 | ChatEntry chat_entry{}; |
| 249 | packet >> chat_entry.nickname; | 249 | packet >> chat_entry.nickname; |
| @@ -300,9 +300,8 @@ const std::string& RoomMember::GetNickname() const { | |||
| 300 | } | 300 | } |
| 301 | 301 | ||
| 302 | const MacAddress& RoomMember::GetMacAddress() const { | 302 | const MacAddress& RoomMember::GetMacAddress() const { |
| 303 | if (GetState() == State::Joined) | 303 | ASSERT_MSG(IsConnected(), "Tried to get MAC address while not connected"); |
| 304 | return room_member_impl->mac_address; | 304 | return room_member_impl->mac_address; |
| 305 | return MacAddress{}; | ||
| 306 | } | 305 | } |
| 307 | 306 | ||
| 308 | RoomInformation RoomMember::GetRoomInformation() const { | 307 | RoomInformation RoomMember::GetRoomInformation() const { |
| @@ -351,28 +350,27 @@ bool RoomMember::IsConnected() const { | |||
| 351 | 350 | ||
| 352 | void RoomMember::SendWifiPacket(const WifiPacket& wifi_packet) { | 351 | void RoomMember::SendWifiPacket(const WifiPacket& wifi_packet) { |
| 353 | Packet packet; | 352 | Packet packet; |
| 354 | packet << static_cast<MessageID>(IdWifiPacket); | 353 | packet << static_cast<u8>(IdWifiPacket); |
| 355 | packet << static_cast<u8>(wifi_packet.type); | 354 | packet << static_cast<u8>(wifi_packet.type); |
| 356 | packet << wifi_packet.channel; | 355 | packet << wifi_packet.channel; |
| 357 | packet << wifi_packet.transmitter_address; | 356 | packet << wifi_packet.transmitter_address; |
| 358 | packet << wifi_packet.destination_address; | 357 | packet << wifi_packet.destination_address; |
| 359 | packet << static_cast<u32>(wifi_packet.data.size()); | ||
| 360 | packet << wifi_packet.data; | 358 | packet << wifi_packet.data; |
| 361 | room_member_impl->Send(packet); | 359 | room_member_impl->Send(std::move(packet)); |
| 362 | } | 360 | } |
| 363 | 361 | ||
| 364 | void RoomMember::SendChatMessage(const std::string& message) { | 362 | void RoomMember::SendChatMessage(const std::string& message) { |
| 365 | Packet packet; | 363 | Packet packet; |
| 366 | packet << static_cast<MessageID>(IdChatMessage); | 364 | packet << static_cast<u8>(IdChatMessage); |
| 367 | packet << message; | 365 | packet << message; |
| 368 | room_member_impl->Send(packet); | 366 | room_member_impl->Send(std::move(packet)); |
| 369 | } | 367 | } |
| 370 | 368 | ||
| 371 | void RoomMember::SendGameName(const std::string& game_name) { | 369 | void RoomMember::SendGameName(const std::string& game_name) { |
| 372 | Packet packet; | 370 | Packet packet; |
| 373 | packet << static_cast<MessageID>(IdSetGameName); | 371 | packet << static_cast<u8>(IdSetGameName); |
| 374 | packet << game_name; | 372 | packet << game_name; |
| 375 | room_member_impl->Send(packet); | 373 | room_member_impl->Send(std::move(packet)); |
| 376 | } | 374 | } |
| 377 | 375 | ||
| 378 | void RoomMember::Leave() { | 376 | void RoomMember::Leave() { |
diff --git a/src/network/room_member.h b/src/network/room_member.h index fce608c82..bc1af3a7e 100644 --- a/src/network/room_member.h +++ b/src/network/room_member.h | |||
| @@ -15,7 +15,7 @@ namespace Network { | |||
| 15 | /// Information about the received WiFi packets. | 15 | /// Information about the received WiFi packets. |
| 16 | /// Acts as our own 802.11 header. | 16 | /// Acts as our own 802.11 header. |
| 17 | struct WifiPacket { | 17 | struct WifiPacket { |
| 18 | enum class PacketType { Beacon, Data, Authentication, AssociationResponse }; | 18 | enum class PacketType : u8 { Beacon, Data, Authentication, AssociationResponse }; |
| 19 | PacketType type; ///< The type of 802.11 frame. | 19 | PacketType type; ///< The type of 802.11 frame. |
| 20 | std::vector<u8> data; ///< Raw 802.11 frame data, starting at the management frame header | 20 | std::vector<u8> data; ///< Raw 802.11 frame data, starting at the management frame header |
| 21 | /// for management frames. | 21 | /// for management frames. |