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((const char *)level);
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((const char *)prot);
140 if (p < 0 || p > User::NO_DEOP)
142 a = (bool)atoi((const char *)aop);
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((const char *)temp);
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((const char *)level);
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);
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);
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 "
684 User * u = c->getUser(from->getNick());
686 from->sendNotice(String("\002You can identify yourself on"
687 " channel\002 ") + channel +
688 " \002only if you are on the channel.\002");
692 if (u->userListItem && u->userListItem->identified) {
693 from->sendNotice(String("\002You are already identified on"
694 " channel\002 ") + channel);
698 if (!u->userListItem) {
699 from->sendNotice("\002You are not in my userlist.\002");
703 if (u->userListItem->passwd ==
704 crypt((const char *)rest, (const char *)u->userListItem->passwd)) {
705 // For each channel, we increment identification counter
706 for (std::map<String, Channel *, std::less<String> >::iterator it =
707 cnx->bot->channelList->begin();
708 it != cnx->bot->channelList->end(); ++it)
709 u->userListItem->identified++;
711 from->sendNotice("\002You are now identified.\002");
713 from->sendNotice("\002This is a wrong password.\002");
717 UserCommands::Invite(ServerConnection *cnx, Person *from,
718 String channel, String rest)
720 Message m = Commands::Invite(cnx->bot, channel, rest);
722 from->sendNotice(m.getMessage());
723 from->sendNotice(String("\002Inviting\002 ") + rest + " \002on channel\002 " + channel);
728 UserCommands::Join(ServerConnection *cnx, Person *from,
729 String channel, String rest)
731 StringTokenizer st(rest);
732 channel = st.next_token();
734 if (!Utils::valid_channel_name_p(channel)) {
735 from->sendNotice(String("\002") + channel +
736 " is not a valid channel name\002");
740 // We change the key only if we are not on the channel. We don't trust
742 if (!cnx->bot->channelList->getChannel(channel)) {
743 if (cnx->bot->wantedChannels[channel])
744 cnx->bot->wantedChannels[channel]->key = st.rest();
746 cnx->bot->wantedChannels[channel] = new wantedChannel("", "", st.rest());
749 cnx->queue->sendJoin(channel, cnx->bot->wantedChannels[channel]->key);
754 UserCommands::Keep(ServerConnection *cnx, Person *from,
755 String channel, String rest)
757 String nick = from->getNick();
759 if (rest.length() == 0) {
760 from->sendNotice("\002No channel modes specified.\002");
764 cnx->bot->channelList->getChannel(channel)->keepModes = rest;
765 from->sendNotice(String("\002Keeping modes\002 ") +
766 rest + " \002on channel\002 " +
772 UserCommands::Kick(ServerConnection *cnx, Person *from,
773 String channel, String rest)
775 String nick = from->getNick();
777 Channel * c = cnx->bot->channelList->getChannel(channel);
779 if (rest.length() == 0) {
780 from->sendNotice("\002No nick specified.\002");
784 StringTokenizer st(rest);
785 String who = st.next_token();
787 if (Utils::wildcard_p(who)) {
788 User * u = c->getUser(nick);
791 if (u->getLevel() < User::TRUSTED_USER) {
792 from->sendNotice("\002You need an higher level to "
793 "use wildcards.\002");
798 if (!cnx->bot->iAmOp(channel)) {
799 from->sendNotice(String("\002I am not channel op on\002 ") +
804 if (Utils::wildcard_p(who)) {
806 for (std::map<String, User *, std::less<String> >::iterator it =
807 c->channelMemory.begin();
808 it != c->channelMemory.end();
810 if (m.matches((*it).second->nick + "!" +
811 (*it).second->userhost) &&
812 (*it).second->getProt() < User::NO_KICK)
813 cnx->queue->sendKick(channel, (*it).second->nick, st.rest());
815 User * u = c->getUser(who);
817 from->sendNotice(String("\002I can not find\002 ") +
818 who + " \002on\002 " + channel);
821 if (u->getProt() < User::NO_KICK)
822 cnx->queue->sendKick(channel, who, st.rest());
824 from->sendNotice(String("\002I can not kick\002 ") +
825 who + " \002on\002 " + channel +
826 " \002(protected).\002");
832 UserCommands::KickBan(ServerConnection *cnx, Person *from,
833 String channel, String rest)
835 StringTokenizer st(rest);
837 Ban(cnx, 0, channel, st.next_token());
838 Kick(cnx, from, channel, rest);
842 UserCommands::Load(ServerConnection *cnx, Person *from,
843 String channel, String rest)
845 cnx->bot->shitList->read();
846 cnx->bot->userList->read();
847 cnx->bot->userList->addUserFirst(cnx->bot->nickName + "!" + cnx->bot->userHost, "*", 0, 3, true, -1, "");
849 from->sendNotice("\002Userlist and shitlist loaded.\002");
854 UserCommands::LoadScript(ServerConnection *cnx, Person *from,
855 String channel, String rest)
857 if (rest.length() != 0)
858 Interp::LoadScript(cnx->bot, rest);
864 UserCommands::Lock(ServerConnection *cnx, Person *from,
865 String channel, String rest)
867 cnx->bot->channelList->getChannel(channel)->lockedTopic = true;
868 from->sendNotice(String("\002Locking topic for channel\002 ") +
874 UserCommands::Mode(ServerConnection *cnx, Person *from,
875 String channel, String rest)
877 String nick = from->getNick();
879 if (rest.length() == 0) {
880 from->sendNotice("\002I need a parameter for this command.\002");
884 if (!cnx->bot->iAmOp(channel)) {
885 from->sendNotice(String("\002I am not channel op on\002 ") +
890 cnx->queue->sendChannelMode(String("MODE ") + channel + " " + rest);
894 UserCommands::Msg(ServerConnection *cnx, Person *from,
895 String channel, String rest)
897 StringTokenizer st(rest);
898 String who = st.next_token();
899 String message = st.rest();
901 Message m = Commands::Msg(cnx->bot, who, message);
902 if (m.getCode() != 0)
903 from->sendNotice(m.getMessage());
907 UserCommands::Names(ServerConnection *cnx, Person *from,
908 String channel, String rest)
910 String nick = from->getNick();
913 Channel *c = cnx->bot->channelList->getChannel(channel);
914 std::map<String, User *, std::less<String> >::iterator it;
916 from->sendNotice(String("\002Names on ") +
919 for (it = c->channelMemory.begin();
920 it != c->channelMemory.end(); ++it) {
922 ((*it).second->mode & User::OP_MODE ? "@" :
923 ((*it).second->mode & User::VOICE_MODE ? "+" : "")) +
924 (*it).second->nick + " ";
925 length += (*it).first.length() + 1;
927 from->sendNotice(result);
928 result = ""; length = 0;
933 from->sendNotice(result);
935 from->sendNotice("\002End of names.\002");
940 UserCommands::NextServer(ServerConnection *cnx, Person *from,
941 String channel, String rest)
943 if (cnx->bot->serverList->size() == 0) {
944 from->sendNotice("\002Server list is empty !\002");
948 if (cnx->bot->serverList->size() == 1) {
949 from->sendNotice("\002Server list has only one item. Use"
950 " \"reconnect\" to force reconnection.\002");
954 if (cnx->bot->canChangeServer()) {
955 cnx->queue->sendQuit("Changing server");
956 cnx->bot->nextServer();
959 from->sendNotice("\002I can not change server without"
960 " losing op on a channel I am on.\002");
965 UserCommands::Nick(ServerConnection *cnx, Person *from,
966 String channel, String rest)
968 // We parse the parameters
969 StringTokenizer st(rest);
970 String nick = st.next_token();
973 from->sendNotice(String("\002No nickname given.\002"));
977 if (!Utils::valid_nickname_p (cnx->bot, nick)) {
978 from->sendNotice(String("\002") + nick +
979 " is not a valid nickname\002");
983 cnx->bot->wantedNickName = nick;
984 cnx->queue->sendNick(nick);
988 UserCommands::NsLookup(ServerConnection *cnx, Person *from,
989 String channel, String rest)
993 if (rest.length() == 0) {
994 from->sendNotice("\002You need to supply a nick or an "
995 "host for this command.\002");
999 if (rest.find('.') == -1) {
1000 StringTokenizer st(cnx->bot->getUserhost("", rest));
1003 if (target.length() == 0) {
1004 from->sendNotice(String("\002I could not find\002 ") +
1011 struct hostent * host;
1012 struct in_addr iaddr;
1014 if (isdigit(target[0])) { // An IP ?
1015 iaddr.s_addr = inet_addr((const char *)target);
1016 host = gethostbyaddr((char *)(&iaddr),
1017 sizeof(struct in_addr),
1020 from->sendNotice(target +
1021 " \002is the IP address of\002 " +
1026 host = gethostbyname((const char *)target);
1028 std::memcpy((char *)&iaddr, (char *)host->h_addr,
1030 from->sendNotice(target + " \002has\002 " +
1031 inet_ntoa(iaddr) + " \002for IP address.\002");
1036 from->sendNotice(String("\002I could not find host\002 ") +
1042 UserCommands::Op(ServerConnection *cnx, Person *from,
1043 String channel, String rest)
1045 String nick = from->getNick();
1047 if (!cnx->bot->iAmOp(channel)) {
1048 from->sendNotice(String("\002I am not channel op on\002 ") +
1053 if (Utils::wildcard_p(rest)) {
1054 from->sendNotice("\002Mass op is not allowed.\002");
1060 if (rest.length() == 0)
1065 User *u = cnx->bot->channelList->getChannel(channel)->getUser(target);
1067 from->sendNotice(String("\002I cannot find\002 ") + target + " \002on channel\002 " + channel);
1071 ShitEntry *se = cnx->bot->shitList->getShit(target, channel);
1072 if (se && se->isStillValid() && se->getShitLevel() >= ShitEntry::SHIT_NOOP) {
1073 from->sendNotice(String("\002I can not op\002 ")+target+" \002on channel\002 "+channel+" \002(shitlist).\002");
1077 if (!(u->mode & User::OP_MODE))
1078 cnx->queue->sendChannelMode(channel, "+o", target);
1081 from->sendNotice(String("\002You are already channel "
1082 "operator on\002 ") + channel);
1084 from->sendNotice(target + " \002is already channel "
1085 "operator on\002 " + channel);
1091 UserCommands::Part(ServerConnection *cnx, Person *from,
1092 String channel, String rest)
1094 wantedChannel *w = cnx->bot->wantedChannels[channel];
1095 cnx->bot->wantedChannels.erase(channel);
1097 cnx->queue->sendPart(channel);
1101 UserCommands::Password(ServerConnection *cnx, Person *from,
1102 String channel, String rest)
1104 Channel *c = cnx->bot->channelList->getChannel(channel);
1106 if (rest.length() == 0) {
1107 from->sendNotice("\002No password.\002");
1111 User * u = c->getUser(from->getNick());
1113 from->sendNotice(String("\002To change your password for\002") +
1114 channel + "\002, you need to be on the "
1119 if (!u->userListItem) {
1120 from->sendNotice("\002You are not in my userlist.\002");
1124 if (rest.toLower() == "none") {
1125 u->userListItem->passwd = "";
1126 from->sendNotice("\002Password cleared.\002");
1130 static char saltChars[] = "abcdefghijklmnopqrstuvwxyz"
1131 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
1134 salt[0] = saltChars[rand() % 64];
1135 salt[1] = saltChars[rand() % 64];
1138 u->userListItem->passwd = crypt((const char *)rest, salt);
1139 from->sendNotice("\002Password changed.\002");
1143 UserCommands::Save(ServerConnection *cnx, Person *from,
1144 String channel, String rest)
1146 cnx->bot->userList->save();
1147 cnx->bot->shitList->save();
1148 from->sendNotice("\002Userlist and shitlist saved.\002");
1153 UserCommands::Say(ServerConnection *cnx, Person *from,
1154 String channel, String rest)
1156 if (rest.length() != 0)
1157 cnx->queue->sendPrivmsg(channel, rest);
1162 UserCommands::Server(ServerConnection *cnx, Person *from,
1163 String channel, String rest)
1166 String nick = from->getNick();
1168 if (rest.length() == 0) {
1169 from->sendNotice("\002You need to supply a server number for this command.\002");
1173 serverNumber = atoi(rest);
1175 if (serverNumber < 0 || serverNumber >= cnx->bot->serverList->size()) {
1176 from->sendNotice(String((long)serverNumber) +
1177 " \002is an invalid server number (see the serverlist).\002");
1181 if (cnx->bot->canChangeServer()) {
1182 cnx->queue->sendQuit("Changing server");
1183 cnx->queue->flush();
1184 cnx->bot->connect(serverNumber);
1187 from->sendNotice("\002I can not change server without losing op on a channel I am on.\002");
1191 UserCommands::ServerList(ServerConnection *cnx, Person *from,
1192 String channel, String rest)
1194 String nick = from->getNick();
1196 from->sendNotice("\002Server list:\002");
1199 for (std::vector<class Server *>::iterator it =
1200 cnx->bot->serverList->v.begin();
1201 it != cnx->bot->serverList->v.end();
1203 s = (*it) == cnx->server ? "\026" : "";
1204 from->sendNotice(s + String(l++) + s + " " +
1205 (*it)->getHostName() +
1206 " (" + String((long)((*it)->getPort())) +
1209 from->sendNotice("\002End of server list.\002");
1214 UserCommands::SetFloodRate(ServerConnection *cnx, Person *from,
1215 String channel, String rest)
1217 Message m = Commands::SetFloodRate (cnx->bot, std::atoi (rest));
1219 from->sendNotice (m.getMessage ());
1221 from->sendNotice ("Flood Rate set to:" + String(std::atol(rest)));
1225 UserCommands::SetVersion(ServerConnection *cnx, Person *from,
1226 String channel, String rest)
1228 Message m = Commands::SetVersion(cnx->bot, rest);
1230 if (m.getCode() < 0)
1232 Commands::Notice (cnx->bot, from->getNick (), m.getMessage());
1237 UserCommands::ShitList(ServerConnection *cnx, Person *from,
1238 String channel, String rest)
1240 from->sendNotice("\002Shitlist:\002");
1241 from->sendNotice("\002Mask Channel Level Expires Reason\002");
1243 for (std::list<ShitEntry *>::iterator it = cnx->bot->shitList->l.begin();
1244 it != cnx->bot->shitList->l.end();
1246 from->sendNotice((*it)->shitMask.getMask().pad(25) + " " +
1247 (*it)->shitChannelMask.getMask().pad(10) + " " +
1248 String((long)(*it)->shitLevel).pad(9) + " " +
1249 String((long)(*it)->expirationDate).pad(9) + " " +
1252 from->sendNotice("\002End of shitlist.\002");
1256 UserCommands::SpyList(ServerConnection *cnx, Person *from,
1257 String channel, String rest)
1259 String nick = from->getNick();
1261 from->sendNotice("\002Spy list:\002");
1263 for (std::map<String, Person *, std::less<String> >::iterator it =
1264 cnx->bot->spyList.begin(); it != cnx->bot->spyList.end(); ++it)
1265 from->sendNotice((*it).first);
1267 from->sendNotice("\002End of spy list.\002");
1271 UserCommands::SpyMessage(ServerConnection *cnx, Person *from,
1272 String channel, String rest)
1274 String nick = from->getNick();
1276 if (cnx->bot->spyList.find(nick) != cnx->bot->spyList.end()) {
1277 from->sendNotice("\002You are already spying messages.\002");
1281 Person *f = from->copy();
1283 cnx->bot->spyList[nick.toLower()] = f;
1284 from->sendNotice("\002You have been added to the spy list.\002");
1289 UserCommands::Reconnect(ServerConnection *cnx, Person *from,
1290 String channel, String rest)
1292 String nick = from->getNick();
1294 if (cnx->bot->canChangeServer()) {
1295 cnx->queue->sendQuit("Reconnecting");
1296 cnx->bot->reconnect();
1299 from->sendNotice("\002I can not change server without losing op on a channel I am on.\002");
1303 UserCommands::RSpyMessage(ServerConnection *cnx, Person *from,
1304 String channel, String rest)
1306 String nick = from->getNick().toLower();
1308 if (cnx->bot->spyList.find(nick) == cnx->bot->spyList.end()) {
1309 from->sendNotice("\002You are not in the spy list.\002");
1313 delete cnx->bot->spyList[nick];
1314 cnx->bot->spyList.erase(nick);
1315 from->sendNotice("\002You have been removed from the "
1321 UserCommands::Unlock(ServerConnection *cnx, Person *from,
1322 String channel, String rest)
1324 cnx->bot->channelList->getChannel(channel)->lockedTopic = false;
1325 from->sendNotice(String("\002Unlocking topic for channel\002 ") +
1330 UserCommands::Stats(ServerConnection *cnx, Person *from,
1331 String channel, String rest)
1333 String nick = from->getNick();
1335 from->sendNotice(String("\002Keeping modes\002 ") +
1336 cnx->bot->channelList->getChannel(channel)->keepModes + " \002on channel\002 " +
1341 UserCommands::TBan(ServerConnection *cnx, Person *from,
1342 String channel, String rest)
1344 Channel * c = cnx->bot->channelList->getChannel(channel);
1345 StringTokenizer st(rest);
1346 String who = st.next_token();
1347 String t = st.next_token();
1349 if (who == "" || t == "") {
1351 from->sendNotice("\002Invalid syntax for this command.\002");
1355 if (Utils::wildcard_p(who) && from) {
1356 User * u = c->getUser(from->getNick());
1357 if (u && u->getLevel() < User::TRUSTED_USER) {
1359 from->sendNotice("\002You need an higher level to use"
1365 Message ret = Commands::TBan (cnx->bot, channel, who, Utils::str2time (t));
1366 if (ret.getCode () && from)
1367 from->sendNotice ("\002" + ret.getMessage () + "\002");
1372 UserCommands::TKBan(ServerConnection *cnx, Person *from,
1373 String channel, String rest)
1375 StringTokenizer st(rest);
1376 String who = st.next_token();
1377 String t = st.next_token();
1379 TBan(cnx, 0, channel, who + " " + t);
1380 Kick(cnx, from, channel, who + " " + st.rest());
1385 UserCommands::Topic(ServerConnection *cnx, Person *from,
1386 String channel, String rest)
1388 String nick = from->getNick();
1390 if (rest.length() == 0) {
1391 if (cnx->bot->channelList->getChannel(channel)->channelTopic == "")
1392 from->sendNotice(String("\002No topic is set for channel\002 ") +
1393 channel + "\002.\002");
1395 from->sendNotice(String("\002Topic for\002 ") +
1396 channel + " \002is:\002 " +
1397 cnx->bot->channelList->getChannel(channel)->channelTopic);
1399 if (cnx->bot->channelList->getChannel(channel)->lockedTopic)
1400 from->sendNotice(String("\002Topic is locked on channel\002 ") +
1403 cnx->queue->sendTopic(channel, rest);
1408 UserCommands::UserList(ServerConnection *cnx, Person *from,
1409 String channel, String rest)
1411 from->sendNotice("\002Userlist:\002");
1412 from->sendNotice("\002Mask Channel Level Prot Aop Expires\002");
1414 for (std::list<UserListItem *>::iterator it = cnx->bot->userList->l.begin();
1415 it != cnx->bot->userList->l.end();
1417 from->sendNotice((*it)->mask.getMask().pad(25)
1419 + (*it)->channelMask.getMask().pad(10)
1421 String(Utils::level2str((*it)->level)).pad(12)
1423 String(Utils::prot2str((*it)->prot)).pad(7)
1425 String(Utils::bool2str((*it)->aop)).pad(5)
1427 String(Utils::long2str ((*it)->expirationDate)));
1429 from->sendNotice("\002End of userlist.\002");
1433 UserCommands::Who(ServerConnection *cnx, Person *from,
1434 String channel, String rest)
1436 String nick = from->getNick();
1437 User * u = cnx->bot->channelList->getChannel(channel)->getUser(nick);
1441 uli = u->userListItem;
1443 uli = cnx->bot->userList->getUserListItem(from->getAddress(),
1447 from->sendNotice(String("\002You are\002 ") +
1448 uli->mask.getMask() + " \002on\002 " +
1449 uli->channelMask.getMask());
1450 from->sendNotice(String("\002Lvl:\002 ") +
1451 Utils::level2str(uli->level) +
1453 Utils::prot2str(uli->prot) +
1455 Utils::bool2str(uli->aop) +
1456 " \002Expired:\002 " +
1457 Utils::bool2str(!uli->isStillValid()) +
1458 " \002Ident:\002 " +
1459 (uli && !uli->identified ? "\026" : "") +
1460 Utils::bool2str(uli && uli->identified) +
1461 (uli && !uli->identified ? "\026" : ""));
1463 from->sendNotice(String("\002You are not in the userlist for\002 ") +
1468 UserCommands::Whois(ServerConnection *cnx, Person *from,
1469 String channel, String rest)
1471 String nick = from->getNick();
1473 if (!rest.length()) {
1474 from->sendNotice("\002No nick specified.\002");
1478 StringTokenizer st(rest);
1479 String otherNick = st.next_token();
1481 User * u = cnx->bot->channelList->getChannel(channel)->getUser(otherNick);
1485 uli = u->userListItem;
1487 uli = cnx->bot->userList->getUserListItem(otherNick + "!" +
1488 cnx->bot->getUserhost(channel,
1493 from->sendNotice(otherNick +
1494 " \002is\002 " + uli->mask.getMask() +
1495 " \002on\002 " + uli->channelMask.getMask());
1496 from->sendNotice(String("\002Lvl:\002 ") +
1497 Utils::level2str(uli->level) +
1499 Utils::prot2str(uli->prot) +
1501 Utils::bool2str(uli->aop) +
1502 " \002Expired:\002 " +
1503 Utils::bool2str(!uli->isStillValid()) +
1504 " \002Ident:\002 " +
1505 Utils::bool2str(uli && uli->identified));
1507 from->sendNotice(otherNick +
1508 " \002is not in the userlist for\002 " +