mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Rewrite the JOIN channel logic, dropping MaxJoins
Instead we fill the JOIN line up with as many channels as we can fit in an IRC line. Rate limiting is done per command now, making MaxJoins unnecessary.
This commit is contained in:
@@ -124,7 +124,6 @@ public:
|
||||
void SetTimestampPrepend(bool b) { m_bPrependTimestamp = b; }
|
||||
void SetTimezoneOffset(float b) { m_fTimezoneOffset = b; }
|
||||
void SetJoinTries(unsigned int i) { m_uMaxJoinTries = i; }
|
||||
void SetMaxJoins(unsigned int i) { m_uMaxJoins = i; }
|
||||
void SetSkinName(const CString& s) { m_sSkinName = s; }
|
||||
// !Setters
|
||||
|
||||
@@ -165,7 +164,6 @@ public:
|
||||
unsigned long long BytesRead() const { return m_uBytesRead; }
|
||||
unsigned long long BytesWritten() const { return m_uBytesWritten; }
|
||||
unsigned int JoinTries() const { return m_uMaxJoinTries; }
|
||||
unsigned int MaxJoins() const { return m_uMaxJoins; }
|
||||
CString GetSkinName() const;
|
||||
// !Getters
|
||||
|
||||
@@ -211,7 +209,6 @@ protected:
|
||||
unsigned long long m_uBytesRead;
|
||||
unsigned long long m_uBytesWritten;
|
||||
unsigned int m_uMaxJoinTries;
|
||||
unsigned int m_uMaxJoins;
|
||||
CString m_sSkinName;
|
||||
|
||||
CModules* m_pModules;
|
||||
|
||||
@@ -58,7 +58,6 @@ class CAdminMod : public CModule {
|
||||
{"KeepBuffer", boolean},
|
||||
{"Password", str},
|
||||
{"JoinTries", integer},
|
||||
{"MaxJoins", integer},
|
||||
{"TimezoneOffset", doublenum},
|
||||
{"Admin", boolean},
|
||||
{"AppendTimestamp", boolean},
|
||||
@@ -154,8 +153,6 @@ class CAdminMod : public CModule {
|
||||
PutModule("BufferCount = " + CString(pUser->GetBufferCount()));
|
||||
else if (sVar == "keepbuffer")
|
||||
PutModule("KeepBuffer = " + CString(pUser->KeepBuffer()));
|
||||
else if (sVar == "maxjoins")
|
||||
PutModule("MaxJoins = " + CString(pUser->MaxJoins()));
|
||||
else if (sVar == "jointries")
|
||||
PutModule("JoinTries = " + CString(pUser->JoinTries()));
|
||||
else if (sVar == "timezoneoffset")
|
||||
@@ -266,11 +263,6 @@ class CAdminMod : public CModule {
|
||||
pUser->SetPass(sHash, CUser::HASH_DEFAULT, sSalt);
|
||||
PutModule("Password has been changed!");
|
||||
}
|
||||
else if (sVar == "maxjoins") {
|
||||
unsigned int i = sValue.ToUInt();
|
||||
pUser->SetMaxJoins(i);
|
||||
PutModule("MaxJoins = " + CString(pUser->MaxJoins()));
|
||||
}
|
||||
else if (sVar == "jointries") {
|
||||
unsigned int i = sValue.ToUInt();
|
||||
pUser->SetJoinTries(i);
|
||||
|
||||
@@ -223,10 +223,6 @@
|
||||
<div class="inputlabel">Join Tries:</div>
|
||||
<div><input type="number" name="jointries" value="<? VAR JoinTries ?>" class="third" min="0" /></div>
|
||||
</div>
|
||||
<div class="subsection">
|
||||
<div class="inputlabel">Max Joins:</div>
|
||||
<div><input type="number" name="maxjoins" value="<? VAR MaxJoins ?>" class="third" min="0" /></div>
|
||||
</div>
|
||||
<div class="subsection half">
|
||||
<div class="inputlabel">CTCP Replies:</div>
|
||||
<div><textarea name="ctcpreplies" cols="70" rows="3"><? LOOP CTCPLoop ?><? VAR CTCP ?>
|
||||
|
||||
@@ -231,7 +231,6 @@ public:
|
||||
pNewUser->SetTimestampPrepend(WebSock.GetParam("prependtimestamp").ToBool());
|
||||
pNewUser->SetTimezoneOffset(WebSock.GetParam("timezoneoffset").ToDouble());
|
||||
pNewUser->SetJoinTries(WebSock.GetParam("jointries").ToUInt());
|
||||
pNewUser->SetMaxJoins(WebSock.GetParam("maxjoins").ToUInt());
|
||||
|
||||
if (spSession->IsAdmin()) {
|
||||
pNewUser->SetDenyLoadMod(WebSock.GetParam("denyloadmod").ToBool());
|
||||
@@ -914,7 +913,6 @@ public:
|
||||
Tmpl["TimestampFormat"] = pUser->GetTimestampFormat();
|
||||
Tmpl["TimezoneOffset"] = CString(pUser->GetTimezoneOffset());
|
||||
Tmpl["JoinTries"] = CString(pUser->JoinTries());
|
||||
Tmpl["MaxJoins"] = CString(pUser->MaxJoins());
|
||||
|
||||
const set<CString>& ssAllowedHosts = pUser->GetAllowedHosts();
|
||||
for (set<CString>::const_iterator it = ssAllowedHosts.begin(); it != ssAllowedHosts.end(); ++it) {
|
||||
|
||||
@@ -640,67 +640,46 @@ bool CIRCNetwork::DelChan(const CString& sName) {
|
||||
}
|
||||
|
||||
void CIRCNetwork::JoinChans() {
|
||||
// Avoid divsion by zero, it's bad!
|
||||
if (m_vChans.empty())
|
||||
return;
|
||||
|
||||
// We start at a random offset into the channel list so that if your
|
||||
// first 3 channels are invite-only and you got MaxJoins == 3, ZNC will
|
||||
// still be able to join the rest of your channels.
|
||||
unsigned int start = rand() % m_vChans.size();
|
||||
unsigned int uJoins = m_pUser->MaxJoins();
|
||||
set<CChan*> sChans;
|
||||
for (unsigned int a = 0; a < m_vChans.size(); a++) {
|
||||
unsigned int idx = (start + a) % m_vChans.size();
|
||||
CChan* pChan = m_vChans[idx];
|
||||
if (!pChan->IsOn() && !pChan->IsDisabled()) {
|
||||
if (!JoinChan(pChan))
|
||||
continue;
|
||||
|
||||
sChans.insert(pChan);
|
||||
|
||||
// Limit the number of joins
|
||||
if (uJoins != 0 && --uJoins == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (!sChans.empty())
|
||||
JoinChans(sChans);
|
||||
}
|
||||
|
||||
void CIRCNetwork::JoinChans(set<CChan*>& sChans) {
|
||||
CString sKeys, sJoin;
|
||||
bool bHaveKey = false;
|
||||
size_t uiJoinLength = strlen("JOIN ");
|
||||
size_t joinLength = 4; // join
|
||||
CString sChannels, sKeys;
|
||||
|
||||
while (!sChans.empty()) {
|
||||
set<CChan*>::iterator it = sChans.begin();
|
||||
const CString& sName = (*it)->GetName();
|
||||
const CString& sKey = (*it)->GetKey();
|
||||
size_t len = sName.length() + sKey.length();
|
||||
len += 2; // two comma
|
||||
for (vector<CChan*>::iterator it = m_vChans.begin(); it != m_vChans.end(); ++it) {
|
||||
CChan *pChan = *it;
|
||||
|
||||
if (!sKeys.empty() && uiJoinLength + len >= 512)
|
||||
break;
|
||||
if (pChan->IsOn() || pChan->IsDisabled() || !JoinChan(pChan)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!sJoin.empty()) {
|
||||
sJoin += ",";
|
||||
size_t length = pChan->GetName().length() + pChan->GetKey().length() + 2; // +2 for either space or commas
|
||||
|
||||
if ((joinLength + length) >= 510) {
|
||||
// Sent what we got, and cleanup
|
||||
PutIRC("JOIN " + sChannels + (bHaveKey ? (" " + sKeys) : ""));
|
||||
|
||||
sChannels = "";
|
||||
sKeys = "";
|
||||
joinLength = 4; // join
|
||||
bHaveKey = false;
|
||||
}
|
||||
|
||||
if (!sChannels.empty()) {
|
||||
sChannels += ",";
|
||||
sKeys += ",";
|
||||
}
|
||||
uiJoinLength += len;
|
||||
sJoin += sName;
|
||||
if (!sKey.empty()) {
|
||||
sKeys += sKey;
|
||||
|
||||
if (!pChan->GetKey().empty()) {
|
||||
bHaveKey = true;
|
||||
sKeys += pChan->GetKey();
|
||||
}
|
||||
sChans.erase(it);
|
||||
|
||||
sChannels += pChan->GetName();
|
||||
joinLength += length;
|
||||
}
|
||||
|
||||
if (bHaveKey)
|
||||
PutIRC("JOIN " + sJoin + " " + sKeys);
|
||||
else
|
||||
PutIRC("JOIN " + sJoin);
|
||||
if (!sChannels.empty()) {
|
||||
PutIRC("JOIN " + sChannels + (bHaveKey ? (" " + sKeys) : ""));
|
||||
}
|
||||
}
|
||||
|
||||
bool CIRCNetwork::JoinChan(CChan* pChan) {
|
||||
|
||||
@@ -77,7 +77,6 @@ CUser::CUser(const CString& sUserName)
|
||||
m_sStatusPrefix = "*";
|
||||
m_uBufferCount = 50;
|
||||
m_uMaxJoinTries = 10;
|
||||
m_uMaxJoins = 5;
|
||||
m_bKeepBuffer = false;
|
||||
m_bBeingDeleted = false;
|
||||
m_sTimestampFormat = "[%H:%M:%S]";
|
||||
@@ -134,7 +133,6 @@ bool CUser::ParseConfig(CConfig* pConfig, CString& sError) {
|
||||
size_t numStringOptions = sizeof(StringOptions) / sizeof(StringOptions[0]);
|
||||
TOption<unsigned int> UIntOptions[] = {
|
||||
{ "jointries", &CUser::SetJoinTries },
|
||||
{ "maxjoins", &CUser::SetMaxJoins },
|
||||
};
|
||||
size_t numUIntOptions = sizeof(UIntOptions) / sizeof(UIntOptions[0]);
|
||||
TOption<bool> BoolOptions[] = {
|
||||
@@ -179,6 +177,9 @@ bool CUser::ParseConfig(CConfig* pConfig, CString& sError) {
|
||||
|
||||
CString sValue;
|
||||
|
||||
// MaxJoins has been removed
|
||||
pConfig->FindStringEntry("maxjoins", sValue);
|
||||
|
||||
CString sDCCLookupValue;
|
||||
pConfig->FindStringEntry("dcclookupmethod", sDCCLookupValue);
|
||||
if (pConfig->FindStringEntry("bouncedccs", sValue)) {
|
||||
@@ -635,7 +636,6 @@ bool CUser::Clone(const CUser& User, CString& sErrorRet, bool bCloneNetworks) {
|
||||
SetDefaultChanModes(User.GetDefaultChanModes());
|
||||
SetBufferCount(User.GetBufferCount(), true);
|
||||
SetJoinTries(User.JoinTries());
|
||||
SetMaxJoins(User.MaxJoins());
|
||||
|
||||
// Allowed Hosts
|
||||
m_ssAllowedHosts.clear();
|
||||
@@ -830,7 +830,6 @@ CConfig CUser::ToConfig() {
|
||||
config.AddKeyValuePair("PrependTimestamp", CString(GetTimestampPrepend()));
|
||||
config.AddKeyValuePair("TimezoneOffset", CString(m_fTimezoneOffset));
|
||||
config.AddKeyValuePair("JoinTries", CString(m_uMaxJoinTries));
|
||||
config.AddKeyValuePair("MaxJoins", CString(m_uMaxJoins));
|
||||
|
||||
// Allow Hosts
|
||||
if (!m_ssAllowedHosts.empty()) {
|
||||
|
||||
Reference in New Issue
Block a user