Implement basic chat functionality
This commit is contained in:
parent
a5a79e2d38
commit
799f0f2552
|
@ -149,6 +149,8 @@ namespace Feather
|
||||||
// .uuid = { 4658857991808325907ull, 7518717155607718277ull },
|
// .uuid = { 4658857991808325907ull, 7518717155607718277ull },
|
||||||
// .username = start.username
|
// .username = start.username
|
||||||
//};
|
//};
|
||||||
|
client.SetUsername(start.username);
|
||||||
|
|
||||||
std::string uuid = "ecb99913-96a8-40a7-8529-a2ca6ad95768";
|
std::string uuid = "ecb99913-96a8-40a7-8529-a2ca6ad95768";
|
||||||
Login::ClientboundSuccess success =
|
Login::ClientboundSuccess success =
|
||||||
{
|
{
|
||||||
|
@ -203,4 +205,22 @@ namespace Feather
|
||||||
{
|
{
|
||||||
// TODO: check these and kick clients that don't send em right or at all
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,14 @@ namespace Feather
|
||||||
inline Network::TCPClientHandle& GetTCPClient() { return m_client; }
|
inline Network::TCPClientHandle& GetTCPClient() { return m_client; }
|
||||||
inline Protocol::ProtocolContext& GetContext() { return m_context; }
|
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);
|
void SendMessage(const NetworkMessage& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::string m_username;
|
||||||
|
|
||||||
Network::TCPClientHandle m_client;
|
Network::TCPClientHandle m_client;
|
||||||
Protocol::ProtocolContext m_context;
|
Protocol::ProtocolContext m_context;
|
||||||
};
|
};
|
||||||
|
|
|
@ -139,17 +139,37 @@
|
||||||
{
|
{
|
||||||
serverbound:
|
serverbound:
|
||||||
{
|
{
|
||||||
|
ChatMessage:
|
||||||
|
{
|
||||||
|
id : 0x03
|
||||||
|
vars :
|
||||||
|
{
|
||||||
|
message : string[256]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
KeepAlive:
|
KeepAlive:
|
||||||
{
|
{
|
||||||
id: 0x0F
|
id : 0x0F
|
||||||
vars: {
|
vars :
|
||||||
id: int64
|
{
|
||||||
|
id : int64
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clientbound :
|
clientbound :
|
||||||
{
|
{
|
||||||
|
ChatMessage:
|
||||||
|
{
|
||||||
|
id : 0x0F
|
||||||
|
vars :
|
||||||
|
{
|
||||||
|
jsonData : string[32767]
|
||||||
|
position : uint8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
JoinGame :
|
JoinGame :
|
||||||
{
|
{
|
||||||
id : 38
|
id : 38
|
||||||
|
|
Loading…
Reference in New Issue