From: <cf...@us...> - 2010-10-23 11:46:21
|
Revision: 2163 http://znc.svn.sourceforge.net/znc/?rev=2163&view=rev Author: cflakes Date: 2010-10-23 11:46:15 +0000 (Sat, 23 Oct 2010) Log Message: ----------- lastseen module: minor code improvements: moved strftime business into a separate method. Modified Paths: -------------- trunk/modules/lastseen.cpp Modified: trunk/modules/lastseen.cpp =================================================================== --- trunk/modules/lastseen.cpp 2010-10-21 17:27:19 UTC (rev 2162) +++ trunk/modules/lastseen.cpp 2010-10-23 11:46:15 UTC (rev 2163) @@ -24,6 +24,17 @@ SetNV(pUser->GetUserName(), CString(time(NULL))); } + const CString FormatLastSeen(const CUser *pUser, const char* sDefault = "") { + time_t last = GetTime(pUser); + if (last < 1) { + return sDefault; + } else { + char buf[1024]; + strftime(buf, sizeof(buf) - 1, "%c", localtime(&last)); + return buf; + } + } + typedef multimap<time_t, CUser*> MTimeMulti; typedef map<CString, CUser*> MUsers; public: @@ -43,7 +54,6 @@ } if (sCommand == "show") { - char buf[1024]; const MUsers& mUsers = CZNC::Get().GetUserMap(); MUsers::const_iterator it; CTable Table; @@ -52,18 +62,9 @@ Table.AddColumn("Last Seen"); for (it = mUsers.begin(); it != mUsers.end(); ++it) { - CUser *pUser = it->second; - time_t last = GetTime(pUser); - Table.AddRow(); Table.SetCell("User", it->first); - - if (last == 0) - Table.SetCell("Last Seen", "never"); - else { - strftime(buf, sizeof(buf), "%c", localtime(&last)); - Table.SetCell("Last Seen", buf); - } + Table.SetCell("Last Seen", FormatLastSeen(it->second)); } PutModule(Table); @@ -103,7 +104,7 @@ } } } - + MTimeMulti mmSorted; const MUsers& mUsers = CZNC::Get().GetUserMap(); @@ -111,20 +112,14 @@ mmSorted.insert(pair<time_t, CUser*>(GetTime(uit->second), uit->second)); } - char buf[1024] = {0}; - for (MTimeMulti::const_iterator it = mmSorted.begin(); it != mmSorted.end(); ++it) { CUser *pUser = it->second; CTemplate& Row = Tmpl.AddRow("UserLoop"); Row["Username"] = pUser->GetUserName(); Row["IsSelf"] = CString(pUser == WebSock.GetSession()->GetUser()); + Row["LastSeen"] = FormatLastSeen(pUser, "never"); - if(it->first > 0) { - strftime(buf, sizeof(buf), "%c", localtime(&it->first)); - Row["LastSeen"] = buf; - } - Row["Info"] = CString(pUser->GetClients().size()) + " client" + CString(pUser->GetClients().size() == 1 ? "" : "s"); if(!pUser->GetCurrentServer()) { @@ -144,7 +139,7 @@ Row["Info"] += " channel" + CString(n == 1 ? "" : "s"); } } - + return true; } @@ -155,12 +150,7 @@ if (sPageName == "webadmin/user" && WebSock.GetSession()->IsAdmin()) { CUser* pUser = CZNC::Get().FindUser(Tmpl["Username"]); if (pUser) { - time_t last = GetTime(pUser); - if (last) { - char buf[1024] = {0}; - strftime(buf, sizeof(buf), "%c", localtime(&last)); - Tmpl["LastSeen"] = buf; - } + Tmpl["LastSeen"] = FormatLastSeen(pUser); } return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |