1 // Parser.C -*- C++ -*-
2 // Copyright (c) 1997, 1998 Etienne BERNARD
3 // Copyright (C) 2002,2003,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 <sys/types.h>
25 #include <netinet/in.h>
27 #include "StringTokenizer.H"
29 #include "UserCommands.H"
35 typedef void (*fptr) (ServerConnection *, Person *, String);
36 std::map < std::string, fptr, std::less < std::string > > Parser::functions;
42 Parser::functions["001"] = Parser::parse001; /* RPL_WELCOME */
43 Parser::functions["302"] = Parser::parse302; /* RPL_USERHOST */
44 Parser::functions["311"] = Parser::parse311; /* RPL_WHOISUSER */
45 Parser::functions["315"] = Parser::parse315; /* RPL_ENDOFWHO */
46 Parser::functions["324"] = Parser::parse324; /* RPL_CHANNELMODEIS */
47 Parser::functions["332"] = Parser::parse332; /* RPL_TOPIC */
48 Parser::functions["352"] = Parser::parse352; /* RPL_WHOREPLY */
49 Parser::functions["353"] = Parser::parse353; /* RPL_NAMESREPLY */
50 Parser::functions["366"] = Parser::parse366; /* RPL_ENDOFNAMES */
51 Parser::functions["367"] = Parser::parse367; /* RPL_BANLIST */
52 Parser::functions["401"] = Parser::parse401; /* ERR_NOSUCHNICK */
53 Parser::functions["433"] = Parser::parse433; /* ERR_NICKNAMEINUSE */
54 Parser::functions["437"] = Parser::parse433; /* ERR_UNAVAILRESOURCE */
55 Parser::functions["471"] = Parser::parse473; /* ERR_CHANNELISFULL */
56 Parser::functions["473"] = Parser::parse473; /* ERR_INVITEONLYCHAN */
57 Parser::functions["474"] = Parser::parse473; /* ERR_BANNEDFROMCHAN */
58 Parser::functions["475"] = Parser::parse473; /* ERR_BADCHANNELKEY */
59 Parser::functions["ERROR"] = Parser::parseError;
60 Parser::functions["INVITE"] = Parser::parseInvite;
61 Parser::functions["JOIN"] = Parser::parseJoin;
62 Parser::functions["KICK"] = Parser::parseKick;
63 Parser::functions["MODE"] = Parser::parseMode;
64 Parser::functions["NICK"] = Parser::parseNick;
65 Parser::functions["NOTICE"] = Parser::parseNotice;
66 Parser::functions["PART"] = Parser::parsePart;
67 Parser::functions["PING"] = Parser::parsePing;
68 Parser::functions["PONG"] = Parser::parsePong;
69 Parser::functions["PRIVMSG"] = Parser::parsePrivmsg;
70 Parser::functions["QUIT"] = Parser::parseQuit;
71 Parser::functions["TOPIC"] = Parser::parseTopic;
72 Parser::functions[""] = Parser::parseError;
77 Parser::parseLine (ServerConnection * cnx, String line)
79 StringTokenizer st (line);
82 cnx->bot->botInterp->RunHooks (Hook::RAW, line,
89 String fromMask = st.next_token ().substr (1);
90 if (fromMask.find ('!') != -1)
91 from = new Person (cnx->bot, fromMask);
94 String command = st.next_token ();
95 String rest = st.rest ();
97 // We must use map<>::find or else a new entry will be created in
98 // the map which will cause another lookup of the same invalid
99 // command to segfault the bot
100 std::map<std::string, fptr, std::less<std::string> >::const_iterator cit
101 = functions.find (command);
103 if (cit != functions.end ())
105 fptr temp_func = cit->second;
106 temp_func (cnx, from, rest);
113 Parser::parse001 (ServerConnection * cnx, Person * from, String rest)
116 StringTokenizer st (rest);
117 String realNick = st.next_token ();
118 if ((cnx->bot->nickName).toLower () != realNick.toLower ())
120 // Yes, this can happen, and it was a very subtle bug
121 cnx->bot->nickName = realNick;
122 cnx->bot->userList->removeFirst ();
123 cnx->bot->userList->addUserFirst (realNick + "!" +
124 cnx->bot->userHost, "*", 0,
126 cnx->bot->lastNickNameChange = time (0);
130 cnx->bot->connected = true;
131 cnx->queue->sendUserMode (cnx->bot->nickName, "+i");
132 cnx->queue->sendWhois (cnx->bot->nickName);
133 for (std::map < String, wantedChannel *,
134 std::less < String > >::iterator it =
135 cnx->bot->wantedChannels.begin ();
136 it != cnx->bot->wantedChannels.end (); ++it)
137 cnx->queue->sendJoin ((*it).first, (*it).second->key);
138 cnx->bot->logLine (String ("Connected to server ") +
139 cnx->bot->serverList->currentServer ()->
140 getHostName () + " (" +
141 String ((long) cnx->bot->serverList->
142 currentServer ()->getPort ()) + ").");
146 Parser::parse302 (ServerConnection * cnx, Person * from, String rest)
148 unsigned long num = cnx->bot->receivedUserhostID++;
149 StringTokenizer st (rest);
151 if (st.rest ().length ())
154 String parameters = st.rest ();
155 parameters = parameters.substr (1);
156 cnx->bot->userhostMap[num] = parameters;
159 cnx->bot->userhostMap[num] = "";
163 Parser::parse311 (ServerConnection * cnx, Person * from, String rest)
165 StringTokenizer st (rest);
167 String nuh = st.next_token () + "!";
168 String uh = st.next_token () + "@";
169 uh = uh + st.next_token ();
171 cnx->bot->userList->addUserFirst (nuh, "*", 0, 3, true, -1, "");
172 cnx->bot->userHost = uh;
176 Parser::parse315 (ServerConnection * cnx, Person * from, String rest)
178 StringTokenizer st (rest);
180 String channel = st.next_token ();
181 Channel *c = cnx->bot->channelList->getChannel (channel);
188 Parser::parse324 (ServerConnection * cnx, Person * from, String rest)
190 StringTokenizer st (rest);
192 String channel = st.next_token ();
193 if (Channel * c = cnx->bot->channelList->getChannel (channel))
195 c->parseMode (from, st.rest ());
199 Parser::parse332 (ServerConnection * cnx, Person * from, String rest)
201 StringTokenizer st (rest);
203 String channel = st.next_token ();
204 if (Channel * c = cnx->bot->channelList->getChannel (channel))
206 c->channelTopic = st.rest ().substr (1);
210 Parser::parse352 (ServerConnection * cnx, Person * from, String rest)
212 StringTokenizer st (rest);
214 String ch = st.next_token ();
215 String uh = st.next_token () + "@";
216 uh = uh + st.next_token ();
218 String n = st.next_token ();
219 String m = st.next_token ();
221 for (int i = 0; i < m.length (); i++)
227 mode |= User::AWAY_MODE;
230 mode |= User::IRCOP_MODE;
233 mode |= User::OP_MODE;
236 mode |= User::VOICE_MODE;
239 if (Channel * c = cnx->bot->channelList->getChannel (ch))
241 c->addNick (n, uh, mode, cnx->bot->userList);
245 Parser::parse353 (ServerConnection * cnx, Person * from, String rest)
249 StringTokenizer st (rest);
252 Channel *c = cnx->bot->channelList->getChannel (st.next_token ());
255 StringTokenizer st2 (st.next_token (':'));
256 while (st2.more_tokens_p ())
258 nick = st2.next_token ();
261 mode = User::OP_MODE;
262 nick = nick.substr (1);
264 else if (nick[0] == '+')
266 mode = User::VOICE_MODE;
267 nick = nick.substr (1);
269 c->addNick (nick, "", mode, 0, true);
274 Parser::parse366 (ServerConnection * cnx, Person * from, String rest)
276 StringTokenizer st (rest);
278 String ch = st.next_token ();
279 if (Channel * c = cnx->bot->channelList->getChannel (ch))
284 Parser::parse367 (ServerConnection * cnx, Person * from, String rest)
286 StringTokenizer st (rest);
288 String ch = st.next_token ();
289 if (Channel * c = cnx->bot->channelList->getChannel (ch))
290 c->addBan (st.next_token (), -1);
294 Parser::parse401 (ServerConnection * cnx, Person * from, String rest)
296 StringTokenizer st (rest);
298 String nick = st.next_token ();
299 if (cnx->bot->spyList.find (nick) != cnx->bot->spyList.end ())
301 delete cnx->bot->spyList[nick];
302 cnx->bot->spyList.erase (nick);
307 Parser::parse433 (ServerConnection * cnx, Person * from, String rest)
309 if (cnx->bot->connected)
311 if (cnx->bot->nickName.length () == 9)
315 i < cnx->bot->nickName.length ()
316 && cnx->bot->nickName[i] == '_'; i++);
317 if (i < cnx->bot->nickName.length ())
319 cnx->bot->nickName.substr (0,
321 cnx->bot->nickName.substr (i + 1);
323 cnx->bot->nickName = cnx->bot->nickName.substr (0, 4) +
324 String ((long) (rand () % 10000));
327 cnx->bot->nickName = cnx->bot->nickName + "_";
328 cnx->queue->sendNick (cnx->bot->nickName);
332 Parser::parse473 (ServerConnection * cnx, Person * from, String rest)
334 StringTokenizer st (rest);
336 cnx->bot->logLine (String ("Unable to join channel ") +
337 st.next_token () + ".");
341 Parser::parseError (ServerConnection * cnx, Person * from, String rest)
343 cnx->bot->logLine (String ("Error from server ") +
344 cnx->bot->serverList->currentServer ()->
345 getHostName () + " (" +
346 String ((long) cnx->bot->serverList->
347 currentServer ()->getPort ()) + ").");
348 cnx->bot->nextServer ();
352 Parser::parseInvite (ServerConnection * cnx, Person * from, String rest)
354 String nick = from->getNick ();
355 StringTokenizer st (rest);
357 String channel = st.rest ();
359 cnx->bot->botInterp->RunHooks (Hook::INVITE,
360 nick + " " + channel,
365 (channel), SCM_UNDEFINED));
367 if (cnx->bot->wantedChannels.find (channel) !=
368 cnx->bot->wantedChannels.end ())
369 cnx->queue->sendJoin (channel, cnx->bot->wantedChannels[channel]->key);
373 Parser::parseJoin (ServerConnection * cnx, Person * from, String rest)
375 StringTokenizer st (from->getAddress ());
376 String n = st.next_token ('!');
377 String uh = st.next_token ();
378 StringTokenizer st2 (rest);
379 String c = st2.next_token (':');
381 bool joinAndMode = false;
383 cnx->bot->botInterp->RunHooks (Hook::JOIN, n + " " + c,
387 str2scm (c), SCM_UNDEFINED));
389 // This part of code is for the combined JOIN & MODE of ircd 2.9
390 if (c.find ('\007') >= 0)
393 StringTokenizer st3 (c);
394 c = st3.next_token ('\007');
395 String m = st3.rest ();
397 for (int i = 0; i < m.length (); i++)
398 mode = mode + " " + n;
401 if (n == cnx->bot->nickName)
403 cnx->bot->logLine (String ("Joined channel ") + c + ".");
404 if (cnx->bot->wantedChannels.find (c) !=
405 cnx->bot->wantedChannels.end ())
406 cnx->bot->channelList->
407 addChannel (cnx, c, cnx->bot->wantedChannels[c]->keep);
409 cnx->bot->channelList->addChannel (cnx, c);
410 cnx->queue->sendWho (c);
411 cnx->queue->sendChannelMode (String ("MODE ") + c + " b");
412 cnx->queue->sendChannelMode (String ("MODE ") + c);
416 Channel *ch = cnx->bot->channelList->getChannel (c);
419 ShitEntry *se = cnx->bot->shitList->getShit (n + "!" + uh, c);
420 if (se && se->isStillValid () &&
421 se->getShitLevel () >= ShitEntry::SHIT_NOJOIN)
423 cnx->queue->sendChannelMode (c, "+b", se->getMask ());
424 cnx->queue->sendKick (c, n, se->getShitReason ());
427 ch->addNick (n, uh, 0, cnx->bot->userList);
428 if (ch->getUser (n)->getAop ()
429 && !(ch->getUser (n)->mode & User::OP_MODE) && cnx->bot->iAmOp (c))
431 // This is a part of the antispoof code
432 ch->getUser(n)->userkey = Utils::get_key ();
433 Commands::CTCP (cnx->bot, n, "PING",
434 ch->getUser(n)->userkey + " " + c);
439 parseMode (cnx, 0, mode);
443 Parser::parseKick (ServerConnection * cnx, Person * from, String rest)
445 StringTokenizer st (rest);
446 String channel = st.next_token ();
447 String target = st.next_token ();
448 String reason = st.rest ().substr (1);
450 cnx->bot->botInterp->RunHooks (Hook::KICK,
452 from->getNick () + " " +
453 channel + " " + reason,
466 (reason), SCM_UNDEFINED));
468 if (target == cnx->bot->nickName)
470 cnx->bot->logLine (from->getAddress () +
471 " kicked me out of channel " + channel +
472 " (" + reason + ").");
473 cnx->queue->sendJoin (channel,
474 cnx->bot->channelList->
475 getChannel (channel)->channelKey);
476 cnx->bot->channelList->delChannel (channel);
480 if (!cnx->bot->channelList->getChannel (channel))
482 User *u = cnx->bot->channelList->getChannel (channel)->getUser (target);
483 if (u && u->getProt () >= User::NO_KICK)
485 String fromNick = from->getNick ();
487 cnx->bot->channelList->getChannel (channel)->getUser (fromNick);
488 if (v->getProt () < User::NO_KICK)
490 cnx->bot->logLine (from->getAddress () + " kicked " + target +
491 " (protected) out of channel " + channel +
492 " (" + reason + ").");
493 cnx->queue->sendKick (channel, fromNick,
494 target + " \002is protected !\002");
497 cnx->bot->channelList->getChannel (channel)->delNick (target);
502 Parser::parseMode (ServerConnection * cnx, Person * from, String rest)
504 StringTokenizer st (rest);
505 String ch = st.next_token ();
506 String modes = st.rest ();
509 cnx->bot->botInterp->RunHooks (Hook::MODE,
510 from->getNick () + " " + ch +
522 if (Utils::channel_p (ch))
524 Channel *c = cnx->bot->channelList->getChannel (ch);
528 c->parseMode (from, modes);
530 c->parseMode (0, modes);
535 Parser::parseNick (ServerConnection * cnx, Person * from, String rest)
537 String on_orig = from->getNick ();
538 String on = on_orig.toLower ();
539 String nn = rest.substr (1);
540 String nn_lower = nn.toLower ();
542 cnx->bot->botInterp->RunHooks (Hook::NICKNAME,
551 if ((cnx->bot->nickName).toLower () == on)
553 cnx->bot->userList->removeFirst ();
554 cnx->bot->userList->addUserFirst (nn + "!" +
555 cnx->bot->userHost, "*", 0,
557 cnx->bot->lastNickNameChange = time (0);
558 cnx->bot->nickName = nn;
562 if (cnx->bot->spyList.find (on) != cnx->bot->spyList.end ())
564 cnx->bot->spyList[nn_lower] = cnx->bot->spyList[on];
565 cnx->bot->spyList.erase (on);
568 for (std::map < String, Channel *,
569 std::less < String > >::iterator it =
570 cnx->bot->channelList->begin ();
571 it != cnx->bot->channelList->end (); ++it)
572 if ((*it).second->hasNick (on))
573 (*it).second->changeNick (on, nn_lower);
577 Parser::parseNotice (ServerConnection * cnx, Person * from, String rest)
581 nick = from->getNick ();
582 StringTokenizer st (rest);
583 String to = st.next_token ();
584 rest = st.rest ().substr (1);
585 if (rest[0] != '\001')
588 if (Utils::channel_p (to))
589 cnx->bot->botInterp->RunHooks (Hook::PUBLIC_NOTICE,
590 nick + " " + to + " " + rest,
599 cnx->bot->botInterp->RunHooks (Hook::NOTICE, nick + " " + rest,
609 rest = rest.substr (1, rest.length () - 2);
610 StringTokenizer st2 (rest);
611 String command = st2.next_token ();
614 cnx->bot->botInterp->RunHooks (Hook::CTCP_REPLY,
615 nick + " " + command + " " +
626 if (command == "PING")
628 StringTokenizer st3 (rest);
629 rest = st3.next_token ();
630 String c = st3.rest ();
631 if (cnx->bot->channelList->getChannel (c) &&
632 cnx->bot->channelList->getChannel (c)->getUser (nick) &&
633 cnx->bot->channelList->getChannel (c)->getUser (nick)->
635 && !(cnx->bot->channelList->getChannel (c)->
636 getUser (nick)->mode & User::OP_MODE)
637 && cnx->bot->channelList->getChannel (c)->getUser (nick)->
639 cnx->queue->sendChannelMode (c, "+o", nick);
644 Parser::parsePrivmsg (ServerConnection * cnx, Person * from, String rest)
646 String nick = from->getNick ();
647 StringTokenizer st (rest);
648 String to = st.next_token ();
649 String fromUserhost = Utils::get_userhost (from->getAddress ());
650 rest = st.rest ().substr (1);
651 if (++(cnx->bot->ignoredUserhosts[fromUserhost]) > Bot::MAX_MESSAGES)
653 if (cnx->bot->ignoredUserhosts[fromUserhost] == Bot::MAX_MESSAGES + 1)
656 cnx->bot->botInterp->RunHooks (Hook::FLOOD, nick,
661 cnx->bot->ignoredUserhosts[fromUserhost] += Bot::IGNORE_DELAY;
662 cnx->bot->logLine (from->getAddress () +
663 " is flooding me. We will ignore him/her/it.");
664 if (!Utils::channel_p (to))
666 sendNotice (String ("\002You are now being ignored for ") +
667 String ((long) Bot::IGNORE_DELAY) +
670 // The following lines reset the counter if you use the
671 // command "!sorry" (if '!' is your command char).
672 // This is not documented, I know. But one probably does
673 // not want that every users can bypass the flood control
674 // Of course, if you want this feature to remain 'secret',
675 // do not use it in public.
676 if (rest.toUpper () == String (cnx->bot->commandChar) + "SORRY")
678 cnx->bot->ignoredUserhosts[fromUserhost] = 0;
679 from->sendNotice ("\002Don't do it again!\002");
684 if (rest[0] == '\001')
686 rest = rest.substr (1, rest.length () - 2);
687 if (!Utils::channel_p (to))
688 for (std::map < String, Person *,
689 std::less < String > >::iterator it =
690 cnx->bot->spyList.begin (); it != cnx->bot->spyList.end (); ++it)
691 (*it).second->sendNotice (String ("CTCP From ") +
693 Parser::parseCTCP (cnx, from, to, rest);
697 if ((rest.length () < 5 ||
698 rest.substr (1, 5).toUpper () != "IDENT") &&
699 (rest.length () < 8 ||
700 rest.substr (1, 8).toUpper () != "PASSWORD") &&
701 !Utils::channel_p (to))
702 for (std::map < String, Person *,
703 std::less < String > >::iterator it =
704 cnx->bot->spyList.begin (); it != cnx->bot->spyList.end (); ++it)
705 (*it).second->sendNotice (String ("*") + nick + "* " + rest);
706 Parser::parseMessage (cnx, from, to, rest);
711 Parser::parsePart (ServerConnection * cnx, Person * from, String rest)
713 String n = from->getNick ();
714 StringTokenizer st (rest);
715 String channel = st.next_token ();
717 cnx->bot->botInterp->RunHooks (Hook::PART, n + " " + channel,
722 (channel), SCM_UNDEFINED));
724 if (n.toLower () == cnx->bot->nickName.toLower ())
726 cnx->bot->logLine (String ("Left channel ") + channel + ".");
727 cnx->bot->channelList->delChannel (channel);
731 Channel *c = cnx->bot->channelList->getChannel (channel);
735 if (c->countOp == 0 && c->count == 1)
737 cnx->queue->sendPart (channel);
738 cnx->queue->sendJoin (channel,
739 cnx->bot->wantedChannels[channel]->key);
745 Parser::parsePing (ServerConnection * cnx, Person * from, String rest)
747 cnx->queue->sendPong (rest);
751 Parser::parsePong (ServerConnection * cnx, Person * from, String rest)
753 cnx->lag = (cnx->lag + 2 * (time (NULL) - cnx->pingTime)) / 3;
754 cnx->bot->sentPing = false;
758 Parser::parseQuit (ServerConnection * cnx, Person * from, String rest)
760 String n = from->getNick ();
762 cnx->bot->botInterp->RunHooks (Hook::SIGNOFF, n + " " + rest,
769 if (n == cnx->bot->nickName)
770 cnx->bot->stop = true;
771 for (std::map < String, Channel *,
772 std::less < String > >::iterator it =
773 cnx->bot->channelList->begin ();
774 it != cnx->bot->channelList->end (); ++it)
775 (*it).second->delNick (n);
779 Parser::parseTopic (ServerConnection * cnx, Person * from, String rest)
781 StringTokenizer st (rest);
782 String channel = st.next_token ();
783 String newTopic = st.rest ().substr (1);
784 Channel *c = cnx->bot->channelList->getChannel (channel);
786 cnx->bot->botInterp->RunHooks (Hook::TOPIC,
787 from->getNick () + " " +
788 channel + " " + newTopic,
798 (newTopic), SCM_UNDEFINED));
802 if (c->lockedTopic && from->getNick () != cnx->bot->nickName)
803 cnx->queue->sendTopic (channel, c->channelTopic);
804 c->channelTopic = newTopic;
808 Parser::parseCTCP (ServerConnection * cnx,
809 Person * from, String to, String parameters)
811 StringTokenizer st (parameters);
812 String command = Utils::to_upper (st.next_token ());
813 String nick = from->getNick ();
815 if (st.more_tokens_p ())
820 cnx->bot->botInterp->RunHooks (Hook::CTCP,
821 nick + " " + to + " " +
822 command + " " + rest,
834 if (command == "PING")
836 Commands::CTCPReply (cnx->bot, nick, "PING", rest);
838 else if (command == "VERSION")
840 Commands::CTCPReply (cnx->bot, nick, "VERSION",
841 cnx->bot->versionString);
843 else if (command == "CLOCK")
845 time_t diff = time (NULL) - cnx->bot->startTime;
846 Commands::CTCPReply (cnx->bot, nick, "CLOCK",
847 String ("elapsed time: ") +
848 String ((long) (diff / 86400)) +
850 String ((long) (diff % 86400) /
852 String ((long) (diff % 3600) / 60) +
853 "m" + String ((long) (diff % 60)) + "s");
855 else if (command == "COMMAND")
857 Commands::CTCPReply (cnx->bot, nick,
858 "COMMAND", String (cnx->bot->commandChar));
860 else if (command == "LAG")
862 Commands::CTCPReply (cnx->bot, nick, "LAG",
863 String ((long) cnx->lag) + " second(s)");
865 else if (command == "DCC")
867 StringTokenizer st2 (rest);
868 command = Utils::to_upper (st2.next_token ());
869 if (command == "CHAT")
873 unsigned long address =
874 std::strtoul (st2.next_token ().c_str(), 0, 0);
875 int port = std::atoi (st2.next_token().c_str());
876 if (port >= 1024 && Utils::get_level (cnx->bot, from->getAddress ()))
877 cnx->bot->addDCC (from, address, port, Bot::CHAT);
879 cnx->bot->logLine ("DCC Chat Failed in Parser");
883 else if (command == "ACTION")
885 cnx->bot->botInterp->RunHooks (Hook::ACTION,
886 from->getNick () + " " + to +
902 Parser::parseMessage (ServerConnection * cnx,
903 Person * from, String to, String parameters)
906 if (Utils::channel_p (to))
907 cnx->bot->botInterp->RunHooks (Hook::PUBLIC,
908 from->getNick () + " " + to +
918 (parameters), SCM_UNDEFINED));
920 cnx->bot->botInterp->RunHooks (Hook::MESSAGE,
921 from->getNick () + " " +
929 (parameters), SCM_UNDEFINED));
931 if (parameters[0] != cnx->bot->commandChar)
934 StringTokenizer st (parameters);
935 String command = Utils::to_upper (st.next_token ().substr (1));
936 String rest = Utils::trim_str (st.rest ());
938 bool identified = false;
939 std::map<std::string, class userFunction*,
940 std::less<std::string> >::const_iterator uf_iter
941 = cnx->bot->userFunctions.find (command);
942 userFunction * f = 0;
944 if (uf_iter != cnx->bot->userFunctions.end ())
951 if (f->needsChannelName)
953 if (Utils::channel_p (rest))
955 StringTokenizer st2 (rest);
956 to = st.next_token ();
959 if (!Utils::channel_p (to))
961 from->sendNotice ("\002You need to supply a channel name"
962 " for this command\002");
965 if (!cnx->bot->channelList->getChannel (to))
967 from->sendNotice (String ("\002I am not on channel\002 ") +
971 level = Utils::get_level (cnx->bot, from->getAddress (), to);
973 if (Channel * c = cnx->bot->channelList->getChannel (to))
974 u = c->getUser (from->getNick ());
975 if (!u || !u->userListItem)
978 identified = u->userListItem->passwd == ""
979 || u->userListItem->identified > 0;
983 level = Utils::get_level (cnx->bot, from->getAddress ());
986 if (level >= f->minLevel)
988 cnx->bot->logLine (from->getAddress () + " did " + command +
991 if (f->argsCount != -1)
993 Parser::parseScriptFunction (cnx, to, f->needsChannelName,
994 f->scmFunc, f->argsCount,
999 f->function (cnx, from, to, rest);
1002 f->function (cnx, from, to, rest);
1010 ("\002You are not identified on channel\002 ") +
1018 Parser::parseScriptFunction (ServerConnection * cnx,
1020 bool needsChannelName,
1021 SCM scmFunc, int argsCount, String parameters)
1024 SCM args_list = scm_listify (SCM_UNDEFINED);
1025 if (needsChannelName)
1027 args_list = gh_append2 (args_list,
1028 scm_listify (Utils::
1034 StringTokenizer st (parameters);
1035 for (int i = argsCount; i > 0; i--)
1040 param = st.next_token ();
1041 args_list = gh_append2 (args_list,
1042 scm_listify (Utils::str2scm (param),
1046 struct wrapper_data wd;
1048 wd.args = args_list;
1049 scm_internal_catch (SCM_BOOL_T,
1050 (scm_t_catch_body) Interp::LazyApplyWrapper,
1052 (scm_t_catch_handler) Interp::EmptyHandler, 0);