Autojoin rooms with password
This commit is contained in:
parent
b851fab140
commit
1c5504d7c6
4 changed files with 35 additions and 20 deletions
|
@ -105,7 +105,7 @@ void IRCNetworkPlugin::handleJoinRoomRequest(const std::string &user, const std:
|
|||
}
|
||||
}
|
||||
std::cout << "JOINING " << r << "\n";
|
||||
m_sessions[u]->addAutoJoinChannel(r);
|
||||
m_sessions[u]->addAutoJoinChannel(r, password);
|
||||
m_sessions[u]->sendCommand(IrcCommand::createJoin(FROM_UTF8(r), FROM_UTF8(password)));
|
||||
m_sessions[u]->rooms += 1;
|
||||
// update nickname, because we have nickname per session, no nickname per room.
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "session.h"
|
||||
#include <QtCore>
|
||||
#include <iostream>
|
||||
#include "Swiften/Elements/StatusShow.h"
|
||||
#include <IrcCommand>
|
||||
#include <IrcMessage>
|
||||
|
||||
|
@ -40,8 +39,8 @@ void MyIrcSession::on_connected() {
|
|||
np->handleConnected(user);
|
||||
}
|
||||
|
||||
for(std::list<std::string>::const_iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
|
||||
sendCommand(IrcCommand::createJoin(FROM_UTF8(*it)));
|
||||
for(AutoJoinMap::iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
|
||||
sendCommand(IrcCommand::createJoin(FROM_UTF8(it->second->getChannel()), FROM_UTF8(it->second->getPassword())));
|
||||
}
|
||||
|
||||
if (getIdentify().find(" ") != std::string::npos) {
|
||||
|
@ -88,23 +87,23 @@ void MyIrcSession::on_parted(IrcMessage *message) {
|
|||
|
||||
void MyIrcSession::on_quit(IrcMessage *message) {
|
||||
IrcQuitMessage *m = (IrcQuitMessage *) message;
|
||||
for(std::list<std::string>::const_iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
|
||||
for(AutoJoinMap::iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
|
||||
bool flags = 0;
|
||||
std::string nickname = TO_UTF8(m->sender().name());
|
||||
flags = correctNickname(nickname);
|
||||
LOG4CXX_INFO(logger, user << ": " << nickname << " quit " << (*it) + suffix);
|
||||
np->handleParticipantChanged(user, nickname, (*it) + suffix,(int) flags, pbnetwork::STATUS_NONE, TO_UTF8(m->reason()));
|
||||
LOG4CXX_INFO(logger, user << ": " << nickname << " quit " << it->second->getChannel() + suffix);
|
||||
np->handleParticipantChanged(user, nickname, it->second->getChannel() + suffix,(int) flags, pbnetwork::STATUS_NONE, TO_UTF8(m->reason()));
|
||||
}
|
||||
}
|
||||
|
||||
void MyIrcSession::on_nickChanged(IrcMessage *message) {
|
||||
IrcNickMessage *m = (IrcNickMessage *) message;
|
||||
|
||||
for(std::list<std::string>::const_iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
|
||||
for(AutoJoinMap::iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
|
||||
std::string nickname = TO_UTF8(m->sender().name());
|
||||
bool flags = m_modes[(*it) + nickname];
|
||||
bool flags = m_modes[it->second->getChannel() + nickname];
|
||||
LOG4CXX_INFO(logger, user << ": " << nickname << " changed nickname to " << TO_UTF8(m->nick()));
|
||||
np->handleParticipantChanged(user, nickname, (*it) + suffix,(int) flags, pbnetwork::STATUS_ONLINE, "", TO_UTF8(m->nick()));
|
||||
np->handleParticipantChanged(user, nickname, it->second->getChannel() + suffix,(int) flags, pbnetwork::STATUS_ONLINE, "", TO_UTF8(m->nick()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,15 +116,15 @@ void MyIrcSession::on_modeChanged(IrcMessage *message) {
|
|||
if (nickname.empty())
|
||||
return;
|
||||
LOG4CXX_INFO(logger, user << ": " << nickname << " changed mode to " << mode);
|
||||
for(std::list<std::string>::const_iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
|
||||
for(AutoJoinMap::iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
|
||||
if (mode == "+o") {
|
||||
m_modes[(*it) + nickname] = 1;
|
||||
m_modes[it->second->getChannel() + nickname] = 1;
|
||||
}
|
||||
else {
|
||||
m_modes[(*it) + nickname] = 0;
|
||||
m_modes[it->second->getChannel() + nickname] = 0;
|
||||
}
|
||||
bool flags = m_modes[(*it) + nickname];
|
||||
np->handleParticipantChanged(user, nickname, (*it) + suffix,(int) flags, pbnetwork::STATUS_ONLINE, "");
|
||||
bool flags = m_modes[it->second->getChannel() + nickname];
|
||||
np->handleParticipantChanged(user, nickname, it->second->getChannel() + suffix,(int) flags, pbnetwork::STATUS_ONLINE, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
#include <IrcSession>
|
||||
#include <transport/networkplugin.h>
|
||||
#include "Swiften/Swiften.h"
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
|
||||
using namespace Transport;
|
||||
|
||||
|
@ -21,17 +23,31 @@ class MyIrcSession : public IrcSession
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
class AutoJoinChannel {
|
||||
public:
|
||||
AutoJoinChannel(const std::string &channel = "", const std::string &password = "") : m_channel(channel), m_password(password) {}
|
||||
virtual ~AutoJoinChannel() {}
|
||||
|
||||
const std::string &getChannel() { return m_channel; }
|
||||
const std::string &getPassword() { return m_password; }
|
||||
private:
|
||||
std::string m_channel;
|
||||
std::string m_password;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, boost::shared_ptr<AutoJoinChannel> > AutoJoinMap;
|
||||
|
||||
MyIrcSession(const std::string &user, NetworkPlugin *np, const std::string &suffix = "", QObject* parent = 0);
|
||||
std::map<std::string, bool> m_modes;
|
||||
std::string suffix;
|
||||
int rooms;
|
||||
|
||||
void addAutoJoinChannel(const std::string &channel) {
|
||||
m_autoJoin.push_back(channel);
|
||||
void addAutoJoinChannel(const std::string &channel, const std::string &password) {
|
||||
m_autoJoin[channel] = boost::make_shared<AutoJoinChannel>(channel, password);
|
||||
}
|
||||
|
||||
void removeAutoJoinChannel(const std::string &channel) {
|
||||
m_autoJoin.remove(channel);
|
||||
m_autoJoin.erase(channel);
|
||||
}
|
||||
|
||||
void setIdentify(const std::string &identify) {
|
||||
|
@ -63,7 +79,7 @@ protected:
|
|||
NetworkPlugin *np;
|
||||
std::string user;
|
||||
std::string m_identify;
|
||||
std::list<std::string> m_autoJoin;
|
||||
AutoJoinMap m_autoJoin;
|
||||
std::string m_topicData;
|
||||
bool m_connected;
|
||||
};
|
||||
|
|
|
@ -114,7 +114,7 @@ void SingleIRCNetworkPlugin::handleJoinRoomRequest(const std::string &user, cons
|
|||
}
|
||||
|
||||
LOG4CXX_INFO(logger, user << ": Joining " << room);
|
||||
m_sessions[user]->addAutoJoinChannel(room);
|
||||
m_sessions[user]->addAutoJoinChannel(room, password);
|
||||
m_sessions[user]->sendCommand(IrcCommand::createJoin(FROM_UTF8(room), FROM_UTF8(password)));
|
||||
m_sessions[user]->rooms += 1;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue