diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd_mode.cpp | 35 | ||||
-rw-r--r-- | src/command_parse.cpp | 65 | ||||
-rw-r--r-- | src/mode.cpp | 11 |
3 files changed, 98 insertions, 13 deletions
diff --git a/src/cmd_mode.cpp b/src/cmd_mode.cpp new file mode 100644 index 000000000..c1d128bf9 --- /dev/null +++ b/src/cmd_mode.cpp @@ -0,0 +1,35 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. + * E-mail: + * <brain@chatspike.net> + * <Craig@chatspike.net> + * + * Written by Craig Edwards, Craig McLure, and others. + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + +#include "configreader.h" +#include "users.h" +#include "commands/cmd_mode.h" + +extern "C" command_t* init_command(InspIRCd* Instance) +{ + return new cmd_mode(Instance); +} + +void cmd_mode::Handle (const char** parameters, int pcnt, userrec *user) +{ + if (!user) + return; + + ServerInstance->Modes->Process(parameters, pcnt, user, false); + + return; +} + diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 13ba64169..600ce2e61 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -444,8 +444,22 @@ void CommandParser::ProcessBuffer(std::string &buffer,userrec *user) } } -bool CommandParser::CreateCommand(command_t *f) +bool CommandParser::CreateCommand(command_t *f, void* so_handle) { + if (so_handle) + { + if (RFCCommands.find(f->command) == RFCCommands.end()) + { + RFCCommands[f->command] = so_handle; + ServerInstance->Log(DEFAULT,"Monitoring RFC-specified reloadable command at %8x",so_handle); + } + else + { + ServerInstance->Log(DEFAULT,"ERK! Somehow, we loaded a cmd_*.so file twice! Only the first instance is being recorded."); + return false; + } + } + /* create the command and push it onto the table */ if (cmdlist.find(f->command) == cmdlist.end()) { @@ -472,6 +486,49 @@ void CommandParser::FindSym(void** v, void* h) } } +bool CommandParser::ReloadCommand(const char* cmd) +{ + char filename[MAXBUF]; + char commandname[MAXBUF]; + int y = 0; + + for (const char* x = cmd; *x; x++, y++) + commandname[y] = toupper(*x); + + commandname[y] = 0; + + SharedObjectList::iterator command = RFCCommands.find(commandname); + + if (command != RFCCommands.end()) + { + command_t* cmdptr = cmdlist.find(commandname)->second; + cmdlist.erase(cmdlist.find(commandname)); + + for (char* x = commandname; *x; x++) + *x = tolower(*x); + + + delete cmdptr; + dlclose(command->second); + + sprintf(filename, "cmd_%s.so", commandname); + this->LoadCommand(filename); + + return true; + } + + return false; +} + +void cmd_reload::Handle(const char** parameters, int pcnt, userrec *user) +{ + user->WriteServ("NOTICE %s :*** Reloading command '%s'",user->nick, parameters[0]); + if (ServerInstance->Parser->ReloadCommand(parameters[0])) + user->WriteServ("NOTICE %s :*** Successfully reloaded command '%s'", user->nick, parameters[0]); + else + user->WriteServ("NOTICE %s :*** Could not reload command '%s'", user->nick, parameters[0]); +} + void CommandParser::LoadCommand(const char* name) { char filename[MAXBUF]; @@ -490,11 +547,13 @@ void CommandParser::LoadCommand(const char* name) command_t* newcommand = cmd_factory_func(ServerInstance); - this->CreateCommand(newcommand); + this->CreateCommand(newcommand, h); } void CommandParser::SetupCommandTable() { + RFCCommands.clear(); + DIR* library = opendir(LIBRARYDIR); if (library) { @@ -508,5 +567,7 @@ void CommandParser::SetupCommandTable() } closedir(library); } + + this->CreateCommand(new cmd_reload(ServerInstance)); } diff --git a/src/mode.cpp b/src/mode.cpp index 5da96249f..3bdcb1a30 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -515,17 +515,6 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool } } - -void cmd_mode::Handle (const char** parameters, int pcnt, userrec *user) -{ - if (!user) - return; - - ServerInstance->Modes->Process(parameters, pcnt, user, false); - - return; -} - void ModeParser::CleanMask(std::string &mask) { std::string::size_type pos_of_pling = mask.find_first_of('!'); |