access to ircclient trough config::network

ver3
acetone 2023-03-05 08:41:55 +03:00
parent 7143458781
commit ea575a9de9
4 changed files with 35 additions and 31 deletions

View File

@ -20,6 +20,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "currenttime.h" #include "currenttime.h"
#include "adminircpanel.h" #include "adminircpanel.h"
#include "ircnetworkclient.h"
#include "config.h" #include "config.h"
#include <QMutex> #include <QMutex>
@ -72,10 +73,9 @@ bool AdminIRCPanel::parse(const QString& networkName, const QString &input, QStr
channel.remove(rgx_channel); channel.remove(rgx_channel);
auto configs = Config::networksAccess(); auto configs = Config::networksAccess();
QListIterator<Config::Network> networksIter(configs); for (auto iter = configs.begin(); iter != configs.end(); ++iter)
while(networksIter.hasNext())
{ {
auto network = networksIter.next(); auto& network = *iter;
if (network.networkName != networkName) continue; if (network.networkName != networkName) continue;
if (add and network.channels.contains(channel)) if (add and network.channels.contains(channel))
@ -86,8 +86,7 @@ bool AdminIRCPanel::parse(const QString& networkName, const QString &input, QStr
else if (add) else if (add)
{ {
network.channels.push_back(channel); network.channels.push_back(channel);
// TODO: update ircnetworkclient instance answer.push_back("Success. Channel " + channel + " added.");
answer.push_back("Success. Channel " + channel + " added. ");
return true; return true;
} }
@ -99,7 +98,6 @@ bool AdminIRCPanel::parse(const QString& networkName, const QString &input, QStr
else if (not add) else if (not add)
{ {
network.channels.removeOne(channel); network.channels.removeOne(channel);
// TODO: update ircnetworkclient instance
answer.push_back("Success. Channel " + channel + " removed."); answer.push_back("Success. Channel " + channel + " removed.");
return true; return true;
} }
@ -109,18 +107,21 @@ bool AdminIRCPanel::parse(const QString& networkName, const QString &input, QStr
else if (input.contains(rgx_reloadChannels)) else if (input.contains(rgx_reloadChannels))
{ {
// TODO auto configs = Config::networksAccess();
answer.push_back("NOT IMPLEMENTED"); for (auto iter = configs.begin(); iter != configs.end(); ++iter)
{
iter->instance->reloadChannelList();
}
answer.push_back("Success. Reloaded.");
} }
else if (input.contains(rgx_voiceGate)) else if (input.contains(rgx_voiceGate))
{ {
bool enable = input.endsWith("enable", Qt::CaseInsensitive); bool enable = input.endsWith("enable", Qt::CaseInsensitive);
auto configs = Config::networksAccess(); auto configs = Config::networksAccess();
QListIterator<Config::Network> networksIter(configs); for (auto iter = configs.begin(); iter != configs.end(); ++iter)
while(networksIter.hasNext())
{ {
auto network = networksIter.next(); auto& network = *iter;
if (network.networkName != networkName) continue; if (network.networkName != networkName) continue;
if (network.voiceGate == enable) if (network.voiceGate == enable)

View File

@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
class IRCNetworkClient;
class QJsonObject; class QJsonObject;
class Config class Config
@ -51,6 +52,8 @@ public:
QStringList channels; QStringList channels;
bool autoReconnect; bool autoReconnect;
bool voiceGate; bool voiceGate;
IRCNetworkClient* instance = nullptr;
}; };
static void setConfigurationFilePath(const QString& path) { m_configurationFilePath = path; } static void setConfigurationFilePath(const QString& path) { m_configurationFilePath = path; }

View File

@ -26,8 +26,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <QStringList> #include <QStringList>
#include <QDebug> #include <QDebug>
#define LOG_WARN qWarning().noquote() << "[" + m_config.networkName + "]" #define LOG_WARN qWarning().noquote() << "[" + m_config->networkName + "]"
#define LOG_INFO qInfo().noquote() << "[" + m_config.networkName + "]" #define LOG_INFO qInfo().noquote() << "[" + m_config->networkName + "]"
IRCNetworkClient::IRCNetworkClient(QObject *parent) : QObject(parent) {} IRCNetworkClient::IRCNetworkClient(QObject *parent) : QObject(parent) {}
@ -41,7 +41,7 @@ void IRCNetworkClient::reloadChannelList()
while (connectedChannelListIterator.hasNext()) while (connectedChannelListIterator.hasNext())
{ {
auto connectedChan = connectedChannelListIterator.next(); auto connectedChan = connectedChannelListIterator.next();
if (not m_config.channels.contains(connectedChan->GetName())) if (not m_config->channels.contains(connectedChan->GetName()))
{ {
channelsToPart.push_back(connectedChan->GetName()); channelsToPart.push_back(connectedChan->GetName());
} }
@ -58,7 +58,7 @@ void IRCNetworkClient::reloadChannelList()
// JOIN // JOIN
QStringList channelsToJoin; QStringList channelsToJoin;
QStringListIterator newChannelListIter (m_config.channels); QStringListIterator newChannelListIter (m_config->channels);
while (newChannelListIter.hasNext()) while (newChannelListIter.hasNext())
{ {
auto newChannel = newChannelListIter.next(); auto newChannel = newChannelListIter.next();
@ -79,17 +79,17 @@ void IRCNetworkClient::reloadChannelList()
void IRCNetworkClient::start() void IRCNetworkClient::start()
{ {
libirc::ServerAddress address(m_config.host); libirc::ServerAddress address(m_config->host);
address.SetPort(m_config.port); address.SetPort(m_config->port);
address.SetSSL(m_config.ssl); address.SetSSL(m_config->ssl);
address.SetNick(m_config.nickname); address.SetNick(m_config->nickname);
address.SetPassword(m_config.password); address.SetPassword(m_config->password);
address.SetIdent(m_config.ident); address.SetIdent(m_config->ident);
address.SetRealname(m_config.realName); address.SetRealname(m_config->realName);
address.SetSuffix(m_config.channels.join(',')); address.SetSuffix(m_config->channels.join(','));
m_network = new libircclient::Network(address, m_config.networkName); m_network = new libircclient::Network(address, m_config->networkName);
m_network->SetDefaultIdentifyString(m_config.identifyFormat); m_network->SetDefaultIdentifyString(m_config->identifyFormat);
m_network->Connect(); m_network->Connect();
connect(m_network, &libircclient::Network::Event_WhoisRegNick, this, &IRCNetworkClient::Slot_adminIdentified); connect(m_network, &libircclient::Network::Event_WhoisRegNick, this, &IRCNetworkClient::Slot_adminIdentified);
@ -120,21 +120,21 @@ void IRCNetworkClient::Slot_adminIdentified(libircclient::Parser* p)
LOG_WARN << "Event_WhoisRegNick failure: params.size() < 2, expected 2"; LOG_WARN << "Event_WhoisRegNick failure: params.size() < 2, expected 2";
return; return;
} }
if (p->GetParameters().at(1) != m_config.ircabotAdmin) if (p->GetParameters().at(1) != m_config->ircabotAdmin)
{ {
LOG_WARN << "Event_WhoisRegNick failure: requested, but admin changed"; LOG_WARN << "Event_WhoisRegNick failure: requested, but admin changed";
return; return;
} }
LOG_INFO << "Admin authorized:" << m_config.ircabotAdmin; LOG_INFO << "Admin authorized:" << m_config->ircabotAdmin;
AdminIRCPanel::identifiedTimestampUpdate(m_network->GetNetworkName()); AdminIRCPanel::identifiedTimestampUpdate(m_network->GetNetworkName());
m_network->SendMessage(m_config.ircabotAdmin, "You have been identified as an IRCaBot administrator. " m_network->SendMessage(m_config->ircabotAdmin, "You have been identified as an IRCaBot administrator. "
"Timeout: " + QString::number(Config::ircAdminAuthorizationTimeout()) + " secs"); "Timeout: " + QString::number(Config::ircAdminAuthorizationTimeout()) + " secs");
} }
void IRCNetworkClient::Slot_onDirectMessage(QString sender, QString text) void IRCNetworkClient::Slot_onDirectMessage(QString sender, QString text)
{ {
if (sender != m_config.ircabotAdmin) return; if (sender != m_config->ircabotAdmin) return;
QStringList answer; QStringList answer;
if (not AdminIRCPanel::parse(m_network->GetNetworkName(), text, answer)) if (not AdminIRCPanel::parse(m_network->GetNetworkName(), text, answer))

View File

@ -30,7 +30,7 @@ class IRCNetworkClient : public QObject
Q_OBJECT Q_OBJECT
public: public:
IRCNetworkClient(QObject* parent = nullptr); IRCNetworkClient(QObject* parent = nullptr);
void setConfig(const Config::Network& config) { m_config = config; } void setConfig(const Config::Network* config) { m_config = config; }
// after config change; voiceGate, ircabotAdmin and autoReconnect have effect in run-time automatically // after config change; voiceGate, ircabotAdmin and autoReconnect have effect in run-time automatically
void reloadChannelList(); void reloadChannelList();
void start(); void start();
@ -47,7 +47,7 @@ private slots:
void Slot_onChannelMessage(QString channel, QString sender, QString text); void Slot_onChannelMessage(QString channel, QString sender, QString text);
private: private:
Config::Network m_config; const Config::Network* m_config;
libircclient::Network* m_network = nullptr; libircclient::Network* m_network = nullptr;
}; };