3 Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <unordered_map>
26 #include "network/networkprotocol.h"
27 #include "irrlichttypes.h"
29 enum ModChannelState : u8
31 MODCHANNEL_STATE_INIT,
32 MODCHANNEL_STATE_READ_WRITE,
33 MODCHANNEL_STATE_READ_ONLY,
40 ModChannel(const std::string &name) : m_name(name) {}
41 ~ModChannel() = default;
43 const std::string &getName() const { return m_name; }
44 bool registerConsumer(session_t peer_id);
45 bool removeConsumer(session_t peer_id);
46 const std::vector<u16> &getChannelPeers() const { return m_client_consumers; }
47 bool canWrite() const;
48 void setState(ModChannelState state);
52 ModChannelState m_state = MODCHANNEL_STATE_INIT;
53 std::vector<u16> m_client_consumers;
56 enum ModChannelSignal : u8
58 MODCHANNEL_SIGNAL_JOIN_OK,
59 MODCHANNEL_SIGNAL_JOIN_FAILURE,
60 MODCHANNEL_SIGNAL_LEAVE_OK,
61 MODCHANNEL_SIGNAL_LEAVE_FAILURE,
62 MODCHANNEL_SIGNAL_CHANNEL_NOT_REGISTERED,
63 MODCHANNEL_SIGNAL_SET_STATE,
69 ModChannelMgr() = default;
70 ~ModChannelMgr() = default;
72 void registerChannel(const std::string &channel);
73 bool setChannelState(const std::string &channel, ModChannelState state);
74 bool joinChannel(const std::string &channel, session_t peer_id);
75 bool leaveChannel(const std::string &channel, session_t peer_id);
76 bool channelRegistered(const std::string &channel) const;
77 ModChannel *getModChannel(const std::string &channel);
79 * This function check if a local mod can write on the channel
82 * @return true if write is allowed
84 bool canWriteOnChannel(const std::string &channel) const;
85 void leaveAllChannels(session_t peer_id);
86 const std::vector<u16> &getChannelPeers(const std::string &channel) const;
89 bool removeChannel(const std::string &channel);
91 std::unordered_map<std::string, std::unique_ptr<ModChannel>>
92 m_registered_channels;