Skip to content
Browse files

Add JoinAfterCloaked setting to q.cpp

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...
1 parent db0e099 commit c59e4d1bee5f6c5c7bb850658b00c672d43226b4 @ahf ahf committed
Showing with 38 additions and 4 deletions.
  1. +38 −4 modules/q.cpp
View
42 modules/q.cpp
@@ -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
@@ -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();
}
@@ -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>");
@@ -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);
@@ -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") {
@@ -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");
@@ -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;
@@ -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!");
}
@@ -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;
@@ -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) {

0 comments on commit c59e4d1

Please sign in to comment.
Something went wrong with that request. Please try again.