mirror of
https://github.com/znc/znc.git
synced 2026-08-06 17:03:14 +02:00
Merge pull request #735 from jpnurmi/modcommand
Convert most of the remaining modules to use CModCommand
This commit is contained in:
+54
-47
@@ -24,6 +24,9 @@
|
||||
class CAdminLogMod : public CModule {
|
||||
public:
|
||||
MODCONSTRUCTOR(CAdminLogMod) {
|
||||
AddHelpCommand();
|
||||
AddCommand("Show", static_cast<CModCommand::ModCmdFunc>(&CAdminLogMod::OnShowCommand), "", "Show the logging target");
|
||||
AddCommand("Target", static_cast<CModCommand::ModCmdFunc>(&CAdminLogMod::OnTargetCommand), "<file|syslog|both>", "Set the logging target");
|
||||
openlog("znc", LOG_PID, LOG_DAEMON);
|
||||
}
|
||||
|
||||
@@ -107,59 +110,63 @@ public:
|
||||
virtual void OnModCommand(const CString& sCommand) {
|
||||
if (!GetUser()->IsAdmin()) {
|
||||
PutModule("Access denied");
|
||||
} else {
|
||||
HandleCommand(sCommand);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTargetCommand(const CString& sCommand) {
|
||||
CString sArg = sCommand.Token(1, true);
|
||||
CString sTarget;
|
||||
CString sMessage;
|
||||
LogMode mode;
|
||||
|
||||
if (sArg.Equals("file")) {
|
||||
sTarget = "file";
|
||||
sMessage = "Now only logging to file";
|
||||
mode = LOG_TO_FILE;
|
||||
} else if (sArg.Equals("syslog")) {
|
||||
sTarget = "syslog";
|
||||
sMessage = "Now only logging to syslog";
|
||||
mode = LOG_TO_SYSLOG;
|
||||
} else if (sArg.Equals("both")) {
|
||||
sTarget = "both";
|
||||
sMessage = "Now logging to file and syslog";
|
||||
mode = LOG_TO_BOTH;
|
||||
} else {
|
||||
if (sArg.empty()) {
|
||||
PutModule("Usage: Target <file|syslog|both>");
|
||||
} else {
|
||||
PutModule("Unknown target");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
CString sCmd = sCommand.Token(0);
|
||||
Log(sMessage);
|
||||
SetNV("target", sTarget);
|
||||
m_eLogMode = mode;
|
||||
PutModule(sMessage);
|
||||
}
|
||||
|
||||
if (sCmd.Equals("target")) {
|
||||
CString sArg = sCommand.Token(1, true);
|
||||
CString sTarget;
|
||||
CString sMessage;
|
||||
LogMode mode;
|
||||
void OnShowCommand(const CString& sCommand) {
|
||||
CString sTarget;
|
||||
|
||||
if (sArg.Equals("file")) {
|
||||
sTarget = "file";
|
||||
sMessage = "Now only logging to file";
|
||||
mode = LOG_TO_FILE;
|
||||
} else if (sArg.Equals("syslog")) {
|
||||
sTarget = "syslog";
|
||||
sMessage = "Now only logging to syslog";
|
||||
mode = LOG_TO_SYSLOG;
|
||||
} else if (sArg.Equals("both")) {
|
||||
sTarget = "both";
|
||||
sMessage = "Now logging to file and syslog";
|
||||
mode = LOG_TO_BOTH;
|
||||
} else {
|
||||
PutModule("Unknown target");
|
||||
return;
|
||||
}
|
||||
switch (m_eLogMode)
|
||||
{
|
||||
case LOG_TO_FILE:
|
||||
sTarget = "file";
|
||||
break;
|
||||
case LOG_TO_SYSLOG:
|
||||
sTarget = "syslog";
|
||||
break;
|
||||
case LOG_TO_BOTH:
|
||||
sTarget = "both, file and syslog";
|
||||
break;
|
||||
}
|
||||
|
||||
Log(sMessage);
|
||||
SetNV("target", sTarget);
|
||||
m_eLogMode = mode;
|
||||
PutModule(sMessage);
|
||||
} else if (sCmd.Equals("show")) {
|
||||
CString sTarget;
|
||||
|
||||
switch (m_eLogMode)
|
||||
{
|
||||
case LOG_TO_FILE:
|
||||
sTarget = "file";
|
||||
break;
|
||||
case LOG_TO_SYSLOG:
|
||||
sTarget = "syslog";
|
||||
break;
|
||||
case LOG_TO_BOTH:
|
||||
sTarget = "both, file and syslog";
|
||||
break;
|
||||
}
|
||||
|
||||
PutModule("Logging is enabled for " + sTarget);
|
||||
if (m_eLogMode != LOG_TO_SYSLOG)
|
||||
PutModule("Log file will be written to [" + m_sLogFile + "]");
|
||||
} else
|
||||
PutModule("Commands: show, target <file|syslog|both>");
|
||||
PutModule("Logging is enabled for " + sTarget);
|
||||
if (m_eLogMode != LOG_TO_SYSLOG)
|
||||
PutModule("Log file will be written to [" + m_sLogFile + "]");
|
||||
}
|
||||
private:
|
||||
enum LogMode {
|
||||
|
||||
+36
-54
@@ -22,6 +22,10 @@ using std::vector;
|
||||
class CAutoCycleMod : public CModule {
|
||||
public:
|
||||
MODCONSTRUCTOR(CAutoCycleMod) {
|
||||
AddHelpCommand();
|
||||
AddCommand("Add", static_cast<CModCommand::ModCmdFunc>(&CAutoCycleMod::OnAddCommand), "[!]<#chan>", "Add an entry, use !#chan to negate and * for wildcards");
|
||||
AddCommand("Del", static_cast<CModCommand::ModCmdFunc>(&CAutoCycleMod::OnDelCommand), "[!]<#chan>", "Remove an entry, needs to be an exact match");
|
||||
AddCommand("List", static_cast<CModCommand::ModCmdFunc>(&CAutoCycleMod::OnListCommand), "", "List all entries");
|
||||
m_recentlyCycled.SetTTL(15 * 1000);
|
||||
}
|
||||
|
||||
@@ -50,67 +54,45 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void OnModCommand(const CString& sLine) {
|
||||
CString sCommand = sLine.Token(0);
|
||||
void OnAddCommand(const CString& sLine) {
|
||||
CString sChan = sLine.Token(1);
|
||||
|
||||
if (sCommand.Equals("ADD")) {
|
||||
CString sChan = sLine.Token(1);
|
||||
|
||||
if (AlreadyAdded(sChan)) {
|
||||
PutModule(sChan + " is already added");
|
||||
} else if (Add(sChan)) {
|
||||
PutModule("Added " + sChan + " to list");
|
||||
} else {
|
||||
PutModule("Usage: Add [!]<#chan>");
|
||||
}
|
||||
} else if (sCommand.Equals("DEL")) {
|
||||
CString sChan = sLine.Token(1);
|
||||
|
||||
if (Del(sChan))
|
||||
PutModule("Removed " + sChan + " from list");
|
||||
else
|
||||
PutModule("Usage: Del [!]<#chan>");
|
||||
} else if (sCommand.Equals("LIST")) {
|
||||
CTable Table;
|
||||
Table.AddColumn("Chan");
|
||||
|
||||
for (unsigned int a = 0; a < m_vsChans.size(); a++) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("Chan", m_vsChans[a]);
|
||||
}
|
||||
|
||||
for (unsigned int b = 0; b < m_vsNegChans.size(); b++) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("Chan", "!" + m_vsNegChans[b]);
|
||||
}
|
||||
|
||||
if (Table.size()) {
|
||||
PutModule(Table);
|
||||
} else {
|
||||
PutModule("You have no entries.");
|
||||
}
|
||||
if (AlreadyAdded(sChan)) {
|
||||
PutModule(sChan + " is already added");
|
||||
} else if (Add(sChan)) {
|
||||
PutModule("Added " + sChan + " to list");
|
||||
} else {
|
||||
CTable Table;
|
||||
Table.AddColumn("Command");
|
||||
Table.AddColumn("Description");
|
||||
PutModule("Usage: Add [!]<#chan>");
|
||||
}
|
||||
}
|
||||
|
||||
void OnDelCommand(const CString& sLine) {
|
||||
CString sChan = sLine.Token(1);
|
||||
|
||||
if (Del(sChan))
|
||||
PutModule("Removed " + sChan + " from list");
|
||||
else
|
||||
PutModule("Usage: Del [!]<#chan>");
|
||||
}
|
||||
|
||||
void OnListCommand(const CString& sLine) {
|
||||
CTable Table;
|
||||
Table.AddColumn("Chan");
|
||||
|
||||
for (unsigned int a = 0; a < m_vsChans.size(); a++) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("Command", "Add");
|
||||
Table.SetCell("Description", "Add an entry, use !#chan to negate and * for wildcards");
|
||||
Table.SetCell("Chan", m_vsChans[a]);
|
||||
}
|
||||
|
||||
for (unsigned int b = 0; b < m_vsNegChans.size(); b++) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("Command", "Del");
|
||||
Table.SetCell("Description", "Remove an entry, needs to be an exact match");
|
||||
Table.SetCell("Chan", "!" + m_vsNegChans[b]);
|
||||
}
|
||||
|
||||
Table.AddRow();
|
||||
Table.SetCell("Command", "List");
|
||||
Table.SetCell("Description", "List all entries");
|
||||
|
||||
if (Table.size()) {
|
||||
PutModule(Table);
|
||||
} else {
|
||||
PutModule("You have no entries.");
|
||||
}
|
||||
if (Table.size()) {
|
||||
PutModule(Table);
|
||||
} else {
|
||||
PutModule("You have no entries.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+164
-113
@@ -149,7 +149,16 @@ protected:
|
||||
|
||||
class CAutoOpMod : public CModule {
|
||||
public:
|
||||
MODCONSTRUCTOR(CAutoOpMod) {}
|
||||
MODCONSTRUCTOR(CAutoOpMod) {
|
||||
AddHelpCommand();
|
||||
AddCommand("ListUsers", static_cast<CModCommand::ModCmdFunc>(&CAutoOpMod::OnListUsersCommand), "", "List all users");
|
||||
AddCommand("AddChans", static_cast<CModCommand::ModCmdFunc>(&CAutoOpMod::OnAddChansCommand), "<user> <channel> [channel] ...", "Adds channels to a user");
|
||||
AddCommand("DelChans", static_cast<CModCommand::ModCmdFunc>(&CAutoOpMod::OnDelChansCommand), "<user> <channel> [channel] ...", "Removes channels from a user");
|
||||
AddCommand("AddMasks", static_cast<CModCommand::ModCmdFunc>(&CAutoOpMod::OnAddMasksCommand), "<user> <mask>,[mask] ...", "Adds masks to a user");
|
||||
AddCommand("DelMasks", static_cast<CModCommand::ModCmdFunc>(&CAutoOpMod::OnDelMasksCommand), "<user> <mask>,[mask] ...", "Removes masks from a user");
|
||||
AddCommand("AddUser", static_cast<CModCommand::ModCmdFunc>(&CAutoOpMod::OnAddUserCommand), "<user> <hostmask>[,<hostmasks>...] <key> [channels]", "Adds a user");
|
||||
AddCommand("DelUser", static_cast<CModCommand::ModCmdFunc>(&CAutoOpMod::OnDelUserCommand), "<user>", "Removes a user");
|
||||
}
|
||||
|
||||
virtual bool OnLoad(const CString& sArgs, CString& sMessage) {
|
||||
AddTimer(new CAutoOpTimer(this));
|
||||
@@ -229,121 +238,163 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnModCommand(const CString& sLine) {
|
||||
void OnModCommand(const CString& sLine) {
|
||||
CString sCommand = sLine.Token(0).AsUpper();
|
||||
|
||||
if (sCommand.Equals("HELP")) {
|
||||
PutModule("Commands are: ListUsers, AddChans, DelChans, AddMasks, DelMasks, AddUser, DelUser");
|
||||
} else if (sCommand.Equals("TIMERS")) {
|
||||
if (sCommand.Equals("TIMERS")) {
|
||||
// for testing purposes - hidden from help
|
||||
ListTimers();
|
||||
} else if (sCommand.Equals("ADDUSER") || sCommand.Equals("DELUSER")) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CString sHost = sLine.Token(2);
|
||||
CString sKey = sLine.Token(3);
|
||||
|
||||
if (sCommand.Equals("ADDUSER")) {
|
||||
if (sHost.empty()) {
|
||||
PutModule("Usage: " + sCommand + " <user> <hostmask>[,<hostmasks>...] <key> [channels]");
|
||||
} else {
|
||||
CAutoOpUser* pUser = AddUser(sUser, sKey, sHost, sLine.Token(4, true));
|
||||
|
||||
if (pUser) {
|
||||
SetNV(sUser, pUser->ToString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
DelUser(sUser);
|
||||
DelNV(sUser);
|
||||
}
|
||||
} else if (sCommand.Equals("LISTUSERS")) {
|
||||
if (m_msUsers.empty()) {
|
||||
PutModule("There are no users defined");
|
||||
return;
|
||||
}
|
||||
|
||||
CTable Table;
|
||||
|
||||
Table.AddColumn("User");
|
||||
Table.AddColumn("Hostmasks");
|
||||
Table.AddColumn("Key");
|
||||
Table.AddColumn("Channels");
|
||||
|
||||
for (map<CString, CAutoOpUser*>::iterator it = m_msUsers.begin(); it != m_msUsers.end(); ++it) {
|
||||
VCString vsHostmasks;
|
||||
it->second->GetHostmasks().Split(",", vsHostmasks);
|
||||
for (unsigned int a = 0; a < vsHostmasks.size(); a++) {
|
||||
Table.AddRow();
|
||||
if (a == 0) {
|
||||
Table.SetCell("User", it->second->GetUsername());
|
||||
Table.SetCell("Key", it->second->GetUserKey());
|
||||
Table.SetCell("Channels", it->second->GetChannels());
|
||||
} else if (a == vsHostmasks.size()-1) {
|
||||
Table.SetCell("User", "`-");
|
||||
} else {
|
||||
Table.SetCell("User", "|-");
|
||||
}
|
||||
Table.SetCell("Hostmasks", vsHostmasks[a]);
|
||||
}
|
||||
}
|
||||
|
||||
PutModule(Table);
|
||||
} else if (sCommand.Equals("ADDCHANS") || sCommand.Equals("DELCHANS")) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CString sChans = sLine.Token(2, true);
|
||||
|
||||
if (sChans.empty()) {
|
||||
PutModule("Usage: " + sCommand + " <user> <channel> [channel] ...");
|
||||
return;
|
||||
}
|
||||
|
||||
CAutoOpUser* pUser = FindUser(sUser);
|
||||
|
||||
if (!pUser) {
|
||||
PutModule("No such user");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sCommand.Equals("ADDCHANS")) {
|
||||
pUser->AddChans(sChans);
|
||||
PutModule("Channel(s) added to user [" + pUser->GetUsername() + "]");
|
||||
} else {
|
||||
pUser->DelChans(sChans);
|
||||
PutModule("Channel(s) Removed from user [" + pUser->GetUsername() + "]");
|
||||
}
|
||||
|
||||
SetNV(pUser->GetUsername(), pUser->ToString());
|
||||
} else if (sCommand.Equals("ADDMASKS") || sCommand.Equals("DELMASKS")) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CString sHostmasks = sLine.Token(2, true);
|
||||
|
||||
if (sHostmasks.empty()) {
|
||||
PutModule("Usage: " + sCommand + " <user> <mask>,[mask] ...");
|
||||
return;
|
||||
}
|
||||
|
||||
CAutoOpUser* pUser = FindUser(sUser);
|
||||
|
||||
if (!pUser) {
|
||||
PutModule("No such user");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sCommand.Equals("ADDMASKS")) {
|
||||
pUser->AddHostmasks(sHostmasks);
|
||||
PutModule("Hostmasks(s) added to user [" + pUser->GetUsername() + "]");
|
||||
SetNV(pUser->GetUsername(), pUser->ToString());
|
||||
} else {
|
||||
if (pUser->DelHostmasks(sHostmasks)) {
|
||||
PutModule("Removed user [" + pUser->GetUsername() + "] with key [" + pUser->GetUserKey() + "] and channels [" + pUser->GetChannels() + "]");
|
||||
DelUser(sUser);
|
||||
DelNV(sUser);
|
||||
} else {
|
||||
PutModule("Hostmasks(s) Removed from user [" + pUser->GetUsername() + "]");
|
||||
SetNV(pUser->GetUsername(), pUser->ToString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
PutModule("Unknown command, try HELP");
|
||||
HandleCommand(sLine);
|
||||
}
|
||||
}
|
||||
|
||||
void OnAddUserCommand(const CString& sLine) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CString sHost = sLine.Token(2);
|
||||
CString sKey = sLine.Token(3);
|
||||
|
||||
if (sHost.empty()) {
|
||||
PutModule("Usage: AddUser <user> <hostmask>[,<hostmasks>...] <key> [channels]");
|
||||
} else {
|
||||
CAutoOpUser* pUser = AddUser(sUser, sKey, sHost, sLine.Token(4, true));
|
||||
|
||||
if (pUser) {
|
||||
SetNV(sUser, pUser->ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnDelUserCommand(const CString& sLine) {
|
||||
CString sUser = sLine.Token(1);
|
||||
|
||||
if (sUser.empty()) {
|
||||
PutModule("Usage: DelUser <user>");
|
||||
} else {
|
||||
DelUser(sUser);
|
||||
DelNV(sUser);
|
||||
}
|
||||
}
|
||||
|
||||
void OnListUsersCommand(const CString& sLine) {
|
||||
if (m_msUsers.empty()) {
|
||||
PutModule("There are no users defined");
|
||||
return;
|
||||
}
|
||||
|
||||
CTable Table;
|
||||
|
||||
Table.AddColumn("User");
|
||||
Table.AddColumn("Hostmasks");
|
||||
Table.AddColumn("Key");
|
||||
Table.AddColumn("Channels");
|
||||
|
||||
for (map<CString, CAutoOpUser*>::iterator it = m_msUsers.begin(); it != m_msUsers.end(); ++it) {
|
||||
VCString vsHostmasks;
|
||||
it->second->GetHostmasks().Split(",", vsHostmasks);
|
||||
for (unsigned int a = 0; a < vsHostmasks.size(); a++) {
|
||||
Table.AddRow();
|
||||
if (a == 0) {
|
||||
Table.SetCell("User", it->second->GetUsername());
|
||||
Table.SetCell("Key", it->second->GetUserKey());
|
||||
Table.SetCell("Channels", it->second->GetChannels());
|
||||
} else if (a == vsHostmasks.size()-1) {
|
||||
Table.SetCell("User", "`-");
|
||||
} else {
|
||||
Table.SetCell("User", "|-");
|
||||
}
|
||||
Table.SetCell("Hostmasks", vsHostmasks[a]);
|
||||
}
|
||||
}
|
||||
|
||||
PutModule(Table);
|
||||
}
|
||||
|
||||
void OnAddChansCommand(const CString& sLine) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CString sChans = sLine.Token(2, true);
|
||||
|
||||
if (sChans.empty()) {
|
||||
PutModule("Usage: AddChans <user> <channel> [channel] ...");
|
||||
return;
|
||||
}
|
||||
|
||||
CAutoOpUser* pUser = FindUser(sUser);
|
||||
|
||||
if (!pUser) {
|
||||
PutModule("No such user");
|
||||
return;
|
||||
}
|
||||
|
||||
pUser->AddChans(sChans);
|
||||
PutModule("Channel(s) added to user [" + pUser->GetUsername() + "]");
|
||||
SetNV(pUser->GetUsername(), pUser->ToString());
|
||||
}
|
||||
|
||||
void OnDelChansCommand(const CString& sLine) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CString sChans = sLine.Token(2, true);
|
||||
|
||||
if (sChans.empty()) {
|
||||
PutModule("Usage: DelChans <user> <channel> [channel] ...");
|
||||
return;
|
||||
}
|
||||
|
||||
CAutoOpUser* pUser = FindUser(sUser);
|
||||
|
||||
if (!pUser) {
|
||||
PutModule("No such user");
|
||||
return;
|
||||
}
|
||||
|
||||
pUser->DelChans(sChans);
|
||||
PutModule("Channel(s) Removed from user [" + pUser->GetUsername() + "]");
|
||||
SetNV(pUser->GetUsername(), pUser->ToString());
|
||||
}
|
||||
|
||||
void OnAddMasksCommand(const CString& sLine) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CString sHostmasks = sLine.Token(2, true);
|
||||
|
||||
if (sHostmasks.empty()) {
|
||||
PutModule("Usage: AddMasks <user> <mask>,[mask] ...");
|
||||
return;
|
||||
}
|
||||
|
||||
CAutoOpUser* pUser = FindUser(sUser);
|
||||
|
||||
if (!pUser) {
|
||||
PutModule("No such user");
|
||||
return;
|
||||
}
|
||||
|
||||
pUser->AddHostmasks(sHostmasks);
|
||||
PutModule("Hostmasks(s) added to user [" + pUser->GetUsername() + "]");
|
||||
SetNV(pUser->GetUsername(), pUser->ToString());
|
||||
}
|
||||
|
||||
void OnDelMasksCommand(const CString& sLine) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CString sHostmasks = sLine.Token(2, true);
|
||||
|
||||
if (sHostmasks.empty()) {
|
||||
PutModule("Usage: DelMasks <user> <mask>,[mask] ...");
|
||||
return;
|
||||
}
|
||||
|
||||
CAutoOpUser* pUser = FindUser(sUser);
|
||||
|
||||
if (!pUser) {
|
||||
PutModule("No such user");
|
||||
return;
|
||||
}
|
||||
|
||||
if (pUser->DelHostmasks(sHostmasks)) {
|
||||
PutModule("Removed user [" + pUser->GetUsername() + "] with key [" + pUser->GetUserKey() + "] and channels [" + pUser->GetChannels() + "]");
|
||||
DelUser(sUser);
|
||||
DelNV(sUser);
|
||||
} else {
|
||||
PutModule("Hostmasks(s) Removed from user [" + pUser->GetUsername() + "]");
|
||||
SetNV(pUser->GetUsername(), pUser->ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-13
@@ -21,6 +21,9 @@
|
||||
class CAutoReplyMod : public CModule {
|
||||
public:
|
||||
MODCONSTRUCTOR(CAutoReplyMod) {
|
||||
AddHelpCommand();
|
||||
AddCommand("Set", static_cast<CModCommand::ModCmdFunc>(&CAutoReplyMod::OnSetCommand), "<reply>", "Sets a new reply");
|
||||
AddCommand("Show", static_cast<CModCommand::ModCmdFunc>(&CAutoReplyMod::OnShowCommand), "", "Displays the current query reply");
|
||||
m_Messaged.SetTTL(1000 * 120);
|
||||
}
|
||||
|
||||
@@ -70,20 +73,14 @@ public:
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
virtual void OnModCommand(const CString& sCommand) {
|
||||
const CString& sCmd = sCommand.Token(0);
|
||||
void OnShowCommand(const CString& sCommand) {
|
||||
PutModule("Current reply is: " + GetNV("Reply")
|
||||
+ " (" + GetReply() + ")");
|
||||
}
|
||||
|
||||
if (sCmd.Equals("SHOW")) {
|
||||
PutModule("Current reply is: " + GetNV("Reply")
|
||||
+ " (" + GetReply() + ")");
|
||||
} else if (sCmd.Equals("SET")) {
|
||||
SetReply(sCommand.Token(1, true));
|
||||
PutModule("New reply set");
|
||||
} else {
|
||||
PutModule("Available commands are:");
|
||||
PutModule("Show - Displays the current query reply");
|
||||
PutModule("Set <reply> - Sets a new reply");
|
||||
}
|
||||
void OnSetCommand(const CString& sCommand) {
|
||||
SetReply(sCommand.Token(1, true));
|
||||
PutModule("New reply set");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
+95
-69
@@ -115,7 +115,14 @@ protected:
|
||||
|
||||
class CAutoVoiceMod : public CModule {
|
||||
public:
|
||||
MODCONSTRUCTOR(CAutoVoiceMod) {}
|
||||
MODCONSTRUCTOR(CAutoVoiceMod) {
|
||||
AddHelpCommand();
|
||||
AddCommand("ListUsers", static_cast<CModCommand::ModCmdFunc>(&CAutoVoiceMod::OnListUsersCommand), "", "List all users");
|
||||
AddCommand("AddChans", static_cast<CModCommand::ModCmdFunc>(&CAutoVoiceMod::OnAddChansCommand), "<user> <channel> [channel] ...", "Adds channels to a user");
|
||||
AddCommand("DelChans", static_cast<CModCommand::ModCmdFunc>(&CAutoVoiceMod::OnDelChansCommand), "<user> <channel> [channel] ...", "Removes channels from a user");
|
||||
AddCommand("AddUser", static_cast<CModCommand::ModCmdFunc>(&CAutoVoiceMod::OnAddUserCommand), "<user> <hostmask> [channels]", "Adds a user");
|
||||
AddCommand("DelUser", static_cast<CModCommand::ModCmdFunc>(&CAutoVoiceMod::OnDelUserCommand), "<user>", "Removes a user");
|
||||
}
|
||||
|
||||
virtual bool OnLoad(const CString& sArgs, CString& sMessage) {
|
||||
// Load the chans from the command line
|
||||
@@ -165,79 +172,98 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnModCommand(const CString& sLine) {
|
||||
CString sCommand = sLine.Token(0).AsUpper();
|
||||
void OnAddUserCommand(const CString& sLine) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CString sHost = sLine.Token(2);
|
||||
|
||||
if (sCommand.Equals("HELP")) {
|
||||
PutModule("Commands are: ListUsers, AddChans, DelChans, AddUser, DelUser");
|
||||
} else if (sCommand.Equals("ADDUSER") || sCommand.Equals("DELUSER")) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CString sHost = sLine.Token(2);
|
||||
|
||||
if (sCommand.Equals("ADDUSER")) {
|
||||
if (sHost.empty()) {
|
||||
PutModule("Usage: " + sCommand + " <user> <hostmask> [channels]");
|
||||
} else {
|
||||
CAutoVoiceUser* pUser = AddUser(sUser, sHost, sLine.Token(3, true));
|
||||
|
||||
if (pUser) {
|
||||
SetNV(sUser, pUser->ToString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
DelUser(sUser);
|
||||
DelNV(sUser);
|
||||
}
|
||||
} else if (sCommand.Equals("LISTUSERS")) {
|
||||
if (m_msUsers.empty()) {
|
||||
PutModule("There are no users defined");
|
||||
return;
|
||||
}
|
||||
|
||||
CTable Table;
|
||||
|
||||
Table.AddColumn("User");
|
||||
Table.AddColumn("Hostmask");
|
||||
Table.AddColumn("Channels");
|
||||
|
||||
for (map<CString, CAutoVoiceUser*>::iterator it = m_msUsers.begin(); it != m_msUsers.end(); ++it) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("User", it->second->GetUsername());
|
||||
Table.SetCell("Hostmask", it->second->GetHostmask());
|
||||
Table.SetCell("Channels", it->second->GetChannels());
|
||||
}
|
||||
|
||||
PutModule(Table);
|
||||
} else if (sCommand.Equals("ADDCHANS") || sCommand.Equals("DELCHANS")) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CString sChans = sLine.Token(2, true);
|
||||
|
||||
if (sChans.empty()) {
|
||||
PutModule("Usage: " + sCommand + " <user> <channel> [channel] ...");
|
||||
return;
|
||||
}
|
||||
|
||||
CAutoVoiceUser* pUser = FindUser(sUser);
|
||||
|
||||
if (!pUser) {
|
||||
PutModule("No such user");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sCommand.Equals("ADDCHANS")) {
|
||||
pUser->AddChans(sChans);
|
||||
PutModule("Channel(s) added to user [" + pUser->GetUsername() + "]");
|
||||
} else {
|
||||
pUser->DelChans(sChans);
|
||||
PutModule("Channel(s) Removed from user [" + pUser->GetUsername() + "]");
|
||||
}
|
||||
|
||||
SetNV(pUser->GetUsername(), pUser->ToString());
|
||||
if (sHost.empty()) {
|
||||
PutModule("Usage: AddUser <user> <hostmask> [channels]");
|
||||
} else {
|
||||
PutModule("Unknown command, try HELP");
|
||||
CAutoVoiceUser* pUser = AddUser(sUser, sHost, sLine.Token(3, true));
|
||||
|
||||
if (pUser) {
|
||||
SetNV(sUser, pUser->ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnDelUserCommand(const CString& sLine) {
|
||||
CString sUser = sLine.Token(1);
|
||||
|
||||
if (sUser.empty()) {
|
||||
PutModule("Usage: DelUser <user>");
|
||||
} else {
|
||||
DelUser(sUser);
|
||||
DelNV(sUser);
|
||||
}
|
||||
}
|
||||
|
||||
void OnListUsersCommand(const CString& sLine) {
|
||||
if (m_msUsers.empty()) {
|
||||
PutModule("There are no users defined");
|
||||
return;
|
||||
}
|
||||
|
||||
CTable Table;
|
||||
|
||||
Table.AddColumn("User");
|
||||
Table.AddColumn("Hostmask");
|
||||
Table.AddColumn("Channels");
|
||||
|
||||
for (map<CString, CAutoVoiceUser*>::iterator it = m_msUsers.begin(); it != m_msUsers.end(); ++it) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("User", it->second->GetUsername());
|
||||
Table.SetCell("Hostmask", it->second->GetHostmask());
|
||||
Table.SetCell("Channels", it->second->GetChannels());
|
||||
}
|
||||
|
||||
PutModule(Table);
|
||||
}
|
||||
|
||||
void OnAddChansCommand(const CString& sLine) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CString sChans = sLine.Token(2, true);
|
||||
|
||||
if (sChans.empty()) {
|
||||
PutModule("Usage: AddChans <user> <channel> [channel] ...");
|
||||
return;
|
||||
}
|
||||
|
||||
CAutoVoiceUser* pUser = FindUser(sUser);
|
||||
|
||||
if (!pUser) {
|
||||
PutModule("No such user");
|
||||
return;
|
||||
}
|
||||
|
||||
pUser->AddChans(sChans);
|
||||
PutModule("Channel(s) added to user [" + pUser->GetUsername() + "]");
|
||||
|
||||
SetNV(pUser->GetUsername(), pUser->ToString());
|
||||
}
|
||||
|
||||
void OnDelChansCommand(const CString& sLine) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CString sChans = sLine.Token(2, true);
|
||||
|
||||
if (sChans.empty()) {
|
||||
PutModule("Usage: DelChans <user> <channel> [channel] ...");
|
||||
return;
|
||||
}
|
||||
|
||||
CAutoVoiceUser* pUser = FindUser(sUser);
|
||||
|
||||
if (!pUser) {
|
||||
PutModule("No such user");
|
||||
return;
|
||||
}
|
||||
|
||||
pUser->DelChans(sChans);
|
||||
PutModule("Channel(s) Removed from user [" + pUser->GetUsername() + "]");
|
||||
|
||||
SetNV(pUser->GetUsername(), pUser->ToString());
|
||||
}
|
||||
|
||||
CAutoVoiceUser* FindUser(const CString& sUser) {
|
||||
map<CString, CAutoVoiceUser*>::iterator it = m_msUsers.find(sUser.AsLower());
|
||||
|
||||
|
||||
+53
-37
@@ -23,7 +23,12 @@ using std::vector;
|
||||
|
||||
class CBlockUser : public CModule {
|
||||
public:
|
||||
MODCONSTRUCTOR(CBlockUser) {}
|
||||
MODCONSTRUCTOR(CBlockUser) {
|
||||
AddHelpCommand();
|
||||
AddCommand("List", static_cast<CModCommand::ModCmdFunc>(&CBlockUser::OnListCommand), "", "List blocked users");
|
||||
AddCommand("Block", static_cast<CModCommand::ModCmdFunc>(&CBlockUser::OnBlockCommand), "<user>", "Block a user");
|
||||
AddCommand("Unblock", static_cast<CModCommand::ModCmdFunc>(&CBlockUser::OnUnblockCommand), "<user>", "Unblock a user");
|
||||
}
|
||||
|
||||
virtual ~CBlockUser() {}
|
||||
|
||||
@@ -61,48 +66,59 @@ public:
|
||||
}
|
||||
|
||||
void OnModCommand(const CString& sCommand) {
|
||||
CString sCmd = sCommand.Token(0);
|
||||
|
||||
if (!GetUser()->IsAdmin()) {
|
||||
PutModule("Access denied");
|
||||
} else {
|
||||
HandleCommand(sCommand);
|
||||
}
|
||||
}
|
||||
|
||||
void OnListCommand(const CString& sCommand) {
|
||||
CTable Table;
|
||||
MCString::iterator it;
|
||||
|
||||
Table.AddColumn("Blocked user");
|
||||
|
||||
for (it = BeginNV(); it != EndNV(); ++it) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("Blocked user", it->first);
|
||||
}
|
||||
|
||||
if (PutModule(Table) == 0)
|
||||
PutModule("No users blocked");
|
||||
}
|
||||
|
||||
void OnBlockCommand(const CString& sCommand) {
|
||||
CString sUser = sCommand.Token(1, true);
|
||||
|
||||
if (sUser.empty()) {
|
||||
PutModule("Usage: Block <user>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sCmd.Equals("list")) {
|
||||
CTable Table;
|
||||
MCString::iterator it;
|
||||
|
||||
Table.AddColumn("Blocked user");
|
||||
|
||||
for (it = BeginNV(); it != EndNV(); ++it) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("Blocked user", it->first);
|
||||
}
|
||||
|
||||
if (PutModule(Table) == 0)
|
||||
PutModule("No users blocked");
|
||||
} else if (sCmd.Equals("block")) {
|
||||
CString sUser = sCommand.Token(1, true);
|
||||
|
||||
if (GetUser()->GetUserName().Equals(sUser)) {
|
||||
PutModule("You can't block yourself");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Block(sUser))
|
||||
PutModule("Blocked [" + sUser + "]");
|
||||
else
|
||||
PutModule("Could not block [" + sUser + "] (misspelled?)");
|
||||
} else if (sCmd.Equals("unblock")) {
|
||||
CString sUser = sCommand.Token(1, true);
|
||||
|
||||
if (DelNV(sUser))
|
||||
PutModule("Unblocked [" + sUser + "]");
|
||||
else
|
||||
PutModule("This user is not blocked");
|
||||
} else {
|
||||
PutModule("Commands: list, block [user], unblock [user]");
|
||||
if (GetUser()->GetUserName().Equals(sUser)) {
|
||||
PutModule("You can't block yourself");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Block(sUser))
|
||||
PutModule("Blocked [" + sUser + "]");
|
||||
else
|
||||
PutModule("Could not block [" + sUser + "] (misspelled?)");
|
||||
}
|
||||
|
||||
void OnUnblockCommand(const CString& sCommand) {
|
||||
CString sUser = sCommand.Token(1, true);
|
||||
|
||||
if (sUser.empty()) {
|
||||
PutModule("Usage: Unblock <user>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (DelNV(sUser))
|
||||
PutModule("Unblocked [" + sUser + "]");
|
||||
else
|
||||
PutModule("This user is not blocked");
|
||||
}
|
||||
|
||||
bool OnEmbeddedWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) {
|
||||
|
||||
+42
-24
@@ -44,6 +44,11 @@ protected:
|
||||
|
||||
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 notifies for unseen IP addresses only on or off");
|
||||
AddCommand("OnDisconnect", static_cast<CModCommand::ModCmdFunc>(&CClientNotifyMod::OnDisconnectCommand), "<on|off>", "Turns notifies on disconnecting clients on or off");
|
||||
AddCommand("Show", static_cast<CModCommand::ModCmdFunc>(&CClientNotifyMod::OnShowCommand), "", "Show the current settings");
|
||||
}
|
||||
|
||||
bool OnLoad(const CString& sArgs, CString& sMessage) {
|
||||
@@ -81,35 +86,48 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void OnModCommand(const CString& sCommand) {
|
||||
const CString& sCmd = sCommand.Token(0).AsLower();
|
||||
void OnMethodCommand(const CString& sCommand) {
|
||||
const CString& sArg = sCommand.Token(1, true).AsLower();
|
||||
|
||||
if (sCmd.Equals("method") && !sArg.empty()) {
|
||||
if(sArg != "notice" && sArg != "message" && sArg != "off") {
|
||||
PutModule("Unknown method. Use one of: message / notice / off");
|
||||
}
|
||||
else {
|
||||
m_sMethod = sArg;
|
||||
SaveSettings();
|
||||
PutModule("Saved.");
|
||||
}
|
||||
if (sArg != "notice" && sArg != "message" && sArg != "off") {
|
||||
PutModule("Usage: Method <message|notice|off>");
|
||||
return;
|
||||
}
|
||||
else if (sCmd.Equals("newonly") && !sArg.empty()) {
|
||||
m_bNewOnly = (sArg == "on" || sArg == "true");
|
||||
SaveSettings();
|
||||
PutModule("Saved.");
|
||||
|
||||
m_sMethod = sArg;
|
||||
SaveSettings();
|
||||
PutModule("Saved.");
|
||||
}
|
||||
|
||||
void OnNewOnlyCommand(const CString& sCommand) {
|
||||
const CString& sArg = sCommand.Token(1, true).AsLower();
|
||||
|
||||
if (sArg.empty()) {
|
||||
PutModule("Usage: NewOnly <on|off>");
|
||||
return;
|
||||
}
|
||||
else if (sCmd.Equals("ondisconnect") && !sArg.empty()) {
|
||||
m_bOnDisconnect = (sArg == "on" || sArg == "true");
|
||||
SaveSettings();
|
||||
PutModule("Saved.");
|
||||
}
|
||||
else {
|
||||
PutModule("Current settings: Method: " + m_sMethod + ", for unseen IP addresses only: " + CString(m_bNewOnly) +
|
||||
", notify on disconnecting clients: " + CString(m_bOnDisconnect));
|
||||
PutModule("Commands: show, method <message|notice|off>, newonly <on|off>, ondisconnect <on|off>");
|
||||
|
||||
m_bNewOnly = sArg.ToBool();
|
||||
SaveSettings();
|
||||
PutModule("Saved.");
|
||||
}
|
||||
|
||||
void OnDisconnectCommand(const CString& sCommand) {
|
||||
const CString& sArg = sCommand.Token(1, true).AsLower();
|
||||
|
||||
if (sArg.empty()) {
|
||||
PutModule("Usage: OnDisconnect <on|off>");
|
||||
return;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+54
-52
@@ -44,7 +44,13 @@ class CCryptMod : public CModule {
|
||||
}
|
||||
|
||||
public:
|
||||
MODCONSTRUCTOR(CCryptMod) {}
|
||||
MODCONSTRUCTOR(CCryptMod) {
|
||||
AddHelpCommand();
|
||||
AddCommand("DelKey", static_cast<CModCommand::ModCmdFunc>(&CCryptMod::OnDelKeyCommand), "<#chan|Nick>", "Remove a key for nick or channel");
|
||||
AddCommand("SetKey", static_cast<CModCommand::ModCmdFunc>(&CCryptMod::OnSetKeyCommand), "<#chan|Nick> <Key>", "Set a key for nick or channel");
|
||||
AddCommand("ListKeys", static_cast<CModCommand::ModCmdFunc>(&CCryptMod::OnListKeysCommand), "", "List all keys");
|
||||
}
|
||||
|
||||
virtual ~CCryptMod() {}
|
||||
|
||||
virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage) {
|
||||
@@ -104,61 +110,57 @@ public:
|
||||
|
||||
}
|
||||
|
||||
virtual void OnModCommand(const CString& sCommand) {
|
||||
CString sCmd = sCommand.Token(0);
|
||||
void OnDelKeyCommand(const CString& sCommand) {
|
||||
CString sTarget = sCommand.Token(1);
|
||||
|
||||
if (sCmd.Equals("DELKEY")) {
|
||||
CString sTarget = sCommand.Token(1);
|
||||
|
||||
if (!sTarget.empty()) {
|
||||
if (DelNV(sTarget.AsLower())) {
|
||||
PutModule("Target [" + sTarget + "] deleted");
|
||||
} else {
|
||||
PutModule("Target [" + sTarget + "] not found");
|
||||
}
|
||||
if (!sTarget.empty()) {
|
||||
if (DelNV(sTarget.AsLower())) {
|
||||
PutModule("Target [" + sTarget + "] deleted");
|
||||
} else {
|
||||
PutModule("Usage DelKey <#chan|Nick>");
|
||||
PutModule("Target [" + sTarget + "] not found");
|
||||
}
|
||||
} else if (sCmd.Equals("SETKEY")) {
|
||||
CString sTarget = sCommand.Token(1);
|
||||
CString sKey = sCommand.Token(2, true);
|
||||
|
||||
// Strip "cbc:" from beginning of string incase someone pastes directly from mircryption
|
||||
sKey.TrimPrefix("cbc:");
|
||||
|
||||
if (!sKey.empty()) {
|
||||
SetNV(sTarget.AsLower(), sKey);
|
||||
PutModule("Set encryption key for [" + sTarget + "] to [" + sKey + "]");
|
||||
} else {
|
||||
PutModule("Usage: SetKey <#chan|Nick> <Key>");
|
||||
}
|
||||
} else if (sCmd.Equals("LISTKEYS")) {
|
||||
if (BeginNV() == EndNV()) {
|
||||
PutModule("You have no encryption keys set.");
|
||||
} else {
|
||||
CTable Table;
|
||||
Table.AddColumn("Target");
|
||||
Table.AddColumn("Key");
|
||||
|
||||
for (MCString::iterator it = BeginNV(); it != EndNV(); ++it) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("Target", it->first);
|
||||
Table.SetCell("Key", it->second);
|
||||
}
|
||||
|
||||
MCString::iterator it = FindNV(NICK_PREFIX_KEY);
|
||||
if (it == EndNV()) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("Target", NICK_PREFIX_KEY);
|
||||
Table.SetCell("Key", NickPrefix());
|
||||
}
|
||||
|
||||
PutModule(Table);
|
||||
}
|
||||
} else if (sCmd.Equals("HELP")) {
|
||||
PutModule("Try: SetKey, DelKey, ListKeys");
|
||||
} else {
|
||||
PutModule("Unknown command, try 'Help'");
|
||||
PutModule("Usage DelKey <#chan|Nick>");
|
||||
}
|
||||
}
|
||||
|
||||
void OnSetKeyCommand(const CString& sCommand) {
|
||||
CString sTarget = sCommand.Token(1);
|
||||
CString sKey = sCommand.Token(2, true);
|
||||
|
||||
// Strip "cbc:" from beginning of string incase someone pastes directly from mircryption
|
||||
sKey.TrimPrefix("cbc:");
|
||||
|
||||
if (!sKey.empty()) {
|
||||
SetNV(sTarget.AsLower(), sKey);
|
||||
PutModule("Set encryption key for [" + sTarget + "] to [" + sKey + "]");
|
||||
} else {
|
||||
PutModule("Usage: SetKey <#chan|Nick> <Key>");
|
||||
}
|
||||
}
|
||||
|
||||
void OnListKeysCommand(const CString& sCommand) {
|
||||
if (BeginNV() == EndNV()) {
|
||||
PutModule("You have no encryption keys set.");
|
||||
} else {
|
||||
CTable Table;
|
||||
Table.AddColumn("Target");
|
||||
Table.AddColumn("Key");
|
||||
|
||||
for (MCString::iterator it = BeginNV(); it != EndNV(); ++it) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("Target", it->first);
|
||||
Table.SetCell("Key", it->second);
|
||||
}
|
||||
|
||||
MCString::iterator it = FindNV(NICK_PREFIX_KEY);
|
||||
if (it == EndNV()) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("Target", NICK_PREFIX_KEY);
|
||||
Table.SetCell("Key", NickPrefix());
|
||||
}
|
||||
|
||||
PutModule(Table);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+37
-21
@@ -22,6 +22,11 @@ public:
|
||||
MODCONSTRUCTOR(CCtcpFloodMod) {
|
||||
m_tLastCTCP = 0;
|
||||
m_iNumCTCP = 0;
|
||||
|
||||
AddHelpCommand();
|
||||
AddCommand("Secs", static_cast<CModCommand::ModCmdFunc>(&CCtcpFloodMod::OnSecsCommand), "<limit>", "Set seconds limit");
|
||||
AddCommand("Lines", static_cast<CModCommand::ModCmdFunc>(&CCtcpFloodMod::OnLinesCommand), "<limit>", "Set lines limit");
|
||||
AddCommand("Show", static_cast<CModCommand::ModCmdFunc>(&CCtcpFloodMod::OnShowCommand), "", "Show the current limits");
|
||||
}
|
||||
|
||||
~CCtcpFloodMod() {
|
||||
@@ -87,30 +92,41 @@ public:
|
||||
return Message(Nick, sMessage);
|
||||
}
|
||||
|
||||
void OnModCommand(const CString& sCommand) {
|
||||
const CString& sCmd = sCommand.Token(0);
|
||||
void OnSecsCommand(const CString& sCommand) {
|
||||
const CString& sArg = sCommand.Token(1, true);
|
||||
|
||||
if (sCmd.Equals("secs") && !sArg.empty()) {
|
||||
m_iThresholdSecs = sArg.ToUInt();
|
||||
if (m_iThresholdSecs == 0)
|
||||
m_iThresholdSecs = 1;
|
||||
|
||||
PutModule("Set seconds limit to [" + CString(m_iThresholdSecs) + "]");
|
||||
Save();
|
||||
} else if (sCmd.Equals("lines") && !sArg.empty()) {
|
||||
m_iThresholdMsgs = sArg.ToUInt();
|
||||
if (m_iThresholdMsgs == 0)
|
||||
m_iThresholdMsgs = 2;
|
||||
|
||||
PutModule("Set lines limit to [" + CString(m_iThresholdMsgs) + "]");
|
||||
Save();
|
||||
} else if (sCmd.Equals("show")) {
|
||||
PutModule("Current limit is " + CString(m_iThresholdMsgs) + " CTCPs "
|
||||
"in " + CString(m_iThresholdSecs) + " secs");
|
||||
} else {
|
||||
PutModule("Commands: show, secs [limit], lines [limit]");
|
||||
if (sArg.empty()) {
|
||||
PutModule("Usage: Secs <limit>");
|
||||
return;
|
||||
}
|
||||
|
||||
m_iThresholdSecs = sArg.ToUInt();
|
||||
if (m_iThresholdSecs == 0)
|
||||
m_iThresholdSecs = 1;
|
||||
|
||||
PutModule("Set seconds limit to [" + CString(m_iThresholdSecs) + "]");
|
||||
Save();
|
||||
}
|
||||
|
||||
void OnLinesCommand(const CString& sCommand) {
|
||||
const CString& sArg = sCommand.Token(1, true);
|
||||
|
||||
if (sArg.empty()) {
|
||||
PutModule("Usage: Lines <limit>");
|
||||
return;
|
||||
}
|
||||
|
||||
m_iThresholdMsgs = sArg.ToUInt();
|
||||
if (m_iThresholdMsgs == 0)
|
||||
m_iThresholdMsgs = 2;
|
||||
|
||||
PutModule("Set lines limit to [" + CString(m_iThresholdMsgs) + "]");
|
||||
Save();
|
||||
}
|
||||
|
||||
void OnShowCommand(const CString& sCommand) {
|
||||
PutModule("Current limit is " + CString(m_iThresholdMsgs) + " CTCPs "
|
||||
"in " + CString(m_iThresholdSecs) + " secs");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
+20
-17
@@ -34,7 +34,12 @@ private:
|
||||
|
||||
class CKeepNickMod : public CModule {
|
||||
public:
|
||||
MODCONSTRUCTOR(CKeepNickMod) {}
|
||||
MODCONSTRUCTOR(CKeepNickMod) {
|
||||
AddHelpCommand();
|
||||
AddCommand("Enable", static_cast<CModCommand::ModCmdFunc>(&CKeepNickMod::OnEnableCommand), "", "Try to get your primary nick");
|
||||
AddCommand("Disable", static_cast<CModCommand::ModCmdFunc>(&CKeepNickMod::OnDisableCommand), "", "No longer trying to get your primary nick");
|
||||
AddCommand("State", static_cast<CModCommand::ModCmdFunc>(&CKeepNickMod::OnStateCommand), "", "Show the current state");
|
||||
}
|
||||
|
||||
~CKeepNickMod() {}
|
||||
|
||||
@@ -168,23 +173,21 @@ public:
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
void OnModCommand(const CString& sCommand) {
|
||||
CString sCmd = sCommand.AsUpper();
|
||||
void OnEnableCommand(const CString& sCommand) {
|
||||
Enable();
|
||||
PutModule("Trying to get your primary nick");
|
||||
}
|
||||
|
||||
if (sCmd == "ENABLE") {
|
||||
Enable();
|
||||
PutModule("Trying to get your primary nick");
|
||||
} else if (sCmd == "DISABLE") {
|
||||
Disable();
|
||||
PutModule("No longer trying to get your primary nick");
|
||||
} else if (sCmd == "STATE") {
|
||||
if (m_pTimer)
|
||||
PutModule("Currently trying to get your primary nick");
|
||||
else
|
||||
PutModule("Currently disabled, try 'enable'");
|
||||
} else {
|
||||
PutModule("Commands: Enable, Disable, State");
|
||||
}
|
||||
void OnDisableCommand(const CString& sCommand) {
|
||||
Disable();
|
||||
PutModule("No longer trying to get your primary nick");
|
||||
}
|
||||
|
||||
void OnStateCommand(const CString& sCommand) {
|
||||
if (m_pTimer)
|
||||
PutModule("Currently trying to get your primary nick");
|
||||
else
|
||||
PutModule("Currently disabled, try 'enable'");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
+26
-26
@@ -50,7 +50,11 @@ private:
|
||||
unsigned int delay;
|
||||
|
||||
public:
|
||||
MODCONSTRUCTOR(CRejoinMod) {}
|
||||
MODCONSTRUCTOR(CRejoinMod) {
|
||||
AddHelpCommand();
|
||||
AddCommand("SetDelay", static_cast<CModCommand::ModCmdFunc>(&CRejoinMod::OnSetDelayCommand), "<secs>", "Set the rejoin delay");
|
||||
AddCommand("ShowDelay", static_cast<CModCommand::ModCmdFunc>(&CRejoinMod::OnShowDelayCommand), "", "Show the rejoin delay");
|
||||
}
|
||||
virtual ~CRejoinMod() {}
|
||||
|
||||
virtual bool OnLoad(const CString& sArgs, CString& sErrorMsg) {
|
||||
@@ -75,33 +79,29 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void OnModCommand(const CString& sCommand) {
|
||||
CString sCmdName = sCommand.Token(0).AsLower();
|
||||
void OnSetDelayCommand(const CString& sCommand) {
|
||||
int i;
|
||||
i = sCommand.Token(1).ToInt();
|
||||
|
||||
if (sCmdName == "setdelay") {
|
||||
int i;
|
||||
i = sCommand.Token(1).ToInt();
|
||||
|
||||
if (i < 0) {
|
||||
PutModule("Negative delays don't make any sense!");
|
||||
return;
|
||||
}
|
||||
|
||||
delay = i;
|
||||
SetNV("delay", CString(delay));
|
||||
|
||||
if (delay)
|
||||
PutModule("Rejoin delay set to " + CString(delay) + " seconds");
|
||||
else
|
||||
PutModule("Rejoin delay disabled");
|
||||
} else if (sCmdName == "showdelay") {
|
||||
if (delay)
|
||||
PutModule("Rejoin delay enabled, " + CString(delay) + " seconds");
|
||||
else
|
||||
PutModule("Rejoin delay disabled");
|
||||
} else {
|
||||
PutModule("Commands: setdelay <secs>, showdelay");
|
||||
if (i < 0) {
|
||||
PutModule("Negative delays don't make any sense!");
|
||||
return;
|
||||
}
|
||||
|
||||
delay = i;
|
||||
SetNV("delay", CString(delay));
|
||||
|
||||
if (delay)
|
||||
PutModule("Rejoin delay set to " + CString(delay) + " seconds");
|
||||
else
|
||||
PutModule("Rejoin delay disabled");
|
||||
}
|
||||
|
||||
void OnShowDelayCommand(const CString& sCommand) {
|
||||
if (delay)
|
||||
PutModule("Rejoin delay enabled, " + CString(delay) + " seconds");
|
||||
else
|
||||
PutModule("Rejoin delay disabled");
|
||||
}
|
||||
|
||||
virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& pChan, const CString& sMessage) {
|
||||
|
||||
+9
-12
@@ -64,7 +64,10 @@ private:
|
||||
|
||||
class CListSockets : public CModule {
|
||||
public:
|
||||
MODCONSTRUCTOR(CListSockets) {}
|
||||
MODCONSTRUCTOR(CListSockets) {
|
||||
AddHelpCommand();
|
||||
AddCommand("List", static_cast<CModCommand::ModCmdFunc>(&CListSockets::OnListCommand), "[-n]", "Show the list of active sockets. Pass -n to show IP addresses");
|
||||
}
|
||||
|
||||
virtual bool OnLoad(const CString& sArgs, CString& sMessage)
|
||||
{
|
||||
@@ -128,20 +131,14 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void OnModCommand(const CString& sLine) {
|
||||
CString sCommand = sLine.Token(0);
|
||||
void OnListCommand(const CString& sLine) {
|
||||
CString sArg = sLine.Token(1, true);
|
||||
|
||||
if (sCommand.Equals("LIST")) {
|
||||
bool bShowHosts = true;
|
||||
if (sArg.Equals("-n")) {
|
||||
bShowHosts = false;
|
||||
}
|
||||
ShowSocks(bShowHosts);
|
||||
} else {
|
||||
PutModule("Use 'list' to view a list of active sockets");
|
||||
PutModule("Use 'list -n' if you want IP addresses to be displayed");
|
||||
bool bShowHosts = true;
|
||||
if (sArg.Equals("-n")) {
|
||||
bShowHosts = false;
|
||||
}
|
||||
ShowSocks(bShowHosts);
|
||||
}
|
||||
|
||||
CString GetSocketState(Csock* pSocket) {
|
||||
|
||||
+32
-18
@@ -59,6 +59,11 @@ public:
|
||||
{
|
||||
m_bBootError = false;
|
||||
m_bFirstLoad = false;
|
||||
|
||||
AddHelpCommand();
|
||||
AddCommand("SetPass", static_cast<CModCommand::ModCmdFunc>(&CSaveBuff::OnSetPassCommand), "<password>", "Sets the password");
|
||||
AddCommand("Replay", static_cast<CModCommand::ModCmdFunc>(&CSaveBuff::OnReplayCommand), "<buffer>", "Replays the buffer");
|
||||
AddCommand("Save", static_cast<CModCommand::ModCmdFunc>(&CSaveBuff::OnSaveCommand), "", "Saves all buffers");
|
||||
}
|
||||
virtual ~CSaveBuff()
|
||||
{
|
||||
@@ -206,18 +211,21 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnModCommand(const CString& sCmdLine)
|
||||
void OnSetPassCommand(const CString& sCmdLine)
|
||||
{
|
||||
CString sArgs = sCmdLine.Token(1, true);
|
||||
|
||||
PutModule("Password set to [" + sArgs + "]");
|
||||
m_sPassword = CBlowfish::MD5(sArgs);
|
||||
}
|
||||
|
||||
void OnModCommand(const CString& sCmdLine)
|
||||
{
|
||||
CString sCommand = sCmdLine.Token(0);
|
||||
CString sArgs = sCmdLine.Token(1, true);
|
||||
|
||||
if (sCommand.Equals("setpass"))
|
||||
{
|
||||
PutModule("Password set to [" + sArgs + "]");
|
||||
m_sPassword = CBlowfish::MD5(sArgs);
|
||||
|
||||
} else if (sCommand.Equals("dumpbuff"))
|
||||
{
|
||||
if (sCommand.Equals("dumpbuff")) {
|
||||
// for testing purposes - hidden from help
|
||||
CString sFile;
|
||||
if (DecryptBuffer(sArgs, sFile))
|
||||
{
|
||||
@@ -233,17 +241,23 @@ public:
|
||||
}
|
||||
}
|
||||
PutModule("//!-- EOF " + sArgs);
|
||||
} else if (sCommand.Equals("replay"))
|
||||
{
|
||||
Replay(sArgs);
|
||||
PutModule("Replayed " + sArgs);
|
||||
} else {
|
||||
HandleCommand(sCmdLine);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (sCommand.Equals("save"))
|
||||
{
|
||||
SaveBufferToDisk();
|
||||
PutModule("Done.");
|
||||
} else
|
||||
PutModule("Unknown command [" + sCommand + "]");
|
||||
void OnReplayCommand(const CString& sCmdLine)
|
||||
{
|
||||
CString sArgs = sCmdLine.Token(1, true);
|
||||
|
||||
Replay(sArgs);
|
||||
PutModule("Replayed " + sArgs);
|
||||
}
|
||||
|
||||
void OnSaveCommand(const CString& sCmdLine)
|
||||
{
|
||||
SaveBufferToDisk();
|
||||
PutModule("Done.");
|
||||
}
|
||||
|
||||
void Replay(const CString & sBuffer)
|
||||
|
||||
+33
-51
@@ -47,6 +47,12 @@ public:
|
||||
m_iAwayWait = SIMPLE_AWAY_DEFAULT_TIME;
|
||||
m_bClientSetAway = false;
|
||||
m_bWeSetAway = false;
|
||||
|
||||
AddHelpCommand();
|
||||
AddCommand("Reason", static_cast<CModCommand::ModCmdFunc>(&CSimpleAway::OnReasonCommand), "[<text>]", "Prints or sets the away reason (%s is replaced with the time you were set away)");
|
||||
AddCommand("Timer", static_cast<CModCommand::ModCmdFunc>(&CSimpleAway::OnTimerCommand), "", "Prints the current time to wait before setting you away");
|
||||
AddCommand("SetTimer", static_cast<CModCommand::ModCmdFunc>(&CSimpleAway::OnSetTimerCommand), "<seconds>", "Sets the time to wait before setting you away");
|
||||
AddCommand("DisableTimer", static_cast<CModCommand::ModCmdFunc>(&CSimpleAway::OnDisableTimerCommand), "", "Disables the wait time before setting you away");
|
||||
}
|
||||
|
||||
virtual ~CSimpleAway() {}
|
||||
@@ -102,62 +108,38 @@ public:
|
||||
SetAway();
|
||||
}
|
||||
|
||||
virtual void OnModCommand(const CString& sLine) {
|
||||
CString sCommand = sLine.Token(0);
|
||||
|
||||
if (sCommand.Equals("help")) {
|
||||
CTable Table;
|
||||
Table.AddColumn("Command");
|
||||
Table.AddColumn("Description");
|
||||
Table.AddRow();
|
||||
Table.SetCell("Command", "Reason [<text>]");
|
||||
Table.SetCell("Description", "Prints and optionally sets the away reason.");
|
||||
Table.AddRow();
|
||||
Table.SetCell("Command", "Timer");
|
||||
Table.SetCell("Description", "Prints the current time to wait before setting you away.");
|
||||
Table.AddRow();
|
||||
Table.SetCell("Command", "SetTimer <time>");
|
||||
Table.SetCell("Description", "Sets the time to wait before setting you away (in seconds).");
|
||||
Table.AddRow();
|
||||
Table.SetCell("Command", "DisableTimer");
|
||||
Table.SetCell("Description", "Disables the wait time before setting you away.");
|
||||
PutModule(Table);
|
||||
|
||||
PutModule("In the away reason, %s will be replaced with the time you were set away.");
|
||||
|
||||
} else if (sCommand.Equals("reason")) {
|
||||
CString sReason = sLine.Token(1, true);
|
||||
|
||||
if (!sReason.empty()) {
|
||||
SetReason(sReason);
|
||||
PutModule("Away reason set");
|
||||
} else {
|
||||
PutModule("Away reason: " + m_sReason);
|
||||
PutModule("Current away reason would be: " + ExpandReason());
|
||||
}
|
||||
|
||||
} else if (sCommand.Equals("timer")) {
|
||||
PutModule("Current timer setting: "
|
||||
+ CString(m_iAwayWait) + " seconds");
|
||||
|
||||
} else if (sCommand.Equals("settimer")) {
|
||||
SetAwayWait(sLine.Token(1).ToUInt());
|
||||
|
||||
if (m_iAwayWait == 0)
|
||||
PutModule("Timer disabled");
|
||||
else
|
||||
PutModule("Timer set to "
|
||||
+ CString(m_iAwayWait) + " seconds");
|
||||
|
||||
} else if (sCommand.Equals("disabletimer")) {
|
||||
SetAwayWait(0);
|
||||
PutModule("Timer disabled");
|
||||
void OnReasonCommand(const CString& sLine) {
|
||||
CString sReason = sLine.Token(1, true);
|
||||
|
||||
if (!sReason.empty()) {
|
||||
SetReason(sReason);
|
||||
PutModule("Away reason set");
|
||||
} else {
|
||||
PutModule("Unknown command. Try 'help'.");
|
||||
PutModule("Away reason: " + m_sReason);
|
||||
PutModule("Current away reason would be: " + ExpandReason());
|
||||
}
|
||||
}
|
||||
|
||||
void OnTimerCommand(const CString& sLine) {
|
||||
PutModule("Current timer setting: "
|
||||
+ CString(m_iAwayWait) + " seconds");
|
||||
}
|
||||
|
||||
void OnSetTimerCommand(const CString& sLine) {
|
||||
SetAwayWait(sLine.Token(1).ToUInt());
|
||||
|
||||
if (m_iAwayWait == 0)
|
||||
PutModule("Timer disabled");
|
||||
else
|
||||
PutModule("Timer set to "
|
||||
+ CString(m_iAwayWait) + " seconds");
|
||||
}
|
||||
|
||||
void OnDisableTimerCommand(const CString& sLine) {
|
||||
SetAwayWait(0);
|
||||
PutModule("Timer disabled");
|
||||
}
|
||||
|
||||
virtual EModRet OnUserRaw(CString &sLine) {
|
||||
if (!sLine.Token(0).Equals("AWAY"))
|
||||
return CONTINUE;
|
||||
|
||||
+33
-29
@@ -22,7 +22,12 @@ using std::vector;
|
||||
class CStickyChan : public CModule
|
||||
{
|
||||
public:
|
||||
MODCONSTRUCTOR(CStickyChan) {}
|
||||
MODCONSTRUCTOR(CStickyChan) {
|
||||
AddHelpCommand();
|
||||
AddCommand("Stick", static_cast<CModCommand::ModCmdFunc>(&CStickyChan::OnStickCommand), "<#channel> [key]", "Sticks a channel");
|
||||
AddCommand("Unstick", static_cast<CModCommand::ModCmdFunc>(&CStickyChan::OnUnstickCommand), "<#channel>", "Unsticks a channel");
|
||||
AddCommand("List", static_cast<CModCommand::ModCmdFunc>(&CStickyChan::OnListCommand), "", "Lists sticky channels");
|
||||
}
|
||||
virtual ~CStickyChan()
|
||||
{
|
||||
}
|
||||
@@ -48,40 +53,39 @@ public:
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
virtual void OnModCommand(const CString& sCommand)
|
||||
void OnStickCommand(const CString& sCommand)
|
||||
{
|
||||
CString sCmdName = sCommand.Token(0);
|
||||
CString sChannel = sCommand.Token(1);
|
||||
sChannel.MakeLower();
|
||||
if ((sCmdName == "stick") && (!sChannel.empty()))
|
||||
{
|
||||
SetNV(sChannel, sCommand.Token(2));
|
||||
PutModule("Stuck " + sChannel);
|
||||
CString sChannel = sCommand.Token(1).AsLower();
|
||||
if (sChannel.empty()) {
|
||||
PutModule("Usage: Stick <#channel> [key]");
|
||||
return;
|
||||
}
|
||||
else if ((sCmdName == "unstick") && (!sChannel.empty()))
|
||||
{
|
||||
MCString::iterator it = FindNV(sChannel);
|
||||
if (it != EndNV())
|
||||
DelNV(it);
|
||||
SetNV(sChannel, sCommand.Token(2));
|
||||
PutModule("Stuck " + sChannel);
|
||||
}
|
||||
|
||||
PutModule("UnStuck " + sChannel);
|
||||
void OnUnstickCommand(const CString& sCommand) {
|
||||
CString sChannel = sCommand.Token(1);
|
||||
if (sChannel.empty()) {
|
||||
PutModule("Usage: Unstick <#channel>");
|
||||
return;
|
||||
}
|
||||
else if ((sCmdName == "list") && (sChannel.empty()))
|
||||
MCString::iterator it = FindNV(sChannel);
|
||||
if (it != EndNV())
|
||||
DelNV(it);
|
||||
PutModule("Unstuck " + sChannel);
|
||||
}
|
||||
|
||||
void OnListCommand(const CString& sCommand) {
|
||||
int i = 1;
|
||||
for (MCString::iterator it = BeginNV(); it != EndNV(); ++it, i++)
|
||||
{
|
||||
int i = 1;
|
||||
for (MCString::iterator it = BeginNV(); it != EndNV(); ++it, i++)
|
||||
{
|
||||
if (it->second.empty())
|
||||
PutModule(CString(i) + ": " + it->first);
|
||||
else
|
||||
PutModule(CString(i) + ": " + it->first + " (" + it->second + ")");
|
||||
}
|
||||
PutModule(" -- End of List");
|
||||
}
|
||||
else
|
||||
{
|
||||
PutModule("USAGE: [un]stick #channel [key], list");
|
||||
if (it->second.empty())
|
||||
PutModule(CString(i) + ": " + it->first);
|
||||
else
|
||||
PutModule(CString(i) + ": " + it->first + " (" + it->second + ")");
|
||||
}
|
||||
PutModule(" -- End of List");
|
||||
}
|
||||
|
||||
virtual void RunJob()
|
||||
|
||||
Reference in New Issue
Block a user