Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 0 additions & 160 deletions DALnet_logs

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ifeq ($(FEXTRA),true)
endif

ifeq ($(FDEBUG),true)
CFLAGS += -g3
CFLAGS += -gdwarf-3
VFLAGS += -D DEBUG_MODE
endif

Expand Down
25 changes: 14 additions & 11 deletions src/command/JOIN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/command/MODE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>::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();
}
21 changes: 15 additions & 6 deletions src/command/ModeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ static bool is_valid_modestring(const std::string& modestring)
void ModeParser::set_arg(std::vector<std::string>::const_iterator arg)
{
_arg = arg;
_arg += 2;
}

void ModeParser::set_end_of_arg(std::vector<std::string>::const_iterator end)
Expand Down Expand Up @@ -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);
Expand All @@ -104,16 +105,19 @@ void ModeParser::client_limit_mode()
_target->set_max_users(0);
add_to_modestring_reply("-l");
}
DEBUG("args++");
_arg++;
}
_arg++;
}

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);
Expand All @@ -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);
Expand All @@ -150,6 +157,8 @@ void ModeParser::oper_user_mode()
add_to_modestring_reply("-o");
add_to_args_reply(*_arg);
}
DEBUG("args++");
_arg++;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/management/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Binary file added tests/.command.cpp.swp
Binary file not shown.
2 changes: 0 additions & 2 deletions tests/CmdTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions tests/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,18 +381,20 @@ 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");
s.create_client();
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);
Expand All @@ -406,15 +408,18 @@ 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");
s.create_client();
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);
Expand Down