IRC_SERVER
By @hyunjunk (hyunjun2372@gmail.com)
Loading...
Searching...
No Matches
ChannelControlBlock.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5#include <map>
6
7#include "Core/Core.hpp"
8using namespace IRCCore;
9
10
11namespace IRC
12{
13
15
16class ChannelControlBlock : public FlexibleMemoryPoolingBase<ChannelControlBlock>
17{
18public:
19 std::string Name;
20
21 /** ""(empty string) means no topic */
22 std::string Topic;
23
24 /** Check bPrivate before checking this */
25 std::string Password;
26
27 std::map<std::string, WeakPtr< ClientControlBlock > > Clients;
28
29 std::map<std::string, WeakPtr< ClientControlBlock > > Operators;
30
31 /** '0' means no limit */
32 size_t MaxClients;
33
35
36 /** Topic settable by channel operator only flag */
38
39 /** Channel has a password */
41
42 std::map<std::string, WeakPtr< ClientControlBlock > > InvitedClients;
43
44 inline ChannelControlBlock(const std::string& name, SharedPtr< ClientControlBlock > creator, std::string creatorNickname)
45 : Name(name)
46 , Topic("")
47 , Password("")
48 , Clients()
49 , Operators()
50 , MaxClients(0)
51 , bInviteOnly(false)
52 , bTopicProtected(false)
53 , bPrivate(false)
54 {
55 Clients.insert(std::make_pair(creatorNickname, creator));
56 Operators.insert(std::make_pair(creatorNickname, creator));
57
58 // ! DEBUG. Constructor call check
59 std::cout << ANSI_BGRN << "Channel Created: " << Name << ANSI_RESET << std::endl;
60 }
61
63 {
64 // ! DEBUG. Destructor call check
65 std::cout << ANSI_BGRN << "Channel Deleted: " << Name << ANSI_RESET << std::endl;
66 }
67
69 {
70 std::map<std::string, WeakPtr< ClientControlBlock > >::iterator it = Clients.find(nickname);
71 if (it == Clients.end())
72 {
74 }
75 else if (it->second.Expired())
76 {
77 Clients.erase(it);
78 Operators.erase(nickname);
80 }
81 return it->second.Lock();
82 }
83
84 FORCEINLINE bool IsOperator(const std::string& nickname)
85 {
86 return Operators.find(nickname) != Operators.end();
87 }
88};
89
90
91} // namespace IRC
92
#define ANSI_BGRN
Definition AnsiColorDefines.hpp:20
#define ANSI_RESET
Definition AnsiColorDefines.hpp:5
#define FORCEINLINE
Definition AttributeDefines.hpp:55
Definition ChannelControlBlock.hpp:17
bool bPrivate
Channel has a password.
Definition ChannelControlBlock.hpp:40
std::map< std::string, WeakPtr< ClientControlBlock > > InvitedClients
Definition ChannelControlBlock.hpp:42
std::string Topic
""(empty string) means no topic
Definition ChannelControlBlock.hpp:22
bool bInviteOnly
Definition ChannelControlBlock.hpp:34
std::string Password
Check bPrivate before checking this.
Definition ChannelControlBlock.hpp:25
std::map< std::string, WeakPtr< ClientControlBlock > > Clients
Definition ChannelControlBlock.hpp:27
SharedPtr< ClientControlBlock > FindClient(const std::string &nickname)
Definition ChannelControlBlock.hpp:68
ChannelControlBlock(const std::string &name, SharedPtr< ClientControlBlock > creator, std::string creatorNickname)
Definition ChannelControlBlock.hpp:44
bool bTopicProtected
Topic settable by channel operator only flag.
Definition ChannelControlBlock.hpp:37
bool IsOperator(const std::string &nickname)
Definition ChannelControlBlock.hpp:84
size_t MaxClients
'0' means no limit
Definition ChannelControlBlock.hpp:32
std::map< std::string, WeakPtr< ClientControlBlock > > Operators
Definition ChannelControlBlock.hpp:29
~ChannelControlBlock()
Definition ChannelControlBlock.hpp:62
std::string Name
Definition ChannelControlBlock.hpp:19
Control block for management of a client connection and its information.
Definition ClientControlBlock.hpp:25
Base class for memory pooling with new/delete operator overloading.
Definition FlexibleMemoryPoolingBase.hpp:39
Shared pointer custom implementation for C++98 standard.
Definition SharedPtr.hpp:164
Definition ControlBlock.hpp:7
Definition ChannelControlBlock.hpp:12