-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
101 lines (89 loc) · 2.69 KB
/
utils.cpp
File metadata and controls
101 lines (89 loc) · 2.69 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: diogosan <diogosan@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/05 14:30:28 by diogosan #+# #+# */
/* Updated: 2025/03/17 14:31:09 by diogosan ### ########.fr */
/* */
/* ************************************************************************** */
#include "Channel.hpp"
#include "Server.hpp"
#include <cstddef>
#include <string>
#include <vector>
bool Server::LookClientInChannel(std::string channel)
{
std::map<std::string, Channel>::iterator It = _channels.begin();
while (It != _channels.end())
{
if (getLower(It->first) == getLower(channel))
break;
++It;
}
if (It != _channels.end())
{
const std::map<int, std::vector<std::string> >& clients = It->second.getClients();
for (std::map<int, std::vector<std::string> >::const_iterator clientIt = clients.begin(); clientIt != clients.end(); ++clientIt)
{
if (clientIt->first == _clientFd)
{
return true;
}
}
}
return false;
}
bool Server::LookBotInChannel(std::string channel)
{
std::map<std::string, Channel>::iterator It = _channels.begin();
while (It != _channels.end())
{
if (getLower(It->first) == getLower(channel))
break;
++It;
}
if (It != _channels.end())
{
const std::map<int, std::vector<std::string> >& clients = It->second.getClients();
for (std::map<int, std::vector<std::string> >::const_iterator clientIt = clients.begin(); clientIt != clients.end(); ++clientIt)
{
if (clientIt->first == 424242)
{
return true;
}
}
}
return false;
}
std::string Server::getChannelTopic(std::string channel)
{
std::map<std::string, Channel>::iterator it = _channels.begin();
while (it != _channels.end())
{
if (getLower(it->first) == getLower(channel))
break;
++it;
}
if (it != _channels.end())
{
return it->second.getTopic();
}
return "";
}
void Server::changeChannelTopic(const std::string &channel, std::string &newTopic)
{
std::map<std::string, Channel>::iterator it = _channels.begin();
while (it != _channels.end())
{
if (getLower(it->first) == getLower(channel))
break;
++it;
}
if (it != _channels.end())
{
it->second.setTopic(newTopic);
}
}