botkernel.h

Go to the documentation of this file.
00001 /*
00002 #########################################################################
00003 #
00004 #  This file is part of trustyRC.
00005 #
00006 #  trustyRC, fully modular IRC robot 
00007 #  Copyright (C) 2006-2008 Nicoleau Fabien 
00008 #
00009 #  trustyRC is free software: you can redistribute it and/or modify
00010 #  it under the terms of the GNU General Public License as published by
00011 #  the Free Software Foundation, either version 3 of the License, or
00012 #  (at your option) any later version.
00013 #
00014 #  trustyRC is distributed in the hope that it will be useful,
00015 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 #  GNU General Public License for more details.
00018 #
00019 #  You should have received a copy of the GNU General Public License
00020 #  along with trustyRC.  If not, see <http://www.gnu.org/licenses/>.
00021 #
00022 #########################################################################
00023 */
00024 
00029 #ifndef BOTKERNEL_H
00030 #define BOTKERNEL_H
00031 
00032 // timeout ----
00033 #include <unistd.h>
00034 #include <signal.h>
00035 #include <setjmp.h>
00036 // ------------
00037 #include <time.h>
00038 #include <dlfcn.h>
00039 #include <sys/types.h>
00040 #include <dirent.h>
00041 #include "message.h"
00042 #include "ircprotocol.h"
00043 #include "configurationfile.h"
00044 #include "logfile.h"
00045 #include "tools.h"
00046 #include "socket.h"
00047 #include "plugin.h"
00048 #include <list>
00049 using namespace std;
00050 
00052 typedef struct 
00053 {
00054    time_t last_decrease;
00055    int penality  ;
00056 }AntiExcessFlood;
00057 
00059 typedef struct {  
00060    StructFunctionStorage function;
00061    Message msg;
00062    time_t timestamp;
00063    unsigned int count;
00064 }CountDownFunction;
00065 
00071 class BotKernel
00072 {
00073    public:
00075       BotKernel(string);
00077       ~BotKernel();
00079       plugin_function registerFunction(string,Plugin*,func_type,string,plugin_function,time_t,unsigned int);
00081       void unregisterFunction(plugin_function);
00083       plugin_function addCountDown(Plugin*,plugin_function,Message*,unsigned int,unsigned int);
00085                 void run();
00087                 void stop();
00089                 void send(string);
00091                 void send(vector<string>);
00093                 string getVersion();
00095                 string getDescription();
00097                 string getAuthor();
00099                 void setConnected(bool);
00101                 bool getConnected();
00103                 LogFile* getSysLog();
00105       string getNick();
00107                 void setNick(string);
00109                 bool loadPlugin(string,bool);
00111                 bool unloadPlugin(string,bool);
00113                 pPlugin* getPlugin(string);
00115       vector<string> getPluginsList();
00117       time_t getStartTime();
00119       time_t getStartOnline();
00121       vector<CountDownFunction>* getCountDowns();
00123                 ConfigurationFile* getCONFF();
00125       string getDatasDir();
00126 
00127    private:
00129                 bool connected;
00131                 string version;
00133                 string description;
00135                 string author;
00137                 list<string> sendQueue;
00139                 bool turn;
00141       string datasDir;
00143                 bool verbose;
00145       time_t startTime;
00147       time_t startOnline;
00149                 LogFile* myLog;
00151                 ConfigurationFile * conff;
00153                 Socket * sock;
00155                 vector<StructFunctionStorage> in_loop_plugins;
00157                 vector<StructFunctionStorage> in_free_command_handler_plugins;
00159                 vector<StructFunctionStorage> in_command_handler_plugins;
00161                 vector<StructFunctionStorage> in_type_handler_plugins;
00163                 vector<StructFunctionStorage> in_before_treatment_plugins;
00165                 vector<StructFunctionStorage> in_all_msgs_plugins;
00167                 vector<StructFunctionStorage> in_first_word_plugins;
00169                 vector<StructFunctionStorage> out_all_msgs_plugins;
00171                 vector<pPlugin> myPlugins;
00173       vector<CountDownFunction> countDowns;
00175       string nick ;
00177       void displayLicenceHeader();
00179       void initDirs() ;
00181       bool executeFunction(Message*,StructFunctionStorage);
00183       plugin_function storeFunction(StructFunctionStorage*);
00185       AntiExcessFlood AEX;
00187                 void msgTreatment(Message*);
00189                 void connect();
00191                 void reconnect();
00193                 void loadPlugins(bool);
00195                 void unloadMyPlugins(bool);
00197                 bool pluginLoaded(string);
00199                 bool pluginLoaded(void*);
00200 };
00201 #endif

Generated on Sun Apr 19 02:47:15 2009 for trustyRC by  doxygen 1.5.7.1