From 85dce87d6abb498b594f6123d202390ace651acf Mon Sep 17 00:00:00 2001 From: psychon Date: Wed, 27 May 2009 10:49:48 +0000 Subject: [PATCH] Traffic API breakage again The last commit broke the order in which the traffic stats used to be displayed and it turns out that KiNgMaR cannot live with that, so now we are back to the old order. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1523 726aef4b-f618-498e-8847-2d620e286838 --- ClientCommand.cpp | 25 ++++++++++++++++++++++--- znc.cpp | 14 +++++++------- znc.h | 14 ++++++++++---- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/ClientCommand.cpp b/ClientCommand.cpp index dbcaf36d..45972545 100644 --- a/ClientCommand.cpp +++ b/ClientCommand.cpp @@ -928,9 +928,10 @@ void CClient::UserCommand(const CString& sLine) { PutStatus("BufferCount for [" + sChan + "] set to [" + CString(pChan->GetBufferCount()) + "]"); } else if (m_pUser->IsAdmin() && sCommand.Equals("TRAFFIC")) { - map >::const_iterator it; - map > traffic = - CZNC::Get().GetTrafficStats(); + CZNC::TrafficStatsPair Users, ZNC, Total; + CZNC::TrafficStatsMap traffic = CZNC::Get().GetTrafficStats(Users, ZNC, Total); + CZNC::TrafficStatsMap::const_iterator it; + CTable Table; Table.AddColumn("Username"); Table.AddColumn("In"); @@ -945,6 +946,24 @@ void CClient::UserCommand(const CString& sLine) { Table.SetCell("Total", CString::ToByteStr(it->second.first + it->second.second)); } + Table.AddRow(); + Table.SetCell("Username", ""); + Table.SetCell("In", CString::ToByteStr(Users.first)); + Table.SetCell("Out", CString::ToByteStr(Users.second)); + Table.SetCell("Total", CString::ToByteStr(Users.first + Users.second)); + + Table.AddRow(); + Table.SetCell("Username", ""); + Table.SetCell("In", CString::ToByteStr(ZNC.first)); + Table.SetCell("Out", CString::ToByteStr(ZNC.second)); + Table.SetCell("Total", CString::ToByteStr(ZNC.first + ZNC.second)); + + Table.AddRow(); + Table.SetCell("Username", ""); + Table.SetCell("In", CString::ToByteStr(Total.first)); + Table.SetCell("Out", CString::ToByteStr(Total.second)); + Table.SetCell("Total", CString::ToByteStr(Total.first + Total.second)); + PutStatus(Table); } else if (m_pUser->IsAdmin() && sCommand.Equals("UPTIME")) { PutStatus("Running for " + CZNC::Get().GetUptime()); diff --git a/znc.cpp b/znc.cpp index b52b6934..48342e9b 100644 --- a/znc.cpp +++ b/znc.cpp @@ -1726,8 +1726,9 @@ CZNC& CZNC::Get() { return *pZNC; } -map > CZNC::GetTrafficStats() { - map > ret; +CZNC::TrafficStatsMap CZNC::GetTrafficStats(TrafficStatsPair &Users, + TrafficStatsPair &ZNC, TrafficStatsPair &Total) { + TrafficStatsMap ret; unsigned long long uiUsers_in, uiUsers_out, uiZNC_in, uiZNC_out; const map& msUsers = CZNC::Get().GetUserMap(); @@ -1736,8 +1737,7 @@ map > CZNC::GetTraffi uiZNC_out = BytesWritten(); for (map::const_iterator it = msUsers.begin(); it != msUsers.end(); it++) { - ret[it->first] = std::pair - (it->second->BytesRead(), it->second->BytesWritten()); + ret[it->first] = TrafficStatsPair(it->second->BytesRead(), it->second->BytesWritten()); uiUsers_in += it->second->BytesRead(); uiUsers_out += it->second->BytesWritten(); } @@ -1761,9 +1761,9 @@ map > CZNC::GetTraffi } } - ret[""] = std::pair(uiUsers_in, uiUsers_out); - ret[""] = std::pair(uiZNC_in, uiZNC_out); - ret[""] = std::pair(uiUsers_in + uiZNC_in, uiUsers_out + uiZNC_out); + Users = TrafficStatsPair(uiUsers_in, uiUsers_out); + ZNC = TrafficStatsPair(uiZNC_in, uiZNC_out); + Total = TrafficStatsPair(uiUsers_in + uiZNC_in, uiUsers_out + uiZNC_out); return ret; } diff --git a/znc.h b/znc.h index 3549cb68..5a05fad1 100644 --- a/znc.h +++ b/znc.h @@ -124,10 +124,16 @@ public: void AddBytesWritten(unsigned long long u) { m_uBytesWritten += u; } unsigned long long BytesRead() const { return m_uBytesRead; } unsigned long long BytesWritten() const { return m_uBytesWritten; } - // Returns a map which maps user names to , special - // "usernames" are (All users total), (Traffic which couldn't be - // accounted to any user) and (Total traffic, + ). - map > GetTrafficStats(); + + // Traffic fun + typedef std::pair TrafficStatsPair; + typedef std::map TrafficStatsMap; + // Returns a map which maps user names to + // while also providing the traffic of all users together, traffic which + // couldn't be accounted to any particular user and the total traffic + // generated through ZNC. + TrafficStatsMap GetTrafficStats(TrafficStatsPair &Users, + TrafficStatsPair &ZNC, TrafficStatsPair &Total); // Authenticate a user. // The result is passed back via callbacks to CAuthBase.