X-Git-Url: https://git.hcoop.net/clinton/bobotpp.git/blobdiff_plain/cb21075d829be5ad97d026daf76061c13d4bc171..6b7614a8f1ae00cb470a620af4e0b6ffbbaa1951:/source/UserCommands.C diff --git a/source/UserCommands.C b/source/UserCommands.C index 0b01aaa..199e9ef 100644 --- a/source/UserCommands.C +++ b/source/UserCommands.C @@ -1,6 +1,6 @@ // UserCommands.C -*- C++ -*- // Copyright (c) 1997, 1998 Etienne BERNARD -// Copyright (C) 2002 Clinton Ebadi +// Copyright (C) 2002,2005 Clinton Ebadi // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -14,19 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifdef HAVE_CONFIG_H #include "config.h" #endif #include +#include +#include +#include +#include #include #include #include #include #include -#include +#include #ifndef _X_OPEN_SOURCE #define _X_OPEN_SOURCE #endif @@ -41,6 +45,7 @@ #include "Commands.H" #include "UserCommands.H" #include "DCCConnection.H" +#include "DCCManager.H" #include "Parser.H" #include "Macros.H" #include "StringTokenizer.H" @@ -69,13 +74,13 @@ UserCommands::AddUser(ServerConnection *cnx, Person *from, String mask, who, maskChannel, level, prot, aop, expiration, passwd; - mask = who = st.nextToken(); - maskChannel = st.nextToken(); - level = st.nextToken(); - prot = st.nextToken(); - aop = st.nextToken(); - expiration = st.nextToken(); - passwd = st.nextToken(); + mask = who = st.next_token(); + maskChannel = st.next_token(); + level = st.next_token(); + prot = st.next_token(); + aop = st.next_token(); + expiration = st.next_token(); + passwd = st.next_token(); if (mask == "" || maskChannel == "" || level == "" || prot == "" || aop == "") { @@ -83,13 +88,13 @@ UserCommands::AddUser(ServerConnection *cnx, Person *from, return; } -// if (!Utils::isWildcard(mask)) { +// if (!Utils::wildcard_p(mask)) { // mask = cnx->bot->getUserhost(channel, who); // if (mask == "") { // from->sendNotice(String("\002I can not find\002 ") + who); // return; // } -// mask = Utils::makeWildcard(mask); +// mask = Utils::make_wildcard(mask); // } // if (cnx->bot->userList->isInUserList(mask, maskChannel)) { @@ -105,7 +110,7 @@ UserCommands::AddUser(ServerConnection *cnx, Person *from, l = atoi((const char *)level); if (l < 0 || l > User::FRIEND) return; - if (l > Utils::getLevel(cnx->bot, from->getAddress())) { + if (l > Utils::get_level(cnx->bot, from->getAddress())) { from->sendNotice("\002You can not give a level greater than yours.\002"); return; } @@ -116,7 +121,7 @@ UserCommands::AddUser(ServerConnection *cnx, Person *from, if (a != 0 && a != 1) return; - e = Utils::strToTime(expiration); + e = Utils::str2time(expiration); if (!e) e = -1; @@ -130,11 +135,11 @@ UserCommands::AddUser(ServerConnection *cnx, Person *from, from->sendNotice(String("\002Added\002 ") + mask + " \002on channels\002 " + maskChannel); from->sendNotice(String("\002Level:\002 ") + - Utils::levelToStr(l) + + Utils::level2str(l) + " \002Protection:\002 " + - Utils::protToStr(p) + + Utils::prot2str(p) + " \002Auto-op:\002 " + - Utils::boolToStr(a)); + Utils::bool2str(a)); } else from->sendNotice(m.getMessage ()); @@ -152,11 +157,11 @@ UserCommands::AddServer(ServerConnection *cnx, Person *from, } StringTokenizer st(rest); - String serverName = st.nextToken(); + String serverName = st.next_token(); int port = 6667; - if (st.hasMoreTokens()) { - String temp = st.nextToken(); + if (st.more_tokens_p()) { + String temp = st.next_token(); port = atoi((const char *)temp); } @@ -178,11 +183,11 @@ UserCommands::AddShit(ServerConnection *cnx, Person *from, StringTokenizer st(rest); String mask, who, maskChannel, level, expiration, reason; - mask = who = st.nextToken(); - maskChannel = st.nextToken(); - level = st.nextToken(); - expiration = st.nextToken(); - reason = st.rest().trim(); + mask = who = st.next_token(); + maskChannel = st.next_token(); + level = st.next_token(); + expiration = st.next_token(); + reason = Utils::trim_str (st.rest()); /* if (mask == "" || maskChannel == "" || level == "") { from->sendNotice("\002Invalid syntax for this command.\002"); @@ -196,13 +201,13 @@ UserCommands::AddShit(ServerConnection *cnx, Person *from, */ /* - if (!Utils::isWildcard(mask)) { + if (!Utils::wildcard_p(mask)) { mask = cnx->bot->getUserhost(channel, who); if (mask == "") { from->sendNotice(String("\002I can not find\002 ") + who); return; } - mask = Utils::makeWildcard(mask); + mask = Utils::make_wildcard(mask); if (cnx->bot->shitList->getShit(mask, maskChannel)) { from->sendNotice(mask + " \002is already in shitlist on channel(s)\002 " + maskChannel); @@ -217,7 +222,7 @@ UserCommands::AddShit(ServerConnection *cnx, Person *from, if (l < 0 || l > ShitEntry::SHIT_NODEBAN) return; - e = Utils::strToTime(expiration); + e = Utils::str2time(expiration); if (!e) e = -1; @@ -247,9 +252,8 @@ UserCommands::Alias(ServerConnection *cnx, Person *from, String channel, String rest) { StringTokenizer st(rest); - String newF = st.nextToken().toUpper(); - String oldF = st.nextToken().toUpper(); - std::list::iterator it; + String newF = Utils::to_upper (st.next_token()); + String oldF = Utils::to_upper (st.next_token()); if (newF == "" || oldF == "") { from->sendNotice("\002Invalid syntax for this command.\002"); @@ -257,36 +261,22 @@ UserCommands::Alias(ServerConnection *cnx, Person *from, } // First, we check that the "new" function does not exist - for (it = cnx->bot->userFunctions.begin(); it != - cnx->bot->userFunctions.end(); ++it) - if (newF == (*it)->name) { + if (cnx->bot->userFunctions[newF]) { from->sendNotice(newF + " \002is already an alias.\002"); return; - } + } // Next, we check that the "old" function exist - bool found = false; - userFunction *u; - for (it = cnx->bot->userFunctions.begin(); it != - cnx->bot->userFunctions.end(); ++it) - if (oldF == (*it)->name) { - found = true; - u = *it; - break; + if (!cnx->bot->userFunctions[oldF]) + { + from->sendNotice(String("\002I don't know the\002 ") + oldF + + " \002command."); + return; } - if (!found) { - from->sendNotice(String("\002I don't know the\002 ") + oldF + - " \002command."); - return; - } // Fine, we do the binding - cnx->bot->userFunctions.push_back(new - userFunction((char *)(const char - *)newF, - u->function, - u->minLevel, - u->needsChannelName)); + cnx->bot->userFunctions[newF] = + new userFunction (*cnx->bot->userFunctions[oldF]); from->sendNotice("\002Alias added.\002"); } @@ -332,16 +322,16 @@ UserCommands::BanList(ServerConnection *cnx, Person *from, // StringTokenizer st(rest); // String who; -// String mask = who = st.nextToken(); -// String maskChannel = st.nextToken(); -// String level = st.nextToken(); +// String mask = who = st.next_token(); +// String maskChannel = st.next_token(); +// String level = st.next_token(); // if (mask == "" || maskChannel == "" || level == "") { // from->sendNotice("\002Invalid syntax for this command.\002"); // return; // } -// if (!Utils::isWildcard(mask)) { +// if (!Utils::wildcard_p(mask)) { // mask = cnx->bot->getUserhost(channel, who); // if (mask == "") { // from->sendNotice(String("\002I can not find\002 ") + who); @@ -366,12 +356,12 @@ UserCommands::BanList(ServerConnection *cnx, Person *from, // return; // } -// if (l > Utils::getLevel(cnx->bot, from->getAddress())) { +// if (l > Utils::get_level(cnx->bot, from->getAddress())) { // from->sendNotice("\002You can not give a level greater than yours.\002"); // return; // } -// if (Utils::getLevel(cnx->bot, from->getAddress()) < uli->level) { +// if (Utils::get_level(cnx->bot, from->getAddress()) < uli->level) { // from->sendNotice("\002You can not change the level for a person " // "whose level is greater than yours.\002"); // return; @@ -418,13 +408,13 @@ UserCommands::DCCList(ServerConnection *cnx, Person *from, from->sendNotice("\002DCClist:\002"); from->sendNotice("\002Hostname Last used\002"); - for (std::list::iterator it = - cnx->bot->dccConnections.begin(); - it != cnx->bot->dccConnections.end(); + for (DCC_MAP::iterator it = + cnx->bot->dccConnections->dcc_map.begin (); + it != cnx->bot->dccConnections->dcc_map.end(); ++it) { - from->sendNotice((*it)->nuh.pad(32) + " " + + from->sendNotice(String(it->second->dcc->get_nuh()).pad(32) + " " + String((long)(current_time - - (*it)->lastSpoken))); + it->second->dcc->get_lastSpoken()))); } from->sendNotice("\002End of dcclist.\002"); @@ -474,21 +464,21 @@ UserCommands::DelUser(ServerConnection *cnx, Person *from, StringTokenizer st(rest); String who; - String mask = who = st.nextToken(); - String maskChannel = st.nextToken(); + String mask = who = st.next_token(); + String maskChannel = st.next_token(); if (mask == "" || maskChannel == "") { from->sendNotice("\002Invalid syntax for this command.\002"); return; } - if (!Utils::isWildcard(mask)) { + if (!Utils::wildcard_p(mask)) { mask = cnx->bot->getUserhost(channel, who); if (mask == "") { from->sendNotice(String("\002I can not find\002 ") + who); return; } - mask = Utils::makeWildcard(mask); + mask = Utils::make_wildcard(mask); } if (!cnx->bot->userList->isInUserList(mask, maskChannel)) { @@ -510,21 +500,21 @@ UserCommands::DelShit(ServerConnection *cnx, Person *from, StringTokenizer st(rest); String who; - String mask = who = st.nextToken(); - String maskChannel = st.nextToken(); + String mask = who = st.next_token(); + String maskChannel = st.next_token(); if (mask == "" || maskChannel == "") { from->sendNotice("\002Invalid syntax for this command.\002"); return; } - if (!Utils::isWildcard(mask)) { + if (!Utils::wildcard_p(mask)) { mask = cnx->bot->getUserhost(channel, who); if (mask == "") { from->sendNotice(String("\002I can not find\002 ") + who); return; } - mask = Utils::makeWildcard(mask); + mask = Utils::make_wildcard(mask); } if (!cnx->bot->shitList->getShit(mask, maskChannel)) { @@ -589,14 +579,14 @@ UserCommands::Help(ServerConnection *cnx, Person *from, { if (rest.length() == 0) { from->sendNotice("\002Available topics for you are:\002"); - int level = Utils::getLevel(cnx->bot, from->getAddress()); + int level = Utils::get_level(cnx->bot, from->getAddress()); String result = ""; int length = 0; - std::list::iterator it; + std::map >::iterator it; for (it = cnx->bot->userFunctions.begin(); it != cnx->bot->userFunctions.end(); ++it) - if ((*it)->minLevel <= level) { - result = result + (*it)->name + " "; - length += strlen((*it)->name) + 1; + if ((*it).second->minLevel <= level) { + result = result + (*it).first + " "; + length += (*it).first.length() + 1; if (length >= 256) { from->sendNotice(result); result = ""; length = 0; @@ -610,7 +600,7 @@ UserCommands::Help(ServerConnection *cnx, Person *from, } StringTokenizer st(rest); - String command = st.nextToken().toUpper(); + String command = Utils::to_upper (st.next_token()); std::ifstream helpFile(cnx->bot->helpFileName); if (!helpFile) { @@ -700,9 +690,9 @@ UserCommands::Join(ServerConnection *cnx, Person *from, String channel, String rest) { StringTokenizer st(rest); - channel = st.nextToken(); + channel = st.next_token(); - if (!Utils::isValidChannelName(channel)) { + if (!Utils::valid_channel_name_p(channel)) { from->sendNotice(String("\002") + channel + " is not a valid channel name\002"); return; @@ -753,9 +743,9 @@ UserCommands::Kick(ServerConnection *cnx, Person *from, } StringTokenizer st(rest); - String who = st.nextToken(); + String who = st.next_token(); - if (Utils::isWildcard(who)) { + if (Utils::wildcard_p(who)) { User * u = c->getUser(nick); if (!u) return; @@ -772,7 +762,7 @@ UserCommands::Kick(ServerConnection *cnx, Person *from, return; } - if (Utils::isWildcard(who)) { + if (Utils::wildcard_p(who)) { Mask m(who); for (std::map >::iterator it = c->channelMemory.begin(); @@ -805,7 +795,7 @@ UserCommands::KickBan(ServerConnection *cnx, Person *from, { StringTokenizer st(rest); - Ban(cnx, 0, channel, st.nextToken()); + Ban(cnx, 0, channel, st.next_token()); Kick(cnx, from, channel, rest); } @@ -866,7 +856,7 @@ UserCommands::Msg(ServerConnection *cnx, Person *from, String channel, String rest) { StringTokenizer st(rest); - String who = st.nextToken(); + String who = st.next_token(); String message = st.rest(); Message m = Commands::Msg(cnx->bot, who, message); @@ -938,14 +928,14 @@ UserCommands::Nick(ServerConnection *cnx, Person *from, { // We parse the parameters StringTokenizer st(rest); - String nick = st.nextToken(); + String nick = st.next_token(); if (rest == "") { from->sendNotice(String("\002No nickname given.\002")); return; } - if (!Utils::isValidNickName(nick)) { + if (!Utils::valid_nickname_p (cnx->bot, nick)) { from->sendNotice(String("\002") + nick + " is not a valid nickname\002"); return; @@ -969,7 +959,7 @@ UserCommands::NsLookup(ServerConnection *cnx, Person *from, if (rest.find('.') == -1) { StringTokenizer st(cnx->bot->getUserhost("", rest)); - st.nextToken('@'); + st.next_token('@'); target = st.rest(); if (target.length() == 0) { from->sendNotice(String("\002I could not find\002 ") + @@ -1021,7 +1011,7 @@ UserCommands::Op(ServerConnection *cnx, Person *from, return; } - if (Utils::isWildcard(rest)) { + if (Utils::wildcard_p(rest)) { from->sendNotice("\002Mass op is not allowed.\002"); return; } @@ -1180,13 +1170,28 @@ UserCommands::ServerList(ServerConnection *cnx, Person *from, from->sendNotice("\002End of server list.\002"); } + +void +UserCommands::SetFloodRate(ServerConnection *cnx, Person *from, + String channel, String rest) +{ + Message m = Commands::SetFloodRate (cnx->bot, std::atoi (rest)); + if (m.getCode ()) + from->sendNotice (m.getMessage ()); + else + from->sendNotice ("Flood Rate set to:" + String(std::atol(rest))); +} + void UserCommands::SetVersion(ServerConnection *cnx, Person *from, String channel, String rest) { Message m = Commands::SetVersion(cnx->bot, rest); + if (m.getCode() < 0) - from->sendNotice(m.getMessage()); + { + Commands::Notice (cnx->bot, from->getNick (), m.getMessage()); + } } void @@ -1301,8 +1306,8 @@ UserCommands::TBan(ServerConnection *cnx, Person *from, Channel * c = cnx->bot->channelList->getChannel(channel); StringTokenizer st(rest); - String who = st.nextToken(); - String t = st.nextToken(); + String who = st.next_token(); + String t = st.next_token(); String dest; if (who == "" || t == "") { @@ -1311,7 +1316,7 @@ UserCommands::TBan(ServerConnection *cnx, Person *from, return; } - if (Utils::isWildcard(who) && from) { + if (Utils::wildcard_p(who) && from) { User * u = c->getUser(from->getNick()); if (u && u->getLevel() < User::TRUSTED_USER) { if (from) @@ -1328,7 +1333,7 @@ UserCommands::TBan(ServerConnection *cnx, Person *from, return; } - if (!Utils::isWildcard(who)) + if (!Utils::wildcard_p(who)) dest = cnx->bot->getUserhost(channel, who); else dest = who; @@ -1341,13 +1346,13 @@ UserCommands::TBan(ServerConnection *cnx, Person *from, time_t w; - if ((w = Utils::strToTime(t)) == 0) { + if ((w = Utils::str2time(t)) == 0) { if (from) from->sendNotice(t + " \002is an invalid time.\002"); return; } - dest = Utils::makeWildcard(dest); + dest = Utils::make_wildcard(dest); Mask m(dest); for (std::list::iterator it = cnx->bot->userList->l.begin(); @@ -1379,8 +1384,8 @@ UserCommands::TKBan(ServerConnection *cnx, Person *from, String channel, String rest) { StringTokenizer st(rest); - String who = st.nextToken(); - String t = st.nextToken(); + String who = st.next_token(); + String t = st.next_token(); TBan(cnx, 0, channel, who + " " + t); Kick(cnx, from, channel, who + " " + st.rest()); @@ -1420,13 +1425,18 @@ UserCommands::UserList(ServerConnection *cnx, Person *from, for (std::list::iterator it = cnx->bot->userList->l.begin(); it != cnx->bot->userList->l.end(); it++) - from->sendNotice((*it)->mask.getMask().pad(25) + " " + - (*it)->channelMask.getMask().pad(10) + " " + - Utils::levelToStr((*it)->level).pad(12) + " " + - Utils::protToStr((*it)->prot).pad(7) + " " + - Utils::boolToStr((*it)->aop).pad(5) + " " + - String((long)(*it)->expirationDate)); - + from->sendNotice((*it)->mask.getMask().pad(25) + + " " + + (*it)->channelMask.getMask().pad(10) + + " " + + String(Utils::level2str((*it)->level)).pad(12) + + " " + + String(Utils::prot2str((*it)->prot)).pad(7) + + " " + + String(Utils::bool2str((*it)->aop)).pad(5) + + " " + + String(Utils::long2str ((*it)->expirationDate))); + from->sendNotice("\002End of userlist.\002"); } @@ -1449,16 +1459,16 @@ UserCommands::Who(ServerConnection *cnx, Person *from, uli->mask.getMask() + " \002on\002 " + uli->channelMask.getMask()); from->sendNotice(String("\002Lvl:\002 ") + - Utils::levelToStr(uli->level) + + Utils::level2str(uli->level) + " \002Prot:\002 " + - Utils::protToStr(uli->prot) + + Utils::prot2str(uli->prot) + " \002Aop:\002 " + - Utils::boolToStr(uli->aop) + + Utils::bool2str(uli->aop) + " \002Expired:\002 " + - Utils::boolToStr(!uli->isStillValid()) + + Utils::bool2str(!uli->isStillValid()) + " \002Ident:\002 " + (uli && !uli->identified ? "\026" : "") + - Utils::boolToStr(uli && uli->identified) + + Utils::bool2str(uli && uli->identified) + (uli && !uli->identified ? "\026" : "")); } else from->sendNotice(String("\002You are not in the userlist for\002 ") + @@ -1477,7 +1487,7 @@ UserCommands::Whois(ServerConnection *cnx, Person *from, } StringTokenizer st(rest); - String otherNick = st.nextToken(); + String otherNick = st.next_token(); User * u = cnx->bot->channelList->getChannel(channel)->getUser(otherNick); UserListItem * uli; @@ -1495,15 +1505,15 @@ UserCommands::Whois(ServerConnection *cnx, Person *from, " \002is\002 " + uli->mask.getMask() + " \002on\002 " + uli->channelMask.getMask()); from->sendNotice(String("\002Lvl:\002 ") + - Utils::levelToStr(uli->level) + + Utils::level2str(uli->level) + " \002Prot:\002 " + - Utils::protToStr(uli->prot) + + Utils::prot2str(uli->prot) + " \002Aop:\002 " + - Utils::boolToStr(uli->aop) + + Utils::bool2str(uli->aop) + " \002Expired:\002 " + - Utils::boolToStr(!uli->isStillValid()) + + Utils::bool2str(!uli->isStillValid()) + " \002Ident:\002 " + - Utils::boolToStr(uli && uli->identified)); + Utils::bool2str(uli && uli->identified)); } else from->sendNotice(otherNick + " \002is not in the userlist for\002 " +