summaryrefslogtreecommitdiffstats
path: root/src/game/server/chat.cc
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-12-11 15:14:26 +0500
committeruntodesu <kirill@untode.su>2025-12-11 15:14:26 +0500
commitf40d09cb8f712e87691af4912f3630d92d692779 (patch)
tree7ac3a4168ff722689372fd489c6f94d0a2546e8f /src/game/server/chat.cc
parent8bcbd2729388edc63c82d77d314b583af1447c49 (diff)
downloadvoxelius-f40d09cb8f712e87691af4912f3630d92d692779.tar.bz2
voxelius-f40d09cb8f712e87691af4912f3630d92d692779.zip
Shuffle stuff around
- Use the new and improved hierarchy I figured out when making Prospero chat - Re-add NSIS scripts, again from Prospero - Update most build and utility scripts with their most recent versions
Diffstat (limited to 'src/game/server/chat.cc')
-rw-r--r--src/game/server/chat.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/game/server/chat.cc b/src/game/server/chat.cc
new file mode 100644
index 0000000..a0ceba8
--- /dev/null
+++ b/src/game/server/chat.cc
@@ -0,0 +1,55 @@
+#include "server/pch.hh"
+
+#include "server/chat.hh"
+
+#include "server/globals.hh"
+#include "server/sessions.hh"
+#include "shared/protocol.hh"
+
+static void on_chat_message_packet(const protocol::ChatMessage& packet)
+{
+ if(packet.type == protocol::ChatMessage::TEXT_MESSAGE) {
+ if(auto session = sessions::find(packet.peer)) {
+ server_chat::broadcast(packet.message.c_str(), session->client_username.c_str());
+ }
+ else {
+ server_chat::broadcast(packet.message.c_str(), packet.sender.c_str());
+ }
+ }
+}
+
+void server_chat::init(void)
+{
+ globals::dispatcher.sink<protocol::ChatMessage>().connect<&on_chat_message_packet>();
+}
+
+void server_chat::broadcast(std::string_view message)
+{
+ server_chat::broadcast(message, "server");
+}
+
+void server_chat::broadcast(std::string_view message, std::string_view sender)
+{
+ protocol::ChatMessage packet;
+ packet.type = protocol::ChatMessage::TEXT_MESSAGE;
+ packet.message = message;
+ packet.sender = sender;
+
+ protocol::broadcast(globals::server_host, protocol::encode(packet));
+
+ spdlog::info("<{}> {}", sender, message);
+}
+
+void server_chat::send(Session* session, std::string_view message)
+{
+ server_chat::send(session, message, "server");
+}
+
+void server_chat::send(Session* session, std::string_view message, std::string_view sender)
+{
+ protocol::ChatMessage packet;
+ packet.type = protocol::ChatMessage::TEXT_MESSAGE;
+ packet.message = message;
+ packet.sender = sender;
+ protocol::broadcast(globals::server_host, protocol::encode(packet));
+}