BotKernel Class Reference

Bot kernel class. More...

#include <botkernel.h>

List of all members.

Public Member Functions

 BotKernel (string)
 Constructor.
 ~BotKernel ()
 Destructor.
plugin_function registerFunction (string, Plugin *, func_type, string, plugin_function, time_t, unsigned int)
 Register a function.
void unregisterFunction (plugin_function)
 Unregister a finction.
plugin_function addCountDown (Plugin *, plugin_function, Message *, unsigned int, unsigned int)
 Add a countdown.
void run ()
 Launch kernel process.
void stop ()
 Stop kernel process.
void send (string)
 Send a message.
void send (vector< string >)
 Send a list (in a vector) of messages.
string getVersion ()
 Return the kernel version.
string getDescription ()
 Return the kernel description.
string getAuthor ()
 Return the kernel author.
void setConnected (bool)
 set the bot connection state
bool getConnected ()
 get the bot connection state
LogFilegetSysLog ()
 Return the SysLog object pointer.
string getNick ()
 get bot's nick
void setNick (string)
 set bot's nick
bool loadPlugin (string, bool)
 Load a plugin.
bool unloadPlugin (string, bool)
 Unload a plugin.
pPlugingetPlugin (string)
 Send a plugin informations.
vector< string > getPluginsList ()
 Send plugin list.
time_t getStartTime ()
 Return power on timestamp.
time_t getStartOnline ()
 Return connection timestamp.
vector< CountDownFunction > * getCountDowns ()
 get a pointer on countdowns
ConfigurationFilegetCONFF ()
 Return the configuration file object pointer.
string getDatasDir ()
 Return datasdir.

Private Member Functions

void displayLicenceHeader ()
 Display licence header.
void initDirs ()
 Create needed directories.
bool executeFunction (Message *, StructFunctionStorage)
 Execute a plugin function.
plugin_function storeFunction (StructFunctionStorage *)
 Store a plugin function.
void msgTreatment (Message *)
 Treat a received message.
void connect ()
 Connect the bot.
void reconnect ()
 Reconnect the bot.
void loadPlugins (bool)
 Load all the plugins mentionned in the configuration file.
void unloadMyPlugins (bool)
 Unload all the loaded plugins.
