// 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
// 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 <fstream>
+#include <map>
+#include <string>
+#include <cctype>
+#include <cstdlib>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
-#include <ctype.h>
+#include <cstdlib>
#ifndef _X_OPEN_SOURCE
#define _X_OPEN_SOURCE
#endif
#include "Commands.H"
#include "UserCommands.H"
#include "DCCConnection.H"
+#include "DCCManager.H"
#include "Parser.H"
#include "Macros.H"
#include "StringTokenizer.H"
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 == "") {
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)) {
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;
}
if (a != 0 && a != 1)
return;
- e = Utils::strToTime(expiration);
+ e = Utils::str2time(expiration);
if (!e)
e = -1;
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 ());
}
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);
}
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");
*/
/*
- 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);
if (l < 0 || l > ShitEntry::SHIT_NODEBAN)
return;
- e = Utils::strToTime(expiration);
+ e = Utils::str2time(expiration);
if (!e)
e = -1;
String channel, String rest)
{
StringTokenizer st(rest);
- String newF = st.nextToken().toUpper();
- String oldF = st.nextToken().toUpper();
- std::list<userFunction *>::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");
}
// 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");
}
// 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);
// 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;
from->sendNotice("\002DCClist:\002");
from->sendNotice("\002Hostname Last used\002");
- for (std::list<DCCConnection *>::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");
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)) {
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)) {
{
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<userFunction *>::iterator it;
+ std::map<std::string, class userFunction*, std::less<std::string> >::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;
}
StringTokenizer st(rest);
- String command = st.nextToken().toUpper();
+ String command = Utils::to_upper (st.next_token());
std::ifstream helpFile(cnx->bot->helpFileName);
if (!helpFile) {
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;
}
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;
return;
}
- if (Utils::isWildcard(who)) {
+ if (Utils::wildcard_p(who)) {
Mask m(who);
for (std::map<String, User *, std::less<String> >::iterator it =
c->channelMemory.begin();
{
StringTokenizer st(rest);
- Ban(cnx, 0, channel, st.nextToken());
+ Ban(cnx, 0, channel, st.next_token());
Kick(cnx, from, channel, rest);
}
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);
{
// 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;
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 ") +
return;
}
- if (Utils::isWildcard(rest)) {
+ if (Utils::wildcard_p(rest)) {
from->sendNotice("\002Mass op is not allowed.\002");
return;
}
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
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 == "") {
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)
return;
}
- if (!Utils::isWildcard(who))
+ if (!Utils::wildcard_p(who))
dest = cnx->bot->getUserhost(channel, who);
else
dest = who;
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<UserListItem *>::iterator it = cnx->bot->userList->l.begin();
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());
for (std::list<UserListItem *>::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");
}
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 ") +
}
StringTokenizer st(rest);
- String otherNick = st.nextToken();
+ String otherNick = st.next_token();
User * u = cnx->bot->channelList->getChannel(channel)->getUser(otherNick);
UserListItem * uli;
" \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 " +