The complete source code of IdealIRC
http://www.idealirc.org/
54 lines
2.2 KiB
54 lines
2.2 KiB
/*
|
|
* IdealIRC - Internet Relay Chat client
|
|
* Copyright (C) 2021 Tom-Andre Barstad.
|
|
* This software is licensed under the Software Attribution License.
|
|
* See LICENSE for more information.
|
|
*/
|
|
|
|
#include "ICommand/ICommandPriv.h"
|
|
#include "ConfigMgr.h"
|
|
#include <chrono>
|
|
|
|
void ICommandPriv::cmd_server(bool ssl, bool newstatus, bool activate, const std::string& host, const std::string& port)
|
|
{
|
|
auto& mdi = MdiManager::instance();
|
|
IWinStatus* sw = newstatus ? static_cast<IWinStatus*>(mdi.createSubwindow(nullptr, "Status", IWin::Type::Status, activate))
|
|
: mdi.currentStatus();
|
|
|
|
const auto& conf = ConfigMgr::instance();
|
|
auto& con = sw->getConnection();
|
|
|
|
if (con.isConnected()) {
|
|
const auto quitMsg = conf.common("QuitMessage").toStdString();
|
|
con.setReconnectDetails(ssl, host, port);
|
|
auto e = con.disconnectFromServer(quitMsg);
|
|
if (e != IRCError::NoError)
|
|
sw->print(PrintType::ProgramInfo, IRCErrorToString(e).c_str());
|
|
}
|
|
else {
|
|
QString nickname = conf.connection("Nickname");
|
|
QString realname = conf.connection("Realname");
|
|
QString username = conf.connection("Username");
|
|
|
|
con.setHostname(host, ssl);
|
|
con.setPort(port);
|
|
con.setRealname(realname.toStdString());
|
|
con.setIdent(username.toStdString());
|
|
con.setNickname(nickname.toStdString());
|
|
|
|
bool manualKeepaliveEnabled = conf.common("ManualKeepaliveEnabled").toInt();
|
|
int manualKeepalive = manualKeepaliveEnabled ? conf.common("ManualKeepalive").toInt() : 0;
|
|
con.setManualKeepalive(std::chrono::seconds(manualKeepalive));
|
|
|
|
const auto cfgSSLExcept_Expired = conf.common("SSLExpired");
|
|
const auto cfgSSLExcept_Selfsigned = conf.common("SSLSelfsigned");
|
|
const auto cfgSSLExcept_CNMismatch = conf.common("SSLCNMismatch");
|
|
con.exceptSSL_Expired(cfgSSLExcept_Expired == "1");
|
|
con.exceptSSL_SelfSigned(cfgSSLExcept_Selfsigned == "1");
|
|
con.exceptSSL_CNMismatch(cfgSSLExcept_CNMismatch == "1");
|
|
|
|
auto e = con.tryConnect();
|
|
if (e != IRCError::NoError)
|
|
sw->print(PrintType::ProgramInfo, IRCErrorToString(e).c_str());
|
|
}
|
|
}
|
|
|