From fd92e65b7091ade454dd6909a083e944cdec707c Mon Sep 17 00:00:00 2001 From: psychon Date: Sun, 28 Sep 2008 12:05:49 +0000 Subject: [PATCH] Add CClient::PutStatus(const CTable&) and use it everywhere git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1222 726aef4b-f618-498e-8847-2d620e286838 --- Client.cpp | 8 ++++ Client.h | 1 + ClientCommand.cpp | 103 ++++++---------------------------------------- Modules.cpp | 18 +------- 4 files changed, 24 insertions(+), 106 deletions(-) diff --git a/Client.cpp b/Client.cpp index 9258cd87..e39a89da 100644 --- a/Client.cpp +++ b/Client.cpp @@ -717,6 +717,14 @@ void CClient::PutStatusNotice(const CString& sLine) { PutModNotice("status", sLine); } +unsigned int CClient::PutStatus(const CTable& table) { + unsigned int idx = 0; + CString sLine; + while (table.GetLine(idx++, sLine)) + PutStatus(sLine); + return idx - 1; +} + void CClient::PutStatus(const CString& sLine) { PutModule("status", sLine); } diff --git a/Client.h b/Client.h index a6e8271f..20813233 100644 --- a/Client.h +++ b/Client.h @@ -100,6 +100,7 @@ public: void PutIRC(const CString& sLine); void PutClient(const CString& sLine); + unsigned int PutStatus(const CTable& table); void PutStatus(const CString& sLine); void PutStatusNotice(const CString& sLine); void PutModule(const CString& sModule, const CString& sLine); diff --git a/ClientCommand.cpp b/ClientCommand.cpp index 2a063a9b..c7d0bf81 100644 --- a/ClientCommand.cpp +++ b/ClientCommand.cpp @@ -85,12 +85,7 @@ void CClient::UserCommand(const CString& sLine) { Table.SetCell("Host", a->second->GetHost()); } - unsigned int uTableIdx = 0; - CString sTmp; - - while (Table.GetLine(uTableIdx++, sTmp)) { - PutStatus(sTmp); - } + PutStatus(Table); } else if (sCommand.CaseCmp("DETACH") == 0) { if (m_pUser) { CString sChan = sLine.Token(1); @@ -163,14 +158,7 @@ void CClient::UserCommand(const CString& sLine) { Table.SetCell("Host", vClients[a]->GetRemoteIP()); } - if (Table.size()) { - unsigned int uTableIdx = 0; - CString sTmp; - - while (Table.GetLine(uTableIdx++, sTmp)) { - PutStatus(sTmp); - } - } + PutStatus(Table); } } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("LISTUSERS") == 0) { const map& msUsers = CZNC::Get().GetUserMap(); @@ -194,14 +182,7 @@ void CClient::UserCommand(const CString& sLine) { } } - if (Table.size()) { - unsigned int uTableIdx = 0; - CString sTmp; - - while (Table.GetLine(uTableIdx++, sTmp)) { - PutStatus(sTmp); - } - } + PutStatus(Table); } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("SetMOTD") == 0) { CString sMessage = sLine.Token(1, true); @@ -341,14 +322,7 @@ void CClient::UserCommand(const CString& sLine) { } } - if (Table.size()) { - unsigned int uTableIdx = 0; - CString sTmp; - - while (Table.GetLine(uTableIdx++, sTmp)) { - PutStatus(sTmp); - } - } + PutStatus(Table); } } else if (sCommand.CaseCmp("ADDSERVER") == 0) { CString sServer = sLine.Token(1); @@ -407,14 +381,7 @@ void CClient::UserCommand(const CString& sLine) { Table.SetCell("Pass", pServer->GetPass()); } - if (Table.size()) { - unsigned int uTableIdx = 0; - CString sTmp; - - while (Table.GetLine(uTableIdx++, sTmp)) { - PutStatus(sTmp); - } - } + PutStatus(Table); } else { PutStatus("You don't have any servers added."); } @@ -435,14 +402,7 @@ void CClient::UserCommand(const CString& sLine) { Table.SetCell("Topic", pChan->GetTopic()); } - if (Table.size()) { - unsigned int uTableIdx = 0; - CString sTmp; - - while (Table.GetLine(uTableIdx++, sTmp)) { - PutStatus(sTmp); - } - } + PutStatus(Table); } } else if (sCommand.CaseCmp("SEND") == 0) { CString sToNick = sLine.Token(1); @@ -574,14 +534,7 @@ void CClient::UserCommand(const CString& sLine) { } } - if (Table.size()) { - unsigned int uTableIdx = 0; - CString sTmp; - - while (Table.GetLine(uTableIdx++, sTmp)) { - PutStatus(sTmp); - } - } else { + if (PutStatus(Table) == 0) { PutStatus("You have no active DCCs."); } } else if ((sCommand.CaseCmp("LISTMODS") == 0) || (sCommand.CaseCmp("LISTMODULES") == 0)) { @@ -603,11 +556,7 @@ void CClient::UserCommand(const CString& sLine) { GTable.SetCell("Description", GModules[b]->GetDescription().Ellipsize(128)); } - unsigned int uTableIdx = 0; - CString sTmp; - while (GTable.GetLine(uTableIdx++, sTmp)) { - PutStatus(sTmp); - } + PutStatus(GTable); } } @@ -628,11 +577,7 @@ void CClient::UserCommand(const CString& sLine) { Table.SetCell("Description", Modules[b]->GetDescription().Ellipsize(128)); } - unsigned int uTableIdx = 0; - CString sTmp; - while (Table.GetLine(uTableIdx++, sTmp)) { - PutStatus(sTmp); - } + PutStatus(Table); } } #else @@ -666,12 +611,7 @@ void CClient::UserCommand(const CString& sLine) { GTable.SetCell("Description", Info.GetDescription().Ellipsize(128)); } - unsigned int uTableIdx = 0; - CString sTmp; - - while (GTable.GetLine(uTableIdx++, sTmp)) { - PutStatus(sTmp); - } + PutStatus(GTable); } } @@ -695,11 +635,7 @@ void CClient::UserCommand(const CString& sLine) { Table.SetCell("Description", Info.GetDescription().Ellipsize(128)); } - unsigned int uTableIdx = 0; - CString sTmp; - while (Table.GetLine(uTableIdx++, sTmp)) { - PutStatus(sTmp); - } + PutStatus(Table); } } #else @@ -972,13 +908,7 @@ void CClient::UserCommand(const CString& sLine) { Table.SetCell("Out", CString::ToByteStr(users_total_out + CZNC::Get().BytesWritten())); Table.SetCell("Total", CString::ToByteStr(users_total_in + CZNC::Get().BytesRead() + users_total_out + CZNC::Get().BytesWritten())); - if (Table.size()) { - unsigned int uTableIdx = 0; - CString sTmp; - while (Table.GetLine(uTableIdx++, sTmp)) { - PutStatus(sTmp); - } - } + PutStatus(Table); } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("UPTIME") == 0) { PutStatus("Running for " + CZNC::Get().GetUptime()); } else { @@ -1200,12 +1130,5 @@ void CClient::HelpUser() { Table.SetCell("Description", "Restarts znc"); } - if (Table.size()) { - unsigned int uTableIdx = 0; - CString sLine; - - while (Table.GetLine(uTableIdx++, sLine)) { - PutStatus(sLine); - } - } + PutStatus(Table); } diff --git a/Modules.cpp b/Modules.cpp index de22a27c..6469b48c 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -333,14 +333,7 @@ void CModule::ListTimers() { Table.SetCell("Description", pTimer->GetDescription()); } - if (Table.size()) { - unsigned int uTableIdx = 0; - CString sLine; - - while (Table.GetLine(uTableIdx++, sLine)) { - PutModule(sLine); - } - } + PutModule(Table); } bool CModule::AddSocket(CSocket* pSocket) { @@ -432,14 +425,7 @@ void CModule::ListSockets() { Table.SetCell("RemotePort", (pSocket->GetRemotePort()) ? CString(pSocket->GetRemotePort()) : CString("")); } - if (Table.size()) { - unsigned int uTableIdx = 0; - CString sLine; - - while (Table.GetLine(uTableIdx++, sLine)) { - PutModule(sLine); - } - } + PutModule(Table); } CString CModule::GetModNick() const { return ((m_pUser) ? m_pUser->GetStatusPrefix() : "*") + m_sModName; }