From: <Jef...@us...> - 2007-10-09 21:15:32
|
Revision: 253 http://libirc.svn.sourceforge.net/libirc/?rev=253&view=rev Author: JeffM2501 Date: 2007-10-09 14:15:30 -0700 (Tue, 09 Oct 2007) Log Message: ----------- hook in some basic command handler callbacks Modified Paths: -------------- trunk/libirc/include/IRCServer.h trunk/libirc/src/IRCServer.cpp Modified: trunk/libirc/include/IRCServer.h =================================================================== --- trunk/libirc/include/IRCServer.h 2007-10-09 21:15:06 UTC (rev 252) +++ trunk/libirc/include/IRCServer.h 2007-10-09 21:15:30 UTC (rev 253) @@ -100,6 +100,29 @@ MemberDataMap members; }; +// base command handler for any command +class IRCServerCommandHandler +{ +public: + IRCServerCommandHandler(){return;} + virtual ~IRCServerCommandHandler(){return;} + + // called when the system wishes to know the name of this command + virtual std::string getCommandName ( void ){return name;} + + // the send and receve methods return true if the default handler is to be called + // it is recomended that the default ALWAYS be called, as it often sets internal data for other mesages + + // called when the client receves a command of this type + virtual bool receve ( IRCServer &server, IRCServerConnectedClient *client, std::string &command, BaseIRCCommandInfo &info ){return true;} + + // called when the user wishes to send a command of this type + virtual bool send ( IRCServer &server, IRCServerConnectedClient *client, std::string &command, BaseIRCCommandInfo &info ){return true;} + +protected: + std::string name; +}; + class IRCServer : public TCPServerDataPendingListener { public: @@ -184,6 +207,27 @@ // channels typedef std::map<std::string, IRCServerChannel*> ChannelMap; ChannelMap channels; + + // command handlers + + typedef std::map<std::string, IRCServerCommandHandler*> tmCommandHandlerMap; + typedef std::map<std::string, std::vector<IRCServerCommandHandler*> > tmCommandHandlerListMap; + + tmCommandHandlerMap defaultCommandHandlers; + tmCommandHandlerListMap userCommandHandlers; + + void addDefaultCommandHandlers ( IRCServerCommandHandler* handler ); + void clearDefaultCommandHandlers ( void ); + void registerDefaultCommandHandlers ( void ); + }; #endif //_IRC_SERVER_H_ + +// Local Variables: *** +// mode:C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 \ No newline at end of file Modified: trunk/libirc/src/IRCServer.cpp =================================================================== --- trunk/libirc/src/IRCServer.cpp 2007-10-09 21:15:06 UTC (rev 252) +++ trunk/libirc/src/IRCServer.cpp 2007-10-09 21:15:30 UTC (rev 253) @@ -445,12 +445,31 @@ void IRCServer::clientIRCCommand ( const BaseIRCCommandInfo &command, IRCServerConnectedClient *client ) { +} +void IRCServer::addDefaultCommandHandlers ( IRCServerCommandHandler* handler ) +{ + defaultCommandHandlers[handler->getCommandName()] = handler; } +void IRCServer::clearDefaultCommandHandlers ( void ) +{ + tmCommandHandlerMap::iterator itr = defaultCommandHandlers.begin(); + while (itr != defaultCommandHandlers.end()) + { + delete(itr->second); + itr++; + } + defaultCommandHandlers.clear(); +} +void IRCServer::registerDefaultCommandHandlers ( void ) +{ +} + + // Local Variables: *** // mode:C++ *** // tab-width: 8 *** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |