示例#1
0
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);
}
示例#2
0
文件: IRCNetwork.cpp 项目: johnfb/znc
void CIRCNetwork::JoinChans() {
	bool bHaveKey = false;
	size_t joinLength = 4;  // join
	CString sChannels, sKeys;

	for (vector<CChan*>::iterator it = m_vChans.begin(); it != m_vChans.end(); ++it) {
		CChan *pChan = *it;

		if (pChan->IsOn() || pChan->IsDisabled() || !JoinChan(pChan)) {
			continue;
		}

		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 += ",";
		}

		if (!pChan->GetKey().empty()) {
			bHaveKey = true;
			sKeys += pChan->GetKey();
		}

		sChannels += pChan->GetName();
		joinLength += length;
	}

	if (!sChannels.empty()) {
		PutIRC("JOIN " + sChannels + (bHaveKey ? (" " + sKeys) : ""));
	}
}