mirror of
https://github.com/znc/znc.git
synced 2026-08-08 09:52:55 +02:00
clang-format: switch tabs to spaces
I like tabs, but I have to admit that spaces make source code more consistent, because every editor/viewer tends to render tabs differently :(
This commit is contained in:
+91
-91
@@ -24,127 +24,127 @@ using std::multimap;
|
||||
|
||||
class CLastSeenMod : public CModule {
|
||||
private:
|
||||
time_t GetTime(const CUser* pUser) {
|
||||
return GetNV(pUser->GetUserName()).ToULong();
|
||||
}
|
||||
time_t GetTime(const CUser* pUser) {
|
||||
return GetNV(pUser->GetUserName()).ToULong();
|
||||
}
|
||||
|
||||
void SetTime(const CUser* pUser) {
|
||||
SetNV(pUser->GetUserName(), CString(time(nullptr)));
|
||||
}
|
||||
void SetTime(const CUser* pUser) {
|
||||
SetNV(pUser->GetUserName(), CString(time(nullptr)));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
typedef multimap<time_t, CUser*> MTimeMulti;
|
||||
typedef map<CString, CUser*> MUsers;
|
||||
|
||||
void ShowCommand(const CString& sLine) {
|
||||
if (!GetUser()->IsAdmin()) {
|
||||
PutModule("Access denied");
|
||||
return;
|
||||
}
|
||||
void ShowCommand(const CString& sLine) {
|
||||
if (!GetUser()->IsAdmin()) {
|
||||
PutModule("Access denied");
|
||||
return;
|
||||
}
|
||||
|
||||
const MUsers& mUsers = CZNC::Get().GetUserMap();
|
||||
MUsers::const_iterator it;
|
||||
CTable Table;
|
||||
const MUsers& mUsers = CZNC::Get().GetUserMap();
|
||||
MUsers::const_iterator it;
|
||||
CTable Table;
|
||||
|
||||
Table.AddColumn("User");
|
||||
Table.AddColumn("Last Seen");
|
||||
Table.AddColumn("User");
|
||||
Table.AddColumn("Last Seen");
|
||||
|
||||
for (it = mUsers.begin(); it != mUsers.end(); ++it) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("User", it->first);
|
||||
Table.SetCell("Last Seen", FormatLastSeen(it->second, "never"));
|
||||
}
|
||||
for (it = mUsers.begin(); it != mUsers.end(); ++it) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("User", it->first);
|
||||
Table.SetCell("Last Seen", FormatLastSeen(it->second, "never"));
|
||||
}
|
||||
|
||||
PutModule(Table);
|
||||
}
|
||||
PutModule(Table);
|
||||
}
|
||||
|
||||
public:
|
||||
MODCONSTRUCTOR(CLastSeenMod) {
|
||||
AddHelpCommand();
|
||||
AddCommand("Show", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CLastSeenMod::ShowCommand),
|
||||
"", "Shows list of users and when they last logged in");
|
||||
}
|
||||
MODCONSTRUCTOR(CLastSeenMod) {
|
||||
AddHelpCommand();
|
||||
AddCommand("Show", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CLastSeenMod::ShowCommand),
|
||||
"", "Shows list of users and when they last logged in");
|
||||
}
|
||||
|
||||
virtual ~CLastSeenMod() {}
|
||||
virtual ~CLastSeenMod() {}
|
||||
|
||||
// Event stuff:
|
||||
// Event stuff:
|
||||
|
||||
void OnClientLogin() override { SetTime(GetUser()); }
|
||||
void OnClientLogin() override { SetTime(GetUser()); }
|
||||
|
||||
void OnClientDisconnect() override { SetTime(GetUser()); }
|
||||
void OnClientDisconnect() override { SetTime(GetUser()); }
|
||||
|
||||
EModRet OnDeleteUser(CUser& User) override {
|
||||
DelNV(User.GetUserName());
|
||||
return CONTINUE;
|
||||
}
|
||||
EModRet OnDeleteUser(CUser& User) override {
|
||||
DelNV(User.GetUserName());
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
// Web stuff:
|
||||
// Web stuff:
|
||||
|
||||
bool WebRequiresAdmin() override { return true; }
|
||||
CString GetWebMenuTitle() override { return "Last Seen"; }
|
||||
bool WebRequiresAdmin() override { return true; }
|
||||
CString GetWebMenuTitle() override { return "Last Seen"; }
|
||||
|
||||
bool OnWebRequest(CWebSock& WebSock, const CString& sPageName,
|
||||
CTemplate& Tmpl) override {
|
||||
if (sPageName == "index") {
|
||||
CModules& GModules = CZNC::Get().GetModules();
|
||||
Tmpl["WebAdminLoaded"] =
|
||||
CString(GModules.FindModule("webadmin") != nullptr);
|
||||
bool OnWebRequest(CWebSock& WebSock, const CString& sPageName,
|
||||
CTemplate& Tmpl) override {
|
||||
if (sPageName == "index") {
|
||||
CModules& GModules = CZNC::Get().GetModules();
|
||||
Tmpl["WebAdminLoaded"] =
|
||||
CString(GModules.FindModule("webadmin") != nullptr);
|
||||
|
||||
MTimeMulti mmSorted;
|
||||
const MUsers& mUsers = CZNC::Get().GetUserMap();
|
||||
MTimeMulti mmSorted;
|
||||
const MUsers& mUsers = CZNC::Get().GetUserMap();
|
||||
|
||||
for (MUsers::const_iterator uit = mUsers.begin();
|
||||
uit != mUsers.end(); ++uit) {
|
||||
mmSorted.insert(
|
||||
pair<time_t, CUser*>(GetTime(uit->second), uit->second));
|
||||
}
|
||||
for (MUsers::const_iterator uit = mUsers.begin();
|
||||
uit != mUsers.end(); ++uit) {
|
||||
mmSorted.insert(
|
||||
pair<time_t, CUser*>(GetTime(uit->second), uit->second));
|
||||
}
|
||||
|
||||
for (MTimeMulti::const_iterator it = mmSorted.begin();
|
||||
it != mmSorted.end(); ++it) {
|
||||
CUser* pUser = it->second;
|
||||
CTemplate& Row = Tmpl.AddRow("UserLoop");
|
||||
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");
|
||||
}
|
||||
Row["Username"] = pUser->GetUserName();
|
||||
Row["IsSelf"] =
|
||||
CString(pUser == WebSock.GetSession()->GetUser());
|
||||
Row["LastSeen"] = FormatLastSeen(pUser, "never");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OnEmbeddedWebRequest(CWebSock& WebSock, const CString& sPageName,
|
||||
CTemplate& Tmpl) override {
|
||||
if (sPageName == "webadmin/user" && WebSock.GetSession()->IsAdmin()) {
|
||||
CUser* pUser = CZNC::Get().FindUser(Tmpl["Username"]);
|
||||
if (pUser) {
|
||||
Tmpl["LastSeen"] = FormatLastSeen(pUser);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool OnEmbeddedWebRequest(CWebSock& WebSock, const CString& sPageName,
|
||||
CTemplate& Tmpl) override {
|
||||
if (sPageName == "webadmin/user" && WebSock.GetSession()->IsAdmin()) {
|
||||
CUser* pUser = CZNC::Get().FindUser(Tmpl["Username"]);
|
||||
if (pUser) {
|
||||
Tmpl["LastSeen"] = FormatLastSeen(pUser);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
void TModInfo<CLastSeenMod>(CModInfo& Info) {
|
||||
Info.SetWikiPage("lastseen");
|
||||
Info.SetWikiPage("lastseen");
|
||||
}
|
||||
|
||||
GLOBALMODULEDEFS(CLastSeenMod,
|
||||
|
||||
Reference in New Issue
Block a user