Skip to content

Commit

Permalink
Merge pull request #193 from DALnet/persist-uhm-settings-to-disk
Browse files Browse the repository at this point in the history
Persist the uhm_type and uhm_uhmode values to disk
  • Loading branch information
eaescob authored Sep 10, 2021
2 parents 160fce8 + 8a3cb36 commit b5b3578
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Changes for 2.2.0:
rasengan (2):
Added /stats P to show listening ports (PR #134)

Ryan Smith (9):
Ryan Smith (10):
=======
Override clone limits with SVSCLONE (PR #148)
Updates to user hostmasking (PR #175)
Do not attempt to mask the Staff_Address for opers. (PR #175)
Expand All @@ -13,6 +14,7 @@ Ryan Smith (9):
Send out WATCH notifications if the hostname changes due to a mode H change. (PR #175)
Minor typo fixes.
Show UHM variables in /INFO.
Persist the uhm_type and uhm_uhmode values to disk to handle restarts properly.

Emilio Escobar (4):
Fixed oper block corruption when two opers share the same IP (PR #181)
Expand Down
3 changes: 3 additions & 0 deletions include/h.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ extern void terminate(void), write_pidfile(void);
extern int match(char *, char *);
extern char *collapse(char *);

extern int load_settings();
extern int save_settings();

extern int writecalls, writeb[];
#ifdef WRITEV_IOV
extern int deliver_it(aClient *, struct iovec *, int);
Expand Down
79 changes: 79 additions & 0 deletions src/ircd.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ extern void read_help(char *); /* defined in s_serv.c */
extern void init_globals();
extern int klinestore_init(int); /* defined in klines.c */

extern int uhm_type;
extern int uhm_umodeh;

char **myargv;
char configfile[PATH_MAX] = {0}; /* Server configuration file */

Expand Down Expand Up @@ -872,6 +875,8 @@ main(int argc, char *argv[])
}
}

load_settings();

/* init the modules, load default modules! */
init_modules();

Expand Down Expand Up @@ -1334,3 +1339,77 @@ memcount_ircd(MCircd *mc)
return 0;
}

/* load_settings - Load the persistent settings
* Returns: 1 = Success
* 0 = Failure
*/
int load_settings()
{
FILE *fp;
char tmp[PATH_MAX];
char line[1024];
char *para[MAXPARA + 1];
int parc;

ircsprintf(tmp, "%s/settings.txt", dpath);
if(!(fp = fopen(tmp, "r")))
return 0; /* Can't open file! */

while(fgets(line, sizeof(line), fp))
{
char *tmp = strchr(line, '\n');
if(!tmp)
break;
*tmp = '\0';
tmp = line;
parc = 0;
while(*tmp)
{
while(*tmp==' ')
*tmp++ = '\0';

if(*tmp==':')
{
para[parc++] = tmp + 1;
break;
}
para[parc++] = tmp;
while(*tmp && *tmp!=' ')
tmp++;
}
para[parc + 1] = NULL;
if(!mycmp(para[0], "uhm_type") && parc > 1)
{
uhm_type = atoi(para[1]);
}
if(!mycmp(para[0], "uhm_umodeh") && parc > 1)
{
uhm_umodeh = atoi(para[1]);
}
}
fclose(fp);

return 1;
}

/* save_settings - Save the persistent settings file
* Returns: 1 = Success
* 0 = Failure
*/
int save_settings()
{
char tmp[PATH_MAX];
FILE *fp;

ircsprintf(tmp, "%s/settings.txt", dpath);
fp = fopen(tmp, "w");
if(!fp)
return 0;

fprintf(fp, "uhm_type %d\n", uhm_type);
fprintf(fp, "uhm_umodeh %d\n", uhm_umodeh);

fclose(fp);

return 1;
}
2 changes: 2 additions & 0 deletions src/m_services.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,8 @@ int m_svsuhm(aClient *cptr, aClient *sptr, int parc, char *parv[])
}
else sendto_serv_butone(cptr, ":%s SVSUHM %s", sptr->name, parv[1]);

save_settings();

return 0;
}

Expand Down

0 comments on commit b5b3578

Please sign in to comment.