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) {
52 control_fp = fopen("citadel.control", "wb+");
53 if (control_fp != NULL) {
54 memset(&CitControl, 0, sizeof(struct CitControl));
55 fwrite(&CitControl, sizeof(struct CitControl),
60 if (control_fp == NULL) {
61 lprintf(1, "ERROR opening citadel.control: %s\n",
67 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
71 * put_control - write the control record to disk.
73 void put_control(void) {
75 if (control_fp != NULL) {
77 fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp);
84 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
86 long get_new_message_number(void) {
87 begin_critical_section(S_CONTROL);
89 ++CitControl.MMhighest;
91 end_critical_section(S_CONTROL);
92 return(CitControl.MMhighest);
97 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
99 long get_new_user_number(void) {
100 begin_critical_section(S_CONTROL);
102 ++CitControl.MMnextuser;
104 end_critical_section(S_CONTROL);
105 return(CitControl.MMnextuser);
111 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
113 long get_new_room_number(void) {
114 begin_critical_section(S_CONTROL);
116 ++CitControl.MMnextroom;
118 end_critical_section(S_CONTROL);
119 return(CitControl.MMnextroom);
125 * Get or set global configuration options
127 void cmd_conf(char *argbuf) {
132 if (!(CC->logged_in)) {
133 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
137 if (CC->usersupp.axlevel < 6) {
138 cprintf("%d Higher access required.\n",
139 ERROR+HIGHER_ACCESS_REQUIRED);
143 extract(cmd, argbuf, 0);
144 if (!strcasecmp(cmd, "GET")) {
145 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
146 cprintf("%s\n", config.c_nodename);
147 cprintf("%s\n", config.c_fqdn);
148 cprintf("%s\n", config.c_humannode);
149 cprintf("%s\n", config.c_phonenum);
150 cprintf("%d\n", config.c_creataide);
151 cprintf("%d\n", config.c_sleeping);
152 cprintf("%d\n", config.c_initax);
153 cprintf("%d\n", config.c_regiscall);
154 cprintf("%d\n", config.c_twitdetect);
155 cprintf("%s\n", config.c_twitroom);
156 cprintf("%s\n", config.c_moreprompt);
157 cprintf("%d\n", config.c_restrict);
158 cprintf("%s\n", config.c_bbs_city);
159 cprintf("%s\n", config.c_sysadm);
160 cprintf("%d\n", config.c_maxsessions);
161 cprintf("%s\n", config.c_net_password);
162 cprintf("%d\n", config.c_userpurge);
163 cprintf("%d\n", config.c_roompurge);
164 cprintf("%s\n", config.c_logpages);
165 cprintf("%d\n", config.c_createax);
166 cprintf("%d\n", config.c_maxmsglen);
170 else if (!strcasecmp(cmd, "SET")) {
171 cprintf("%d Send configuration...\n", SEND_LISTING);
173 while (client_gets(buf), strcmp(buf, "000")) {
175 case 0: strncpy(config.c_nodename, buf, 16);
177 case 1: strncpy(config.c_fqdn, buf, 64);
179 case 2: strncpy(config.c_humannode, buf, 21);
181 case 3: strncpy(config.c_phonenum, buf, 16);
183 case 4: config.c_creataide = atoi(buf);
185 case 5: config.c_sleeping = atoi(buf);
187 case 6: config.c_initax = atoi(buf);
188 if (config.c_initax < 1) config.c_initax = 1;
189 if (config.c_initax > 6) config.c_initax = 6;
191 case 7: config.c_regiscall = atoi(buf);
192 if (config.c_regiscall != 0)
193 config.c_regiscall = 1;
195 case 8: config.c_twitdetect = atoi(buf);
196 if (config.c_twitdetect != 0)
197 config.c_twitdetect = 1;
199 case 9: strncpy(config.c_twitroom,
202 case 10: strncpy(config.c_moreprompt, buf, 80);
204 case 11: config.c_restrict = atoi(buf);
205 if (config.c_restrict != 0)
206 config.c_restrict = 1;
208 case 12: strncpy(config.c_bbs_city, buf, 32);
210 case 13: strncpy(config.c_sysadm, buf, 26);
212 case 14: config.c_maxsessions = atoi(buf);
213 if (config.c_maxsessions < 1)
214 config.c_maxsessions = 1;
216 case 15: strncpy(config.c_net_password, buf, 20);
218 case 16: config.c_userpurge = atoi(buf);
220 case 17: config.c_roompurge = atoi(buf);
222 case 18: strncpy(config.c_logpages,
225 case 19: config.c_createax = atoi(buf);
226 if (config.c_createax < 1)
227 config.c_createax = 1;
228 if (config.c_createax > 6)
229 config.c_createax = 6;
231 case 20: if (atoi(buf) >= 8192)
232 config.c_maxmsglen = atoi(buf);
238 snprintf(buf,sizeof buf,
239 "Global system configuration edited by %s",
243 if (strlen(config.c_logpages) > 0)
244 create_room(config.c_logpages, 4, "", 0);
248 cprintf("%d The only valid options are GET and SET.\n",
249 ERROR+ILLEGAL_VALUE);