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 String parameters = st.rest ();
176 parameters = parameters.substr (1);
177 cnx->bot->userhostMap[num] = parameters;
180 cnx->bot->userhostMap[num] = "";
184 Parser::parse311 (ServerConnection * cnx, Person * from, String rest)
186 StringTokenizer st (rest);
188 String nuh = st.next_token () + "!";
189 String uh = st.next_token () + "@";
190 uh = uh + st.next_token ();
192 cnx->bot->userList->addUserFirst (nuh, "*", 0, 3, true, -1, "");
193 cnx->bot->userHost = uh;
197 Parser::parse315 (ServerConnection * cnx, Person * from, String rest)
199 StringTokenizer st (rest);
201 String channel = st.next_token ();
202 Channel *c = cnx->bot->channelList->getChannel (channel);
209 Parser::parse324 (ServerConnection * cnx, Person * from, String rest)
211 StringTokenizer st (rest);
213 String channel = st.next_token ();
214 if (Channel * c = cnx->bot->channelList->getChannel (channel))
216 c->parseMode (from, st.rest ());
220 Parser::parse332 (ServerConnection * cnx, Person * from, String rest)
222 StringTokenizer st (rest);
224 String channel = st.next_token ();
225 if (Channel * c = cnx->bot->channelList->getChannel (channel))
227 c->channelTopic = st.rest ().substr (1);
231 Parser::parse352 (ServerConnection * cnx, Person * from, String rest)
233 StringTokenizer st (rest);
235 String ch = st.next_token ();
236 String uh = st.next_token () + "@";
237 uh = uh + st.next_token ();
239 String n = st.next_token ();
240 String m = st.next_token ();
242 for (int i = 0; i < m.length (); i++)
248 mode |= User::AWAY_MODE;
251 mode |= User::IRCOP_MODE;
254 mode |= User::OP_MODE;
257 mode |= User::VOICE_MODE;
260 if (Channel * c = cnx->bot->channelList->getChannel (ch))
262 c->addNick (n, uh, mode, cnx->bot->userList);
266 Parser::parse353 (ServerConnection * cnx, Person * from, String rest)
270 StringTokenizer st (rest);
273 Channel *c = cnx->bot->channelList->getChannel (st.next_token ());
276 StringTokenizer st2 (st.next_token (':'));
277 while (st2.more_tokens_p ())
279 nick = st2.next_token ();
282 mode = User::OP_MODE;
283 nick = nick.substr (1);
285 else if (nick[0] == '+')
287 mode = User::VOICE_MODE;
288 nick = nick.substr (1);
290 c->addNick (nick, "", mode, 0, true);
295 Parser::parse366 (ServerConnection * cnx, Person * from, String rest)
297 StringTokenizer st (rest);
299 String ch = st.next_token ();
300 if (Channel * c = cnx->bot->channelList->getChannel (ch))
305 Parser::parse367 (ServerConnection * cnx, Person * from, String rest)
307 StringTokenizer st (rest);
309 String ch = st.next_token ();
310 if (Channel * c = cnx->bot->channelList->getChannel (ch))
311 c->addBan (st.next_token (), -1);
315 Parser::parse401 (ServerConnection * cnx, Person * from, String rest)
317 StringTokenizer st (rest);
319 String nick = st.next_token ();
320 if (cnx->bot->spyList.find (nick) != cnx->bot->spyList.end ())
322 delete cnx->bot->spyList[nick];
323 cnx->bot->spyList.erase (nick);
328 Parser::parse433 (ServerConnection * cnx, Person * from, String rest)
330 if (cnx->bot->connected)
332 if (cnx->bot->nickName.length () == 9)
336 i < cnx->bot->nickName.length ()
337 && cnx->bot->nickName[i] == '_'; i++);
338 if (i < cnx->bot->nickName.length ())
340 cnx->bot->nickName.substr (0,
342 cnx->bot->nickName.substr (i + 1);
344 cnx->bot->nickName = cnx->bot->nickName.substr (0, 4) +
345 String ((long) (rand () % 10000));
348 cnx->bot->nickName = cnx->bot->nickName + "_";
349 cnx->queue->sendNick (cnx->bot->nickName);
353 Parser::parse473 (ServerConnection * cnx, Person * from, String rest)
355 StringTokenizer st (rest);
357 cnx->bot->logLine (String ("Unable to join channel ") +
358 st.next_token () + ".");
362 Parser::parseError (ServerConnection * cnx, Person * from, String rest)
364 cnx->bot->logLine (String ("Error from server ") +
365 cnx->bot->serverList->currentServer ()->
366 getHostName () + " (" +
367 String ((long) cnx->bot->serverList->
368 currentServer ()->getPort ()) + ").");
369 cnx->bot->nextServer ();
373 Parser::parseInvite (ServerConnection * cnx, Person * from, String rest)
375 String nick = from->getNick ();
376 StringTokenizer st (rest);
378 String channel = st.rest ();
380 cnx->bot->botInterp->RunHooks (Hook::INVITE,
381 nick + " " + channel,
386 (channel), SCM_UNDEFINED));
388 if (cnx->bot->wantedChannels.find (channel) !=
389 cnx->bot->wantedChannels.end ())
390 cnx->queue->sendJoin (channel, cnx->bot->wantedChannels[channel]->key);
394 Parser::parseJoin (ServerConnection * cnx, Person * from, String rest)
396 StringTokenizer st (from->getAddress ());
397 String n = st.next_token ('!');
398 String uh = st.next_token ();
399 StringTokenizer st2 (rest);
400 String c = st2.next_token (':');
402 bool joinAndMode = false;
404 cnx->bot->botInterp->RunHooks (Hook::JOIN, n + " " + c,
408 str2scm (c), SCM_UNDEFINED));
410 // This part of code is for the combined JOIN & MODE of ircd 2.9
411 if (c.find ('\007') >= 0)
414 StringTokenizer st3 (c);
415 c = st3.next_token ('\007');
416 String m = st3.rest ();
418 for (int i = 0; i < m.length (); i++)
419 mode = mode + " " + n;
422 if (n == cnx->bot->nickName)
424 cnx->bot->logLine (String ("Joined channel ") + c + ".");
425 if (cnx->bot->wantedChannels.find (c) !=
426 cnx->bot->wantedChannels.end ())
427 cnx->bot->channelList->
428 addChannel (cnx, c, cnx->bot->wantedChannels[c]->keep);
430 cnx->bot->channelList->addChannel (cnx, c);
431 cnx->queue->sendWho (c);
432 cnx->queue->sendChannelMode (String ("MODE ") + c + " b");
433 cnx->queue->sendChannelMode (String ("MODE ") + c);
437 Channel *ch = cnx->bot->channelList->getChannel (c);
440 ShitEntry *se = cnx->bot->shitList->getShit (n + "!" + uh, c);
441 if (se && se->isStillValid () &&
442 se->getShitLevel () >= ShitEntry::SHIT_NOJOIN)
444 cnx->queue->sendChannelMode (c, "+b", se->getMask ());
445 cnx->queue->sendKick (c, n, se->getShitReason ());
448 ch->addNick (n, uh, 0, cnx->bot->userList);
449 if (ch->getUser (n)->getAop ()
450 && !(ch->getUser (n)->mode & User::OP_MODE) && cnx->bot->iAmOp (c))
452 // This is a part of the antispoof code
453 ch->getUser(n)->userkey = Utils::get_key ();
454 Commands::CTCP (cnx->bot, n, "PING",
455 ch->getUser(n)->userkey + " " + c);
460 parseMode (cnx, 0, mode);
464 Parser::parseKick (ServerConnection * cnx, Person * from, String rest)
466 StringTokenizer st (rest);
467 String channel = st.next_token ();
468 String target = st.next_token ();
469 String reason = st.rest ().substr (1);
471 cnx->bot->botInterp->RunHooks (Hook::KICK,
473 from->getNick () + " " +
474 channel + " " + reason,
487 (reason), SCM_UNDEFINED));
489 if (target == cnx->bot->nickName)
491 cnx->bot->logLine (from->getAddress () +
492 " kicked me out of channel " + channel +
493 " (" + reason + ").");
494 cnx->queue->sendJoin (channel,
495 cnx->bot->channelList->
496 getChannel (channel)->channelKey);
497 cnx->bot->channelList->delChannel (channel);
501 if (!cnx->bot->channelList->getChannel (channel))
503 User *u = cnx->bot->channelList->getChannel (channel)->getUser (target);
504 if (u && 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");
518 cnx->bot->channelList->getChannel (channel)->delNick (target);
523 Parser::parseMode (ServerConnection * cnx, Person * from, String rest)
525 StringTokenizer st (rest);
526 String ch = st.next_token ();
527 String modes = st.rest ();
530 cnx->bot->botInterp->RunHooks (Hook::MODE,
531 from->getNick () + " " + ch +
543 if (Utils::channel_p (ch))
545 Channel *c = cnx->bot->channelList->getChannel (ch);
549 c->parseMode (from, modes);
551 c->parseMode (0, modes);
556 Parser::parseNick (ServerConnection * cnx, Person * from, String rest)
558 String on_orig = from->getNick ();
559 String on = on_orig.toLower ();
560 String nn = rest.substr (1);
561 String nn_lower = nn.toLower ();
563 cnx->bot->botInterp->RunHooks (Hook::NICKNAME,
572 if ((cnx->bot->nickName).toLower () == on)
574 cnx->bot->userList->removeFirst ();
575 cnx->bot->userList->addUserFirst (nn + "!" +
576 cnx->bot->userHost, "*", 0,
578 cnx->bot->lastNickNameChange = time (0);
579 cnx->bot->nickName = nn;
583 if (cnx->bot->spyList.find (on) != cnx->bot->spyList.end ())
585 cnx->bot->spyList[nn_lower] = cnx->bot->spyList[on];
586 cnx->bot->spyList.erase (on);
589 for (std::map < String, Channel *,
590 std::less < String > >::iterator it =
591 cnx->bot->channelList->begin ();
592 it != cnx->bot->channelList->end (); ++it)
593 if ((*it).second->hasNick (on))
594 (*it).second->changeNick (on, nn_lower);
598 Parser::parseNotice (ServerConnection * cnx, Person * from, String rest)
602 nick = from->getNick ();
603 StringTokenizer st (rest);
604 String to = st.next_token ();
605 rest = st.rest ().substr (1);
606 if (rest[0] != '\001')
609 if (Utils::channel_p (to))
610 cnx->bot->botInterp->RunHooks (Hook::PUBLIC_NOTICE,
611 nick + " " + to + " " + rest,
620 cnx->bot->botInterp->RunHooks (Hook::NOTICE, nick + " " + rest,
630 rest = rest.substr (1, rest.length () - 2);
631 StringTokenizer st2 (rest);
632 String command = st2.next_token ();
635 cnx->bot->botInterp->RunHooks (Hook::CTCP_REPLY,
636 nick + " " + command + " " +
647 if (command == "PING")
649 StringTokenizer st3 (rest);
650 rest = st3.next_token ();
651 String c = st3.rest ();
652 if (cnx->bot->channelList->getChannel (c) &&
653 cnx->bot->channelList->getChannel (c)->getUser (nick) &&
654 cnx->bot->channelList->getChannel (c)->getUser (nick)->
656 && !(cnx->bot->channelList->getChannel (c)->
657 getUser (nick)->mode & User::OP_MODE)
658 && cnx->bot->channelList->getChannel (c)->getUser (nick)->
660 cnx->queue->sendChannelMode (c, "+o", nick);
665 Parser::parsePrivmsg (ServerConnection * cnx, Person * from, String rest)
667 String nick = from->getNick ();
668 StringTokenizer st (rest);
669 String to = st.next_token ();
670 String fromUserhost = Utils::get_userhost (from->getAddress ());
671 rest = st.rest ().substr (1);
672 if (++(cnx->bot->ignoredUserhosts[fromUserhost]) > Bot::MAX_MESSAGES)
674 if (cnx->bot->ignoredUserhosts[fromUserhost] == Bot::MAX_MESSAGES + 1)
677 cnx->bot->botInterp->RunHooks (Hook::FLOOD, nick,
682 cnx->bot->ignoredUserhosts[fromUserhost] += Bot::IGNORE_DELAY;
683 cnx->bot->logLine (from->getAddress () +
684 " is flooding me. We will ignore him/her/it.");
685 if (!Utils::channel_p (to))
687 sendNotice (String ("\002You are now being ignored for ") +
688 String ((long) Bot::IGNORE_DELAY) +
691 // The following lines reset the counter if you use the
692 // command "!sorry" (if '!' is your command char).
693 // This is not documented, I know. But one probably does
694 // not want that every users can bypass the flood control
695 // Of course, if you want this feature to remain 'secret',
696 // do not use it in public.
697 if (rest.toUpper () == String (cnx->bot->commandChar) + "SORRY")
699 cnx->bot->ignoredUserhosts[fromUserhost] = 0;
700 from->sendNotice ("\002Don't do it again!\002");
705 if (rest[0] == '\001')
707 rest = rest.substr (1, rest.length () - 2);
708 if (!Utils::channel_p (to))
709 for (std::map < String, Person *,
710 std::less < String > >::iterator it =
711 cnx->bot->spyList.begin (); it != cnx->bot->spyList.end (); ++it)
712 (*it).second->sendNotice (String ("CTCP From ") +
714 Parser::parseCTCP (cnx, from, to, rest);
718 if ((rest.length () < 5 ||
719 rest.substr (1, 5).toUpper () != "IDENT") &&
720 (rest.length () < 8 ||
721 rest.substr (1, 8).toUpper () != "PASSWORD") &&
722 !Utils::channel_p (to))
723 for (std::map < String, Person *,
724 std::less < String > >::iterator it =
725 cnx->bot->spyList.begin (); it != cnx->bot->spyList.end (); ++it)
726 (*it).second->sendNotice (String ("*") + nick + "* " + rest);
727 Parser::parseMessage (cnx, from, to, rest);
732 Parser::parsePart (ServerConnection * cnx, Person * from, String rest)
734 String n = from->getNick ();
735 StringTokenizer st (rest);
736 String channel = st.next_token ();
738 cnx->bot->botInterp->RunHooks (Hook::PART, n + " " + channel,
743 (channel), SCM_UNDEFINED));
745 if (n.toLower () == cnx->bot->nickName.toLower ())
747 cnx->bot->logLine (String ("Left channel ") + channel + ".");
748 cnx->bot->channelList->delChannel (channel);
752 Channel *c = cnx->bot->channelList->getChannel (channel);
756 if (c->countOp == 0 && c->count == 1)
758 cnx->queue->sendPart (channel);
759 cnx->queue->sendJoin (channel,
760 cnx->bot->wantedChannels[channel]->key);
766 Parser::parsePing (ServerConnection * cnx, Person * from, String rest)
768 cnx->queue->sendPong (rest);
772 Parser::parsePong (ServerConnection * cnx, Person * from, String rest)
774 cnx->lag = (cnx->lag + 2 * (time (NULL) - cnx->pingTime)) / 3;
775 cnx->bot->sentPing = false;
779 Parser::parseQuit (ServerConnection * cnx, Person * from, String rest)
781 String n = from->getNick ();
783 cnx->bot->botInterp->RunHooks (Hook::SIGNOFF, n + " " + rest,
790 if (n == cnx->bot->nickName)
791 cnx->bot->stop = true;
792 for (std::map < String, Channel *,
793 std::less < String > >::iterator it =
794 cnx->bot->channelList->begin ();
795 it != cnx->bot->channelList->end (); ++it)
796 (*it).second->delNick (n);
800 Parser::parseTopic (ServerConnection * cnx, Person * from, String rest)
802 StringTokenizer st (rest);
803 String channel = st.next_token ();
804 String newTopic = st.rest ().substr (1);
805 Channel *c = cnx->bot->channelList->getChannel (channel);
807 cnx->bot->botInterp->RunHooks (Hook::TOPIC,
808 from->getNick () + " " +
809 channel + " " + newTopic,
819 (newTopic), SCM_UNDEFINED));
823 if (c->lockedTopic && from->getNick () != cnx->bot->nickName)
824 cnx->queue->sendTopic (channel, c->channelTopic);
825 c->channelTopic = newTopic;
829 Parser::parseCTCP (ServerConnection * cnx,
830 Person * from, String to, String parameters)
832 StringTokenizer st (parameters);
833 String command = Utils::to_upper (st.next_token ());
834 String nick = from->getNick ();
836 if (st.more_tokens_p ())
841 cnx->bot->botInterp->RunHooks (Hook::CTCP,
842 nick + " " + to + " " +
843 command + " " + rest,
855 if (command == "PING")
857 Commands::CTCPReply (cnx->bot, nick, "PING", rest);
859 else if (command == "VERSION")
861 Commands::CTCPReply (cnx->bot, nick, "VERSION",
862 cnx->bot->versionString);
864 else if (command == "CLOCK")
866 time_t diff = time (NULL) - cnx->bot->startTime;
867 Commands::CTCPReply (cnx->bot, nick, "CLOCK",
868 String ("elapsed time: ") +
869 String ((long) (diff / 86400)) +
871 String ((long) (diff % 86400) /
873 String ((long) (diff % 3600) / 60) +
874 "m" + String ((long) (diff % 60)) + "s");
876 else if (command == "COMMAND")
878 Commands::CTCPReply (cnx->bot, nick,
879 "COMMAND", String (cnx->bot->commandChar));
881 else if (command == "LAG")
883 Commands::CTCPReply (cnx->bot, nick, "LAG",
884 String ((long) cnx->lag) + " second(s)");
886 else if (command == "DCC")
888 StringTokenizer st2 (rest);
889 command = Utils::to_upper (st2.next_token ());
890 if (command == "CHAT")
894 unsigned long address =
895 std::strtoul (st2.next_token ().c_str(), 0, 0);
896 int port = std::atoi (st2.next_token().c_str());
897 if (port >= 1024 && Utils::get_level (cnx->bot, from->getAddress ()))
898 cnx->bot->addDCC (from, address, port, Bot::CHAT);
900 cnx->bot->logLine ("DCC Chat Failed in Parser");
904 else if (command == "ACTION")
906 cnx->bot->botInterp->RunHooks (Hook::ACTION,
907 from->getNick () + " " + to +
923 Parser::parseMessage (ServerConnection * cnx,
924 Person * from, String to, String parameters)
927 if (Utils::channel_p (to))
928 cnx->bot->botInterp->RunHooks (Hook::PUBLIC,
929 from->getNick () + " " + to +
939 (parameters), SCM_UNDEFINED));
941 cnx->bot->botInterp->RunHooks (Hook::MESSAGE,
942 from->getNick () + " " +
950 (parameters), SCM_UNDEFINED));
952 if (parameters[0] != cnx->bot->commandChar)
955 StringTokenizer st (parameters);
956 String command = Utils::to_upper (st.next_token ().substr (1));
957 String rest = Utils::trim_str (st.rest ());
959 bool identified = false;
960 std::map<std::string, class userFunction*,
961 std::less<std::string> >::const_iterator uf_iter
962 = cnx->bot->userFunctions.find (command);
963 userFunction * f = 0;
965 if (uf_iter != cnx->bot->userFunctions.end ())
972 if (f->needsChannelName)
974 if (Utils::channel_p (rest))
976 StringTokenizer st2 (rest);
977 to = st.next_token ();
980 if (!Utils::channel_p (to))
982 from->sendNotice ("\002You need to supply a channel name"
983 " for this command\002");
986 if (!cnx->bot->channelList->getChannel (to))
988 from->sendNotice (String ("\002I am not on channel\002 ") +
992 level = Utils::get_level (cnx->bot, from->getAddress (), to);
994 if (Channel * c = cnx->bot->channelList->getChannel (to))
995 u = c->getUser (from->getNick ());
996 if (!u || !u->userListItem)
999 identified = u->userListItem->passwd == ""
1000 || u->userListItem->identified > 0;
1004 level = Utils::get_level (cnx->bot, from->getAddress ());
1007 if (level >= f->minLevel)
1009 cnx->bot->logLine (from->getAddress () + " did " + command +
1012 if (f->argsCount != -1)
1014 Parser::parseScriptFunction (cnx, to, f->needsChannelName,
1015 f->scmFunc, f->argsCount,
1020 f->function (cnx, from, to, rest);
1023 f->function (cnx, from, to, rest);
1031 ("\002You are not identified on channel\002 ") +
1039 Parser::parseScriptFunction (ServerConnection * cnx,
1041 bool needsChannelName,
1042 SCM scmFunc, int argsCount, String parameters)
1045 SCM args_list = scm_list_n (SCM_UNDEFINED);
1046 if (needsChannelName)
1048 args_list = scm_append (scm_list_2 (args_list,
1055 StringTokenizer st (parameters);
1056 for (int i = argsCount; i > 0; i--)
1061 param = st.next_token ();
1062 args_list = scm_append (scm_list_2 (args_list,
1063 scm_list_n (Utils::str2scm (param),
1067 struct wrapper_data wd;
1069 wd.args = args_list;
1070 scm_internal_catch (SCM_BOOL_T,
1071 (scm_t_catch_body) Interp::LazyApplyWrapper,
1073 (scm_t_catch_handler) Interp::EmptyHandler, 0);