mirror of
https://github.com/znc/znc.git
synced 2026-08-06 17:03:14 +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:
+102
-102
@@ -21,135 +21,135 @@ using std::set;
|
||||
|
||||
class CClientNotifyMod : public CModule {
|
||||
protected:
|
||||
CString m_sMethod;
|
||||
bool m_bNewOnly{};
|
||||
bool m_bOnDisconnect{};
|
||||
CString m_sMethod;
|
||||
bool m_bNewOnly{};
|
||||
bool m_bOnDisconnect{};
|
||||
|
||||
set<CString> m_sClientsSeen;
|
||||
set<CString> m_sClientsSeen;
|
||||
|
||||
void SaveSettings() {
|
||||
SetNV("method", m_sMethod);
|
||||
SetNV("newonly", m_bNewOnly ? "1" : "0");
|
||||
SetNV("ondisconnect", m_bOnDisconnect ? "1" : "0");
|
||||
}
|
||||
void SaveSettings() {
|
||||
SetNV("method", m_sMethod);
|
||||
SetNV("newonly", m_bNewOnly ? "1" : "0");
|
||||
SetNV("ondisconnect", m_bOnDisconnect ? "1" : "0");
|
||||
}
|
||||
|
||||
void SendNotification(const CString& sMessage) {
|
||||
if (m_sMethod == "message") {
|
||||
GetUser()->PutStatus(sMessage, nullptr, GetClient());
|
||||
} else if (m_sMethod == "notice") {
|
||||
GetUser()->PutStatusNotice(sMessage, nullptr, GetClient());
|
||||
}
|
||||
}
|
||||
void SendNotification(const CString& sMessage) {
|
||||
if (m_sMethod == "message") {
|
||||
GetUser()->PutStatus(sMessage, nullptr, GetClient());
|
||||
} else if (m_sMethod == "notice") {
|
||||
GetUser()->PutStatusNotice(sMessage, nullptr, GetClient());
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
MODCONSTRUCTOR(CClientNotifyMod) {
|
||||
AddHelpCommand();
|
||||
AddCommand("Method", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CClientNotifyMod::OnMethodCommand),
|
||||
"<message|notice|off>", "Sets the notify method");
|
||||
AddCommand("NewOnly", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CClientNotifyMod::OnNewOnlyCommand),
|
||||
"<on|off>",
|
||||
"Turns notifications for unseen IP addresses on or off");
|
||||
AddCommand("OnDisconnect", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CClientNotifyMod::OnDisconnectCommand),
|
||||
"<on|off>",
|
||||
"Turns notifications for clients disconnecting on or off");
|
||||
AddCommand("Show", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CClientNotifyMod::OnShowCommand),
|
||||
"", "Show the current settings");
|
||||
}
|
||||
MODCONSTRUCTOR(CClientNotifyMod) {
|
||||
AddHelpCommand();
|
||||
AddCommand("Method", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CClientNotifyMod::OnMethodCommand),
|
||||
"<message|notice|off>", "Sets the notify method");
|
||||
AddCommand("NewOnly", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CClientNotifyMod::OnNewOnlyCommand),
|
||||
"<on|off>",
|
||||
"Turns notifications for unseen IP addresses on or off");
|
||||
AddCommand("OnDisconnect", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CClientNotifyMod::OnDisconnectCommand),
|
||||
"<on|off>",
|
||||
"Turns notifications for clients disconnecting on or off");
|
||||
AddCommand("Show", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CClientNotifyMod::OnShowCommand),
|
||||
"", "Show the current settings");
|
||||
}
|
||||
|
||||
bool OnLoad(const CString& sArgs, CString& sMessage) override {
|
||||
m_sMethod = GetNV("method");
|
||||
bool OnLoad(const CString& sArgs, CString& sMessage) override {
|
||||
m_sMethod = GetNV("method");
|
||||
|
||||
if (m_sMethod != "notice" && m_sMethod != "message" &&
|
||||
m_sMethod != "off") {
|
||||
m_sMethod = "message";
|
||||
}
|
||||
if (m_sMethod != "notice" && m_sMethod != "message" &&
|
||||
m_sMethod != "off") {
|
||||
m_sMethod = "message";
|
||||
}
|
||||
|
||||
// default = off for these:
|
||||
// default = off for these:
|
||||
|
||||
m_bNewOnly = (GetNV("newonly") == "1");
|
||||
m_bOnDisconnect = (GetNV("ondisconnect") == "1");
|
||||
m_bNewOnly = (GetNV("newonly") == "1");
|
||||
m_bOnDisconnect = (GetNV("ondisconnect") == "1");
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnClientLogin() override {
|
||||
CString sRemoteIP = GetClient()->GetRemoteIP();
|
||||
if (!m_bNewOnly ||
|
||||
m_sClientsSeen.find(sRemoteIP) == m_sClientsSeen.end()) {
|
||||
SendNotification(
|
||||
"Another client authenticated as your user. "
|
||||
"Use the 'ListClients' command to see all " +
|
||||
CString(GetUser()->GetAllClients().size()) + " clients.");
|
||||
void OnClientLogin() override {
|
||||
CString sRemoteIP = GetClient()->GetRemoteIP();
|
||||
if (!m_bNewOnly ||
|
||||
m_sClientsSeen.find(sRemoteIP) == m_sClientsSeen.end()) {
|
||||
SendNotification(
|
||||
"Another client authenticated as your user. "
|
||||
"Use the 'ListClients' command to see all " +
|
||||
CString(GetUser()->GetAllClients().size()) + " clients.");
|
||||
|
||||
// the set<> will automatically disregard duplicates:
|
||||
m_sClientsSeen.insert(sRemoteIP);
|
||||
}
|
||||
}
|
||||
// the set<> will automatically disregard duplicates:
|
||||
m_sClientsSeen.insert(sRemoteIP);
|
||||
}
|
||||
}
|
||||
|
||||
void OnClientDisconnect() override {
|
||||
if (m_bOnDisconnect) {
|
||||
SendNotification(
|
||||
"A client disconnected from your user. "
|
||||
"Use the 'ListClients' command to see the " +
|
||||
CString(GetUser()->GetAllClients().size()) +
|
||||
" remaining client(s).");
|
||||
}
|
||||
}
|
||||
void OnClientDisconnect() override {
|
||||
if (m_bOnDisconnect) {
|
||||
SendNotification(
|
||||
"A client disconnected from your user. "
|
||||
"Use the 'ListClients' command to see the " +
|
||||
CString(GetUser()->GetAllClients().size()) +
|
||||
" remaining client(s).");
|
||||
}
|
||||
}
|
||||
|
||||
void OnMethodCommand(const CString& sCommand) {
|
||||
const CString& sArg = sCommand.Token(1, true).AsLower();
|
||||
void OnMethodCommand(const CString& sCommand) {
|
||||
const CString& sArg = sCommand.Token(1, true).AsLower();
|
||||
|
||||
if (sArg != "notice" && sArg != "message" && sArg != "off") {
|
||||
PutModule("Usage: Method <message|notice|off>");
|
||||
return;
|
||||
}
|
||||
if (sArg != "notice" && sArg != "message" && sArg != "off") {
|
||||
PutModule("Usage: Method <message|notice|off>");
|
||||
return;
|
||||
}
|
||||
|
||||
m_sMethod = sArg;
|
||||
SaveSettings();
|
||||
PutModule("Saved.");
|
||||
}
|
||||
m_sMethod = sArg;
|
||||
SaveSettings();
|
||||
PutModule("Saved.");
|
||||
}
|
||||
|
||||
void OnNewOnlyCommand(const CString& sCommand) {
|
||||
const CString& sArg = sCommand.Token(1, true).AsLower();
|
||||
void OnNewOnlyCommand(const CString& sCommand) {
|
||||
const CString& sArg = sCommand.Token(1, true).AsLower();
|
||||
|
||||
if (sArg.empty()) {
|
||||
PutModule("Usage: NewOnly <on|off>");
|
||||
return;
|
||||
}
|
||||
if (sArg.empty()) {
|
||||
PutModule("Usage: NewOnly <on|off>");
|
||||
return;
|
||||
}
|
||||
|
||||
m_bNewOnly = sArg.ToBool();
|
||||
SaveSettings();
|
||||
PutModule("Saved.");
|
||||
}
|
||||
m_bNewOnly = sArg.ToBool();
|
||||
SaveSettings();
|
||||
PutModule("Saved.");
|
||||
}
|
||||
|
||||
void OnDisconnectCommand(const CString& sCommand) {
|
||||
const CString& sArg = sCommand.Token(1, true).AsLower();
|
||||
void OnDisconnectCommand(const CString& sCommand) {
|
||||
const CString& sArg = sCommand.Token(1, true).AsLower();
|
||||
|
||||
if (sArg.empty()) {
|
||||
PutModule("Usage: OnDisconnect <on|off>");
|
||||
return;
|
||||
}
|
||||
if (sArg.empty()) {
|
||||
PutModule("Usage: OnDisconnect <on|off>");
|
||||
return;
|
||||
}
|
||||
|
||||
m_bOnDisconnect = sArg.ToBool();
|
||||
SaveSettings();
|
||||
PutModule("Saved.");
|
||||
}
|
||||
m_bOnDisconnect = sArg.ToBool();
|
||||
SaveSettings();
|
||||
PutModule("Saved.");
|
||||
}
|
||||
|
||||
void OnShowCommand(const CString& sLine) {
|
||||
PutModule("Current settings: Method: " + m_sMethod +
|
||||
", for unseen IP addresses only: " + CString(m_bNewOnly) +
|
||||
", notify on disconnecting clients: " +
|
||||
CString(m_bOnDisconnect));
|
||||
}
|
||||
void OnShowCommand(const CString& sLine) {
|
||||
PutModule("Current settings: Method: " + m_sMethod +
|
||||
", for unseen IP addresses only: " + CString(m_bNewOnly) +
|
||||
", notify on disconnecting clients: " +
|
||||
CString(m_bOnDisconnect));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
void TModInfo<CClientNotifyMod>(CModInfo& Info) {
|
||||
Info.SetWikiPage("clientnotify");
|
||||
Info.SetWikiPage("clientnotify");
|
||||
}
|
||||
|
||||
USERMODULEDEFS(CClientNotifyMod,
|
||||
|
||||
Reference in New Issue
Block a user