2 * Server functions which perform operations on room objects.
4 * Copyright (c) 1987-2020 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
18 #include <sys/types.h>
20 #include <dirent.h> /* for cmd_rdir to read contents of the directory */
21 #include <libcitadel.h>
23 #include "citserver.h"
24 #include "ctdl_module.h"
29 * Back-back-end for all room listing commands
31 void list_roomname(struct ctdlroom *qrbuf, int ra, int current_view, int default_view)
33 char truncated_roomname[ROOMNAMELEN];
35 /* For my own mailbox rooms, chop off the owner prefix */
36 if ( (qrbuf->QRflags & QR_MAILBOX)
37 && (atol(qrbuf->QRname) == CC->user.usernum) ) {
38 safestrncpy(truncated_roomname, qrbuf->QRname, sizeof truncated_roomname);
39 safestrncpy(truncated_roomname, &truncated_roomname[11], sizeof truncated_roomname);
40 cprintf("%s", truncated_roomname);
42 /* For all other rooms, just display the name in its entirety */
44 cprintf("%s", qrbuf->QRname);
47 /* ...and now the other parameters */
48 cprintf("|%u|%d|%d|%d|%d|%d|%d|%ld|\n",
52 (int) qrbuf->QRflags2,
62 * cmd_lrms() - List all accessible rooms, known or forgotten
64 void cmd_lrms_backend(struct ctdlroom *qrbuf, void *data)
66 int FloorBeingSearched = (-1);
70 FloorBeingSearched = *(int *)data;
71 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
73 if ((( ra & (UA_KNOWN | UA_ZAPPED)))
74 && ((qrbuf->QRfloor == (FloorBeingSearched))
75 || ((FloorBeingSearched) < 0)))
76 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
79 void cmd_lrms(char *argbuf)
81 int FloorBeingSearched = (-1);
82 if (!IsEmptyStr(argbuf))
83 FloorBeingSearched = extract_int(argbuf, 0);
85 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
87 CtdlGetUser(&CC->user, CC->curr_user);
88 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
90 CtdlForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
97 * cmd_lkra() - List all known rooms
99 void cmd_lkra_backend(struct ctdlroom *qrbuf, void *data)
101 int FloorBeingSearched = (-1);
105 FloorBeingSearched = *(int *)data;
106 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
108 if ((( ra & (UA_KNOWN)))
109 && ((qrbuf->QRfloor == (FloorBeingSearched))
110 || ((FloorBeingSearched) < 0)))
111 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
114 void cmd_lkra(char *argbuf)
116 int FloorBeingSearched = (-1);
117 if (!IsEmptyStr(argbuf))
118 FloorBeingSearched = extract_int(argbuf, 0);
120 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
122 CtdlGetUser(&CC->user, CC->curr_user);
123 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
125 CtdlForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
131 void cmd_lprm_backend(struct ctdlroom *qrbuf, void *data)
133 int FloorBeingSearched = (-1);
137 FloorBeingSearched = *(int *)data;
138 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
140 if ( ((qrbuf->QRflags & QR_PRIVATE) == 0)
141 && ((qrbuf->QRflags & QR_MAILBOX) == 0)
142 && ((qrbuf->QRfloor == (FloorBeingSearched))
143 || ((FloorBeingSearched) < 0)))
144 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
147 void cmd_lprm(char *argbuf)
149 int FloorBeingSearched = (-1);
150 if (!IsEmptyStr(argbuf))
151 FloorBeingSearched = extract_int(argbuf, 0);
153 cprintf("%d Public rooms:\n", LISTING_FOLLOWS);
155 CtdlForEachRoom(cmd_lprm_backend, &FloorBeingSearched);
162 * cmd_lkrn() - List all known rooms with new messages
164 void cmd_lkrn_backend(struct ctdlroom *qrbuf, void *data)
166 int FloorBeingSearched = (-1);
170 FloorBeingSearched = *(int *)data;
171 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
174 && (ra & UA_HASNEWMSGS)
175 && ((qrbuf->QRfloor == (FloorBeingSearched))
176 || ((FloorBeingSearched) < 0)))
177 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
180 void cmd_lkrn(char *argbuf)
182 int FloorBeingSearched = (-1);
183 if (!IsEmptyStr(argbuf))
184 FloorBeingSearched = extract_int(argbuf, 0);
186 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
188 CtdlGetUser(&CC->user, CC->curr_user);
189 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
191 CtdlForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
198 * cmd_lkro() - List all known rooms
200 void cmd_lkro_backend(struct ctdlroom *qrbuf, void *data)
202 int FloorBeingSearched = (-1);
206 FloorBeingSearched = *(int *)data;
207 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
210 && ((ra & UA_HASNEWMSGS) == 0)
211 && ((qrbuf->QRfloor == (FloorBeingSearched))
212 || ((FloorBeingSearched) < 0)))
213 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
216 void cmd_lkro(char *argbuf)
218 int FloorBeingSearched = (-1);
219 if (!IsEmptyStr(argbuf))
220 FloorBeingSearched = extract_int(argbuf, 0);
222 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
224 CtdlGetUser(&CC->user, CC->curr_user);
225 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
227 CtdlForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
234 * cmd_lzrm() - List all forgotten rooms
236 void cmd_lzrm_backend(struct ctdlroom *qrbuf, void *data)
238 int FloorBeingSearched = (-1);
242 FloorBeingSearched = *(int *)data;
243 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
245 if ((ra & UA_GOTOALLOWED)
247 && ((qrbuf->QRfloor == (FloorBeingSearched))
248 || ((FloorBeingSearched) < 0)))
249 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
252 void cmd_lzrm(char *argbuf)
254 int FloorBeingSearched = (-1);
255 if (!IsEmptyStr(argbuf))
256 FloorBeingSearched = extract_int(argbuf, 0);
258 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
260 CtdlGetUser(&CC->user, CC->curr_user);
261 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
263 CtdlForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
269 * cmd_goto() - goto a new room
271 void cmd_goto(char *gargs)
273 struct CitContext *CCC = CC;
274 struct ctdlroom QRscratch;
278 char augmented_roomname[ROOMNAMELEN];
279 char towhere[ROOMNAMELEN];
283 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
285 extract_token(towhere, gargs, 0, '|', sizeof towhere);
286 extract_token(password, gargs, 1, '|', sizeof password);
287 transiently = extract_int(gargs, 2);
289 CtdlGetUser(&CCC->user, CCC->curr_user);
292 * Handle some of the macro named rooms
294 convert_room_name_macros(towhere, sizeof towhere);
296 /* First try a regular match */
297 c = CtdlGetRoom(&QRscratch, towhere);
299 /* Then try a mailbox name match */
301 CtdlMailboxName(augmented_roomname, sizeof augmented_roomname,
302 &CCC->user, towhere);
303 c = CtdlGetRoom(&QRscratch, augmented_roomname);
305 safestrncpy(towhere, augmented_roomname, sizeof towhere);
308 /* And if the room was found... */
311 /* Let internal programs go directly to any room. */
312 if (CCC->internal_pgm) {
313 memcpy(&CCC->room, &QRscratch,
314 sizeof(struct ctdlroom));
315 CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
319 /* See if there is an existing user/room relationship */
320 CtdlRoomAccess(&QRscratch, &CCC->user, &ra, NULL);
322 /* normal clients have to pass through security */
323 if (ra & UA_GOTOALLOWED) {
328 if ((QRscratch.QRflags & QR_MAILBOX) &&
329 ((ra & UA_GOTOALLOWED))) {
330 memcpy(&CCC->room, &QRscratch,
331 sizeof(struct ctdlroom));
332 CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
334 } else if ((QRscratch.QRflags & QR_PASSWORDED) &&
335 ((ra & UA_KNOWN) == 0) &&
336 (strcasecmp(QRscratch.QRpasswd, password)) &&
337 (CCC->user.axlevel < AxAideU)
339 cprintf("%d wrong or missing passwd\n",
340 ERROR + PASSWORD_REQUIRED);
342 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
343 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
344 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
345 ((ra & UA_KNOWN) == 0) &&
346 (CCC->user.axlevel < AxAideU)
348 syslog(LOG_DEBUG, "rooms: failed to acquire private room");
350 memcpy(&CCC->room, &QRscratch,
351 sizeof(struct ctdlroom));
352 CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
358 cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
362 void cmd_whok(char *cmdbuf)
364 struct ctdluser temp;
365 struct cdbdata *cdbus;
368 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
369 cdb_rewind(CDB_USERS);
370 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
371 memset(&temp, 0, sizeof temp);
372 memcpy(&temp, cdbus->ptr, sizeof temp);
375 CtdlRoomAccess(&CC->room, &temp, &ra, NULL);
376 if ((!IsEmptyStr(temp.fullname)) &&
377 (CC->room.QRflags & QR_INUSE) &&
380 cprintf("%s\n", temp.fullname);
387 * RDIR command for room directory
389 void cmd_rdir(char *cmdbuf)
396 struct dirent *filedir_entry;
402 if (CtdlAccessCheck(ac_logged_in)) return;
404 CtdlGetRoom(&CC->room, CC->room.QRname);
405 CtdlGetUser(&CC->user, CC->curr_user);
407 if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
408 cprintf("%d not here.\n", ERROR + NOT_HERE);
411 if (((CC->room.QRflags & QR_VISDIR) == 0)
412 && (CC->user.axlevel < AxAideU)
413 && (CC->user.usernum != CC->room.QRroomaide)) {
414 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
418 snprintf(buf, sizeof buf, "%s/%s", ctdl_file_dir, CC->room.QRdirname);
419 filedir = opendir (buf);
421 if (filedir == NULL) {
422 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
425 cprintf("%d %s|%s/%s\n", LISTING_FOLLOWS, CtdlGetConfigStr("c_fqdn"), ctdl_file_dir, CC->room.QRdirname);
427 snprintf(buf, sizeof buf, "%s/%s/filedir", ctdl_file_dir, CC->room.QRdirname);
428 fd = fopen(buf, "r");
430 fd = fopen("/dev/null", "r");
431 while ((filedir_entry = readdir(filedir)))
433 if (strcasecmp(filedir_entry->d_name, "filedir") && filedir_entry->d_name[0] != '.')
435 #ifdef _DIRENT_HAVE_D_NAMELEN
436 d_namelen = filedir_entry->d_namlen;
438 d_namelen = strlen(filedir_entry->d_name);
440 snprintf(buf, sizeof buf, "%s/%s/%s", ctdl_file_dir, CC->room.QRdirname, filedir_entry->d_name);
441 stat(buf, &statbuf); /* stat the file */
442 if (!(statbuf.st_mode & S_IFREG))
444 snprintf(buf2, sizeof buf2,
445 "\"%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",
448 CtdlAideMessage(buf2, "Unusable data found in room directory");
449 continue; /* not a useable file type so don't show it */
451 safestrncpy(comment, "", sizeof comment);
452 fseek(fd, 0L, 0); /* rewind descriptions file */
453 /* Get the description from the descriptions file */
454 while ((fgets(buf, sizeof buf, fd) != NULL) && (IsEmptyStr(comment)))
456 buf[strlen(buf) - 1] = 0;
457 if ((!strncasecmp(buf, filedir_entry->d_name, d_namelen)) && (buf[d_namelen] == ' '))
458 safestrncpy(comment, &buf[d_namelen + 1], sizeof comment);
460 len = extract_token (mimebuf, comment, 0,' ', 64);
461 if ((len <0) || strchr(mimebuf, '/') == NULL)
463 snprintf (mimebuf, 64, "application/octetstream");
466 cprintf("%s|%ld|%s|%s\n",
467 filedir_entry->d_name,
468 (long)statbuf.st_size,
480 * get room parameters (admin or room admin command)
482 void cmd_getr(char *cmdbuf)
484 if (CtdlAccessCheck(ac_room_aide)) return;
486 CtdlGetRoom(&CC->room, CC->room.QRname);
487 cprintf("%d%c%s|%s|%s|%d|%d|%d|%d|%d|\n",
491 ((CC->room.QRflags & QR_MAILBOX) ?
492 &CC->room.QRname[11] : CC->room.QRname),
494 ((CC->room.QRflags & QR_PASSWORDED) ?
495 CC->room.QRpasswd : ""),
497 ((CC->room.QRflags & QR_DIRECTORY) ?
498 CC->room.QRdirname : ""),
501 (int) CC->room.QRfloor,
502 (int) CC->room.QRorder,
504 CC->room.QRdefaultview,
510 * set room parameters (admin or room admin command)
512 void cmd_setr(char *args)
518 char new_name[ROOMNAMELEN];
520 if (CtdlAccessCheck(ac_logged_in)) return;
522 if (num_parms(args) >= 6) {
523 new_floor = extract_int(args, 5);
525 new_floor = (-1); /* don't change the floor */
528 /* When is a new name more than just a new name? When the old name
529 * has a namespace prefix.
531 if (CC->room.QRflags & QR_MAILBOX) {
532 sprintf(new_name, "%010ld.", atol(CC->room.QRname) );
534 safestrncpy(new_name, "", sizeof new_name);
536 extract_token(&new_name[strlen(new_name)], args, 0, '|', (sizeof new_name - strlen(new_name)));
538 r = CtdlRenameRoom(CC->room.QRname, new_name, new_floor);
540 if (r == crr_room_not_found) {
541 cprintf("%d Internal error - room not found?\n", ERROR + INTERNAL_ERROR);
542 } else if (r == crr_already_exists) {
543 cprintf("%d '%s' already exists.\n",
544 ERROR + ALREADY_EXISTS, new_name);
545 } else if (r == crr_noneditable) {
546 cprintf("%d Cannot edit this room.\n", ERROR + NOT_HERE);
547 } else if (r == crr_invalid_floor) {
548 cprintf("%d Target floor does not exist.\n",
549 ERROR + INVALID_FLOOR_OPERATION);
550 } else if (r == crr_access_denied) {
551 cprintf("%d You do not have permission to edit '%s'\n",
552 ERROR + HIGHER_ACCESS_REQUIRED,
554 } else if (r != crr_ok) {
555 cprintf("%d Error: CtdlRenameRoom() returned %d\n",
556 ERROR + INTERNAL_ERROR, r);
563 CtdlGetRoom(&CC->room, new_name);
565 /* Now we have to do a bunch of other stuff */
567 if (num_parms(args) >= 7) {
568 new_order = extract_int(args, 6);
575 CtdlGetRoomLock(&CC->room, CC->room.QRname);
578 extract_token(buf, args, 2, '|', sizeof buf);
580 safestrncpy(CC->room.QRdirname, buf,
581 sizeof CC->room.QRdirname);
584 if (num_parms(args) >= 8) {
585 CC->room.QRdefaultview = extract_int(args, 7);
588 /* Second set of flags */
589 if (num_parms(args) >= 9) {
590 CC->room.QRflags2 = extract_int(args, 8);
594 CC->room.QRflags = (extract_int(args, 3) | QR_INUSE);
595 /* Clean up a client boo-boo: if the client set the room to
596 * guess-name or passworded, ensure that the private flag is
599 if ((CC->room.QRflags & QR_GUESSNAME)
600 || (CC->room.QRflags & QR_PASSWORDED))
601 CC->room.QRflags |= QR_PRIVATE;
603 /* Some changes can't apply to BASEROOM */
604 if (!strncasecmp(CC->room.QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)) {
605 CC->room.QRorder = 0;
606 CC->room.QRpasswd[0] = '\0';
607 CC->room.QRflags &= ~(QR_PRIVATE & QR_PASSWORDED &
608 QR_GUESSNAME & QR_PREFONLY & QR_MAILBOX);
609 CC->room.QRflags |= QR_PERMANENT;
611 /* March order (doesn't apply to AIDEROOM) */
612 if (num_parms(args) >= 7)
613 CC->room.QRorder = (char) new_order;
615 extract_token(buf, args, 1, '|', sizeof buf);
617 safestrncpy(CC->room.QRpasswd, buf,
618 sizeof CC->room.QRpasswd);
619 /* Kick everyone out if the client requested it
620 * (by changing the room's generation number)
622 if (extract_int(args, 4)) {
623 time(&CC->room.QRgen);
626 /* Some changes can't apply to AIDEROOM */
627 if (!strncasecmp(CC->room.QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)) {
628 CC->room.QRorder = 0;
629 CC->room.QRflags &= ~QR_MAILBOX;
630 CC->room.QRflags |= QR_PERMANENT;
633 /* Write the room record back to disk */
634 CtdlPutRoomLock(&CC->room);
636 /* Create a room directory if necessary */
637 if (CC->room.QRflags & QR_DIRECTORY) {
638 snprintf(buf, sizeof buf,"%s/%s",
643 snprintf(buf, sizeof buf, "The room \"%s\" has been edited by %s.\n",
645 (CC->logged_in ? CC->curr_user : "an administrator")
647 CtdlAideMessage(buf, "Room modification Message");
648 cprintf("%d Ok\n", CIT_OK);
654 * get the name of the room admin for this room
656 void cmd_geta(char *cmdbuf)
658 struct ctdluser usbuf;
660 if (CtdlAccessCheck(ac_logged_in)) return;
662 if (CtdlGetUserByNumber(&usbuf, CC->room.QRroomaide) == 0) {
663 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
665 cprintf("%d \n", CIT_OK);
671 * set the room admin for this room
673 void cmd_seta(char *new_ra)
675 struct ctdluser usbuf;
680 if (CtdlAccessCheck(ac_room_aide)) return;
682 if (CtdlGetUser(&usbuf, new_ra) != 0) {
685 newu = usbuf.usernum;
688 CtdlGetRoomLock(&CC->room, CC->room.QRname);
690 if (CC->room.QRroomaide != newu) {
693 CC->room.QRroomaide = newu;
694 CtdlPutRoomLock(&CC->room);
697 * We have to post the change notice _after_ writing changes to
698 * the room table, otherwise it would deadlock!
700 if (post_notice == 1) {
701 if (!IsEmptyStr(usbuf.fullname))
702 snprintf(buf, sizeof buf,
703 "%s is now the room admin for \"%s\".\n",
704 usbuf.fullname, CC->room.QRname);
706 snprintf(buf, sizeof buf,
707 "There is now no room admin for \"%s\".\n",
709 CtdlAideMessage(buf, "Admin Room Modification");
711 cprintf("%d Ok\n", CIT_OK);
715 * Retrieve info file for this room (this ought to be upgraded to handle non-plain-text)
717 void cmd_rinf(char *argbuf)
719 struct CtdlMessage *msg = CtdlFetchMessage(CC->room.msgnum_info, 1);
721 cprintf("%d Info:\n", LISTING_FOLLOWS);
722 CtdlOutputPreLoadedMsg(msg, MT_CITADEL, HEADERS_NONE, 0, 0, 0);
727 cprintf("%d No info file.\n", ERROR + FILE_NOT_FOUND);
733 * admin command: kill the current room
735 void cmd_kill(char *argbuf)
737 char deleted_room_name[ROOMNAMELEN];
741 kill_ok = extract_int(argbuf, 0);
743 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->room) == 0) {
744 cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
748 if (CC->room.QRflags & QR_MAILBOX) {
749 safestrncpy(deleted_room_name, &CC->room.QRname[11], sizeof deleted_room_name);
752 safestrncpy(deleted_room_name, CC->room.QRname, sizeof deleted_room_name);
755 /* Do the dirty work */
756 CtdlScheduleRoomForDeletion(&CC->room);
758 /* Return to the Lobby */
759 CtdlUserGoto(CtdlGetConfigStr("c_baseroom"), 0, 0, NULL, NULL, NULL, NULL);
761 /* tell the world what we did */
762 snprintf(msg, sizeof msg, "The room \"%s\" has been deleted by %s.\n",
764 (CC->logged_in ? CC->curr_user : "an administrator")
766 CtdlAideMessage(msg, "Room Purger Message");
767 cprintf("%d '%s' deleted.\n", CIT_OK, deleted_room_name);
769 cprintf("%d ok to delete.\n", CIT_OK);
777 void cmd_cre8(char *args)
780 char new_room_name[ROOMNAMELEN];
782 char new_room_pass[32];
785 char *notification_message = NULL;
788 int avoid_access = 0;
790 cre8_ok = extract_int(args, 0);
791 extract_token(new_room_name, args, 1, '|', sizeof new_room_name);
792 new_room_name[ROOMNAMELEN - 1] = 0;
793 new_room_type = extract_int(args, 2);
794 extract_token(new_room_pass, args, 3, '|', sizeof new_room_pass);
795 avoid_access = extract_int(args, 5);
796 new_room_view = extract_int(args, 6);
797 new_room_pass[9] = 0;
800 if ((IsEmptyStr(new_room_name)) && (cre8_ok == 1)) {
801 cprintf("%d Invalid room name.\n", ERROR + ILLEGAL_VALUE);
805 if (!strcasecmp(new_room_name, MAILROOM)) {
806 cprintf("%d '%s' already exists.\n",
807 ERROR + ALREADY_EXISTS, new_room_name);
811 if (num_parms(args) >= 5) {
812 fl = CtdlGetCachedFloor(extract_int(args, 4));
814 cprintf("%d Invalid floor number.\n",
815 ERROR + INVALID_FLOOR_OPERATION);
818 else if ((fl->f_flags & F_INUSE) == 0) {
819 cprintf("%d Invalid floor number.\n",
820 ERROR + INVALID_FLOOR_OPERATION);
823 new_room_floor = extract_int(args, 4);
827 if (CtdlAccessCheck(ac_logged_in)) return;
829 if (CC->user.axlevel < CtdlGetConfigInt("c_createax") && !CC->internal_pgm) {
830 cprintf("%d You need higher access to create rooms.\n",
831 ERROR + HIGHER_ACCESS_REQUIRED);
835 if ((IsEmptyStr(new_room_name)) && (cre8_ok == 0)) {
836 cprintf("%d Ok to create rooms.\n", CIT_OK);
840 if ((new_room_type < 0) || (new_room_type > 5)) {
841 cprintf("%d Invalid room type.\n", ERROR + ILLEGAL_VALUE);
845 if (new_room_type == 5) {
846 if (CC->user.axlevel < AxAideU) {
847 cprintf("%d Higher access required\n",
848 ERROR + HIGHER_ACCESS_REQUIRED);
853 /* Check to make sure the requested room name doesn't already exist */
854 newflags = CtdlCreateRoom(new_room_name,
855 new_room_type, new_room_pass, new_room_floor,
856 0, avoid_access, new_room_view);
858 cprintf("%d '%s' already exists.\n",
859 ERROR + ALREADY_EXISTS, new_room_name);
864 cprintf("%d OK to create '%s'\n", CIT_OK, new_room_name);
868 /* If we reach this point, the room needs to be created. */
870 newflags = CtdlCreateRoom(new_room_name,
871 new_room_type, new_room_pass, new_room_floor, 1, 0,
874 /* post a message in Aide> describing the new room */
875 notification_message = malloc(1024);
876 snprintf(notification_message, 1024,
877 "A new room called \"%s\" has been created by %s%s%s%s%s%s\n",
879 (CC->logged_in ? CC->curr_user : "an administrator"),
880 ((newflags & QR_MAILBOX) ? " [personal]" : ""),
881 ((newflags & QR_PRIVATE) ? " [private]" : ""),
882 ((newflags & QR_GUESSNAME) ? " [hidden]" : ""),
883 ((newflags & QR_PASSWORDED) ? " Password: " : ""),
884 ((newflags & QR_PASSWORDED) ? new_room_pass : "")
886 CtdlAideMessage(notification_message, "Room Creation Message");
887 free(notification_message);
889 cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
894 * Upload the room banner text for this room.
895 * This should be amended to handle content types other than plain text.
897 void cmd_einf(char *ok)
898 { /* enter info file for current room */
902 if (CtdlAccessCheck(ac_room_aide)) return;
905 cprintf("%d Ok.\n", CIT_OK);
909 StrBuf *NewBanner = NewStrBufPlain("Content-type: text/plain; charset=UTF-8\nContent-transfer-encoding: 8bit\n\n", -1);
911 cprintf("%d Transmit new banner in plain text now.\n", SEND_LISTING);
912 while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
913 StrBufAppendBufPlain(NewBanner, buf, -1, 0);
914 StrBufAppendBufPlain(NewBanner, HKEY("\n"), 0);
917 // We have read the new banner from the user , now save it
918 long new_msgnum = quickie_message("Citadel", NULL, NULL, SYSCONFIGROOM, ChrPtr(NewBanner), FMT_RFC822, "Banner submitted with EINF command");
919 FreeStrBuf(&NewBanner);
921 // Update the room record with a pointer to our new banner
922 CtdlGetRoomLock(&CC->room, CC->room.QRname);
923 long old_msgnum = CC->room.msgnum_info;
924 CC->room.msgnum_info = new_msgnum;
925 CtdlPutRoomLock(&CC->room);
927 // Delete the old one
928 CtdlDeleteMessages(SYSCONFIGROOM, &old_msgnum, 1, "");
933 * cmd_lflr() - List all known floors
935 void cmd_lflr(char *gargs)
940 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
942 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
944 for (a = 0; a < MAXFLOORS; ++a) {
945 CtdlGetFloor(&flbuf, a);
946 if (flbuf.f_flags & F_INUSE) {
947 cprintf("%d|%s|%d\n",
961 void cmd_cflr(char *argbuf)
963 char new_floor_name[256];
966 int free_slot = (-1);
969 extract_token(new_floor_name, argbuf, 0, '|', sizeof new_floor_name);
970 cflr_ok = extract_int(argbuf, 1);
972 if (CtdlAccessCheck(ac_aide)) return;
974 if (IsEmptyStr(new_floor_name)) {
975 cprintf("%d Blank floor name not allowed.\n",
976 ERROR + ILLEGAL_VALUE);
980 for (a = 0; a < MAXFLOORS; ++a) {
981 CtdlGetFloor(&flbuf, a);
983 /* note any free slots while we're scanning... */
984 if (((flbuf.f_flags & F_INUSE) == 0)
988 /* check to see if it already exists */
989 if ((!strcasecmp(flbuf.f_name, new_floor_name))
990 && (flbuf.f_flags & F_INUSE)) {
991 cprintf("%d Floor '%s' already exists.\n",
992 ERROR + ALREADY_EXISTS,
999 cprintf("%d There is no space available for a new floor.\n",
1000 ERROR + INVALID_FLOOR_OPERATION);
1004 cprintf("%d ok to create...\n", CIT_OK);
1007 lgetfloor(&flbuf, free_slot);
1008 flbuf.f_flags = F_INUSE;
1009 flbuf.f_ref_count = 0;
1010 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1011 lputfloor(&flbuf, free_slot);
1012 cprintf("%d %d\n", CIT_OK, free_slot);
1020 void cmd_kflr(char *argbuf)
1023 int floor_to_delete;
1027 floor_to_delete = extract_int(argbuf, 0);
1028 kflr_ok = extract_int(argbuf, 1);
1030 if (CtdlAccessCheck(ac_aide)) return;
1032 lgetfloor(&flbuf, floor_to_delete);
1035 if ((flbuf.f_flags & F_INUSE) == 0) {
1036 cprintf("%d Floor %d not in use.\n",
1037 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1040 if (flbuf.f_ref_count != 0) {
1041 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1042 ERROR + INVALID_FLOOR_OPERATION,
1047 cprintf("%d Ok\n", CIT_OK);
1049 cprintf("%d Ok to delete...\n", CIT_OK);
1056 if ((delete_ok == 1) && (kflr_ok == 1))
1058 lputfloor(&flbuf, floor_to_delete);
1064 void cmd_eflr(char *argbuf)
1070 np = num_parms(argbuf);
1072 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
1076 if (CtdlAccessCheck(ac_aide)) return;
1078 floor_num = extract_int(argbuf, 0);
1079 lgetfloor(&flbuf, floor_num);
1080 if ((flbuf.f_flags & F_INUSE) == 0) {
1081 lputfloor(&flbuf, floor_num);
1082 cprintf("%d Floor %d is not in use.\n",
1083 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1087 extract_token(flbuf.f_name, argbuf, 1, '|', sizeof flbuf.f_name);
1088 lputfloor(&flbuf, floor_num);
1090 cprintf("%d Ok\n", CIT_OK);
1096 * cmd_stat() - return the modification time of the current room (maybe other things in the future)
1098 void cmd_stat(char *gargs)
1100 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
1101 CtdlGetRoom(&CC->room, CC->room.QRname);
1102 cprintf("%d %s|%ld|\n", CIT_OK, CC->room.QRname, CC->room.QRmtime);
1108 /*****************************************************************************/
1109 /* MODULE INITIALIZATION STUFF */
1110 /*****************************************************************************/
1112 CTDL_MODULE_INIT(rooms)
1115 CtdlRegisterProtoHook(cmd_lrms, "LRMS", "List rooms");
1116 CtdlRegisterProtoHook(cmd_lkra, "LKRA", "List all known rooms");
1117 CtdlRegisterProtoHook(cmd_lkrn, "LKRN", "List known rooms with new messages");
1118 CtdlRegisterProtoHook(cmd_lkro, "LKRO", "List known rooms without new messages");
1119 CtdlRegisterProtoHook(cmd_lzrm, "LZRM", "List zapped rooms");
1120 CtdlRegisterProtoHook(cmd_lprm, "LPRM", "List public rooms");
1121 CtdlRegisterProtoHook(cmd_goto, "GOTO", "Goto a named room");
1122 CtdlRegisterProtoHook(cmd_stat, "STAT", "Get mtime of the current room");
1123 CtdlRegisterProtoHook(cmd_whok, "WHOK", "List users who know this room");
1124 CtdlRegisterProtoHook(cmd_rdir, "RDIR", "List files in room directory");
1125 CtdlRegisterProtoHook(cmd_getr, "GETR", "Get room parameters");
1126 CtdlRegisterProtoHook(cmd_setr, "SETR", "Set room parameters");
1127 CtdlRegisterProtoHook(cmd_geta, "GETA", "Get the room admin name");
1128 CtdlRegisterProtoHook(cmd_seta, "SETA", "Set the room admin for this room");
1129 CtdlRegisterProtoHook(cmd_rinf, "RINF", "Fetch room info file");
1130 CtdlRegisterProtoHook(cmd_kill, "KILL", "Kill (delete) the current room");
1131 CtdlRegisterProtoHook(cmd_cre8, "CRE8", "Create a new room");
1132 CtdlRegisterProtoHook(cmd_einf, "EINF", "Enter info file for the current room");
1133 CtdlRegisterProtoHook(cmd_lflr, "LFLR", "List all known floors");
1134 CtdlRegisterProtoHook(cmd_cflr, "CFLR", "Create a new floor");
1135 CtdlRegisterProtoHook(cmd_kflr, "KFLR", "Kill a floor");
1136 CtdlRegisterProtoHook(cmd_eflr, "EFLR", "Edit a floor");
1138 /* return our Subversion id for the Log */