static GLOBAL_FUNC(cmd_list) { struct globalMessage *message; struct helpfile_table table; unsigned int length, nn; if(!messageList) { global_notice(user, "GMSG_NO_MESSAGES"); return 1; } for(nn=0, message = messageList; message; nn++, message=message->next) ; table.length = nn+1; table.width = 5; table.flags = TABLE_NO_FREE; table.contents = calloc(table.length, sizeof(char**)); table.contents[0] = calloc(table.width, sizeof(char*)); table.contents[0][0] = "ID"; table.contents[0][1] = "Target"; table.contents[0][2] = "Expires"; table.contents[0][3] = "From"; table.contents[0][4] = "Message"; for(nn=1, message = messageList; message; nn++, message = message->next) { char buffer[64]; table.contents[nn] = calloc(table.width, sizeof(char*)); snprintf(buffer, sizeof(buffer), "%lu", message->id); table.contents[nn][0] = strdup(buffer); table.contents[nn][1] = messageType(message); if(message->duration) intervalString(buffer, message->posted + message->duration - now, user->handle_info); else strcpy(buffer, "Never."); table.contents[nn][2] = strdup(buffer); table.contents[nn][3] = message->from; length = strlen(message->message); safestrncpy(buffer, message->message, sizeof(buffer)); if(length > (sizeof(buffer) - 4)) { buffer[sizeof(buffer) - 1] = 0; buffer[sizeof(buffer) - 2] = buffer[sizeof(buffer) - 3] = buffer[sizeof(buffer) - 4] = '.'; } table.contents[nn][4] = strdup(buffer); } table_send(global, user->nick, 0, NULL, table); for (nn=1; nn<table.length; nn++) { free((char*)table.contents[nn][0]); free((char*)table.contents[nn][2]); free((char*)table.contents[nn][4]); free(table.contents[nn]); } free(table.contents[0]); free(table.contents); return 1; }
void do_shitlist(COMMAND_ARGS) { Shit *shit; table_buffer("\037channel\037\t\037mask\037\t\037action\037\t\037set by\037\t\037reason\037\t\037expires\037"); for(shit=current->shitlist;shit;shit=shit->next) { table_buffer(FMT_6XSTRTAB,shit->chan,shit->mask,shit_actions[shit->action], nickcpy(NULL,shit->from),shit->reason,time2away(shit->expire)); } table_send(from,2); }
void do_kicksay(COMMAND_ARGS) { /* * on_msg checks: CARGS */ KickSay *kick; char *channel,*mask; int inum; channel = chop(&rest); if (!channel) { if (!current->kicklist) { to_user(from,"Kicksay list is empty"); return; } if (dcc_only_command(from)) return; table_buffer("\037channel\037\t\037action\037\t\037string\037\t\037kick reason\037"); for(kick=current->kicklist;kick;kick=kick->next) { table_buffer("%s\t%s\t%s\t%s",kick->chan,ks_actions[kick->action],kick->mask,kick->reason); } table_send(from,2); return; } if (ischannel(channel) || *channel == '*') { if (get_useraccess(from,channel) < cmdaccess) return; inum = DEFAULT_KS_LEVEL; if (*rest != '"') { inum = a2i(chop(&rest)); if (errno || inum < 0 || inum > MAX_KS_LEVEL) return; } mask = get_token(&rest,"\""); if (!mask || !*mask) goto usage; /* * check for previously existing kicks */ if ((kick = find_kicksay(mask,channel)) != NULL) { to_user(from,"I'm already kicking on \"%s\"",kick->mask); return; } /* * dig out the reason (the rest) */ while(rest && *rest == ' ') rest++; if (!*rest) goto usage; /* * add it to the list */ set_mallocdoer(do_kicksay); kick = (KickSay*)Calloc(sizeof(KickSay) + Strlen(channel,mask,rest,NULL)); kick->next = current->kicklist; current->kicklist = kick; kick->action = inum; if (!matches("\\*?*\\*",mask)) kick->chan = Strcpy(kick->mask,mask) + 1; else { kick->mask[0] = '*'; Strcpy(kick->mask+1,mask); kick->chan = Strcat(kick->mask,MATCH_ALL) + 1; } kick->reason = Strcpy(kick->chan,channel) + 1; Strcpy(kick->reason,rest); to_user(from,"Now kicking on \"%s\" on %s",mask,channel); current->ul_save++; return; } usage: usage(from); /* usage for CurrentCmd->name */ }
void do_help(COMMAND_ARGS) { char line[MSGLEN]; char *pt; int i,level,axs; int cur,nxt,count,ci,tl; int in; if (dcc_only_command(from)) return; axs = get_maxaccess(from); if (!*rest) { cur = -1; *line = 0; help_loop: count = 0; nxt = OWNERLEVEL; for(i=0;mcmd[i].name;i++) { tl = acmd[i]; if ((tl < nxt) && (tl > cur)) nxt = tl; if (tl != cur) continue; if (count == 0) sprintf(line,"\037Level %3i\037: ",cur); count++; } if (!count) { cur = nxt; goto help_loop; } ci = count; for(i=0;mcmd[i].name;i++) { tl = acmd[i]; if (tl != cur) continue; if (ci != count) Strcat(line,", "); print_help(from,line,strlen(mcmd[i].name)); if (*line == 0) Strcpy(line," "); Strcat(line,(char*)mcmd[i].name); count--; } print_help(from,line,500); if ((cur != OWNERLEVEL) && (nxt <= axs)) cur = nxt; else return; goto help_loop; } level = a2i(rest); if (!errno) { if ((level > axs) || (level < 0)) level = axs; to_user(from,"\037Commands available at Level %i:\037",level); *line = 0; ci = 0; for(i=0;mcmd[i].name;i++) { if (acmd[i] <= level) { if (ci != 0) Strcat(line,", "); ci++; print_help(from,line,strlen(mcmd[i].name)); Strcat(line,(char*)mcmd[i].name); } } if (ci) print_help(from,line,58); else to_user(from,TEXT_NONE); return; } if (STRCHR(rest,'*')) { line[0] = 0; ci = 0; to_user(from,"\037Commands that match query %s\037:",rest); for(i=0;mcmd[i].name;i++) { if ((!matches(rest,(char*)mcmd[i].name)) && (acmd[i] <= axs)) { if (ci != 0) Strcat(line,", "); ci++; print_help(from,line,strlen(mcmd[i].name)); Strcat(line,(char*)mcmd[i].name); } } if (ci) print_help(from,line,500); else to_user(from,TEXT_NONE); return; } /* * We dont want to show help for "../../../../../../etc/passwd" */ if (!is_safepath(rest)) return; pt = Strcpy(line,HELPDIR); for(i=0;(rest[i]);i++) { if (rest[i] >= 'a' && rest[i] <= 'z') *pt = rest[i] - 0x20; else *pt = rest[i]; pt++; } *pt = 0; #ifdef DEBUG debug("(do_help) help file check: %s\n",line); #endif /* DEBUG */ if ((in = open(line,O_RDONLY)) < 0) { to_user(from,"No help found for \"%s\"",rest); return; } #ifdef DEBUG debug("(do_help) helpfile for = '%s'\n",rest); #endif /* DEBUG */ table_buffer("\037Help on %s\037",rest); level = access_needed(rest); if (level > 200) table_buffer("Level needed: Command disabled"); else if (level > 0) table_buffer("Level needed: %i",level); for(i=0;ulist[i].command;i++) { if (!Strcasecmp(rest,ulist[i].command)) { pt = (ulist[i].usage) ? ulist[i].usage : ""; table_buffer("Usage: %s %s",ulist[i].command,pt); break; } } readline(in,&do_help_callback); /* readline closes in */ table_send(from,0); }