Add support for password-protected IRC rooms.
This commit is contained in:
@@ -108,7 +108,7 @@ IrcClient* Bridge::get_irc_client(const std::string& hostname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Bridge::join_irc_channel(const Iid& iid, const std::string& username)
|
bool Bridge::join_irc_channel(const Iid& iid, const std::string& username, const std::string& password)
|
||||||
{
|
{
|
||||||
IrcClient* irc = this->get_irc_client(iid.get_server(), username);
|
IrcClient* irc = this->get_irc_client(iid.get_server(), username);
|
||||||
if (iid.get_local().empty())
|
if (iid.get_local().empty())
|
||||||
@@ -135,7 +135,7 @@ bool Bridge::join_irc_channel(const Iid& iid, const std::string& username)
|
|||||||
}
|
}
|
||||||
if (irc->is_channel_joined(iid.get_local()) == false)
|
if (irc->is_channel_joined(iid.get_local()) == false)
|
||||||
{
|
{
|
||||||
irc->send_join_command(iid.get_local());
|
irc->send_join_command(iid.get_local(), password);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public:
|
|||||||
* Try to join an irc_channel, does nothing and return true if the channel
|
* Try to join an irc_channel, does nothing and return true if the channel
|
||||||
* was already joined.
|
* was already joined.
|
||||||
*/
|
*/
|
||||||
bool join_irc_channel(const Iid& iid, const std::string& username);
|
bool join_irc_channel(const Iid& iid, const std::string& username, const std::string& password = "");
|
||||||
void send_channel_message(const Iid& iid, const std::string& body);
|
void send_channel_message(const Iid& iid, const std::string& body);
|
||||||
void send_private_message(const Iid& iid, const std::string& body, const std::string& type="PRIVMSG");
|
void send_private_message(const Iid& iid, const std::string& body, const std::string& type="PRIVMSG");
|
||||||
void leave_irc_channel(Iid&& iid, std::string&& status_message);
|
void leave_irc_channel(Iid&& iid, std::string&& status_message);
|
||||||
|
|||||||
@@ -206,12 +206,12 @@ void IrcClient::send_quit_command(const std::string& reason)
|
|||||||
this->send_message(IrcMessage("QUIT", {reason}));
|
this->send_message(IrcMessage("QUIT", {reason}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void IrcClient::send_join_command(const std::string& chan_name)
|
void IrcClient::send_join_command(const std::string& chan_name, const std::string& password)
|
||||||
{
|
{
|
||||||
if (this->welcomed == false)
|
if (this->welcomed == false)
|
||||||
this->channels_to_join.push_back(chan_name);
|
this->channels_to_join.push_back(chan_name);
|
||||||
else
|
else
|
||||||
this->send_message(IrcMessage("JOIN", {chan_name}));
|
this->send_message(IrcMessage("JOIN", {chan_name, password}));
|
||||||
this->start();
|
this->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Send the JOIN irc command.
|
* Send the JOIN irc command.
|
||||||
*/
|
*/
|
||||||
void send_join_command(const std::string& chan_name);
|
void send_join_command(const std::string& chan_name, const std::string& password = "");
|
||||||
/**
|
/**
|
||||||
* Send a PRIVMSG command for a channel
|
* Send a PRIVMSG command for a channel
|
||||||
* Return true if the message was actually sent
|
* Return true if the message was actually sent
|
||||||
|
|||||||
@@ -338,7 +338,9 @@ void XmppComponent::handle_presence(const Stanza& stanza)
|
|||||||
const std::string own_nick = bridge->get_own_nick(iid);
|
const std::string own_nick = bridge->get_own_nick(iid);
|
||||||
if (!own_nick.empty() && own_nick != to.resource)
|
if (!own_nick.empty() && own_nick != to.resource)
|
||||||
bridge->send_irc_nick_change(iid, to.resource);
|
bridge->send_irc_nick_change(iid, to.resource);
|
||||||
bridge->join_irc_channel(iid, to.resource);
|
XmlNode* x = stanza.get_child("x", MUC_NS);
|
||||||
|
XmlNode* password = x? x->get_child("password", MUC_NS): NULL;
|
||||||
|
bridge->join_irc_channel(iid, to.resource, password? password->get_inner(): "");
|
||||||
}
|
}
|
||||||
else if (type == "unavailable")
|
else if (type == "unavailable")
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user