-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathquit.cpp
More file actions
50 lines (47 loc) · 1.32 KB
/
quit.cpp
File metadata and controls
50 lines (47 loc) · 1.32 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
#include "server.hpp"
#include "Channel.hpp"
#include "numeric_replies.hpp"
void Server::remove_fd(int fd)
{
for(size_t i = 0; i < this->pollfds.size(); i++)
{
if(this->pollfds[i].fd == fd)
{
this->pollfds.erase(this->pollfds.begin() + i);
break;
}
}
}
void Server::monitor_channells()
{
if(this->channels.size() == 0)
return;
for(std::vector<Channel>::iterator it = this->channels.begin(); it != this->channels.end(); it++)
{
if(it->get_users().size() == 0)
{
this->channels.erase(it);
it = this->channels.begin();
}
if(this->channels.size() == 1)
break;
}
if(channels[0].get_users().size() == 0)
this->channels.erase(channels.begin());
}
void Server::quit_cmd(int client_socket)
{
Client client_caller = clients[client_socket];
std::string msg = ":" + client_caller.get_nickname() + " QUIT\r\n";
for(size_t i = 0; i < this->channels.size(); i++)
{
if(channels[i].search_client_in_channel(client_caller.get_nickname()) != 0)
{
part_cmd(client_socket, channels[i].get_name());
}
}
send(client_socket, msg.c_str(),msg.length(),0);
remove_fd(client_socket);
clients.erase(client_socket);
close(client_socket);
}