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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
23 #include <sys/types.h>
24 #include <netinet/in.h>
26 #include "StringTokenizer.H"
28 #include "UserCommands.H"
33 typedef void (*fptr) (ServerConnection *, Person *, String);
34 std::map < std::string, fptr, std::less < std::string > >Parser::functions;
40 Parser::functions["001"] = Parser::parse001; /* RPL_WELCOME */
41 Parser::functions["302"] = Parser::parse302; /* RPL_USERHOST */
42 Parser::functions["311"] = Parser::parse311; /* RPL_WHOISUSER */
43 Parser::functions["315"] = Parser::parse315; /* RPL_ENDOFWHO */
44 Parser::functions["324"] = Parser::parse324; /* RPL_CHANNELMODEIS */
45 Parser::functions["332"] = Parser::parse332; /* RPL_TOPIC */
46 Parser::functions["352"] = Parser::parse352; /* RPL_WHOREPLY */
47 Parser::functions["353"] = Parser::parse353; /* RPL_NAMESREPLY */
48 Parser::functions["366"] = Parser::parse366; /* RPL_ENDOFNAMES */
49 Parser::functions["367"] = Parser::parse367; /* RPL_BANLIST */
50 Parser::functions["401"] = Parser::parse401; /* ERR_NOSUCHNICK */
51 Parser::functions["433"] = Parser::parse433; /* ERR_NICKNAMEINUSE */
52 Parser::functions["437"] = Parser::parse433; /* ERR_UNAVAILRESOURCE */
53 Parser::functions["471"] = Parser::parse473; /* ERR_CHANNELISFULL */
54 Parser::functions["473"] = Parser::parse473; /* ERR_INVITEONLYCHAN */
55 Parser::functions["474"] = Parser::parse473; /* ERR_BANNEDFROMCHAN */
56 Parser::functions["475"] = Parser::parse473; /* ERR_BADCHANNELKEY */
57 Parser::functions["ERROR"] = Parser::parseError;
58 Parser::functions["INVITE"] = Parser::parseInvite;
59 Parser::functions["JOIN"] = Parser::parseJoin;
60 Parser::functions["KICK"] = Parser::parseKick;
61 Parser::functions["MODE"] = Parser::parseMode;
62 Parser::functions["NICK"] = Parser::parseNick;
63 Parser::functions["NOTICE"] = Parser::parseNotice;
64 Parser::functions["PART"] = Parser::parsePart;
65 Parser::functions["PING"] = Parser::parsePing;
66 Parser::functions["PONG"] = Parser::parsePong;
67 Parser::functions["PRIVMSG"] = Parser::parsePrivmsg;
68 Parser::functions["QUIT"] = Parser::parseQuit;
69 Parser::functions["TOPIC"] = Parser::parseTopic;
70 Parser::functions[""] = Parser::parseError;
75 Parser::parseLine (ServerConnection * cnx, String line)
77 StringTokenizer st (line);
80 cnx->bot->botInterp->RunHooks (Hook::RAW, line,
87 String fromMask = st.next_token ().substr (1);
88 if (fromMask.find ('!') != -1)
89 from = new Person (cnx->bot, fromMask);
92 String command = st.next_token ();
93 String rest = st.rest ();
95 if (fptr temp_func = functions[command])
96 temp_func (cnx, from, rest);
101 Parser::parse001 (ServerConnection * cnx, Person * from, String rest)
104 StringTokenizer st (rest);
105 String realNick = st.next_token ();
106 if ((cnx->bot->nickName).toLower () != realNick)
108 // Yes, this can happen, and it was a very subtle bug
109 cnx->bot->nickName = realNick;
110 cnx->bot->userList->removeFirst ();
111 cnx->bot->userList->addUserFirst (realNick + "!" +
112 cnx->bot->userHost, "*", 0,
114 cnx->bot->lastNickNameChange = time (0);
118 cnx->bot->connected = true;
119 cnx->queue->sendUserMode (cnx->bot->nickName, "+i");
120 cnx->queue->sendWhois (cnx->bot->nickName);
121 for (std::map < String, wantedChannel *,
122 std::less < String > >::iterator it =
123 cnx->bot->wantedChannels.begin ();
124 it != cnx->bot->wantedChannels.end (); ++it)
125 cnx->queue->sendJoin ((*it).first, (*it).second->key);
126 cnx->bot->logLine (String ("Connected to server ") +
127 cnx->bot->serverList->currentServer ()->
128 getHostName () + " (" +
129 String ((long) cnx->bot->serverList->
130 currentServer ()->getPort ()) + ").");
134 Parser::parse302 (ServerConnection * cnx, Person * from, String rest)
136 unsigned long num = cnx->bot->receivedUserhostID++;
137 StringTokenizer st (rest);
139 if (st.rest ().length ())
142 String parameters = st.rest ();
143 parameters = parameters.substr (1);
144 cnx->bot->userhostMap[num] = parameters;
147 cnx->bot->userhostMap[num] = "";
151 Parser::parse311 (ServerConnection * cnx, Person * from, String rest)
153 StringTokenizer st (rest);
155 String nuh = st.next_token () + "!";
156 String uh = st.next_token () + "@";
157 uh = uh + st.next_token ();
159 cnx->bot->userList->addUserFirst (nuh, "*", 0, 3, true, -1, "");
160 cnx->bot->userHost = uh;
164 Parser::parse315 (ServerConnection * cnx, Person * from, String rest)
166 StringTokenizer st (rest);
168 String channel = st.next_token ();
169 Channel *c = cnx->bot->channelList->getChannel (channel);
176 Parser::parse324 (ServerConnection * cnx, Person * from, String rest)
178 StringTokenizer st (rest);
180 String channel = st.next_token ();
181 if (Channel * c = cnx->bot->channelList->getChannel (channel))
183 c->parseMode (from, st.rest ());
187 Parser::parse332 (ServerConnection * cnx, Person * from, String rest)
189 StringTokenizer st (rest);
191 String channel = st.next_token ();
192 if (Channel * c = cnx->bot->channelList->getChannel (channel))
194 c->channelTopic = st.rest ().substr (1);
198 Parser::parse352 (ServerConnection * cnx, Person * from, String rest)
200 StringTokenizer st (rest);
202 String ch = st.next_token ();
203 String uh = st.next_token () + "@";
204 uh = uh + st.next_token ();
206 String n = st.next_token ();
207 String m = st.next_token ();
209 for (int i = 0; i < m.length (); i++)
215 mode |= User::AWAY_MODE;
218 mode |= User::IRCOP_MODE;
221 mode |= User::OP_MODE;
224 mode |= User::VOICE_MODE;
227 if (Channel * c = cnx->bot->channelList->getChannel (ch))
229 c->addNick (n, uh, mode, cnx->bot->userList);
233 Parser::parse353 (ServerConnection * cnx, Person * from, String rest)
237 StringTokenizer st (rest);
240 Channel *c = cnx->bot->channelList->getChannel (st.next_token ());
243 StringTokenizer st2 (st.next_token (':'));
244 while (st2.more_tokens_p ())
246 nick = st2.next_token ();
249 mode = User::OP_MODE;
250 nick = nick.substr (1);
252 else if (nick[0] == '+')
254 mode = User::VOICE_MODE;
255 nick = nick.substr (1);
257 c->addNick (nick, "", mode, 0, true);
262 Parser::parse366 (ServerConnection * cnx, Person * from, String rest)
264 StringTokenizer st (rest);
266 String ch = st.next_token ();
267 if (Channel * c = cnx->bot->channelList->getChannel (ch))
272 Parser::parse367 (ServerConnection * cnx, Person * from, String rest)
274 StringTokenizer st (rest);
276 String ch = st.next_token ();
277 if (Channel * c = cnx->bot->channelList->getChannel (ch))
278 c->addBan (st.next_token (), -1);
282 Parser::parse401 (ServerConnection * cnx, Person * from, String rest)
284 StringTokenizer st (rest);
286 String nick = st.next_token ();
287 if (cnx->bot->spyList.find (nick) != cnx->bot->spyList.end ())
289 delete cnx->bot->spyList[nick];
290 cnx->bot->spyList.erase (nick);
295 Parser::parse433 (ServerConnection * cnx, Person * from, String rest)
297 if (cnx->bot->connected)
299 if (cnx->bot->nickName.length () == 9)
303 i < cnx->bot->nickName.length ()
304 && cnx->bot->nickName[i] == '_'; i++);
305 if (i < cnx->bot->nickName.length ())
307 cnx->bot->nickName.substr (0,
309 cnx->bot->nickName.substr (i + 1);
311 cnx->bot->nickName = cnx->bot->nickName.substr (0, 4) +
312 String ((long) (rand () % 10000));
315 cnx->bot->nickName = cnx->bot->nickName + "_";
316 cnx->queue->sendNick (cnx->bot->nickName);
320 Parser::parse473 (ServerConnection * cnx, Person * from, String rest)
322 StringTokenizer st (rest);
324 cnx->bot->logLine (String ("Unable to join channel ") +
325 st.next_token () + ".");
329 Parser::parseError (ServerConnection * cnx, Person * from, String rest)
331 cnx->bot->logLine (String ("Error from server ") +
332 cnx->bot->serverList->currentServer ()->
333 getHostName () + " (" +
334 String ((long) cnx->bot->serverList->
335 currentServer ()->getPort ()) + ").");
336 cnx->bot->nextServer ();
340 Parser::parseInvite (ServerConnection * cnx, Person * from, String rest)
342 String nick = from->getNick ();
343 StringTokenizer st (rest);
345 String channel = st.rest ();
347 cnx->bot->botInterp->RunHooks (Hook::INVITE,
348 nick + " " + channel,
353 (channel), SCM_UNDEFINED));
355 if (cnx->bot->wantedChannels.find (channel) !=
356 cnx->bot->wantedChannels.end ())
357 cnx->queue->sendJoin (channel, cnx->bot->wantedChannels[channel]->key);
361 Parser::parseJoin (ServerConnection * cnx, Person * from, String rest)
363 StringTokenizer st (from->getAddress ());
364 String n = st.next_token ('!');
365 String uh = st.next_token ();
366 StringTokenizer st2 (rest);
367 String c = st2.next_token (':');
369 bool joinAndMode = false;
371 cnx->bot->botInterp->RunHooks (Hook::JOIN, n + " " + c,
375 str2scm (c), SCM_UNDEFINED));
377 // This part of code is for the combined JOIN & MODE of ircd 2.9
378 if (c.find ('\007') >= 0)
381 StringTokenizer st3 (c);
382 c = st3.next_token ('\007');
383 String m = st3.rest ();
385 for (int i = 0; i < m.length (); i++)
386 mode = mode + " " + n;
389 if (n == cnx->bot->nickName)
391 cnx->bot->logLine (String ("Joined channel ") + c + ".");
392 if (cnx->bot->wantedChannels.find (c) !=
393 cnx->bot->wantedChannels.end ())
394 cnx->bot->channelList->
395 addChannel (cnx, c, cnx->bot->wantedChannels[c]->keep);
397 cnx->bot->channelList->addChannel (cnx, c);
398 cnx->queue->sendWho (c);
399 cnx->queue->sendChannelMode (String ("MODE ") + c + " b");
400 cnx->queue->sendChannelMode (String ("MODE ") + c);
404 Channel *ch = cnx->bot->channelList->getChannel (c);
407 ShitEntry *se = cnx->bot->shitList->getShit (n + "!" + uh, c);
408 if (se && se->isStillValid () &&
409 se->getShitLevel () >= ShitEntry::SHIT_NOJOIN)
411 cnx->queue->sendChannelMode (c, "+b", se->getMask ());
412 cnx->queue->sendKick (c, n, se->getShitReason ());
415 ch->addNick (n, uh, 0, cnx->bot->userList);
416 if (ch->getUser (n)->getAop ()
417 && !(ch->getUser (n)->mode & User::OP_MODE) && cnx->bot->iAmOp (c))
419 // This is a part of the antispoof code
420 ch->getUser (n)->userkey = Utils::get_key ();
421 cnx->queue->sendCTCP (n, "PING",
422 ch->getUser (n)->userkey + " " + c);
427 parseMode (cnx, 0, mode);
431 Parser::parseKick (ServerConnection * cnx, Person * from, String rest)
433 StringTokenizer st (rest);
434 String channel = st.next_token ();
435 String target = st.next_token ();
436 String reason = st.rest ().substr (1);
438 cnx->bot->botInterp->RunHooks (Hook::KICK,
440 from->getNick () + " " +
441 channel + " " + reason,
454 (reason), SCM_UNDEFINED));
456 if (target == cnx->bot->nickName)
458 cnx->bot->logLine (from->getAddress () +
459 " kicked me out of channel " + channel +
460 " (" + reason + ").");
461 cnx->queue->sendJoin (channel,
462 cnx->bot->channelList->
463 getChannel (channel)->channelKey);
464 cnx->bot->channelList->delChannel (channel);
468 if (!cnx->bot->channelList->getChannel (channel))
470 User *u = cnx->bot->channelList->getChannel (channel)->getUser (target);
471 if (u && u->getProt () >= User::NO_KICK)
473 String fromNick = from->getNick ();
475 cnx->bot->channelList->getChannel (channel)->getUser (fromNick);
476 if (v->getProt () < User::NO_KICK)
478 cnx->bot->logLine (from->getAddress () + " kicked " + target +
479 " (protected) out of channel " + channel +
480 " (" + reason + ").");
481 cnx->queue->sendKick (channel, fromNick,
482 target + " \002is protected !\002");
485 cnx->bot->channelList->getChannel (channel)->delNick (target);
490 Parser::parseMode (ServerConnection * cnx, Person * from, String rest)
492 StringTokenizer st (rest);
493 String ch = st.next_token ();
494 String modes = st.rest ();
497 cnx->bot->botInterp->RunHooks (Hook::MODE,
498 from->getNick () + " " + ch +
510 if (Utils::channel_p (ch))
512 Channel *c = cnx->bot->channelList->getChannel (ch);
516 c->parseMode (from, modes);
518 c->parseMode (0, modes);
523 Parser::parseNick (ServerConnection * cnx, Person * from, String rest)
525 String on_orig = from->getNick ();
526 String on = on_orig.toLower ();
527 String nn = rest.substr (1);
528 String nn_lower = nn.toLower ();
530 cnx->bot->botInterp->RunHooks (Hook::NICKNAME,
539 if ((cnx->bot->nickName).toLower () == on)
541 cnx->bot->userList->removeFirst ();
542 cnx->bot->userList->addUserFirst (nn + "!" +
543 cnx->bot->userHost, "*", 0,
545 cnx->bot->lastNickNameChange = time (0);
546 cnx->bot->nickName = nn;
550 if (cnx->bot->spyList.find (on) != cnx->bot->spyList.end ())
552 cnx->bot->spyList[nn_lower] = cnx->bot->spyList[on];
553 cnx->bot->spyList.erase (on);
556 for (std::map < String, Channel *,
557 std::less < String > >::iterator it =
558 cnx->bot->channelList->begin ();
559 it != cnx->bot->channelList->end (); ++it)
560 if ((*it).second->hasNick (on))
561 (*it).second->changeNick (on, nn_lower);
565 Parser::parseNotice (ServerConnection * cnx, Person * from, String rest)
569 nick = from->getNick ();
570 StringTokenizer st (rest);
571 String to = st.next_token ();
572 rest = st.rest ().substr (1);
573 if (rest[0] != '\001')
576 if (Utils::channel_p (to))
577 cnx->bot->botInterp->RunHooks (Hook::PUBLIC_NOTICE,
578 nick + " " + to + " " + rest,
587 cnx->bot->botInterp->RunHooks (Hook::NOTICE, nick + " " + rest,
597 rest = rest.substr (1, rest.length () - 2);
598 StringTokenizer st2 (rest);
599 String command = st2.next_token ();
602 cnx->bot->botInterp->RunHooks (Hook::CTCP_REPLY,
603 nick + " " + command + " " +
614 if (command == "PING")
616 StringTokenizer st3 (rest);
617 rest = st3.next_token ();
618 String c = st3.rest ();
619 if (cnx->bot->channelList->getChannel (c) &&
620 cnx->bot->channelList->getChannel (c)->getUser (nick) &&
621 cnx->bot->channelList->getChannel (c)->getUser (nick)->
623 && !(cnx->bot->channelList->getChannel (c)->
624 getUser (nick)->mode & User::OP_MODE)
625 && cnx->bot->channelList->getChannel (c)->getUser (nick)->
627 cnx->queue->sendChannelMode (c, "+o", nick);
632 Parser::parsePrivmsg (ServerConnection * cnx, Person * from, String rest)
634 String nick = from->getNick ();
635 StringTokenizer st (rest);
636 String to = st.next_token ();
637 String fromUserhost = Utils::get_userhost (from->getAddress ());
638 rest = st.rest ().substr (1);
639 if (++(cnx->bot->ignoredUserhosts[fromUserhost]) > Bot::MAX_MESSAGES)
641 if (cnx->bot->ignoredUserhosts[fromUserhost] == Bot::MAX_MESSAGES + 1)
644 cnx->bot->botInterp->RunHooks (Hook::FLOOD, nick,
649 cnx->bot->ignoredUserhosts[fromUserhost] += Bot::IGNORE_DELAY;
650 cnx->bot->logLine (from->getAddress () +
651 " is flooding me. We will ignore him/her/it.");
652 if (!Utils::channel_p (to))
654 sendNotice (String ("\002You are now being ignored for ") +
655 String ((long) Bot::IGNORE_DELAY) +
658 // The following lines reset the counter if you use the
659 // command "!sorry" (if '!' is your command char).
660 // This is not documented, I know. But one probably does
661 // not want that every users can bypass the flood control
662 // Of course, if you want this feature to remain 'secret',
663 // do not use it in public.
664 if (rest.toUpper () == String (cnx->bot->commandChar) + "SORRY")
666 cnx->bot->ignoredUserhosts[fromUserhost] = 0;
667 from->sendNotice ("\002Don't do it again!\002");
672 if (rest[0] == '\001')
674 rest = rest.substr (1, rest.length () - 2);
675 if (!Utils::channel_p (to))
676 for (std::map < String, Person *,
677 std::less < String > >::iterator it =
678 cnx->bot->spyList.begin (); it != cnx->bot->spyList.end (); ++it)
679 (*it).second->sendNotice (String ("CTCP From ") +
681 Parser::parseCTCP (cnx, from, to, rest);
685 if ((rest.length () < 5 ||
686 rest.substr (1, 5).toUpper () != "IDENT") &&
687 (rest.length () < 8 ||
688 rest.substr (1, 8).toUpper () != "PASSWORD") &&
689 !Utils::channel_p (to))
690 for (std::map < String, Person *,
691 std::less < String > >::iterator it =
692 cnx->bot->spyList.begin (); it != cnx->bot->spyList.end (); ++it)
693 (*it).second->sendNotice (String ("*") + nick + "* " + rest);
694 Parser::parseMessage (cnx, from, to, rest);
699 Parser::parsePart (ServerConnection * cnx, Person * from, String rest)
701 String n = from->getNick ();
702 StringTokenizer st (rest);
703 String channel = st.next_token ();
705 cnx->bot->botInterp->RunHooks (Hook::LEAVE, n + " " + channel,
710 (channel), SCM_UNDEFINED));
712 if (n.toLower () == cnx->bot->nickName.toLower ())
714 cnx->bot->logLine (String ("Leaved channel ") + channel + ".");
715 cnx->bot->channelList->delChannel (channel);
719 Channel *c = cnx->bot->channelList->getChannel (channel);
723 if (c->countOp == 0 && c->count == 1)
725 cnx->queue->sendPart (channel);
726 cnx->queue->sendJoin (channel,
727 cnx->bot->wantedChannels[channel]->key);
733 Parser::parsePing (ServerConnection * cnx, Person * from, String rest)
735 cnx->queue->sendPong (rest);
739 Parser::parsePong (ServerConnection * cnx, Person * from, String rest)
741 cnx->lag = (cnx->lag + 2 * (time (NULL) - cnx->pingTime)) / 3;
742 cnx->bot->sentPing = false;
746 Parser::parseQuit (ServerConnection * cnx, Person * from, String rest)
748 String n = from->getNick ();
750 cnx->bot->botInterp->RunHooks (Hook::SIGNOFF, n + " " + rest,
757 if (n == cnx->bot->nickName)
758 cnx->bot->stop = true;
759 for (std::map < String, Channel *,
760 std::less < String > >::iterator it =
761 cnx->bot->channelList->begin ();
762 it != cnx->bot->channelList->end (); ++it)
763 (*it).second->delNick (n);
767 Parser::parseTopic (ServerConnection * cnx, Person * from, String rest)
769 StringTokenizer st (rest);
770 String channel = st.next_token ();
771 String newTopic = st.rest ().substr (1);
772 Channel *c = cnx->bot->channelList->getChannel (channel);
774 cnx->bot->botInterp->RunHooks (Hook::TOPIC,
775 from->getNick () + " " +
776 channel + " " + newTopic,
786 (newTopic), SCM_UNDEFINED));
790 if (c->lockedTopic && from->getNick () != cnx->bot->nickName)
791 cnx->queue->sendTopic (channel, c->channelTopic);
792 c->channelTopic = newTopic;
796 Parser::parseCTCP (ServerConnection * cnx,
797 Person * from, String to, String parameters)
799 StringTokenizer st (parameters);
800 String command = Utils::to_upper (st.next_token ());
801 String nick = from->getNick ();
803 if (st.more_tokens_p ())
808 cnx->bot->botInterp->RunHooks (Hook::CTCP,
809 nick + " " + to + " " +
810 command + " " + rest,
822 if (command == "PING")
823 cnx->queue->sendCTCPReply (nick, "PING", rest);
824 else if (command == "VERSION")
825 cnx->queue->sendCTCPReply (nick, "VERSION", cnx->bot->versionString);
826 else if (command == "CLOCK")
828 time_t diff = time (NULL) - cnx->bot->startTime;
829 cnx->queue->sendCTCPReply (nick, "CLOCK",
830 String ("elapsed time: ") +
831 String ((long) (diff / 86400)) +
833 String ((long) (diff % 86400) /
835 String ((long) (diff % 3600) / 60) +
836 "m" + String ((long) (diff % 60)) + "s");
838 else if (command == "COMMAND")
839 cnx->queue->sendCTCPReply (nick,
840 "COMMAND", String (cnx->bot->commandChar));
841 else if (command == "LAG")
842 cnx->queue->sendCTCPReply (nick, "LAG",
843 String ((long) cnx->lag) + " second(s)");
844 else if (command == "DCC")
846 StringTokenizer st2 (rest);
847 command = Utils::to_upper (st2.next_token ());
848 if (command == "CHAT")
852 unsigned long address =
853 std::strtoul (st2.next_token ().c_str(), 0, 0);
854 int port = std::atoi (st2.next_token().c_str());
855 if (port >= 1024 && Utils::get_level (cnx->bot, from->getAddress ()))
856 cnx->bot->addDCC (from, address, port, Bot::CHAT);
858 cnx->bot->logLine ("DCC Chat Failed in Parser");
862 else if (command == "ACTION")
864 cnx->bot->botInterp->RunHooks (Hook::ACTION,
865 from->getAddress () + " " + to +
881 Parser::parseMessage (ServerConnection * cnx,
882 Person * from, String to, String parameters)
885 if (Utils::channel_p (to))
886 cnx->bot->botInterp->RunHooks (Hook::PUBLIC,
887 from->getNick () + " " + to +
897 (parameters), SCM_UNDEFINED));
899 cnx->bot->botInterp->RunHooks (Hook::MESSAGE,
900 from->getNick () + " " +
908 (parameters), SCM_UNDEFINED));
910 if (parameters[0] != cnx->bot->commandChar)
913 StringTokenizer st (parameters);
914 String command = Utils::to_upper (st.next_token ().substr (1));
915 String rest = Utils::trim_str (st.rest ());
917 bool identified = false;
918 std::map<std::string, class userFunction*,
919 std::less<std::string> >::const_iterator uf_iter
920 = cnx->bot->userFunctions.find (command);
921 userFunction * f = 0;
923 if (uf_iter != cnx->bot->userFunctions.end ())
930 if (f->needsChannelName)
932 if (Utils::channel_p (rest))
934 StringTokenizer st2 (rest);
935 to = st.next_token ();
938 if (!Utils::channel_p (to))
940 from->sendNotice ("\002You need to supply a channel name"
941 " for this command\002");
944 if (!cnx->bot->channelList->getChannel (to))
946 from->sendNotice (String ("\002I am not on channel\002 ") +
950 level = Utils::get_level (cnx->bot, from->getAddress (), to);
952 if (Channel * c = cnx->bot->channelList->getChannel (to))
953 u = c->getUser (from->getNick ());
954 if (!u || !u->userListItem)
957 identified = u->userListItem->passwd == ""
958 || u->userListItem->identified > 0;
962 level = Utils::get_level (cnx->bot, from->getAddress ());
965 if (level >= f->minLevel)
967 cnx->bot->logLine (from->getAddress () + " did " + command +
970 if (f->argsCount != -1)
972 Parser::parseScriptFunction (cnx, to, f->needsChannelName,
973 f->scmFunc, f->argsCount,
978 f->function (cnx, from, to, rest);
981 f->function (cnx, from, to, rest);
989 ("\002You are not identified on channel\002 ") +
997 Parser::parseScriptFunction (ServerConnection * cnx,
999 bool needsChannelName,
1000 SCM scmFunc, int argsCount, String parameters)
1003 SCM args_list = scm_listify (SCM_UNDEFINED);
1004 if (needsChannelName)
1006 args_list = gh_append2 (args_list,
1007 scm_listify (Utils::
1013 StringTokenizer st (parameters);
1014 for (int i = argsCount; i > 0; i--)
1019 param = st.next_token ();
1020 args_list = gh_append2 (args_list,
1021 scm_listify (Utils::str2scm (param),
1025 struct wrapper_data wd;
1027 wd.args = args_list;
1028 gh_catch (SCM_BOOL_T, (scm_t_catch_body) scm_apply_wrapper,
1029 (void *) &wd, (scm_t_catch_handler) Interp::ErrorHandler, 0);