#include "../lib/base64.h"
#include "../core/modules.h"
#include "../lib/version.h"
+#include "../lib/irc_string.h"
#include "control.h"
#include <stdio.h>
int controlreload(void *sender, int cargc, char **cargv);
int controlhelpcmd(void *sender, int cargc, char **cargv);
void controlnoticeopers(flag_t permissionlevel, flag_t noticelevel, char *format, ...);
+void handlerehash(int hooknum, void *arg);
void _init() {
controlcmds=newcommandtree();
registercontrolhelpcmd("die",NO_DEVELOPER,1,&die,"Usage: die <reason>\nTerminates the service.");
registercontrolhelpcmd("insmod",NO_DEVELOPER,1,&controlinsmod,"Usage: insmod <module>\nAdds a module to the running instance.");
registercontrolhelpcmd("rmmod",NO_DEVELOPER,1,&controlrmmod,"Usage: rmmod <module>\nRemoves a module from the running instance.");
- registercontrolhelpcmd("lsmod",NO_DEVELOPER,0,&controllsmod,"Usage: lsmod\nLists currently running modules.");
+ registercontrolhelpcmd("lsmod",NO_OPER,0,&controllsmod,"Usage: lsmod\nLists currently running modules.");
registercontrolhelpcmd("rehash",NO_DEVELOPER,1,&controlrehash,"Usage: rehash\nReloads configuration file.");
registercontrolhelpcmd("showcommands",NO_ACCOUNT,0,&controlshowcommands,"Usage: showcommands\nShows all registered commands.");
registercontrolhelpcmd("reload",NO_DEVELOPER,1,&controlreload,"Usage: reload <module>\nReloads specified module.");
registercontrolhelpcmd("help",NO_ANYONE,1,&controlhelpcmd,"Usage: help <command>\nShows help for specified command.");
-
+
+ registerhook(HOOK_CORE_REHASH, &handlerehash);
scheduleoneshot(time(NULL)+1,&controlconnect,NULL);
}
deregistercontrolcmd("help",&controlhelpcmd);
destroycommandtree(controlcmds);
+
+ deregisterhook(HOOK_CORE_REHASH, &handlerehash);
}
void registercontrolhelpcmd(const char *name, int level, int maxparams, CommandHandler handler, char *help) {
}
int controlstatus(void *sender, int cargc, char **cargv) {
- unsigned long level=5;
+ unsigned long level=999;
hooknick=(nick *)sender;
if (cargc>0) {
if (target->umodes) {
controlreply((nick *)sender,"Umode(s) : %s",printflags(target->umodes,umodeflags));
}
+ if (IsOper(target) && target->opername)
+ controlreply((nick *)sender,"Opered as : %s",target->opername->content);
if (IsAccount(target)) {
controlreply((nick *)sender,"Account : %s",target->authname);
if (target->accountts)
controlreply((nick *)sender,"AccountTS : %ld",target->accountts);
- if (target->auth)
+ if (target->auth) {
controlreply((nick *)sender,"UserID : %ld",target->auth->userid);
- if (target->accountflags)
- controlreply((nick *)sender,"AccFlags : %s",printflags(target->accountflags,accountflags));
+ if (target->auth->flags)
+ controlreply((nick *)sender,"AccFlags : %s",printflags(target->auth->flags,accountflags));
+ }
}
hooknick=(nick *)sender;
char *ptr;
if (cargc < 1) { /* list all loaded modules */
- ptr = lsmod(i);
- controlreply((nick *)sender,"Module");
+ const char *ver, *buildid;
+ time_t t, t2 = time(NULL);
+ ptr = lsmod(i, &ver, &buildid, &t);
+
+ /* 9999d 24h 59m 59s fbf2a4a69ee1-tip */
+ controlreply((nick *)sender,"Module Loaded for Version Build id");
while (ptr != NULL) {
- const char *ver = lsmodver(i);
- controlreply((nick *)sender,"%s%s%s%s", ptr, ver?" (":"", ver?ver:"", ver?")":"");
- ptr = lsmod(++i);
+ controlreply((nick *)sender," %-40s %-17s %-20s %s", ptr, longtoduration(t2-t, 2), ver?ver:"", buildid?buildid:"");
+ ptr = lsmod(++i, &ver, &buildid, &t);
}
} else {
- ptr = lsmod(getindex(cargv[0]));
+ ptr = lsmod(getindex(cargv[0]), NULL, NULL, NULL);
controlreply((nick *)sender,"Module \"%s\" %s", cargv[0], (ptr ? "is loaded." : "is NOT loaded."));
}
return CMD_OK;
}
int die(void *sender, int cargc, char **cargv) {
- if (cargc<1) {
+ if (cargc<1 || (strlen(cargv[0]) < 10)) {
controlreply((nick *)sender,"You must give a reason.");
return CMD_USAGE;
}
chanban *cbp;
char buf[BUFSIZE];
char buf2[12];
- int i,j;
+ int i,j, ops=0, voice=0;
char timebuf[30];
if (cargc<1)
controlreply((nick *)sender,"Topic : %s",cp->topic->content);
strftime(timebuf, 30, "%d/%m/%y %H:%M", localtime(&(cp->topictime)));
controlreply((nick *)sender,"T-time : %ld [%s]",cp->topictime,timebuf);
+ } else {
+ controlreply((nick *)sender,"Topic : (none)");
}
controlreply((nick *)sender,"Mode(s) : %s %s%s%s",printflags(cp->flags,cmodeflags),IsLimit(cp)?buf2:"",
IsLimit(cp)?" ":"",IsKey(cp)?cp->key->content:"");
break;
}
if (cp->users->content[j]!=nouser) {
+ if (cp->users->content[j]&CUMODE_OP)
+ ops++;
+ else if (cp->users->content[j]&CUMODE_VOICE)
+ voice++;
np=getnickbynumeric(cp->users->content[j]);
sprintf(&buf[i*18],"%c%c%-15s ",cp->users->content[j]&CUMODE_VOICE?'+':' ',
cp->users->content[j]&CUMODE_OP?'@':' ', np?np->nick:"!BUG-NONICK!");
buf[i*18]=' ';
}
}
-
+ controlreply((nick *)sender, "Users : Opped: %d, Voiced: %d", ops,voice);
for (cbp=cp->bans;cbp;cbp=cbp->next) {
controlreply((nick *)sender,"Ban : %s",bantostringdebug(cbp));
}
void controlspecialrmmod(void *arg) {
struct specialsched *a = (struct specialsched *)arg;
+ sstring *froo = a->modulename;
a->schedule = NULL;
- sstring *froo = a->modulename;
rmmod(froo->content);
freesstring(froo);
void controlspecialreloadmod(void *arg) {
struct specialsched *a = (struct specialsched *)arg;
+ sstring *froo = a->modulename;
a->schedule = NULL;
- sstring *froo = a->modulename;
safereload(froo->content);
freesstring(froo);
}
void controlhelp(nick *np, Command *cmd) {
- char *cp = cmd->help, *sp = cp;
- if(!cp || !*cp) {
+ sstring *scp = cmd->help;
+ if(!scp) {
controlreply(np, "Sorry, no help for this command.");
} else {
+ char *cp = scp->content, *sp = cp;
int finished = 0;
for(;;cp++) {
if(*cp == '\0' || *cp == '\n') {
controlnotice(np, "%s", broadcast);
}
+void controlnswall(int noticelevel, char *format, ...) {
+ char broadcast[512];
+ va_list va;
+
+ va_start(va, format);
+ vsnprintf(broadcast, sizeof(broadcast), format, va);
+ va_end(va);
+
+ controlwall(NO_OPER, noticelevel, "%s", broadcast);
+}
+
+void handlerehash(int hooknum, void *arg) {
+ long hupped = (long)arg;
+ if(hupped)
+ controlwall(NO_OPER, NL_OPERATIONS, "SIGHUP received, rehashing...");
+}
+