-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIRCCommandHandler.cpp
More file actions
86 lines (78 loc) · 3.01 KB
/
IRCCommandHandler.cpp
File metadata and controls
86 lines (78 loc) · 3.01 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* IRCCommandHandler.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adiaz-uf <adiaz-uf@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/17 07:25:15 by bmatos-d #+# #+# */
/* Updated: 2025/01/21 11:33:35 by adiaz-uf ### ########.fr */
/* */
/* ************************************************************************** */
# include "IRCCommandHandler.hpp"
std::vector<std::string> IRCCommandHandler::split_istringstream(std::string str) {
std::vector<std::string> split;
std::istringstream isstream(str);
std::string word;
while(isstream >> word){
split.push_back(word);
}
return split;
}
void IRCCommandHandler::handleCommand(Server &server, Client &client, std::string input)
{
int fd = client.getSocket();
int n = -1;
std::string ircCommands[13] = { "PASS", "JOIN", "NICK", "TOPIC", "KICK", "MODE", "PRIVMSG", "INVITE", "USER", "PART", "QUIT", "WHO", "BOT"};
std::vector<std::string> command = IRCCommandHandler::split_istringstream(input);
std::transform(command[0].begin(), command[0].end(), command[0].begin(), ::toupper);
do
n++;
while (n < 13 && command[0] != ircCommands[n]);
if (!client.isAuthenticated() && n != 0 && n != 2 && n != 8)
return(server.sendMessageToClient("You must provide the PASS, USER and NICK first.\r\n", client.getSocket()));
switch (n)
{
case 0:
pass(command, server, client);
break;
case 1:
join(command, server, client);
break;
case 2:
nick(command, server, client);
break;
case 3:
topic(command, server, client);
break;
case 4:
kick(command, server, client);
break;
case 5:
mode(command, server, client);
break;
case 6:
privmsg(command, server, client);
break;
case 7:
invite(command, server, client);
break;
case 8:
user(command, server, client);
break;
case 9:
part(command, server, client);
break;
case 10:
quit(command, server, client);
break;
case 11:
who(command, server, client);
break;
case 12:
bot(command, server, client);
default:
break;
}
if (server.getClient(fd)) if (client.isAuthenticated() == false) client.authenticate(server);
}