This repository was archived by the owner on Aug 3, 2025. It is now read-only.
forked from Jaapet/ft_irc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChannel.cpp
More file actions
149 lines (129 loc) · 3.22 KB
/
Copy pathChannel.cpp
File metadata and controls
149 lines (129 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "Channel.hpp"
Channel::Channel (std::string const &name, std::string const &founder)
{
this->name = name;
this->founder = founder;
this->op_topic = true;
this->invite = false;
this->pw = "";
this->topic = "";
this->max_users = 0;
this->creation_time_ts = Utils::getCurrentTimestamp();
}
Channel::~Channel ()
{
}
void Channel::set_name(const std::string &name)
{
this->name = name;
}
void Channel::set_pw(const std::string &pw)
{
this->pw = pw;
}
void Channel::set_topic(const std::string &topic, const std::string &user)
{
this->topic = topic;
this->topic_timestamp = Utils::getCurrentTimestamp();
this->topic_user = user;
}
void Channel::set_max_users(const size_t &max_users)
{
this->max_users = max_users;
}
void Channel::set_op_topic(const bool &op_topic)
{
this->op_topic = op_topic;
}
void Channel::set_invite(const bool &invite)
{
this->invite = invite;
}
//-----------------------------------------------------------------------------------------------
bool Channel::is_op(std::string const &nickname)
{
for (size_t i = 0; i < this->operators.size(); i++)
{
if (this->operators[i] == nickname)
return (true);
}
return (false);
}
bool Channel::is_user(std::string const &nickname)
{
std::vector<std::string> user = this->users;
std::vector<std::string>::iterator it = user.begin();
while(it != user.end())
{
if(it->data() == nickname)
return(true);
it++;
}
return(false);
}
void Channel::rm_op(std::string const &nickname)
{
std::vector<std::string>::iterator it = std::find(this->operators.begin(),this->operators.end(),nickname);
if(it != this->operators.end())
{
Debug::Warning("Remove a channel op his nickname is:" + nickname);
this->operators.erase(it);
}
else
Debug::Warning("Tried to remove an op who is not in the op list");
}
//-----------------------------------------------------------------------------------------------
int Channel::add_user(std::string const &nickname)
{
// if (this->invite && *std::find(this->invited_users.begin(), this->invited_users.end(), nickname) != nickname)
// return (1);
// if (*std::find(this->users.begin(), this->users.end(), nickname) == nickname)
// return (2);
// if (this->users.size() >= this->max_users && this->max_users)
// return (3);
this->users.push_back(nickname);
return (0);
}
bool Channel::rm_user(std::string const &nickname)
{
std::string temp;
// for (size_t i = 0; i < this->users.size(); i++)
// {
// if (this->users[i] == nickname)
// {
// this->users[i] = this->users[get_nmemb() - 1];
// this->users[get_nmemb() - 1] = nickname;
// this->users.pop_back();
// return (true);
// }
// }
std::vector<std::string>::iterator it = this->users.begin();
while(it != this->users.end())
{
if(it->data() == nickname)
{
this->users.erase(it);
return(true);
}
it++;
}
return (false);
}
void Channel::invite_user(std::string const &nickname)
{
for (size_t i = 0; i < this->invited_users.size(); i++)
{
if (this->invited_users[i] == nickname)
return ;
}
this->invited_users.push_back(nickname);
}
bool Channel::getUserInvited(std::string const &nickname)
{
for (size_t i = 0; i < this->invited_users.size(); i++)
{
if (this->invited_users[i] == nickname)
return true;
}
return false;
}