2 * Server functions which perform operations on room objects.
4 * Copyright (c) 1987-2015 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.
16 #include <dirent.h> /* for cmd_rdir to read contents of the directory */
17 #include <libcitadel.h>
19 #include "citserver.h"
20 #include "ctdl_module.h"
25 * Back-back-end for all room listing commands
27 void list_roomname(struct ctdlroom *qrbuf, int ra, int current_view, int default_view)
29 char truncated_roomname[ROOMNAMELEN];
31 /* For my own mailbox rooms, chop off the owner prefix */
32 if ( (qrbuf->QRflags & QR_MAILBOX)
33 && (atol(qrbuf->QRname) == CC->user.usernum) ) {
34 safestrncpy(truncated_roomname, qrbuf->QRname, sizeof truncated_roomname);
35 safestrncpy(truncated_roomname, &truncated_roomname[11], sizeof truncated_roomname);
36 cprintf("%s", truncated_roomname);
38 /* For all other rooms, just display the name in its entirety */
40 cprintf("%s", qrbuf->QRname);
43 /* ...and now the other parameters */
44 cprintf("|%u|%d|%d|%d|%d|%d|%d|%ld|\n",
48 (int) qrbuf->QRflags2,
58 * cmd_lrms() - List all accessible rooms, known or forgotten
60 void cmd_lrms_backend(struct ctdlroom *qrbuf, void *data)
62 int FloorBeingSearched = (-1);
66 FloorBeingSearched = *(int *)data;
67 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
69 if ((( ra & (UA_KNOWN | UA_ZAPPED)))
70 && ((qrbuf->QRfloor == (FloorBeingSearched))
71 || ((FloorBeingSearched) < 0)))
72 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
75 void cmd_lrms(char *argbuf)
77 int FloorBeingSearched = (-1);
78 if (!IsEmptyStr(argbuf))
79 FloorBeingSearched = extract_int(argbuf, 0);
81 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
83 CtdlGetUser(&CC->user, CC->curr_user);
84 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
86 CtdlForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
93 * cmd_lkra() - List all known rooms
95 void cmd_lkra_backend(struct ctdlroom *qrbuf, void *data)
97 int FloorBeingSearched = (-1);
101 FloorBeingSearched = *(int *)data;
102 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
104 if ((( ra & (UA_KNOWN)))
105 && ((qrbuf->QRfloor == (FloorBeingSearched))
106 || ((FloorBeingSearched) < 0)))
107 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
110 void cmd_lkra(char *argbuf)
112 int FloorBeingSearched = (-1);
113 if (!IsEmptyStr(argbuf))
114 FloorBeingSearched = extract_int(argbuf, 0);
116 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
118 CtdlGetUser(&CC->user, CC->curr_user);
119 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
121 CtdlForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
127 void cmd_lprm_backend(struct ctdlroom *qrbuf, void *data)
129 int FloorBeingSearched = (-1);
133 FloorBeingSearched = *(int *)data;
134 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
136 if ( ((qrbuf->QRflags & QR_PRIVATE) == 0)
137 && ((qrbuf->QRflags & QR_MAILBOX) == 0)
138 && ((qrbuf->QRfloor == (FloorBeingSearched))
139 || ((FloorBeingSearched) < 0)))
140 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
143 void cmd_lprm(char *argbuf)
145 int FloorBeingSearched = (-1);
146 if (!IsEmptyStr(argbuf))
147 FloorBeingSearched = extract_int(argbuf, 0);
149 cprintf("%d Public rooms:\n", LISTING_FOLLOWS);
151 CtdlForEachRoom(cmd_lprm_backend, &FloorBeingSearched);
158 * cmd_lkrn() - List all known rooms with new messages
160 void cmd_lkrn_backend(struct ctdlroom *qrbuf, void *data)
162 int FloorBeingSearched = (-1);
166 FloorBeingSearched = *(int *)data;
167 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
170 && (ra & UA_HASNEWMSGS)
171 && ((qrbuf->QRfloor == (FloorBeingSearched))
172 || ((FloorBeingSearched) < 0)))
173 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
176 void cmd_lkrn(char *argbuf)
178 int FloorBeingSearched = (-1);
179 if (!IsEmptyStr(argbuf))
180 FloorBeingSearched = extract_int(argbuf, 0);
182 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
184 CtdlGetUser(&CC->user, CC->curr_user);
185 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
187 CtdlForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
194 * cmd_lkro() - List all known rooms
196 void cmd_lkro_backend(struct ctdlroom *qrbuf, void *data)
198 int FloorBeingSearched = (-1);
202 FloorBeingSearched = *(int *)data;
203 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
206 && ((ra & UA_HASNEWMSGS) == 0)
207 && ((qrbuf->QRfloor == (FloorBeingSearched))
208 || ((FloorBeingSearched) < 0)))
209 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
212 void cmd_lkro(char *argbuf)
214 int FloorBeingSearched = (-1);
215 if (!IsEmptyStr(argbuf))
216 FloorBeingSearched = extract_int(argbuf, 0);
218 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
220 CtdlGetUser(&CC->user, CC->curr_user);
221 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
223 CtdlForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
230 * cmd_lzrm() - List all forgotten rooms
232 void cmd_lzrm_backend(struct ctdlroom *qrbuf, void *data)
234 int FloorBeingSearched = (-1);
238 FloorBeingSearched = *(int *)data;
239 CtdlRoomAccess(qrbuf, &CC->user, &ra, &view);
241 if ((ra & UA_GOTOALLOWED)
243 && ((qrbuf->QRfloor == (FloorBeingSearched))
244 || ((FloorBeingSearched) < 0)))
245 list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
248 void cmd_lzrm(char *argbuf)
250 int FloorBeingSearched = (-1);
251 if (!IsEmptyStr(argbuf))
252 FloorBeingSearched = extract_int(argbuf, 0);
254 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
256 CtdlGetUser(&CC->user, CC->curr_user);
257 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
259 CtdlForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
265 * cmd_goto() - goto a new room
267 void cmd_goto(char *gargs)
269 struct ctdlroom QRscratch;
273 char augmented_roomname[ROOMNAMELEN];
274 char towhere[ROOMNAMELEN];
278 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
280 extract_token(towhere, gargs, 0, '|', sizeof towhere);
281 extract_token(password, gargs, 1, '|', sizeof password);
282 transiently = extract_int(gargs, 2);
284 CtdlGetUser(&CC->user, CC->curr_user);
287 * Handle some of the macro named rooms
289 convert_room_name_macros(towhere, sizeof towhere);
291 /* First try a regular match */
292 c = CtdlGetRoom(&QRscratch, towhere);
294 /* Then try a mailbox name match */
296 CtdlMailboxName(augmented_roomname, sizeof augmented_roomname,
298 c = CtdlGetRoom(&QRscratch, augmented_roomname);
300 safestrncpy(towhere, augmented_roomname, sizeof towhere);
303 /* And if the room was found... */
306 /* Let internal programs go directly to any room. */
307 if (CC->internal_pgm) {
308 memcpy(&CC->room, &QRscratch,
309 sizeof(struct ctdlroom));
310 CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
314 /* See if there is an existing user/room relationship */
315 CtdlRoomAccess(&QRscratch, &CC->user, &ra, NULL);
317 /* normal clients have to pass through security */
318 if (ra & UA_GOTOALLOWED) {
323 if ((QRscratch.QRflags & QR_MAILBOX) &&
324 ((ra & UA_GOTOALLOWED))) {
325 memcpy(&CC->room, &QRscratch,
326 sizeof(struct ctdlroom));
327 CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
329 } else if ((QRscratch.QRflags & QR_PASSWORDED) &&
330 ((ra & UA_KNOWN) == 0) &&
331 (strcasecmp(QRscratch.QRpasswd, password)) &&
332 (CC->user.axlevel < AxAideU)
334 cprintf("%d wrong or missing passwd\n",
335 ERROR + PASSWORD_REQUIRED);
337 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
338 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
339 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
340 ((ra & UA_KNOWN) == 0) &&
341 (CC->user.axlevel < AxAideU)
343 syslog(LOG_DEBUG, "Failed to acquire private room\n");
345 memcpy(&CC->room, &QRscratch,
346 sizeof(struct ctdlroom));
347 CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
353 cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
357 void cmd_whok(char *cmdbuf)
359 struct ctdluser temp;
360 struct cdbdata *cdbus;
363 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
364 cdb_rewind(CDB_USERS);
365 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
366 memset(&temp, 0, sizeof temp);
367 memcpy(&temp, cdbus->ptr, sizeof temp);
370 CtdlRoomAccess(&CC->room, &temp, &ra, NULL);
371 if ((!IsEmptyStr(temp.fullname)) &&
372 (CC->room.QRflags & QR_INUSE) &&
375 cprintf("%s\n", temp.fullname);
382 * RDIR command for room directory
384 void cmd_rdir(char *cmdbuf)
391 struct dirent *filedir_entry;
397 if (CtdlAccessCheck(ac_logged_in)) return;
399 CtdlGetRoom(&CC->room, CC->room.QRname);
400 CtdlGetUser(&CC->user, CC->curr_user);
402 if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
403 cprintf("%d not here.\n", ERROR + NOT_HERE);
406 if (((CC->room.QRflags & QR_VISDIR) == 0)
407 && (CC->user.axlevel < AxAideU)
408 && (CC->user.usernum != CC->room.QRroomaide)) {
409 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
413 snprintf(buf, sizeof buf, "%s/%s", ctdl_file_dir, CC->room.QRdirname);
414 filedir = opendir (buf);
416 if (filedir == NULL) {
417 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
420 cprintf("%d %s|%s/%s\n", LISTING_FOLLOWS, CtdlGetConfigStr("c_fqdn"), ctdl_file_dir, CC->room.QRdirname);
422 snprintf(buf, sizeof buf, "%s/%s/filedir", ctdl_file_dir, CC->room.QRdirname);
423 fd = fopen(buf, "r");
425 fd = fopen("/dev/null", "r");
426 while ((filedir_entry = readdir(filedir)))
428 if (strcasecmp(filedir_entry->d_name, "filedir") && filedir_entry->d_name[0] != '.')
430 #ifdef _DIRENT_HAVE_D_NAMELEN
431 d_namelen = filedir_entry->d_namlen;
433 d_namelen = strlen(filedir_entry->d_name);
435 snprintf(buf, sizeof buf, "%s/%s/%s", ctdl_file_dir, CC->room.QRdirname, filedir_entry->d_name);
436 stat(buf, &statbuf); /* stat the file */
437 if (!(statbuf.st_mode & S_IFREG))
439 snprintf(buf2, sizeof buf2,
440 "\"%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",
443 CtdlAideMessage(buf2, "Unusable data found in room directory");
444 continue; /* not a useable file type so don't show it */
446 safestrncpy(comment, "", sizeof comment);
447 fseek(fd, 0L, 0); /* rewind descriptions file */
448 /* Get the description from the descriptions file */
449 while ((fgets(buf, sizeof buf, fd) != NULL) && (IsEmptyStr(comment)))
451 buf[strlen(buf) - 1] = 0;
452 if ((!strncasecmp(buf, filedir_entry->d_name, d_namelen)) && (buf[d_namelen] == ' '))
453 safestrncpy(comment, &buf[d_namelen + 1], sizeof comment);
455 len = extract_token (mimebuf, comment, 0,' ', 64);
456 if ((len <0) || strchr(mimebuf, '/') == NULL)
458 snprintf (mimebuf, 64, "application/octetstream");
461 cprintf("%s|%ld|%s|%s\n",
462 filedir_entry->d_name,
463 (long)statbuf.st_size,
475 * get room parameters (admin or room admin command)
477 void cmd_getr(char *cmdbuf)
479 if (CtdlAccessCheck(ac_room_aide)) return;
481 CtdlGetRoom(&CC->room, CC->room.QRname);
482 cprintf("%d%c%s|%s|%s|%d|%d|%d|%d|%d|\n",
486 ((CC->room.QRflags & QR_MAILBOX) ?
487 &CC->room.QRname[11] : CC->room.QRname),
489 ((CC->room.QRflags & QR_PASSWORDED) ?
490 CC->room.QRpasswd : ""),
492 ((CC->room.QRflags & QR_DIRECTORY) ?
493 CC->room.QRdirname : ""),
496 (int) CC->room.QRfloor,
497 (int) CC->room.QRorder,
499 CC->room.QRdefaultview,
505 * set room parameters (admin or room admin command)
507 void cmd_setr(char *args)
513 char new_name[ROOMNAMELEN];
515 if (CtdlAccessCheck(ac_logged_in)) return;
517 if (num_parms(args) >= 6) {
518 new_floor = extract_int(args, 5);
520 new_floor = (-1); /* don't change the floor */
523 /* When is a new name more than just a new name? When the old name
524 * has a namespace prefix.
526 if (CC->room.QRflags & QR_MAILBOX) {
527 sprintf(new_name, "%010ld.", atol(CC->room.QRname) );
529 safestrncpy(new_name, "", sizeof new_name);
531 extract_token(&new_name[strlen(new_name)], args, 0, '|', (sizeof new_name - strlen(new_name)));
533 r = CtdlRenameRoom(CC->room.QRname, new_name, new_floor);
535 if (r == crr_room_not_found) {
536 cprintf("%d Internal error - room not found?\n", ERROR + INTERNAL_ERROR);
537 } else if (r == crr_already_exists) {
538 cprintf("%d '%s' already exists.\n",
539 ERROR + ALREADY_EXISTS, new_name);
540 } else if (r == crr_noneditable) {
541 cprintf("%d Cannot edit this room.\n", ERROR + NOT_HERE);
542 } else if (r == crr_invalid_floor) {
543 cprintf("%d Target floor does not exist.\n",
544 ERROR + INVALID_FLOOR_OPERATION);
545 } else if (r == crr_access_denied) {
546 cprintf("%d You do not have permission to edit '%s'\n",
547 ERROR + HIGHER_ACCESS_REQUIRED,
549 } else if (r != crr_ok) {
550 cprintf("%d Error: CtdlRenameRoom() returned %d\n",
551 ERROR + INTERNAL_ERROR, r);
558 CtdlGetRoom(&CC->room, new_name);
560 /* Now we have to do a bunch of other stuff */
562 if (num_parms(args) >= 7) {
563 new_order = extract_int(args, 6);
570 CtdlGetRoomLock(&CC->room, CC->room.QRname);
573 extract_token(buf, args, 2, '|', sizeof buf);
575 safestrncpy(CC->room.QRdirname, buf,
576 sizeof CC->room.QRdirname);
579 if (num_parms(args) >= 8) {
580 CC->room.QRdefaultview = extract_int(args, 7);
583 /* Second set of flags */
584 if (num_parms(args) >= 9) {
585 CC->room.QRflags2 = extract_int(args, 8);
589 CC->room.QRflags = (extract_int(args, 3) | QR_INUSE);
590 /* Clean up a client boo-boo: if the client set the room to
591 * guess-name or passworded, ensure that the private flag is
594 if ((CC->room.QRflags & QR_GUESSNAME)
595 || (CC->room.QRflags & QR_PASSWORDED))
596 CC->room.QRflags |= QR_PRIVATE;
598 /* Some changes can't apply to BASEROOM */
599 if (!strncasecmp(CC->room.QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)) {
600 CC->room.QRorder = 0;
601 CC->room.QRpasswd[0] = '\0';
602 CC->room.QRflags &= ~(QR_PRIVATE & QR_PASSWORDED &
603 QR_GUESSNAME & QR_PREFONLY & QR_MAILBOX);
604 CC->room.QRflags |= QR_PERMANENT;
606 /* March order (doesn't apply to AIDEROOM) */
607 if (num_parms(args) >= 7)
608 CC->room.QRorder = (char) new_order;
610 extract_token(buf, args, 1, '|', sizeof buf);
612 safestrncpy(CC->room.QRpasswd, buf,
613 sizeof CC->room.QRpasswd);
614 /* Kick everyone out if the client requested it
615 * (by changing the room's generation number)
617 if (extract_int(args, 4)) {
618 time(&CC->room.QRgen);
621 /* Some changes can't apply to AIDEROOM */
622 if (!strncasecmp(CC->room.QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)) {
623 CC->room.QRorder = 0;
624 CC->room.QRflags &= ~QR_MAILBOX;
625 CC->room.QRflags |= QR_PERMANENT;
628 /* Write the room record back to disk */
629 CtdlPutRoomLock(&CC->room);
631 /* Create a room directory if necessary */
632 if (CC->room.QRflags & QR_DIRECTORY) {
633 snprintf(buf, sizeof buf,"%s/%s",
638 snprintf(buf, sizeof buf, "The room \"%s\" has been edited by %s.\n",
640 (CC->logged_in ? CC->curr_user : "an administrator")
642 CtdlAideMessage(buf, "Room modification Message");
643 cprintf("%d Ok\n", CIT_OK);
649 * get the name of the room admin for this room
651 void cmd_geta(char *cmdbuf)
653 struct ctdluser usbuf;
655 if (CtdlAccessCheck(ac_logged_in)) return;
657 if (CtdlGetUserByNumber(&usbuf, CC->room.QRroomaide) == 0) {
658 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
660 cprintf("%d \n", CIT_OK);
666 * set the room admin for this room
668 void cmd_seta(char *new_ra)
670 struct ctdluser usbuf;
675 if (CtdlAccessCheck(ac_room_aide)) return;
677 if (CtdlGetUser(&usbuf, new_ra) != 0) {
680 newu = usbuf.usernum;
683 CtdlGetRoomLock(&CC->room, CC->room.QRname);
685 if (CC->room.QRroomaide != newu) {
688 CC->room.QRroomaide = newu;
689 CtdlPutRoomLock(&CC->room);
692 * We have to post the change notice _after_ writing changes to
693 * the room table, otherwise it would deadlock!
695 if (post_notice == 1) {
696 if (!IsEmptyStr(usbuf.fullname))
697 snprintf(buf, sizeof buf,
698 "%s is now the room admin for \"%s\".\n",
699 usbuf.fullname, CC->room.QRname);
701 snprintf(buf, sizeof buf,
702 "There is now no room admin for \"%s\".\n",
704 CtdlAideMessage(buf, "Admin Room Modification");
706 cprintf("%d Ok\n", CIT_OK);
710 * retrieve info file for this room
712 void cmd_rinf(char *gargs)
714 char filename[PATH_MAX];
718 assoc_file_name(filename, sizeof filename, &CC->room, ctdl_info_dir);
719 info_fp = fopen(filename, "r");
721 if (info_fp == NULL) {
722 cprintf("%d No info file.\n", ERROR + FILE_NOT_FOUND);
725 cprintf("%d Info:\n", LISTING_FOLLOWS);
726 while (fgets(buf, sizeof buf, info_fp) != NULL) {
727 if (!IsEmptyStr(buf))
728 buf[strlen(buf) - 1] = 0;
729 cprintf("%s\n", buf);
737 * admin command: kill the current room
739 void cmd_kill(char *argbuf)
741 char deleted_room_name[ROOMNAMELEN];
745 kill_ok = extract_int(argbuf, 0);
747 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->room) == 0) {
748 cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
752 if (CC->room.QRflags & QR_MAILBOX) {
753 safestrncpy(deleted_room_name, &CC->room.QRname[11], sizeof deleted_room_name);
756 safestrncpy(deleted_room_name, CC->room.QRname, sizeof deleted_room_name);
759 /* Do the dirty work */
760 CtdlScheduleRoomForDeletion(&CC->room);
762 /* Return to the Lobby */
763 CtdlUserGoto(CtdlGetConfigStr("c_baseroom"), 0, 0, NULL, NULL, NULL, NULL);
765 /* tell the world what we did */
766 snprintf(msg, sizeof msg, "The room \"%s\" has been deleted by %s.\n",
768 (CC->logged_in ? CC->curr_user : "an administrator")
770 CtdlAideMessage(msg, "Room Purger Message");
771 cprintf("%d '%s' deleted.\n", CIT_OK, deleted_room_name);
773 cprintf("%d ok to delete.\n", CIT_OK);
781 void cmd_cre8(char *args)
784 char new_room_name[ROOMNAMELEN];
786 char new_room_pass[32];
789 char *notification_message = NULL;
792 int avoid_access = 0;
794 cre8_ok = extract_int(args, 0);
795 extract_token(new_room_name, args, 1, '|', sizeof new_room_name);
796 new_room_name[ROOMNAMELEN - 1] = 0;
797 new_room_type = extract_int(args, 2);
798 extract_token(new_room_pass, args, 3, '|', sizeof new_room_pass);
799 avoid_access = extract_int(args, 5);
800 new_room_view = extract_int(args, 6);
801 new_room_pass[9] = 0;
804 if ((IsEmptyStr(new_room_name)) && (cre8_ok == 1)) {
805 cprintf("%d Invalid room name.\n", ERROR + ILLEGAL_VALUE);
809 if (!strcasecmp(new_room_name, MAILROOM)) {
810 cprintf("%d '%s' already exists.\n",
811 ERROR + ALREADY_EXISTS, new_room_name);
815 if (num_parms(args) >= 5) {
816 fl = CtdlGetCachedFloor(extract_int(args, 4));
818 cprintf("%d Invalid floor number.\n",
819 ERROR + INVALID_FLOOR_OPERATION);
822 else if ((fl->f_flags & F_INUSE) == 0) {
823 cprintf("%d Invalid floor number.\n",
824 ERROR + INVALID_FLOOR_OPERATION);
827 new_room_floor = extract_int(args, 4);
831 if (CtdlAccessCheck(ac_logged_in)) return;
833 if (CC->user.axlevel < CtdlGetConfigInt("c_createax") && !CC->internal_pgm) {
834 cprintf("%d You need higher access to create rooms.\n",
835 ERROR + HIGHER_ACCESS_REQUIRED);
839 if ((IsEmptyStr(new_room_name)) && (cre8_ok == 0)) {
840 cprintf("%d Ok to create rooms.\n", CIT_OK);
844 if ((new_room_type < 0) || (new_room_type > 5)) {
845 cprintf("%d Invalid room type.\n", ERROR + ILLEGAL_VALUE);
849 if (new_room_type == 5) {
850 if (CC->user.axlevel < AxAideU) {
851 cprintf("%d Higher access required\n",
852 ERROR + HIGHER_ACCESS_REQUIRED);
857 /* Check to make sure the requested room name doesn't already exist */
858 newflags = CtdlCreateRoom(new_room_name,
859 new_room_type, new_room_pass, new_room_floor,
860 0, avoid_access, new_room_view);
862 cprintf("%d '%s' already exists.\n",
863 ERROR + ALREADY_EXISTS, new_room_name);
868 cprintf("%d OK to create '%s'\n", CIT_OK, new_room_name);
872 /* If we reach this point, the room needs to be created. */
874 newflags = CtdlCreateRoom(new_room_name,
875 new_room_type, new_room_pass, new_room_floor, 1, 0,
878 /* post a message in Aide> describing the new room */
879 notification_message = malloc(1024);
880 snprintf(notification_message, 1024,
881 "A new room called \"%s\" has been created by %s%s%s%s%s%s\n",
883 (CC->logged_in ? CC->curr_user : "an administrator"),
884 ((newflags & QR_MAILBOX) ? " [personal]" : ""),
885 ((newflags & QR_PRIVATE) ? " [private]" : ""),
886 ((newflags & QR_GUESSNAME) ? " [hidden]" : ""),
887 ((newflags & QR_PASSWORDED) ? " Password: " : ""),
888 ((newflags & QR_PASSWORDED) ? new_room_pass : "")
890 CtdlAideMessage(notification_message, "Room Creation Message");
891 free(notification_message);
893 cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
898 void cmd_einf(char *ok)
899 { /* enter info file for current room */
901 char infofilename[SIZ];
906 if (CtdlAccessCheck(ac_room_aide)) return;
909 cprintf("%d Ok.\n", CIT_OK);
912 assoc_file_name(infofilename, sizeof infofilename, &CC->room, ctdl_info_dir);
913 syslog(LOG_DEBUG, "opening\n");
914 fp = fopen(infofilename, "w");
915 syslog(LOG_DEBUG, "checking\n");
917 cprintf("%d Cannot open %s: %s\n",
918 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
921 cprintf("%d Send info...\n", SEND_LISTING);
924 client_getln(buf, sizeof buf);
925 if (strcmp(buf, "000"))
926 fprintf(fp, "%s\n", buf);
927 } while (strcmp(buf, "000"));
930 /* now update the room index so people will see our new info */
931 CtdlGetRoomLock(&CC->room, CC->room.QRname); /* lock so no one steps on us */
932 CC->room.QRinfo = CC->room.QRhighest + 1L;
933 CtdlPutRoomLock(&CC->room);
938 * cmd_lflr() - List all known floors
940 void cmd_lflr(char *gargs)
945 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
947 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
949 for (a = 0; a < MAXFLOORS; ++a) {
950 CtdlGetFloor(&flbuf, a);
951 if (flbuf.f_flags & F_INUSE) {
952 cprintf("%d|%s|%d\n",
966 void cmd_cflr(char *argbuf)
968 char new_floor_name[256];
971 int free_slot = (-1);
974 extract_token(new_floor_name, argbuf, 0, '|', sizeof new_floor_name);
975 cflr_ok = extract_int(argbuf, 1);
977 if (CtdlAccessCheck(ac_aide)) return;
979 if (IsEmptyStr(new_floor_name)) {
980 cprintf("%d Blank floor name not allowed.\n",
981 ERROR + ILLEGAL_VALUE);
985 for (a = 0; a < MAXFLOORS; ++a) {
986 CtdlGetFloor(&flbuf, a);
988 /* note any free slots while we're scanning... */
989 if (((flbuf.f_flags & F_INUSE) == 0)
993 /* check to see if it already exists */
994 if ((!strcasecmp(flbuf.f_name, new_floor_name))
995 && (flbuf.f_flags & F_INUSE)) {
996 cprintf("%d Floor '%s' already exists.\n",
997 ERROR + ALREADY_EXISTS,
1003 if (free_slot < 0) {
1004 cprintf("%d There is no space available for a new floor.\n",
1005 ERROR + INVALID_FLOOR_OPERATION);
1009 cprintf("%d ok to create...\n", CIT_OK);
1012 lgetfloor(&flbuf, free_slot);
1013 flbuf.f_flags = F_INUSE;
1014 flbuf.f_ref_count = 0;
1015 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1016 lputfloor(&flbuf, free_slot);
1017 cprintf("%d %d\n", CIT_OK, free_slot);
1025 void cmd_kflr(char *argbuf)
1028 int floor_to_delete;
1032 floor_to_delete = extract_int(argbuf, 0);
1033 kflr_ok = extract_int(argbuf, 1);
1035 if (CtdlAccessCheck(ac_aide)) return;
1037 lgetfloor(&flbuf, floor_to_delete);
1040 if ((flbuf.f_flags & F_INUSE) == 0) {
1041 cprintf("%d Floor %d not in use.\n",
1042 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1045 if (flbuf.f_ref_count != 0) {
1046 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1047 ERROR + INVALID_FLOOR_OPERATION,
1052 cprintf("%d Ok\n", CIT_OK);
1054 cprintf("%d Ok to delete...\n", CIT_OK);
1061 if ((delete_ok == 1) && (kflr_ok == 1))
1063 lputfloor(&flbuf, floor_to_delete);
1069 void cmd_eflr(char *argbuf)
1075 np = num_parms(argbuf);
1077 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
1081 if (CtdlAccessCheck(ac_aide)) return;
1083 floor_num = extract_int(argbuf, 0);
1084 lgetfloor(&flbuf, floor_num);
1085 if ((flbuf.f_flags & F_INUSE) == 0) {
1086 lputfloor(&flbuf, floor_num);
1087 cprintf("%d Floor %d is not in use.\n",
1088 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1092 extract_token(flbuf.f_name, argbuf, 1, '|', sizeof flbuf.f_name);
1093 lputfloor(&flbuf, floor_num);
1095 cprintf("%d Ok\n", CIT_OK);
1101 * cmd_stat() - return the modification time of the current room (maybe other things in the future)
1103 void cmd_stat(char *gargs)
1105 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
1106 CtdlGetRoom(&CC->room, CC->room.QRname);
1107 cprintf("%d %s|%ld|\n", CIT_OK, CC->room.QRname, CC->room.QRmtime);
1113 /*****************************************************************************/
1114 /* MODULE INITIALIZATION STUFF */
1115 /*****************************************************************************/
1117 CTDL_MODULE_INIT(rooms)
1120 CtdlRegisterProtoHook(cmd_lrms, "LRMS", "List rooms");
1121 CtdlRegisterProtoHook(cmd_lkra, "LKRA", "List all known rooms");
1122 CtdlRegisterProtoHook(cmd_lkrn, "LKRN", "List known rooms with new messages");
1123 CtdlRegisterProtoHook(cmd_lkro, "LKRO", "List known rooms without new messages");
1124 CtdlRegisterProtoHook(cmd_lzrm, "LZRM", "List zapped rooms");
1125 CtdlRegisterProtoHook(cmd_lprm, "LPRM", "List public rooms");
1126 CtdlRegisterProtoHook(cmd_goto, "GOTO", "Goto a named room");
1127 CtdlRegisterProtoHook(cmd_stat, "STAT", "Get mtime of the current room");
1128 CtdlRegisterProtoHook(cmd_whok, "WHOK", "List users who know this room");
1129 CtdlRegisterProtoHook(cmd_rdir, "RDIR", "List files in room directory");
1130 CtdlRegisterProtoHook(cmd_getr, "GETR", "Get room parameters");
1131 CtdlRegisterProtoHook(cmd_setr, "SETR", "Set room parameters");
1132 CtdlRegisterProtoHook(cmd_geta, "GETA", "Get the room admin name");
1133 CtdlRegisterProtoHook(cmd_seta, "SETA", "Set the room admin for this room");
1134 CtdlRegisterProtoHook(cmd_rinf, "RINF", "Fetch room info file");
1135 CtdlRegisterProtoHook(cmd_kill, "KILL", "Kill (delete) the current room");
1136 CtdlRegisterProtoHook(cmd_cre8, "CRE8", "Create a new room");
1137 CtdlRegisterProtoHook(cmd_einf, "EINF", "Enter info file for the current room");
1138 CtdlRegisterProtoHook(cmd_lflr, "LFLR", "List all known floors");
1139 CtdlRegisterProtoHook(cmd_cflr, "CFLR", "Create a new floor");
1140 CtdlRegisterProtoHook(cmd_kflr, "KFLR", "Kill a floor");
1141 CtdlRegisterProtoHook(cmd_eflr, "EFLR", "Edit a floor");
1143 /* return our Subversion id for the Log */