void ClearCommand(const CString& sLine) { CString name = sLine.Token(1, false, " "); CAlias clear_alias; if (CAlias::AliasGet(clear_alias, this, name)) { clear_alias.AliasCmds().clear(); clear_alias.Commit(); PutModule("Modified alias."); } else PutModule("Alias does not exist."); }
void Swap(const CString& sCommand) { u_int iNumA = sCommand.Token(1).ToUInt(); u_int iNumB = sCommand.Token(2).ToUInt(); if (iNumA > m_vPerform.size() || iNumA <= 0 || iNumB > m_vPerform.size() || iNumB <= 0) { PutModule("Illegal # Requested"); } else { std::iter_swap(m_vPerform.begin() + (iNumA - 1), m_vPerform.begin() + (iNumB - 1)); PutModule("Commands Swapped."); Save(); } }
virtual void OnModCommand(const CString& sCommand) { CString sResult; VCString vsResult; CString sCmd = sCommand; if (sCmd.Token(0).CaseCmp(".tcl") == 0) sCmd = sCmd.Token(1,true); if (sCmd.Left(1).CaseCmp(".") == 0) sCmd = "Binds::ProcessDcc - - {" + sCmd + "}"; Tcl_Eval(interp, sCmd.c_str()); sResult = CString(Tcl_GetStringResult(interp)); if (!sResult.empty()) { sResult.Split("\n", vsResult); unsigned int a = 0; for (a = 0; a < vsResult.size(); a++) PutModule(vsResult[a].TrimRight_n()); } }
void HandleAdd(const CString& sLine) { CString sMsg = sLine.Token(1, true); bool bHelp = false; bool bNegated = sMsg.TrimPrefix("!"); CString sChan = sMsg.Token(0); CString sSearch = sMsg.Token(1); CString sHost = sMsg.Token(2); if (sChan.empty()) { bHelp = true; } else if (Add(bNegated, sChan, sSearch, sHost)) { PutModule("Added to list"); } else { PutModule(sLine.Token(1, true) + " is already added"); bHelp = true; } if (bHelp) { PutModule("Usage: Add [!]<#chan> <search> <host>"); PutModule("Wildcards are allowed"); } }
void Del(const CString& sCommand) { u_int iNum = sCommand.Token(1, true).ToUInt(); if (iNum > m_vPerform.size() || iNum <= 0) { PutModule("Illegal # Requested"); return; } else { m_vPerform.erase(m_vPerform.begin() + iNum - 1); PutModule("Command Erased."); } Save(); }
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()); }
bool CIRCNetwork::AddServer(const CString& sName) { if (sName.empty()) { return false; } bool bSSL = false; CString sLine = sName; sLine.Trim(); CString sHost = sLine.Token(0); CString sPort = sLine.Token(1); if (sPort.TrimPrefix("+")) { bSSL = true; } unsigned short uPort = sPort.ToUShort(); CString sPass = sLine.Token(2, true); return AddServer(sHost, uPort, sPass, bSSL); }
void Add(const CString& sCommand) { CString sPerf = sCommand.Token(1, true); if (sPerf.empty()) { PutModule("Usage: add <command>"); return; } m_vPerform.push_back(ParsePerform(sPerf)); PutModule("Added!"); Save(); }
void CLogMod::SetRulesCmd(const CString& sLine) { VCString vsRules = SplitRules(sLine.Token(1, true)); if (vsRules.empty()) { PutModule("Usage: SetRules <rules>"); PutModule("Wildcards are allowed"); } else { SetRules(vsRules); SetNV("rules", JoinRules(",")); ListRulesCmd(); } }
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; } m_sMethod = sArg; 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 OnNewOnlyCommand(const CString& sCommand) { const CString& sArg = sCommand.Token(1, true).AsLower(); if (sArg.empty()) { PutModule("Usage: NewOnly <on|off>"); return; } m_bNewOnly = sArg.ToBool(); SaveSettings(); PutModule("Saved."); }
virtual bool OnLoad(const CString& sArgs, CString& sMessage) override { VCString vsChans; sArgs.Split(" ", vsChans, false); for (VCString::const_iterator it = vsChans.begin(); it != vsChans.end(); ++it) { CString sAdd = *it; bool bNegated = sAdd.TrimPrefix("!"); CString sChan = sAdd.Token(0); CString sSearch = sAdd.Token(1); CString sHost = sAdd.Token(2, true); if (!Add(bNegated, sChan, sSearch, sHost)) { PutModule("Unable to add [" + *it + "]"); } } // Load our saved settings, ignore errors MCString::iterator it; for (it = BeginNV(); it != EndNV(); ++it) { CString sAdd = it->first; bool bNegated = sAdd.TrimPrefix("!"); CString sChan = sAdd.Token(0); CString sSearch = sAdd.Token(1); CString sHost = sAdd.Token(2, true); Add(bNegated, sChan, sSearch, sHost); } return true; }
void GetChan(const CString& sLine) { const CString var = sLine.Token(1).AsLower(); CString username = sLine.Token(2); CString chan = sLine.Token(3, true); if (var.empty()) { PutModule("Usage: getchan <variable> [username] <chan>"); return; } if (chan.empty()) { chan = username; username = ""; } if (username.empty()) { username = m_pUser->GetUserName(); } CUser* user = GetUser(username); if (!user) return; CChan* pChan = user->FindChan(chan); if (!pChan) { PutModule("Error: Channel not found: " + chan); return; } if (var == "defmodes") PutModule("DefModes = " + pChan->GetDefaultModes()); else if (var == "buffer") PutModule("Buffer = " + CString(pChan->GetBufferCount())); else if (var == "inconfig") PutModule("InConfig = " + pChan->InConfig()); else if (var == "keepbuffer") PutModule("KeepBuffer = " + pChan->KeepBuffer()); else if (var == "detached") PutModule("Detached = " + pChan->IsDetached()); else PutModule("Error: Unknown variable"); }
void CIdentServerMod::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", "Status"); Table.SetCell("Description", "Displays status information about IdentServer"); PutModule(Table); return; } else if(sCommand.Equals("STATUS")) { if(m_identServer) { PutModule("IdentServer is listening on: " + m_identServer->GetLocalIP() + ":" + CString(m_serverPort)); if(m_pUser->IsAdmin()) { PutModule("List of active users/networks:"); for(CIRCNetwork* pNetwork : m_identServer->GetActiveUsers()) { PutModule("* " + pNetwork->GetUser()->GetCleanUserName() + "/" + pNetwork->GetName()); } } } else { if(m_listenFailed) { PutModule("WARNING: Opening the listening socket failed!"); } PutModule("IdentServer isn't listening."); } if(m_pUser->IsAdmin()) { PutModule("Last IDENT request: " + m_sLastRequest); PutModule("Last IDENT reply: " + m_sLastReply); } } else { PutModule("Unknown command [" + sCommand + "] try 'Help'"); } }
EModRet OnRaw(CString& sLine) override { const CString sCmd = sLine.Token(1); if ((sCmd == "375" /* begin of MOTD */ || sCmd == "372" /* MOTD */) && !ShouldTemporarilyAcceptMotd()) return HALT; if (sCmd == "376" /* End of MOTD */) { if (!ShouldTemporarilyAcceptMotd()) { sLine = sLine.Token(0) + " 422 " + sLine.Token(2) + " :" + t_s("MOTD blocked by ZNC"); } StopTemporarilyAcceptingMotd(); } if (sCmd == "422") { // Server has no MOTD StopTemporarilyAcceptingMotd(); } return CONTINUE; }
void CreateUserCommand(const CString &sLine) { CString sCreate = sLine.Token(1); if (!sCreate.empty()) { SetNV("CreateUser", sCreate); } if (CreateUser()) { PutModule("We will create users on their first login"); } else { PutModule("We will not create users on their first login"); } }
bool CUser::AddServer(const CString& sName) { if (sName.empty()) { return false; } bool bSSL = false; CString sLine = sName; sLine.Trim(); CString sHost = sLine.Token(0); CString sPort = sLine.Token(1); if (sPort.Left(1) == "+") { bSSL = true; sPort.LeftChomp(); } unsigned short uPort = sPort.ToUShort(); CString sPass = sLine.Token(2, true); return AddServer(sHost, uPort, sPass, bSSL); }
virtual void OnModCommand(const CString& sCommand) { const CString sCmd = sCommand.Token(0); const CString sArgs = sCommand.Token(1, true); if (sCmd.Equals("silent")) { if (sArgs.Equals("yes")) { SetNV("silent_timeouts", "yes"); PutModule("Disabled timeout messages"); } else if (sArgs.Equals("no")) { DelNV("silent_timeouts"); PutModule("Enabled timeout messages"); } else if (sArgs.empty()) { if (GetNV("silent_timeouts") == "yes") PutModule("Timeout messages are disabled"); else PutModule("Timeout message are enabled"); } else PutModule("Invalid argument"); } else { PutModule("Available commands: silent [yes/no], silent"); } }
virtual 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")) { CString sFile; if (DecryptChannel(sArgs, sFile)) { VCString vsLines; VCString::iterator it; sFile.Split("\n", vsLines); for (it = vsLines.begin(); it != vsLines.end(); ++it) { CString sLine(*it); sLine.Trim(); PutModule("[" + sLine + "]"); } } PutModule("//!-- EOF " + sArgs); } else if (sCommand.Equals("replay")) { Replay(sArgs); PutModule("Replayed " + sArgs); } else if (sCommand.Equals("save")) { SaveBufferToDisk(); PutModule("Done."); } else PutModule("Unknown command [" + sCommand + "]"); }
void CloneUserCommand(const CString &sLine) { CString sUsername = sLine.Token(1); if (!sUsername.empty()) { SetNV("CloneUser", sUsername); } if (ShouldCloneUser()) { PutModule("We will clone [" + CloneUser() + "]"); } else { PutModule("We will not clone a user"); } }
void SilentCommand(const CString& sLine) { const CString sArg = sLine.Token(1, true); if (!sArg.empty()) { SetNV("silent", CString(sArg.ToBool())); } if (GetNV("silent").ToBool()) { PutModule(t_s("Module messages are disabled")); } else { PutModule(t_s("Module messages are enabled")); } }
void LinesCommand(const CString& sLine) { const CString sArg = sLine.Token(1, true); if (sArg.empty()) { PutModule(t_f("Lines limit is {1}")(m_iThresholdMsgs)); } else { m_iThresholdMsgs = sArg.ToUInt(); if (m_iThresholdMsgs == 0) m_iThresholdMsgs = 2; PutModule(t_f("Set lines limit to {1}")(m_iThresholdMsgs)); Save(); } }
bool CModule::HandleCommand(const CString& sLine) { const CString& sCmd = sLine.Token(0); const CModCommand* pCmd = FindCommand(sCmd); if (pCmd) { pCmd->Call(this, sLine); return true; } OnUnknownModCommand(sLine); return false; }
EModRet OnUserRaw(CString& sLine) override { // We dont care if we are not connected to IRC if (!GetNetwork()->IsIRCConnected()) return CONTINUE; // We are trying to get the config nick and this is a /nick? if (!m_pTimer || !sLine.Token(0).Equals("NICK")) return CONTINUE; // Is the nick change for the nick we are trying to get? CString sNick = sLine.Token(1); // Don't even think of using spaces in your nick! if (sNick.Left(1) == ":") sNick.LeftChomp(); if (!sNick.Equals(GetNick())) return CONTINUE; // Indeed trying to change to this nick, generate a 433 for it. // This way we can *always* block incoming 433s from the server. PutUser(":" + GetNetwork()->GetIRCServer() + " 433 " + GetNetwork()->GetIRCNick().GetNick() + " " + sNick + " :ZNC is already trying to get this nickname"); return CONTINUE; }
virtual bool OnLoad(const CString& sArgs, CString& sMessage) { if (sArgs.Trim_n().empty()) { return true; // use defaults } m_sServer = sArgs.Token(0); CString sPort = sArgs.Token(1); m_sUserFormat = sArgs.Token(2); if (sPort.Left(1) == "+") { m_bSSL = true; sPort.LeftChomp(); } unsigned short uPort = sPort.ToUShort(); if (uPort) { m_uPort = uPort; } return true; }
// Unblocks a user from the blocked list. 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"); }
void OnDelKeyCommand(const CString& sCommand) { CString sTarget = sCommand.Token(1); if (!sTarget.empty()) { if (DelNV(sTarget.AsLower())) { PutModule("Target [" + sTarget + "] deleted"); } else { PutModule("Target [" + sTarget + "] not found"); } } else { PutModule("Usage DelKey <#chan|Nick>"); } }
void AddCmd(const CString& sCommand) { CString sPattern = sCommand.Token(1); if (IsValid(sPattern)) { if (Add(sPattern)) { PutModule("Pattern added"); } else { PutModule("Pattern already exists"); } } else { PutModule("Pattern has errors"); } }
void HandleIgnoreCommand(const CString& sLine) { CString sHostmask = sLine.Token(1); CString sType = sLine.Token(2); if (sType.empty()) { sType = "all"; } else if (sType.Equals("*")) { sType = "all"; } if (!(sType.Equals("all") || sType.Equals("privmsg") || sType.Equals("notice") || sType.Equals("ctcp"))) { PutModule("Unknown type"); return; } CIgnore Ignore(sHostmask, sType); m_vIgnores.push_back(Ignore); Save(); PutModule("Ignore added (" + Ignore.GetHostmask() + ")"); }