4 * This module handles states which are global to the entire server.
28 #include "sysdep_decls.h"
35 struct CitControl CitControl;
37 FILE *control_fp = NULL;
40 * get_control - read the control record into memory.
42 void get_control(void) {
44 /* Zero it out. If the control record on disk is missing or short,
45 * the system functions with all control record fields initialized
48 memset(&CitControl, 0, sizeof(struct CitControl));
49 if (control_fp == NULL)
50 control_fp = fopen("citadel.control", "rb+");
51 if (control_fp == NULL) return;
54 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
58 * put_control - write the control record to disk.
60 void put_control(void) {
62 if (control_fp != NULL) {
64 fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp);
71 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
73 long get_new_message_number(void) {
74 begin_critical_section(S_CONTROL);
76 ++CitControl.MMhighest;
78 end_critical_section(S_CONTROL);
79 return(CitControl.MMhighest);
84 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
86 long get_new_user_number(void) {
87 begin_critical_section(S_CONTROL);
89 ++CitControl.MMnextuser;
91 end_critical_section(S_CONTROL);
92 return(CitControl.MMnextuser);
98 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
100 long get_new_room_number(void) {
101 begin_critical_section(S_CONTROL);
103 ++CitControl.MMnextroom;
105 end_critical_section(S_CONTROL);
106 return(CitControl.MMnextroom);
112 * Get or set global configuration options
114 void cmd_conf(char *argbuf) {
119 if (!(CC->logged_in)) {
120 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
124 if (CC->usersupp.axlevel < 6) {
125 cprintf("%d Higher access required.\n",
126 ERROR+HIGHER_ACCESS_REQUIRED);
130 extract(cmd, argbuf, 0);
131 if (!strcasecmp(cmd, "GET")) {
132 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
133 cprintf("%s\n", config.c_nodename);
134 cprintf("%s\n", config.c_fqdn);
135 cprintf("%s\n", config.c_humannode);
136 cprintf("%s\n", config.c_phonenum);
137 cprintf("%d\n", config.c_creataide);
138 cprintf("%d\n", config.c_sleeping);
139 cprintf("%d\n", config.c_initax);
140 cprintf("%d\n", config.c_regiscall);
141 cprintf("%d\n", config.c_twitdetect);
142 cprintf("%s\n", config.c_twitroom);
143 cprintf("%s\n", config.c_moreprompt);
144 cprintf("%d\n", config.c_restrict);
145 cprintf("%s\n", config.c_bbs_city);
146 cprintf("%s\n", config.c_sysadm);
147 cprintf("%d\n", config.c_maxsessions);
148 cprintf("%s\n", config.c_net_password);
149 cprintf("%d\n", config.c_userpurge);
150 cprintf("%d\n", config.c_roompurge);
151 cprintf("%s\n", config.c_logpages);
152 cprintf("%d\n", config.c_createax);
156 else if (!strcasecmp(cmd, "SET")) {
157 cprintf("%d Send configuration...\n", SEND_LISTING);
159 while (client_gets(buf), strcmp(buf, "000")) {
161 case 0: strncpy(config.c_nodename, buf, 16);
163 case 1: strncpy(config.c_fqdn, buf, 64);
165 case 2: strncpy(config.c_humannode, buf, 21);
167 case 3: strncpy(config.c_phonenum, buf, 16);
169 case 4: config.c_creataide = atoi(buf);
171 case 5: config.c_sleeping = atoi(buf);
173 case 6: config.c_initax = atoi(buf);
174 if (config.c_initax < 1) config.c_initax = 1;
175 if (config.c_initax > 6) config.c_initax = 6;
177 case 7: config.c_regiscall = atoi(buf);
178 if (config.c_regiscall != 0)
179 config.c_regiscall = 1;
181 case 8: config.c_twitdetect = atoi(buf);
182 if (config.c_twitdetect != 0)
183 config.c_twitdetect = 1;
185 case 9: strncpy(config.c_twitroom,
188 case 10: strncpy(config.c_moreprompt, buf, 80);
190 case 11: config.c_restrict = atoi(buf);
191 if (config.c_restrict != 0)
192 config.c_restrict = 1;
194 case 12: strncpy(config.c_bbs_city, buf, 32);
196 case 13: strncpy(config.c_sysadm, buf, 26);
198 case 14: config.c_maxsessions = atoi(buf);
199 if (config.c_maxsessions < 1)
200 config.c_maxsessions = 1;
202 case 15: strncpy(config.c_net_password, buf, 20);
204 case 16: config.c_userpurge = atoi(buf);
206 case 17: config.c_roompurge = atoi(buf);
208 case 18: strncpy(config.c_logpages,
211 case 19: config.c_createax = atoi(buf);
212 if (config.c_createax < 1)
213 config.c_createax = 1;
214 if (config.c_createax > 6)
215 config.c_createax = 6;
221 snprintf(buf,sizeof buf,
222 "Global system configuration edited by %s",
226 if (strlen(config.c_logpages) > 0)
227 create_room(config.c_logpages, 4, "", 0);
231 cprintf("%d The only valid options are GET and SET.\n",
232 ERROR+ILLEGAL_VALUE);