Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
modchannels.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
22#include <unordered_map>
23#include <string>
24#include <vector>
25#include <memory>
27#include "irrlichttypes.h"
28
30{
35};
36
38{
39public:
40 ModChannel(const std::string &name) : m_name(name) {}
41 ~ModChannel() = default;
42
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);
49
50private:
51 std::string m_name;
53 std::vector<u16> m_client_consumers;
54};
55
57{
64};
65
67{
68public:
69 ModChannelMgr() = default;
70 ~ModChannelMgr() = default;
71
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);
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;
87
88private:
89 bool removeChannel(const std::string &channel);
90
91 std::unordered_map<std::string, std::unique_ptr<ModChannel>>
93};
Definition: modchannels.h:67
~ModChannelMgr()=default
void leaveAllChannels(session_t peer_id)
Definition: modchannels.cpp:137
std::unordered_map< std::string, std::unique_ptr< ModChannel > > m_registered_channels
Definition: modchannels.h:92
bool canWriteOnChannel(const std::string &channel) const
This function check if a local mod can write on the channel.
Definition: modchannels.cpp:79
bool channelRegistered(const std::string &channel) const
Definition: modchannels.cpp:66
bool joinChannel(const std::string &channel, session_t peer_id)
Definition: modchannels.cpp:114
bool leaveChannel(const std::string &channel, session_t peer_id)
Definition: modchannels.cpp:122
void registerChannel(const std::string &channel)
Definition: modchannels.cpp:89
ModChannelMgr()=default
ModChannel * getModChannel(const std::string &channel)
Definition: modchannels.cpp:71
const std::vector< u16 > & getChannelPeers(const std::string &channel) const
Definition: modchannels.cpp:144
bool removeChannel(const std::string &channel)
Definition: modchannels.cpp:105
bool setChannelState(const std::string &channel, ModChannelState state)
Definition: modchannels.cpp:94
Definition: modchannels.h:38
bool registerConsumer(session_t peer_id)
Definition: modchannels.cpp:25
const std::string & getName() const
Definition: modchannels.h:43
const std::vector< u16 > & getChannelPeers() const
Definition: modchannels.h:46
ModChannel(const std::string &name)
Definition: modchannels.h:40
bool removeConsumer(session_t peer_id)
Definition: modchannels.cpp:36
ModChannelState m_state
Definition: modchannels.h:52
void setState(ModChannelState state)
Definition: modchannels.cpp:59
std::string m_name
Definition: modchannels.h:51
bool canWrite() const
Definition: modchannels.cpp:54
std::vector< u16 > m_client_consumers
Definition: modchannels.h:53
~ModChannel()=default
ModChannelState
Definition: modchannels.h:30
@ MODCHANNEL_STATE_READ_ONLY
Definition: modchannels.h:33
@ MODCHANNEL_STATE_MAX
Definition: modchannels.h:34
@ MODCHANNEL_STATE_INIT
Definition: modchannels.h:31
@ MODCHANNEL_STATE_READ_WRITE
Definition: modchannels.h:32
ModChannelSignal
Definition: modchannels.h:57
@ MODCHANNEL_SIGNAL_LEAVE_OK
Definition: modchannels.h:60
@ MODCHANNEL_SIGNAL_LEAVE_FAILURE
Definition: modchannels.h:61
@ MODCHANNEL_SIGNAL_CHANNEL_NOT_REGISTERED
Definition: modchannels.h:62
@ MODCHANNEL_SIGNAL_SET_STATE
Definition: modchannels.h:63
@ MODCHANNEL_SIGNAL_JOIN_OK
Definition: modchannels.h:58
@ MODCHANNEL_SIGNAL_JOIN_FAILURE
Definition: modchannels.h:59
u16 session_t
Definition: networkprotocol.h:251