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 CitContext *CCC = CC;
270 struct ctdlroom QRscratch;
274 char augmented_roomname[ROOMNAMELEN];
275 char towhere[ROOMNAMELEN];
279 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
281 extract_token(towhere, gargs, 0, '|', sizeof towhere);
282 extract_token(password, gargs, 1, '|', sizeof password);
283 transiently = extract_int(gargs, 2);
285 CtdlGetUser(&CCC->user, CCC->curr_user);
288 * Handle some of the macro named rooms
290 convert_room_name_macros(towhere, sizeof towhere);
292 /* First try a regular match */
293 c = CtdlGetRoom(&QRscratch, towhere);
295 /* Then try a mailbox name match */
297 CtdlMailboxName(augmented_roomname, sizeof augmented_roomname,
298 &CCC->user, towhere);
299 c = CtdlGetRoom(&QRscratch, augmented_roomname);
301 safestrncpy(towhere, augmented_roomname, sizeof towhere);
304 /* And if the room was found... */
307 /* Let internal programs go directly to any room. */
308 if (CCC->internal_pgm) {
309 memcpy(&CCC->room, &QRscratch,
310 sizeof(struct ctdlroom));
311 CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
315 /* See if there is an existing user/room relationship */
316 CtdlRoomAccess(&QRscratch, &CCC->user, &ra, NULL);
318 /* normal clients have to pass through security */
319 if (ra & UA_GOTOALLOWED) {
324 if ((QRscratch.QRflags & QR_MAILBOX) &&
325 ((ra & UA_GOTOALLOWED))) {
326 memcpy(&CCC->room, &QRscratch,
327 sizeof(struct ctdlroom));
328 CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
330 } else if ((QRscratch.QRflags & QR_PASSWORDED) &&
331 ((ra & UA_KNOWN) == 0) &&
332 (strcasecmp(QRscratch.QRpasswd, password)) &&
333 (CCC->user.axlevel < AxAideU)
335 cprintf("%d wrong or missing passwd\n",
336 ERROR + PASSWORD_REQUIRED);
338 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
339 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
340 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
341 ((ra & UA_KNOWN) == 0) &&
342 (CCC->user.axlevel < AxAideU)
344 CTDLM_syslog(LOG_DEBUG, "Failed to acquire private room");
346 memcpy(&CCC->room, &QRscratch,
347 sizeof(struct ctdlroom));
348 CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
354 cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
358 void cmd_whok(char *cmdbuf)
360 struct ctdluser temp;
361 struct cdbdata *cdbus;
364 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
365 cdb_rewind(CDB_USERS);
366 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
367 memset(&temp, 0, sizeof temp);
368 memcpy(&temp, cdbus->ptr, sizeof temp);
371 CtdlRoomAccess(&CC->room, &temp, &ra, NULL);
372 if ((!IsEmptyStr(temp.fullname)) &&
373 (CC->room.QRflags & QR_INUSE) &&
376 cprintf("%s\n", temp.fullname);
383 * RDIR command for room directory
385 void cmd_rdir(char *cmdbuf)
392 struct dirent *filedir_entry;
398 if (CtdlAccessCheck(ac_logged_in)) return;
400 CtdlGetRoom(&CC->room, CC->room.QRname);
401 CtdlGetUser(&CC->user, CC->curr_user);
403 if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
404 cprintf("%d not here.\n", ERROR + NOT_HERE);
407 if (((CC->room.QRflags & QR_VISDIR) == 0)
408 && (CC->user.axlevel < AxAideU)
409 && (CC->user.usernum != CC->room.QRroomaide)) {
410 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
414 snprintf(buf, sizeof buf, "%s/%s", ctdl_file_dir, CC->room.QRdirname);
415 filedir = opendir (buf);
417 if (filedir == NULL) {
418 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
421 cprintf("%d %s|%s/%s\n", LISTING_FOLLOWS, CtdlGetConfigStr("c_fqdn"), ctdl_file_dir, CC->room.QRdirname);
423 snprintf(buf, sizeof buf, "%s/%s/filedir", ctdl_file_dir, CC->room.QRdirname);
424 fd = fopen(buf, "r");
426 fd = fopen("/dev/null", "r");
427 while ((filedir_entry = readdir(filedir)))
429 if (strcasecmp(filedir_entry->d_name, "filedir") && filedir_entry->d_name[0] != '.')
431 #ifdef _DIRENT_HAVE_D_NAMELEN
432 d_namelen = filedir_entry->d_namlen;
434 d_namelen = strlen(filedir_entry->d_name);
436 snprintf(buf, sizeof buf, "%s/%s/%s", ctdl_file_dir, CC->room.QRdirname, filedir_entry->d_name);
437 stat(buf, &statbuf); /* stat the file */
438 if (!(statbuf.st_mode & S_IFREG))
440 snprintf(buf2, sizeof buf2,
441 "\"%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",
444 CtdlAideMessage(buf2, "Unusable data found in room directory");
445 continue; /* not a useable file type so don't show it */
447 safestrncpy(comment, "", sizeof comment);
448 fseek(fd, 0L, 0); /* rewind descriptions file */
449 /* Get the description from the descriptions file */
450 while ((fgets(buf, sizeof buf, fd) != NULL) && (IsEmptyStr(comment)))
452 buf[strlen(buf) - 1] = 0;
453 if ((!strncasecmp(buf, filedir_entry->d_name, d_namelen)) && (buf[d_namelen] == ' '))
454 safestrncpy(comment, &buf[d_namelen + 1], sizeof comment);
456 len = extract_token (mimebuf, comment, 0,' ', 64);
457 if ((len <0) || strchr(mimebuf, '/') == NULL)
459 snprintf (mimebuf, 64, "application/octetstream");
462 cprintf("%s|%ld|%s|%s\n",
463 filedir_entry->d_name,
464 (long)statbuf.st_size,
476 * get room parameters (admin or room admin command)
478 void cmd_getr(char *cmdbuf)
480 if (CtdlAccessCheck(ac_room_aide)) return;
482 CtdlGetRoom(&CC->room, CC->room.QRname);
483 cprintf("%d%c%s|%s|%s|%d|%d|%d|%d|%d|\n",
487 ((CC->room.QRflags & QR_MAILBOX) ?
488 &CC->room.QRname[11] : CC->room.QRname),
490 ((CC->room.QRflags & QR_PASSWORDED) ?
491 CC->room.QRpasswd : ""),
493 ((CC->room.QRflags & QR_DIRECTORY) ?
494 CC->room.QRdirname : ""),
497 (int) CC->room.QRfloor,
498 (int) CC->room.QRorder,
500 CC->room.QRdefaultview,
506 * set room parameters (admin or room admin command)
508 void cmd_setr(char *args)
514 char new_name[ROOMNAMELEN];
516 if (CtdlAccessCheck(ac_logged_in)) return;
518 if (num_parms(args) >= 6) {
519 new_floor = extract_int(args, 5);
521 new_floor = (-1); /* don't change the floor */
524 /* When is a new name more than just a new name? When the old name
525 * has a namespace prefix.
527 if (CC->room.QRflags & QR_MAILBOX) {
528 sprintf(new_name, "%010ld.", atol(CC->room.QRname) );
530 safestrncpy(new_name, "", sizeof new_name);
532 extract_token(&new_name[strlen(new_name)], args, 0, '|', (sizeof new_name - strlen(new_name)));
534 r = CtdlRenameRoom(CC->room.QRname, new_name, new_floor);
536 if (r == crr_room_not_found) {
537 cprintf("%d Internal error - room not found?\n", ERROR + INTERNAL_ERROR);
538 } else if (r == crr_already_exists) {
539 cprintf("%d '%s' already exists.\n",
540 ERROR + ALREADY_EXISTS, new_name);
541 } else if (r == crr_noneditable) {
542 cprintf("%d Cannot edit this room.\n", ERROR + NOT_HERE);
543 } else if (r == crr_invalid_floor) {
544 cprintf("%d Target floor does not exist.\n",
545 ERROR + INVALID_FLOOR_OPERATION);
546 } else if (r == crr_access_denied) {
547 cprintf("%d You do not have permission to edit '%s'\n",
548 ERROR + HIGHER_ACCESS_REQUIRED,
550 } else if (r != crr_ok) {
551 cprintf("%d Error: CtdlRenameRoom() returned %d\n",
552 ERROR + INTERNAL_ERROR, r);
559 CtdlGetRoom(&CC->room, new_name);
561 /* Now we have to do a bunch of other stuff */
563 if (num_parms(args) >= 7) {
564 new_order = extract_int(args, 6);
571 CtdlGetRoomLock(&CC->room, CC->room.QRname);
574 extract_token(buf, args, 2, '|', sizeof buf);
576 safestrncpy(CC->room.QRdirname, buf,
577 sizeof CC->room.QRdirname);
580 if (num_parms(args) >= 8) {
581 CC->room.QRdefaultview = extract_int(args, 7);
584 /* Second set of flags */
585 if (num_parms(args) >= 9) {
586 CC->room.QRflags2 = extract_int(args, 8);
590 CC->room.QRflags = (extract_int(args, 3) | QR_INUSE);
591 /* Clean up a client boo-boo: if the client set the room to
592 * guess-name or passworded, ensure that the private flag is
595 if ((CC->room.QRflags & QR_GUESSNAME)
596 || (CC->room.QRflags & QR_PASSWORDED))
597 CC->room.QRflags |= QR_PRIVATE;
599 /* Some changes can't apply to BASEROOM */
600 if (!strncasecmp(CC->room.QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)) {
601 CC->room.QRorder = 0;
602 CC->room.QRpasswd[0] = '\0';
603 CC->room.QRflags &= ~(QR_PRIVATE & QR_PASSWORDED &
604 QR_GUESSNAME & QR_PREFONLY & QR_MAILBOX);
605 CC->room.QRflags |= QR_PERMANENT;
607 /* March order (doesn't apply to AIDEROOM) */
608 if (num_parms(args) >= 7)
609 CC->room.QRorder = (char) new_order;
611 extract_token(buf, args, 1, '|', sizeof buf);
613 safestrncpy(CC->room.QRpasswd, buf,
614 sizeof CC->room.QRpasswd);
615 /* Kick everyone out if the client requested it
616 * (by changing the room's generation number)
618 if (extract_int(args, 4)) {
619 time(&CC->room.QRgen);
622 /* Some changes can't apply to AIDEROOM */
623 if (!strncasecmp(CC->room.QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)) {
624 CC->room.QRorder = 0;
625 CC->room.QRflags &= ~QR_MAILBOX;
626 CC->room.QRflags |= QR_PERMANENT;
629 /* Write the room record back to disk */
630 CtdlPutRoomLock(&CC->room);
632 /* Create a room directory if necessary */
633 if (CC->room.QRflags & QR_DIRECTORY) {
634 snprintf(buf, sizeof buf,"%s/%s",
639 snprintf(buf, sizeof buf, "The room \"%s\" has been edited by %s.\n",
641 (CC->logged_in ? CC->curr_user : "an administrator")
643 CtdlAideMessage(buf, "Room modification Message");
644 cprintf("%d Ok\n", CIT_OK);
650 * get the name of the room admin for this room
652 void cmd_geta(char *cmdbuf)
654 struct ctdluser usbuf;
656 if (CtdlAccessCheck(ac_logged_in)) return;
658 if (CtdlGetUserByNumber(&usbuf, CC->room.QRroomaide) == 0) {
659 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
661 cprintf("%d \n", CIT_OK);
667 * set the room admin for this room
669 void cmd_seta(char *new_ra)
671 struct ctdluser usbuf;
676 if (CtdlAccessCheck(ac_room_aide)) return;
678 if (CtdlGetUser(&usbuf, new_ra) != 0) {
681 newu = usbuf.usernum;
684 CtdlGetRoomLock(&CC->room, CC->room.QRname);
686 if (CC->room.QRroomaide != newu) {
689 CC->room.QRroomaide = newu;
690 CtdlPutRoomLock(&CC->room);
693 * We have to post the change notice _after_ writing changes to
694 * the room table, otherwise it would deadlock!
696 if (post_notice == 1) {
697 if (!IsEmptyStr(usbuf.fullname))
698 snprintf(buf, sizeof buf,
699 "%s is now the room admin for \"%s\".\n",
700 usbuf.fullname, CC->room.QRname);
702 snprintf(buf, sizeof buf,
703 "There is now no room admin for \"%s\".\n",
705 CtdlAideMessage(buf, "Admin Room Modification");
707 cprintf("%d Ok\n", CIT_OK);
711 * Retrieve info file for this room (this ought to be upgraded to handle non-plain-text)
713 void cmd_rinf(char *argbuf)
715 struct CtdlMessage *msg = CtdlFetchMessage(CC->room.msgnum_info, 1, 1);
717 cprintf("%d Info:\n", LISTING_FOLLOWS);
718 CtdlOutputPreLoadedMsg(msg, MT_CITADEL, HEADERS_NONE, 0, 0, 0);
723 cprintf("%d No info file.\n", ERROR + FILE_NOT_FOUND);
729 * admin command: kill the current room
731 void cmd_kill(char *argbuf)
733 char deleted_room_name[ROOMNAMELEN];
737 kill_ok = extract_int(argbuf, 0);
739 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->room) == 0) {
740 cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
744 if (CC->room.QRflags & QR_MAILBOX) {
745 safestrncpy(deleted_room_name, &CC->room.QRname[11], sizeof deleted_room_name);
748 safestrncpy(deleted_room_name, CC->room.QRname, sizeof deleted_room_name);
751 /* Do the dirty work */
752 CtdlScheduleRoomForDeletion(&CC->room);
754 /* Return to the Lobby */
755 CtdlUserGoto(CtdlGetConfigStr("c_baseroom"), 0, 0, NULL, NULL, NULL, NULL);
757 /* tell the world what we did */
758 snprintf(msg, sizeof msg, "The room \"%s\" has been deleted by %s.\n",
760 (CC->logged_in ? CC->curr_user : "an administrator")
762 CtdlAideMessage(msg, "Room Purger Message");
763 cprintf("%d '%s' deleted.\n", CIT_OK, deleted_room_name);
765 cprintf("%d ok to delete.\n", CIT_OK);
773 void cmd_cre8(char *args)
776 char new_room_name[ROOMNAMELEN];
778 char new_room_pass[32];
781 char *notification_message = NULL;
784 int avoid_access = 0;
786 cre8_ok = extract_int(args, 0);
787 extract_token(new_room_name, args, 1, '|', sizeof new_room_name);
788 new_room_name[ROOMNAMELEN - 1] = 0;
789 new_room_type = extract_int(args, 2);
790 extract_token(new_room_pass, args, 3, '|', sizeof new_room_pass);
791 avoid_access = extract_int(args, 5);
792 new_room_view = extract_int(args, 6);
793 new_room_pass[9] = 0;
796 if ((IsEmptyStr(new_room_name)) && (cre8_ok == 1)) {
797 cprintf("%d Invalid room name.\n", ERROR + ILLEGAL_VALUE);
801 if (!strcasecmp(new_room_name, MAILROOM)) {
802 cprintf("%d '%s' already exists.\n",
803 ERROR + ALREADY_EXISTS, new_room_name);
807 if (num_parms(args) >= 5) {
808 fl = CtdlGetCachedFloor(extract_int(args, 4));
810 cprintf("%d Invalid floor number.\n",
811 ERROR + INVALID_FLOOR_OPERATION);
814 else if ((fl->f_flags & F_INUSE) == 0) {
815 cprintf("%d Invalid floor number.\n",
816 ERROR + INVALID_FLOOR_OPERATION);
819 new_room_floor = extract_int(args, 4);
823 if (CtdlAccessCheck(ac_logged_in)) return;
825 if (CC->user.axlevel < CtdlGetConfigInt("c_createax") && !CC->internal_pgm) {
826 cprintf("%d You need higher access to create rooms.\n",
827 ERROR + HIGHER_ACCESS_REQUIRED);
831 if ((IsEmptyStr(new_room_name)) && (cre8_ok == 0)) {
832 cprintf("%d Ok to create rooms.\n", CIT_OK);
836 if ((new_room_type < 0) || (new_room_type > 5)) {
837 cprintf("%d Invalid room type.\n", ERROR + ILLEGAL_VALUE);
841 if (new_room_type == 5) {
842 if (CC->user.axlevel < AxAideU) {
843 cprintf("%d Higher access required\n",
844 ERROR + HIGHER_ACCESS_REQUIRED);
849 /* Check to make sure the requested room name doesn't already exist */
850 newflags = CtdlCreateRoom(new_room_name,
851 new_room_type, new_room_pass, new_room_floor,
852 0, avoid_access, new_room_view);
854 cprintf("%d '%s' already exists.\n",
855 ERROR + ALREADY_EXISTS, new_room_name);
860 cprintf("%d OK to create '%s'\n", CIT_OK, new_room_name);
864 /* If we reach this point, the room needs to be created. */
866 newflags = CtdlCreateRoom(new_room_name,
867 new_room_type, new_room_pass, new_room_floor, 1, 0,
870 /* post a message in Aide> describing the new room */
871 notification_message = malloc(1024);
872 snprintf(notification_message, 1024,
873 "A new room called \"%s\" has been created by %s%s%s%s%s%s\n",
875 (CC->logged_in ? CC->curr_user : "an administrator"),
876 ((newflags & QR_MAILBOX) ? " [personal]" : ""),
877 ((newflags & QR_PRIVATE) ? " [private]" : ""),
878 ((newflags & QR_GUESSNAME) ? " [hidden]" : ""),
879 ((newflags & QR_PASSWORDED) ? " Password: " : ""),
880 ((newflags & QR_PASSWORDED) ? new_room_pass : "")
882 CtdlAideMessage(notification_message, "Room Creation Message");
883 free(notification_message);
885 cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
890 void cmd_einf(char *ok)
891 { /* enter info file for current room */
892 struct CitContext *CCC = CC;
894 char infofilename[SIZ];
899 if (CtdlAccessCheck(ac_room_aide)) return;
902 cprintf("%d Ok.\n", CIT_OK);
905 assoc_file_name(infofilename, sizeof infofilename, &CCC->room, ctdl_info_dir);
906 CTDL_syslog(LOG_DEBUG, "opening %s", infofilename);
907 fp = fopen(infofilename, "w");
908 CTDLM_syslog(LOG_DEBUG, "checking");
910 cprintf("%d Cannot open %s: %s\n",
911 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
914 cprintf("%d Send info...\n", SEND_LISTING);
917 client_getln(buf, sizeof buf);
918 if (strcmp(buf, "000"))
919 fprintf(fp, "%s\n", buf);
920 } while (strcmp(buf, "000"));
923 /* now update the room index so people will see our new info */
924 CtdlGetRoomLock(&CCC->room, CCC->room.QRname); /* lock so no one steps on us */
925 CtdlPutRoomLock(&CCC->room);
930 * cmd_lflr() - List all known floors
932 void cmd_lflr(char *gargs)
937 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
939 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
941 for (a = 0; a < MAXFLOORS; ++a) {
942 CtdlGetFloor(&flbuf, a);
943 if (flbuf.f_flags & F_INUSE) {
944 cprintf("%d|%s|%d\n",
958 void cmd_cflr(char *argbuf)
960 char new_floor_name[256];
963 int free_slot = (-1);
966 extract_token(new_floor_name, argbuf, 0, '|', sizeof new_floor_name);
967 cflr_ok = extract_int(argbuf, 1);
969 if (CtdlAccessCheck(ac_aide)) return;
971 if (IsEmptyStr(new_floor_name)) {
972 cprintf("%d Blank floor name not allowed.\n",
973 ERROR + ILLEGAL_VALUE);
977 for (a = 0; a < MAXFLOORS; ++a) {
978 CtdlGetFloor(&flbuf, a);
980 /* note any free slots while we're scanning... */
981 if (((flbuf.f_flags & F_INUSE) == 0)
985 /* check to see if it already exists */
986 if ((!strcasecmp(flbuf.f_name, new_floor_name))
987 && (flbuf.f_flags & F_INUSE)) {
988 cprintf("%d Floor '%s' already exists.\n",
989 ERROR + ALREADY_EXISTS,
996 cprintf("%d There is no space available for a new floor.\n",
997 ERROR + INVALID_FLOOR_OPERATION);
1001 cprintf("%d ok to create...\n", CIT_OK);
1004 lgetfloor(&flbuf, free_slot);
1005 flbuf.f_flags = F_INUSE;
1006 flbuf.f_ref_count = 0;
1007 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1008 lputfloor(&flbuf, free_slot);
1009 cprintf("%d %d\n", CIT_OK, free_slot);
1017 void cmd_kflr(char *argbuf)
1020 int floor_to_delete;
1024 floor_to_delete = extract_int(argbuf, 0);
1025 kflr_ok = extract_int(argbuf, 1);
1027 if (CtdlAccessCheck(ac_aide)) return;
1029 lgetfloor(&flbuf, floor_to_delete);
1032 if ((flbuf.f_flags & F_INUSE) == 0) {
1033 cprintf("%d Floor %d not in use.\n",
1034 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1037 if (flbuf.f_ref_count != 0) {
1038 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1039 ERROR + INVALID_FLOOR_OPERATION,
1044 cprintf("%d Ok\n", CIT_OK);
1046 cprintf("%d Ok to delete...\n", CIT_OK);
1053 if ((delete_ok == 1) && (kflr_ok == 1))
1055 lputfloor(&flbuf, floor_to_delete);
1061 void cmd_eflr(char *argbuf)
1067 np = num_parms(argbuf);
1069 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
1073 if (CtdlAccessCheck(ac_aide)) return;
1075 floor_num = extract_int(argbuf, 0);
1076 lgetfloor(&flbuf, floor_num);
1077 if ((flbuf.f_flags & F_INUSE) == 0) {
1078 lputfloor(&flbuf, floor_num);
1079 cprintf("%d Floor %d is not in use.\n",
1080 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1084 extract_token(flbuf.f_name, argbuf, 1, '|', sizeof flbuf.f_name);
1085 lputfloor(&flbuf, floor_num);
1087 cprintf("%d Ok\n", CIT_OK);
1093 * cmd_stat() - return the modification time of the current room (maybe other things in the future)
1095 void cmd_stat(char *gargs)
1097 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
1098 CtdlGetRoom(&CC->room, CC->room.QRname);
1099 cprintf("%d %s|%ld|\n", CIT_OK, CC->room.QRname, CC->room.QRmtime);
1105 /*****************************************************************************/
1106 /* MODULE INITIALIZATION STUFF */
1107 /*****************************************************************************/
1109 CTDL_MODULE_INIT(rooms)
1112 CtdlRegisterProtoHook(cmd_lrms, "LRMS", "List rooms");
1113 CtdlRegisterProtoHook(cmd_lkra, "LKRA", "List all known rooms");
1114 CtdlRegisterProtoHook(cmd_lkrn, "LKRN", "List known rooms with new messages");
1115 CtdlRegisterProtoHook(cmd_lkro, "LKRO", "List known rooms without new messages");
1116 CtdlRegisterProtoHook(cmd_lzrm, "LZRM", "List zapped rooms");
1117 CtdlRegisterProtoHook(cmd_lprm, "LPRM", "List public rooms");
1118 CtdlRegisterProtoHook(cmd_goto, "GOTO", "Goto a named room");
1119 CtdlRegisterProtoHook(cmd_stat, "STAT", "Get mtime of the current room");
1120 CtdlRegisterProtoHook(cmd_whok, "WHOK", "List users who know this room");
1121 CtdlRegisterProtoHook(cmd_rdir, "RDIR", "List files in room directory");
1122 CtdlRegisterProtoHook(cmd_getr, "GETR", "Get room parameters");
1123 CtdlRegisterProtoHook(cmd_setr, "SETR", "Set room parameters");
1124 CtdlRegisterProtoHook(cmd_geta, "GETA", "Get the room admin name");
1125 CtdlRegisterProtoHook(cmd_seta, "SETA", "Set the room admin for this room");
1126 CtdlRegisterProtoHook(cmd_rinf, "RINF", "Fetch room info file");
1127 CtdlRegisterProtoHook(cmd_kill, "KILL", "Kill (delete) the current room");
1128 CtdlRegisterProtoHook(cmd_cre8, "CRE8", "Create a new room");
1129 CtdlRegisterProtoHook(cmd_einf, "EINF", "Enter info file for the current room");
1130 CtdlRegisterProtoHook(cmd_lflr, "LFLR", "List all known floors");
1131 CtdlRegisterProtoHook(cmd_cflr, "CFLR", "Create a new floor");
1132 CtdlRegisterProtoHook(cmd_kflr, "KFLR", "Kill a floor");
1133 CtdlRegisterProtoHook(cmd_eflr, "EFLR", "Edit a floor");
1135 /* return our Subversion id for the Log */