1 // UserCommands.C -*- C++ -*-
2 // Copyright (c) 1997, 1998 Etienne BERNARD
3 // Copyright (C) 2002,2005 Clinton Ebadi
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include "UserCommands.H"
35 #include <sys/types.h>
36 #include <sys/socket.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
41 #ifndef _X_OPEN_SOURCE
42 #define _X_OPEN_SOURCE
44 #ifndef _X_OPEN_SOURCE_EXTENDED
45 #define _X_OPEN_SOURCE_EXTENDED 1
55 #include "ChannelList.H"
57 #include "DCCConnection.H"
58 #include "DCCManager.H"
59 #include "DCCPerson.H"
66 #include "ServerConnection.H"
67 #include "ServerList.H"
68 #include "ShitEntry.H"
69 #include "StringTokenizer.H"
79 char * crypt(const char *p, const char *s) { return p; }
83 UserCommands::Action(ServerConnection *cnx, Person *from,
84 String channel, String rest)
86 Message m = Commands::Action(cnx->bot, channel, rest);
88 from->sendNotice(m.getMessage());
92 UserCommands::AddUser(ServerConnection *cnx, Person *from,
93 String channel, String rest)
95 StringTokenizer st(rest);
96 String mask, who, maskChannel, level, prot,
97 aop, expiration, passwd;
99 mask = who = st.next_token();
100 maskChannel = st.next_token();
101 level = st.next_token();
102 prot = st.next_token();
103 aop = st.next_token();
104 expiration = st.next_token();
105 passwd = st.next_token();
107 if (mask == "" || maskChannel == "" || level == "" ||
108 prot == "" || aop == "") {
109 from->sendNotice("\002Invalid syntax for this command.\002");
113 // if (!Utils::wildcard_p(mask)) {
114 // mask = cnx->bot->getUserhost(channel, who);
116 // from->sendNotice(String("\002I can not find\002 ") + who);
119 // mask = Utils::make_wildcard(mask);
122 // if (cnx->bot->userList->isInUserList(mask, maskChannel)) {
123 // from->sendNotice(who + " \002is already in userlist on channel(s)\002 " +
132 l = atoi(level.c_str ());
133 if (l < 0 || l > User::FRIEND)
135 if (l > Utils::get_level(cnx->bot, from->getAddress())) {
136 from->sendNotice("\002You can not give a level greater than yours.\002");
139 p = atoi(prot.c_str ());
140 if (p < 0 || p > User::NO_DEOP)
142 a = (bool)atoi(aop.c_str ());
143 if (a != 0 && a != 1)
146 e = Utils::str2time(expiration);
151 // cnx->bot->userList->addUser(mask, maskChannel, l, p, a, e, passwd);
154 Commands::AddUser (cnx->bot, who, maskChannel, l, p, a, e, passwd);
157 from->sendNotice(String("\002Added\002 ") + mask +
158 " \002on channels\002 " + maskChannel);
159 from->sendNotice(String("\002Level:\002 ") +
160 Utils::level2str(l) +
161 " \002Protection:\002 " +
163 " \002Auto-op:\002 " +
167 from->sendNotice(m.getMessage ());
169 // cnx->bot->rehash();
173 UserCommands::AddServer(ServerConnection *cnx, Person *from,
174 String channel, String rest)
176 if (rest.length() == 0) {
177 from->sendNotice("\002You must supply a server name.\002");
181 StringTokenizer st(rest);
182 String serverName = st.next_token();
185 if (st.more_tokens_p()) {
186 String temp = st.next_token();
187 port = atoi(temp.c_str ());
190 Message m = Commands::AddServer(cnx->bot, serverName, port);
191 if (m.getCode() != 0)
192 from->sendNotice(m.getMessage());
194 from->sendNotice(String("\002Server\002 ") +
195 serverName + " \002on port\002 " +
196 String((long)port) + " \002has been added "
197 "to the server list.\002");
200 // FIXME: does this work now
202 UserCommands::AddShit(ServerConnection *cnx, Person *from,
203 String channel, String rest)
205 StringTokenizer st(rest);
206 String mask, who, maskChannel, level, expiration, reason;
208 mask = who = st.next_token();
209 maskChannel = st.next_token();
210 level = st.next_token();
211 expiration = st.next_token();
212 reason = Utils::trim_str (st.rest());
214 /* if (mask == "" || maskChannel == "" || level == "") {
215 from->sendNotice("\002Invalid syntax for this command.\002");
222 reason = "You're on my shitlist, lamer";
226 if (!Utils::wildcard_p(mask)) {
227 mask = cnx->bot->getUserhost(channel, who);
229 from->sendNotice(String("\002I can not find\002 ") + who);
232 mask = Utils::make_wildcard(mask);
233 if (cnx->bot->shitList->getShit(mask, maskChannel)) {
234 from->sendNotice(mask + " \002is already in shitlist on channel(s)\002 " +
243 l = atoi(level.c_str ());
244 if (l < 0 || l > ShitEntry::SHIT_NODEBAN)
247 e = Utils::str2time(expiration);
253 if (cnx->bot->userList->getMaxProt(mask, maskChannel) > 0) {
254 from->sendNotice(String("\002I can not add\002 ") + who +
255 " \002into the shitlist (protection).");
259 cnx->bot->shitList->addShit(mask, maskChannel, l, e, reason);
262 Message M = Commands::AddShit (cnx->bot, mask, maskChannel, l, e, reason);
264 from->sendNotice(String("\002Added\002 ") + mask +
265 " \002on channels\002 " + maskChannel +
266 " \002into the shitlist.\002");
268 from->sendNotice (M.getMessage ());
271 // FIXME: Convert (and change ?)
273 UserCommands::Alias(ServerConnection *cnx, Person *from,
274 String channel, String rest)
276 StringTokenizer st(rest);
277 String newF = Utils::to_upper (st.next_token());
278 String oldF = Utils::to_upper (st.next_token());
280 if (newF == "" || oldF == "") {
281 from->sendNotice("\002Invalid syntax for this command.\002");
285 // First, we check that the "new" function does not exist
286 if (cnx->bot->userFunctions[newF]) {
287 from->sendNotice(newF + " \002is already an alias.\002");
291 // Next, we check that the "old" function exist
292 if (!cnx->bot->userFunctions[oldF])
294 from->sendNotice(String("\002I don't know the\002 ") + oldF +
299 // Fine, we do the binding
300 cnx->bot->userFunctions[newF] =
301 new userFunction (*cnx->bot->userFunctions[oldF]);
303 from->sendNotice("\002Alias added.\002");
307 UserCommands::Ban(ServerConnection *cnx, Person *from,
308 String channel, String rest)
310 if (rest.length() == 0) {
312 from->sendNotice("\002No nick/mask specified.\002");
316 Message m = Commands::Ban(cnx->bot, channel, rest);
317 if (m.getCode() != 0 && from)
318 from->sendNotice(m.getMessage());
323 void print_ban_list (Person * from, const BanEntry * b)
325 if (b->getExpirationDate() == -1)
326 from->sendNotice(b->getMask().getMask().pad(30) + " -1");
328 from->sendNotice(b->getMask().getMask().pad(30) + " " +
329 String((long)(b->getExpirationDate() - std::time (0))));
334 UserCommands::BanList(ServerConnection *cnx, Person *from,
335 String channel, String rest)
337 Channel *c = cnx->bot->channelList->getChannel(channel);
339 from->sendNotice(String("\002Banlist for channel\002 ") +
340 channel + "\002:\002");
341 from->sendNotice("\002Mask Expires (seconds)\002");
343 c->for_each_ban_entry (std::bind1st (std::ptr_fun (print_ban_list),
346 from->sendNotice("\002End of banlist.\002");
350 // UserCommands::ChangeLevel(ServerConnection *cnx, Person *from,
351 // String channel, String rest)
353 // StringTokenizer st(rest);
356 // String mask = who = st.next_token();
357 // String maskChannel = st.next_token();
358 // String level = st.next_token();
360 // if (mask == "" || maskChannel == "" || level == "") {
361 // from->sendNotice("\002Invalid syntax for this command.\002");
365 // if (!Utils::wildcard_p(mask)) {
366 // mask = cnx->bot->getUserhost(channel, who);
368 // from->sendNotice(String("\002I can not find\002 ") + who);
371 // mask = from->getNick() + "!" + mask;
374 // UserListItem *uli = cnx->bot->userList->getUserListItem(mask, maskChannel);
377 // from->sendNotice(String("\002I can not find\002 ") + who +
378 // " \002on channel(s)\002 " + maskChannel +
379 // " \002in my userlist.\002");
383 // int l = atoi((const char *)level);
385 // if (l < User::NONE || l > User::MASTER) {
386 // from->sendNotice("\002This is not a valid level.\002");
390 // if (l > Utils::get_level(cnx->bot, from->getAddress())) {
391 // from->sendNotice("\002You can not give a level greater than yours.\002");
395 // if (Utils::get_level(cnx->bot, from->getAddress()) < uli->level) {
396 // from->sendNotice("\002You can not change the level for a person "
397 // "whose level is greater than yours.\002");
402 // from->sendNotice("\002Level changed.\002");
403 // cnx->bot->rehash();
407 UserCommands::Channels(ServerConnection *cnx, Person *from,
408 String channel, String rest)
412 for (std::map<String, Channel *, std::less<String> >::iterator it =
413 cnx->bot->channelList->begin();
414 it != cnx->bot->channelList->end(); ++it)
415 result = result + (*it).first + " ";
418 from->sendNotice("\002I am not on any channel.\002");
420 from->sendNotice(String("\002I am currently on channel(s):\002 ")
425 UserCommands::Cycle(ServerConnection *cnx, Person *from,
426 String channel, String rest)
428 Message m = Commands::Cycle(cnx->bot, channel);
429 if (m.getCode() != 0)
430 from->sendNotice(m.getMessage());
434 UserCommands::DCCList(ServerConnection *cnx, Person *from,
435 String channel, String rest)
437 time_t current_time = time(0);
439 from->sendNotice("\002DCClist:\002");
440 from->sendNotice("\002Hostname Last used\002");
442 for (DCC_MAP::iterator it =
443 cnx->bot->dccConnections->dcc_map.begin ();
444 it != cnx->bot->dccConnections->dcc_map.end();
446 from->sendNotice(String(it->second->dcc->get_nuh()).pad(32) + " " +
447 String((long)(current_time -
448 it->second->dcc->get_lastSpoken())));
451 from->sendNotice("\002End of dcclist.\002");
455 UserCommands::Deban(ServerConnection *cnx, Person *from,
456 String channel, String rest)
458 if (rest.length() == 0) {
459 from->sendNotice("\002No nick/mask specified.\002");
463 Message m = Commands::Deban(cnx->bot, channel, rest);
464 if (m.getCode() != 0)
465 from->sendNotice(m.getMessage());
469 UserCommands::DelServer(ServerConnection *cnx, Person *from,
470 String channel, String rest)
472 if (rest.length() == 0) {
473 from->sendNotice("\002You need to supply a server number"
474 " for this command.\002");
478 int serverNumber = atoi(rest.c_str ());
480 Message m = Commands::DelServer(cnx->bot, serverNumber);
481 if (m.getCode() != 0)
482 from->sendNotice(m.getMessage());
484 from->sendNotice(String("Deleted server ") +
485 cnx->bot->serverList->get(serverNumber)->getHostName() +
486 " (" + String((long)cnx->bot->serverList->get(serverNumber)->getPort()) +
492 UserCommands::DelUser(ServerConnection *cnx, Person *from,
493 String channel, String rest)
495 StringTokenizer st(rest);
498 String mask = who = st.next_token();
499 String maskChannel = st.next_token();
501 if (mask == "" || maskChannel == "") {
502 from->sendNotice("\002Invalid syntax for this command.\002");
506 if (!Utils::wildcard_p(mask)) {
507 mask = cnx->bot->getUserhost(channel, who);
509 from->sendNotice(String("\002I can not find\002 ") + who);
512 mask = Utils::make_wildcard(mask);
515 if (!cnx->bot->userList->isInUserList(mask, maskChannel)) {
516 from->sendNotice(mask + " \002is not in userlist on channel(s)\002 " +
521 cnx->bot->userList->removeUser(mask, maskChannel);
522 from->sendNotice(who + " \002has been removed from the userlist.\002");
528 UserCommands::DelShit(ServerConnection *cnx, Person *from,
529 String channel, String rest)
531 StringTokenizer st(rest);
534 String mask = who = st.next_token();
535 String maskChannel = st.next_token();
537 if (mask == "" || maskChannel == "") {
538 from->sendNotice("\002Invalid syntax for this command.\002");
542 if (!Utils::wildcard_p(mask)) {
543 mask = cnx->bot->getUserhost(channel, who);
545 from->sendNotice(String("\002I can not find\002 ") + who);
548 mask = Utils::make_wildcard(mask);
551 if (!cnx->bot->shitList->getShit(mask, maskChannel)) {
552 from->sendNotice(mask + " \002is not in shitlist on channel(s)\002 " +
557 cnx->bot->shitList->delShit(mask, maskChannel);
558 from->sendNotice(who + " \002has been removed from the shitlist.\002");
562 UserCommands::Deop(ServerConnection *cnx, Person *from,
563 String channel, String rest)
565 String target = rest;
567 if (target.length() == 0)
568 target = from->getNick();
570 Message m = Commands::Deop(cnx->bot, channel, target);
571 if (m.getCode() != 0)
572 from->sendNotice(m.getMessage());
576 UserCommands::Die(ServerConnection *cnx, Person *from,
577 String channel, String rest)
581 if (rest.length() == 0)
586 Commands::Die(cnx->bot, reason);
590 UserCommands::Do(ServerConnection *cnx, Person *from,
591 String channel, String rest)
593 if (rest.length() != 0)
594 Commands::Do(cnx->bot, rest);
599 UserCommands::Execute(ServerConnection *cnx, Person *from,
600 String channel, String rest)
602 if (rest.length() != 0)
603 Interp::Execute(cnx->bot, rest);
608 UserCommands::Help(ServerConnection *cnx, Person *from,
609 String channel, String rest)
611 if (rest.length() == 0) {
612 from->sendNotice("\002Available topics for you are:\002");
613 int level = Utils::get_level(cnx->bot, from->getAddress());
616 std::map<std::string, class userFunction*,
617 std::less<std::string> >::iterator it;
619 for (it = cnx->bot->userFunctions.begin();
620 it != cnx->bot->userFunctions.end(); ++it)
622 if ((*it).second->minLevel <= level)
624 result = result + (*it).first + " ";
625 length += (*it).first.length() + 1;
629 from->sendNotice(result);
630 result = ""; length = 0;
635 from->sendNotice(result);
636 from->sendNotice("\002Use\002 HELP <command> \002for"
637 " help about\002 <command>");
641 StringTokenizer st(rest);
642 String command = Utils::to_upper (st.next_token());
643 std::ifstream helpFile(cnx->bot->helpFileName.c_str ());
646 from->sendNotice(String("\002Error: I can not find the "
648 cnx->bot->helpFileName);
653 while (!helpFile.eof()) {
655 if (buf.subString(0, command.length()) == String(":") + command) {
656 buf = buf.subString(1);
657 from->sendNotice(String("\002Help for\002 ") + command +
660 from->sendNotice(buf);
663 from->sendNotice("\002End of help.\002");
668 from->sendNotice(String("\002No such topic (\002") +
669 command + "\002).\002");
673 UserCommands::Ident(ServerConnection *cnx, Person *from,
674 String channel, String rest)
676 Channel *c = cnx->bot->channelList->getChannel(channel);
678 if (rest.length() <= 2) {
679 from->sendNotice("\002No password specified or password "
686 User u = c->getUser(from->getNick());
688 if (u.userListItem && u.userListItem->identified) {
689 from->sendNotice(String("\002You are already identified on"
690 " channel\002 ") + channel);
694 if (!u.userListItem) {
695 from->sendNotice("\002You are not in my userlist.\002");
699 if (u.userListItem->passwd ==
700 crypt(rest.c_str (), u.userListItem->passwd.c_str ())) {
701 // For each channel, we increment identification counter
702 // fixme: is this logic correct?
703 for (std::map<String, Channel *, std::less<String> >::iterator it =
704 cnx->bot->channelList->begin();
705 it != cnx->bot->channelList->end(); ++it)
706 u.userListItem->identified++;
708 from->sendNotice("\002You are now identified.\002");
710 from->sendNotice("\002This is a wrong password.\002");
712 catch (ChannelUserList::user_not_found &e)
714 from->sendNotice(String("\002You can identify yourself on"
715 " channel\002 ") + channel +
716 " \002only if you are on the channel.\002");
722 UserCommands::Invite(ServerConnection *cnx, Person *from,
723 String channel, String rest)
725 Message m = Commands::Invite(cnx->bot, channel, rest);
727 from->sendNotice(m.getMessage());
728 from->sendNotice(String("\002Inviting\002 ") + rest + " \002on channel\002 " + channel);
733 UserCommands::Join(ServerConnection *cnx, Person *from,
734 String channel, String rest)
736 StringTokenizer st(rest);
737 channel = st.next_token();
739 if (!Utils::valid_channel_name_p(channel)) {
740 from->sendNotice(String("\002") + channel +
741 " is not a valid channel name\002");
745 // We change the key only if we are not on the channel. We don't trust
747 if (!cnx->bot->channelList->getChannel(channel)) {
748 if (cnx->bot->wantedChannels[channel])
749 cnx->bot->wantedChannels[channel]->key = st.rest();
751 cnx->bot->wantedChannels[channel] = new wantedChannel("", "", st.rest());
754 cnx->queue->sendJoin(channel, cnx->bot->wantedChannels[channel]->key);
759 UserCommands::Keep(ServerConnection *cnx, Person *from,
760 String channel, String rest)
762 String nick = from->getNick();
764 if (rest.length() == 0) {
765 from->sendNotice("\002No channel modes specified.\002");
769 cnx->bot->channelList->getChannel(channel)->keepModes = rest;
770 from->sendNotice(String("\002Keeping modes\002 ") +
771 rest + " \002on channel\002 " +
776 UserCommands::Kick(ServerConnection *cnx, Person *from,
777 String channel, String rest)
779 Channel * c = cnx->bot->channelList->getChannel(channel);
781 if (rest.length() == 0) {
782 from->sendNotice("\002No nick specified.\002");
786 StringTokenizer st(rest);
787 String who = st.next_token();
789 if (Utils::wildcard_p(who)) {
792 User u = c->getUser(from->getNick ());
794 if (u.getLevel() < User::TRUSTED_USER) {
795 from->sendNotice("\002You need an higher level to "
796 "use wildcards.\002");
800 catch (const ChannelUserList::user_not_found &)
806 Message ret = Commands::Kick (cnx->bot, channel, who, st.rest ());
807 if (ret.getCode () != 0)
808 from->sendNotice (ret.getMessage ());
813 UserCommands::KickBan(ServerConnection *cnx, Person *from,
814 String channel, String rest)
816 StringTokenizer st(rest);
818 Ban(cnx, 0, channel, st.next_token());
819 Kick(cnx, from, channel, rest);
823 UserCommands::Load(ServerConnection *cnx, Person *from,
824 String channel, String rest)
826 cnx->bot->shitList->read();
827 cnx->bot->userList->read();
828 cnx->bot->userList->addUserFirst(cnx->bot->nickName + "!" + cnx->bot->userHost, "*", 0, 3, true, -1, "");
830 from->sendNotice("\002Userlist and shitlist loaded.\002");
835 UserCommands::LoadScript(ServerConnection *cnx, Person *from,
836 String channel, String rest)
838 if (rest.length() != 0)
839 Interp::LoadScript(cnx->bot, rest);
845 UserCommands::Lock(ServerConnection *cnx, Person *from,
846 String channel, String rest)
848 cnx->bot->channelList->getChannel(channel)->lockedTopic = true;
849 from->sendNotice(String("\002Locking topic for channel\002 ") +
855 UserCommands::Mode(ServerConnection *cnx, Person *from,
856 String channel, String rest)
858 String nick = from->getNick();
860 if (rest.length() == 0) {
861 from->sendNotice("\002I need a parameter for this command.\002");
865 if (!cnx->bot->iAmOp(channel)) {
866 from->sendNotice(String("\002I am not channel op on\002 ") +
871 cnx->queue->sendChannelMode(String("MODE ") + channel + " " + rest);
875 UserCommands::Msg(ServerConnection *cnx, Person *from,
876 String channel, String rest)
878 StringTokenizer st(rest);
879 String who = st.next_token();
880 String message = st.rest();
882 Message m = Commands::Msg(cnx->bot, who, message);
883 if (m.getCode() != 0)
884 from->sendNotice(m.getMessage());
887 UserCommands::map_names::map_names (Person *f, std::string &r)
888 : from (f), result (r), length (0)
892 UserCommands::map_names::operator() (const User &user)
894 result += (user.mode & User::OP_MODE ? "@" :
895 (user.mode & User::VOICE_MODE ? "+" : "")) + user.nick + " ";
896 length += user.nick.length() + 1;
899 from->sendNotice(result);
900 result = ""; length = 0;
905 UserCommands::Names(ServerConnection *cnx, Person *from,
906 String channel, String rest)
908 String nick = from->getNick();
909 Channel *c = cnx->bot->channelList->getChannel(channel);
912 from->sendNotice(String("\002Names on ") +
915 map_names f (from, result);
916 c->for_each_channel_users (f);
919 from->sendNotice(result);
921 from->sendNotice("\002End of names.\002");
926 UserCommands::NextServer(ServerConnection *cnx, Person *from,
927 String channel, String rest)
929 if (cnx->bot->serverList->size() == 0) {
930 from->sendNotice("\002Server list is empty !\002");
934 if (cnx->bot->serverList->size() == 1) {
935 from->sendNotice("\002Server list has only one item. Use"
936 " \"reconnect\" to force reconnection.\002");
940 if (cnx->bot->canChangeServer()) {
941 cnx->queue->sendQuit("Changing server");
942 cnx->bot->nextServer();
945 from->sendNotice("\002I can not change server without"
946 " losing op on a channel I am on.\002");
951 UserCommands::Nick(ServerConnection *cnx, Person *from,
952 String channel, String rest)
954 // We parse the parameters
955 StringTokenizer st(rest);
956 String nick = st.next_token();
959 from->sendNotice(String("\002No nickname given.\002"));
963 if (!Utils::valid_nickname_p (cnx->bot, nick)) {
964 from->sendNotice(String("\002") + nick +
965 " is not a valid nickname\002");
969 cnx->bot->wantedNickName = nick;
970 cnx->queue->sendNick(nick);
974 UserCommands::NsLookup(ServerConnection *cnx, Person *from,
975 String channel, String rest)
979 if (rest.length() == 0) {
980 from->sendNotice("\002You need to supply a nick or an "
981 "host for this command.\002");
985 if (rest.find('.') == -1) {
986 StringTokenizer st(cnx->bot->getUserhost("", rest));
989 if (target.length() == 0) {
990 from->sendNotice(String("\002I could not find\002 ") +
997 struct hostent * host;
998 struct in_addr iaddr;
1000 if (isdigit(target[0])) { // An IP ?
1001 iaddr.s_addr = inet_addr(target.c_str ());
1002 host = gethostbyaddr((char *)(&iaddr),
1003 sizeof(struct in_addr),
1006 from->sendNotice(target +
1007 " \002is the IP address of\002 " +
1012 host = gethostbyname(target.c_str ());
1014 std::memcpy((char *)&iaddr, (char *)host->h_addr,
1016 from->sendNotice(target + " \002has\002 " +
1017 inet_ntoa(iaddr) + " \002for IP address.\002");
1022 from->sendNotice(String("\002I could not find host\002 ") +
1027 UserCommands::Op(ServerConnection *cnx, Person *from,
1028 String channel, String rest)
1030 Message ret = Commands::Op (cnx->bot, channel,
1031 rest.length () == 0 ? from->getNick () : rest);
1033 if (ret.getCode () != 0)
1034 from->sendNotice (ret.getMessage ());
1038 UserCommands::Part(ServerConnection *cnx, Person *from,
1039 String channel, String rest)
1041 Message ret = Commands::Part (cnx->bot, channel);
1043 if (ret.getCode () != 0)
1044 from->sendNotice (ret.getMessage ());
1048 UserCommands::Password(ServerConnection *cnx, Person *from,
1049 String channel, String rest)
1051 if (rest.length() == 0) {
1052 from->sendNotice("\002No password.\002");
1058 Channel *c = cnx->bot->channelList->getChannel(channel);
1059 User u = c->getUser(from->getNick());
1061 if (!u.userListItem) {
1062 from->sendNotice("\002You are not in my userlist.\002");
1066 if (rest.toLower() == "none") {
1067 u.userListItem->passwd = "";
1068 from->sendNotice("\002Password cleared.\002");
1072 static char saltChars[] = "abcdefghijklmnopqrstuvwxyz"
1073 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
1076 salt[0] = saltChars[rand() % 64];
1077 salt[1] = saltChars[rand() % 64];
1080 u.userListItem->passwd = crypt(rest.c_str (), salt);
1081 from->sendNotice("\002Password changed.\002");
1083 catch (const ChannelUserList::user_not_found &e)
1085 from->sendNotice(String("\002To change your password for\002") +
1086 channel + "\002, you need to be on the "
1093 UserCommands::Save(ServerConnection *cnx, Person *from,
1094 String channel, String rest)
1096 cnx->bot->userList->save();
1097 cnx->bot->shitList->save();
1098 from->sendNotice("\002Userlist and shitlist saved.\002");
1103 UserCommands::Say(ServerConnection *cnx, Person *from,
1104 String channel, String rest)
1106 if (rest.length() != 0)
1107 cnx->queue->sendPrivmsg(channel, rest);
1112 UserCommands::Server(ServerConnection *cnx, Person *from,
1113 String channel, String rest)
1116 String nick = from->getNick();
1118 if (rest.length() == 0) {
1119 from->sendNotice("\002You need to supply a server number for this command.\002");
1123 serverNumber = atoi(rest.c_str ());
1125 if (serverNumber < 0 || serverNumber >= cnx->bot->serverList->size()) {
1126 from->sendNotice(String((long)serverNumber) +
1127 " \002is an invalid server number (see the serverlist).\002");
1131 if (cnx->bot->canChangeServer()) {
1132 cnx->queue->sendQuit("Changing server");
1133 cnx->queue->flush();
1134 cnx->bot->connect(serverNumber);
1137 from->sendNotice("\002I can not change server without losing op on a channel I am on.\002");
1141 UserCommands::ServerList(ServerConnection *cnx, Person *from,
1142 String channel, String rest)
1144 String nick = from->getNick();
1146 from->sendNotice("\002Server list:\002");
1149 for (std::vector<class Server *>::iterator it =
1150 cnx->bot->serverList->v.begin();
1151 it != cnx->bot->serverList->v.end();
1153 s = (*it) == cnx->server ? "\026" : "";
1154 from->sendNotice(s + String(l++) + s + " " +
1155 (*it)->getHostName() +
1156 " (" + String((long)((*it)->getPort())) +
1159 from->sendNotice("\002End of server list.\002");
1164 UserCommands::SetFloodRate(ServerConnection *cnx, Person *from,
1165 String channel, String rest)
1167 Message m = Commands::SetFloodRate (cnx->bot, std::atoi (rest.c_str ()));
1169 from->sendNotice (m.getMessage ());
1171 from->sendNotice ("Flood Rate set to:" + String(std::atol(rest.c_str ())));
1175 UserCommands::SetVersion(ServerConnection *cnx, Person *from,
1176 String channel, String rest)
1178 Message m = Commands::SetVersion(cnx->bot, rest);
1180 if (m.getCode() < 0)
1182 Commands::Notice (cnx->bot, from->getNick (), m.getMessage());
1187 UserCommands::ShitList(ServerConnection *cnx, Person *from,
1188 String channel, String rest)
1190 from->sendNotice("\002Shitlist:\002");
1191 from->sendNotice("\002Mask Channel Level Expires Reason\002");
1193 for (std::list<ShitEntry *>::iterator it = cnx->bot->shitList->l.begin();
1194 it != cnx->bot->shitList->l.end();
1196 from->sendNotice((*it)->shitMask.getMask().pad(25) + " " +
1197 (*it)->shitChannelMask.getMask().pad(10) + " " +
1198 String((long)(*it)->shitLevel).pad(9) + " " +
1199 String((long)(*it)->expirationDate).pad(9) + " " +
1202 from->sendNotice("\002End of shitlist.\002");
1206 UserCommands::SpyList(ServerConnection *cnx, Person *from,
1207 String channel, String rest)
1209 String nick = from->getNick();
1211 from->sendNotice("\002Spy list:\002");
1213 for (std::map<String, Person *, std::less<String> >::iterator it =
1214 cnx->bot->spyList.begin(); it != cnx->bot->spyList.end(); ++it)
1215 from->sendNotice((*it).first);
1217 from->sendNotice("\002End of spy list.\002");
1221 UserCommands::SpyMessage(ServerConnection *cnx, Person *from,
1222 String channel, String rest)
1224 String nick = from->getNick();
1226 if (cnx->bot->spyList.find(nick) != cnx->bot->spyList.end()) {
1227 from->sendNotice("\002You are already spying messages.\002");
1231 Person *f = from->copy();
1233 cnx->bot->spyList[nick.toLower()] = f;
1234 from->sendNotice("\002You have been added to the spy list.\002");
1239 UserCommands::Reconnect(ServerConnection *cnx, Person *from,
1240 String channel, String rest)
1242 String nick = from->getNick();
1244 if (cnx->bot->canChangeServer()) {
1245 cnx->queue->sendQuit("Reconnecting");
1246 cnx->bot->reconnect();
1249 from->sendNotice("\002I can not change server without losing op on a channel I am on.\002");
1253 UserCommands::RSpyMessage(ServerConnection *cnx, Person *from,
1254 String channel, String rest)
1256 String nick = from->getNick().toLower();
1258 if (cnx->bot->spyList.find(nick) == cnx->bot->spyList.end()) {
1259 from->sendNotice("\002You are not in the spy list.\002");
1263 delete cnx->bot->spyList[nick];
1264 cnx->bot->spyList.erase(nick);
1265 from->sendNotice("\002You have been removed from the "
1271 UserCommands::Unlock(ServerConnection *cnx, Person *from,
1272 String channel, String rest)
1274 cnx->bot->channelList->getChannel(channel)->lockedTopic = false;
1275 from->sendNotice(String("\002Unlocking topic for channel\002 ") +
1280 UserCommands::Stats(ServerConnection *cnx, Person *from,
1281 String channel, String rest)
1283 String nick = from->getNick();
1285 from->sendNotice(String("\002Keeping modes\002 ") +
1286 cnx->bot->channelList->getChannel(channel)->keepModes + " \002on channel\002 " +
1291 UserCommands::TBan(ServerConnection *cnx, Person *from,
1292 String channel, String rest)
1294 Channel * c = cnx->bot->channelList->getChannel(channel);
1295 StringTokenizer st(rest);
1296 String who = st.next_token();
1297 String t = st.next_token();
1299 if (who == "" || t == "") {
1301 from->sendNotice("\002Invalid syntax for this command.\002");
1305 if (Utils::wildcard_p(who) && from) {
1306 if (c->hasNick (from->getNick ())
1307 && c->getUser(from->getNick()).getLevel() < User::TRUSTED_USER) {
1309 from->sendNotice("\002You need an higher level to use"
1315 Message ret = Commands::TBan (cnx->bot, channel, who, Utils::str2time (t));
1316 if (ret.getCode () && from)
1317 from->sendNotice ("\002" + ret.getMessage () + "\002");
1322 UserCommands::TKBan(ServerConnection *cnx, Person *from,
1323 String channel, String rest)
1325 StringTokenizer st(rest);
1326 String who = st.next_token();
1327 String t = st.next_token();
1329 TBan(cnx, 0, channel, who + " " + t);
1330 Kick(cnx, from, channel, who + " " + st.rest());
1335 UserCommands::Topic(ServerConnection *cnx, Person *from,
1336 String channel, String rest)
1338 String nick = from->getNick();
1340 if (rest.length() == 0) {
1341 if (cnx->bot->channelList->getChannel(channel)->channelTopic == "")
1342 from->sendNotice(String("\002No topic is set for channel\002 ") +
1343 channel + "\002.\002");
1345 from->sendNotice(String("\002Topic for\002 ") +
1346 channel + " \002is:\002 " +
1347 cnx->bot->channelList->getChannel(channel)->channelTopic);
1349 if (cnx->bot->channelList->getChannel(channel)->lockedTopic)
1350 from->sendNotice(String("\002Topic is locked on channel\002 ") +
1353 cnx->queue->sendTopic(channel, rest);
1358 UserCommands::UserList(ServerConnection *cnx, Person *from,
1359 String channel, String rest)
1361 from->sendNotice("\002Userlist:\002");
1362 from->sendNotice("\002Mask Channel Level Prot Aop Expires\002");
1364 for (std::list<UserListItem *>::iterator it = cnx->bot->userList->l.begin();
1365 it != cnx->bot->userList->l.end();
1367 from->sendNotice((*it)->mask.getMask().pad(25)
1369 + (*it)->channelMask.getMask().pad(10)
1371 String(Utils::level2str((*it)->level)).pad(12)
1373 String(Utils::prot2str((*it)->prot)).pad(7)
1375 String(Utils::bool2str((*it)->aop)).pad(5)
1377 String(Utils::long2str ((*it)->expirationDate)));
1379 from->sendNotice("\002End of userlist.\002");
1383 UserCommands::Who(ServerConnection *cnx, Person *from,
1384 String channel, String rest)
1386 String nick = from->getNick();
1389 if (cnx->bot->channelList->getChannel(channel)->hasNick(nick))
1390 uli = cnx->bot->channelList->getChannel(channel)->getUser(nick).userListItem;
1392 uli = cnx->bot->userList->getUserListItem(from->getAddress(),
1396 from->sendNotice(String("\002You are\002 ") +
1397 uli->mask.getMask() + " \002on\002 " +
1398 uli->channelMask.getMask());
1399 from->sendNotice(String("\002Lvl:\002 ") +
1400 Utils::level2str(uli->level) +
1402 Utils::prot2str(uli->prot) +
1404 Utils::bool2str(uli->aop) +
1405 " \002Expired:\002 " +
1406 Utils::bool2str(!uli->isStillValid()) +
1407 " \002Ident:\002 " +
1408 (uli && !uli->identified ? "\026" : "") +
1409 Utils::bool2str(uli && uli->identified) +
1410 (uli && !uli->identified ? "\026" : ""));
1412 from->sendNotice(String("\002You are not in the userlist for\002 ") +
1417 UserCommands::Whois(ServerConnection *cnx, Person *from,
1418 String channel, String rest)
1420 String nick = from->getNick();
1422 if (!rest.length()) {
1423 from->sendNotice("\002No nick specified.\002");
1427 StringTokenizer st(rest);
1428 String otherNick = st.next_token();
1432 if (cnx->bot->channelList->getChannel(channel)->hasNick(otherNick))
1433 uli = cnx->bot->channelList->getChannel(channel)->getUser(otherNick).userListItem;
1435 uli = cnx->bot->userList->getUserListItem(otherNick + "!" +
1436 cnx->bot->getUserhost(channel,
1441 from->sendNotice(otherNick +
1442 " \002is\002 " + uli->mask.getMask() +
1443 " \002on\002 " + uli->channelMask.getMask());
1444 from->sendNotice(String("\002Lvl:\002 ") +
1445 Utils::level2str(uli->level) +
1447 Utils::prot2str(uli->prot) +
1449 Utils::bool2str(uli->aop) +
1450 " \002Expired:\002 " +
1451 Utils::bool2str(!uli->isStillValid()) +
1452 " \002Ident:\002 " +
1453 Utils::bool2str(uli && uli->identified));
1455 from->sendNotice(otherNick +
1456 " \002is not in the userlist for\002 " +