aboutsummaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/client.cpp')
-rw-r--r--src/client.cpp58
1 files changed, 57 insertions, 1 deletions
diff --git a/src/client.cpp b/src/client.cpp
index a56e3c974..4e6dc102c 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -39,6 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock_mesh.h"
#include "mapblock.h"
#include "minimap.h"
+#include "modchannels.h"
#include "mods.h"
#include "profiler.h"
#include "shader.h"
@@ -94,7 +95,8 @@ Client::Client(
m_chosen_auth_mech(AUTH_MECHANISM_NONE),
m_media_downloader(new ClientMediaDownloader()),
m_state(LC_Created),
- m_game_ui_flags(game_ui_flags)
+ m_game_ui_flags(game_ui_flags),
+ m_modchannel_mgr(new ModChannelMgr())
{
// Add local player
m_env.setLocalPlayer(new LocalPlayer(this, playername));
@@ -1919,3 +1921,57 @@ std::string Client::getModStoragePath() const
{
return porting::path_user + DIR_DELIM + "client" + DIR_DELIM + "mod_storage";
}
+
+/*
+ * Mod channels
+ */
+
+bool Client::joinModChannel(const std::string &channel)
+{
+ if (m_modchannel_mgr->channelRegistered(channel))
+ return false;
+
+ NetworkPacket pkt(TOSERVER_MODCHANNEL_JOIN, 2 + channel.size());
+ pkt << channel;
+ Send(&pkt);
+
+ m_modchannel_mgr->joinChannel(channel, 0);
+ return true;
+}
+
+bool Client::leaveModChannel(const std::string &channel)
+{
+ if (!m_modchannel_mgr->channelRegistered(channel))
+ return false;
+
+ NetworkPacket pkt(TOSERVER_MODCHANNEL_LEAVE, 2 + channel.size());
+ pkt << channel;
+ Send(&pkt);
+
+ m_modchannel_mgr->leaveChannel(channel, 0);
+ return true;
+}
+
+bool Client::sendModChannelMessage(const std::string &channel, const std::string &message)
+{
+ if (!m_modchannel_mgr->canWriteOnChannel(channel))
+ return false;
+
+ if (message.size() > STRING_MAX_LEN) {
+ warningstream << "ModChannel message too long, dropping before sending "
+ << " (" << message.size() << " > " << STRING_MAX_LEN << ", channel: "
+ << channel << ")" << std::endl;
+ return false;
+ }
+
+ // @TODO: do some client rate limiting
+ NetworkPacket pkt(TOSERVER_MODCHANNEL_MSG, 2 + channel.size() + 2 + message.size());
+ pkt << channel << message;
+ Send(&pkt);
+ return true;
+}
+
+ModChannel* Client::getModChannel(const std::string &channel)
+{
+ return m_modchannel_mgr->getModChannel(channel);
+}