Implement basic chat functionality

This commit is contained in:
Joshua Ashton 2020-08-08 01:25:32 +01:00
parent a5a79e2d38
commit 799f0f2552
3 changed files with 48 additions and 3 deletions

View File

@ -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);
}
}

View File

@ -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;
};

View File

@ -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