summaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-09-26 00:11:20 +0200
committerGitHub <noreply@github.com>2017-09-26 00:11:20 +0200
commit6f1c90720402415b62fb4d5e809ec7dbc1cd7f96 (patch)
tree6f94c2bbc2d343be50945a0074bc16da282a4bc1 /src/client.cpp
parent6df312a608912b3cb21d04532151e29e8b0c7301 (diff)
downloadminetest-6f1c90720402415b62fb4d5e809ec7dbc1cd7f96.tar.gz
minetest-6f1c90720402415b62fb4d5e809ec7dbc1cd7f96.tar.bz2
minetest-6f1c90720402415b62fb4d5e809ec7dbc1cd7f96.zip
Implement mod communication channels (#6351)
Implement network communication for channels * Implement ModChannel manager server side to route incoming messages from clients to other clients * Add signal handler switch on client & ModChannelMgr on client to handle channels * Add Lua API bindings + client packet sending + unittests * Implement server message sending * Add callback from received message handler to Lua API using registration method
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);
+}