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
25 #include <sys/types.h>
26 #include <netinet/in.h>
28 #include "StringTokenizer.H"
30 #include "UserCommands.H"
36 typedef void (*fptr) (ServerConnection *, Person *, String);
37 std::map < std::string, fptr, std::less < std::string > > Parser::functions;
43 Parser::functions["001"] = Parser::parse001; /* RPL_WELCOME */
44 Parser::functions["302"] = Parser::parse302; /* RPL_USERHOST */
45 Parser::functions["311"] = Parser::parse311; /* RPL_WHOISUSER */
46 Parser::functions["315"] = Parser::parse315; /* RPL_ENDOFWHO */
47 Parser::functions["324"] = Parser::parse324; /* RPL_CHANNELMODEIS */
48 Parser::functions["332"] = Parser::parse332; /* RPL_TOPIC */
49 Parser::functions["352"] = Parser::parse352; /* RPL_WHOREPLY */
50 Parser::functions["353"] = Parser::parse353; /* RPL_NAMESREPLY */
51 Parser::functions["366"] = Parser::parse366; /* RPL_ENDOFNAMES */
52 Parser::functions["367"] = Parser::parse367; /* RPL_BANLIST */
53 Parser::functions["401"] = Parser::parse401; /* ERR_NOSUCHNICK */
54 Parser::functions["433"] = Parser::parse433; /* ERR_NICKNAMEINUSE */
55 Parser::functions["437"] = Parser::parse433; /* ERR_UNAVAILRESOURCE */
56 Parser::functions["471"] = Parser::parse473; /* ERR_CHANNELISFULL */
57 Parser::functions["473"] = Parser::parse473; /* ERR_INVITEONLYCHAN */
58 Parser::functions["474"] = Parser::parse473; /* ERR_BANNEDFROMCHAN */
59 Parser::functions["475"] = Parser::parse473; /* ERR_BADCHANNELKEY */
60 Parser::functions["ERROR"] = Parser::parseError;
61 Parser::functions["INVITE"] = Parser::parseInvite;
62 Parser::functions["JOIN"] = Parser::parseJoin;
63 Parser::functions["KICK"] = Parser::parseKick;
64 Parser::functions["MODE"] = Parser::parseMode;
65 Parser::functions["NICK"] = Parser::parseNick;
66 Parser::functions["NOTICE"] = Parser::parseNotice;
67 Parser::functions["PART"] = Parser::parsePart;
68 Parser::functions["PING"] = Parser::parsePing;
69 Parser::functions["PONG"] = Parser::parsePong;
70 Parser::functions["PRIVMSG"] = Parser::parsePrivmsg;
71 Parser::functions["QUIT"] = Parser::parseQuit;
72 Parser::functions["TOPIC"] = Parser::parseTopic;
73 Parser::functions[""] = Parser::parseError;
78 Parser::parseLine (ServerConnection * cnx, String line)
80 StringTokenizer st (line);
83 cnx->bot->botInterp->RunHooks (Hook::RAW, line,
90 String fromMask = st.next_token ().substr (1);
91 if (fromMask.find ('!') != -1)
92 from = new Person (cnx->bot, fromMask);
95 String command = st.next_token ();
96 String rest = st.rest ();
98 // We must use map<>::find or else a new entry will be created in
99 // the map which will cause another lookup of the same invalid
100 // command to segfault the bot
101 std::map<std::string, fptr, std::less<std::string> >::const_iterator cit
102 = functions.find (command);
104 if (cit != functions.end ())
106 fptr temp_func = cit->second;
107 temp_func (cnx, from, rest);
114 Parser::parse001 (ServerConnection * cnx, Person * from, String rest)
117 StringTokenizer st (rest);
118 String realNick = st.next_token ();
119 if ((cnx->bot->nickName).toLower () != realNick.toLower ())
121 // Yes, this can happen, and it was a very subtle bug
122 cnx->bot->nickName = realNick;
123 cnx->bot->userList->removeFirst ();
124 cnx->bot->userList->addUserFirst (realNick + "!" +
125 cnx->bot->userHost, "*", 0,
127 cnx->bot->lastNickNameChange = time (0);
131 cnx->bot->connected = true;
132 cnx->queue->sendUserMode (cnx->bot->nickName, "+i");
133 cnx->queue->sendWhois (cnx->bot->nickName);
134 for (std::map < String, wantedChannel *,
135 std::less < String > >::iterator it =
136 cnx->bot->wantedChannels.begin ();
137 it != cnx->bot->wantedChannels.end (); ++it)
138 cnx->queue->sendJoin ((*it).first, (*it).second->key);
139 cnx->bot->logLine (String ("Connected to server ") +
140 cnx->bot->serverList->currentServer ()->
141 getHostName () + " (" +
142 String ((long) cnx->bot->serverList->
143 currentServer ()->getPort ()) + ").");
147 Parser::parse302 (ServerConnection * cnx, Person * from, String rest)
149 unsigned long num = cnx->bot->receivedUserhostID++;
150 StringTokenizer st (rest);
152 if (st.rest ().length ())
155 String parameters = st.rest ();
156 parameters = parameters.substr (1);
157 cnx->bot->userhostMap[num] = parameters;
160 cnx->bot->userhostMap[num] = "";
164 Parser::parse311 (ServerConnection * cnx, Person * from, String rest)
166 StringTokenizer st (rest);
168 String nuh = st.next_token () + "!";
169 String uh = st.next_token () + "@";
170 uh = uh + st.next_token ();
172 cnx->bot->userList->addUserFirst (nuh, "*", 0, 3, true, -1, "");
173 cnx->bot->userHost = uh;
177 Parser::parse315 (ServerConnection * cnx, Person * from, String rest)
179 StringTokenizer st (rest);
181 String channel = st.next_token ();
182 Channel *c = cnx->bot->channelList->getChannel (channel);
189 Parser::parse324 (ServerConnection * cnx, Person * from, String rest)
191 StringTokenizer st (rest);
193 String channel = st.next_token ();
194 if (Channel * c = cnx->bot->channelList->getChannel (channel))
196 c->parseMode (from, st.rest ());
200 Parser::parse332 (ServerConnection * cnx, Person * from, String rest)
202 StringTokenizer st (rest);
204 String channel = st.next_token ();
205 if (Channel * c = cnx->bot->channelList->getChannel (channel))
207 c->channelTopic = st.rest ().substr (1);
211 Parser::parse352 (ServerConnection * cnx, Person * from, String rest)
213 StringTokenizer st (rest);
215 String ch = st.next_token ();
216 String uh = st.next_token () + "@";
217 uh = uh + st.next_token ();
219 String n = st.next_token ();
220 String m = st.next_token ();
222 for (int i = 0; i < m.length (); i++)
228 mode |= User::AWAY_MODE;
231 mode |= User::IRCOP_MODE;
234 mode |= User::OP_MODE;
237 mode |= User::VOICE_MODE;
240 if (Channel * c = cnx->bot->channelList->getChannel (ch))
242 c->addNick (n, uh, mode, cnx->bot->userList);
246 Parser::parse353 (ServerConnection * cnx, Person * from, String rest)
250 StringTokenizer st (rest);
253 Channel *c = cnx->bot->channelList->getChannel (st.next_token ());
256 StringTokenizer st2 (st.next_token (':'));
257 while (st2.more_tokens_p ())
259 nick = st2.next_token ();
262 mode = User::OP_MODE;
263 nick = nick.substr (1);
265 else if (nick[0] == '+')
267 mode = User::VOICE_MODE;
268 nick = nick.substr (1);
270 c->addNick (nick, "", mode, 0, true);
275 Parser::parse366 (ServerConnection * cnx, Person * from, String rest)
277 StringTokenizer st (rest);
279 String ch = st.next_token ();
280 if (Channel * c = cnx->bot->channelList->getChannel (ch))
285 Parser::parse367 (ServerConnection * cnx, Person * from, String rest)
287 StringTokenizer st (rest);
289 String ch = st.next_token ();
290 if (Channel * c = cnx->bot->channelList->getChannel (ch))
291 c->addBan (st.next_token (), -1);
295 Parser::parse401 (ServerConnection * cnx, Person * from, String rest)
297 StringTokenizer st (rest);
299 String nick = st.next_token ();
300 if (cnx->bot->spyList.find (nick) != cnx->bot->spyList.end ())
302 delete cnx->bot->spyList[nick];
303 cnx->bot->spyList.erase (nick);
308 Parser::parse433 (ServerConnection * cnx, Person * from, String rest)
310 if (cnx->bot->connected)
312 if (cnx->bot->nickName.length () == 9)
316 i < cnx->bot->nickName.length ()
317 && cnx->bot->nickName[i] == '_'; i++);
318 if (i < cnx->bot->nickName.length ())
320 cnx->bot->nickName.substr (0,
322 cnx->bot->nickName.substr (i + 1);
324 cnx->bot->nickName = cnx->bot->nickName.substr (0, 4) +
325 String ((long) (rand () % 10000));
328 cnx->bot->nickName = cnx->bot->nickName + "_";
329 cnx->queue->sendNick (cnx->bot->nickName);
333 Parser::parse473 (ServerConnection * cnx, Person * from, String rest)
335 StringTokenizer st (rest);
337 cnx->bot->logLine (String ("Unable to join channel ") +
338 st.next_token () + ".");
342 Parser::parseError (ServerConnection * cnx, Person * from, String rest)
344 cnx->bot->logLine (String ("Error from server ") +
345 cnx->bot->serverList->currentServer ()->
346 getHostName () + " (" +
347 String ((long) cnx->bot->serverList->
348 currentServer ()->getPort ()) + ").");
349 cnx->bot->nextServer ();
353 Parser::parseInvite (ServerConnection * cnx, Person * from, String rest)
355 String nick = from->getNick ();
356 StringTokenizer st (rest);
358 String channel = st.rest ();
360 cnx->bot->botInterp->RunHooks (Hook::INVITE,
361 nick + " " + channel,
366 (channel), SCM_UNDEFINED));
368 if (cnx->bot->wantedChannels.find (channel) !=
369 cnx->bot->wantedChannels.end ())
370 cnx->queue->sendJoin (channel, cnx->bot->wantedChannels[channel]->key);
374 Parser::parseJoin (ServerConnection * cnx, Person * from, String rest)
376 StringTokenizer st (from->getAddress ());
377 String n = st.next_token ('!');
378 String uh = st.next_token ();
379 StringTokenizer st2 (rest);
380 String c = st2.next_token (':');
382 bool joinAndMode = false;
384 cnx->bot->botInterp->RunHooks (Hook::JOIN, n + " " + c,
388 str2scm (c), SCM_UNDEFINED));
390 // This part of code is for the combined JOIN & MODE of ircd 2.9
391 if (c.find ('\007') >= 0)
394 StringTokenizer st3 (c);
395 c = st3.next_token ('\007');
396 String m = st3.rest ();
398 for (int i = 0; i < m.length (); i++)
399 mode = mode + " " + n;
402 if (n == cnx->bot->nickName)
404 cnx->bot->logLine (String ("Joined channel ") + c + ".");
405 if (cnx->bot->wantedChannels.find (c) !=
406 cnx->bot->wantedChannels.end ())
407 cnx->bot->channelList->
408 addChannel (cnx, c, cnx->bot->wantedChannels[c]->keep);
410 cnx->bot->channelList->addChannel (cnx, c);
411 cnx->queue->sendWho (c);
412 cnx->queue->sendChannelMode (String ("MODE ") + c + " b");
413 cnx->queue->sendChannelMode (String ("MODE ") + c);
417 Channel *ch = cnx->bot->channelList->getChannel (c);
420 ShitEntry *se = cnx->bot->shitList->getShit (n + "!" + uh, c);
421 if (se && se->isStillValid () &&
422 se->getShitLevel () >= ShitEntry::SHIT_NOJOIN)
424 cnx->queue->sendChannelMode (c, "+b", se->getMask ());
425 cnx->queue->sendKick (c, n, se->getShitReason ());
428 ch->addNick (n, uh, 0, cnx->bot->userList);
429 if (ch->getUser (n)->getAop ()
430 && !(ch->getUser (n)->mode & User::OP_MODE) && cnx->bot->iAmOp (c))
432 // This is a part of the antispoof code
433 ch->getUser(n)->userkey = Utils::get_key ();
434 Commands::CTCP (cnx->bot, n, "PING",
435 ch->getUser(n)->userkey + " " + c);
440 parseMode (cnx, 0, mode);
444 Parser::parseKick (ServerConnection * cnx, Person * from, String rest)
446 StringTokenizer st (rest);
447 String channel = st.next_token ();
448 String target = st.next_token ();
449 String reason = st.rest ().substr (1);
451 cnx->bot->botInterp->RunHooks (Hook::KICK,
453 from->getNick () + " " +
454 channel + " " + reason,
467 (reason), SCM_UNDEFINED));
469 if (target == cnx->bot->nickName)
471 cnx->bot->logLine (from->getAddress () +
472 " kicked me out of channel " + channel +
473 " (" + reason + ").");
474 cnx->queue->sendJoin (channel,
475 cnx->bot->channelList->
476 getChannel (channel)->channelKey);
477 cnx->bot->channelList->delChannel (channel);
481 if (!cnx->bot->channelList->getChannel (channel))
483 User *u = cnx->bot->channelList->getChannel (channel)->getUser (target);
484 if (u && u->getProt () >= User::NO_KICK)
486 String fromNick = from->getNick ();
488 cnx->bot->channelList->getChannel (channel)->getUser (fromNick);
489 if (v->getProt () < User::NO_KICK)
491 cnx->bot->logLine (from->getAddress () + " kicked " + target +
492 " (protected) out of channel " + channel +
493 " (" + reason + ").");
494 cnx->queue->sendKick (channel, fromNick,
495 target + " \002is protected !\002");
498 cnx->bot->channelList->getChannel (channel)->delNick (target);
503 Parser::parseMode (ServerConnection * cnx, Person * from, String rest)
505 StringTokenizer st (rest);
506 String ch = st.next_token ();
507 String modes = st.rest ();
510 cnx->bot->botInterp->RunHooks (Hook::MODE,
511 from->getNick () + " " + ch +
523 if (Utils::channel_p (ch))
525 Channel *c = cnx->bot->channelList->getChannel (ch);
529 c->parseMode (from, modes);
531 c->parseMode (0, modes);
536 Parser::parseNick (ServerConnection * cnx, Person * from, String rest)
538 String on_orig = from->getNick ();
539 String on = on_orig.toLower ();
540 String nn = rest.substr (1);
541 String nn_lower = nn.toLower ();
543 cnx->bot->botInterp->RunHooks (Hook::NICKNAME,
552 if ((cnx->bot->nickName).toLower () == on)
554 cnx->bot->userList->removeFirst ();
555 cnx->bot->userList->addUserFirst (nn + "!" +
556 cnx->bot->userHost, "*", 0,
558 cnx->bot->lastNickNameChange = time (0);
559 cnx->bot->nickName = nn;
563 if (cnx->bot->spyList.find (on) != cnx->bot->spyList.end ())
565 cnx->bot->spyList[nn_lower] = cnx->bot->spyList[on];
566 cnx->bot->spyList.erase (on);
569 for (std::map < String, Channel *,
570 std::less < String > >::iterator it =
571 cnx->bot->channelList->begin ();
572 it != cnx->bot->channelList->end (); ++it)
573 if ((*it).second->hasNick (on))
574 (*it).second->changeNick (on, nn_lower);
578 Parser::parseNotice (ServerConnection * cnx, Person * from, String rest)
582 nick = from->getNick ();
583 StringTokenizer st (rest);
584 String to = st.next_token ();
585 rest = st.rest ().substr (1);
586 if (rest[0] != '\001')
589 if (Utils::channel_p (to))
590 cnx->bot->botInterp->RunHooks (Hook::PUBLIC_NOTICE,
591 nick + " " + to + " " + rest,
600 cnx->bot->botInterp->RunHooks (Hook::NOTICE, nick + " " + rest,
610 rest = rest.substr (1, rest.length () - 2);
611 StringTokenizer st2 (rest);
612 String command = st2.next_token ();
615 cnx->bot->botInterp->RunHooks (Hook::CTCP_REPLY,
616 nick + " " + command + " " +
627 if (command == "PING")
629 StringTokenizer st3 (rest);
630 rest = st3.next_token ();
631 String c = st3.rest ();
632 if (cnx->bot->channelList->getChannel (c) &&
633 cnx->bot->channelList->getChannel (c)->getUser (nick) &&
634 cnx->bot->channelList->getChannel (c)->getUser (nick)->
636 && !(cnx->bot->channelList->getChannel (c)->
637 getUser (nick)->mode & User::OP_MODE)
638 && cnx->bot->channelList->getChannel (c)->getUser (nick)->
640 cnx->queue->sendChannelMode (c, "+o", nick);
645 Parser::parsePrivmsg (ServerConnection * cnx, Person * from, String rest)
647 String nick = from->getNick ();
648 StringTokenizer st (rest);
649 String to = st.next_token ();
650 String fromUserhost = Utils::get_userhost (from->getAddress ());
651 rest = st.rest ().substr (1);
652 if (++(cnx->bot->ignoredUserhosts[fromUserhost]) > Bot::MAX_MESSAGES)
654 if (cnx->bot->ignoredUserhosts[fromUserhost] == Bot::MAX_MESSAGES + 1)
657 cnx->bot->botInterp->RunHooks (Hook::FLOOD, nick,
662 cnx->bot->ignoredUserhosts[fromUserhost] += Bot::IGNORE_DELAY;
663 cnx->bot->logLine (from->getAddress () +
664 " is flooding me. We will ignore him/her/it.");
665 if (!Utils::channel_p (to))
667 sendNotice (String ("\002You are now being ignored for ") +
668 String ((long) Bot::IGNORE_DELAY) +
671 // The following lines reset the counter if you use the
672 // command "!sorry" (if '!' is your command char).
673 // This is not documented, I know. But one probably does
674 // not want that every users can bypass the flood control
675 // Of course, if you want this feature to remain 'secret',
676 // do not use it in public.
677 if (rest.toUpper () == String (cnx->bot->commandChar) + "SORRY")
679 cnx->bot->ignoredUserhosts[fromUserhost] = 0;
680 from->sendNotice ("\002Don't do it again!\002");
685 if (rest[0] == '\001')
687 rest = rest.substr (1, rest.length () - 2);
688 if (!Utils::channel_p (to))
689 for (std::map < String, Person *,
690 std::less < String > >::iterator it =
691 cnx->bot->spyList.begin (); it != cnx->bot->spyList.end (); ++it)
692 (*it).second->sendNotice (String ("CTCP From ") +
694 Parser::parseCTCP (cnx, from, to, rest);
698 if ((rest.length () < 5 ||
699 rest.substr (1, 5).toUpper () != "IDENT") &&
700 (rest.length () < 8 ||
701 rest.substr (1, 8).toUpper () != "PASSWORD") &&
702 !Utils::channel_p (to))
703 for (std::map < String, Person *,
704 std::less < String > >::iterator it =
705 cnx->bot->spyList.begin (); it != cnx->bot->spyList.end (); ++it)
706 (*it).second->sendNotice (String ("*") + nick + "* " + rest);
707 Parser::parseMessage (cnx, from, to, rest);
712 Parser::parsePart (ServerConnection * cnx, Person * from, String rest)
714 String n = from->getNick ();
715 StringTokenizer st (rest);
716 String channel = st.next_token ();
718 cnx->bot->botInterp->RunHooks (Hook::PART, n + " " + channel,
723 (channel), SCM_UNDEFINED));
725 if (n.toLower () == cnx->bot->nickName.toLower ())
727 cnx->bot->logLine (String ("Left channel ") + channel + ".");
728 cnx->bot->channelList->delChannel (channel);
732 Channel *c = cnx->bot->channelList->getChannel (channel);
736 if (c->countOp == 0 && c->count == 1)
738 cnx->queue->sendPart (channel);
739 cnx->queue->sendJoin (channel,
740 cnx->bot->wantedChannels[channel]->key);
746 Parser::parsePing (ServerConnection * cnx, Person * from, String rest)
748 cnx->queue->sendPong (rest);
752 Parser::parsePong (ServerConnection * cnx, Person * from, String rest)
754 cnx->lag = (cnx->lag + 2 * (time (NULL) - cnx->pingTime)) / 3;
755 cnx->bot->sentPing = false;
759 Parser::parseQuit (ServerConnection * cnx, Person * from, String rest)
761 String n = from->getNick ();
763 cnx->bot->botInterp->RunHooks (Hook::SIGNOFF, n + " " + rest,
770 if (n == cnx->bot->nickName)
771 cnx->bot->stop = true;
772 for (std::map < String, Channel *,
773 std::less < String > >::iterator it =
774 cnx->bot->channelList->begin ();
775 it != cnx->bot->channelList->end (); ++it)
776 (*it).second->delNick (n);
780 Parser::parseTopic (ServerConnection * cnx, Person * from, String rest)
782 StringTokenizer st (rest);
783 String channel = st.next_token ();
784 String newTopic = st.rest ().substr (1);
785 Channel *c = cnx->bot->channelList->getChannel (channel);
787 cnx->bot->botInterp->RunHooks (Hook::TOPIC,
788 from->getNick () + " " +
789 channel + " " + newTopic,
799 (newTopic), SCM_UNDEFINED));
803 if (c->lockedTopic && from->getNick () != cnx->bot->nickName)
804 cnx->queue->sendTopic (channel, c->channelTopic);
805 c->channelTopic = newTopic;
809 Parser::parseCTCP (ServerConnection * cnx,
810 Person * from, String to, String parameters)
812 StringTokenizer st (parameters);
813 String command = Utils::to_upper (st.next_token ());
814 String nick = from->getNick ();
816 if (st.more_tokens_p ())
821 cnx->bot->botInterp->RunHooks (Hook::CTCP,
822 nick + " " + to + " " +
823 command + " " + rest,
835 if (command == "PING")
837 Commands::CTCPReply (cnx->bot, nick, "PING", rest);
839 else if (command == "VERSION")
841 Commands::CTCPReply (cnx->bot, nick, "VERSION",
842 cnx->bot->versionString);
844 else if (command == "CLOCK")
846 time_t diff = time (NULL) - cnx->bot->startTime;
847 Commands::CTCPReply (cnx->bot, nick, "CLOCK",
848 String ("elapsed time: ") +
849 String ((long) (diff / 86400)) +
851 String ((long) (diff % 86400) /
853 String ((long) (diff % 3600) / 60) +
854 "m" + String ((long) (diff % 60)) + "s");
856 else if (command == "COMMAND")
858 Commands::CTCPReply (cnx->bot, nick,
859 "COMMAND", String (cnx->bot->commandChar));
861 else if (command == "LAG")
863 Commands::CTCPReply (cnx->bot, nick, "LAG",
864 String ((long) cnx->lag) + " second(s)");
866 else if (command == "DCC")
868 StringTokenizer st2 (rest);
869 command = Utils::to_upper (st2.next_token ());
870 if (command == "CHAT")
874 unsigned long address =
875 std::strtoul (st2.next_token ().c_str(), 0, 0);
876 int port = std::atoi (st2.next_token().c_str());
877 if (port >= 1024 && Utils::get_level (cnx->bot, from->getAddress ()))
878 cnx->bot->addDCC (from, address, port, Bot::CHAT);
880 cnx->bot->logLine ("DCC Chat Failed in Parser");
884 else if (command == "ACTION")
886 cnx->bot->botInterp->RunHooks (Hook::ACTION,
887 from->getNick () + " " + to +
903 Parser::parseMessage (ServerConnection * cnx,
904 Person * from, String to, String parameters)
907 if (Utils::channel_p (to))
908 cnx->bot->botInterp->RunHooks (Hook::PUBLIC,
909 from->getNick () + " " + to +
919 (parameters), SCM_UNDEFINED));
921 cnx->bot->botInterp->RunHooks (Hook::MESSAGE,
922 from->getNick () + " " +
930 (parameters), SCM_UNDEFINED));
932 if (parameters[0] != cnx->bot->commandChar)
935 StringTokenizer st (parameters);
936 String command = Utils::to_upper (st.next_token ().substr (1));
937 String rest = Utils::trim_str (st.rest ());
939 bool identified = false;
940 std::map<std::string, class userFunction*,
941 std::less<std::string> >::const_iterator uf_iter
942 = cnx->bot->userFunctions.find (command);
943 userFunction * f = 0;
945 if (uf_iter != cnx->bot->userFunctions.end ())
952 if (f->needsChannelName)
954 if (Utils::channel_p (rest))
956 StringTokenizer st2 (rest);
957 to = st.next_token ();
960 if (!Utils::channel_p (to))
962 from->sendNotice ("\002You need to supply a channel name"
963 " for this command\002");
966 if (!cnx->bot->channelList->getChannel (to))
968 from->sendNotice (String ("\002I am not on channel\002 ") +
972 level = Utils::get_level (cnx->bot, from->getAddress (), to);
974 if (Channel * c = cnx->bot->channelList->getChannel (to))
975 u = c->getUser (from->getNick ());
976 if (!u || !u->userListItem)
979 identified = u->userListItem->passwd == ""
980 || u->userListItem->identified > 0;
984 level = Utils::get_level (cnx->bot, from->getAddress ());
987 if (level >= f->minLevel)
989 cnx->bot->logLine (from->getAddress () + " did " + command +
992 if (f->argsCount != -1)
994 Parser::parseScriptFunction (cnx, to, f->needsChannelName,
995 f->scmFunc, f->argsCount,
1000 f->function (cnx, from, to, rest);
1003 f->function (cnx, from, to, rest);
1011 ("\002You are not identified on channel\002 ") +
1019 Parser::parseScriptFunction (ServerConnection * cnx,
1021 bool needsChannelName,
1022 SCM scmFunc, int argsCount, String parameters)
1025 SCM args_list = scm_listify (SCM_UNDEFINED);
1026 if (needsChannelName)
1028 args_list = gh_append2 (args_list,
1029 scm_listify (Utils::
1035 StringTokenizer st (parameters);
1036 for (int i = argsCount; i > 0; i--)
1041 param = st.next_token ();
1042 args_list = gh_append2 (args_list,
1043 scm_listify (Utils::str2scm (param),
1047 struct wrapper_data wd;
1049 wd.args = args_list;
1050 scm_internal_catch (SCM_BOOL_T,
1051 (scm_t_catch_body) Interp::LazyApplyWrapper,
1053 (scm_t_catch_handler) Interp::EmptyHandler, 0);