void do_note(COMMAND_ARGS) { User *u; Note *n; Strp *sp,**np; char header[MSGLEN]; /* * no-args is handled in on_msg() */ if (!(u = find_handle(rest))) { to_user(from,TEXT_UNKNOWNUSER,rest); return; } to_user(from,"Enter your note for %s, end with \".\" on a line by itself", u->name); set_mallocdoer(do_note); n = Calloc(sizeof(Note) + StrlenX(from,to,u->name,NULL)); n->start = now; n->next = notelist; notelist = n; n->to = stringcat(n->from,from) + 1; n->user = stringcat(n->to,to) + 1; stringcpy(n->user,rest); /* * add a note header */ sprintf(header,"\001%s %s",from,time2str(now)); append_strp(&u->note,header); }
void set_str_varc(Chan *channel, int which, char *value) { char *temp,**dst; if (value && *value) { set_mallocdoer(set_str_varc); temp = Strdup(value); } else temp = NULL; dst = (channel) ? (char**)&channel->setting[which] : (char**)¤t->setting[which]; if (*dst) Free(dst); *dst = temp; }
void copy_vars(UniVar *dst, UniVar *src) { int i; for(i=0;i<CHANSET_SIZE;i++) { if (IsStr(i)) { if (src[i].str_var) { set_mallocdoer(copy_vars); dst[i].str_var = Strdup(src[i].str_var); } } else { dst[i].int_var = src[i].int_var; } } }
Shit *add_shit(char *from, char *chan, char *mask, char *reason, int axs, int expire) { Shit *shit; set_mallocdoer(add_shit); shit = (Shit*)Calloc(sizeof(Shit) + StrlenX(from,chan,mask,reason,NULL)); shit->action = axs; shit->time = now; shit->expire = expire; shit->next = current->shitlist; current->shitlist = shit; shit->chan = stringcpy(shit->mask,mask) + 1; shit->from = stringcpy(shit->chan,chan) + 1; shit->reason = stringcpy(shit->from,from) + 1; stringcpy(shit->reason,reason); current->ul_save++; return(shit); }
void stats_plusminususer(Chan *chan, int plusminus) { ChanStats *stats; ChanUser *cu; if (!(stats = chan->stats)) { set_mallocdoer(stats_plusminususer); chan->stats = stats = (ChanStats*)Calloc(sizeof(ChanStats)); /* Calloc sets memory to 0 */ for(cu=chan->users;cu;cu=cu->next) stats->users++; stats->userpeak = stats->users; stats->userlow = stats->users; stats->lastuser = now; stats->flags = CSTAT_PARTIAL; } /* * add (number of users until now * seconds since last user entered/left) */ stats->userseconds += stats->users * (now - stats->lastuser); stats->lastuser = now; stats->users += plusminus; /* can be both negative (-1), zero (0) and positive (+1) */ if (stats->userpeak < stats->users) stats->userpeak = stats->users; if (stats->userlow > stats->users) stats->userlow = stats->users; #ifdef DEBUG debug("(stats_plusminususer) %s: %i users, %i userseconds, %i high, %i low; %s (%lu)\n", chan->name,stats->users,stats->userseconds,stats->userpeak,stats->userlow, atime(stats->lastuser),stats->lastuser); #endif /* DEBUG */ }
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 make_seen(char *nick, char *userhost, char *pa, char *pb, time_t when, int t) { Seen *seen,**pp; char *pt; uchar c1; int i; for(pt=userhost;*pt;pt++) { if (*pt == '!') { userhost = pt + 1; break; } } c1 = nickcmptab[(uchar)(*nick)]; pt = nick + 1; pp = &seenlist; step_one: if (*pp) { if (c1 > nickcmptab[(uchar)(*(*pp)->nick)]) { pp = &(*pp)->next; goto step_one; } } step_two: if (*pp) { if (c1 == nickcmptab[(uchar)(*(*pp)->nick)]) { i = nickcmp(pt,(*pp)->nick+1); if (i > 0) { pp = &(*pp)->next; goto step_two; } if (!i) { seen = *pp; *pp = seen->next; Free((char**)&seen); } } } /* * dont f**k with this code unless you really know what you're doing * pa might be NULL, but then pb is NULL also; pb might be NULL * any NULL terminates the Strlen() check */ set_mallocdoer(make_seen); seen = (Seen*)Calloc(sizeof(Seen) + Strlen(nick,userhost,pa,pb,NULL)); seen->next = *pp; *pp = seen; seen->when = when; seen->t = t; /* Calloc sets to zero seen->pa = seen->pb = NULL; */ seen->userhost = Strcpy(seen->nick,nick) + 1; pt = Strcpy(seen->userhost,userhost) + 1; if (pa) { seen->pa = pt; pt = Strcpy(seen->pa,pa) + 1; if (pb) { seen->pb = pt; Strcpy(seen->pb,pb); } } }
int read_bigcharset_callback(char *rest) { Strp *sp,**pp; char *opt; int *n,sz; if (charlines) { charlines--; sz = strlen(rest); if (sz > newchar->width) newchar->width = sz; pp = &newchar->data; while(*pp) pp = &(*pp)->next; set_mallocdoer(read_bigcharset_callback); *pp = sp = (Strp*)Calloc(sizeof(Strp) + sz); /* Calloc sets to zero sp->next = NULL; */ Strcpy(sp->p,rest); return(FALSE); } opt = chop(&rest); n = NULL; if (!Strcasecmp(opt,"chars") && charheight) { charlines = charheight; opt = chop(&rest); set_mallocdoer(read_bigcharset_callback); newchar = (BigC*)Calloc(sizeof(BigC) + strlen(opt)); /* Calloc sets to zero newchar->width = 0; newchar->data = NULL; */ newchar->next = fontlist; fontlist = newchar; Strcpy(newchar->chars,opt); } else if (!Strcasecmp(opt,"spacewidth")) { n = &spacewidth; } else if (!Strcasecmp(opt,"charheight")) { n = &charheight; } else if (!Strcasecmp(opt,"kerning")) { n = &kerning; } else if (!Strcasecmp(opt,"fontname")) { opt = chop(&rest); if (fontname && !Strcasecmp(fontname,opt)) { fontlist = orig_fontlist; charlines = orig_charlines; charheight = orig_charheight; spacewidth = orig_spacewidth; kerning = orig_kerning; orig_fontlist = NULL; return(TRUE); } Free((char**)&fontname); set_mallocdoer(read_bigcharset_callback); fontname = Strdup(opt); } if (n) { *n = a2i(rest); if (errno) *n = 0; } return(FALSE); }
void do_greet(COMMAND_ARGS) { /* * on_msg checks: CARGS */ User *user; char *handle; int isfile; if ((handle = chop(&rest)) == NULL) goto usage; if ((user = find_handle(handle)) == NULL) { to_user(from,TEXT_UNKNOWNUSER,handle); return; } if (!usercanmodify(from,user)) { to_user(from,TEXT_USEROWNSYOU,user->name); return; } isfile = FALSE; if (*rest == '@' || *rest == '%') { isfile = *rest; rest++; while(*rest == ' ') rest++; } if (*rest) { if (isfile) { if (!is_safepath(rest)) goto usage; } user->x.x.greetfile = (isfile == '@') ? TRUE : FALSE; user->x.x.randline = (isfile == '%') ? TRUE : FALSE; set_mallocdoer(do_greet); user->greet = Strdup(rest); to_user(from,"greeting for user %s has been set to: %s%s",user->name,user->greet, (isfile == '@') ? " (file)" : ((isfile == '%') ? " (random line from file)" : "")); current->ul_save++; } else if (isfile) { goto usage; } else if (user->greet) { Free((char**)&user->greet); to_user(from,"greeting for user %s has been removed",user->name); current->ul_save++; } return; usage: usage(from); /* usage for CurrentCmd->name */ }
void do_set(COMMAND_ARGS) { /* * on_msg checks: */ Chan *chan; UniVar *univar,*varval; char tmp[MSGLEN]; char *pp,*channel,*name; int n,which,i,sz,limit,uaccess; /* * */ channel = get_channel2(to,&rest); chan = find_channel_ny(channel); name = chop(&rest); /* * empty args, its "set" or "set #channel" */ if (!name) { if (!chan) { to_user(from,ERR_CHAN,channel); return; } if (!CurrentDCC) return; i = CHANSET_SIZE; limit = SIZE_VARS - 1; univar = current->setting; *tmp = 0; if ((uaccess = get_useraccess(from,GLOBAL_CHANNEL))) to_user(from,str_underline("Global settings")); second_pass: for(;i<limit;i++) { if (uaccess < VarName[i].uaccess) continue; varval = (IsProc(i)) ? current->setting[i].proc_var : &univar[i]; sz = Strlen2(tmp,VarName[i].name); if (IsStr(i)) { sz += (varval->str_var) ? strlen(varval->str_var) : 7; } if (sz > 58) { to_user(from,FMT_PLAIN,tmp); *tmp = 0; } if (IsInt(i)) { pp = tolowercat(tmp,VarName[i].name); sprintf(pp,(IsChar(i)) ? "=`%c' " : "=%i ",varval->int_var); } else if (IsStr(i)) { pp = tolowercat(tmp,VarName[i].name); sprintf(pp,(varval->str_var) ? "=\"%s\" " : "=(unset) ",varval->str_var); } else if (IsTog(i)) { pp = Strcat(tmp,(varval->int_var) ? "+" : "-"); pp = tolowercat(pp,VarName[i].name); pp[0] = ' '; pp[1] = 0; } } if (*tmp && tmp[1]) to_user(from,FMT_PLAIN,tmp); if (limit != CHANSET_SIZE) { to_user(from,"\037Channel settings: %s\037",(chan) ? chan->name : rest); i = 0; limit = CHANSET_SIZE; univar = chan->setting; *tmp = 0; uaccess = get_useraccess(from,(chan) ? chan->name : rest); goto second_pass; } return; } /* * alter a setting */ if ((which = find_setting(name)) == -1) { set_usage: usage(from); /* usage for CurrentCmd->name */ return; } if ((which < CHANSET_SIZE) && *channel != '*') { if (!chan) { to_user(from,ERR_CHAN,channel); return; } /* * its a channel setting */ channel = chan->name; varval = &chan->setting[which]; } else { /* * its a global setting */ channel = MATCH_ALL; varval = ¤t->setting[which]; } if (VarName[which].uaccess > get_authaccess(from,channel)) return; /* * Check each type and process `rest' if needed. */ n = 0; if (IsChar(which)) { if (rest[1]) goto set_usage; } else if (IsNum(which)) { if (IsTog(which)) { if (!Strcasecmp(rest,"ON")) { n = 1; goto num_data_ok; } else if (!Strcasecmp(rest,"OFF")) { /* n is 0 by default */ goto num_data_ok; } } n = a2i((rest = chop(&rest))); if (errno || n < VarName[which].min || n > VarName[which].max) { to_user(from,"Possible values are %i through %i",VarName[which].min,VarName[which].max); return; } } num_data_ok: /* * */ if ((which < CHANSET_SIZE) && *channel == '*') { for(chan=current->chanlist;chan;chan=chan->next) { if (IsNum(which)) { chan->setting[which].int_var = n; } else if (IsStr(which)) { Free((char**)&chan->setting[which].str_var); if (*rest) { set_mallocdoer(do_set); chan->setting[which].str_var = Strdup(rest); } } } channel = "(all channels)"; } else { if (IsProc(which)) varval = varval->proc_var; if (IsChar(which)) varval->char_var = *rest; else if (IsNum(which)) varval->int_var = n; else { if (varval->str_var) Free((char**)&varval->str_var); if (*rest) { set_mallocdoer(do_set); varval->str_var = Strdup(rest); } } } to_user(from,"Var: %s On: %s Set to: %s",VarName[which].name, (which >= CHANSET_SIZE) ? "(global)" : channel,(*rest) ? rest : NULLSTR); if (VarName[which].func) VarName[which].func(&VarName[which]); }