diff --git a/src/DedicatedServer.cpp b/src/DedicatedServer.cpp index 5730813..c152b7a 100644 --- a/src/DedicatedServer.cpp +++ b/src/DedicatedServer.cpp @@ -149,6 +149,8 @@ namespace Feather // .uuid = { 4658857991808325907ull, 7518717155607718277ull }, // .username = start.username //}; + client.SetUsername(start.username); + std::string uuid = "ecb99913-96a8-40a7-8529-a2ca6ad95768"; Login::ClientboundSuccess success = { @@ -203,4 +205,22 @@ namespace Feather { // TODO: check these and kick clients that don't send em right or at all } + + template <> + void DedicatedServer::HandlePacket(MinecraftClient& client, const Play::ServerboundChatMessage& chat) + { + Log::Info("{}: {}", client.GetUsername(), chat.message); + + std::string json = fmt::format(R"({{ "text": "<{}> {}" }})", client.GetUsername(), chat.message); + Play::ClientboundChatMessage message = + { + .jsonData = json, + .position = 0 + }; + + // m_clients is already locked for us! + auto& clients = m_clients.steal(); + for (auto& client : clients) + client.SendMessage(message); + } } diff --git a/src/MinecraftClient.h b/src/MinecraftClient.h index bf4997e..bc463e3 100644 --- a/src/MinecraftClient.h +++ b/src/MinecraftClient.h @@ -16,9 +16,14 @@ namespace Feather inline Network::TCPClientHandle& GetTCPClient() { return m_client; } inline Protocol::ProtocolContext& GetContext() { return m_context; } + inline const std::string& GetUsername() const { return m_username; } + inline void SetUsername(const std::string& username) { m_username = username; } + void SendMessage(const NetworkMessage& message); private: + std::string m_username; + Network::TCPClientHandle m_client; Protocol::ProtocolContext m_context; }; diff --git a/src/protocol/protocol.hjson b/src/protocol/protocol.hjson index 20d3147..3596eaf 100644 --- a/src/protocol/protocol.hjson +++ b/src/protocol/protocol.hjson @@ -139,17 +139,37 @@ { serverbound: { + ChatMessage: + { + id : 0x03 + vars : + { + message : string[256] + } + } + KeepAlive: { - id: 0x0F - vars: { - id: int64 + id : 0x0F + vars : + { + id : int64 } } } clientbound : { + ChatMessage: + { + id : 0x0F + vars : + { + jsonData : string[32767] + position : uint8 + } + } + JoinGame : { id : 38