diff --git a/Chan.cpp b/Chan.cpp index 15c3561a..5c0fe073 100644 --- a/Chan.cpp +++ b/Chan.cpp @@ -128,18 +128,18 @@ void CChan::JoinUser(bool bForce, const CString& sKey, CClient* pClient) { else pThisClient = pClient; - for (map::iterator a = m_msNicks.begin(); a != m_msNicks.end(); ++a) { + for (map::iterator a = m_msNicks.begin(); a != m_msNicks.end(); ++a) { if (pThisClient->HasNamesx()) { - sPerm = a->second->GetPermStr(); + sPerm = a->second.GetPermStr(); } else { - char c = a->second->GetPermChar(); + char c = a->second.GetPermChar(); sPerm = ""; if (c != '\0') { sPerm += c; } } - if (pThisClient->HasUHNames() && !a->second->GetIdent().empty() && !a->second->GetHost().empty()) { - sNick = a->first + "!" + a->second->GetIdent() + "@" + a->second->GetHost(); + if (pThisClient->HasUHNames() && !a->second.GetIdent().empty() && !a->second.GetHost().empty()) { + sNick = a->first + "!" + a->second.GetIdent() + "@" + a->second.GetHost(); } else { sNick = a->first; } @@ -369,10 +369,6 @@ CString CChan::GetModeArg(CString& sArgs) const { } void CChan::ClearNicks() { - for (map::iterator a = m_msNicks.begin(); a != m_msNicks.end(); ++a) { - delete a->second; - } - m_msNicks.clear(); } @@ -434,7 +430,7 @@ bool CChan::AddNick(const CString& sNick) { } } - m_msNicks[pNick->GetNick()] = pNick; + m_msNicks[pNick->GetNick()] = *pNick; return true; } @@ -442,9 +438,9 @@ bool CChan::AddNick(const CString& sNick) { map CChan::GetPermCounts() const { map mRet; - map::const_iterator it; + map::const_iterator it; for (it = m_msNicks.begin(); it != m_msNicks.end(); ++it) { - CString sPerms = it->second->GetPermStr(); + CString sPerms = it->second.GetPermStr(); for (unsigned int p = 0; p < sPerms.size(); p++) { mRet[sPerms[p]]++; @@ -455,7 +451,7 @@ map CChan::GetPermCounts() const { } bool CChan::RemNick(const CString& sNick) { - map::iterator it; + map::iterator it; set::iterator it2; it = m_msNicks.find(sNick); @@ -463,21 +459,20 @@ bool CChan::RemNick(const CString& sNick) { return false; } - delete it->second; m_msNicks.erase(it); return true; } bool CChan::ChangeNick(const CString& sOldNick, const CString& sNewNick) { - map::iterator it = m_msNicks.find(sOldNick); + map::iterator it = m_msNicks.find(sOldNick); if (it == m_msNicks.end()) { return false; } // Rename this nick - it->second->SetNick(sNewNick); + it->second.SetNick(sNewNick); // Insert a new element into the map then erase the old one, do this to change the key to the new nick m_msNicks[sNewNick] = it->second; @@ -486,9 +481,14 @@ bool CChan::ChangeNick(const CString& sOldNick, const CString& sNewNick) { return true; } -CNick* CChan::FindNick(const CString& sNick) const { - map::const_iterator it = m_msNicks.find(sNick); - return (it != m_msNicks.end()) ? it->second : NULL; +const CNick* CChan::FindNick(const CString& sNick) const { + map::const_iterator it = m_msNicks.find(sNick); + return (it != m_msNicks.end()) ? &it->second : NULL; +} + +CNick* CChan::FindNick(const CString& sNick) { + map::iterator it = m_msNicks.find(sNick); + return (it != m_msNicks.end()) ? &it->second : NULL; } int CChan::AddBuffer(const CString& sLine) { diff --git a/Chan.h b/Chan.h index 1ecb765c..87b60bb2 100644 --- a/Chan.h +++ b/Chan.h @@ -75,7 +75,8 @@ public: // Nicks void ClearNicks(); - CNick* FindNick(const CString& sNick) const; + const CNick* FindNick(const CString& sNick) const; + CNick* FindNick(const CString& sNick); int AddNicks(const CString& sNicks); bool AddNick(const CString& sNick); bool RemNick(const CString& sNick); @@ -127,7 +128,7 @@ public: unsigned int GetTopicDate() const { return m_ulTopicDate; } const CString& GetDefaultModes() const { return m_sDefaultModes; } const vector& GetBuffer() const { return m_vsBuffer; } - const map& GetNicks() const { return m_msNicks; } + const map& GetNicks() const { return m_msNicks; } unsigned int GetNickCount() const { return m_msNicks.size(); } unsigned int GetBufferCount() const { return m_uBufferCount; } bool KeepBuffer() const { return m_bKeepBuffer; } @@ -154,7 +155,7 @@ protected: CNick m_Nick; unsigned int m_uJoinTries; CString m_sDefaultModes; - map m_msNicks; // Todo: make this caseless (irc style) + map m_msNicks; // Todo: make this caseless (irc style) unsigned int m_uBufferCount; vector m_vsBuffer; diff --git a/ClientCommand.cpp b/ClientCommand.cpp index 0dda5ab0..0d0e0f79 100644 --- a/ClientCommand.cpp +++ b/ClientCommand.cpp @@ -51,7 +51,7 @@ void CClient::UserCommand(CString& sLine) { return; } - const map& msNicks = pChan->GetNicks(); + const map& msNicks = pChan->GetNicks(); CIRCSock* pIRCSock = m_pUser->GetIRCSock(); const CString& sPerms = (pIRCSock) ? pIRCSock->GetPerms() : ""; @@ -72,20 +72,20 @@ void CClient::UserCommand(CString& sLine) { Table.AddColumn("Ident"); Table.AddColumn("Host"); - for (map::const_iterator a = msNicks.begin(); a != msNicks.end(); ++a) { + for (map::const_iterator a = msNicks.begin(); a != msNicks.end(); ++a) { Table.AddRow(); for (unsigned int b = 0; b < sPerms.size(); b++) { - if (a->second->HasPerm(sPerms[b])) { + if (a->second.HasPerm(sPerms[b])) { CString sPerm; sPerm += sPerms[b]; Table.SetCell(sPerm, sPerm); } } - Table.SetCell("Nick", a->second->GetNick()); - Table.SetCell("Ident", a->second->GetIdent()); - Table.SetCell("Host", a->second->GetHost()); + Table.SetCell("Nick", a->second.GetNick()); + Table.SetCell("Ident", a->second.GetIdent()); + Table.SetCell("Host", a->second.GetHost()); } PutStatus(Table); diff --git a/Nick.cpp b/Nick.cpp index 16823d21..e135c0f0 100644 --- a/Nick.cpp +++ b/Nick.cpp @@ -55,9 +55,9 @@ unsigned int CNick::GetCommonChans(vector& vRetChans, CUser* pUser) cons for (unsigned int a = 0; a < vChans.size(); a++) { CChan* pChan = vChans[a]; - const map& msNicks = pChan->GetNicks(); + const map& msNicks = pChan->GetNicks(); - for (map::const_iterator it = msNicks.begin(); it != msNicks.end(); ++it) { + for (map::const_iterator it = msNicks.begin(); it != msNicks.end(); ++it) { if (it->first.Equals(m_sNick)) { vRetChans.push_back(pChan); continue; diff --git a/modules/autocycle.cpp b/modules/autocycle.cpp index f7e5bfff..b018e704 100644 --- a/modules/autocycle.cpp +++ b/modules/autocycle.cpp @@ -124,8 +124,8 @@ protected: return; // Is that person us and we don't have op? - const CNick* pNick = Channel.GetNicks().begin()->second; - if (!pNick->HasPerm(CChan::Op) && pNick->GetNick().Equals(m_pUser->GetCurNick())) + const CNick& pNick = Channel.GetNicks().begin()->second; + if (!pNick.HasPerm(CChan::Op) && pNick.GetNick().Equals(m_pUser->GetCurNick())) Channel.Cycle(); } diff --git a/modules/autoop.cpp b/modules/autoop.cpp index 784ce074..e0f5eaec 100644 --- a/modules/autoop.cpp +++ b/modules/autoop.cpp @@ -352,7 +352,7 @@ public: for (size_t a = 0; a < Chans.size(); a++) { const CChan& Chan = *Chans[a]; - CNick* pNick = Chan.FindNick(Nick.GetNick()); + const CNick* pNick = Chan.FindNick(Nick.GetNick()); if (pNick) { if (pNick->HasPerm(CChan::Op) && pUser->ChannelMatches(Chan.GetName())) { @@ -446,7 +446,7 @@ public: const CChan& Chan = *Chans[a]; if (Chan.HasPerm(CChan::Op) && User.ChannelMatches(Chan.GetName())) { - CNick* pNick = Chan.FindNick(Nick.GetNick()); + const CNick* pNick = Chan.FindNick(Nick.GetNick()); if (pNick && !pNick->HasPerm(CChan::Op)) { PutIRC("MODE " + Chan.GetName() + " +o " + Nick.GetNick()); diff --git a/modules/extra/modtcl.cpp b/modules/extra/modtcl.cpp index 7150a256..3169c8a5 100644 --- a/modules/extra/modtcl.cpp +++ b/modules/extra/modtcl.cpp @@ -302,9 +302,9 @@ private: return TCL_ERROR; } - const map& msNicks = pChannel->GetNicks(); - for (map::const_iterator it = msNicks.begin(); it != msNicks.end(); ++it) { - const CNick& Nick = *it->second; + const map& msNicks = pChannel->GetNicks(); + for (map::const_iterator it = msNicks.begin(); it != msNicks.end(); ++it) { + const CNick& Nick = it->second; l[0] = (Nick.GetNick()).c_str(); l[1] = (Nick.GetIdent()).c_str(); l[2] = (Nick.GetHost()).c_str();