Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
modchannels.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
4
5#pragma once
6
7#include <unordered_map>
8#include <string>
9#include <vector>
10#include <memory>
12#include "irrlichttypes.h"
13
21
23{
24public:
25 ModChannel(const std::string &name) : m_name(name) {}
26 ~ModChannel() = default;
27
28 const std::string &getName() const { return m_name; }
29 bool registerConsumer(session_t peer_id);
30 bool removeConsumer(session_t peer_id);
31 const std::vector<u16> &getChannelPeers() const { return m_client_consumers; }
32 bool canWrite() const;
33 void setState(ModChannelState state);
34
35private:
36 std::string m_name;
38 std::vector<u16> m_client_consumers;
39};
40
50
52{
53public:
54 ModChannelMgr() = default;
55 ~ModChannelMgr() = default;
56
57 void registerChannel(const std::string &channel);
58 bool setChannelState(const std::string &channel, ModChannelState state);
59 bool joinChannel(const std::string &channel, session_t peer_id);
60 bool leaveChannel(const std::string &channel, session_t peer_id);
61 bool channelRegistered(const std::string &channel) const;
62 ModChannel *getModChannel(const std::string &channel);
69 bool canWriteOnChannel(const std::string &channel) const;
70 void leaveAllChannels(session_t peer_id);
71 const std::vector<u16> &getChannelPeers(const std::string &channel) const;
72
73private:
74 bool removeChannel(const std::string &channel);
75
76 std::unordered_map<std::string, std::unique_ptr<ModChannel>>
78};
Definition modchannels.h:52
~ModChannelMgr()=default
void leaveAllChannels(session_t peer_id)
Definition modchannels.cpp:122
std::unordered_map< std::string, std::unique_ptr< ModChannel > > m_registered_channels
Definition modchannels.h:77
bool canWriteOnChannel(const std::string &channel) const
This function check if a local mod can write on the channel.
Definition modchannels.cpp:64
bool channelRegistered(const std::string &channel) const
Definition modchannels.cpp:51
bool joinChannel(const std::string &channel, session_t peer_id)
Definition modchannels.cpp:99
bool leaveChannel(const std::string &channel, session_t peer_id)
Definition modchannels.cpp:107
void registerChannel(const std::string &channel)
Definition modchannels.cpp:74
ModChannelMgr()=default
ModChannel * getModChannel(const std::string &channel)
Definition modchannels.cpp:56
const std::vector< u16 > & getChannelPeers(const std::string &channel) const
Definition modchannels.cpp:129
bool removeChannel(const std::string &channel)
Definition modchannels.cpp:90
bool setChannelState(const std::string &channel, ModChannelState state)
Definition modchannels.cpp:79
Definition modchannels.h:23
bool registerConsumer(session_t peer_id)
Definition modchannels.cpp:10
const std::string & getName() const
Definition modchannels.h:28
const std::vector< u16 > & getChannelPeers() const
Definition modchannels.h:31
ModChannel(const std::string &name)
Definition modchannels.h:25
bool removeConsumer(session_t peer_id)
Definition modchannels.cpp:21
ModChannelState m_state
Definition modchannels.h:37
void setState(ModChannelState state)
Definition modchannels.cpp:44
std::string m_name
Definition modchannels.h:36
bool canWrite() const
Definition modchannels.cpp:39
std::vector< u16 > m_client_consumers
Definition modchannels.h:38
~ModChannel()=default
ModChannelState
Definition modchannels.h:15
@ MODCHANNEL_STATE_READ_ONLY
Definition modchannels.h:18
@ MODCHANNEL_STATE_MAX
Definition modchannels.h:19
@ MODCHANNEL_STATE_INIT
Definition modchannels.h:16
@ MODCHANNEL_STATE_READ_WRITE
Definition modchannels.h:17
ModChannelSignal
Definition modchannels.h:42
@ MODCHANNEL_SIGNAL_LEAVE_OK
Definition modchannels.h:45
@ MODCHANNEL_SIGNAL_LEAVE_FAILURE
Definition modchannels.h:46
@ MODCHANNEL_SIGNAL_CHANNEL_NOT_REGISTERED
Definition modchannels.h:47
@ MODCHANNEL_SIGNAL_SET_STATE
Definition modchannels.h:48
@ MODCHANNEL_SIGNAL_JOIN_OK
Definition modchannels.h:43
@ MODCHANNEL_SIGNAL_JOIN_FAILURE
Definition modchannels.h:44
u16 session_t
Definition networkprotocol.h:22