4 * This module handles states which are global to the entire server.
28 #include "sysdep_decls.h"
35 struct CitControl CitControl;
39 * get_control - read the control record into memory.
41 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 fp = fopen("citadel.control", "rb");
50 if (fp == NULL) return;
52 fread(&CitControl, sizeof(struct CitControl), 1, fp);
57 * put_control - write the control record to disk.
59 void put_control(void) {
62 fp = fopen("citadel.control", "wb");
64 fwrite(&CitControl, sizeof(struct CitControl), 1, 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);
155 else if (!strcasecmp(cmd, "SET")) {
156 cprintf("%d Send configuration...\n", SEND_LISTING);
158 while (client_gets(buf), strcmp(buf, "000")) {
160 case 0: strncpy(config.c_nodename, buf, 16);
162 case 1: strncpy(config.c_fqdn, buf, 64);
164 case 2: strncpy(config.c_humannode, buf, 21);
166 case 3: strncpy(config.c_phonenum, buf, 16);
168 case 4: config.c_creataide = atoi(buf);
170 case 5: config.c_sleeping = atoi(buf);
172 case 6: config.c_initax = atoi(buf);
173 if (config.c_initax < 1) config.c_initax = 1;
174 if (config.c_initax > 6) config.c_initax = 6;
176 case 7: config.c_regiscall = atoi(buf);
177 if (config.c_regiscall != 0)
178 config.c_regiscall = 1;
180 case 8: config.c_twitdetect = atoi(buf);
181 if (config.c_twitdetect != 0)
182 config.c_twitdetect = 1;
184 case 9: strncpy(config.c_twitroom,
187 case 10: strncpy(config.c_moreprompt, buf, 80);
189 case 11: config.c_restrict = atoi(buf);
190 if (config.c_restrict != 0)
191 config.c_restrict = 1;
193 case 12: strncpy(config.c_bbs_city, buf, 32);
195 case 13: strncpy(config.c_sysadm, buf, 26);
197 case 14: config.c_maxsessions = atoi(buf);
198 if (config.c_maxsessions < 1)
199 config.c_maxsessions = 1;
201 case 15: strncpy(config.c_net_password, buf, 20);
203 case 16: config.c_userpurge = atoi(buf);
205 case 17: config.c_roompurge = atoi(buf);
207 case 18: strncpy(config.c_logpages,
214 snprintf(buf,sizeof buf,
215 "Global system configuration edited by %s",
219 if (strlen(config.c_logpages) > 0)
220 create_room(config.c_logpages, 4, "", 0);
224 cprintf("%d The only valid options are GET and SET.\n",
225 ERROR+ILLEGAL_VALUE);