Skip to content

Commit

Permalink
Add JoinAfterCloaked setting to q.cpp
Browse files Browse the repository at this point in the history
This patch adds a new setting to the Q module, JoinAfterCloaked, that
allows the user to specify whether ZNC should postpone joining channels
before the user is cloaked.

Fixes #286
  • Loading branch information
ahf committed May 29, 2014
1 parent db0e099 commit c59e4d1
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions modules/q.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ class CQModule : public CModule {
}

CString sTmp;
m_bUseCloakedHost = (sTmp = GetNV("UseCloakedHost")).empty() ? true : sTmp.ToBool();
m_bUseChallenge = (sTmp = GetNV("UseChallenge")).empty() ? true : sTmp.ToBool();
m_bRequestPerms = GetNV("RequestPerms").ToBool();
m_bJoinOnInvite = (sTmp = GetNV("JoinOnInvite")).empty() ? true : sTmp.ToBool();
m_bUseCloakedHost = (sTmp = GetNV("UseCloakedHost")).empty() ? true : sTmp.ToBool();
m_bUseChallenge = (sTmp = GetNV("UseChallenge")).empty() ? true : sTmp.ToBool();
m_bRequestPerms = GetNV("RequestPerms").ToBool();
m_bJoinOnInvite = (sTmp = GetNV("JoinOnInvite")).empty() ? true : sTmp.ToBool();
m_bJoinAfterCloaked = (sTmp = GetNV("JoinAfterCloaked")).empty() ? true : sTmp.ToBool();

// Make sure NVs are stored in config. Note: SetUseCloakedHost() is called further down.
SetUseChallenge(m_bUseChallenge);
SetRequestPerms(m_bRequestPerms);
SetJoinOnInvite(m_bJoinOnInvite);
SetJoinAfterCloaked(m_bJoinAfterCloaked);

OnIRCDisconnected(); // reset module's state

Expand All @@ -67,6 +69,8 @@ class CQModule : public CModule {
"with /msg *q Set UseCloakedHost true/false.");
m_bUseCloakedHost = true;
SetUseCloakedHost(m_bUseCloakedHost);
m_bJoinAfterCloaked = true;
SetJoinAfterCloaked(m_bJoinAfterCloaked);
} else if (m_bUseChallenge) {
Cloak();
}
Expand Down Expand Up @@ -149,6 +153,10 @@ class CQModule : public CModule {
Table2.SetCell("Setting", "JoinOnInvite");
Table2.SetCell("Type", "Boolean");
Table2.SetCell("Description", "Whether to join channels when Q invites you.");
Table2.AddRow();
Table2.SetCell("Setting", "JoinAfterCloaked");
Table2.SetCell("Type", "Boolean");
Table2.SetCell("Description", "Whether to delay joining channels until after you are cloaked.");
PutModule(Table2);

PutModule("This module takes 2 optional parameters: <username> <password>");
Expand Down Expand Up @@ -177,6 +185,9 @@ class CQModule : public CModule {
} else if (sSetting == "joinoninvite") {
SetJoinOnInvite(sValue.ToBool());
PutModule("JoinOnInvite set");
} else if (sSetting == "joinaftercloaked") {
SetJoinAfterCloaked(sValue.ToBool());
PutModule("JoinAfterCloaked set");
} else
PutModule("Unknown setting: " + sSetting);

Expand All @@ -202,6 +213,9 @@ class CQModule : public CModule {
Table.AddRow();
Table.SetCell("Setting", "JoinOnInvite");
Table.SetCell("Value", CString(m_bJoinOnInvite));
Table.AddRow();
Table.SetCell("Setting", "JoinAfterCloaked");
Table.SetCell("Value", CString(m_bJoinAfterCloaked));
PutModule(Table);

} else if (sCommand == "status") {
Expand Down Expand Up @@ -255,6 +269,13 @@ class CQModule : public CModule {
return HandleMessage(Nick, sMessage);
}

virtual EModRet OnJoining(CChan& Channel) {
if (m_bJoinAfterCloaked && !m_bCloaked)
return HALT;

return CONTINUE;
}

virtual void OnJoin(const CNick& Nick, CChan& Channel) {
if (m_bRequestPerms && IsSelf(Nick))
HandleNeed(Channel, "ov");
Expand Down Expand Up @@ -297,6 +318,7 @@ class CQModule : public CModule {
SetUseChallenge(WebSock.GetParam("usechallenge").ToBool());
SetRequestPerms(WebSock.GetParam("requestperms").ToBool());
SetJoinOnInvite(WebSock.GetParam("joinoninvite").ToBool());
SetJoinAfterCloaked(WebSock.GetParam("joinaftercloaked").ToBool());
}

Tmpl["Username"] = m_sUsername;
Expand Down Expand Up @@ -325,6 +347,12 @@ class CQModule : public CModule {
o4["Tooltip"] = "Whether to join channels when Q invites you.";
o4["Checked"] = CString(m_bJoinOnInvite);

CTemplate& o5 = Tmpl.AddRow("OptionLoop");
o5["Name"] = "joinaftercloaked";
o5["DisplayName"] = "JoinAfterCloaked";
o5["Tooltip"] = "Whether to delay joining channels until after you are cloaked.";
o5["Checked"] = CString(m_bJoinAfterCloaked);

if (bSubmitted) {
WebSock.GetSession()->AddSuccess("Changes have been saved!");
}
Expand Down Expand Up @@ -558,6 +586,7 @@ class CQModule : public CModule {
bool m_bUseChallenge;
bool m_bRequestPerms;
bool m_bJoinOnInvite;
bool m_bJoinAfterCloaked;

void SetUsername(const CString& sUsername) {
m_sUsername = sUsername;
Expand Down Expand Up @@ -591,6 +620,11 @@ class CQModule : public CModule {
m_bJoinOnInvite = bJoinOnInvite;
SetNV("JoinOnInvite", CString(bJoinOnInvite));
}

void SetJoinAfterCloaked(const bool bJoinAfterCloaked) {
m_bJoinAfterCloaked = bJoinAfterCloaked;
SetNV("JoinAfterCloaked", CString(bJoinAfterCloaked));
}
};

template<> void TModInfo<CQModule>(CModInfo& Info) {
Expand Down

0 comments on commit c59e4d1

Please sign in to comment.