]>
Commit | Line | Data |
---|---|---|
c86edd1d Q |
1 | /* |
2 | * This is the first client module for newserv :) | |
3 | * | |
4 | * A very simple bot which should give people some ideas for how to | |
5 | * implement stuff on this thing | |
6 | */ | |
7 | ||
8 | #include "../irc/irc_config.h" | |
9 | #include "../parser/parser.h" | |
10 | #include "../localuser/localuser.h" | |
11 | #include "../localuser/localuserchannel.h" | |
12 | #include "../nick/nick.h" | |
13 | #include "../lib/sstring.h" | |
14 | #include "../core/config.h" | |
15 | #include "../irc/irc.h" | |
16 | #include "../lib/splitline.h" | |
17 | #include "../channel/channel.h" | |
18 | #include "../lib/flags.h" | |
19 | #include "../core/schedule.h" | |
20 | #include "../lib/base64.h" | |
21 | #include "../core/modules.h" | |
87698d77 | 22 | #include "../lib/version.h" |
c86edd1d Q |
23 | #include "control.h" |
24 | ||
25 | #include <stdio.h> | |
26 | #include <string.h> | |
27 | #include <stdarg.h> | |
28 | ||
70b0a4e5 | 29 | MODULE_VERSION(""); |
87698d77 | 30 | |
38cee035 | 31 | nick *hooknick; |
c86edd1d | 32 | |
38cee035 | 33 | nick *mynick; |
c86edd1d | 34 | |
38cee035 CP |
35 | CommandTree *controlcmds; |
36 | ControlMsg controlreply; | |
37 | ControlWall controlwall; | |
c86edd1d Q |
38 | |
39 | void handlemessages(nick *target, int messagetype, void **args); | |
40 | int controlstatus(void *sender, int cargc, char **cargv); | |
41 | void controlconnect(void *arg); | |
42 | int controlwhois(void *sender, int cargc, char **cargv); | |
43 | int controlchannel(void *sender, int cargc, char **cargv); | |
44 | int relink(void *sender, int cargc, char **cargv); | |
45 | int die(void *sender, int cargc, char **cargv); | |
46 | int controlinsmod(void *sender, int cargc, char **cargv); | |
1fab6211 | 47 | int controllsmod(void *sender, int cargc, char **cargv); |
c86edd1d | 48 | int controlrehash(void *sender, int cargc, char **cargv); |
c86edd1d | 49 | int controlreload(void *sender, int cargc, char **cargv); |
38cee035 CP |
50 | int controlhelpcmd(void *sender, int cargc, char **cargv); |
51 | void controlnoticeopers(flag_t permissionlevel, flag_t noticelevel, char *format, ...); | |
c86edd1d Q |
52 | |
53 | void _init() { | |
54 | controlcmds=newcommandtree(); | |
38cee035 CP |
55 | controlreply=&controlmessage; |
56 | controlwall=&controlnoticeopers; | |
57 | ||
58 | registercontrolhelpcmd("status",NO_DEVELOPER,1,&controlstatus,"Usage: status ?level?\nDisplays status information, increasing level gives more verbose information."); | |
59 | registercontrolhelpcmd("whois",NO_OPERED,1,&controlwhois,"Usage: whois <nickname|#numeric>\nDisplays lots of information about the specified nickname or numeric."); | |
60 | registercontrolhelpcmd("channel",NO_OPER,1,&controlchannel,"Usage: channel <#channel>\nDisplays channel information."); | |
61 | registercontrolhelpcmd("relink",NO_DEVELOPER,1,&relink,"Usage: relink\nRelinks service to the network."); | |
62 | registercontrolhelpcmd("die",NO_DEVELOPER,1,&die,"Usage: die <reason>\nTerminates the service."); | |
63 | registercontrolhelpcmd("insmod",NO_DEVELOPER,1,&controlinsmod,"Usage: insmod <module>\nAdds a module to the running instance."); | |
64 | registercontrolhelpcmd("rmmod",NO_DEVELOPER,1,&controlrmmod,"Usage: rmmod <module>\nRemoves a module from the running instance."); | |
65 | registercontrolhelpcmd("lsmod",NO_DEVELOPER,0,&controllsmod,"Usage: lsmod\nLists currently running modules."); | |
66 | registercontrolhelpcmd("rehash",NO_DEVELOPER,1,&controlrehash,"Usage: rehash\nReloads configuration file."); | |
67 | registercontrolhelpcmd("showcommands",NO_ACCOUNT,0,&controlshowcommands,"Usage: showcommands\nShows all registered commands."); | |
68 | registercontrolhelpcmd("reload",NO_DEVELOPER,1,&controlreload,"Usage: reload <module>\nReloads specified module."); | |
69 | registercontrolhelpcmd("help",NO_ANYONE,1,&controlhelpcmd,"Usage: help <command>\nShows help for specified command."); | |
c86edd1d Q |
70 | |
71 | scheduleoneshot(time(NULL)+1,&controlconnect,NULL); | |
72 | } | |
73 | ||
0f003446 | 74 | void _fini() { |
a7f301e5 | 75 | deleteallschedules(&controlconnect); |
0f003446 | 76 | if (mynick) { |
77 | deregisterlocaluser(mynick,"Leaving"); | |
78 | } | |
a7f301e5 | 79 | |
80 | deregistercontrolcmd("status",&controlstatus); | |
81 | deregistercontrolcmd("whois",&controlwhois); | |
82 | deregistercontrolcmd("channel",&controlchannel); | |
83 | deregistercontrolcmd("relink",&relink); | |
84 | deregistercontrolcmd("die",&die); | |
85 | deregistercontrolcmd("insmod",&controlinsmod); | |
86 | deregistercontrolcmd("rmmod",&controlrmmod); | |
87 | deregistercontrolcmd("lsmod",&controllsmod); | |
88 | deregistercontrolcmd("rehash",&controlrehash); | |
89 | deregistercontrolcmd("showcommands",&controlshowcommands); | |
90 | deregistercontrolcmd("reload",&controlreload); | |
91 | deregistercontrolcmd("help",&controlhelpcmd); | |
92 | ||
93 | destroycommandtree(controlcmds); | |
0f003446 | 94 | } |
95 | ||
38cee035 CP |
96 | void registercontrolhelpcmd(const char *name, int level, int maxparams, CommandHandler handler, char *help) { |
97 | addcommandhelptotree(controlcmds,name,level,maxparams,handler,help); | |
c86edd1d Q |
98 | } |
99 | ||
100 | int deregistercontrolcmd(const char *name, CommandHandler handler) { | |
101 | return deletecommandfromtree(controlcmds, name, handler); | |
102 | } | |
103 | ||
104 | void controlconnect(void *arg) { | |
105 | sstring *cnick, *myident, *myhost, *myrealname, *myauthname; | |
106 | channel *cp; | |
107 | ||
108 | cnick=getcopyconfigitem("control","nick","C",NICKLEN); | |
109 | myident=getcopyconfigitem("control","ident","control",NICKLEN); | |
110 | myhost=getcopyconfigitem("control","hostname",myserver->content,HOSTLEN); | |
111 | myrealname=getcopyconfigitem("control","realname","NewServ Control Service",REALLEN); | |
112 | myauthname=getcopyconfigitem("control","authname","C",ACCOUNTLEN); | |
113 | ||
84e923c7 | 114 | mynick=registerlocaluser(cnick->content,myident->content,myhost->content,myrealname->content,myauthname->content,UMODE_SERVICE|UMODE_DEAF|UMODE_OPER|UMODE_ACCOUNT|UMODE_INV,&handlemessages); |
38cee035 | 115 | triggerhook(HOOK_CONTROL_REGISTERED, mynick); |
c86edd1d Q |
116 | cp=findchannel("#twilightzone"); |
117 | if (!cp) { | |
118 | localcreatechannel(mynick,"#twilightzone"); | |
119 | } else { | |
120 | localjoinchannel(mynick,cp); | |
121 | localgetops(mynick,cp); | |
122 | } | |
123 | ||
124 | freesstring(cnick); | |
125 | freesstring(myident); | |
126 | freesstring(myhost); | |
127 | freesstring(myrealname); | |
128 | freesstring(myauthname); | |
129 | } | |
130 | ||
131 | void handlestats(int hooknum, void *arg) { | |
38cee035 | 132 | controlreply(hooknick,"%s",(char *)arg); |
c86edd1d Q |
133 | } |
134 | ||
135 | int controlstatus(void *sender, int cargc, char **cargv) { | |
c3db6f7e | 136 | unsigned long level=5; |
38cee035 | 137 | hooknick=(nick *)sender; |
c86edd1d Q |
138 | |
139 | if (cargc>0) { | |
140 | level=strtoul(cargv[0],NULL,10); | |
141 | } | |
c56c22bc | 142 | |
c86edd1d | 143 | registerhook(HOOK_CORE_STATSREPLY,&handlestats); |
c56c22bc | 144 | |
c86edd1d Q |
145 | triggerhook(HOOK_CORE_STATSREQUEST,(void *)level); |
146 | deregisterhook(HOOK_CORE_STATSREPLY,&handlestats); | |
147 | return CMD_OK; | |
148 | } | |
149 | ||
150 | int controlrehash(void *sender, int cargc, char **cargv) { | |
151 | nick *np=(nick *)sender; | |
152 | ||
153 | controlreply(np,"Rehashing the config file."); | |
154 | ||
155 | rehashconfig(); | |
156 | triggerhook(HOOK_CORE_REHASH,(void *)0); | |
157 | return CMD_OK; | |
158 | } | |
38cee035 CP |
159 | |
160 | void handlewhois(int hooknum, void *arg) { | |
161 | controlreply(hooknick,"%s",(char *)arg); | |
162 | } | |
163 | ||
c86edd1d Q |
164 | int controlwhois(void *sender, int cargc, char **cargv) { |
165 | nick *target; | |
166 | channel **channels; | |
167 | char buf[BUFSIZE]; | |
168 | int i; | |
169 | ||
38cee035 CP |
170 | if (cargc<1) |
171 | return CMD_USAGE; | |
c86edd1d Q |
172 | |
173 | if (cargv[0][0]=='#') { | |
174 | if (!(target=getnickbynumericstr(cargv[0]+1))) { | |
38cee035 | 175 | controlreply(sender,"Sorry, couldn't find numeric %s",cargv[0]+1); |
c86edd1d Q |
176 | return CMD_ERROR; |
177 | } | |
178 | } else { | |
179 | if ((target=getnickbynick(cargv[0]))==NULL) { | |
38cee035 | 180 | controlreply((nick *)sender,"Sorry, couldn't find that user"); |
c86edd1d Q |
181 | return CMD_ERROR; |
182 | } | |
183 | } | |
184 | ||
38cee035 CP |
185 | controlreply((nick *)sender,"Nick : %s",target->nick); |
186 | controlreply((nick *)sender,"Numeric : %s",longtonumeric(target->numeric,5)); | |
187 | controlreply((nick *)sender,"User@Host : %s@%s (%d user(s) on this host)",target->ident,target->host->name->content,target->host->clonecount); | |
c86edd1d Q |
188 | if (IsSetHost(target)) { |
189 | if (target->shident) { | |
38cee035 | 190 | controlreply((nick *)sender,"Fakehost : %s@%s",target->shident->content, target->sethost->content); |
c86edd1d | 191 | } else { |
38cee035 | 192 | controlreply((nick *)sender,"Fakehost : %s",target->sethost->content); |
c86edd1d Q |
193 | } |
194 | } | |
38cee035 | 195 | controlreply((nick *)sender,"Timestamp : %lu",target->timestamp); |
526e7c1d | 196 | controlreply((nick *)sender,"IP address: %s",IPtostr(target->p_ipaddr)); |
38cee035 | 197 | controlreply((nick *)sender,"Realname : %s (%d user(s) have this realname)",target->realname->name->content,target->realname->usercount); |
c86edd1d | 198 | if (target->umodes) { |
38cee035 | 199 | controlreply((nick *)sender,"Umode(s) : %s",printflags(target->umodes,umodeflags)); |
c86edd1d Q |
200 | } |
201 | if (IsAccount(target)) { | |
38cee035 | 202 | controlreply((nick *)sender,"Account : %s",target->authname); |
c86edd1d | 203 | if (target->accountts) |
38cee035 | 204 | controlreply((nick *)sender,"AccountTS : %ld",target->accountts); |
c56c22bc CP |
205 | if (target->auth) |
206 | controlreply((nick *)sender,"UserID : %ld",target->auth->userid); | |
c153c0dc CP |
207 | if (target->accountflags) |
208 | controlreply((nick *)sender,"AccFlags : %s",printflags(target->accountflags,accountflags)); | |
c86edd1d | 209 | } |
38cee035 CP |
210 | |
211 | hooknick=(nick *)sender; | |
212 | registerhook(HOOK_CONTROL_WHOISREPLY,&handlewhois); | |
213 | triggerhook(HOOK_CONTROL_WHOISREQUEST,target); | |
214 | deregisterhook(HOOK_CONTROL_WHOISREPLY,&handlewhois); | |
215 | ||
c86edd1d | 216 | if (target->channels->cursi==0) { |
38cee035 | 217 | controlreply((nick *)sender,"Channels : none"); |
c86edd1d | 218 | } else if (target->channels->cursi>50) { |
38cee035 | 219 | controlreply((nick *)sender,"Channels : - (total: %d)",target->channels->cursi); |
c86edd1d Q |
220 | } else { |
221 | buf[0]='\0'; | |
222 | channels=(channel **)target->channels->content; | |
223 | for (i=0;i<=target->channels->cursi;i++) { | |
224 | if (!((i==target->channels->cursi) || ((70-strlen(buf))<channels[i]->index->name->length && strlen(buf)>0))) { | |
225 | strcat(buf,channels[i]->index->name->content); | |
226 | strcat(buf," "); | |
227 | } else { | |
228 | if (strlen(buf)==0) { | |
229 | break; | |
230 | } else { | |
38cee035 | 231 | controlreply((nick *)sender,"Channels : %s",buf); |
c86edd1d Q |
232 | buf[0]='\0'; |
233 | i--; | |
234 | } | |
235 | } | |
236 | } | |
237 | } | |
238 | ||
239 | return CMD_OK; | |
240 | } | |
241 | ||
242 | int controlinsmod(void *sender, int cargc, char **cargv) { | |
38cee035 CP |
243 | if (cargc<1) |
244 | return CMD_USAGE; | |
c86edd1d Q |
245 | |
246 | switch(insmod(cargv[0])) { | |
247 | case -1: | |
38cee035 | 248 | controlreply((nick *)sender,"Unable to load module %s",cargv[0]); |
c86edd1d Q |
249 | return CMD_ERROR; |
250 | ||
251 | case 1: | |
38cee035 | 252 | controlreply((nick *)sender,"Module %s already loaded, or name not valid",cargv[0]); |
c86edd1d Q |
253 | return CMD_ERROR; |
254 | ||
255 | case 0: | |
38cee035 | 256 | controlreply((nick *)sender,"Module %s loaded.",cargv[0]); |
c86edd1d Q |
257 | return CMD_OK; |
258 | ||
259 | default: | |
38cee035 | 260 | controlreply((nick *)sender,"An unknown error occured."); |
c86edd1d Q |
261 | return CMD_ERROR; |
262 | } | |
263 | } | |
264 | ||
265 | int controlrmmod(void *sender, int cargc, char **cargv) { | |
38cee035 CP |
266 | if (cargc<1) |
267 | return CMD_USAGE; | |
c86edd1d Q |
268 | |
269 | switch(rmmod(cargv[0])) { | |
270 | case 1: | |
38cee035 | 271 | controlreply((nick *)sender,"Module %s is not loaded.",cargv[0]); |
c86edd1d Q |
272 | return CMD_ERROR; |
273 | ||
274 | case 0: | |
38cee035 | 275 | controlreply((nick *)sender,"Module %s unloaded.",cargv[0]); |
c86edd1d Q |
276 | return CMD_OK; |
277 | ||
278 | default: | |
38cee035 | 279 | controlreply((nick *)sender,"An unknown error occured."); |
c86edd1d Q |
280 | return CMD_ERROR; |
281 | } | |
282 | } | |
283 | ||
1fab6211 | 284 | int controllsmod(void *sender, int cargc, char **cargv) { |
285 | int i=0; | |
286 | char *ptr; | |
287 | ||
288 | if (cargc < 1) { /* list all loaded modules */ | |
289 | ptr = lsmod(i); | |
38cee035 | 290 | controlreply((nick *)sender,"Module"); |
1fab6211 | 291 | while (ptr != NULL) { |
87698d77 CP |
292 | const char *ver = lsmodver(i); |
293 | controlreply((nick *)sender,"%s%s%s%s", ptr, ver?" (":"", ver?ver:"", ver?")":""); | |
1fab6211 | 294 | ptr = lsmod(++i); |
295 | } | |
296 | } else { | |
297 | ptr = lsmod(getindex(cargv[0])); | |
38cee035 | 298 | controlreply((nick *)sender,"Module \"%s\" %s", cargv[0], (ptr ? "is loaded." : "is NOT loaded.")); |
1fab6211 | 299 | } |
300 | return CMD_OK; | |
301 | } | |
302 | ||
c86edd1d | 303 | int controlreload(void *sender, int cargc, char **cargv) { |
38cee035 CP |
304 | if (cargc<1) |
305 | return CMD_USAGE; | |
65f2c6a3 | 306 | |
307 | controlreply((nick *)sender,"Imma gonna try and reload %s",cargv[0]); | |
3fa581ac | 308 | |
65f2c6a3 | 309 | safereload(cargv[0]); |
3fa581ac | 310 | |
311 | return CMD_OK; | |
65f2c6a3 | 312 | } |
c86edd1d Q |
313 | |
314 | int relink(void *sender, int cargc, char **cargv) { | |
315 | if (cargc<1) { | |
38cee035 CP |
316 | controlreply((nick *)sender,"You must give a reason."); |
317 | return CMD_USAGE; | |
c86edd1d Q |
318 | } |
319 | ||
320 | irc_send("%s SQ %s 0 :%s",mynumeric->content,myserver->content,cargv[0]); | |
321 | irc_disconnected(); | |
322 | ||
323 | return CMD_OK; | |
324 | } | |
325 | ||
326 | int die(void *sender, int cargc, char **cargv) { | |
327 | if (cargc<1) { | |
38cee035 CP |
328 | controlreply((nick *)sender,"You must give a reason."); |
329 | return CMD_USAGE; | |
c86edd1d | 330 | } |
83951d54 | 331 | |
bec7f5c6 | 332 | controlwall(NO_OPER,NL_OPERATIONS,"DIE from %s: %s",((nick *)sender)->nick, cargv[0]); |
c86edd1d | 333 | |
83951d54 | 334 | newserv_shutdown_pending=1; |
c86edd1d | 335 | |
83951d54 | 336 | return CMD_OK; |
c86edd1d Q |
337 | } |
338 | ||
339 | int controlchannel(void *sender, int cargc, char **cargv) { | |
340 | channel *cp; | |
341 | nick *np; | |
342 | chanban *cbp; | |
343 | char buf[BUFSIZE]; | |
344 | char buf2[12]; | |
c6aa54dd | 345 | int i,j, ops=0, voice=0; |
08454d38 P |
346 | char timebuf[30]; |
347 | ||
38cee035 CP |
348 | if (cargc<1) |
349 | return CMD_USAGE; | |
c86edd1d Q |
350 | |
351 | if ((cp=findchannel(cargv[0]))==NULL) { | |
38cee035 | 352 | controlreply((nick *)sender,"Couldn't find channel: %s",cargv[0]); |
c86edd1d Q |
353 | return CMD_ERROR; |
354 | } | |
355 | ||
356 | if (IsLimit(cp)) { | |
357 | sprintf(buf2,"%d",cp->limit); | |
358 | } | |
359 | ||
38cee035 | 360 | controlreply((nick *)sender,"Channel : %s",cp->index->name->content); |
08454d38 P |
361 | strftime(timebuf, 30, "%d/%m/%y %H:%M", localtime(&(cp->timestamp))); |
362 | controlreply((nick *)sender,"C-time : %ld [%s]",cp->timestamp,timebuf); | |
c86edd1d | 363 | if (cp->topic) { |
38cee035 | 364 | controlreply((nick *)sender,"Topic : %s",cp->topic->content); |
08454d38 P |
365 | strftime(timebuf, 30, "%d/%m/%y %H:%M", localtime(&(cp->topictime))); |
366 | controlreply((nick *)sender,"T-time : %ld [%s]",cp->topictime,timebuf); | |
c6aa54dd P |
367 | } else { |
368 | controlreply((nick *)sender,"Topic : (none)"); | |
c86edd1d | 369 | } |
38cee035 | 370 | controlreply((nick *)sender,"Mode(s) : %s %s%s%s",printflags(cp->flags,cmodeflags),IsLimit(cp)?buf2:"", |
c86edd1d | 371 | IsLimit(cp)?" ":"",IsKey(cp)?cp->key->content:""); |
38cee035 | 372 | controlreply((nick *)sender,"Users : %d (hash size %d, utilisation %.1f%%); %d unique hosts", |
c86edd1d Q |
373 | cp->users->totalusers,cp->users->hashsize,((float)(100*cp->users->totalusers)/cp->users->hashsize), |
374 | countuniquehosts(cp)); | |
375 | i=0; | |
376 | memset(buf,' ',90); | |
377 | buf[72]='\0'; | |
378 | for (j=0;j<=cp->users->hashsize;j++) { | |
379 | if (i==4 || j==cp->users->hashsize) { | |
380 | if(i>0) { | |
38cee035 | 381 | controlreply((nick *)sender,"Users : %s",buf); |
c86edd1d Q |
382 | } |
383 | i=0; | |
384 | memset(buf,' ',72); | |
385 | if (j==cp->users->hashsize) | |
386 | break; | |
387 | } | |
388 | if (cp->users->content[j]!=nouser) { | |
c6aa54dd P |
389 | if (cp->users->content[j]&CUMODE_VOICE) |
390 | voice++; | |
391 | else if (cp->users->content[j]&CUMODE_OP) | |
392 | ops++; | |
c86edd1d Q |
393 | np=getnickbynumeric(cp->users->content[j]); |
394 | sprintf(&buf[i*18],"%c%c%-15s ",cp->users->content[j]&CUMODE_VOICE?'+':' ', | |
395 | cp->users->content[j]&CUMODE_OP?'@':' ', np?np->nick:"!BUG-NONICK!"); | |
396 | i++; | |
397 | if (i<4) | |
398 | buf[i*18]=' '; | |
399 | } | |
400 | } | |
c6aa54dd | 401 | controlreply((nick *)sender, "Users : Opped: %d, Voiced: %d", ops,voice); |
c86edd1d | 402 | for (cbp=cp->bans;cbp;cbp=cbp->next) { |
38cee035 | 403 | controlreply((nick *)sender,"Ban : %s",bantostringdebug(cbp)); |
c86edd1d Q |
404 | } |
405 | return CMD_OK; | |
406 | } | |
407 | ||
408 | int controlshowcommands(void *sender, int cargc, char **cargv) { | |
409 | nick *np=(nick *)sender; | |
410 | Command *cmdlist[100]; | |
411 | int i,n; | |
412 | ||
413 | n=getcommandlist(controlcmds,cmdlist,100); | |
414 | ||
415 | controlreply(np,"The following commands are registered at present:"); | |
416 | ||
417 | for(i=0;i<n;i++) { | |
38cee035 | 418 | controlreply(np,"%s",cmdlist[i]->command->content); |
c86edd1d Q |
419 | } |
420 | ||
421 | controlreply(np,"End of list."); | |
422 | return CMD_OK; | |
423 | } | |
424 | ||
425 | void handlemessages(nick *target, int messagetype, void **args) { | |
426 | Command *cmd; | |
427 | char *cargv[50]; | |
428 | int cargc; | |
429 | nick *sender; | |
430 | ||
431 | switch(messagetype) { | |
432 | case LU_PRIVMSG: | |
433 | case LU_SECUREMSG: | |
434 | /* If it's a message, first arg is nick and second is message */ | |
435 | sender=(nick *)args[0]; | |
436 | ||
437 | Error("control",ERR_INFO,"From: %s!%s@%s: %s",sender->nick,sender->ident,sender->host->name->content, (char *)args[1]); | |
438 | ||
439 | /* Split the line into params */ | |
440 | cargc=splitline((char *)args[1],cargv,50,0); | |
441 | ||
442 | if (!cargc) { | |
443 | /* Blank line */ | |
444 | return; | |
445 | } | |
446 | ||
447 | cmd=findcommandintree(controlcmds,cargv[0],1); | |
448 | if (cmd==NULL) { | |
38cee035 | 449 | controlreply(sender,"Unknown command."); |
c86edd1d Q |
450 | return; |
451 | } | |
452 | ||
38cee035 CP |
453 | if (cmd->level>0 && !IsOper(sender)) { |
454 | controlreply(sender,"You need to be opered to use this command."); | |
c86edd1d Q |
455 | return; |
456 | } | |
457 | ||
458 | /* If we were doing "authed user tracking" here we'd put a check in for authlevel */ | |
459 | ||
460 | /* Check the maxargs */ | |
461 | if (cmd->maxparams<(cargc-1)) { | |
462 | /* We need to do some rejoining */ | |
463 | rejoinline(cargv[cmd->maxparams],cargc-(cmd->maxparams)); | |
464 | cargc=(cmd->maxparams)+1; | |
465 | } | |
466 | ||
38cee035 CP |
467 | if((cmd->handler)((void *)sender,cargc-1,&(cargv[1])) == CMD_USAGE) |
468 | controlhelp(sender, cmd); | |
c86edd1d Q |
469 | break; |
470 | ||
471 | case LU_KILLED: | |
472 | /* someone killed me? Bastards */ | |
473 | scheduleoneshot(time(NULL)+1,&controlconnect,NULL); | |
474 | mynick=NULL; | |
475 | break; | |
476 | ||
477 | default: | |
478 | break; | |
479 | } | |
480 | } | |
481 | ||
38cee035 | 482 | void controlmessage(nick *target, char *message, ... ) { |
c86edd1d Q |
483 | char buf[512]; |
484 | va_list va; | |
485 | ||
486 | if (mynick==NULL) { | |
487 | return; | |
488 | } | |
489 | ||
490 | va_start(va,message); | |
491 | vsnprintf(buf,512,message,va); | |
492 | va_end(va); | |
493 | ||
494 | sendmessagetouser(mynick,target,"%s",buf); | |
495 | } | |
496 | ||
497 | void controlchanmsg(channel *cp, char *message, ...) { | |
498 | char buf[512]; | |
499 | va_list va; | |
500 | ||
501 | if (mynick==NULL) { | |
502 | return; | |
503 | } | |
504 | ||
505 | va_start(va,message); | |
506 | vsnprintf(buf,512,message,va); | |
507 | va_end(va); | |
508 | ||
509 | sendmessagetochannel(mynick,cp,"%s",buf); | |
510 | } | |
511 | ||
512 | void controlnotice(nick *target, char *message, ... ) { | |
513 | char buf[512]; | |
514 | va_list va; | |
515 | ||
516 | if (mynick==NULL) { | |
517 | return; | |
518 | } | |
519 | ||
520 | va_start(va,message); | |
521 | vsnprintf(buf,512,message,va); | |
522 | va_end(va); | |
523 | ||
524 | sendnoticetouser(mynick,target,"%s",buf); | |
525 | } | |
526 | ||
38cee035 CP |
527 | void controlspecialrmmod(void *arg) { |
528 | struct specialsched *a = (struct specialsched *)arg; | |
b015c3e9 | 529 | |
38cee035 CP |
530 | a->schedule = NULL; |
531 | sstring *froo = a->modulename; | |
532 | ||
533 | rmmod(froo->content); | |
534 | freesstring(froo); | |
535 | } | |
536 | ||
537 | void controlspecialreloadmod(void *arg) { | |
538 | struct specialsched *a = (struct specialsched *)arg; | |
539 | ||
540 | a->schedule = NULL; | |
541 | sstring *froo = a->modulename; | |
542 | ||
65f2c6a3 | 543 | safereload(froo->content); |
38cee035 CP |
544 | freesstring(froo); |
545 | } | |
546 | ||
547 | void controlhelp(nick *np, Command *cmd) { | |
548 | char *cp = cmd->help, *sp = cp; | |
549 | if(!cp || !*cp) { | |
550 | controlreply(np, "Sorry, no help for this command."); | |
551 | } else { | |
552 | int finished = 0; | |
553 | for(;;cp++) { | |
554 | if(*cp == '\0' || *cp == '\n') { | |
555 | if(*cp == '\0') { | |
556 | finished = 1; | |
557 | } else { | |
558 | *cp = '\0'; | |
559 | } | |
560 | ||
561 | if(sp != cp) | |
562 | controlreply(np, "%s", sp); | |
563 | ||
564 | if(finished) | |
565 | break; | |
566 | ||
567 | *cp = '\n'; | |
568 | ||
569 | sp = cp + 1; | |
570 | } | |
571 | } | |
572 | } | |
573 | } | |
b015c3e9 | 574 | |
38cee035 CP |
575 | int controlhelpcmd(void *sender, int cargc, char **cargv) { |
576 | Command *cmd; | |
577 | nick *np = (nick *)sender; | |
578 | ||
579 | if (cargc<1) | |
580 | return CMD_USAGE; | |
581 | ||
582 | cmd=findcommandintree(controlcmds,cargv[0],1); | |
583 | if (cmd==NULL) { | |
584 | controlreply(np,"Unknown command."); | |
585 | return CMD_ERROR; | |
586 | } | |
587 | ||
588 | controlhelp(np, cmd); | |
589 | return CMD_OK; | |
b015c3e9 | 590 | } |
a80cbef6 CP |
591 | |
592 | void controlnoticeopers(flag_t permissionlevel, flag_t noticelevel, char *format, ...) { | |
593 | int i; | |
594 | nick *np; | |
595 | char broadcast[512]; | |
596 | va_list va; | |
597 | ||
598 | va_start(va, format); | |
599 | vsnprintf(broadcast, sizeof(broadcast), format, va); | |
600 | va_end(va); | |
601 | ||
602 | for(i=0;i<NICKHASHSIZE;i++) | |
603 | for(np=nicktable[i];np;np=np->next) | |
604 | if (IsOper(np)) | |
605 | controlnotice(np, "%s", broadcast); | |
606 | } | |
271ef2d2 | 607 | |
0a659cde CP |
608 | void controlnswall(int noticelevel, char *format, ...) { |
609 | char broadcast[512]; | |
610 | va_list va; | |
611 | ||
612 | va_start(va, format); | |
613 | vsnprintf(broadcast, sizeof(broadcast), format, va); | |
614 | va_end(va); | |
615 | ||
616 | controlwall(NO_OPER, noticelevel, "%s", broadcast); | |
617 | } | |
618 |