diff --git a/Chan.cpp b/Chan.cpp index af2b71b4..4a5c85da 100644 --- a/Chan.cpp +++ b/Chan.cpp @@ -34,13 +34,8 @@ CChan::~CChan() { } void CChan::Reset() { - m_bWhoDone = false; m_bIsOn = false; - m_suUserPerms.clear(); m_musModes.clear(); - m_muuPermCount.clear(); - m_uLimit = 0; - m_uClientRequests = 0; m_sTopic = ""; m_sTopicOwner = ""; m_ulTopicDate = 0; @@ -98,8 +93,6 @@ void CChan::Cycle() const { void CChan::JoinUser(bool bForce, const CString& sKey, CClient* pClient) { if (!bForce && (!IsOn() || !IsDetached())) { - IncClientRequests(); - m_pUser->PutIRC("JOIN " + GetName() + " " + ((sKey.empty()) ? GetKey() : sKey)); return; } @@ -203,32 +196,9 @@ CString CChan::GetModeForNames() const { void CChan::SetModes(const CString& sModes) { m_musModes.clear(); - m_uLimit = 0; ModeChange(sModes); } -void CChan::IncClientRequests() { - m_uClientRequests++; -} - -bool CChan::DecClientRequests() { - if (!m_uClientRequests) { - return false; - } - - m_uClientRequests--; - return true; -} - -bool CChan::Who() { - if (m_bWhoDone) { - return false; - } - - m_pUser->PutIRC("WHO " + GetName()); - return true; -} - void CChan::OnWho(const CString& sNick, const CString& sIdent, const CString& sHost) { CNick* pNick = FindNick(sNick); @@ -266,17 +236,13 @@ void CChan::ModeChange(const CString& sModes, const CString& sOpNick) { if (uPerm) { if (bAdd) { - if (pNick->AddPerm(uPerm)) { - IncPermCount(uPerm); - } + pNick->AddPerm(uPerm); if (pNick->GetNick().Equals(m_pUser->GetCurNick())) { AddPerm(uPerm); } } else { - if (pNick->RemPerm(uPerm)) { - DecPermCount(uPerm); - } + pNick->RemPerm(uPerm); if (pNick->GetNick().Equals(m_pUser->GetCurNick())) { RemPerm(uPerm); @@ -462,9 +428,7 @@ bool CChan::AddNick(const CString& sNick) { pNick->SetHost(sHost); for (CString::size_type i = 0; i < sPrefix.length(); i++) { - if (pNick->AddPerm(sPrefix[i])) { - IncPermCount(sPrefix[i]); - } + pNick->AddPerm(sPrefix[i]); } if (pNick->GetNick().Equals(m_pUser->GetCurNick())) { @@ -478,31 +442,19 @@ bool CChan::AddNick(const CString& sNick) { return true; } -unsigned int CChan::GetPermCount(unsigned char uPerm) const { - map::const_iterator it = m_muuPermCount.find(uPerm); - return (it == m_muuPermCount.end()) ? 0 : it->second; -} +map CChan::GetPermCounts() const { + map mRet; -void CChan::DecPermCount(unsigned char uPerm) { - map::iterator it = m_muuPermCount.find(uPerm); + map::const_iterator it; + for (it = m_msNicks.begin(); it != m_msNicks.end(); it++) { + CString sPerms = it->second->GetPermStr(); - if (it == m_muuPermCount.end()) { - m_muuPermCount[uPerm] = 0; - } else { - if (it->second) { - m_muuPermCount[uPerm]--; + for (unsigned int p = 0; p < sPerms.size(); p++) { + mRet[sPerms[p]]++; } } -} -void CChan::IncPermCount(unsigned char uPerm) { - map::iterator it = m_muuPermCount.find(uPerm); - - if (it == m_muuPermCount.end()) { - m_muuPermCount[uPerm] = 1; - } else { - m_muuPermCount[uPerm]++; - } + return mRet; } bool CChan::RemNick(const CString& sNick) { @@ -514,12 +466,6 @@ bool CChan::RemNick(const CString& sNick) { return false; } - const set& suPerms = it->second->GetChanPerms(); - - for (it2 = suPerms.begin(); it2 != suPerms.end(); it2++) { - DecPermCount(*it2); - } - delete it->second; m_msNicks.erase(it); diff --git a/Chan.h b/Chan.h index fe5c6358..12629668 100644 --- a/Chan.h +++ b/Chan.h @@ -61,10 +61,6 @@ public: void DetachUser(); void AttachUser(); - void IncClientRequests(); - bool DecClientRequests(); - - bool Who(); void OnWho(const CString& sNick, const CString& sIdent, const CString& sHost); // Modes @@ -102,8 +98,6 @@ public: // !wrappers // Setters - void IncPermCount(unsigned char uPerm); - void DecPermCount(unsigned char uPerm); void SetIsOn(bool b) { m_bIsOn = b; if (!b) { Reset(); } } void SetKey(const CString& s) { m_sKey = s; } void SetTopic(const CString& s) { m_sTopic = s; } @@ -112,7 +106,6 @@ public: void SetDefaultModes(const CString& s) { m_sDefaultModes = s; } void SetBufferCount(unsigned int u) { m_uBufferCount = u; } void SetKeepBuffer(bool b) { m_bKeepBuffer = b; } - void SetWhoDone(bool b = true) { m_bWhoDone = b; } void SetDetached(bool b = true) { m_bDetached = b; } void SetInConfig(bool b) { m_bInConfig = b; } void SetCreationDate(unsigned long u) { m_ulCreationDate = u; } @@ -126,17 +119,15 @@ public: bool HasMode(unsigned char uMode) const; CString GetOptions() const; CString GetModeArg(unsigned char uMode) const; - unsigned int GetPermCount(unsigned char uPerm) const; + map GetPermCounts() const; bool IsOn() const { return m_bIsOn; } const CString& GetName() const { return m_sName; } const map& GetModes() const { return m_musModes; } const CString& GetKey() const { return m_sKey; } - unsigned int GetLimit() const { return m_uLimit; } const CString& GetTopic() const { return m_sTopic; } const CString& GetTopicOwner() const { return m_sTopicOwner; } unsigned int GetTopicDate() const { return m_ulTopicDate; } const CString& GetDefaultModes() const { return m_sDefaultModes; } - const vector& GetBans() const { return m_vsBans; } const vector& GetBuffer() const { return m_vsBuffer; } const map& GetNicks() const { return m_msNicks; } unsigned int GetNickCount() const { return m_msNicks.size(); } @@ -152,7 +143,6 @@ private: protected: bool m_bDetached; bool m_bIsOn; - bool m_bWhoDone; bool m_bKeepBuffer; bool m_bInConfig; bool m_bDisabled; @@ -164,18 +154,13 @@ protected: unsigned long m_ulCreationDate; CUser* m_pUser; CNick m_Nick; - unsigned int m_uLimit; unsigned int m_uJoinTries; CString m_sDefaultModes; - vector m_vsBans; map m_msNicks; // Todo: make this caseless (irc style) - set m_suUserPerms; unsigned int m_uBufferCount; - unsigned int m_uClientRequests; // Used to tell how many times a client tried to join this chan vector m_vsBuffer; map m_musModes; - map m_muuPermCount; }; #endif // !_CHAN_H diff --git a/ClientCommand.cpp b/ClientCommand.cpp index 7d71c3cc..26a06e6a 100644 --- a/ClientCommand.cpp +++ b/ClientCommand.cpp @@ -305,10 +305,10 @@ void CClient::UserCommand(const CString& sLine) { Table.SetCell("Modes", pChan->GetModeString()); Table.SetCell("Users", CString(pChan->GetNickCount())); + map mPerms = pChan->GetPermCounts(); for (unsigned int b = 0; b < sPerms.size(); b++) { - CString sPerm; - sPerm += sPerms[b]; - Table.SetCell(sPerm, CString(pChan->GetPermCount(sPerms[b]))); + char cPerm = sPerms[b]; + Table.SetCell(CString(cPerm), CString(mPerms[cPerm])); } } diff --git a/IRCSock.cpp b/IRCSock.cpp index 03d70f10..e98fd649 100644 --- a/IRCSock.cpp +++ b/IRCSock.cpp @@ -154,20 +154,6 @@ void CIRCSock::ReadLine(const CString& sData) { case 372: // motd case 376: // end motd m_pUser->AddMotdBuffer(":" + sServer + " " + sCmd + " ", " " + sRest); - break; - case 471: // :irc.server.net 471 nick #chan :Cannot join channel (+l) - case 473: // :irc.server.net 473 nick #chan :Cannot join channel (+i) - case 475: // :irc.server.net 475 nick #chan :Cannot join channel (+k) - if (m_pUser->IsUserAttached()) { - CChan* pChan = m_pUser->FindChan(sRest.substr(0, sRest.find(' '))); - - if ((pChan) && (!pChan->IsOn())) { - if (!pChan->DecClientRequests()) { - return; - } - } - } - break; case 437: // :irc.server.net 437 * badnick :Nick/channel is temporarily unavailable @@ -185,16 +171,6 @@ void CIRCSock::ReadLine(const CString& sData) { } break; } - case 315: { - // :irc.server.com 315 yournick #chan :End of /WHO list. - CChan* pChan = m_pUser->FindChan(sLine.Token(3)); - - if (pChan) { - pChan->SetWhoDone(); - } - - break; - } case 331: { // :irc.server.com 331 yournick #chan :No topic is set. CChan* pChan = m_pUser->FindChan(sLine.Token(3));