-const char* CommandParser::LoadCommand(const char* name)
-{
- char filename[MAXBUF];
- void* h;
- Command* (*cmd_factory_func)(InspIRCd*);
-
- /* Command already exists? Succeed silently - this is needed for REHASH */
- if (RFCCommands.find(name) != RFCCommands.end())
- {
- ServerInstance->Logs->Log("COMMAND",DEBUG,"Not reloading command %s/%s, it already exists", LIBRARYDIR, name);
- return NULL;
- }
-
- snprintf(filename, MAXBUF, "%s/%s", LIBRARYDIR, name);
- h = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
-
- if (!h)
- {
- const char* n = dlerror();
- ServerInstance->Logs->Log("COMMAND",SPARSE, "Error loading core command %s: %s", name, n);
- return n;
- }
-
- if (this->FindSym((void **)&cmd_factory_func, h, name))
- {
- Command* newcommand = cmd_factory_func(ServerInstance);
- this->CreateCommand(newcommand, h);
- }
- return NULL;
-}
-
-void CommandParser::SetupCommandTable(User* user)
-{
- RFCCommands.clear();
-
- if (!user)
- {
- printf("\nLoading core commands");
- fflush(stdout);
- }
-
- DIR* library = opendir(LIBRARYDIR);
- if (library)
- {
- dirent* entry = NULL;
- while ((entry = readdir(library)))
- {
- if (match(entry->d_name, "cmd_*.so"))
- {
- if (!user)
- {
- printf(".");
- fflush(stdout);
- }
- const char* err = this->LoadCommand(entry->d_name);
- if (err)
- {
- if (user)
- {
- user->WriteServ("NOTICE %s :*** Failed to load core command %s: %s", user->nick, entry->d_name, err);
- }
- else
- {
- printf("Error loading %s: %s", entry->d_name, err);
- exit(EXIT_STATUS_BADHANDLER);
- }
- }
- }
- }
- closedir(library);
- if (!user)
- printf("\n");
- }
-
- if (cmdlist.find("RELOAD") == cmdlist.end())
- this->CreateCommand(new cmd_reload(ServerInstance));