commands whois, whowas created and fixed, update ping, nick, commands.cpp, update Server and user

This commit is contained in:
Samy Ben Tayeb 2025-06-17 18:04:21 +02:00
parent 597aed08d8
commit 6ffc1e5534
16 changed files with 250 additions and 34 deletions

View file

@ -25,6 +25,8 @@
#include "userCmd.hpp"
#include "pass.hpp"
#include "part.hpp"
#include "whois.hpp"
#include "whowas.hpp"
#include <iterator>
/**
@ -40,7 +42,15 @@ std::vector<std::string> cmd::split(std::string &line) {
size_t start = 0;
size_t end;
while ((end = line.find(' ', start)) != std::string::npos) {
while (start < line.length()) {
if (line[start] == ':') {
std::string arg = line.substr(start + 1);
args.push_back(arg);
break;
}
end = line.find(' ', start);
if (end == std::string::npos)
end = line.length();
std::string arg = line.substr(start, end - start);
if (!arg.empty()) {
for (size_t i = 0; i < arg.length(); ++i)
@ -49,12 +59,6 @@ std::vector<std::string> cmd::split(std::string &line) {
}
start = end + 1;
}
if (start < line.length()) {
std::string arg = line.substr(start);
for (size_t i = 0; i < arg.length(); ++i)
arg[i] = std::tolower(arg[i]);
args.push_back(arg);
}
return args;
}
@ -135,6 +139,13 @@ void cmd::dispatch(::User *user, Channel *channel, Server *server, std::string &
userCmd(user, channel, server, line).execute();
}
break;
case 'w':
if (command_name == "whois") {
Whois(user, channel, server, line).execute();
} else if (command_name == "whowas") {
Whowas(user, channel, server, line).execute();
}
break;
default:
WARNING_MSG("Unknown command: " << command_name);
}