// BotInterp.H -*- C++ -*- // Copyright (c) 1998 Etienne BERNARD // Copyright (C) 2002,2005,2008 Clinton Ebadi // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // 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., 51 Franklin Street, Fifth Floor, Boston, MA // 02110-1301, USA. #ifndef BOTINTERP_H #define BOTINTERP_H #ifdef HAVE_CONFIG_H #include "config.h" #endif #ifdef USESCRIPTS #include #include #include #include #include #include "BotThreading.H" #include "String.H" #include "Utils.H" class Bot; struct Hook { int type; int priority; bool fallthru; String regex_str; String name; SCM regex; SCM function; Hook(int t, String rs, SCM r, SCM f, int p, bool ft, String n="DEFAULT") : type(t), priority (p), fallthru (ft), regex_str(rs), name (n), regex(r), function(f) { } bool operator< (const Hook &h) const { if (priority < h.priority) { return true; } else if (priority > h.priority) { return false; } else if (fallthru && h.fallthru) { return false; } else if (fallthru && !h.fallthru) { return false; } else if (!fallthru && h.fallthru) { return true; } else { // NOTE: This should never be reached return false; } } enum { ACTION, NICKNAME, SIGNOFF, CTCP, CTCP_REPLY, DISCONNECT, FLOOD, INVITE, JOIN, KICK, MODE, MESSAGE, NAMES, NOTICE, PART, PUBLIC, PUBLIC_NOTICE, RAW, TIMER, TOPIC, // send hooks SEND_ACTION, SEND_CTCP, SEND_PUBLIC, SEND_MESSAGE, SEND_WHO, SEND_WHOIS, // DCC hooks DCC_CHAT_BEGIN, DCC_CHAT_END, DCC_CHAT_MESSAGE }; }; struct Timer { int count; std::time_t when; SCM function; Timer(int c, std::time_t t, SCM f) : count(c), when(t), function(f) { } bool operator< (const Timer & other) const { return when < other.when; } }; class BotInterp { typedef std::list TimerList; Bot * bot; SCM logPort; std::map, std::less > hooksMap; TimerList timers; Utils::IndirectPred > timer_sort_p; int counter; BotMutex hook_mutex; BotMutex timer_mutex; // NOTE: recursive lock public: BotInterp(Bot *, String); SCM ScriptLog(); void Execute(String); void LoadScript(String); bool AddHook(int, SCM, SCM, int, bool, String); bool RunHooks(int, String, SCM); SCM AddTimer(int, SCM); bool DelTimer(SCM); bool RunTimers(int); friend class Interp; friend class ScriptCommands; }; #endif #endif