diff --git a/DALnet_logs b/DALnet_logs deleted file mode 100644 index d07bef9..0000000 --- a/DALnet_logs +++ /dev/null @@ -1,160 +0,0 @@ -<< CAP LS -<< NICK rmorel -<< USER rmorel rmorel irc.dal.net :Romain MOREL ->> :punch.wa.us.dal.net NOTICE AUTH :*** Looking up your hostname... ->> :punch.wa.us.dal.net NOTICE AUTH :*** Found your hostname ->> :punch.wa.us.dal.net 001 rmorel :Welcome to the DALnet IRC Network rmorel!~rmorel@62.210.33.230 -<< MODE rmorel +i ->> :punch.wa.us.dal.net 002 rmorel :Your host is punch.wa.us.dal.net, running version bahamut-2.2.2 ->> :punch.wa.us.dal.net 003 rmorel :This server was created Wed Oct 12 2022 at 20:31:55 UTC ->> :punch.wa.us.dal.net 004 rmorel punch.wa.us.dal.net bahamut-2.2.2 aAbcCdefFghHiIjkKmnoOPrRsSwxXy AbceiIjklLmMnoOpPrRsStv beIjklov ->> :punch.wa.us.dal.net 005 rmorel NETWORK=DALnet SAFELIST MAXBANS=200 MAXCHANNELS=50 CHANNELLEN=32 KICKLEN=307 NICKLEN=30 TOPICLEN=307 MODES=6 CHANTYPES=# CHANLIMIT=#:50 PREFIX=(ohv)@%+ STATUSMSG=@%+ :are available on this server ->> :punch.wa.us.dal.net 005 rmorel CASEMAPPING=ascii WATCH=128 SILENCE=10 ELIST=cmntu EXCEPTS INVEX CHANMODES=beI,k,jl,ciPAmMnOprRsSt MAXLIST=b:200,e:100,I:100 TARGMAX=DCCALLOW:,JOIN:,KICK:4,KILL:20,NOTICE:20,PART:,PRIVMSG:20,WHOIS:,WHOWAS: :are available on this server ->> :punch.wa.us.dal.net 251 rmorel :There are 82 users and 7268 invisible on 37 servers ->> :punch.wa.us.dal.net 252 rmorel 77 :IRC Operators online ->> :punch.wa.us.dal.net 254 rmorel 3785 :channels formed ->> :punch.wa.us.dal.net 255 rmorel :I have 217 clients and 1 servers ->> :punch.wa.us.dal.net 265 rmorel :Current local users: 217 Max: 2105 ->> :punch.wa.us.dal.net 266 rmorel :Current global users: 7350 Max: 12060 ->> :punch.wa.us.dal.net NOTICE rmorel :*** Notice -- motd was last changed at 14/8/2020 11:15 ->> :punch.wa.us.dal.net NOTICE rmorel :*** Notice -- Please read the motd if you haven't read it ->> :punch.wa.us.dal.net 375 rmorel :- punch.wa.us.dal.net Message of the Day - ->> :punch.wa.us.dal.net 372 rmorel :- ->> :punch.wa.us.dal.net 372 rmorel :- Welcome to DALnet! This is punch.wa.us.dal.net, and YOU are ->> :punch.wa.us.dal.net 372 rmorel :- the reason punch.* is here! ->> :punch.wa.us.dal.net 372 rmorel :- ->> :punch.wa.us.dal.net 372 rmorel :- SERVER RULES: ->> :punch.wa.us.dal.net 372 rmorel :- ->> :punch.wa.us.dal.net 372 rmorel :- IMPERSONATION, CLONING, SPAMMING, FLOODING, ->> :punch.wa.us.dal.net 372 rmorel :- OR ANY OTHER KIND OF ABUSE CAN ->> :punch.wa.us.dal.net 372 rmorel :- AND WILL CAUSE YOU TO BE BANNED FROM THIS ->> :punch.wa.us.dal.net 372 rmorel :- SERVER AT ANY GIVEN TIME ->> :punch.wa.us.dal.net 372 rmorel :- ->> :punch.wa.us.dal.net 372 rmorel :- We reserve the right to deny access to this server without ->> :punch.wa.us.dal.net 372 rmorel :- warning or explanation. Usage is governed by the DALnet ->> :punch.wa.us.dal.net 372 rmorel :- AUP at . ->> :punch.wa.us.dal.net 372 rmorel :- ->> :punch.wa.us.dal.net 372 rmorel :- * For help: /join #help * ->> :punch.wa.us.dal.net 372 rmorel :- * For IRCop/CSop assistance: /join #OperHelp * ->> :punch.wa.us.dal.net 372 rmorel :- * For multilingual information: * ->> :punch.wa.us.dal.net 372 rmorel :- * For server related problems: punch-staff@dal.net * ->> :punch.wa.us.dal.net 372 rmorel :- ->> :punch.wa.us.dal.net 372 rmorel :- For assistance with trojan or virus removal please /join #NoHack ->> :punch.wa.us.dal.net 372 rmorel :- ->> :punch.wa.us.dal.net 372 rmorel :- This server does not check for ident, and does not support ident. ->> :punch.wa.us.dal.net 372 rmorel :- To help prevent abuse, this server will check your PC for open proxy ->> :punch.wa.us.dal.net 372 rmorel :- servers when you connect. If you do not want this test performed, ->> :punch.wa.us.dal.net 372 rmorel :- do not connect. ->> :punch.wa.us.dal.net 372 rmorel :- ->> :punch.wa.us.dal.net 372 rmorel :- Please feel free to visit the only official punch.* server channel, ->> :punch.wa.us.dal.net 372 rmorel :- #punch. ->> :punch.wa.us.dal.net 372 rmorel :- ->> :punch.wa.us.dal.net 372 rmorel :- Are you using SSL? If not, why not? Point your IRC client to ->> :punch.wa.us.dal.net 372 rmorel :- TCP 6697 on punch.dal.net for encrypted chatting! ->> :punch.wa.us.dal.net 372 rmorel :- ->> :punch.wa.us.dal.net 372 rmorel :- More useful: ->> :punch.wa.us.dal.net 372 rmorel :- ->> :punch.wa.us.dal.net 372 rmorel :- Some children saw Nasreddin coming from the vineyard with two ->> :punch.wa.us.dal.net 372 rmorel :- baskets full of grapes loaded on his donkey. They gathered around ->> :punch.wa.us.dal.net 372 rmorel :- him and asked him to give them a taste. Nasreddin picked up a ->> :punch.wa.us.dal.net 372 rmorel :- bunch of grapes and gave each child a grape. "You have so much, ->> :punch.wa.us.dal.net 372 rmorel :- but you gave us so little," the children whined. "There is no ->> :punch.wa.us.dal.net 372 rmorel :- difference whether you have a basketful or a small piece. They ->> :punch.wa.us.dal.net 372 rmorel :- all taste the same," Nasreddin answered, and continued on his way. ->> :punch.wa.us.dal.net 372 rmorel :- ->> :punch.wa.us.dal.net 372 rmorel :- Your hosts are: ->> :punch.wa.us.dal.net 372 rmorel :- ->> :punch.wa.us.dal.net 372 rmorel :- robt@DAL.net - Administrator ->> :punch.wa.us.dal.net 372 rmorel :- visigoth@DAL.net - IRC Operator, Services Administrator ->> :punch.wa.us.dal.net 372 rmorel :- key@DAL.net - IRC Operator ->> :punch.wa.us.dal.net 372 rmorel :- ->> :punch.wa.us.dal.net 372 rmorel :- Please enjoy your stay and thank you for being part of DALnet! ->> :punch.wa.us.dal.net 372 rmorel :- ->> :punch.wa.us.dal.net 376 rmorel :End of /MOTD command. ->> :punch.wa.us.dal.net NOTICE rmorel :*** Notice -- This server runs an open proxy monitor to prevent abuse. ->> :punch.wa.us.dal.net NOTICE rmorel :*** Notice -- If you see connections on various ports from irc.dal.net ->> :punch.wa.us.dal.net NOTICE rmorel :*** Notice -- please disregard them, as they are the monitor in action. ->> :punch.wa.us.dal.net NOTICE rmorel :*** Notice -- For more information please visit http://kline.dal.net/proxy/ ->> :rmorel MODE rmorel :+iH -<< PING punch.wa.us.dal.net ->> :punch.wa.us.dal.net PONG punch.wa.us.dal.net :rmorel ---> lag pong -<< JOIN #newchan ->> :rmorel!~rmorel@bb20-af4f-e9f8-d76-6f4e.210.62.ip JOIN :#newchan ->> :punch.wa.us.dal.net 353 rmorel = #newchan :@rmorel ->> :punch.wa.us.dal.net 366 rmorel #newchan :End of /NAMES list. -<< MODE #newchan ->> :punch.wa.us.dal.net 324 rmorel #newchan + ---> chanquery mode -<< WHO #newchan ->> :punch.wa.us.dal.net 329 rmorel #newchan 1690983697 ---> event 329 ->> :punch.wa.us.dal.net 352 rmorel #newchan ~rmorel bb20-af4f-e9f8-d76-6f4e.210.62.ip punch.wa.us.dal.net rmorel H@ :0 Romain MOREL ---> silent event who ->> :punch.wa.us.dal.net 315 rmorel #newchan :End of /WHO list. ---> chanquery who end -<< MODE #newchan b ->> :punch.wa.us.dal.net 368 rmorel #newchan :End of Channel Ban List ---> chanquery ban end -<< MODE #newchan +o johnny ->> :punch.wa.us.dal.net 441 rmorel johnny #newchan :They aren't on that channel -<< PING punch.wa.us.dal.net ->> :punch.wa.us.dal.net PONG punch.wa.us.dal.net :rmorel ---> lag pong -<< MODE #newchan -o rmorel ->> :rmorel!~rmorel@bb20-af4f-e9f8-d76-6f4e.210.62.ip MODE #newchan -o rmorel -<< MODE #newchan +i ->> :punch.wa.us.dal.net 482 rmorel #newchan :You're not channel operator -<< PING punch.wa.us.dal.net ->> :punch.wa.us.dal.net PONG punch.wa.us.dal.net :rmorel ---> lag pong -<< MODE #newchan +o gfwahjbghjkawbgbaw ->> :punch.wa.us.dal.net 482 rmorel #newchan :You're not channel operator -<< PART #newchan ->> :rmorel!~rmorel@bb20-af4f-e9f8-d76-6f4e.210.62.ip PART #newchan -<< JOIN #oui ->> :rmorel!~rmorel@bb20-af4f-e9f8-d76-6f4e.210.62.ip JOIN :#oui ->> :punch.wa.us.dal.net 353 rmorel = #oui :@rmorel ->> :punch.wa.us.dal.net 366 rmorel #oui :End of /NAMES list. -<< MODE #oui ->> :punch.wa.us.dal.net 324 rmorel #oui + ---> chanquery mode -<< WHO #oui ->> :punch.wa.us.dal.net 329 rmorel #oui 1690983851 ---> event 329 ->> :punch.wa.us.dal.net 352 rmorel #oui ~rmorel bb20-af4f-e9f8-d76-6f4e.210.62.ip punch.wa.us.dal.net rmorel H@ :0 Romain MOREL ---> silent event who ->> :punch.wa.us.dal.net 315 rmorel #oui :End of /WHO list. ---> chanquery who end -<< MODE #oui b ->> :punch.wa.us.dal.net 368 rmorel #oui :End of Channel Ban List ---> chanquery ban end -<< MODE #oui +o jongawjknbghkwabhbaw ->> :punch.wa.us.dal.net 401 rmorel jongawjknbghkwabhbaw :No such nick/channel ->> :punch.wa.us.dal.net 441 rmorel jongawjknbghkwabhbaw #oui :They aren't on that channel -<< PING punch.wa.us.dal.net ->> :punch.wa.us.dal.net PONG punch.wa.us.dal.net :rmorel ---> lag pong -<< PING punch.wa.us.dal.net ->> :punch.wa.us.dal.net PONG punch.wa.us.dal.net :rmorel ---> lag pong -<< PING punch.wa.us.dal.net ->> :punch.wa.us.dal.net PONG punch.wa.us.dal.net :rmorel ---> lag pong -<< PING punch.wa.us.dal.net ->> :punch.wa.us.dal.net PONG punch.wa.us.dal.net :rmorel ---> lag pong -<< PING punch.wa.us.dal.net ->> :punch.wa.us.dal.net PONG punch.wa.us.dal.net :rmorel ---> lag pong -<< PING punch.wa.us.dal.net ->> :punch.wa.us.dal.net PONG punch.wa.us.dal.net :rmorel ---> lag pong -<< PING punch.wa.us.dal.net ->> :punch.wa.us.dal.net PONG punch.wa.us.dal.net :rmorel ---> lag pong -<< PING punch.wa.us.dal.net ->> :punch.wa.us.dal.net PONG punch.wa.us.dal.net :rmorel ---> lag pong -<< PRIVMSG #oui :2/quit\ -<< QUIT :leaving diff --git a/Makefile b/Makefile index fbad357..97a80db 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ ifeq ($(FEXTRA),true) endif ifeq ($(FDEBUG),true) - CFLAGS += -g3 + CFLAGS += -gdwarf-3 VFLAGS += -D DEBUG_MODE endif diff --git a/src/command/JOIN.cpp b/src/command/JOIN.cpp index b260ce1..cb8e4d8 100644 --- a/src/command/JOIN.cpp +++ b/src/command/JOIN.cpp @@ -21,17 +21,20 @@ void Command::join_channel(const std::string& channel_name, const std::string& Channel* channel = _server->get_channel(channel_name); if (channel == NULL) { _server->create_channel(_client, channel_name); - } else if (!channel->is_in_channel(_client)){ - if (channel->is_in_channel(_client)) return; - if (channel->is_invited(_client)) - channel->add_user(_client); - else if (channel->is_invite_only()) - reply(ERR_INVITEONLYCHAN(channel_name), 473); - else if (channel->is_full()) - reply(ERR_CHANNELISFULL(channel_name), 471); - else if (channel->is_password_restricted() && !channel->validate_password(password)) - reply(ERR_PASSWDMISMATCH(), 464); - else + } else if (!channel->is_in_channel(_client)) { + if (channel->is_in_channel(_client)) + return; + if (!channel->is_invited(_client)) { + if (channel->is_invite_only()) + reply(ERR_INVITEONLYCHAN(channel_name), 473); + else if (channel->is_full()) + reply(ERR_CHANNELISFULL(channel_name), 471); + else if (channel->is_password_restricted() + && !channel->validate_password(password)) + reply(ERR_BADCHANNELKEY(channel_name), 475); + else + channel->add_user(_client); + } else channel->add_user(_client); } } diff --git a/src/command/MODE.cpp b/src/command/MODE.cpp index 79423c0..e8f5e18 100644 --- a/src/command/MODE.cpp +++ b/src/command/MODE.cpp @@ -53,7 +53,12 @@ int Command::execute_MODE() if (_message.get_parameters().size() == 1) return reply(RPL_CHANNELMODEIS(target->get_mode_list()), 324); ModeParser mode(_message.get_parameters()[1], target, _server, _client); - mode.set_arg(_message.get_parameters().begin()); + _message.print_message(); + for (std::vector::const_iterator it = _message.get_parameters().begin(); + it != _message.get_parameters().end(); it++) + std::cout << "[" << *it << "], "; + std::cout << std::endl; + mode.set_arg(_message.get_parameters().begin() + 2); mode.set_end_of_arg(_message.get_parameters().end()); return mode.execute(); } diff --git a/src/command/ModeParser.cpp b/src/command/ModeParser.cpp index 2d042f8..cf55ef8 100644 --- a/src/command/ModeParser.cpp +++ b/src/command/ModeParser.cpp @@ -58,7 +58,6 @@ static bool is_valid_modestring(const std::string& modestring) void ModeParser::set_arg(std::vector::const_iterator arg) { _arg = arg; - _arg += 2; } void ModeParser::set_end_of_arg(std::vector::const_iterator end) @@ -95,7 +94,9 @@ void ModeParser::client_limit_mode() { if (!_l_is_set) { - if (_operand && !no_more_args() && std::atoi((*_arg).c_str())) { + if (no_more_args()) + return ; + else if (_operand && std::atoi((*_arg).c_str())) { _target->set_max_users(std::atoi((*_arg).c_str())); add_to_modestring_reply("+l"); add_to_args_reply(*_arg); @@ -104,8 +105,9 @@ void ModeParser::client_limit_mode() _target->set_max_users(0); add_to_modestring_reply("-l"); } + DEBUG("args++"); + _arg++; } - _arg++; } void ModeParser::key_channel_mode() @@ -113,7 +115,9 @@ void ModeParser::key_channel_mode() if (!_k_is_set) // ie no password set yet { _k_is_set = true; - if (_operand && !no_more_args()) { + if (no_more_args()) + return; + if (_operand) { if (is_valid_password(*_arg)) { _target->set_password_activation(true); _target->set_password(*_arg); @@ -127,14 +131,17 @@ void ModeParser::key_channel_mode() add_to_modestring_reply("-k"); _target->set_password_activation(false); } + DEBUG("args++"); + _arg++; } - _arg++; } void ModeParser::oper_user_mode() { - if (!_o_is_set && !no_more_args()) { + if (!_o_is_set) { _o_is_set = true; + if (no_more_args()) + return; Client* client = _server->get_client(*_arg); if (!client) reply(ERR_USERNOTINCHANNEL(*_arg, get_target_name()), 441); @@ -150,6 +157,8 @@ void ModeParser::oper_user_mode() add_to_modestring_reply("-o"); add_to_args_reply(*_arg); } + DEBUG("args++"); + _arg++; } } diff --git a/src/management/Channel.cpp b/src/management/Channel.cpp index 6c2aca3..734a60b 100644 --- a/src/management/Channel.cpp +++ b/src/management/Channel.cpp @@ -46,13 +46,13 @@ bool Channel::is_topic_restricted() const { return _topic_restriction; } bool Channel::is_password_restricted() const { return _password_restriction; } -void Channel::set_invite_only(bool invite_only) { _invite_only = invite_only; } +void Channel::set_invite_only(bool invite_only) { INFO(_name << " invite_only = " << invite_only); _invite_only = invite_only; } -void Channel::set_topic_restriction(bool topic_restriction) { _topic_restriction = topic_restriction; } +void Channel::set_topic_restriction(bool topic_restriction) { INFO(_name << " topic_restriction = " << topic_restriction); _topic_restriction = topic_restriction; } -void Channel::set_password_activation(bool password_activation) { _password_restriction = password_activation; } +void Channel::set_password_activation(bool password_activation) { INFO(_name << " password = " << password_activation); _password_restriction = password_activation; } -void Channel::set_password(const std::string& password) { _password = password; } +void Channel::set_password(const std::string& password) { INFO("password = "<< password); _password = password; } void Channel::set_topic(const Client& user, const std::string& topic) { diff --git a/tests/.command.cpp.swp b/tests/.command.cpp.swp new file mode 100644 index 0000000..d179a9b Binary files /dev/null and b/tests/.command.cpp.swp differ diff --git a/tests/CmdTest.cpp b/tests/CmdTest.cpp index 15668be..582c8e5 100644 --- a/tests/CmdTest.cpp +++ b/tests/CmdTest.cpp @@ -7,9 +7,7 @@ static void* start_server_loop(void* ptr) { Server* server = (Server*)ptr; while (server->running()) { - DEBUG("OUI"); server->loop(); - DEBUG("NON"); } DEBUG("OVER"); return NULL; diff --git a/tests/command.cpp b/tests/command.cpp index 3280606..dcbaa46 100644 --- a/tests/command.cpp +++ b/tests/command.cpp @@ -381,6 +381,7 @@ void mode_key() s.send(1, "NICK apigeon"); s.send(1, "USER arthur 0 * :Arthur Pigeon"); s.send(1, "JOIN #linux"); + usleep(50000); s.receive(1); s.send(1, "MODE #linux +k 123"); assert_str(s.receive(1), ":apigeon!arthur@127.0.0.1 MODE #linux +k 123"); @@ -388,11 +389,12 @@ void mode_key() s.send(2, "PASS password"); s.send(2, "NICK rmorel"); s.send(2, "USER romain 0 * :Romain Morel"); + usleep(50000); s.receive(2); s.send(2, "JOIN #linux"); - assert_str(s.receive(2), "464 rmorel :Password incorrect"); + assert_str(s.receive(2), "475 rmorel #linux :Cannot join channel (+k)"); s.send(2, "JOIN #linux 456"); - assert_str(s.receive(2), "464 rmorel :Password incorrect"); + assert_str(s.receive(2), "475 rmorel #linux :Cannot join channel (+k)"); s.send(2, "JOIN #linux 123"); assert_str(s.receive(2), ":rmorel!romain@127.0.0.1 JOIN :#linux"); usleep(50000); @@ -406,6 +408,7 @@ void mode_operator() s.send(1, "NICK apigeon"); s.send(1, "USER arthur 0 * :Arthur Pigeon"); s.send(1, "JOIN #linux"); + usleep(50000); s.receive(1); s.send(1, "MODE #linux +o johny"); assert_str(s.receive(1), "441 apigeon johny #linux :They aren't on that channel"); @@ -413,8 +416,10 @@ void mode_operator() s.send(2, "PASS password"); s.send(2, "NICK rmorel"); s.send(2, "USER romain 0 * :Romain Morel"); + usleep(50000); s.receive(2); s.send(2, "JOIN #linux"); + usleep(50000); s.receive(1); usleep(50000); s.receive(2);