bool pluginLoaded (string)
 Tell if a plugin is loaded (based on the plugin's name).
bool pluginLoaded (void *)
 Tell if a plugin is loaded (based on the plugin's handle).

Private Attributes

bool connected
 Bot connection state.
string version
 Bot version.
string description
 Bot description.
string author
 Bot author.
list< string > sendQueue
 Contains messages to send.
bool turn
 True if the bot must process.
string datasDir
 bot's datas directory
bool verbose
 True if received messages must be displayed.
time_t startTime
 Timestamp representing the bot launch time.
time_t startOnline
 Timestamp representing the bot connection time.
LogFilemyLog
 SysLog pointer.
ConfigurationFileconff
 ConfigurationFile pointer.
Socketsock
 Socket pointer.
vector< StructFunctionStoragein_loop_plugins
 "loop" plugins functions storage
vector< StructFunctionStoragein_free_command_handler_plugins
 "command handler" plugins functions storage
vector< StructFunctionStoragein_command_handler_plugins
 "free command handler" plugins functions storage
vector< StructFunctionStoragein_type_handler_plugins
 "type" plugins functions storage
vector< StructFunctionStoragein_before_treatment_plugins
 "before traitement" plugins functions storage
vector< StructFunctionStoragein_all_msgs_plugins
 "all messages" plugins functions storage
vector< StructFunctionStoragein_first_word_plugins
 "First word check" plugins functions storage
vector< StructFunctionStorageout_all_msgs_plugins
 "all outgoing messages" plugins functions storage
vector< pPluginmyPlugins
 plugins object en headers
vector< CountDownFunctioncountDowns
 Countdowns storage.
string nick
 Bot's nick.
AntiExcessFlood AEX
 Anti excess flood variables.


Detailed Description

Bot kernel class.

This class manages the bot kernel. It can load plugins, and uses all project class

Definition at line 83 of file botkernel.h.


Constructor & Destructor Documentation

BotKernel::BotKernel ( string  confFile  ) 

Constructor.

The class constructor. Initialize private attributes. Parse the configuration file and initialize bot parameters and objects. Then load plugins

Parameters:
confFile Configuration file path (including name)
Postcondition:
An object is contructed

Definition at line 41 of file botkernel.cpp.

References ConfigurationFile::addProtectedKey(), AEX, author, conff, connected, countDowns, datasDir, description, displayLicenceHeader(), ConfigurationFile::getValue(), in_all_msgs_plugins, in_before_treatment_plugins, in_command_handler_plugins, in_free_command_handler_plugins, in_loop_plugins, in_type_handler_plugins, initDirs(), AntiExcessFlood::last_decrease, ConfigurationFile::load(), loadPlugins(), myLog, LogFile::open(), AntiExcessFlood::penality, sendQueue, sock, startTime, turn, verbose, and version.

BotKernel::~BotKernel (  ) 

Destructor.

The class destructor Unload plugins, stop threads, and delete objects

Definition at line 89 of file botkernel.cpp.

References conff, INFO, LogFile::log(), myLog, sock, and unloadMyPlugins().


Member Function Documentation

plugin_function BotKernel::addCountDown ( Plugin p,
plugin_function  f,
Message m,
unsigned int  count,
unsigned int  timeout 
)

Add a countdown.

Add a count down to the kernel. Functions stored will be executed at the end of their count down A countdown function return false if it must not be deleted after execution (re launch countdown)

Parameters:
p Plugin's object
f Function to execute
m Message
count countdown
timeout Function timeout
Returns:
function adress

Definition at line 639 of file botkernel.cpp.

References conff, CountDownFunction::count, COUNTDOWN, countDowns, CountDownFunction::function, StructFunctionStorage::function, Plugin::getHandle(), Message::getMessage(), ConfigurationFile::getValue(), StructFunctionStorage::handle, StructFunctionStorage::highlightedWord, Tools::intToStr(), StructFunctionStorage::lastExec, LogFile::log(), CountDownFunction::msg, myLog, StructFunctionStorage::object, Tools::strToUnsignedInt(), StructFunctionStorage::symbole, StructFunctionStorage::timeout, CountDownFunction::timestamp, StructFunctionStorage::type, and WARNING.

Referenced by addad(), bannedHandler(), Advertising::launchAdvertise(), launchSurvey(), secondaryNick(), and slapme().

void BotKernel::connect (  )  [private]

Connect the bot.

Connect the bot to the IRC server. Connection parameters are picked in the configuration file.

Definition at line 102 of file botkernel.cpp.

References conff, Socket::connectSock(), ERROR, ConfigurationFile::getValue(), IRCProtocol::identify(), INFO, LogFile::log(), myLog, send(), setConnected(), setNick(), sock, startOnline, Tools::strToInt(), and turn.

Referenced by reconnect(), and run().

void BotKernel::displayLicenceHeader (  )  [private]

Display licence header.

Display licence header

Definition at line 828 of file botkernel.cpp.

References author, and version.

Referenced by BotKernel().

bool BotKernel::executeFunction ( Message m,
StructFunctionStorage  pfs 
) [private]

Execute a plugin function.

Execute a function, managing the timeout

Parameters:
m Message pointer
pfs Function storage
Returns:
True if the message treatment must continue, else false

Definition at line 719 of file botkernel.cpp.

References ThreadParams::b, StructFunctionStorage::back, CPPThread::exec(), ThreadParams::function, Message::getNickSender(), CPPThread::join(), LogFile::log(), ThreadParams::msg, myLog, OUT_ALL_MSGS, ThreadParams::sem, send(), IRCProtocol::sendNotice(), StructFunctionStorage::symbole, CPPThread::terminate(), threadFunc(), StructFunctionStorage::timeout, StructFunctionStorage::type, and WARNING.

Referenced by msgTreatment(), run(), and send().

string BotKernel::getAuthor (  ) 

Return the kernel author.

Get kernel author

Returns:
Kernel's author

Definition at line 898 of file botkernel.cpp.

References author.

ConfigurationFile * BotKernel::getCONFF (  ) 

bool BotKernel::getConnected (  ) 

get the bot connection state

get the bot connexion state

Returns:
true for connected, false for disconnected

Definition at line 953 of file botkernel.cpp.

References connected.

vector< CountDownFunction > * BotKernel::getCountDowns (  ) 

get a pointer on countdowns

Get a pointer on countdowns

Returns:
The pointer

Definition at line 1031 of file botkernel.cpp.

References countDowns.

Referenced by clearCountDowns(), and getnbcountdowns().

string BotKernel::getDatasDir (  ) 

string BotKernel::getDescription (  ) 

Return the kernel description.

Get kernel description

Returns:
Kernel description

Definition at line 916 of file botkernel.cpp.

References description.

string BotKernel::getNick (  ) 

pPlugin * BotKernel::getPlugin ( string  name  ) 

vector< string > BotKernel::getPluginsList (  ) 

Send plugin list.

Return the plugins list

Returns:
A vector containing plugins names

Definition at line 999 of file botkernel.cpp.

References myPlugins.

Referenced by listmodules().

time_t BotKernel::getStartOnline (  ) 

Return connection timestamp.

Return connection timestamp

Returns:
connection timestamp

Definition at line 1022 of file botkernel.cpp.

References startOnline.

Referenced by online().

time_t BotKernel::getStartTime (  ) 

Return power on timestamp.

Return power on timestamp

Returns:
Power on timestamp

Definition at line 1013 of file botkernel.cpp.

References startTime.

Referenced by uptime().

LogFile * BotKernel::getSysLog (  ) 

string BotKernel::getVersion (  ) 

Return the kernel version.

Get kernel version

Returns:
Kernel version

Definition at line 907 of file botkernel.cpp.

References version.

Referenced by ctcp_version(), and version().

void BotKernel::initDirs (  )  [private]

Create needed directories.

Create needed directories

Definition at line 839 of file botkernel.cpp.

References conff, datasDir, and ConfigurationFile::getFilePath().

Referenced by BotKernel().

bool BotKernel::loadPlugin ( string  fileName,
bool  checkDependancy 
)

Load a plugin.

Load a plugin, to make all its functions usable by the bot

Postcondition:
The kernel can use new functions
Parameters:
fileName Dynamic librairy containing the plugins. Just the name, not the path
checkDependancy Set this to true to check for plugin requirements
Returns:
true if the plugin has correctly been loaded, else false

Definition at line 291 of file botkernel.cpp.

References Plugin::checkMembers(), pPlugin::creator, datasDir, pPlugin::destructor, ERROR, error(), StructFunctionStorage::function, Plugin::getFunctions(), Plugin::getName(), Plugin::getRequirements(), StructFunctionStorage::handle, pPlugin::handle, INFO, LogFile::log(), myLog, myPlugins, pPlugin::name, pPlugin::object, pluginLoaded(), Plugin::setHandle(), storeFunction(), StructFunctionStorage::symbole, and WARNING.

Referenced by load(), loadnocheck(), and loadPlugins().

void BotKernel::loadPlugins ( bool  checkDependancy  )  [private]

Load all the plugins mentionned in the configuration file.

Load all the plugins mentionned in the configuration file.

Parameters:
checkDependancy Set this to true to check for plugin requirements

Definition at line 268 of file botkernel.cpp.

References conff, ConfigurationFile::getValue(), INFO, Tools::intToStr(), loadPlugin(), LogFile::log(), myLog, and Tools::stringToVector().

Referenced by BotKernel().

void BotKernel::msgTreatment ( Message msg  )  [private]

Treat a received message.

Treat a message according to its type. Each type of plugin is tested to watch if the message is concerned

Parameters:
msg Pointer to the message object

Definition at line 674 of file botkernel.cpp.

References conff, executeFunction(), Message::getPart(), Message::getSplit(), ConfigurationFile::getValue(), in_all_msgs_plugins, in_command_handler_plugins, in_first_word_plugins, in_free_command_handler_plugins, in_type_handler_plugins, Message::nbParts(), and Tools::to_lower().

Referenced by run().

bool BotKernel::pluginLoaded ( void *  handle  )  [private]

Tell if a plugin is loaded (based on the plugin's handle).

Check if a plugin is loaded. The result is based on the plugin handle

Parameters:
handle Plugin handle
Returns:
True if the given plugin is loaded, else false

Definition at line 504 of file botkernel.cpp.

References myPlugins.

bool BotKernel::pluginLoaded ( string  name  )  [private]

Tell if a plugin is loaded (based on the plugin's name).

Check if a plugin is loaded. The result is based on the plugin NAME (object attribute), not on the file name containing the plugin

Parameters:
name Plugin name
Returns:
True if the given plugin is loaded, else false

Definition at line 488 of file botkernel.cpp.

References myPlugins.

Referenced by getPlugin(), loadPlugin(), and registerFunction().

void BotKernel::reconnect (  )  [private]

Reconnect the bot.

Makes the bot reload the connection All connections objects a re-initialised

Definition at line 122 of file botkernel.cpp.

References Socket::closeSock(), connect(), INFO, LogFile::log(), myLog, setConnected(), and sock.

Referenced by run().

plugin_function BotKernel::registerFunction ( string  hlword,
Plugin object,
func_type  type,
string  symbole,
plugin_function  function,
time_t  lastExec,
unsigned int  timeout 
)

Register a function.

Register a new function. The function is added in the plugins queues and can be triggered

Parameters:
hlword higlited word
object plugin's object
type function type
symbole symbole to execute
function function to execute
lastExec last exec
timeout fuction timeout
Returns:
a pointer on the function, NULL if the plugin does no exists

Definition at line 556 of file botkernel.cpp.

References StructFunctionStorage::function, Plugin::getHandle(), StructFunctionStorage::handle, StructFunctionStorage::highlightedWord, StructFunctionStorage::lastExec, StructFunctionStorage::object, pluginLoaded(), storeFunction(), StructFunctionStorage::symbole, StructFunctionStorage::timeout, and StructFunctionStorage::type.

Referenced by launchSurvey().

void BotKernel::run (  ) 

void BotKernel::send ( vector< string >  vec  ) 

Send a list (in a vector) of messages.

Send strings to the server

Parameters:
vec Vector containing strings to send

Definition at line 818 of file botkernel.cpp.

References send().

void BotKernel::send ( string  str  ) 

Send a message.

Send a string to the server

Parameters:
str String to send

Definition at line 756 of file botkernel.cpp.

References AEX, conff, executeFunction(), Message::getMessage(), ConfigurationFile::getValue(), AntiExcessFlood::last_decrease, LogFile::log(), myLog, out_all_msgs_plugins, AntiExcessFlood::penality, Socket::sendStr(), setConnected(), Message::setMessage(), sock, and WARNING.

Referenced by addad(), addIgnore(), addOnlyon(), addQuote(), addsuperadmin(), addtempsuperadmin(), adinfos(), autoop(), autovoice(), ball(), ban(), bandel(), baninfos(), banlist(), banmask(), bug(), bzsearch(), chanlev(), checkBug(), checkConnection(), clearCountDowns(), clearOutBans(), commandsStatus(), connect(), ctcp_ping(), ctcp_version(), cycleChannel(), danstonchat(), delad(), deletekey(), deleteplayer(), delIgnore(), delOnlyon(), delQuote(), delsuperadmin(), disable(), disconnect(), displayAdvertise(), displayPaste(), enable(), endSurvey(), executeFunction(), fas(), flushconffile(), getconfvalue(), getMyFirstNick(), getnbcountdowns(), greplog(), help(), hl(), host2ip(), ignoreList(), increase(), invite(), ip2host(), isIgnored(), joinChannel(), joinHandler(), kick(), kickall(), kickHandler(), lamoule(), lastQuote(), lastseen(), launchSurvey(), leaveChannel(), listads(), listlibs(), listmodules(), load(), loadconffile(), loadnocheck(), masskick(), modeHandler(), modeHandlerProtect(), moduleinfos(), myFunction(), nextscore(), notice(), onEndOfMOTD(), onInvite(), onJoin(), online(), op(), opall(), partHandler(), pinged(), planet(), player(), prefix(), protectmodes(), protecttopic(), q3(), quitHandler(), quote(), quoteInfos(), randomKick(), raw(), rejoinChan(), reloadfas(), reloadUsers(), searchQuote(), secondaryNick(), send(), setconfvalue(), setlogkeepfiles(), setloglevel(), setlogperiod(), setNick(), setSuperAdminPass(), slapme(), slapUser(), stopSurvey(), superadminlist(), sysinfos(), tele(), tell(), top5(), topic(), topicHandler(), topshot(), toptotal(), trad(), unautoop(), unautovoice(), unbanall(), unload(), unloadnocheck(), unop(), unopall(), unprotectmodes(), unprotecttopic(), unvoice(), unvoiceall(), uptime(), version(), voice(), voiceall(), vote(), warsow(), whoami(), whoowns(), and wiki().

void BotKernel::setConnected ( bool  state  ) 

set the bot connection state

Set the bot connexion state This state is important to make the bot reset if disconnected

Parameters:
state true for connected, false for disconnected

Definition at line 963 of file botkernel.cpp.

References connected.

Referenced by checkConnection(), connect(), reconnect(), reset(), run(), and send().

void BotKernel::setNick ( string  nick  ) 

set bot's nick

Set bot's nick

Parameters:
nick new nick

Definition at line 943 of file botkernel.cpp.

Referenced by connect(), getMyFirstNick(), secondaryNick(), and setNick().

void BotKernel::stop (  ) 

Stop kernel process.

Stop the bot

Definition at line 258 of file botkernel.cpp.

References INFO, LogFile::log(), myLog, and turn.

Referenced by disconnect().

plugin_function BotKernel::storeFunction ( StructFunctionStorage func  )  [private]

void BotKernel::unloadMyPlugins ( bool  checkDependancy  )  [private]

Unload all the loaded plugins.

Unload all the loaded plugins. Makes the bot run only with the kernel (no functionnalities)

Parameters:
checkDependancy Set this to true to check for plugin requirements

Definition at line 473 of file botkernel.cpp.

References myPlugins, and unloadPlugin().

Referenced by ~BotKernel().

bool BotKernel::unloadPlugin ( string  name,
bool  checkDependancy 
)

Unload a plugin.

Unload a plugin. Functions provided by the plugin can no more be used by the kernel.

Parameters:
name Plugin name
checkDependancy Set this to true to check for plugin requirements
Returns:
true if the plugin has correctly been unloaded, else false

Definition at line 382 of file botkernel.cpp.

References ERROR, in_all_msgs_plugins, in_before_treatment_plugins, in_command_handler_plugins, in_first_word_plugins, in_free_command_handler_plugins, in_loop_plugins, in_type_handler_plugins, INFO, LogFile::log(), myLog, myPlugins, and out_all_msgs_plugins.

Referenced by unload(), unloadMyPlugins(), and unloadnocheck().

void BotKernel::unregisterFunction ( plugin_function  func  ) 

Unregister a finction.

Unregister a function

Parameters:
func Function pointer

Definition at line 577 of file botkernel.cpp.

References countDowns, in_all_msgs_plugins, in_before_treatment_plugins, in_command_handler_plugins, in_first_word_plugins, in_free_command_handler_plugins, in_loop_plugins, in_type_handler_plugins, and out_all_msgs_plugins.

Referenced by endSurvey(), myUselessFunction(), and stopSurvey().


Member Data Documentation

Anti excess flood variables.

Definition at line 197 of file botkernel.h.

Referenced by BotKernel(), and send().

string BotKernel::author [private]

Bot author.

Definition at line 147 of file botkernel.h.

Referenced by BotKernel(), displayLicenceHeader(), and getAuthor().

bool BotKernel::connected [private]

Bot connection state.

Definition at line 141 of file botkernel.h.

Referenced by BotKernel(), getConnected(), run(), and setConnected().

Countdowns storage.

Definition at line 185 of file botkernel.h.

Referenced by addCountDown(), BotKernel(), getCountDowns(), run(), and unregisterFunction().

string BotKernel::datasDir [private]

bot's datas directory

Definition at line 153 of file botkernel.h.

Referenced by BotKernel(), getDatasDir(), initDirs(), and loadPlugin().

string BotKernel::description [private]

Bot description.

Definition at line 145 of file botkernel.h.

Referenced by BotKernel(), and getDescription().

"all messages" plugins functions storage

Definition at line 177 of file botkernel.h.

Referenced by BotKernel(), msgTreatment(), storeFunction(), unloadPlugin(), and unregisterFunction().

"before traitement" plugins functions storage

Definition at line 175 of file botkernel.h.

Referenced by BotKernel(), run(), storeFunction(), unloadPlugin(), and unregisterFunction().

"free command handler" plugins functions storage

Definition at line 171 of file botkernel.h.

Referenced by BotKernel(), msgTreatment(), storeFunction(), unloadPlugin(), and unregisterFunction().

"First word check" plugins functions storage

Definition at line 179 of file botkernel.h.

Referenced by msgTreatment(), storeFunction(), unloadPlugin(), and unregisterFunction().

"command handler" plugins functions storage

Definition at line 169 of file botkernel.h.

Referenced by BotKernel(), msgTreatment(), storeFunction(), unloadPlugin(), and unregisterFunction().

"loop" plugins functions storage

Definition at line 167 of file botkernel.h.

Referenced by BotKernel(), run(), storeFunction(), unloadPlugin(), and unregisterFunction().

"type" plugins functions storage

Definition at line 173 of file botkernel.h.

Referenced by BotKernel(), msgTreatment(), storeFunction(), unloadPlugin(), and unregisterFunction().

vector<pPlugin> BotKernel::myPlugins [private]

plugins object en headers

Definition at line 183 of file botkernel.h.

Referenced by getPlugin(), getPluginsList(), loadPlugin(), pluginLoaded(), unloadMyPlugins(), and unloadPlugin().

string BotKernel::nick [private]

Bot's nick.

Definition at line 187 of file botkernel.h.

Referenced by getNick().

"all outgoing messages" plugins functions storage

Definition at line 181 of file botkernel.h.

Referenced by send(), storeFunction(), unloadPlugin(), and unregisterFunction().

list<string> BotKernel::sendQueue [private]

Contains messages to send.

Definition at line 149 of file botkernel.h.

Referenced by BotKernel().

Socket* BotKernel::sock [private]

Socket pointer.

Definition at line 165 of file botkernel.h.

Referenced by BotKernel(), connect(), reconnect(), run(), send(), and ~BotKernel().

time_t BotKernel::startOnline [private]

Timestamp representing the bot connection time.

Definition at line 159 of file botkernel.h.

Referenced by connect(), and getStartOnline().

time_t BotKernel::startTime [private]

Timestamp representing the bot launch time.

Definition at line 157 of file botkernel.h.

Referenced by BotKernel(), and getStartTime().

bool BotKernel::turn [private]

True if the bot must process.

Definition at line 151 of file botkernel.h.

Referenced by BotKernel(), connect(), run(), and stop().

bool BotKernel::verbose [private]

True if received messages must be displayed.

Definition at line 155 of file botkernel.h.

Referenced by BotKernel(), and run().

string BotKernel::version [private]

Bot version.

Definition at line 143 of file botkernel.h.

Referenced by BotKernel(), displayLicenceHeader(), and getVersion().


The documentation for this class was generated from the following files:

Generated on Sun Aug 16 15:28:35 2009 for trustyRC by  doxygen 1.5.8