rendered paste bodystatic void u_rehash(const userinput * const u) { /* other variables */ char *templine = mycalloc(maxtextlength); int h,i,filedescriptor,needtojump; channel_t *ch, *rch; xdcc *xd; updatecontext(); if (u->method==method_out_all) u_respond(u,"Caught SIGUSR2, Rehashing..."); gdata.r_transferminspeed = gdata.transferminspeed; gdata.r_transfermaxspeed = gdata.transfermaxspeed; if (gdata.logfd != FD_UNUSED) { close(gdata.logfd); gdata.logfd = FD_UNUSED; } reinit_config_vars(); set_loginname(); /* go */ for (h=1; h<MAXCONFIG && gdata.configfile[h]; h++) { u_respond(u,"Reloading %s ...",gdata.configfile[h]); filedescriptor=open(gdata.configfile[h], O_RDONLY | ADDED_OPEN_FLAGS); while (getfline(templine,maxtextlength,filedescriptor,1)) { if ((templine[0] != '#') && templine[0]) { getconfig_set(templine,1); } } close(filedescriptor); } /* see what needs to be redone */ u_respond(u,"Reconfiguring..."); needtojump=0; if (gdata.local_vhost != gdata.r_local_vhost) { needtojump=1; } /* part deleted channels, add common channels */ ch = irlist_get_head(&gdata.channels); while(ch) { rch = irlist_get_head(&gdata.r_channels); while(rch) { if (!strcmp(ch->name,rch->name)) { break; } rch = irlist_get_next(rch); } if (!rch) { if (!needtojump && (ch->flags & CHAN_ONCHAN)) { writeserver(WRITESERVER_NORMAL, "PART %s", ch->name); } if (gdata.debug > 2) { ioutput(CALLTYPE_NORMAL,OUT_S,COLOR_NO_COLOR, "1 = %s parted\n",ch->name); } clearmemberlist(ch); mydelete(ch->name); mydelete(ch->key); ch = irlist_delete(&gdata.channels, ch); } else { rch->flags |= ch->flags & CHAN_ONCHAN; rch->members = ch->members; mydelete(ch->name); mydelete(ch->key); *ch = *rch; if (gdata.debug > 2) { ioutput(CALLTYPE_NORMAL,OUT_S,COLOR_NO_COLOR, "2 = %s common\n", ch->name); } irlist_delete(&gdata.r_channels, rch); ch = irlist_get_next(ch); } } /* join/add new channels */ rch = irlist_get_head(&gdata.r_channels); while(rch) { ch = irlist_get_head(&gdata.channels); while(ch) { if (!strcmp(ch->name,rch->name)) { break; } ch = irlist_get_next(ch); } if (!ch) { ch = irlist_add(&gdata.channels, sizeof(channel_t)); *ch = *rch; ch->flags &= ~CHAN_ONCHAN; if (!needtojump) { joinchannel(ch); } if (gdata.debug > 2) { ioutput(CALLTYPE_NORMAL,OUT_S,COLOR_NO_COLOR, "3 = %s new\n",ch->name); } rch = irlist_delete(&gdata.r_channels, rch); } else { outerror(OUTERROR_TYPE_CRASH,"channel found!"); } } gdata.local_vhost = gdata.r_local_vhost; gdata.r_local_vhost = 0; if (needtojump) { u_respond(u,"vhost changed, reconnecting"); switchserver(-1); /* switchserver takes care of joining channels */ } if (((!gdata.pidfile) && (gdata.r_pidfile)) || ((gdata.pidfile) && (!gdata.r_pidfile)) || ((gdata.pidfile) && (gdata.r_pidfile) && strcmp(gdata.pidfile,gdata.r_pidfile))) { u_respond(u,"pidfile changed, switching"); if (gdata.pidfile) { unlink(gdata.pidfile); } if (gdata.r_pidfile) { writepidfile(gdata.r_pidfile); } } mydelete(gdata.pidfile); gdata.pidfile = gdata.r_pidfile; gdata.r_pidfile = NULL; if (!gdata.r_config_nick) { u_respond(u,"user_nick missing! keeping old nick!"); } else { if (strcmp(gdata.config_nick,gdata.r_config_nick)) { u_respond(u,"user_nick changed, renaming nick to %s", gdata.r_config_nick); writeserver(WRITESERVER_NOW, "NICK %s", gdata.r_config_nick); } mydelete(gdata.config_nick); gdata.config_nick = gdata.r_config_nick; gdata.r_config_nick = NULL; } gdata.maxb = gdata.overallmaxspeed; if (gdata.overallmaxspeeddayspeed != gdata.overallmaxspeed) { struct tm *localt; localt = localtime(&gdata.curtime); if (localt->tm_hour >= gdata.overallmaxspeeddaytimestart && localt->tm_hour < gdata.overallmaxspeeddaytimeend && ( gdata.overallmaxspeeddaydays & (1 << localt->tm_wday)) ) gdata.maxb = gdata.overallmaxspeeddayspeed; } if ( gdata.r_transferminspeed != gdata.transferminspeed) { xd = irlist_get_head(&gdata.xdccs); while(xd) { if (xd->minspeed == gdata.r_transferminspeed) { xd->minspeed = gdata.transferminspeed; } xd = irlist_get_next(xd); } } if ( gdata.r_transfermaxspeed != gdata.transfermaxspeed) { xd = irlist_get_head(&gdata.xdccs); while(xd) { if (xd->maxspeed == gdata.r_transfermaxspeed) { xd->maxspeed = gdata.transfermaxspeed; } xd = irlist_get_next(xd); } } /* check for completeness */ u_respond(u,"Checking for completeness of config file ..."); if ( !irlist_size(&gdata.servers) || gdata.config_nick == NULL || gdata.user_realname == NULL || gdata.user_modes == NULL || gdata.slotsmax == 0) u_respond(u,"**WARNING** missing vital information, fix and re-rehash ASAP"); if ( irlist_size(&gdata.uploadhost) && ( gdata.uploaddir == NULL || strlen(gdata.uploaddir) < 2 ) ) u_respond(u,"**WARNING** incomplete upload information, fix and re-rehash ASAP"); if ( !irlist_size(&gdata.downloadhost) ) { u_respond(u,"**WARNING** no download hosts defined"); } if ( !gdata.statefile ) { u_respond(u,"**WARNING** no state file defined"); } u_respond(u,"Done."); reverify_restrictsend(); for (i=0; i<100; i++) { if (!gdata.exiting && irlist_size(&gdata.mainqueue) && (irlist_size(&gdata.trans) < min2(MAXTRANS,gdata.slotsmax))) { sendaqueue(0); } } mydelete(templine); }