From: <Jef...@us...> - 2007-11-16 23:16:44
|
Revision: 335 http://libirc.svn.sourceforge.net/libirc/?rev=335&view=rev Author: JeffM2501 Date: 2007-11-16 15:16:40 -0800 (Fri, 16 Nov 2007) Log Message: ----------- start a static lib to consolidate the IRC bot logic into a more manageable class. Modified Paths: -------------- trunk/libirc/Makefile.am trunk/libirc/examples/stupidBot/sample.cfg Added Paths: ----------- trunk/libirc/botlib/ trunk/libirc/botlib/Makefile.am trunk/libirc/botlib/inc/ trunk/libirc/botlib/inc/botlib.h trunk/libirc/botlib/src/ trunk/libirc/botlib/src/botlib.cpp trunk/libirc/botlib/vc7.1/ trunk/libirc/botlib/vc7.1/botlib.sln trunk/libirc/botlib/vc7.1/botlib.vcproj trunk/libirc/botlib/vc8/ Modified: trunk/libirc/Makefile.am =================================================================== --- trunk/libirc/Makefile.am 2007-11-16 22:24:20 UTC (rev 334) +++ trunk/libirc/Makefile.am 2007-11-16 23:16:40 UTC (rev 335) @@ -9,15 +9,18 @@ EXAMPLES= endif + SUBDIRS = \ include \ m4 \ misc \ src \ + botlib \ $(EXAMPLES) DIST_SUBDIRS = \ examples \ + botlib \ include \ m4 \ misc \ Added: trunk/libirc/botlib/Makefile.am =================================================================== --- trunk/libirc/botlib/Makefile.am (rev 0) +++ trunk/libirc/botlib/Makefile.am 2007-11-16 23:16:40 UTC (rev 335) @@ -0,0 +1,13 @@ +# $Id: Makefile.am 234 2007-07-31 09:07:21Z brlcad $ + +SUBDIRS = \ + src \ + inc + +EXTRA_DIST = \ + vc7.1 \ + vc8 + +MAINTAINERCLEANFILES = Makefile.in + +include $(top_srcdir)/misc/Makefile.defs Added: trunk/libirc/botlib/inc/botlib.h =================================================================== --- trunk/libirc/botlib/inc/botlib.h (rev 0) +++ trunk/libirc/botlib/inc/botlib.h 2007-11-16 23:16:40 UTC (rev 335) @@ -0,0 +1,158 @@ +/* libIRC +* Copyright (c) 2007 Christopher Sean Morrison +* +* This package is free software; you can redistribute it and/or +* modify it under the terms of the license found in the file +* named LICENSE that should have accompanied this file. +* +* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +*/ + +#ifndef _LIBIRC_BOTLIB_H_ +#define _LIBIRC_BOTLIB_H_ + +#include "libIRC.h" +#include "IRCTextUtils.h" + +class LibIRCBotConfigDataValue +{ +public: + LibIRCBotConfigDataValue(const char* data = NULL ); + LibIRCBotConfigDataValue ( const std::string &data ); + + std::vector<std::string> params ( void ); + std::string param ( unsigned int index ); + + std::string value; +}; + +typedef std::vector<LibIRCBotConfigDataValue> LibIRCBotConfigDataValueList; + +class LibIRCBotConfigItem +{ +public: + void set ( const char *data ); + + bool write ( std::string &config ); + + std::string key; + LibIRCBotConfigDataValueList values; +}; + +typedef std::map<std::string,LibIRCBotConfigItem> LibIRCBotConfigItemMap; + +class LibIRCBotConfig +{ +public: + LibIRCBotConfig( const char* file = NULL ); + ~LibIRCBotConfig(); + + bool read ( const char * file ); + bool write ( const char * file ); + + LibIRCBotConfigDataValueList& getKeyItems( const char* key ); + LibIRCBotConfigDataValueList& getKeyItems( const std::string &key ); + + void addItem ( const char* key, const char* value ); + void addItem ( const std::string &key, const std::string &value ); + +protected: + LibIRCBotConfigItemMap items; +}; + +typedef struct +{ + std::string server; + int port; + + std::string hostmask; + std::string username; + + std::vector<std::string> nicks; + std::vector<std::string> channels; + + std::string serverPassword; + std::string nickservPassword; +}trLibIRCConnectionRecord; + +class LibIRCBot +{ +public: + LibIRCBot(); + virtual ~LibIRCBot(); + + // called before connection to set the connection info for the bot + virtual void init ( trLibIRCConnectionRecord &conRec ) = 0; + + // called before run and the main update loop + // when using the built in main + // return true if you want to quit out after + // parsing the command line options + virtual bool prerun ( int argc, char *argv[] ) { return false; } + + // called to start the server run the vents + // will be blocking untill quit is called. + // will sleep for the sleepTime each loop + int run ( void ); + + // called once for each update loop + // called internaly buy run, but can be called + // manualy if not using run and you want to + // mix the bot into your own code + bool runOneLoop ( void ); + +protected: + float sleepTime; + +public: + trLibIRCConnectionRecord connectionRecord; + + bool connect ( void ); +}; + +#ifndef _LIBIRC_NO_BOTMAIN +extern LibIRCBot *theBot; +#endif + +#ifdef _WIN32 +#ifndef _NO_WINMAIN +#define _USE_WINMAIN +#endif +#endif + +#ifdef _USE_WINMAIN +#include <windows.h> +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) +{ + std::vector<std::string> cliParams = string_util::tokenize(std::string(lpCmdLine),std::string(" ")); + int argc = (int)cliParams.size(); + char** argv = (char**)malloc(sizeof(char*) * argc); + for ( int i = 0; i < argc; i++ ) + argv[i] = (char*)cliParams[i].c_str(); +#else +int main ( int argc, char *argv[] ) +{ +#endif + LibIRCBot *bot = theBot; + if (!bot || bot->prerun(argc,argv)) + return -1; + bot->run(); + +#ifdef _USE_WINMAIN + free(argv); +#endif + return 0; +} + +#endif //_LIBIRC_BOTLIB_H_ + + +// Local Variables: *** +// mode:C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 Property changes on: trunk/libirc/botlib/inc/botlib.h ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/libirc/botlib/src/botlib.cpp =================================================================== --- trunk/libirc/botlib/src/botlib.cpp (rev 0) +++ trunk/libirc/botlib/src/botlib.cpp 2007-11-16 23:16:40 UTC (rev 335) @@ -0,0 +1,115 @@ +/* libIRC +* Copyright (c) 2007 Christopher Sean Morrison +* +* This package is free software; you can redistribute it and/or +* modify it under the terms of the license found in the file +* named LICENSE that should have accompanied this file. +* +* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +*/ + +#include "botlib.h" + +#ifndef _LIBIRC_NO_BOTMAIN +LibIRCBot *theBot = NULL; +#endif + +LibIRCBot::LibIRCBot() +{ +#ifndef _LIBIRC_NO_BOTMAIN + theBot = this; +#endif + + sleepTime = 1; +} + +LibIRCBot::~LibIRCBot() +{ +#ifndef _LIBIRC_NO_BOTMAIN + theBot = NULL; +#endif +} + + +int LibIRCBot::run ( void ) +{ + init(connectionRecord); + if (!connect()) + return -1; + + while (!runOneLoop()) + IRCOSSleep(sleepTime) +} + +bool LibIRCBot::runOneLoop ( void ) +{ + return true; +} + +bool LibIRCBot::connect ( void ) +{ + return true; +} + + +//----------------LibIRCBotConfigItem +void LibIRCBotConfigItem::set( const char *data ) +{ +} + +bool LibIRCBotConfigItem::write( std::string &config ) +{ +} + +//----------------LibIRCBotConfig +LibIRCBotConfig::LibIRCBotConfig( const char* file ) +{ + if (file) + read(file); +} + +LibIRCBotConfig::~LibIRCBotConfig() +{ +} + +bool LibIRCBotConfig::read ( const char * file ) +{ + return false; +} + +bool LibIRCBotConfig::write ( const char * file ) +{ + return false; +} + +LibIRCBotConfigDataValueList& LibIRCBotConfig::getKeyItems( const char* key ) +{ + static LibIRCBotConfigDataValueList list; + return list; +} + +LibIRCBotConfigDataValueList& LibIRCBotConfig::getKeyItems( const std::string &key ) +{ + static LibIRCBotConfigDataValueList list; + return list; +} + +void LibIRCBotConfig::addItem ( const char* key, const char* value ) +{ +} + +void LibIRCBotConfig::addItem ( const std::string &key, const std::string &value ) +{ +} + + + +// Local Variables: *** +// mode:C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 Property changes on: trunk/libirc/botlib/src/botlib.cpp ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/libirc/botlib/vc7.1/botlib.sln =================================================================== --- trunk/libirc/botlib/vc7.1/botlib.sln (rev 0) +++ trunk/libirc/botlib/vc7.1/botlib.sln 2007-11-16 23:16:40 UTC (rev 335) @@ -0,0 +1,32 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "botlib", "botlib.vcproj", "{860D2857-1DC9-4284-8004-568C5A3942F3}" + ProjectSection(ProjectDependencies) = postProject + {C5D9B854-BC07-48F5-8E51-16A4B23D60FF} = {C5D9B854-BC07-48F5-8E51-16A4B23D60FF} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libirc", "..\..\vc7.1\libirc.vcproj", "{C5D9B854-BC07-48F5-8E51-16A4B23D60FF}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {860D2857-1DC9-4284-8004-568C5A3942F3}.Debug.ActiveCfg = Debug|Win32 + {860D2857-1DC9-4284-8004-568C5A3942F3}.Debug.Build.0 = Debug|Win32 + {860D2857-1DC9-4284-8004-568C5A3942F3}.Release.ActiveCfg = Release|Win32 + {860D2857-1DC9-4284-8004-568C5A3942F3}.Release.Build.0 = Release|Win32 + {C5D9B854-BC07-48F5-8E51-16A4B23D60FF}.Debug.ActiveCfg = Debug|Win32 + {C5D9B854-BC07-48F5-8E51-16A4B23D60FF}.Debug.Build.0 = Debug|Win32 + {C5D9B854-BC07-48F5-8E51-16A4B23D60FF}.Release.ActiveCfg = Release|Win32 + {C5D9B854-BC07-48F5-8E51-16A4B23D60FF}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal Added: trunk/libirc/botlib/vc7.1/botlib.vcproj =================================================================== --- trunk/libirc/botlib/vc7.1/botlib.vcproj (rev 0) +++ trunk/libirc/botlib/vc7.1/botlib.vcproj 2007-11-16 23:16:40 UTC (rev 335) @@ -0,0 +1,125 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="7.10" + Name="botlib" + ProjectGUID="{860D2857-1DC9-4284-8004-568C5A3942F3}" + Keyword="Win32Proj"> + <Platforms> + <Platform + Name="Win32"/> + </Platforms> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="Debug" + IntermediateDirectory="Debug" + ConfigurationType="4" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="../inc;../../include" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB" + MinimalRebuild="TRUE" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="4"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLibrarianTool" + OutputFile="$(OutDir)/botlib.lib"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="4" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories="../inc;../../include" + PreprocessorDefinitions="WIN32;NDEBUG;_LIB" + RuntimeLibrary="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="3"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLibrarianTool" + OutputFile="$(OutDir)/botlib.lib"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> + <File + RelativePath="..\src\botlib.cpp"> + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> + <File + RelativePath="..\inc\botlib.h"> + </File> + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> + </Filter> + <File + RelativePath=".\ReadMe.txt"> + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> Modified: trunk/libirc/examples/stupidBot/sample.cfg =================================================================== --- trunk/libirc/examples/stupidBot/sample.cfg 2007-11-16 22:24:20 UTC (rev 334) +++ trunk/libirc/examples/stupidBot/sample.cfg 2007-11-16 23:16:40 UTC (rev 335) @@ -1,4 +1,4 @@ -nick:stupidBot +nick:JohnDoe1234 nick:stupiderBot nick:stupiderBot2 @@ -9,17 +9,4 @@ host:localhost realname:"a lib irc sample" -channel:#libirc - -master:YOUR_USERNAME - -joinmessage:#libirc "Yet another StupidBot reporting for duty" - -dontknow:"huh?" - -part:"bye" -quit: "quiting" - -action:dance "waves it like it just don't care" -factoid:status "online" -factoid:ping "pong" +channel:#commits This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |