1 // Interp.C -*- C++ -*-
2 // Copyright (c) 1998 Etienne BERNARD
3 // Copyright (C) 2002 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
8 // (at your option) any later version.
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.
28 #include "BotInterp.H"
32 Bot * Interp::bot = 0;
34 pthread_mutex_t Interp::mutex = PTHREAD_MUTEX_INITIALIZER;
37 typedef SCM (*SCMFunc)();
40 scm_apply_wrapper(void *data)
42 wrapper_data * wd = static_cast<wrapper_data *> (data);
43 scm_apply(wd->func, wd->args, SCM_EOL);
47 #define bot_new_procedure(a, b, c, d, e) scm_c_define_gsubr (a, c, d, e, b)
52 // scm_primitive_load_path(scm_makfrom0str("ice-9/boot-9.scm"));
54 bot_new_procedure ("bot-action", (SCMFunc)ScriptCommands::Action, 2, 0, 0);
55 scm_c_define_gsubr ("bot-adduser", 5, 2, 0,
56 (SCMFunc)ScriptCommands::AddUser);
57 bot_new_procedure ("bot-addserver", (SCMFunc)ScriptCommands::Action,
59 scm_c_define_gsubr ("bot-addshit", 3, 2, 0,
60 (SCMFunc)ScriptCommands::AddShit);
61 bot_new_procedure ("bot-ban", (SCMFunc)ScriptCommands::Action, 2, 0, 0);
62 bot_new_procedure ("bot-cycle", (SCMFunc)ScriptCommands::Action, 1, 0, 0);
63 bot_new_procedure ("bot-deban", (SCMFunc)ScriptCommands::Deban, 2, 0, 0);
64 bot_new_procedure ("bot-delserver", (SCMFunc)ScriptCommands::DelServer,
66 bot_new_procedure ("bot-deluser", (SCMFunc)ScriptCommands::DelUser, 2, 0, 0);
67 bot_new_procedure ("bot-delshit", (SCMFunc)ScriptCommands::DelShit, 2, 0, 0);
68 bot_new_procedure ("bot-deop", (SCMFunc)ScriptCommands::Deop, 2, 0, 0);
69 bot_new_procedure ("bot-die", (SCMFunc)ScriptCommands::Die, 1, 0, 0);
70 bot_new_procedure ("bot-do", (SCMFunc)ScriptCommands::Do, 1, 0, 0);
71 bot_new_procedure ("bot-invite", (SCMFunc)ScriptCommands::Invite, 2, 0, 0);
72 bot_new_procedure ("bot-join", (SCMFunc)ScriptCommands::Join, 1, 1, 0);
73 bot_new_procedure ("bot-keep", (SCMFunc)ScriptCommands::Keep, 2, 0, 0);
74 bot_new_procedure ("bot-kick", (SCMFunc)ScriptCommands::Kick, 2, 1, 0);
75 bot_new_procedure ("bot-kickban", (SCMFunc)ScriptCommands::KickBan, 2, 1, 0);
76 bot_new_procedure ("bot-lock", (SCMFunc)ScriptCommands::Lock, 1, 0, 0);
77 bot_new_procedure ("bot-logport", (SCMFunc)ScriptCommands::LogPort, 0, 0, 0);
78 bot_new_procedure ("bot-mode", (SCMFunc)ScriptCommands::Mode, 2, 0, 0);
79 bot_new_procedure ("bot-msg", (SCMFunc)ScriptCommands::Msg, 2, 0, 0);
80 bot_new_procedure ("bot-nextserver", (SCMFunc)ScriptCommands::NextServer,
82 bot_new_procedure ("bot-nick", (SCMFunc)ScriptCommands::Nick, 1, 0, 0);
83 bot_new_procedure ("bot-op", (SCMFunc)ScriptCommands::Op, 2, 0, 0);
84 bot_new_procedure ("bot-part", (SCMFunc)ScriptCommands::Part, 1, 0, 0);
85 bot_new_procedure ("bot-reconnect", (SCMFunc)ScriptCommands::Reconnect,
87 bot_new_procedure ("bot-say", (SCMFunc)ScriptCommands::Say, 2, 0, 0);
88 bot_new_procedure ("bot-server", (SCMFunc)ScriptCommands::Server, 1, 0, 0);
89 bot_new_procedure ("bot-setversion", (SCMFunc)ScriptCommands::SetVersion,
91 bot_new_procedure ("bot-tban", (SCMFunc)ScriptCommands::TBan, 3, 0, 0);
92 bot_new_procedure ("bot-tkban", (SCMFunc)ScriptCommands::TKBan, 3, 1, 0);
93 bot_new_procedure ("bot-topic", (SCMFunc)ScriptCommands::Topic, 2, 0, 0);
94 bot_new_procedure ("bot-unlock", (SCMFunc)ScriptCommands::Unlock, 1, 0, 0);
96 bot_new_procedure ("bot-getnickname", (SCMFunc)ScriptCommands::getNickname,
98 bot_new_procedure ("bot-getserver", (SCMFunc)ScriptCommands::getServer,
100 bot_new_procedure ("bot-getserverlist",
101 (SCMFunc)ScriptCommands::getServerList, 0, 0, 0);
102 bot_new_procedure ("bot-flush", (SCMFunc)ScriptCommands::flushQueue,
104 bot_new_procedure ("bot-flushport", (SCMFunc)ScriptCommands::flushPort,
106 bot_new_procedure ("bot-random", (SCMFunc)ScriptCommands::random,
108 bot_new_procedure ("bot-addcommand", (SCMFunc)ScriptCommands::addCommand,
110 bot_new_procedure ("bot-delcommand", (SCMFunc)ScriptCommands::delCommand,
112 bot_new_procedure ("bot-addhook", (SCMFunc)ScriptCommands::AddHook,
114 bot_new_procedure ("bot-addtimer", (SCMFunc)ScriptCommands::AddTimer,
116 bot_new_procedure ("bot-deltimer", (SCMFunc)ScriptCommands::DelTimer,
118 scm_c_define ("hooks/action", scm_long2num(Hook::ACTION));
119 scm_c_define ("hooks/nickname", scm_long2num(Hook::NICKNAME));
120 scm_c_define ("hooks/signoff", scm_long2num(Hook::SIGNOFF));
121 scm_c_define ("hooks/ctcp", scm_long2num(Hook::CTCP));
122 scm_c_define ("hooks/ctcp-reply", scm_long2num(Hook::CTCP_REPLY));
123 scm_c_define ("hooks/disconnect", scm_long2num(Hook::DISCONNECT));
124 scm_c_define ("hooks/flood", scm_long2num(Hook::FLOOD));
125 scm_c_define ("hooks/invite", scm_long2num(Hook::INVITE));
126 scm_c_define ("hooks/join", scm_long2num(Hook::JOIN));
127 scm_c_define ("hooks/kick", scm_long2num(Hook::KICK));
128 scm_c_define ("hooks/leave", scm_long2num(Hook::LEAVE));
129 scm_c_define ("hooks/part", scm_long2num(Hook::LEAVE));
130 scm_c_define ("hooks/mode", scm_long2num(Hook::MODE));
131 scm_c_define ("hooks/message", scm_long2num(Hook::MESSAGE));
132 // scm_c_define ("hooks/names", scm_long2num(Hook::NAMES));
133 scm_c_define ("hooks/notice", scm_long2num(Hook::NOTICE));
134 scm_c_define ("hooks/public", scm_long2num(Hook::PUBLIC));
135 scm_c_define ("hooks/public-notice", scm_long2num(Hook::PUBLIC_NOTICE));
136 scm_c_define ("hooks/raw", scm_long2num(Hook::RAW));
137 scm_c_define ("hooks/timer", scm_long2num(Hook::TIMER));
138 scm_c_define ("hooks/topic", scm_long2num(Hook::TOPIC));
146 Interp::Execute(Bot *b, String command)
150 pthread_mutex_lock(&mutex);
153 gh_eval_str_with_catch(command, ErrorHandler);
155 // We release the lock
156 pthread_mutex_unlock(&mutex);
161 Interp::LoadScript(Bot *b, String filename)
165 pthread_mutex_lock(&mutex);
168 gh_eval_file_with_catch(filename, ErrorHandler);
170 // We release the lock
171 pthread_mutex_unlock(&mutex);
176 Interp::ErrorHandler(void *data, SCM tag, SCM throw_args)
178 bot->botInterp->ScriptLog(throw_args);