Fixed double messaging bug with DMs.

This commit is contained in:
Xnoe 2021-06-20 21:54:48 +01:00
parent 643d917ac1
commit 82592a13fe
Signed by: xnoe
GPG Key ID: 45AC398F44F0DAFE
6 changed files with 32 additions and 20 deletions

View File

@ -9,8 +9,8 @@ Channel::~Channel() {
remove_addressable_name(channel_name); remove_addressable_name(channel_name);
} }
void Channel::send_direct(std::vector<IRCCommand> messages) { void Channel::send_direct(std::vector<IRCCommand> messages, std::string exclude) {
send_relay(messages); send_relay(messages, exclude);
} }
std::string Channel::get_topic() { std::string Channel::get_topic() {

View File

@ -14,7 +14,7 @@ public:
Channel(IRCServer* server, std::string channel_name); Channel(IRCServer* server, std::string channel_name);
~Channel(); ~Channel();
void send_direct(std::vector<IRCCommand> messages); void send_direct(std::vector<IRCCommand> messages, std::string exclude="");
std::string get_topic(); std::string get_topic();
bool has_topic(); bool has_topic();

View File

@ -61,10 +61,11 @@ std::string Nameable::associates_as_string() {
return associate_list; return associate_list;
} }
void Nameable::send_direct(std::vector<IRCCommand> messages) {} void Nameable::send_direct(std::vector<IRCCommand> messages, std::string exclude) {}
void Nameable::send_relay(std::vector<IRCCommand> messages) { void Nameable::send_relay(std::vector<IRCCommand> messages, std::string exclude) {
for (Nameable* associate : this->associates) { for (Nameable* associate : this->associates) {
associate->send_direct(messages); if (associate->get_addressable_name() != exclude)
associate->send_direct(messages);
} }
} }

View File

@ -37,8 +37,8 @@ public:
void remove_associate(Nameable* associate); void remove_associate(Nameable* associate);
std::string associates_as_string(); std::string associates_as_string();
virtual void send_direct(std::vector<IRCCommand> messages); virtual void send_direct(std::vector<IRCCommand> messages, std::string exclude="");
void send_relay(std::vector<IRCCommand> messages); void send_relay(std::vector<IRCCommand> messages, std::string exclude="");
virtual NameableType what_are_you(); virtual NameableType what_are_you();
}; };

View File

@ -52,13 +52,17 @@ std::vector<IRCCommand> User::user_cmd(IRCCommand cmd) {
this->state = Registered; this->state = Registered;
} }
return { std::vector<IRCCommand> to_return = {
IRCCommand(server->get_hostname(), "001", this->get_nick(), "Welcome to the Polyglottal Network, " + this->get_nick()), 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(), "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(), "003", this->get_nick(), "This server was never created."),
IRCCommand(server->get_hostname(), "004", this->get_nick(), server->get_hostname(), "0", "ABCabc", "ABCabc"), IRCCommand(server->get_hostname(), "004", this->get_nick(), server->get_hostname(), "0", "ABCabc", "ABCabc")
motd_cmd(IRCCommand())[0]
}; };
auto motd = motd_cmd(IRCCommand());
to_return.insert(to_return.end(), motd.begin(), motd.end());
return to_return;
} }
std::vector<IRCCommand> User::ping_cmd(IRCCommand cmd) { std::vector<IRCCommand> User::ping_cmd(IRCCommand cmd) {
@ -121,10 +125,11 @@ std::vector<IRCCommand> User::privmsg_cmd(IRCCommand cmd) {
if (server->has_addressable_name(named_target)) { if (server->has_addressable_name(named_target)) {
Nameable* target = server->resolve_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()) if (associate->get_addressable_name() != this->get_nick())
associate->send_direct({IRCCommand(this->get_nick(), "PRIVMSG", named_target, cmd.get_parameter(1))}); 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 {}; return {};
@ -164,15 +169,18 @@ std::vector<IRCCommand> User::whois_cmd(IRCCommand cmd) {
} }
std::vector<IRCCommand> User::topic_cmd(IRCCommand cmd) { std::vector<IRCCommand> 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 {}; 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) if (target->what_are_you() != NT_Channel)
return {}; return {};
((Channel*)target)->set_topic(cmd.get_parameter(1)); std::string topic = cmd.get_parameter(1);
return {};
((Channel*)target)->set_topic(topic);;
return {IRCCommand(server->get_hostname(), this->get_nick(), named_channel, topic)};
} }
std::vector<IRCCommand> User::names_cmd(IRCCommand cmd) { std::vector<IRCCommand> User::names_cmd(IRCCommand cmd) {
@ -183,7 +191,10 @@ std::vector<IRCCommand> User::names_cmd(IRCCommand cmd) {
if (resolved->what_are_you() != NT_Channel) if (resolved->what_are_you() != NT_Channel)
return {}; return {};
Channel* chan = (Channel*)resolved; 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<IRCCommand> User::motd_cmd(IRCCommand cmd) { std::vector<IRCCommand> User::motd_cmd(IRCCommand cmd) {
@ -257,7 +268,7 @@ std::string User::get_realname(){
return realname; return realname;
} }
void User::send_direct(std::vector<IRCCommand> messages) { void User::send_direct(std::vector<IRCCommand> messages, std::string exclude) {
for (IRCCommand m : messages) { for (IRCCommand m : messages) {
std::cout << m.to_string() << "\n"; std::cout << m.to_string() << "\n";
this->connection->send(m.to_string()); this->connection->send(m.to_string());

2
user.h
View File

@ -67,7 +67,7 @@ public:
std::string get_realname(); std::string get_realname();
void send_direct(std::vector<IRCCommand> messages); void send_direct(std::vector<IRCCommand> messages, std::string exclude="");
NameableType what_are_you() override; NameableType what_are_you() override;