diff options
author | B3n30 <benediktthomas@gmail.com> | 2017-07-09 12:26:03 +0200 |
---|---|---|
committer | B3n30 <benediktthomas@gmail.com> | 2017-07-16 21:29:49 +0200 |
commit | 42e57c121896818f9fbde5ddd9b7dbb5b2a267b1 (patch) | |
tree | b3f27a02bc2cda201297c48fb52dfbc0efba326b /src/network/room_member.cpp | |
parent | Network: Handle the disconnect of a client (diff) | |
download | yuzu-42e57c121896818f9fbde5ddd9b7dbb5b2a267b1.tar yuzu-42e57c121896818f9fbde5ddd9b7dbb5b2a267b1.tar.gz yuzu-42e57c121896818f9fbde5ddd9b7dbb5b2a267b1.tar.bz2 yuzu-42e57c121896818f9fbde5ddd9b7dbb5b2a267b1.tar.lz yuzu-42e57c121896818f9fbde5ddd9b7dbb5b2a267b1.tar.xz yuzu-42e57c121896818f9fbde5ddd9b7dbb5b2a267b1.tar.zst yuzu-42e57c121896818f9fbde5ddd9b7dbb5b2a267b1.zip |
Diffstat (limited to '')
-rw-r--r-- | src/network/room_member.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/network/room_member.cpp b/src/network/room_member.cpp index f919e4de0..d68bb551d 100644 --- a/src/network/room_member.cpp +++ b/src/network/room_member.cpp @@ -68,6 +68,12 @@ public: * @param event The ENet event that was received. */ void HandleWifiPackets(const ENetEvent* event); + + /** + * Extracts a chat entry from a received ENet packet and adds it to the chat queue. + * @param event The ENet event that was received. + */ + void HandleChatPacket(const ENetEvent* event); }; // RoomMemberImpl @@ -89,6 +95,9 @@ void RoomMember::RoomMemberImpl::ReceiveLoop() { if (event.type == ENET_EVENT_TYPE_RECEIVE) { switch (event.packet->data[0]) { // TODO(B3N30): Handle the other message types + case IdChatMessage: + HandleChatPacket(&event); + break; case IdRoomInformation: HandleRoomInformationPacket(&event); break; @@ -208,6 +217,19 @@ void RoomMember::RoomMemberImpl::HandleWifiPackets(const ENetEvent* event) { // TODO(B3N30): Invoke callbacks } +void RoomMember::RoomMemberImpl::HandleChatPacket(const ENetEvent* event) { + Packet packet; + packet.Append(event->packet->data, event->packet->dataLength); + + // Ignore the first byte, which is the message id. + packet.IgnoreBytes(sizeof(MessageID)); + + ChatEntry chat_entry{}; + packet >> chat_entry.nickname; + packet >> chat_entry.message; + // 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); @@ -273,6 +295,13 @@ void RoomMember::SendWifiPacket(const WifiPacket& wifi_packet) { room_member_impl->Send(packet); } +void RoomMember::SendChatMessage(const std::string& message) { + Packet packet; + packet << static_cast<MessageID>(IdChatMessage); + packet << message; + room_member_impl->Send(packet); +} + void RoomMember::Leave() { ASSERT_MSG(room_member_impl->receive_thread != nullptr, "Must be in a room to leave it."); { |