diff --git a/channel.cpp b/channel.cpp index 6a9a5f4..8810ede 100644 --- a/channel.cpp +++ b/channel.cpp @@ -9,8 +9,8 @@ Channel::~Channel() { remove_addressable_name(channel_name); } -void Channel::send_direct(std::vector messages) { - send_relay(messages); +void Channel::send_direct(std::vector messages, std::string exclude) { + send_relay(messages, exclude); } std::string Channel::get_topic() { diff --git a/channel.h b/channel.h index 3a3d3e0..0eca9fd 100644 --- a/channel.h +++ b/channel.h @@ -14,7 +14,7 @@ public: Channel(IRCServer* server, std::string channel_name); ~Channel(); - void send_direct(std::vector messages); + void send_direct(std::vector messages, std::string exclude=""); std::string get_topic(); bool has_topic(); diff --git a/nameable.cpp b/nameable.cpp index 5930ce2..894eaca 100644 --- a/nameable.cpp +++ b/nameable.cpp @@ -61,10 +61,11 @@ std::string Nameable::associates_as_string() { return associate_list; } -void Nameable::send_direct(std::vector messages) {} -void Nameable::send_relay(std::vector messages) { +void Nameable::send_direct(std::vector messages, std::string exclude) {} +void Nameable::send_relay(std::vector messages, std::string exclude) { for (Nameable* associate : this->associates) { - associate->send_direct(messages); + if (associate->get_addressable_name() != exclude) + associate->send_direct(messages); } } diff --git a/nameable.h b/nameable.h index 3c7107e..01a166e 100644 --- a/nameable.h +++ b/nameable.h @@ -37,8 +37,8 @@ public: void remove_associate(Nameable* associate); std::string associates_as_string(); - virtual void send_direct(std::vector messages); - void send_relay(std::vector messages); + virtual void send_direct(std::vector messages, std::string exclude=""); + void send_relay(std::vector messages, std::string exclude=""); virtual NameableType what_are_you(); }; diff --git a/user.cpp b/user.cpp index b5879ce..73767bf 100644 --- a/user.cpp +++ b/user.cpp @@ -52,13 +52,17 @@ std::vector User::user_cmd(IRCCommand cmd) { this->state = Registered; } - return { + std::vector to_return = { IRCCommand(server->get_hostname(), "001", this->get_nick(), "Welcome to the Polyglottal Network, " + this->get_nick()), IRCCommand(server->get_hostname(), "002", this->get_nick(), "Your host is " + server->get_hostname()), IRCCommand(server->get_hostname(), "003", this->get_nick(), "This server was never created."), - IRCCommand(server->get_hostname(), "004", this->get_nick(), server->get_hostname(), "0", "ABCabc", "ABCabc"), - motd_cmd(IRCCommand())[0] + IRCCommand(server->get_hostname(), "004", this->get_nick(), server->get_hostname(), "0", "ABCabc", "ABCabc") }; + + auto motd = motd_cmd(IRCCommand()); + + to_return.insert(to_return.end(), motd.begin(), motd.end()); + return to_return; } std::vector User::ping_cmd(IRCCommand cmd) { @@ -121,10 +125,11 @@ std::vector User::privmsg_cmd(IRCCommand cmd) { if (server->has_addressable_name(named_target)) { Nameable* target = server->resolve_addressable_name(named_target); - for (Nameable* associate : target->get_associates()) { + /*for (Nameable* associate : target->get_associates()) { if (associate->get_addressable_name() != this->get_nick()) associate->send_direct({IRCCommand(this->get_nick(), "PRIVMSG", named_target, cmd.get_parameter(1))}); - } + }*/ + target->send_direct({IRCCommand(this->get_nick(), "PRIVMSG", named_target, cmd.get_parameter(1))}, this->get_nick()); } return {}; @@ -164,15 +169,18 @@ std::vector User::whois_cmd(IRCCommand cmd) { } std::vector User::topic_cmd(IRCCommand cmd) { - if (!server->has_addressable_name(cmd.get_parameter(0))) + std::string named_channel = cmd.get_parameter(0); + if (!server->has_addressable_name(named_channel)) return {}; - Nameable* target = server->resolve_addressable_name(cmd.get_parameter(0)); + Nameable* target = server->resolve_addressable_name(named_channel); if (target->what_are_you() != NT_Channel) return {}; - ((Channel*)target)->set_topic(cmd.get_parameter(1)); - return {}; + std::string topic = cmd.get_parameter(1); + + ((Channel*)target)->set_topic(topic);; + return {IRCCommand(server->get_hostname(), this->get_nick(), named_channel, topic)}; } std::vector User::names_cmd(IRCCommand cmd) { @@ -183,7 +191,10 @@ std::vector User::names_cmd(IRCCommand cmd) { if (resolved->what_are_you() != NT_Channel) return {}; Channel* chan = (Channel*)resolved; - return {IRCCommand(server->get_hostname(), "353", this->get_nick(), named_channel, chan->associates_as_string())}; + return { + IRCCommand(server->get_hostname(), "353", this->get_nick(), named_channel, chan->associates_as_string()), + IRCCommand(server->get_hostname(), "366", this->get_nick(), named_channel, "End of NAMES.") + }; } std::vector User::motd_cmd(IRCCommand cmd) { @@ -257,7 +268,7 @@ std::string User::get_realname(){ return realname; } -void User::send_direct(std::vector messages) { +void User::send_direct(std::vector messages, std::string exclude) { for (IRCCommand m : messages) { std::cout << m.to_string() << "\n"; this->connection->send(m.to_string()); diff --git a/user.h b/user.h index 5128fe6..1f64bae 100644 --- a/user.h +++ b/user.h @@ -67,7 +67,7 @@ public: std::string get_realname(); - void send_direct(std::vector messages); + void send_direct(std::vector messages, std::string exclude=""); NameableType what_are_you() override;