- /* These three are special (can occur without
- * full user registration) and so are saved
- * for later use.
- */
- command_user = new cmd_user;
- command_nick = new cmd_nick;
- command_pass = new cmd_pass;
- this->CreateCommand(command_user);
- this->CreateCommand(command_nick);
- this->CreateCommand(command_pass);
-
- /* The rest of these arent special. boo hoo.
- */
- this->CreateCommand(new cmd_quit);
- this->CreateCommand(new cmd_version);
- this->CreateCommand(new cmd_ping);
- this->CreateCommand(new cmd_pong);
- this->CreateCommand(new cmd_admin);
- this->CreateCommand(new cmd_privmsg);
- this->CreateCommand(new cmd_info);
- this->CreateCommand(new cmd_time);
- this->CreateCommand(new cmd_whois);
- this->CreateCommand(new cmd_wallops);
- this->CreateCommand(new cmd_notice);
- this->CreateCommand(new cmd_join);
- this->CreateCommand(new cmd_names);
- this->CreateCommand(new cmd_part);
- this->CreateCommand(new cmd_kick);
- this->CreateCommand(new cmd_mode);
- this->CreateCommand(new cmd_topic);
- this->CreateCommand(new cmd_who);
- this->CreateCommand(new cmd_motd);
- this->CreateCommand(new cmd_rules);
- this->CreateCommand(new cmd_oper);
- this->CreateCommand(new cmd_list);
- this->CreateCommand(new cmd_die);
- this->CreateCommand(new cmd_restart);
- this->CreateCommand(new cmd_kill);
- this->CreateCommand(new cmd_rehash);
- this->CreateCommand(new cmd_lusers);
- this->CreateCommand(new cmd_stats);
- this->CreateCommand(new cmd_userhost);
- this->CreateCommand(new cmd_away);
- this->CreateCommand(new cmd_ison);
- this->CreateCommand(new cmd_summon);
- this->CreateCommand(new cmd_users);
- this->CreateCommand(new cmd_invite);
- this->CreateCommand(new cmd_trace);
- this->CreateCommand(new cmd_whowas);
- this->CreateCommand(new cmd_connect);
- this->CreateCommand(new cmd_squit);
- this->CreateCommand(new cmd_modules);
- this->CreateCommand(new cmd_links);
- this->CreateCommand(new cmd_map);
- this->CreateCommand(new cmd_kline);
- this->CreateCommand(new cmd_gline);
- this->CreateCommand(new cmd_zline);
- this->CreateCommand(new cmd_qline);
- this->CreateCommand(new cmd_eline);
- this->CreateCommand(new cmd_loadmodule);
- this->CreateCommand(new cmd_unloadmodule);
- this->CreateCommand(new cmd_server);
- this->CreateCommand(new cmd_commands);
+ *v = dlsym(h, "init_command");
+ const char* err = dlerror();
+ if (err && !(*v))
+ {
+ ServerInstance->Logs->Log("COMMAND",SPARSE, "Error loading core command %s: %s\n", name.c_str(), err);
+ return false;
+ }
+ return true;
+}
+
+bool CommandParser::ReloadCommand(std::string cmd, User* user)
+{
+ char filename[MAXBUF];
+ std::transform(cmd.begin(), cmd.end(), cmd.begin(), ::toupper);
+
+ SharedObjectList::iterator command = RFCCommands.find(cmd);
+
+ if (command != RFCCommands.end())
+ {
+ Command* cmdptr = cmdlist.find(cmd)->second;
+ cmdlist.erase(cmdlist.find(cmd));
+
+ RFCCommands.erase(cmd);
+ std::transform(cmd.begin(), cmd.end(), cmd.begin(), ::tolower);
+ delete cmdptr;
+ dlclose(command->second);
+
+ snprintf(filename, MAXBUF, "cmd_%s.so", cmd.c_str());
+ const char* err = this->LoadCommand(filename);
+ if (err)
+ {
+ if (user)
+ user->WriteServ("NOTICE %s :*** Error loading 'cmd_%s.so': %s", user->nick.c_str(), cmd.c_str(), err);
+ return false;
+ }
+
+ return true;
+ }
+
+ return false;
+}
+
+CmdResult cmd_reload::Handle(const std::vector<std::string>& parameters, User *user)
+{
+ if (parameters.size() < 1)
+ return CMD_FAILURE;
+
+ user->WriteServ("NOTICE %s :*** Reloading command '%s'",user->nick.c_str(), parameters[0].c_str());
+ if (ServerInstance->Parser->ReloadCommand(parameters[0], user))
+ {
+ user->WriteServ("NOTICE %s :*** Successfully reloaded command '%s'", user->nick.c_str(), parameters[0].c_str());
+ ServerInstance->SNO->WriteToSnoMask('A', "RELOAD: %s reloaded the '%s' command.", user->nick.c_str(), parameters[0].c_str());
+ return CMD_SUCCESS;
+ }
+ else
+ {
+ user->WriteServ("NOTICE %s :*** Could not reload command '%s' -- fix this problem, then /REHASH as soon as possible!", user->nick.c_str(), parameters[0].c_str());
+ return CMD_FAILURE;
+ }
+}
+
+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;