1 // Parser.C -*- C++ -*-
2 // Copyright (c) 1997, 1998 Etienne BERNARD
3 // Copyright (C) 2002,2003,2005,2008 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
28 #include <sys/types.h>
29 #include <netinet/in.h>
33 #include "BotInterp.H"
39 #include "ChannelList.H"
45 #include "ServerConnection.H"
46 #include "ServerList.H"
47 #include "ShitEntry.H"
49 #include "StringTokenizer.H"
50 #include "UserCommands.H"
56 typedef void (*fptr) (ServerConnection *, Person *, String);
57 std::map < std::string, fptr, std::less < std::string > > Parser::functions;
63 Parser::functions["001"] = Parser::parse001; /* RPL_WELCOME */
64 Parser::functions["302"] = Parser::parse302; /* RPL_USERHOST */
65 Parser::functions["311"] = Parser::parse311; /* RPL_WHOISUSER */
66 Parser::functions["315"] = Parser::parse315; /* RPL_ENDOFWHO */
67 Parser::functions["324"] = Parser::parse324; /* RPL_CHANNELMODEIS */
68 Parser::functions["332"] = Parser::parse332; /* RPL_TOPIC */
69 Parser::functions["352"] = Parser::parse352; /* RPL_WHOREPLY */
70 Parser::functions["353"] = Parser::parse353; /* RPL_NAMESREPLY */
71 Parser::functions["366"] = Parser::parse366; /* RPL_ENDOFNAMES */
72 Parser::functions["367"] = Parser::parse367; /* RPL_BANLIST */
73 Parser::functions["401"] = Parser::parse401; /* ERR_NOSUCHNICK */
74 Parser::functions["433"] = Parser::parse433; /* ERR_NICKNAMEINUSE */
75 Parser::functions["437"] = Parser::parse433; /* ERR_UNAVAILRESOURCE */
76 Parser::functions["471"] = Parser::parse473; /* ERR_CHANNELISFULL */
77 Parser::functions["473"] = Parser::parse473; /* ERR_INVITEONLYCHAN */
78 Parser::functions["474"] = Parser::parse473; /* ERR_BANNEDFROMCHAN */
79 Parser::functions["475"] = Parser::parse473; /* ERR_BADCHANNELKEY */
80 Parser::functions["ERROR"] = Parser::parseError;
81 Parser::functions["INVITE"] = Parser::parseInvite;
82 Parser::functions["JOIN"] = Parser::parseJoin;
83 Parser::functions["KICK"] = Parser::parseKick;
84 Parser::functions["MODE"] = Parser::parseMode;
85 Parser::functions["NICK"] = Parser::parseNick;
86 Parser::functions["NOTICE"] = Parser::parseNotice;
87 Parser::functions["PART"] = Parser::parsePart;
88 Parser::functions["PING"] = Parser::parsePing;
89 Parser::functions["PONG"] = Parser::parsePong;
90 Parser::functions["PRIVMSG"] = Parser::parsePrivmsg;
91 Parser::functions["QUIT"] = Parser::parseQuit;
92 Parser::functions["TOPIC"] = Parser::parseTopic;
93 Parser::functions[""] = Parser::parseError;
98 Parser::parseLine (ServerConnection * cnx, String line)
100 StringTokenizer st (line);
103 cnx->bot->botInterp->RunHooks (Hook::RAW, line,
110 String fromMask = st.next_token ().substr (1);
111 if (fromMask.find ('!') != -1)
112 from = new Person (cnx->bot, fromMask);
115 String command = st.next_token ();
116 String rest = st.rest ();
118 // We must use map<>::find or else a new entry will be created in
119 // the map which will cause another lookup of the same invalid
120 // command to segfault the bot
121 std::map<std::string, fptr, std::less<std::string> >::const_iterator cit
122 = functions.find (command);
124 if (cit != functions.end ())
126 fptr temp_func = cit->second;
127 temp_func (cnx, from, rest);
134 Parser::parse001 (ServerConnection * cnx, Person * from, String rest)
137 StringTokenizer st (rest);
138 String realNick = st.next_token ();
139 if ((cnx->bot->nickName).toLower () != realNick.toLower ())
141 // Yes, this can happen, and it was a very subtle bug
142 cnx->bot->nickName = realNick;
143 cnx->bot->userList->removeFirst ();
144 cnx->bot->userList->addUserFirst (realNick + "!" +
145 cnx->bot->userHost, "*", 0,
147 cnx->bot->lastNickNameChange = time (0);
151 cnx->bot->connected = true;
152 cnx->queue->sendUserMode (cnx->bot->nickName, "+i");
153 cnx->queue->sendWhois (cnx->bot->nickName);
154 for (std::map < String, wantedChannel *,
155 std::less < String > >::iterator it =
156 cnx->bot->wantedChannels.begin ();
157 it != cnx->bot->wantedChannels.end (); ++it)
158 cnx->queue->sendJoin ((*it).first, (*it).second->key);
159 cnx->bot->logLine (String ("Connected to server ") +
160 cnx->bot->serverList->currentServer ()->
161 getHostName () + " (" +
162 String ((long) cnx->bot->serverList->
163 currentServer ()->getPort ()) + ").");
167 Parser::parse302 (ServerConnection * cnx, Person * from, String rest)
169 unsigned long num = cnx->bot->receivedUserhostID++;
170 StringTokenizer st (rest);
172 if (st.rest ().length ())
175 cnx->bot->userhostMap[num] = Utils::trim_str (st.rest().substr(1));
178 cnx->bot->userhostMap[num] = "";
182 Parser::parse311 (ServerConnection * cnx, Person * from, String rest)
184 StringTokenizer st (rest);
186 String nuh = st.next_token () + "!";
187 String uh = st.next_token () + "@";
188 uh = uh + st.next_token ();
190 cnx->bot->userList->addUserFirst (nuh, "*", 0, 3, true, -1, "");
191 cnx->bot->userHost = uh;
195 Parser::parse315 (ServerConnection * cnx, Person * from, String rest)
197 StringTokenizer st (rest);
199 String channel = st.next_token ();
200 Channel *c = cnx->bot->channelList->getChannel (channel);
207 Parser::parse324 (ServerConnection * cnx, Person * from, String rest)
209 StringTokenizer st (rest);
211 String channel = st.next_token ();
212 if (Channel * c = cnx->bot->channelList->getChannel (channel))
214 c->parseMode (from, st.rest ());
218 Parser::parse332 (ServerConnection * cnx, Person * from, String rest)
220 StringTokenizer st (rest);
222 String channel = st.next_token ();
223 if (Channel * c = cnx->bot->channelList->getChannel (channel))
225 c->channelTopic = st.rest ().substr (1);
229 Parser::parse352 (ServerConnection * cnx, Person * from, String rest)
231 StringTokenizer st (rest);
233 String ch = st.next_token ();
234 String uh = st.next_token () + "@";
235 uh = uh + st.next_token ();
237 String n = st.next_token ();
238 String m = st.next_token ();
240 for (int i = 0; i < m.length (); i++)
246 mode |= User::AWAY_MODE;
249 mode |= User::IRCOP_MODE;
252 mode |= User::OP_MODE;
255 mode |= User::VOICE_MODE;
258 if (Channel * c = cnx->bot->channelList->getChannel (ch))
260 c->addNick (n, uh, mode, cnx->bot->userList);
264 Parser::parse353 (ServerConnection * cnx, Person * from, String rest)
268 StringTokenizer st (rest);
271 Channel *c = cnx->bot->channelList->getChannel (st.next_token ());
274 StringTokenizer st2 (st.next_token (':'));
275 while (st2.more_tokens_p ())
277 nick = st2.next_token ();
280 mode = User::OP_MODE;
281 nick = nick.substr (1);
283 else if (nick[0] == '+')
285 mode = User::VOICE_MODE;
286 nick = nick.substr (1);
288 c->addNick (nick, "", mode, 0, true);
293 Parser::parse366 (ServerConnection * cnx, Person * from, String rest)
295 StringTokenizer st (rest);
297 String ch = st.next_token ();
298 if (Channel * c = cnx->bot->channelList->getChannel (ch))
303 Parser::parse367 (ServerConnection * cnx, Person * from, String rest)
305 StringTokenizer st (rest);
307 String ch = st.next_token ();
308 if (Channel * c = cnx->bot->channelList->getChannel (ch))
309 c->addBan (Mask(st.next_token ()), -1);
313 Parser::parse401 (ServerConnection * cnx, Person * from, String rest)
315 StringTokenizer st (rest);
317 String nick = st.next_token ();
318 if (cnx->bot->spyList.find (nick) != cnx->bot->spyList.end ())
320 delete cnx->bot->spyList[nick];
321 cnx->bot->spyList.erase (nick);
326 Parser::parse433 (ServerConnection * cnx, Person * from, String rest)
328 if (cnx->bot->connected)
330 if (cnx->bot->nickName.length () == 9)
334 i < cnx->bot->nickName.length ()
335 && cnx->bot->nickName[i] == '_'; i++);
336 if (i < cnx->bot->nickName.length ())
338 cnx->bot->nickName.substr (0,
340 cnx->bot->nickName.substr (i + 1);
342 cnx->bot->nickName = cnx->bot->nickName.substr (0, 4) +
343 String ((long) (rand () % 10000));
346 cnx->bot->nickName = cnx->bot->nickName + "_";
347 cnx->queue->sendNick (cnx->bot->nickName);
351 Parser::parse473 (ServerConnection * cnx, Person * from, String rest)
353 StringTokenizer st (rest);
355 cnx->bot->logLine (String ("Unable to join channel ") +
356 st.next_token () + ".");
360 Parser::parseError (ServerConnection * cnx, Person * from, String rest)
362 cnx->bot->logLine (String ("Error from server ") +
363 cnx->bot->serverList->currentServer ()->
364 getHostName () + " (" +
365 String ((long) cnx->bot->serverList->
366 currentServer ()->getPort ()) + ").");
367 cnx->bot->nextServer ();
371 Parser::parseInvite (ServerConnection * cnx, Person * from, String rest)
373 String nick = from->getNick ();
374 StringTokenizer st (rest);
376 String channel = st.rest ();
378 cnx->bot->botInterp->RunHooks (Hook::INVITE,
379 nick + " " + channel,
384 (channel), SCM_UNDEFINED));
386 if (cnx->bot->wantedChannels.find (channel) !=
387 cnx->bot->wantedChannels.end ())
388 cnx->queue->sendJoin (channel, cnx->bot->wantedChannels[channel]->key);
392 Parser::parseJoin (ServerConnection * cnx, Person * from, String rest)
394 StringTokenizer st (from->getAddress ());
395 String n = st.next_token ('!');
396 String uh = st.next_token ();
397 StringTokenizer st2 (rest);
398 String c = st2.next_token (':');
400 bool joinAndMode = false;
402 cnx->bot->botInterp->RunHooks (Hook::JOIN, n + " " + c,
406 str2scm (c), SCM_UNDEFINED));
408 // This part of code is for the combined JOIN & MODE of ircd 2.9
409 if (c.find ('\007') >= 0)
412 StringTokenizer st3 (c);
413 c = st3.next_token ('\007');
414 String m = st3.rest ();
416 for (int i = 0; i < m.length (); i++)
417 mode = mode + " " + n;
420 if (n == cnx->bot->nickName)
422 cnx->bot->logLine (String ("Joined channel ") + c + ".");
423 if (cnx->bot->wantedChannels.find (c) !=
424 cnx->bot->wantedChannels.end ())
425 cnx->bot->channelList->
426 addChannel (cnx, c, cnx->bot->wantedChannels[c]->keep);
428 cnx->bot->channelList->addChannel (cnx, c);
429 cnx->queue->sendWho (c);
430 cnx->queue->sendChannelMode (String ("MODE ") + c + " b");
431 cnx->queue->sendChannelMode (String ("MODE ") + c);
435 Channel *ch = cnx->bot->channelList->getChannel (c);
438 ShitEntry *se = cnx->bot->shitList->getShit (n + "!" + uh, c);
439 if (se && se->isStillValid () &&
440 se->getShitLevel () >= ShitEntry::SHIT_NOJOIN)
442 cnx->queue->sendChannelMode (c, "+b", se->getMask ());
443 cnx->queue->sendKick (c, n, se->getShitReason ());
446 ch->addNick (n, uh, 0, cnx->bot->userList);
447 if (ch->getUser (n).getAop ()
448 && !(ch->getUser (n).mode & User::OP_MODE) && cnx->bot->iAmOp (c))
450 // This is a part of the antispoof code
451 ch->change_user_key (n, Utils::get_key ());
452 Commands::CTCP (cnx->bot, n, "PING",
453 ch->getUser(n).userkey + " " + c);
458 parseMode (cnx, 0, mode);
462 Parser::parseKick (ServerConnection * cnx, Person * from, String rest)
464 StringTokenizer st (rest);
465 String channel = st.next_token ();
466 String target = st.next_token ();
467 String reason = st.rest ().substr (1);
469 cnx->bot->botInterp->RunHooks (Hook::KICK,
471 from->getNick () + " " +
472 channel + " " + reason,
485 (reason), SCM_UNDEFINED));
487 if (target == cnx->bot->nickName)
489 cnx->bot->logLine (from->getAddress () +
490 " kicked me out of channel " + channel +
491 " (" + reason + ").");
492 cnx->queue->sendJoin (channel,
493 cnx->bot->channelList->
494 getChannel (channel)->channelKey);
495 cnx->bot->channelList->delChannel (channel);
499 if (!cnx->bot->channelList->getChannel (channel))
503 User u = cnx->bot->channelList->getChannel (channel)->getUser (target);
504 if (u.getProt () >= User::NO_KICK)
506 String fromNick = from->getNick ();
508 cnx->bot->channelList->getChannel (channel)->getUser (fromNick);
509 if (v.getProt () < User::NO_KICK)
511 cnx->bot->logLine (from->getAddress () + " kicked " + target +
512 " (protected) out of channel " + channel +
513 " (" + reason + ").");
514 cnx->queue->sendKick (channel, fromNick,
515 target + " \002is protected !\002");
519 catch (const ChannelUserList::user_not_found &e)
523 cnx->bot->channelList->getChannel (channel)->delNick (target);
528 Parser::parseMode (ServerConnection * cnx, Person * from, String rest)
530 StringTokenizer st (rest);
531 String ch = st.next_token ();
532 String modes = st.rest ();
535 cnx->bot->botInterp->RunHooks (Hook::MODE,
536 from->getNick () + " " + ch +
548 if (Utils::channel_p (ch))
550 Channel *c = cnx->bot->channelList->getChannel (ch);
554 c->parseMode (from, modes);
556 c->parseMode (0, modes);
561 Parser::parseNick (ServerConnection * cnx, Person * from, String rest)
563 String on_orig = from->getNick ();
564 String on = on_orig.toLower ();
565 String nn = rest.substr (1);
566 String nn_lower = nn.toLower ();
568 cnx->bot->botInterp->RunHooks (Hook::NICKNAME,
577 if ((cnx->bot->nickName).toLower () == on)
579 cnx->bot->userList->removeFirst ();
580 cnx->bot->userList->addUserFirst (nn + "!" +
581 cnx->bot->userHost, "*", 0,
583 cnx->bot->lastNickNameChange = time (0);
584 cnx->bot->nickName = nn;
588 if (cnx->bot->spyList.find (on) != cnx->bot->spyList.end ())
590 cnx->bot->spyList[nn_lower] = cnx->bot->spyList[on];
591 cnx->bot->spyList.erase (on);
594 for (std::map < String, Channel *,
595 std::less < String > >::iterator it =
596 cnx->bot->channelList->begin ();
597 it != cnx->bot->channelList->end (); ++it)
598 if ((*it).second->hasNick (on))
599 (*it).second->changeNick (on, nn_lower);
603 Parser::parseNotice (ServerConnection * cnx, Person * from, String rest)
607 nick = from->getNick ();
608 StringTokenizer st (rest);
609 String to = st.next_token ();
610 rest = st.rest ().substr (1);
611 if (rest[0] != '\001')
614 if (Utils::channel_p (to))
615 cnx->bot->botInterp->RunHooks (Hook::PUBLIC_NOTICE,
616 nick + " " + to + " " + rest,
625 cnx->bot->botInterp->RunHooks (Hook::NOTICE, nick + " " + rest,
635 rest = rest.substr (1, rest.length () - 2);
636 StringTokenizer st2 (rest);
637 String command = st2.next_token ();
640 cnx->bot->botInterp->RunHooks (Hook::CTCP_REPLY,
641 nick + " " + command + " " +
652 if (command == "PING")
654 StringTokenizer st3 (rest);
655 rest = st3.next_token ();
656 String c = st3.rest ();
657 Channel *channel = cnx->bot->channelList->getChannel (c);
659 if (channel && channel->hasNick (nick))
661 User u = cnx->bot->channelList->getChannel(c)->getUser(nick);
662 if (u.getAop () && !(u.mode & User::OP_MODE) && u.userkey == rest)
663 cnx->queue->sendChannelMode (c, "+o", nick);
669 Parser::parsePrivmsg (ServerConnection * cnx, Person * from, String rest)
671 String nick = from->getNick ();
672 StringTokenizer st (rest);
673 String to = st.next_token ();
674 String fromUserhost = Utils::get_userhost (from->getAddress ());
675 rest = st.rest ().substr (1);
676 if (++(cnx->bot->ignoredUserhosts[fromUserhost]) > Bot::MAX_MESSAGES)
678 if (cnx->bot->ignoredUserhosts[fromUserhost] == Bot::MAX_MESSAGES + 1)
681 cnx->bot->botInterp->RunHooks (Hook::FLOOD, nick,
686 cnx->bot->ignoredUserhosts[fromUserhost] += Bot::IGNORE_DELAY;
687 cnx->bot->logLine (from->getAddress () +
688 " is flooding me. We will ignore him/her/it.");
689 if (!Utils::channel_p (to))
691 sendNotice (String ("\002You are now being ignored for ") +
692 String ((long) Bot::IGNORE_DELAY) +
695 // The following lines reset the counter if you use the
696 // command "!sorry" (if '!' is your command char).
697 // This is not documented, I know. But one probably does
698 // not want that every users can bypass the flood control
699 // Of course, if you want this feature to remain 'secret',
700 // do not use it in public.
701 if (rest.toUpper () == String (cnx->bot->commandChar) + "SORRY")
703 cnx->bot->ignoredUserhosts[fromUserhost] = 0;
704 from->sendNotice ("\002Don't do it again!\002");
709 if (rest[0] == '\001')
711 rest = rest.substr (1, rest.length () - 2);
712 if (!Utils::channel_p (to))
713 for (std::map < String, Person *,
714 std::less < String > >::iterator it =
715 cnx->bot->spyList.begin (); it != cnx->bot->spyList.end (); ++it)
716 (*it).second->sendNotice (String ("CTCP From ") +
718 Parser::parseCTCP (cnx, from, to, rest);
722 if ((rest.length () < 5 ||
723 rest.substr (1, 5).toUpper () != "IDENT") &&
724 (rest.length () < 8 ||
725 rest.substr (1, 8).toUpper () != "PASSWORD") &&
726 !Utils::channel_p (to))
727 for (std::map < String, Person *,
728 std::less < String > >::iterator it =
729 cnx->bot->spyList.begin (); it != cnx->bot->spyList.end (); ++it)
730 (*it).second->sendNotice (String ("*") + nick + "* " + rest);
731 Parser::parseMessage (cnx, from, to, rest);
736 Parser::parsePart (ServerConnection * cnx, Person * from, String rest)
738 String n = from->getNick ();
739 StringTokenizer st (rest);
740 String channel = st.next_token ();
742 cnx->bot->botInterp->RunHooks (Hook::PART, n + " " + channel,
747 (channel), SCM_UNDEFINED));
749 if (n.toLower () == cnx->bot->nickName.toLower ())
751 cnx->bot->logLine (String ("Left channel ") + channel + ".");
752 cnx->bot->channelList->delChannel (channel);
756 Channel *c = cnx->bot->channelList->getChannel (channel);
760 if (c->operator_count () == 0 && c->user_count () == 1)
762 cnx->queue->sendPart (channel);
763 cnx->queue->sendJoin (channel,
764 cnx->bot->wantedChannels[channel]->key);
770 Parser::parsePing (ServerConnection * cnx, Person * from, String rest)
772 cnx->queue->sendPong (rest);
776 Parser::parsePong (ServerConnection * cnx, Person * from, String rest)
778 cnx->lag = (cnx->lag + 2 * (time (NULL) - cnx->pingTime)) / 3;
779 cnx->bot->sentPing = false;
783 Parser::parseQuit (ServerConnection * cnx, Person * from, String rest)
785 String n = from->getNick ();
787 cnx->bot->botInterp->RunHooks (Hook::SIGNOFF, n + " " + rest,
794 if (n == cnx->bot->nickName)
795 cnx->bot->stop = true;
796 for (std::map < String, Channel *,
797 std::less < String > >::iterator it =
798 cnx->bot->channelList->begin ();
799 it != cnx->bot->channelList->end (); ++it)
800 (*it).second->delNick (n);
804 Parser::parseTopic (ServerConnection * cnx, Person * from, String rest)
806 StringTokenizer st (rest);
807 String channel = st.next_token ();
808 String newTopic = st.rest ().substr (1);
809 Channel *c = cnx->bot->channelList->getChannel (channel);
811 cnx->bot->botInterp->RunHooks (Hook::TOPIC,
812 from->getNick () + " " +
813 channel + " " + newTopic,
823 (newTopic), SCM_UNDEFINED));
827 if (c->lockedTopic && from->getNick () != cnx->bot->nickName)
828 cnx->queue->sendTopic (channel, c->channelTopic);
829 c->channelTopic = newTopic;
833 Parser::parseCTCP (ServerConnection * cnx,
834 Person * from, String to, String parameters)
836 StringTokenizer st (parameters);
837 String command = Utils::to_upper (st.next_token ());
838 String nick = from->getNick ();
840 if (st.more_tokens_p ())
845 cnx->bot->botInterp->RunHooks (Hook::CTCP,
846 nick + " " + to + " " +
847 command + " " + rest,
859 if (command == "PING")
861 Commands::CTCPReply (cnx->bot, nick, "PING", rest);
863 else if (command == "VERSION")
865 Commands::CTCPReply (cnx->bot, nick, "VERSION",
866 cnx->bot->versionString);
868 else if (command == "CLOCK")
870 time_t diff = time (NULL) - cnx->bot->startTime;
871 Commands::CTCPReply (cnx->bot, nick, "CLOCK",
872 String ("elapsed time: ") +
873 String ((long) (diff / 86400)) +
875 String ((long) (diff % 86400) /
877 String ((long) (diff % 3600) / 60) +
878 "m" + String ((long) (diff % 60)) + "s");
880 else if (command == "COMMAND")
882 Commands::CTCPReply (cnx->bot, nick,
883 "COMMAND", String (cnx->bot->commandChar));
885 else if (command == "LAG")
887 Commands::CTCPReply (cnx->bot, nick, "LAG",
888 String ((long) cnx->lag) + " second(s)");
890 else if (command == "DCC")
892 StringTokenizer st2 (rest);
893 command = Utils::to_upper (st2.next_token ());
894 if (command == "CHAT")
898 unsigned long address =
899 std::strtoul (st2.next_token ().c_str(), 0, 0);
900 int port = std::atoi (st2.next_token().c_str());
901 if (port >= 1024 && Utils::get_level (cnx->bot, from->getAddress ()))
902 cnx->bot->addDCC (from, address, port, Bot::CHAT);
904 cnx->bot->logLine ("DCC Chat Failed in Parser");
908 else if (command == "ACTION")
910 cnx->bot->botInterp->RunHooks (Hook::ACTION,
911 from->getNick () + " " + to +
927 Parser::parseMessage (ServerConnection * cnx,
928 Person * from, String to, String parameters)
931 if (Utils::channel_p (to))
932 cnx->bot->botInterp->RunHooks (Hook::PUBLIC,
933 from->getNick () + " " + to +
943 (parameters), SCM_UNDEFINED));
945 cnx->bot->botInterp->RunHooks (Hook::MESSAGE,
946 from->getNick () + " " +
954 (parameters), SCM_UNDEFINED));
956 if (parameters[0] != cnx->bot->commandChar)
959 StringTokenizer st (parameters);
960 String command = Utils::to_upper (st.next_token ().substr (1));
961 String rest = Utils::trim_str (st.rest ());
963 bool identified = false;
964 std::map<std::string, class userFunction*,
965 std::less<std::string> >::const_iterator uf_iter
966 = cnx->bot->userFunctions.find (command);
967 userFunction * f = 0;
969 if (uf_iter != cnx->bot->userFunctions.end ())
976 if (f->needsChannelName)
978 if (Utils::channel_p (rest))
980 StringTokenizer st2 (rest);
981 to = st.next_token ();
984 if (!Utils::channel_p (to))
986 from->sendNotice ("\002You need to supply a channel name"
987 " for this command\002");
990 if (!cnx->bot->channelList->getChannel (to))
992 from->sendNotice (String ("\002I am not on channel\002 ") +
996 level = Utils::get_level (cnx->bot, from->getAddress (), to);
998 Channel * c = cnx->bot->channelList->getChannel (to);
999 if (c && c->hasNick (from->getNick ()))
1001 User u = c->getUser (from->getNick ());
1002 if (!u.userListItem)
1005 identified = u.userListItem->passwd == ""
1006 || u.userListItem->identified > 0;
1015 level = Utils::get_level (cnx->bot, from->getAddress ());
1018 if (level >= f->minLevel)
1020 cnx->bot->logLine (from->getAddress () + " did " + command +
1023 if (f->argsCount != -1)
1025 Parser::parseScriptFunction (cnx, to, f->needsChannelName,
1026 f->scmFunc, f->argsCount,
1031 f->function (cnx, from, to, rest);
1034 f->function (cnx, from, to, rest);
1042 ("\002You are not identified on channel\002 ") +
1050 Parser::parseScriptFunction (ServerConnection * cnx,
1052 bool needsChannelName,
1053 SCM scmFunc, int argsCount, String parameters)
1056 SCM args_list = scm_list_n (SCM_UNDEFINED);
1057 if (needsChannelName)
1059 args_list = scm_append (scm_list_2 (args_list,
1066 StringTokenizer st (parameters);
1067 for (int i = argsCount; i > 0; i--)
1072 param = st.next_token ();
1073 args_list = scm_append (scm_list_2 (args_list,
1074 scm_list_n (Utils::str2scm (param),
1078 struct wrapper_data wd;
1080 wd.args = args_list;
1081 scm_c_with_throw_handler (SCM_BOOL_T,
1082 (scm_t_catch_body) Interp::LazyApplyWrapper,
1084 (scm_t_catch_handler) Interp::EmptyHandler,