// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+// 02110-1301, USA.
#ifdef HAVE_CONFIG_H
#include "config.h"
// static class member initial definitions
Bot * Interp::bot = 0;
SCM Interp::bot_module = 0;
+
#ifdef MULTITHREAD
pthread_mutex_t Interp::mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
typedef SCM (*SCMFunc)();
SCM
-scm_apply_wrapper(void *data)
+Interp::ScmApplyWrapper (void *data)
{
#ifdef MULTITHREAD
// pthread_mutex_lock (&Interp::mutex);
return SCM_BOOL_T;
}
+SCM
+Interp::LazyHandler (void *data, SCM tag, SCM throw_args)
+{
+ SCM log_port = Interp::bot->botInterp->ScriptLog();
+ SCM eport = scm_set_current_error_port(log_port);
+
+ scm_handle_by_message_noexit((void *)"bobot++", tag, throw_args);
+ scm_force_output(log_port);
+ scm_set_current_error_port(eport);
+ scm_ithrow(tag, throw_args, 1);
+ return SCM_UNSPECIFIED; /* never returns */
+}
+
+SCM
+Interp::EmptyHandler(void *data, SCM tag, SCM args)
+{
+ return SCM_UNSPECIFIED;
+}
+
+
+SCM
+Interp::LazyApplyWrapper(void *data)
+{
+ return scm_internal_lazy_catch(SCM_BOOL_T,
+ (scm_t_catch_body) Interp::ScmApplyWrapper,
+ data,
+ (scm_t_catch_handler) Interp::LazyHandler,
+ 0);
+}
+
+
+static SCM
+lazy_eval_file(char *filename)
+{
+ return scm_internal_lazy_catch(SCM_BOOL_T,
+ (scm_t_catch_body) scm_c_primitive_load,
+ filename,
+ (scm_t_catch_handler) Interp::LazyHandler, 0);
+}
+
+static SCM
+lazy_eval_string(char *str)
+{
+ return scm_internal_lazy_catch(SCM_BOOL_T,
+ (scm_t_catch_body) scm_c_eval_string, str,
+ (scm_t_catch_handler) Interp::LazyHandler, 0);
+}
+
+
+
#define bot_new_procedure(a, b, c, d, e) scm_c_define_gsubr (a, c, d, e, b); scm_c_export (a, 0)
#define scm_c_define_gsubr(a, b, c, d, e) scm_c_define_gsubr (a, b, c, d, e); scm_c_export (a, 0)
#define scm_c_define(a, b) scm_c_define (a, b); scm_c_export (a, 0)
scm_c_define ("bot:user-trusted", scm_long2num (User::TRUSTED_USER));
scm_c_define ("bot:user-friend", scm_long2num (User::FRIEND));
scm_c_define ("bot:user-master", scm_long2num (User::MASTER));
+
+ // protection
+ scm_c_define ("bot:protection/none", scm_long2num (User::NO_PROT));
+ scm_c_define ("bot:protection/no-ban", scm_long2num (User::NO_BAN));
+ scm_c_define ("bot:protection/no-kick", scm_long2num (User::NO_KICK));
+ scm_c_define ("bot:protection/no-deop", scm_long2num (User::NO_DEOP));
+
+ // auto-op
+ scm_c_define ("bot:aop/yes", scm_long2num (true));
+ scm_c_define ("bot:aop/no", scm_long2num (false));
+
// sys-dir
scm_c_define ("bot:sys-scripts-dir",
scm_makfrom0str (String(PREFIX) +
scm_c_define ("hooks/invite", scm_long2num(Hook::INVITE));
scm_c_define ("hooks/join", scm_long2num(Hook::JOIN));
scm_c_define ("hooks/kick", scm_long2num(Hook::KICK));
- scm_c_define ("hooks/leave", scm_long2num(Hook::LEAVE));
- scm_c_define ("hooks/part", scm_long2num(Hook::LEAVE));
scm_c_define ("hooks/mode", scm_long2num(Hook::MODE));
scm_c_define ("hooks/message", scm_long2num(Hook::MESSAGE));
scm_c_define ("hooks/notice", scm_long2num(Hook::NOTICE));
+ scm_c_define ("hooks/part", scm_long2num(Hook::PART));
scm_c_define ("hooks/public", scm_long2num(Hook::PUBLIC));
scm_c_define ("hooks/public-notice", scm_long2num(Hook::PUBLIC_NOTICE));
scm_c_define ("hooks/raw", scm_long2num(Hook::RAW));
scm_c_define_gsubr ("bot:addshit", 3, 2, 0,
(SCMFunc)ScriptCommands::AddShit);
bot_new_procedure ("bot:ban", (SCMFunc)ScriptCommands::Action, 2, 0, 0);
+ bot_new_procedure ("bot:change-command-level",
+ (SCMFunc)ScriptCommands::ChangeCommandLevel,
+ 2, 0, 0);
bot_new_procedure ("bot:cycle", (SCMFunc)ScriptCommands::Action, 1, 0, 0);
bot_new_procedure ("bot:deban", (SCMFunc)ScriptCommands::Deban, 2, 0, 0);
bot_new_procedure ("bot:delserver", (SCMFunc)ScriptCommands::DelServer,
bot_new_procedure ("bot:nextserver", (SCMFunc)ScriptCommands::NextServer,
0, 0, 0);
bot_new_procedure ("bot:nick", (SCMFunc)ScriptCommands::Nick, 1, 0, 0);
+
+ scm_c_define_gsubr ("bot:notice", 2, 0, 0,
+ (SCMFunc)ScriptCommands::sendNotice);
+
bot_new_procedure ("bot:op", (SCMFunc)ScriptCommands::Op, 2, 0, 0);
bot_new_procedure ("bot:part", (SCMFunc)ScriptCommands::Part, 1, 0, 0);
bot_new_procedure ("bot:reconnect", (SCMFunc)ScriptCommands::Reconnect,
0, 0, 0);
bot_new_procedure ("bot:say", (SCMFunc)ScriptCommands::Say, 2, 0, 0);
bot_new_procedure ("bot:server", (SCMFunc)ScriptCommands::Server, 1, 0, 0);
+ scm_c_define_gsubr ("bot:setfloodrate", 1, 0, 0,
+ (SCMFunc)ScriptCommands::SetFloodRate);
bot_new_procedure ("bot:setversion", (SCMFunc)ScriptCommands::SetVersion,
1, 0, 0);
bot_new_procedure ("bot:tban", (SCMFunc)ScriptCommands::TBan, 3, 0, 0);
(SCMFunc)ScriptCommands::sendDCCChatMessage);
// "Low Level" Message functuions
- scm_c_define_gsubr ("bot:send-CTCP", 3, 0, 0,
+ scm_c_define_gsubr ("bot:send-ctcp", 3, 0, 0,
(SCMFunc)ScriptCommands::sendCTCP);
+ scm_c_define_gsubr ("bot:send-ctcp-reply", 3, 0, 0,
+ (SCMFunc)ScriptCommands::sendCTCPReply);
}
#undef bot_new_procedure
SCM module = static_cast<SCM> (bot_module);
scm_c_define ("the-bot-module", module);
scm_c_export ("the-bot-module", 0);
+
// load bobot-utils
scm_primitive_load
(scm_makfrom0str (String(PREFIX) +
"/share/bobotpp/scripts/bobot-utils.scm"));
- return 0;
+ return SCM_UNSPECIFIED;
}
void
Interp::Startup()
{
bot_module = scm_c_define_module ("the-bot-module",
- interp_init_helper, 0);
+ interp_init_helper, 0);
+
scm_c_call_with_current_module (bot_module,
interp_post_startup_helper,
bot_module);
// We get the lock
pthread_mutex_lock(&mutex);
#endif
+
bot = b;
- gh_eval_str_with_catch(command, ErrorHandler);
+ scm_internal_catch(SCM_BOOL_T,
+ (scm_t_catch_body) lazy_eval_string, (void *) static_cast<const char *> (command),
+ (scm_t_catch_handler) Interp::EmptyHandler, 0);
+
#ifdef MULTITHREAD
// We release the lock
pthread_mutex_unlock(&mutex);
#endif
}
-void load_script_helper (void* file)
-{
- String filename = *static_cast<String*> (file);
- scm_c_use_module ("guile-user");
- gh_eval_file_with_catch(filename, Interp::ErrorHandler);
-}
void
Interp::LoadScript(Bot *b, String filename)
pthread_mutex_lock(&mutex);
#endif
bot = b;
- //scm_c_define_module ("", load_script_helper, &filename);
- gh_eval_file_with_catch(filename, ErrorHandler);
+ scm_internal_catch(SCM_BOOL_T,
+ (scm_t_catch_body) lazy_eval_file,
+ (void *)static_cast<const char * >(filename),
+ (scm_t_catch_handler) Interp::EmptyHandler, 0);
#ifdef MULTITHREAD
// We release the lock
pthread_mutex_unlock(&mutex);
#endif
}
-SCM
-Interp::ErrorHandler(void *data, SCM tag, SCM throw_args)
-{
- bot->botInterp->ScriptLog(throw_args);
- return SCM_BOOL_F;
-}
-
#endif