feat(cmds): now compiling + removing the const line
This commit is contained in:
parent
4531cfbb8c
commit
fd011571bc
13 changed files with 53 additions and 45 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/20 23:31:58 by rparodi #+# #+# */
|
/* Created: 2025/05/20 23:31:58 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/06/08 22:19:40 by sben-tay ### ########.fr */
|
/* Updated: 2025/06/08 22:57:21 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -22,8 +22,8 @@
|
||||||
|
|
||||||
namespace cmd
|
namespace cmd
|
||||||
{
|
{
|
||||||
void dispatch(User *user, Channel *channel, Server *server, const std::string &line);
|
void dispatch(User *user, Channel *channel, Server *server, std::string &line);
|
||||||
std::vector<std::string> split(const std::string &line);
|
std::vector<std::string> split(std::string &line);
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T searchList(const std::list<T> &list, const std::string &name);
|
T searchList(const std::list<T> &list, const std::string &name);
|
||||||
|
|
||||||
|
|
@ -42,9 +42,10 @@ namespace cmd
|
||||||
virtual void execute() = 0;
|
virtual void execute() = 0;
|
||||||
virtual e_code checkArgs() = 0;
|
virtual e_code checkArgs() = 0;
|
||||||
~ACommand();
|
~ACommand();
|
||||||
ACommand(User *user, Channel *channel, Server *server, const std::string &line);
|
ACommand(User *user, Channel *channel, Server *server, std::string &line);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Cap;
|
||||||
class Invite;
|
class Invite;
|
||||||
class Join;
|
class Join;
|
||||||
class Kick;
|
class Kick;
|
||||||
|
|
@ -54,6 +55,7 @@ namespace cmd
|
||||||
class Nick;
|
class Nick;
|
||||||
class Notice;
|
class Notice;
|
||||||
class Part;
|
class Part;
|
||||||
|
class Pass;
|
||||||
class Ping;
|
class Ping;
|
||||||
class Pong;
|
class Pong;
|
||||||
class PrivMsg;
|
class PrivMsg;
|
||||||
|
|
@ -61,8 +63,6 @@ namespace cmd
|
||||||
class Topic;
|
class Topic;
|
||||||
class Unknown;
|
class Unknown;
|
||||||
class userCmd;
|
class userCmd;
|
||||||
class Pass;
|
|
||||||
class Cap;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "./commands/commands.tpp"
|
#include "./commands/commands.tpp"
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,18 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/06/08 22:08:44 by sben-tay #+# #+# */
|
/* Created: 2025/06/08 22:08:44 by sben-tay #+# #+# */
|
||||||
/* Updated: 2025/06/08 22:16:14 by sben-tay ### ########.fr */
|
/* Updated: 2025/06/08 22:42:04 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "commands.hpp"
|
#include "commands.hpp"
|
||||||
|
#include "core.hpp"
|
||||||
|
|
||||||
class cmd::Cap : public ACommand {
|
class cmd::Cap : public ACommand {
|
||||||
public:
|
public:
|
||||||
Cap(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
|
Cap(User *user, Channel *channel, Server *server, std::string &line) : ACommand(user, channel, server, line) {}
|
||||||
virtual void execute();
|
virtual void execute();
|
||||||
|
virtual e_code checkArgs();
|
||||||
};
|
};
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
class cmd::Invite : public ACommand {
|
class cmd::Invite : public ACommand {
|
||||||
public:
|
public:
|
||||||
Invite(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
|
Invite(User *user, Channel *channel, Server *server, std::string &line) : ACommand(user, channel, server, line) {}
|
||||||
virtual void execute(void);
|
virtual void execute(void);
|
||||||
virtual e_code checkArgs();
|
virtual e_code checkArgs();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
class cmd::Join : public ACommand {
|
class cmd::Join : public ACommand {
|
||||||
public:
|
public:
|
||||||
Join(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
|
Join(User *user, Channel *channel, Server *server, std::string &line) : ACommand(user, channel, server, line) {}
|
||||||
virtual void execute(void);
|
virtual void execute(void);
|
||||||
virtual e_code checkArgs();
|
virtual e_code checkArgs();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
class cmd::Nick : public ACommand {
|
class cmd::Nick : public ACommand {
|
||||||
public:
|
public:
|
||||||
Nick(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
|
Nick(User *user, Channel *channel, Server *server, std::string &line) : ACommand(user, channel, server, line) {}
|
||||||
virtual void execute(void);
|
virtual void execute(void);
|
||||||
virtual e_code checkArgs(void);
|
virtual e_code checkArgs(void);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
class cmd::Notice : public ACommand {
|
class cmd::Notice : public ACommand {
|
||||||
public:
|
public:
|
||||||
Notice(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
|
Notice(User *user, Channel *channel, Server *server, std::string &line) : ACommand(user, channel, server, line) {}
|
||||||
virtual void execute(void);
|
virtual void execute(void);
|
||||||
virtual e_code checkArgs();
|
virtual e_code checkArgs();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
class cmd::Part : public ACommand {
|
class cmd::Part : public ACommand {
|
||||||
public:
|
public:
|
||||||
Part(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
|
Part(User *user, Channel *channel, Server *server, std::string &line) : ACommand(user, channel, server, line) {}
|
||||||
virtual void execute(void);
|
virtual void execute(void);
|
||||||
virtual e_code checkArgs();
|
virtual e_code checkArgs();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
namespace cmd {
|
namespace cmd {
|
||||||
class Pass : public ACommand {
|
class Pass : public ACommand {
|
||||||
public:
|
public:
|
||||||
Pass(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
|
Pass(User *user, Channel *channel, Server *server, std::string &line) : ACommand(user, channel, server, line) {}
|
||||||
virtual void execute(void);
|
virtual void execute(void);
|
||||||
virtual e_code checkArgs();
|
virtual e_code checkArgs();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
class cmd::Ping : public ACommand {
|
class cmd::Ping : public ACommand {
|
||||||
public:
|
public:
|
||||||
Ping(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
|
Ping(User *user, Channel *channel, Server *server, std::string &line) : ACommand(user, channel, server, line) {}
|
||||||
virtual void execute(void);
|
virtual void execute(void);
|
||||||
virtual e_code checkArgs();
|
virtual e_code checkArgs();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
class cmd::PrivMsg : public ACommand {
|
class cmd::PrivMsg : public ACommand {
|
||||||
public:
|
public:
|
||||||
PrivMsg(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
|
PrivMsg(User *user, Channel *channel, Server *server, std::string &line) : ACommand(user, channel, server, line) {}
|
||||||
virtual void execute(void);
|
virtual void execute(void);
|
||||||
virtual e_code checkArgs();
|
virtual e_code checkArgs();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
class cmd::userCmd : public ACommand {
|
class cmd::userCmd : public ACommand {
|
||||||
public:
|
public:
|
||||||
userCmd(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
|
userCmd(User *user, Channel *channel, Server *server, std::string &line) : ACommand(user, channel, server, line) {}
|
||||||
virtual void execute();
|
virtual void execute();
|
||||||
virtual e_code checkArgs();
|
virtual e_code checkArgs();
|
||||||
};
|
};
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/06/08 22:10:24 by sben-tay #+# #+# */
|
/* Created: 2025/06/08 22:10:24 by sben-tay #+# #+# */
|
||||||
/* Updated: 2025/06/08 22:16:23 by sben-tay ### ########.fr */
|
/* Updated: 2025/06/08 22:45:35 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,17 +15,19 @@
|
||||||
|
|
||||||
using namespace cmd;
|
using namespace cmd;
|
||||||
|
|
||||||
cmd::Cap::Cap(User *user, Channel *channel, Server *server, const std::string &line)
|
e_code Cap::checkArgs() {
|
||||||
: ACommand(user, channel, server, line)
|
return _PARSING_OK;
|
||||||
{
|
|
||||||
_args = split(line);
|
|
||||||
_command = "CAP";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd::Cap::execute() {
|
void cmd::Cap::execute() {
|
||||||
|
DEBUG_MSG("coucou");
|
||||||
|
if (this->checkArgs() != _PARSING_OK)
|
||||||
|
return;
|
||||||
|
DEBUG_MSG("coucou");
|
||||||
if (_args.size() >= 2 && _args[1] == "LS") {
|
if (_args.size() >= 2 && _args[1] == "LS") {
|
||||||
std::string reply = "CAP * LS :\r\n";
|
std::string reply = "CAP * LS :\r\n";
|
||||||
_sender->appendToWriteBuffer(reply);
|
_sender->appendToWriteBuffer(reply);
|
||||||
DEBUG_MSG("Replied to CAP LS");
|
DEBUG_MSG("Replied to CAP LS");
|
||||||
}
|
}
|
||||||
|
DEBUG_MSG("coucou");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/24 16:11:56 by rparodi #+# #+# */
|
/* Created: 2025/05/24 16:11:56 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/06/08 20:20:11 by sben-tay ### ########.fr */
|
/* Updated: 2025/06/08 23:26:07 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,7 +16,9 @@
|
||||||
#include "ping.hpp"
|
#include "ping.hpp"
|
||||||
#include "nick.hpp"
|
#include "nick.hpp"
|
||||||
#include "userCmd.hpp"
|
#include "userCmd.hpp"
|
||||||
|
#include "cap.hpp"
|
||||||
|
#include <cctype>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief To send the line where a command is invoqued to execute
|
* @brief To send the line where a command is invoqued to execute
|
||||||
|
|
@ -25,21 +27,26 @@
|
||||||
* @param channel channel where the command is sent
|
* @param channel channel where the command is sent
|
||||||
* @param line line send by the user
|
* @param line line send by the user
|
||||||
*/
|
*/
|
||||||
std::vector<std::string> cmd::split(const std::string &line) {
|
std::vector<std::string> cmd::split(std::string &line) {
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
std::string arg;
|
std::string arg;
|
||||||
if (line.empty())
|
if (line.empty())
|
||||||
return args;
|
return args;
|
||||||
size_t pos = line.find(' ');
|
size_t pos = line.find(' ');
|
||||||
|
size_t old_pos = 0;
|
||||||
while (pos != std::string::npos) {
|
while (pos != std::string::npos) {
|
||||||
arg = line.substr(0, pos);
|
arg = line.substr(old_pos, pos);
|
||||||
if (!arg.empty()) {
|
if (arg.empty()) {
|
||||||
args.push_back(arg);
|
break;
|
||||||
}
|
}
|
||||||
pos = line.find(' ');
|
for (size_t i = 0; i < arg.length(); i++)
|
||||||
|
arg = std::tolower(line[i]);
|
||||||
|
args.push_back(arg);
|
||||||
|
old_pos = pos;
|
||||||
|
pos = line.find(' ', old_pos + 1);
|
||||||
}
|
}
|
||||||
if (!line.empty()) {
|
if (!line.empty()) {
|
||||||
args.push_back(line);
|
return args;
|
||||||
}
|
}
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
@ -52,11 +59,12 @@ std::vector<std::string> cmd::split(const std::string &line) {
|
||||||
* @param server Server where the command is sent
|
* @param server Server where the command is sent
|
||||||
* @param line input line from the user
|
* @param line input line from the user
|
||||||
*/
|
*/
|
||||||
void cmd::dispatch(::User *user, Channel *channel, Server *server, const std::string &line) {
|
void cmd::dispatch(::User *user, Channel *channel, Server *server, std::string &line) {
|
||||||
DEBUG_MSG("in dispatch");
|
DEBUG_MSG("in dispatch");
|
||||||
std::vector<std::string> args = cmd::split(line);
|
std::vector<std::string> args = cmd::split(line);
|
||||||
|
DEBUG_MSG("in dispatch");
|
||||||
if (args.empty()) {
|
if (args.empty()) {
|
||||||
ERROR_MSG("Empty line");
|
DEBUG_MSG("Empty line");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::string command_name = args[0];
|
std::string command_name = args[0];
|
||||||
|
|
@ -64,15 +72,11 @@ void cmd::dispatch(::User *user, Channel *channel, Server *server, const std::st
|
||||||
WARNING_MSG("No command found in line: " << line);
|
WARNING_MSG("No command found in line: " << line);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (command_name[0] == '/') {
|
std::cout << command_name << std::endl;
|
||||||
command_name.erase(0, 1);
|
DEBUG_MSG(command_name);
|
||||||
} else {
|
|
||||||
WARNING_MSG("Command does not start with '/': " << command_name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (command_name[0]) {
|
switch (command_name[0]) {
|
||||||
case 'c':
|
case 'c':
|
||||||
if (command_name == "CAP") {
|
if (command_name == "cap") {
|
||||||
Cap(user, channel, server, line).execute();
|
Cap(user, channel, server, line).execute();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -109,10 +113,10 @@ void cmd::dispatch(::User *user, Channel *channel, Server *server, const std::st
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
if (command_name == "PASS") {
|
if (command_name == "pass") {
|
||||||
Pass(user, channel, server, line).execute();
|
Pass(user, channel, server, line).execute();
|
||||||
}
|
}
|
||||||
if (command_name == "PING") {
|
if (command_name == "ping") {
|
||||||
Ping(user, channel, server, line).execute();
|
Ping(user, channel, server, line).execute();
|
||||||
}
|
}
|
||||||
// if (command_name == "part") {
|
// if (command_name == "part") {
|
||||||
|
|
@ -120,7 +124,7 @@ void cmd::dispatch(::User *user, Channel *channel, Server *server, const std::st
|
||||||
// }
|
// }
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
if (command_name == "USER") {
|
if (command_name == "user") {
|
||||||
userCmd(user, channel, server, line).execute();
|
userCmd(user, channel, server, line).execute();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -133,7 +137,7 @@ void cmd::dispatch(::User *user, Channel *channel, Server *server, const std::st
|
||||||
(void)line;
|
(void)line;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd::ACommand::ACommand(::User *user, ::Channel *channel, ::Server *server, const std::string &line) : _sender(user), _channel(channel), _server(server) {
|
cmd::ACommand::ACommand(::User *user, ::Channel *channel, ::Server *server, std::string &line) : _sender(user), _channel(channel), _server(server) {
|
||||||
DEBUG_MSG("ACommand constructor called");
|
DEBUG_MSG("ACommand constructor called");
|
||||||
_args = split(line);
|
_args = split(line);
|
||||||
_command = _args.at(0);
|
_command = _args.at(0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue