mirror of
https://github.com/znc/znc.git
synced 2026-08-07 17:33:34 +02:00
Add JoinTries config var which sets a limit for channel join tries to avoid
flood issues. This var defaults to 0 which means 'No Limit'. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@811 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
@@ -42,6 +42,7 @@ void CChan::Reset() {
|
||||
m_ulTopicDate = 0;
|
||||
m_ulCreationDate = 0;
|
||||
ClearNicks();
|
||||
ResetJoinTries();
|
||||
}
|
||||
|
||||
bool CChan::WriteConfig(CFile& File) {
|
||||
|
||||
@@ -113,6 +113,8 @@ public:
|
||||
void SetCreationDate(unsigned long u) { m_ulCreationDate = u; }
|
||||
void Disable() { m_bDisabled = true; }
|
||||
void Enable() { m_bDisabled = false; }
|
||||
void IncJoinTries() { m_uJoinTries++; }
|
||||
void ResetJoinTries() { m_uJoinTries = 0; }
|
||||
// !Setters
|
||||
|
||||
// Getters
|
||||
@@ -140,6 +142,7 @@ public:
|
||||
bool InConfig() const { return m_bInConfig; }
|
||||
unsigned long GetCreationDate() const { return m_ulCreationDate; }
|
||||
bool IsDisabled() const { return m_bDisabled; }
|
||||
unsigned int GetJoinTries() { return m_uJoinTries; }
|
||||
// !Getters
|
||||
private:
|
||||
protected:
|
||||
@@ -160,6 +163,7 @@ protected:
|
||||
CUser* m_pUser;
|
||||
CNick m_Nick;
|
||||
unsigned int m_uLimit;
|
||||
unsigned int m_uJoinTries;
|
||||
CString m_sDefaultModes;
|
||||
vector<CString> m_vsBans;
|
||||
map<CString,CNick*> m_msNicks; // Todo: make this caseless (irc style)
|
||||
|
||||
+9
-1
@@ -476,12 +476,20 @@ void CIRCSock::ReadLine(const CString& sData) {
|
||||
sChan.LeftChomp();
|
||||
}
|
||||
|
||||
CChan* pChan;
|
||||
|
||||
// Todo: use nick compare function
|
||||
if (Nick.GetNick().CaseCmp(GetNick()) == 0) {
|
||||
m_pUser->AddChan(sChan, false);
|
||||
pChan = m_pUser->FindChan(sChan);
|
||||
if (pChan) {
|
||||
pChan->ResetJoinTries();
|
||||
pChan->Enable();
|
||||
}
|
||||
} else {
|
||||
pChan = m_pUser->FindChan(sChan);
|
||||
}
|
||||
|
||||
CChan* pChan = m_pUser->FindChan(sChan);
|
||||
if (pChan) {
|
||||
pChan->AddNick(Nick.GetNickMask());
|
||||
MODULECALL(OnJoin(Nick.GetNickMask(), *pChan), m_pUser, NULL, );
|
||||
|
||||
@@ -37,6 +37,7 @@ CUser::CUser(const CString& sUserName) {
|
||||
m_sStatusPrefix = "*";
|
||||
m_sChanPrefixes = "#&";
|
||||
m_uBufferCount = 50;
|
||||
m_uMaxJoinTries = 0;
|
||||
m_bKeepBuffer = false;
|
||||
m_bAutoCycle = true;
|
||||
m_bBeingDeleted = false;
|
||||
@@ -543,6 +544,7 @@ bool CUser::WriteConfig(CFile& File) {
|
||||
PrintLine(File, "AppendTimestamp", CString((GetTimestampAppend()) ? "true" : "false"));
|
||||
PrintLine(File, "PrependTimestamp", CString((GetTimestampPrepend()) ? "true" : "false"));
|
||||
PrintLine(File, "TimezoneOffset", CString(m_fTimezoneOffset));
|
||||
PrintLine(File, "JoinTries", CString(m_uMaxJoinTries));
|
||||
File.Write("\r\n");
|
||||
|
||||
// Allow Hosts
|
||||
@@ -618,7 +620,13 @@ void CUser::JoinChans() {
|
||||
for (unsigned int a = 0; a < m_vChans.size(); a++) {
|
||||
CChan* pChan = m_vChans[a];
|
||||
if (!pChan->IsOn() && !pChan->IsDisabled()) {
|
||||
PutIRC("JOIN " + pChan->GetName() + " " + pChan->GetKey());
|
||||
if (JoinTries() != 0 && pChan->GetJoinTries() >= JoinTries()) {
|
||||
PutStatus("The channel " + pChan->GetName() + " could not be joined, disabling it.");
|
||||
pChan->Disable();
|
||||
} else {
|
||||
pChan->IncJoinTries();
|
||||
PutIRC("JOIN " + pChan->GetName() + " " + pChan->GetKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -657,7 +665,7 @@ bool CUser::DelServer(const CString& sName) {
|
||||
|
||||
if (pIRCSock) {
|
||||
pIRCSock->Close();
|
||||
PutUser("Your current server was removed, jumping...");
|
||||
PutStatus("Your current server was removed, jumping...");
|
||||
}
|
||||
} else if (m_uServerIdx >= m_vServers.size()) {
|
||||
m_uServerIdx = 0;
|
||||
|
||||
@@ -138,6 +138,7 @@ public:
|
||||
void SetTimestampAppend(bool b) { m_bAppendTimestamp = b; }
|
||||
void SetTimestampPrepend(bool b) { m_bPrependTimestamp = b; }
|
||||
void SetTimezoneOffset(float b) { m_fTimezoneOffset = b; }
|
||||
void SetJoinTries(unsigned int i) { m_uMaxJoinTries = i; }
|
||||
// !Setters
|
||||
|
||||
// Getters
|
||||
@@ -186,6 +187,7 @@ public:
|
||||
float GetTimezoneOffset() const { return m_fTimezoneOffset; }
|
||||
unsigned long long BytesRead() const { return m_uBytesRead; }
|
||||
unsigned long long BytesWritten() const { return m_uBytesWritten; }
|
||||
unsigned int JoinTries() const { return m_uMaxJoinTries; }
|
||||
// !Getters
|
||||
private:
|
||||
protected:
|
||||
@@ -242,6 +244,7 @@ protected:
|
||||
unsigned int m_uBufferCount;
|
||||
unsigned long long m_uBytesRead;
|
||||
unsigned long long m_uBytesWritten;
|
||||
unsigned int m_uMaxJoinTries;
|
||||
|
||||
#ifdef _MODULES
|
||||
CModules* m_pModules;
|
||||
|
||||
@@ -1028,6 +1028,9 @@ bool CZNC::ParseConfig(const CString& sConfig) {
|
||||
} else if (sName.CaseCmp("TimezoneOffset") == 0) {
|
||||
pUser->SetTimezoneOffset(sValue.ToDouble()); // there is no ToFloat()
|
||||
continue;
|
||||
} else if (sName.CaseCmp("JoinTries") == 0) {
|
||||
pUser->SetJoinTries(sValue.ToUInt());
|
||||
continue;
|
||||
} else if (sName.CaseCmp("LoadModule") == 0) {
|
||||
CString sModName = sValue.Token(0);
|
||||
CUtils::PrintAction("Loading Module [" + sModName + "]");
|
||||
|
||||
Reference in New Issue
Block a user