1 // Server functions which perform operations on room objects.
3 // Copyright (c) 1987-2022 by the citadel.org team
5 // This program is open source software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License, version 3.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
16 #include <sys/types.h>
18 #include <dirent.h> /* for cmd_rdir to read contents of the directory */
19 #include <libcitadel.h>
21 #include "citserver.h"
22 #include "ctdl_module.h"
26 // Back-back-end for all room listing commands
27 void list_roomname(struct ctdlroom *qrbuf, int ra, int current_view, int default_view) {
28 char truncated_roomname[ROOMNAMELEN];
30 // For my own mailbox rooms, chop off the owner prefix
31 if ( (qrbuf->QRflags & QR_MAILBOX)
32 && (atol(qrbuf->QRname) == CC->user.usernum) ) {
33 safestrncpy(truncated_roomname, qrbuf->QRname, sizeof truncated_roomname);
34 safestrncpy(truncated_roomname, &truncated_roomname[11], sizeof truncated_roomname);
35 cprintf("%s", truncated_roomname);
37 // For all other rooms, just display the name in its entirety
39 cprintf("%s", qrbuf->QRname);
42 /* ...and now the other parameters */
43 cprintf("|%u|%d|%d|%d|%d|%d|%d|%ld|\n",
47 (int) qrbuf->QRflags2,
56 // cmd_lrms() - List all accessible rooms, known or forgotten
57 void cmd_lrms_backend(struct ctdlroom *qrbuf, void *data) {
58 int FloorBeingSearched = (-1);
62 FloorBeingSearched = *(int *)data;
63 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
65 if ((( ra & (UA_KNOWN | UA_ZAPPED)))
66 && ((qrbuf->QRfloor == (FloorBeingSearched))
67 || ((FloorBeingSearched) < 0)))
68 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
72 void cmd_lrms(char *argbuf) {
73 int FloorBeingSearched = (-1);
74 if (!IsEmptyStr(argbuf))
75 FloorBeingSearched = extract_int(argbuf, 0);
77 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
79 CtdlGetUser(&CC->user, CC->curr_user);
80 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
82 CtdlForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
87 // cmd_lkra() - List all known rooms
88 void cmd_lkra_backend(struct ctdlroom *qrbuf, void *data) {
89 int FloorBeingSearched = (-1);
93 FloorBeingSearched = *(int *)data;
94 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
96 if ((( ra & (UA_KNOWN))) && ((qrbuf->QRfloor == (FloorBeingSearched)) || ((FloorBeingSearched) < 0))) {
97 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
102 void cmd_lkra(char *argbuf) {
103 int FloorBeingSearched = (-1);
104 if (!IsEmptyStr(argbuf)) {
105 FloorBeingSearched = extract_int(argbuf, 0);
108 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
110 CtdlGetUser(&CC->user, CC->curr_user);
111 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
113 CtdlForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
118 void cmd_lprm_backend(struct ctdlroom *qrbuf, void *data) {
119 int FloorBeingSearched = (-1);
123 FloorBeingSearched = *(int *)data;
124 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
126 if (((qrbuf->QRflags & QR_PRIVATE) == 0) && ((qrbuf->QRflags & QR_MAILBOX) == 0) && ((qrbuf->QRfloor == (FloorBeingSearched)) || ((FloorBeingSearched) < 0))) {
127 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
132 void cmd_lprm(char *argbuf) {
133 int FloorBeingSearched = (-1);
134 if (!IsEmptyStr(argbuf)) {
135 FloorBeingSearched = extract_int(argbuf, 0);
138 cprintf("%d Public rooms:\n", LISTING_FOLLOWS);
140 CtdlForEachRoom(cmd_lprm_backend, &FloorBeingSearched);
145 // cmd_lkrn() - List all known rooms with new messages
146 void cmd_lkrn_backend(struct ctdlroom *qrbuf, void *data) {
147 int FloorBeingSearched = (-1);
151 FloorBeingSearched = *(int *)data;
152 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
154 if ((ra & UA_KNOWN) && (ra & UA_HASNEWMSGS) && ((qrbuf->QRfloor == (FloorBeingSearched)) || ((FloorBeingSearched) < 0))) {
155 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
160 void cmd_lkrn(char *argbuf) {
161 int FloorBeingSearched = (-1);
162 if (!IsEmptyStr(argbuf)) {
163 FloorBeingSearched = extract_int(argbuf, 0);
166 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
168 CtdlGetUser(&CC->user, CC->curr_user);
169 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
171 CtdlForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
176 // cmd_lkro() - List all known rooms
177 void cmd_lkro_backend(struct ctdlroom *qrbuf, void *data) {
178 int FloorBeingSearched = (-1);
182 FloorBeingSearched = *(int *)data;
183 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
185 if ((ra & UA_KNOWN) && ((ra & UA_HASNEWMSGS) == 0) && ((qrbuf->QRfloor == (FloorBeingSearched)) || ((FloorBeingSearched) < 0))) {
186 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
191 void cmd_lkro(char *argbuf) {
192 int FloorBeingSearched = (-1);
193 if (!IsEmptyStr(argbuf)) {
194 FloorBeingSearched = extract_int(argbuf, 0);
197 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
199 CtdlGetUser(&CC->user, CC->curr_user);
200 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
202 CtdlForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
207 // cmd_lzrm() - List all forgotten rooms
208 void cmd_lzrm_backend(struct ctdlroom *qrbuf, void *data) {
209 int FloorBeingSearched = (-1);
213 FloorBeingSearched = *(int *)data;
214 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
216 if ((ra & UA_GOTOALLOWED) && (ra & UA_ZAPPED) && ((qrbuf->QRfloor == (FloorBeingSearched)) || ((FloorBeingSearched) < 0))) {
217 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
222 void cmd_lzrm(char *argbuf) {
223 int FloorBeingSearched = (-1);
224 if (!IsEmptyStr(argbuf))
225 FloorBeingSearched = extract_int(argbuf, 0);
227 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
229 CtdlGetUser(&CC->user, CC->curr_user);
230 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
232 CtdlForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
237 // cmd_goto() - goto a new room
238 void cmd_goto(char *gargs) {
239 struct CitContext *CCC = CC;
240 struct ctdlroom QRscratch;
244 char augmented_roomname[ROOMNAMELEN];
245 char towhere[ROOMNAMELEN];
249 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
251 extract_token(towhere, gargs, 0, '|', sizeof towhere);
252 extract_token(password, gargs, 1, '|', sizeof password);
253 transiently = extract_int(gargs, 2);
255 CtdlGetUser(&CCC->user, CCC->curr_user);
257 // Handle some of the macro named rooms
258 convert_room_name_macros(towhere, sizeof towhere);
260 // First try a regular match
261 c = CtdlGetRoom(&QRscratch, towhere);
263 // Then try a mailbox name match
265 CtdlMailboxName(augmented_roomname, sizeof augmented_roomname, &CCC->user, towhere);
266 c = CtdlGetRoom(&QRscratch, augmented_roomname);
268 safestrncpy(towhere, augmented_roomname, sizeof towhere);
272 // And if the room was found...
274 // Let internal programs go directly to any room.
275 if (CCC->internal_pgm) {
276 memcpy(&CCC->room, &QRscratch, sizeof(struct ctdlroom));
277 CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
281 // See if there is an existing user/room relationship
282 CtdlRoomAccess(&QRscratch, &CCC->user, &ra, NULL);
284 // normal clients have to pass through security
285 if (ra & UA_GOTOALLOWED) {
290 if ((QRscratch.QRflags & QR_MAILBOX) &&
291 ((ra & UA_GOTOALLOWED))) {
292 memcpy(&CCC->room, &QRscratch, sizeof(struct ctdlroom));
293 CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
296 else if ((QRscratch.QRflags & QR_PASSWORDED) &&
297 ((ra & UA_KNOWN) == 0) &&
298 (strcasecmp(QRscratch.QRpasswd, password)) &&
299 (CCC->user.axlevel < AxAideU)
301 cprintf("%d wrong or missing passwd\n", ERROR + PASSWORD_REQUIRED);
304 else if ((QRscratch.QRflags & QR_PRIVATE) &&
305 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
306 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
307 ((ra & UA_KNOWN) == 0) &&
308 (CCC->user.axlevel < AxAideU)
310 syslog(LOG_DEBUG, "rooms: failed to acquire private room");
313 memcpy(&CCC->room, &QRscratch, sizeof(struct ctdlroom));
314 CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
320 cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
324 void cmd_whok(char *cmdbuf) {
325 struct ctdluser temp;
326 struct cdbdata *cdbus;
329 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
330 cdb_rewind(CDB_USERS);
331 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
332 memset(&temp, 0, sizeof temp);
333 memcpy(&temp, cdbus->ptr, sizeof temp);
336 CtdlRoomAccess(&CC->room, &temp, &ra, NULL);
337 if ((!IsEmptyStr(temp.fullname)) &&
338 (CC->room.QRflags & QR_INUSE) &&
341 cprintf("%s\n", temp.fullname);
347 // RDIR command for room directory
348 void cmd_rdir(char *cmdbuf) {
354 struct dirent *filedir_entry;
360 if (CtdlAccessCheck(ac_logged_in)) return;
362 CtdlGetRoom(&CC->room, CC->room.QRname);
363 CtdlGetUser(&CC->user, CC->curr_user);
365 if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
366 cprintf("%d not here.\n", ERROR + NOT_HERE);
369 if (((CC->room.QRflags & QR_VISDIR) == 0)
370 && (CC->user.axlevel < AxAideU)
371 && (CC->user.usernum != CC->room.QRroomaide))
373 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
377 snprintf(buf, sizeof buf, "%s/%s", ctdl_file_dir, CC->room.QRdirname);
378 filedir = opendir (buf);
380 if (filedir == NULL) {
381 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
384 cprintf("%d %s|%s/%s\n", LISTING_FOLLOWS, CtdlGetConfigStr("c_fqdn"), ctdl_file_dir, CC->room.QRdirname);
386 snprintf(buf, sizeof buf, "%s/%s/filedir", ctdl_file_dir, CC->room.QRdirname);
387 fd = fopen(buf, "r");
389 fd = fopen("/dev/null", "r");
391 while ((filedir_entry = readdir(filedir))) {
392 if (strcasecmp(filedir_entry->d_name, "filedir") && filedir_entry->d_name[0] != '.') {
393 #ifdef _DIRENT_HAVE_D_NAMELEN
394 d_namelen = filedir_entry->d_namlen;
396 d_namelen = strlen(filedir_entry->d_name);
398 snprintf(buf, sizeof buf, "%s/%s/%s", ctdl_file_dir, CC->room.QRdirname, filedir_entry->d_name);
399 stat(buf, &statbuf); /* stat the file */
400 if (!(statbuf.st_mode & S_IFREG)) {
401 snprintf(buf2, sizeof buf2,
402 "\"%s\" appears in the file directory for room \"%s\" but is not a regular file. Directories, named pipes, sockets, etc. are not usable in Citadel room directories.\n",
405 CtdlAideMessage(buf2, "Unusable data found in room directory");
406 continue; /* not a useable file type so don't show it */
408 safestrncpy(comment, "", sizeof comment);
409 fseek(fd, 0L, 0); /* rewind descriptions file */
410 /* Get the description from the descriptions file */
411 while ((fgets(buf, sizeof buf, fd) != NULL) && (IsEmptyStr(comment))) {
412 buf[strlen(buf) - 1] = 0;
413 if ((!strncasecmp(buf, filedir_entry->d_name, d_namelen)) && (buf[d_namelen] == ' '))
414 safestrncpy(comment, &buf[d_namelen + 1], sizeof comment);
416 len = extract_token (mimebuf, comment, 0,' ', 64);
417 if ((len <0) || strchr(mimebuf, '/') == NULL) {
418 snprintf (mimebuf, 64, "application/octetstream");
421 cprintf("%s|%ld|%s|%s\n",
422 filedir_entry->d_name,
423 (long)statbuf.st_size,
435 // get room parameters (admin or room admin command)
436 void cmd_getr(char *cmdbuf) {
437 if (CtdlAccessCheck(ac_room_aide)) return;
439 CtdlGetRoom(&CC->room, CC->room.QRname);
440 cprintf("%d%c%s|%s|%s|%d|%d|%d|%d|%d|\n",
443 ((CC->room.QRflags & QR_MAILBOX) ? &CC->room.QRname[11] : CC->room.QRname),
444 ((CC->room.QRflags & QR_PASSWORDED) ? CC->room.QRpasswd : ""),
445 ((CC->room.QRflags & QR_DIRECTORY) ? CC->room.QRdirname : ""),
447 (int) CC->room.QRfloor,
448 (int) CC->room.QRorder,
449 CC->room.QRdefaultview,
455 // set room parameters (admin or room admin command)
456 void cmd_setr(char *args) {
461 char new_name[ROOMNAMELEN];
463 if (CtdlAccessCheck(ac_logged_in)) return;
465 if (num_parms(args) >= 6) {
466 new_floor = extract_int(args, 5);
469 new_floor = (-1); /* don't change the floor */
472 /* When is a new name more than just a new name? When the old name
473 * has a namespace prefix.
475 if (CC->room.QRflags & QR_MAILBOX) {
476 sprintf(new_name, "%010ld.", atol(CC->room.QRname) );
479 safestrncpy(new_name, "", sizeof new_name);
481 extract_token(&new_name[strlen(new_name)], args, 0, '|', (sizeof new_name - strlen(new_name)));
483 r = CtdlRenameRoom(CC->room.QRname, new_name, new_floor);
485 if (r == crr_room_not_found) {
486 cprintf("%d Internal error - room not found?\n", ERROR + INTERNAL_ERROR);
488 else if (r == crr_already_exists) {
489 cprintf("%d '%s' already exists.\n",
490 ERROR + ALREADY_EXISTS, new_name);
492 else if (r == crr_noneditable) {
493 cprintf("%d Cannot edit this room.\n", ERROR + NOT_HERE);
495 else if (r == crr_invalid_floor) {
496 cprintf("%d Target floor does not exist.\n",
497 ERROR + INVALID_FLOOR_OPERATION);
499 else if (r == crr_access_denied) {
500 cprintf("%d You do not have permission to edit '%s'\n",
501 ERROR + HIGHER_ACCESS_REQUIRED,
504 else if (r != crr_ok) {
505 cprintf("%d Error: CtdlRenameRoom() returned %d\n",
506 ERROR + INTERNAL_ERROR, r);
513 CtdlGetRoom(&CC->room, new_name);
515 /* Now we have to do a bunch of other stuff */
517 if (num_parms(args) >= 7) {
518 new_order = extract_int(args, 6);
525 CtdlGetRoomLock(&CC->room, CC->room.QRname);
528 extract_token(buf, args, 2, '|', sizeof buf);
530 safestrncpy(CC->room.QRdirname, buf,
531 sizeof CC->room.QRdirname);
534 if (num_parms(args) >= 8) {
535 CC->room.QRdefaultview = extract_int(args, 7);
538 /* Second set of flags */
539 if (num_parms(args) >= 9) {
540 CC->room.QRflags2 = extract_int(args, 8);
544 CC->room.QRflags = (extract_int(args, 3) | QR_INUSE);
545 /* Clean up a client boo-boo: if the client set the room to
546 * guess-name or passworded, ensure that the private flag is
549 if ((CC->room.QRflags & QR_GUESSNAME)
550 || (CC->room.QRflags & QR_PASSWORDED))
551 CC->room.QRflags |= QR_PRIVATE;
553 /* Some changes can't apply to BASEROOM */
554 if (!strncasecmp(CC->room.QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)) {
555 CC->room.QRorder = 0;
556 CC->room.QRpasswd[0] = '\0';
557 CC->room.QRflags &= ~(QR_PRIVATE & QR_PASSWORDED &
558 QR_GUESSNAME & QR_PREFONLY & QR_MAILBOX);
559 CC->room.QRflags |= QR_PERMANENT;
562 /* March order (doesn't apply to AIDEROOM) */
563 if (num_parms(args) >= 7)
564 CC->room.QRorder = (char) new_order;
566 extract_token(buf, args, 1, '|', sizeof buf);
568 safestrncpy(CC->room.QRpasswd, buf, sizeof CC->room.QRpasswd);
569 /* Kick everyone out if the client requested it
570 * (by changing the room's generation number)
572 if (extract_int(args, 4)) {
573 time(&CC->room.QRgen);
576 /* Some changes can't apply to AIDEROOM */
577 if (!strncasecmp(CC->room.QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)) {
578 CC->room.QRorder = 0;
579 CC->room.QRflags &= ~QR_MAILBOX;
580 CC->room.QRflags |= QR_PERMANENT;
583 /* Write the room record back to disk */
584 CtdlPutRoomLock(&CC->room);
586 /* Create a room directory if necessary */
587 if (CC->room.QRflags & QR_DIRECTORY) {
588 snprintf(buf, sizeof buf,"%s/%s", ctdl_file_dir, CC->room.QRdirname);
591 snprintf(buf, sizeof buf, "The room \"%s\" has been edited by %s.\n",
593 (CC->logged_in ? CC->curr_user : "an administrator")
595 CtdlAideMessage(buf, "Room modification Message");
596 cprintf("%d Ok\n", CIT_OK);
600 // get the name of the room admin for this room
601 void cmd_geta(char *cmdbuf) {
602 struct ctdluser usbuf;
604 if (CtdlAccessCheck(ac_logged_in)) return;
606 if (CtdlGetUserByNumber(&usbuf, CC->room.QRroomaide) == 0) {
607 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
610 cprintf("%d \n", CIT_OK);
615 // set the room admin for this room
616 void cmd_seta(char *new_ra) {
617 struct ctdluser usbuf;
622 if (CtdlAccessCheck(ac_room_aide)) return;
624 if (CtdlGetUser(&usbuf, new_ra) != 0) {
628 newu = usbuf.usernum;
631 CtdlGetRoomLock(&CC->room, CC->room.QRname);
633 if (CC->room.QRroomaide != newu) {
636 CC->room.QRroomaide = newu;
637 CtdlPutRoomLock(&CC->room);
639 // We have to post the change notice _after_ writing changes to
640 // the room table, otherwise it would deadlock!
641 if (post_notice == 1) {
642 if (!IsEmptyStr(usbuf.fullname))
643 snprintf(buf, sizeof buf,
644 "%s is now the room admin for \"%s\".\n",
645 usbuf.fullname, CC->room.QRname);
647 snprintf(buf, sizeof buf,
648 "There is now no room admin for \"%s\".\n",
650 CtdlAideMessage(buf, "Admin Room Modification");
652 cprintf("%d Ok\n", CIT_OK);
656 // Retrieve info file for this room (this ought to be upgraded to handle non-plain-text)
657 void cmd_rinf(char *argbuf) {
658 struct CtdlMessage *msg = CtdlFetchMessage(CC->room.msgnum_info, 1);
660 cprintf("%d Info:\n", LISTING_FOLLOWS);
661 CtdlOutputPreLoadedMsg(msg, MT_CITADEL, HEADERS_NONE, 0, 0, 0);
666 cprintf("%d No info file.\n", ERROR + FILE_NOT_FOUND);
671 // admin command: kill the current room
672 void cmd_kill(char *argbuf) {
673 char deleted_room_name[ROOMNAMELEN];
677 kill_ok = extract_int(argbuf, 0);
679 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->room) == 0) {
680 cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
684 if (CC->room.QRflags & QR_MAILBOX) {
685 safestrncpy(deleted_room_name, &CC->room.QRname[11], sizeof deleted_room_name);
688 safestrncpy(deleted_room_name, CC->room.QRname, sizeof deleted_room_name);
691 /* Do the dirty work */
692 CtdlScheduleRoomForDeletion(&CC->room);
694 /* Return to the Lobby */
695 CtdlUserGoto(CtdlGetConfigStr("c_baseroom"), 0, 0, NULL, NULL, NULL, NULL);
697 /* tell the world what we did */
698 snprintf(msg, sizeof msg, "The room \"%s\" has been deleted by %s.\n",
700 (CC->logged_in ? CC->curr_user : "an administrator")
702 CtdlAideMessage(msg, "Room Purger Message");
703 cprintf("%d '%s' deleted.\n", CIT_OK, deleted_room_name);
706 cprintf("%d ok to delete.\n", CIT_OK);
712 void cmd_cre8(char *args) {
714 char new_room_name[ROOMNAMELEN];
716 char new_room_pass[32];
719 char *notification_message = NULL;
722 int avoid_access = 0;
724 cre8_ok = extract_int(args, 0);
725 extract_token(new_room_name, args, 1, '|', sizeof new_room_name);
726 new_room_name[ROOMNAMELEN - 1] = 0;
727 new_room_type = extract_int(args, 2);
728 extract_token(new_room_pass, args, 3, '|', sizeof new_room_pass);
729 avoid_access = extract_int(args, 5);
730 new_room_view = extract_int(args, 6);
731 new_room_pass[9] = 0;
734 if ((IsEmptyStr(new_room_name)) && (cre8_ok == 1)) {
735 cprintf("%d Invalid room name.\n", ERROR + ILLEGAL_VALUE);
739 if (!strcasecmp(new_room_name, MAILROOM)) {
740 cprintf("%d '%s' already exists.\n",
741 ERROR + ALREADY_EXISTS, new_room_name);
745 if (num_parms(args) >= 5) {
746 fl = CtdlGetCachedFloor(extract_int(args, 4));
748 cprintf("%d Invalid floor number.\n",
749 ERROR + INVALID_FLOOR_OPERATION);
752 else if ((fl->f_flags & F_INUSE) == 0) {
753 cprintf("%d Invalid floor number.\n",
754 ERROR + INVALID_FLOOR_OPERATION);
757 new_room_floor = extract_int(args, 4);
761 if (CtdlAccessCheck(ac_logged_in)) return;
763 if (CC->user.axlevel < CtdlGetConfigInt("c_createax") && !CC->internal_pgm) {
764 cprintf("%d You need higher access to create rooms.\n",
765 ERROR + HIGHER_ACCESS_REQUIRED);
769 if ((IsEmptyStr(new_room_name)) && (cre8_ok == 0)) {
770 cprintf("%d Ok to create rooms.\n", CIT_OK);
774 if ((new_room_type < 0) || (new_room_type > 5)) {
775 cprintf("%d Invalid room type.\n", ERROR + ILLEGAL_VALUE);
779 if (new_room_type == 5) {
780 if (CC->user.axlevel < AxAideU) {
781 cprintf("%d Higher access required\n",
782 ERROR + HIGHER_ACCESS_REQUIRED);
787 /* Check to make sure the requested room name doesn't already exist */
788 newflags = CtdlCreateRoom(new_room_name,
789 new_room_type, new_room_pass, new_room_floor,
790 0, avoid_access, new_room_view);
792 cprintf("%d '%s' already exists.\n",
793 ERROR + ALREADY_EXISTS, new_room_name);
798 cprintf("%d OK to create '%s'\n", CIT_OK, new_room_name);
802 /* If we reach this point, the room needs to be created. */
804 newflags = CtdlCreateRoom(new_room_name,
805 new_room_type, new_room_pass, new_room_floor, 1, 0,
808 /* post a message in Aide> describing the new room */
809 notification_message = malloc(1024);
810 snprintf(notification_message, 1024,
811 "A new room called \"%s\" has been created by %s%s%s%s%s%s\n",
813 (CC->logged_in ? CC->curr_user : "an administrator"),
814 ((newflags & QR_MAILBOX) ? " [personal]" : ""),
815 ((newflags & QR_PRIVATE) ? " [private]" : ""),
816 ((newflags & QR_GUESSNAME) ? " [hidden]" : ""),
817 ((newflags & QR_PASSWORDED) ? " Password: " : ""),
818 ((newflags & QR_PASSWORDED) ? new_room_pass : "")
820 CtdlAideMessage(notification_message, "Room Creation Message");
821 free(notification_message);
823 cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
827 // Upload the room banner text for this room.
828 // This should be amended to handle content types other than plain text.
829 void cmd_einf(char *ok) { /* enter info file for current room */
833 if (CtdlAccessCheck(ac_room_aide)) return;
836 cprintf("%d Ok.\n", CIT_OK);
840 StrBuf *NewBanner = NewStrBufPlain("Content-type: text/plain; charset=UTF-8\nContent-transfer-encoding: 8bit\n\n", -1);
842 cprintf("%d Transmit new banner in plain text now.\n", SEND_LISTING);
843 while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
844 StrBufAppendBufPlain(NewBanner, buf, -1, 0);
845 StrBufAppendBufPlain(NewBanner, HKEY("\n"), 0);
848 // We have read the new banner from the user , now save it
849 long new_msgnum = quickie_message("Citadel", NULL, NULL, SYSCONFIGROOM, ChrPtr(NewBanner), FMT_RFC822, "Banner submitted with EINF command");
850 FreeStrBuf(&NewBanner);
852 // Update the room record with a pointer to our new banner
853 CtdlGetRoomLock(&CC->room, CC->room.QRname);
854 long old_msgnum = CC->room.msgnum_info;
855 CC->room.msgnum_info = new_msgnum;
856 CtdlPutRoomLock(&CC->room);
858 // Delete the old one
859 CtdlDeleteMessages(SYSCONFIGROOM, &old_msgnum, 1, "");
863 // cmd_lflr() - List all known floors
864 void cmd_lflr(char *gargs) {
868 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
870 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
872 for (a = 0; a < MAXFLOORS; ++a) {
873 CtdlGetFloor(&flbuf, a);
874 if (flbuf.f_flags & F_INUSE) {
875 cprintf("%d|%s|%d\n", a, flbuf.f_name, flbuf.f_ref_count);
882 // create a new floor
883 void cmd_cflr(char *argbuf) {
884 char new_floor_name[256];
887 int free_slot = (-1);
890 extract_token(new_floor_name, argbuf, 0, '|', sizeof new_floor_name);
891 cflr_ok = extract_int(argbuf, 1);
893 if (CtdlAccessCheck(ac_aide)) return;
895 if (IsEmptyStr(new_floor_name)) {
896 cprintf("%d Blank floor name not allowed.\n",
897 ERROR + ILLEGAL_VALUE);
901 for (a = 0; a < MAXFLOORS; ++a) {
902 CtdlGetFloor(&flbuf, a);
904 /* note any free slots while we're scanning... */
905 if (((flbuf.f_flags & F_INUSE) == 0)
909 /* check to see if it already exists */
910 if ((!strcasecmp(flbuf.f_name, new_floor_name))
911 && (flbuf.f_flags & F_INUSE)) {
912 cprintf("%d Floor '%s' already exists.\n",
913 ERROR + ALREADY_EXISTS,
920 cprintf("%d There is no space available for a new floor.\n",
921 ERROR + INVALID_FLOOR_OPERATION);
925 cprintf("%d ok to create...\n", CIT_OK);
928 lgetfloor(&flbuf, free_slot);
929 flbuf.f_flags = F_INUSE;
930 flbuf.f_ref_count = 0;
931 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
932 lputfloor(&flbuf, free_slot);
933 cprintf("%d %d\n", CIT_OK, free_slot);
938 void cmd_kflr(char *argbuf) {
944 floor_to_delete = extract_int(argbuf, 0);
945 kflr_ok = extract_int(argbuf, 1);
947 if (CtdlAccessCheck(ac_aide)) return;
949 lgetfloor(&flbuf, floor_to_delete);
952 if ((flbuf.f_flags & F_INUSE) == 0) {
953 cprintf("%d Floor %d not in use.\n", ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
956 if (flbuf.f_ref_count != 0) {
957 cprintf("%d Cannot delete; floor contains %d rooms.\n",
958 ERROR + INVALID_FLOOR_OPERATION,
964 cprintf("%d Ok\n", CIT_OK);
967 cprintf("%d Ok to delete...\n", CIT_OK);
974 if ((delete_ok == 1) && (kflr_ok == 1)) {
977 lputfloor(&flbuf, floor_to_delete);
982 void cmd_eflr(char *argbuf) {
987 np = num_parms(argbuf);
989 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
993 if (CtdlAccessCheck(ac_aide)) return;
995 floor_num = extract_int(argbuf, 0);
996 lgetfloor(&flbuf, floor_num);
997 if ((flbuf.f_flags & F_INUSE) == 0) {
998 lputfloor(&flbuf, floor_num);
999 cprintf("%d Floor %d is not in use.\n", ERROR + INVALID_FLOOR_OPERATION, floor_num);
1003 extract_token(flbuf.f_name, argbuf, 1, '|', sizeof flbuf.f_name);
1005 lputfloor(&flbuf, floor_num);
1007 cprintf("%d Ok\n", CIT_OK);
1011 // cmd_stat() - return the modification time of the current room (maybe other things in the future)
1012 void cmd_stat(char *gargs) {
1013 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
1014 CtdlGetRoom(&CC->room, CC->room.QRname);
1015 cprintf("%d %s|%ld|\n", CIT_OK, CC->room.QRname, CC->room.QRmtime);
1019 /*****************************************************************************/
1020 /* MODULE INITIALIZATION STUFF */
1021 /*****************************************************************************/
1023 CTDL_MODULE_INIT(rooms)
1026 CtdlRegisterProtoHook(cmd_lrms, "LRMS", "List rooms");
1027 CtdlRegisterProtoHook(cmd_lkra, "LKRA", "List all known rooms");
1028 CtdlRegisterProtoHook(cmd_lkrn, "LKRN", "List known rooms with new messages");
1029 CtdlRegisterProtoHook(cmd_lkro, "LKRO", "List known rooms without new messages");
1030 CtdlRegisterProtoHook(cmd_lzrm, "LZRM", "List zapped rooms");
1031 CtdlRegisterProtoHook(cmd_lprm, "LPRM", "List public rooms");
1032 CtdlRegisterProtoHook(cmd_goto, "GOTO", "Goto a named room");
1033 CtdlRegisterProtoHook(cmd_stat, "STAT", "Get mtime of the current room");
1034 CtdlRegisterProtoHook(cmd_whok, "WHOK", "List users who know this room");
1035 CtdlRegisterProtoHook(cmd_rdir, "RDIR", "List files in room directory");
1036 CtdlRegisterProtoHook(cmd_getr, "GETR", "Get room parameters");
1037 CtdlRegisterProtoHook(cmd_setr, "SETR", "Set room parameters");
1038 CtdlRegisterProtoHook(cmd_geta, "GETA", "Get the room admin name");
1039 CtdlRegisterProtoHook(cmd_seta, "SETA", "Set the room admin for this room");
1040 CtdlRegisterProtoHook(cmd_rinf, "RINF", "Fetch room info file");
1041 CtdlRegisterProtoHook(cmd_kill, "KILL", "Kill (delete) the current room");
1042 CtdlRegisterProtoHook(cmd_cre8, "CRE8", "Create a new room");
1043 CtdlRegisterProtoHook(cmd_einf, "EINF", "Enter info file for the current room");
1044 CtdlRegisterProtoHook(cmd_lflr, "LFLR", "List all known floors");
1045 CtdlRegisterProtoHook(cmd_cflr, "CFLR", "Create a new floor");
1046 CtdlRegisterProtoHook(cmd_kflr, "KFLR", "Kill a floor");
1047 CtdlRegisterProtoHook(cmd_eflr, "EFLR", "Edit a floor");
1049 /* return our Subversion id for the Log */