diff --git a/includes/client.hpp b/includes/client.hpp index 92e0bd4..f328f72 100644 --- a/includes/client.hpp +++ b/includes/client.hpp @@ -6,7 +6,7 @@ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/21 10:33:17 by maldavid #+# #+# */ -/* Updated: 2024/01/30 17:06:21 by vvaas ### ########.fr */ +/* Updated: 2024/01/30 21:12:10 by vvaas ### ########.fr */ /* */ /******************************************************************************/ @@ -41,7 +41,7 @@ namespace irc inline void login() { _logged = true; } inline void register_user() { _registered = true; } - inline void welcome() { if (!isLogged() || isWelcomed() || _nickname.empty()) return ; _welcomed = true; sendCode(RPL_WELCOME, "Welcome to yipirc :), " + _nickname); } + inline void welcome() { if (!isLogged() || !isRegistered() || isWelcomed() || _nickname.empty()) return ; _welcomed = true; sendCode(RPL_WELCOME, "Welcome to yipirc :), " + _nickname); } inline void requireDisconnect() { _disconnect_required = true; } inline bool isLogged() const { return _logged; } diff --git a/srcs/channel.cpp b/srcs/channel.cpp index 87cc8ef..cf0427d 100644 --- a/srcs/channel.cpp +++ b/srcs/channel.cpp @@ -6,7 +6,7 @@ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/21 10:36:21 by maldavid #+# #+# */ -/* Updated: 2024/01/30 21:06:03 by maldavid ### ########.fr */ +/* Updated: 2024/01/30 21:26:58 by vvaas ### ########.fr */ /* */ /******************************************************************************/ @@ -41,7 +41,6 @@ namespace irc void Channel::modOperator(unstd::SharedPtr client, const std::string& clientname, bool mode) { client_it it; - logs::report(log_message, "mode operator, mode = %d", mode); if(mode) { for(it = _clients.begin(); it != _clients.end(); ++it) @@ -59,10 +58,8 @@ namespace irc for(it = _operators.begin(); it != _operators.end(); ++it) { - logs::report(log_message, "nickname %s, clientname : %s", const_cast&>(*it)->getNickName().c_str(), clientname.c_str()); if(const_cast&>(*it)->getNickName() == clientname) { - logs::report(log_message, "found %s to erase", const_cast&>(*it)->getNickName().c_str()); _operators.erase(it); break; } @@ -99,7 +96,6 @@ namespace irc clientlist += '@'; clientlist += const_cast&>(*it)->getNickName() + ' '; } - logs::report(log_message, "%s", clientlist.c_str()); client->sendModular("%s\r\n", clientlist.c_str()); clientlist = ":yipirc " RPL_NAMREPLY " " + client->getNickName() + " @ " + getName() + " :"; client->sendModular(":yipirc %s %s %s : End of names list\r\n", RPL_ENDOFNAMES, client->getNickName().c_str(), getName().c_str()); @@ -154,7 +150,6 @@ namespace irc void Channel::changeMode(unstd::SharedPtr client, const Message& msg) { bool modevalue = (msg.getTokens()[2][0] != '-'); - logs::report(log_message, "tokensize : %d, mode : %c, modevalue %d", msg.getTokens().size(), msg.getTokens()[2][1], modevalue); switch(msg.getTokens()[2][1]) { case 'i': _invite_only = modevalue; break; @@ -204,7 +199,6 @@ namespace irc default : client->sendCode(":yipirc " ERR_UNKNOWNMODE " @", getName().c_str(), "Unknown mode"); return; } - logs::report(log_message, "%s MODES : i:%d t:%d k:%s l:%d", getName().c_str(), _invite_only, _topic_op_restrict, _password.c_str(), _channel_size); showModesModify(client, msg); } diff --git a/srcs/server.cpp b/srcs/server.cpp index ae067ee..ee00aff 100644 --- a/srcs/server.cpp +++ b/srcs/server.cpp @@ -6,7 +6,7 @@ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/21 09:31:17 by maldavid #+# #+# */ -/* Updated: 2024/01/30 21:06:26 by maldavid ### ########.fr */ +/* Updated: 2024/01/30 21:22:56 by vvaas ### ########.fr */ /* */ /******************************************************************************/ @@ -92,7 +92,7 @@ namespace irc close((*it)->getFD()); for(channel_it cit = _channels.begin(); cit != _channels.end();) { - cit->removeClient(*it, ""); + cit->removeClient(*it, "", true); if(cit->getNumberOfClients() == 0) { logs::report(log_message, "channel '%s' has been destroyed", cit->getName().c_str()); diff --git a/srcs/server_functions.cpp b/srcs/server_functions.cpp index 6e8bd90..4e05dd0 100644 --- a/srcs/server_functions.cpp +++ b/srcs/server_functions.cpp @@ -6,7 +6,7 @@ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/22 17:31:06 by maldavid #+# #+# */ -/* Updated: 2024/01/30 21:05:17 by maldavid ### ########.fr */ +/* Updated: 2024/01/30 21:33:51 by vvaas ### ########.fr */ /* */ /******************************************************************************/ @@ -41,11 +41,8 @@ namespace irc client->sendCode(ERR_NONICKNAMEGIVEN, "No nickname given"); return; } - if(msg.getTokens().size() != 2 && msg.getTokens().size() != 3) - { - logs::report(log_error, "NICK, invalid command '%s'", msg.getRawMsg().c_str()); - return; - } + if(msg.getTokens().size() >= 3) + return ; const std::string& nickname = msg.getTokens()[1]; for(client_it it = _client.begin(); it != _client.end(); ++it) { @@ -73,7 +70,6 @@ namespace irc if(msg.getTokens().size() < 5) { client->sendCode(ERR_NEEDMOREPARAMS, "Need more parameters"); - logs::report(log_error, "USER, invalid command '%s'", msg.getRawMsg().c_str()); return; } if(client->isRegistered()) @@ -99,6 +95,8 @@ namespace irc realname.erase(realname.end() - 1); client->setNewRealName(realname); std::cout << "new realname, " << client->getRealName() << std::endl; + client->register_user(); + client->welcome(); } void Server::handlePass(unstd::SharedPtr client, const Message& msg) @@ -129,14 +127,11 @@ namespace irc { if(msg.getTokens().size() < 2 && msg.getTokens().size() > 3) { - logs::report(log_error, "PART, invalid command '%s'", msg.getRawMsg().c_str()); + client->sendCode(ERR_NEEDMOREPARAMS, "Parameters amount invalid"); return; } if(msg.getTokens()[1][0] != '#' && msg.getTokens()[1][0] != '&') - { - logs::report(log_error, "PART, invalid channel name '%s'", msg.getTokens()[1].c_str()); return; - } if(!isChannelKnown(msg.getArgs()[0])) { client->sendCode(ERR_NOSUCHCHANNEL, msg.getArgs()[0] + " no such channel"); @@ -170,14 +165,10 @@ namespace irc if(msg.getArgs().empty()) { client->sendCode(ERR_NEEDMOREPARAMS, "Need more params"); - logs::report(log_error, "JOIN, invalid command '%s'", msg.getRawMsg().c_str()); return; } if(msg.getTokens()[1][0] != '#' && msg.getTokens()[1][0] != '&') - { - logs::report(log_error, "JOIN, invalid channel name '%s'", msg.getTokens()[1].c_str()); return; - } channel_it it; for(it = _channels.begin(); it != _channels.end(); ++it) @@ -208,14 +199,19 @@ namespace irc { if(msg.getArgs().empty()) { - client->sendCode(ERR_NORECIPIENT, "No recipient given\n"); + client->sendCode(ERR_NORECIPIENT, "No recipient given"); return; } if(msg.getTokens().size() < 3) { - client->sendCode(ERR_NOTEXTTOSEND, "No text to send\n"); + client->sendCode(ERR_NOTEXTTOSEND, "No text to send"); return; } + if(msg.getReason().empty()) + { + client->sendCode(ERR_NOTEXTTOSEND, "No text to send"); + return ; + } if(msg.getTokens()[1][0] != '&' && msg.getTokens()[1][0] != '#') { for(client_it itc = _client.begin(); itc != _client.end(); ++itc) @@ -268,10 +264,7 @@ namespace irc void Server::handleNotice(unstd::SharedPtr client, const Message& msg) { if(msg.getArgs().empty()) - { - logs::report(log_error, "NOTICE, invalid command '%s'", msg.getRawMsg().c_str()); return; - } if(msg.getTokens()[1][0] != '&' && msg.getTokens()[1][0] != '#') { for(client_it itc = _client.begin(); itc != _client.end(); ++itc) @@ -318,7 +311,7 @@ namespace irc { if(msg.getArgs().empty() || msg.getArgs().size() != 2) { - logs::report(log_error, "INVITE, invalid command '%s'", msg.getRawMsg().c_str()); + client->sendCode(ERR_NEEDMOREPARAMS, "Invalid parameters"); return; } @@ -368,7 +361,7 @@ namespace irc { if(msg.getArgs().empty()) { - logs::report(log_error, "KICK, invalid command '%s'", msg.getRawMsg().c_str()); + client->sendCode(ERR_NONICKNAMEGIVEN, "No nickname given"); return; } @@ -403,10 +396,7 @@ namespace irc logs::report(log_fatal_error, "(KICK), cannot get client '%s' by name; panic !", user->c_str()); if(!channel_target->kick(client, client_target, msg.getReason())) - { - logs::report(log_error, "could not kick %s because why not", user->c_str()); continue; - } client->printUserHeader(); std::cout << "kicked " << *user << " from " << *channel << std::endl; if(channel_target->getNumberOfClients() == 0) @@ -427,7 +417,6 @@ namespace irc { irc::Channel *chan; - logs::report(log_message, "tokensize ok : %d", msg.getTokens().size()); if(msg.getTokens().size() != 2) return; if((chan = getChannelByName(msg.getTokens()[1])) == NULL) @@ -439,7 +428,7 @@ namespace irc { if(msg.getArgs().empty()) { - logs::report(log_error, "TOPIC, invalid command '%s'", msg.getRawMsg().c_str()); + client->sendCode(ERR_NEEDMOREPARAMS, "Need more parameters"); return; } if(!isChannelKnown(msg.getArgs()[0])) @@ -468,10 +457,7 @@ namespace irc void Server::handlePing(unstd::SharedPtr client, const Message& msg) { if(msg.getTokens().size() == 1) - { - logs::report(log_error, "PING, invalid command '%s'", msg.getRawMsg().c_str()); return; - } std::string out = "PONG"; for(std::vector::const_iterator it = msg.getTokens().begin() + 1; it < msg.getTokens().end(); ++it) out += ' ' + *it;