From 88897381da36256ee28e5260f72e94522f20cab3 Mon Sep 17 00:00:00 2001 From: psychon Date: Mon, 17 Aug 2009 20:00:09 +0000 Subject: [PATCH] JoinChans(): Join channels in a semi random number Now ZNC doesn't try to join the first, then the second etc channel, but instead it will start at a random channel and go on from there. This fixes a bug if you got e.g. MaxJoins = 5 and your first five channels are invite-only. Without this, ZNC would never try to join any of the other channels. With this patch applied, it will sooner or later try to join the other channels, too. (I'd guess more sooner than later) git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1602 726aef4b-f618-498e-8847-2d620e286838 --- User.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/User.cpp b/User.cpp index 24f4cf4e..9ff8a4be 100644 --- a/User.cpp +++ b/User.cpp @@ -704,9 +704,14 @@ CChan* CUser::FindChan(const CString& sName) const { } void CUser::JoinChans() { + // 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_uMaxJoins; for (unsigned int a = 0; a < m_vChans.size(); a++) { - CChan* pChan = m_vChans[a]; + unsigned int idx = (start + a) % m_vChans.size(); + CChan* pChan = m_vChans[idx]; if (!pChan->IsOn() && !pChan->IsDisabled()) { if (!JoinChan(pChan)) continue;