mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Move IRCConnectEnabled to each network instead of a global user setting
This commit is contained in:
@@ -89,6 +89,9 @@ public:
|
||||
bool SetNextServer(const CServer* pServer);
|
||||
bool IsLastServer() const;
|
||||
|
||||
void SetIRCConnectEnabled(bool b);
|
||||
bool GetIRCConnectEnabled() const { return m_bIRCConnectEnabled; }
|
||||
|
||||
CIRCSock* GetIRCSock() { return m_pIRCSock; }
|
||||
const CIRCSock* GetIRCSock() const { return m_pIRCSock; }
|
||||
const CString& GetIRCServer() const;
|
||||
@@ -159,6 +162,7 @@ protected:
|
||||
|
||||
CString m_sChanPrefixes;
|
||||
|
||||
bool m_bIRCConnectEnabled;
|
||||
CString m_sIRCServer;
|
||||
vector<CServer*> m_vServers;
|
||||
unsigned int m_uServerIdx; ///< Index in m_vServers of our current server + 1
|
||||
|
||||
@@ -125,7 +125,6 @@ public:
|
||||
void SetJoinTries(unsigned int i) { m_uMaxJoinTries = i; }
|
||||
void SetMaxJoins(unsigned int i) { m_uMaxJoins = i; }
|
||||
void SetSkinName(const CString& s) { m_sSkinName = s; }
|
||||
void SetIRCConnectEnabled(bool b) { m_bIRCConnectEnabled = b; }
|
||||
// !Setters
|
||||
|
||||
// Getters
|
||||
@@ -146,7 +145,6 @@ public:
|
||||
const CString& GetTimestampFormat() const;
|
||||
bool GetTimestampAppend() const;
|
||||
bool GetTimestampPrepend() const;
|
||||
bool GetIRCConnectEnabled() const { return m_bIRCConnectEnabled; }
|
||||
|
||||
const CString& GetUserPath() const;
|
||||
|
||||
@@ -202,7 +200,6 @@ protected:
|
||||
bool m_bBeingDeleted;
|
||||
bool m_bAppendTimestamp;
|
||||
bool m_bPrependTimestamp;
|
||||
bool m_bIRCConnectEnabled;
|
||||
|
||||
CUserTimer* m_pUserTimer;
|
||||
|
||||
|
||||
@@ -559,7 +559,6 @@ class CAdminMod : public CModule {
|
||||
PutModule("Error: Cloning failed! [" + sError + "]");
|
||||
return;
|
||||
}
|
||||
pNewUser->SetIRCConnectEnabled(false);
|
||||
|
||||
if (!CZNC::Get().AddUser(pNewUser, sError)) {
|
||||
delete pNewUser;
|
||||
@@ -730,8 +729,7 @@ class CAdminMod : public CModule {
|
||||
}
|
||||
|
||||
// then reconnect
|
||||
pUser->SetIRCConnectEnabled(true);
|
||||
pNetwork->CheckIRCConnect();
|
||||
pNetwork->SetIRCConnectEnabled(true);
|
||||
|
||||
PutModule("Queued user for a reconnect.");
|
||||
}
|
||||
@@ -757,14 +755,7 @@ class CAdminMod : public CModule {
|
||||
return;
|
||||
}
|
||||
|
||||
CIRCSock *pIRCSock = pNetwork->GetIRCSock();
|
||||
if (pIRCSock && !pIRCSock->IsConnected())
|
||||
pIRCSock->Close();
|
||||
else if(pIRCSock)
|
||||
pIRCSock->Quit();
|
||||
|
||||
pUser->SetIRCConnectEnabled(false);
|
||||
|
||||
pNetwork->SetIRCConnectEnabled(false);
|
||||
PutModule("Closed user's IRC connection.");
|
||||
}
|
||||
|
||||
|
||||
@@ -158,16 +158,9 @@ private:
|
||||
// Disconnect all networks from irc
|
||||
vector<CIRCNetwork*> vNetworks = pUser->GetNetworks();
|
||||
for (vector<CIRCNetwork*>::iterator it2 = vNetworks.begin(); it2 != vNetworks.end(); ++it2) {
|
||||
CIRCNetwork *pNetwork = *it2;
|
||||
CIRCSock *pIRCSock = pNetwork->GetIRCSock();
|
||||
if (pIRCSock) {
|
||||
pIRCSock->Quit();
|
||||
}
|
||||
(*it2)->SetIRCConnectEnabled(false);
|
||||
}
|
||||
|
||||
// ...and don't reconnect
|
||||
pUser->SetIRCConnectEnabled(false);
|
||||
|
||||
SetNV(pUser->GetUserName(), "");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,12 @@
|
||||
<div><input type="text" name="realname" value="<? VAR RealName ?>" class="full" maxlength="256" /></div>
|
||||
</div>
|
||||
|
||||
<div class="subsection">
|
||||
<div class="inputlabel">Active:</div>
|
||||
<div class="checkbox"><input type="checkbox" name="doconnect" id="doconnect_checkbox"<? IF IRCConnectEnabled ?> checked="checked"<? ENDIF ?> />
|
||||
<label for="doconnect_checkbox">Connect to IRC & automatically re-connect</label></div>
|
||||
</div>
|
||||
|
||||
<div class="subsection half">
|
||||
<div class="inputlabel">Servers:</div>
|
||||
<div><textarea name="servers" cols="70" rows="5"><? LOOP ServerLoop ?><? VAR Server ?>
|
||||
|
||||
@@ -98,14 +98,6 @@
|
||||
<div><input type="text" name="quitmsg" value="<? VAR QuitMsg ?>" class="full" maxlength="256" /></div>
|
||||
</div>
|
||||
<div style="clear: both;"></div>
|
||||
|
||||
<div class="subsection">
|
||||
<div class="inputlabel">Active:</div>
|
||||
<div class="checkbox"><input type="checkbox" name="doconnect" id="doconnect_checkbox"<? IF IRCConnectEnabled ?> checked="checked"<? ENDIF ?> />
|
||||
<label for="doconnect_checkbox">Connect to IRC & automatically re-connect</label></div>
|
||||
</div>
|
||||
<div style="clear: both;"></div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -232,7 +232,6 @@ public:
|
||||
pNewUser->SetTimezoneOffset(WebSock.GetParam("timezoneoffset").ToDouble());
|
||||
pNewUser->SetJoinTries(WebSock.GetParam("jointries").ToUInt());
|
||||
pNewUser->SetMaxJoins(WebSock.GetParam("maxjoins").ToUInt());
|
||||
pNewUser->SetIRCConnectEnabled(WebSock.GetParam("doconnect").ToBool());
|
||||
|
||||
if (spSession->IsAdmin()) {
|
||||
pNewUser->SetDenyLoadMod(WebSock.GetParam("denyloadmod").ToBool());
|
||||
@@ -674,6 +673,8 @@ public:
|
||||
Tmpl["Ident"] = pNetwork->GetIdent();
|
||||
Tmpl["RealName"] = pNetwork->GetRealName();
|
||||
|
||||
Tmpl["IRCConnectEnabled"] = CString(pNetwork->GetIRCConnectEnabled());
|
||||
|
||||
const vector<CServer*>& vServers = pNetwork->GetServers();
|
||||
for (unsigned int a = 0; a < vServers.size(); a++) {
|
||||
CTemplate& l = Tmpl.AddRow("ServerLoop");
|
||||
@@ -701,6 +702,7 @@ public:
|
||||
} else {
|
||||
Tmpl["Action"] = "addnetwork";
|
||||
Tmpl["Title"] = "Add Network for User [" + pUser->GetUserName() + "]";
|
||||
Tmpl["IRCConnectEnabled"] = "true";
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -742,6 +744,8 @@ public:
|
||||
pNetwork->SetRealName(sArg);
|
||||
}
|
||||
|
||||
pNetwork->SetIRCConnectEnabled(WebSock.GetParam("doconnect").ToBool());
|
||||
|
||||
VCString vsArgs;
|
||||
|
||||
pNetwork->DelServers();
|
||||
@@ -882,7 +886,6 @@ public:
|
||||
Tmpl["TimezoneOffset"] = CString(pUser->GetTimezoneOffset());
|
||||
Tmpl["JoinTries"] = CString(pUser->JoinTries());
|
||||
Tmpl["MaxJoins"] = CString(pUser->MaxJoins());
|
||||
Tmpl["IRCConnectEnabled"] = CString(pUser->GetIRCConnectEnabled());
|
||||
|
||||
const set<CString>& ssAllowedHosts = pUser->GetAllowedHosts();
|
||||
for (set<CString>::const_iterator it = ssAllowedHosts.begin(); it != ssAllowedHosts.end(); ++it) {
|
||||
@@ -906,7 +909,6 @@ public:
|
||||
Tmpl["Action"] = "adduser";
|
||||
Tmpl["Title"] = "Add User";
|
||||
Tmpl["StatusPrefix"] = "*";
|
||||
Tmpl["IRCConnectEnabled"] = "true";
|
||||
}
|
||||
|
||||
// To change BindHosts be admin or don't have DenySetBindHost
|
||||
|
||||
@@ -302,8 +302,7 @@ void CClient::UserCommand(CString& sLine) {
|
||||
PutStatus("Connecting...");
|
||||
}
|
||||
|
||||
m_pUser->SetIRCConnectEnabled(true);
|
||||
m_pNetwork->CheckIRCConnect();
|
||||
m_pNetwork->SetIRCConnectEnabled(true);
|
||||
return;
|
||||
} else if (sCommand.Equals("DISCONNECT")) {
|
||||
if (!m_pNetwork) {
|
||||
@@ -316,7 +315,7 @@ void CClient::UserCommand(CString& sLine) {
|
||||
GetIRCSock()->Quit(sQuitMsg);
|
||||
}
|
||||
|
||||
m_pUser->SetIRCConnectEnabled(false);
|
||||
m_pNetwork->SetIRCConnectEnabled(false);
|
||||
PutStatus("Disconnected from IRC. Use 'connect' to reconnect.");
|
||||
return;
|
||||
} else if (sCommand.Equals("ENABLECHAN")) {
|
||||
|
||||
@@ -52,6 +52,8 @@ CIRCNetwork::CIRCNetwork(CUser *pUser, const CString& sName) {
|
||||
m_RawBuffer.SetLineCount(100, true); // This should be more than enough raws, especially since we are buffering the MOTD separately
|
||||
m_MotdBuffer.SetLineCount(200, true); // This should be more than enough motd lines
|
||||
m_QueryBuffer.SetLineCount(250, true);
|
||||
|
||||
SetIRCConnectEnabled(true);
|
||||
}
|
||||
|
||||
CIRCNetwork::CIRCNetwork(CUser *pUser, const CIRCNetwork &Network) {
|
||||
@@ -172,6 +174,7 @@ void CIRCNetwork::Clone(const CIRCNetwork& Network) {
|
||||
}
|
||||
// !Modules
|
||||
|
||||
SetIRCConnectEnabled(Network.GetIRCConnectEnabled());
|
||||
}
|
||||
|
||||
CIRCNetwork::~CIRCNetwork() {
|
||||
@@ -240,6 +243,10 @@ bool CIRCNetwork::ParseConfig(CConfig *pConfig, CString& sError, bool bUpgrade)
|
||||
{ "realname", &CIRCNetwork::SetRealName }
|
||||
};
|
||||
size_t numStringOptions = sizeof(StringOptions) / sizeof(StringOptions[0]);
|
||||
TOption<bool> BoolOptions[] = {
|
||||
{ "ircconnectenabled", &CIRCNetwork::SetIRCConnectEnabled },
|
||||
};
|
||||
size_t numBoolOptions = sizeof(BoolOptions) / sizeof(BoolOptions[0]);
|
||||
|
||||
for (size_t i = 0; i < numStringOptions; i++) {
|
||||
CString sValue;
|
||||
@@ -247,6 +254,12 @@ bool CIRCNetwork::ParseConfig(CConfig *pConfig, CString& sError, bool bUpgrade)
|
||||
(this->*StringOptions[i].pSetter)(sValue);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < numBoolOptions; i++) {
|
||||
CString sValue;
|
||||
if (pConfig->FindStringEntry(BoolOptions[i].name, sValue))
|
||||
(this->*BoolOptions[i].pSetter)(sValue.ToBool());
|
||||
}
|
||||
|
||||
pConfig->FindStringVector("loadmodule", vsList);
|
||||
for (vit = vsList.begin(); vit != vsList.end(); ++vit) {
|
||||
CString sValue = *vit;
|
||||
@@ -334,6 +347,8 @@ CConfig CIRCNetwork::ToConfig() {
|
||||
config.AddKeyValuePair("RealName", m_sRealName);
|
||||
}
|
||||
|
||||
config.AddKeyValuePair("IRCConnectEnabled", CString(GetIRCConnectEnabled()));
|
||||
|
||||
// Modules
|
||||
CModules& Mods = GetModules();
|
||||
|
||||
@@ -452,7 +467,7 @@ void CIRCNetwork::ClientConnected(CClient *pClient) {
|
||||
m_QueryBuffer.Clear();
|
||||
|
||||
// Tell them why they won't connect
|
||||
if (!m_pUser->GetIRCConnectEnabled())
|
||||
if (!GetIRCConnectEnabled())
|
||||
pClient->PutStatus("You are currently disconnected from IRC. "
|
||||
"Use 'connect' to reconnect.");
|
||||
}
|
||||
@@ -880,7 +895,7 @@ CString CIRCNetwork::GetCurNick() const {
|
||||
}
|
||||
|
||||
bool CIRCNetwork::Connect() {
|
||||
if (!m_pUser->GetIRCConnectEnabled() || m_pIRCSock || !HasServers())
|
||||
if (!GetIRCConnectEnabled() || m_pIRCSock || !HasServers())
|
||||
return false;
|
||||
|
||||
CServer *pServer = GetNextServer();
|
||||
@@ -941,9 +956,23 @@ void CIRCNetwork::IRCDisconnected() {
|
||||
CheckIRCConnect();
|
||||
}
|
||||
|
||||
void CIRCNetwork::SetIRCConnectEnabled(bool b) {
|
||||
m_bIRCConnectEnabled = b;
|
||||
|
||||
if (m_bIRCConnectEnabled) {
|
||||
CheckIRCConnect();
|
||||
} else if (GetIRCSock()) {
|
||||
if (GetIRCSock()->IsConnected()) {
|
||||
GetIRCSock()->Quit();
|
||||
} else {
|
||||
GetIRCSock()->Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CIRCNetwork::CheckIRCConnect() {
|
||||
// Do we want to connect?
|
||||
if (m_pUser->GetIRCConnectEnabled() && GetIRCSock() == NULL)
|
||||
if (GetIRCConnectEnabled() && GetIRCSock() == NULL)
|
||||
CZNC::Get().AddNetworkToQueue(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -929,7 +929,7 @@ void CIRCSock::Disconnected() {
|
||||
IRCSOCKMODULECALL(OnIRCDisconnected(), NOTHING);
|
||||
|
||||
DEBUG(GetSockName() << " == Disconnected()");
|
||||
if (!m_pNetwork->GetUser()->IsBeingDeleted() && m_pNetwork->GetUser()->GetIRCConnectEnabled() &&
|
||||
if (!m_pNetwork->GetUser()->IsBeingDeleted() && m_pNetwork->GetIRCConnectEnabled() &&
|
||||
m_pNetwork->GetServers().size() != 0) {
|
||||
m_pNetwork->PutStatus("Disconnected from IRC. Reconnecting...");
|
||||
}
|
||||
|
||||
11
src/User.cpp
11
src/User.cpp
@@ -83,7 +83,6 @@ CUser::CUser(const CString& sUserName)
|
||||
m_sTimestampFormat = "[%H:%M:%S]";
|
||||
m_bAppendTimestamp = false;
|
||||
m_bPrependTimestamp = true;
|
||||
m_bIRCConnectEnabled = true;
|
||||
m_pUserTimer = new CUserTimer(this);
|
||||
CZNC::Get().GetManager().AddCron(m_pUserTimer);
|
||||
}
|
||||
@@ -149,7 +148,6 @@ bool CUser::ParseConfig(CConfig* pConfig, CString& sError) {
|
||||
{ "denysetvhost", &CUser::SetDenySetBindHost },
|
||||
{ "appendtimestamp", &CUser::SetTimestampAppend },
|
||||
{ "prependtimestamp", &CUser::SetTimestampPrepend },
|
||||
{ "ircconnectenabled", &CUser::SetIRCConnectEnabled },
|
||||
};
|
||||
size_t numBoolOptions = sizeof(BoolOptions) / sizeof(BoolOptions[0]);
|
||||
|
||||
@@ -408,6 +406,13 @@ bool CUser::ParseConfig(CConfig* pConfig, CString& sError) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Move ircconnectenabled to the networks
|
||||
if (pConfig->FindStringEntry("ircconnectenabled", sValue)) {
|
||||
for (vector<CIRCNetwork*>::iterator it = m_vIRCNetworks.begin(); it != m_vIRCNetworks.end(); ++it) {
|
||||
(*it)->SetIRCConnectEnabled(sValue.ToBool());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -663,7 +668,6 @@ bool CUser::Clone(const CUser& User, CString& sErrorRet, bool bCloneNetworks) {
|
||||
// !CTCP Replies
|
||||
|
||||
// Flags
|
||||
SetIRCConnectEnabled(User.GetIRCConnectEnabled());
|
||||
SetKeepBuffer(User.KeepBuffer());
|
||||
SetMultiClients(User.MultiClients());
|
||||
SetDenyLoadMod(User.DenyLoadMod());
|
||||
@@ -825,7 +829,6 @@ CConfig CUser::ToConfig() {
|
||||
config.AddKeyValuePair("TimezoneOffset", CString(m_fTimezoneOffset));
|
||||
config.AddKeyValuePair("JoinTries", CString(m_uMaxJoinTries));
|
||||
config.AddKeyValuePair("MaxJoins", CString(m_uMaxJoins));
|
||||
config.AddKeyValuePair("IRCConnectEnabled", CString(GetIRCConnectEnabled()));
|
||||
|
||||
// Allow Hosts
|
||||
if (!m_ssAllowedHosts.empty()) {
|
||||
|
||||
Reference in New Issue
Block a user