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"
23 #include "../../room_ops.h"
24 #include "../../config.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 ctdlroom QRscratch;
243 char augmented_roomname[ROOMNAMELEN];
244 char towhere[ROOMNAMELEN];
248 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
250 extract_token(towhere, gargs, 0, '|', sizeof towhere);
251 extract_token(password, gargs, 1, '|', sizeof password);
252 transiently = extract_int(gargs, 2);
254 CtdlGetUser(&CC->user, CC->curr_user);
256 // Handle some of the macro named rooms
257 convert_room_name_macros(towhere, sizeof towhere);
259 // First try a regular match
260 c = CtdlGetRoom(&QRscratch, towhere);
262 // Then try a mailbox name match
264 CtdlMailboxName(augmented_roomname, sizeof augmented_roomname, &CC->user, towhere);
265 c = CtdlGetRoom(&QRscratch, augmented_roomname);
267 safestrncpy(towhere, augmented_roomname, sizeof towhere);
271 // And if the room was found...
273 // Let internal programs go directly to any room.
274 if (CC->internal_pgm) {
275 memcpy(&CC->room, &QRscratch, sizeof(struct ctdlroom));
276 CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
280 // See if there is an existing user/room relationship
281 CtdlRoomAccess(&QRscratch, &CC->user, &ra, NULL);
283 // normal clients have to pass through security
284 if (ra & UA_GOTOALLOWED) {
289 if ((QRscratch.QRflags & QR_MAILBOX) &&
290 ((ra & UA_GOTOALLOWED))) {
291 memcpy(&CC->room, &QRscratch, sizeof(struct ctdlroom));
292 CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
295 else if ((QRscratch.QRflags & QR_PASSWORDED) &&
296 ((ra & UA_KNOWN) == 0) &&
297 (strcasecmp(QRscratch.QRpasswd, password)) &&
298 (CC->user.axlevel < AxAideU)
300 cprintf("%d wrong or missing passwd\n", ERROR + PASSWORD_REQUIRED);
303 else if ((QRscratch.QRflags & QR_PRIVATE) &&
304 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
305 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
306 ((ra & UA_KNOWN) == 0) &&
307 (CC->user.axlevel < AxAideU)
309 syslog(LOG_DEBUG, "rooms: failed to acquire private room");
312 memcpy(&CC->room, &QRscratch, sizeof(struct ctdlroom));
313 CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
319 cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
323 void cmd_whok(char *cmdbuf) {
324 struct ctdluser temp;
325 struct cdbdata cdbus;
328 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
329 cdb_rewind(CDB_USERS);
330 while (cdbus = cdb_next_item(CDB_USERS), cdbus.len>0) {
331 memset(&temp, 0, sizeof temp);
332 memcpy(&temp, cdbus.ptr, sizeof temp);
334 CtdlRoomAccess(&CC->room, &temp, &ra, NULL);
335 if ((!IsEmptyStr(temp.fullname)) &&
336 (CC->room.QRflags & QR_INUSE) &&
339 cprintf("%s\n", temp.fullname);
345 // RDIR command for room directory
346 void cmd_rdir(char *cmdbuf) {
352 struct dirent *filedir_entry;
358 if (CtdlAccessCheck(ac_logged_in)) return;
360 CtdlGetRoom(&CC->room, CC->room.QRname);
361 CtdlGetUser(&CC->user, CC->curr_user);
363 if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
364 cprintf("%d not here.\n", ERROR + NOT_HERE);
367 if (((CC->room.QRflags & QR_VISDIR) == 0)
368 && (CC->user.axlevel < AxAideU)
369 && (CC->user.usernum != CC->room.QRroomaide))
371 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
375 snprintf(buf, sizeof buf, "%s/%s", ctdl_file_dir, CC->room.QRdirname);
376 filedir = opendir (buf);
378 if (filedir == NULL) {
379 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
382 cprintf("%d %s|%s/%s\n", LISTING_FOLLOWS, CtdlGetConfigStr("c_fqdn"), ctdl_file_dir, CC->room.QRdirname);
384 snprintf(buf, sizeof buf, "%s/%s/filedir", ctdl_file_dir, CC->room.QRdirname);
385 fd = fopen(buf, "r");
387 fd = fopen("/dev/null", "r");
389 while ((filedir_entry = readdir(filedir))) {
390 if (strcasecmp(filedir_entry->d_name, "filedir") && filedir_entry->d_name[0] != '.') {
391 #ifdef _DIRENT_HAVE_D_NAMELEN
392 d_namelen = filedir_entry->d_namlen;
394 d_namelen = strlen(filedir_entry->d_name);
396 snprintf(buf, sizeof buf, "%s/%s/%s", ctdl_file_dir, CC->room.QRdirname, filedir_entry->d_name);
397 stat(buf, &statbuf); /* stat the file */
398 if (!(statbuf.st_mode & S_IFREG)) {
399 snprintf(buf2, sizeof buf2,
400 "\"%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",
403 CtdlAideMessage(buf2, "Unusable data found in room directory");
404 continue; /* not a useable file type so don't show it */
406 safestrncpy(comment, "", sizeof comment);
407 fseek(fd, 0L, 0); /* rewind descriptions file */
408 /* Get the description from the descriptions file */
409 while ((fgets(buf, sizeof buf, fd) != NULL) && (IsEmptyStr(comment))) {
410 buf[strlen(buf) - 1] = 0;
411 if ((!strncasecmp(buf, filedir_entry->d_name, d_namelen)) && (buf[d_namelen] == ' '))
412 safestrncpy(comment, &buf[d_namelen + 1], sizeof comment);
414 len = extract_token (mimebuf, comment, 0,' ', 64);
415 if ((len <0) || strchr(mimebuf, '/') == NULL) {
416 snprintf (mimebuf, 64, "application/octetstream");
419 cprintf("%s|%ld|%s|%s\n",
420 filedir_entry->d_name,
421 (long)statbuf.st_size,
433 // get room parameters (admin or room admin command)
434 void cmd_getr(char *cmdbuf) {
435 if (CtdlAccessCheck(ac_room_aide)) return;
437 CtdlGetRoom(&CC->room, CC->room.QRname);
438 cprintf("%d%c%s|%s|%s|%d|%d|%d|%d|%d|\n",
441 ((CC->room.QRflags & QR_MAILBOX) ? &CC->room.QRname[11] : CC->room.QRname),
442 ((CC->room.QRflags & QR_PASSWORDED) ? CC->room.QRpasswd : ""),
443 ((CC->room.QRflags & QR_DIRECTORY) ? CC->room.QRdirname : ""),
445 (int) CC->room.QRfloor,
446 (int) CC->room.QRorder,
447 CC->room.QRdefaultview,
453 // set room parameters (admin or room admin command)
454 void cmd_setr(char *args) {
459 char new_name[ROOMNAMELEN];
461 if (CtdlAccessCheck(ac_logged_in)) return;
463 if (num_parms(args) >= 6) {
464 new_floor = extract_int(args, 5);
467 new_floor = (-1); /* don't change the floor */
470 /* When is a new name more than just a new name? When the old name
471 * has a namespace prefix.
473 if (CC->room.QRflags & QR_MAILBOX) {
474 sprintf(new_name, "%010ld.", atol(CC->room.QRname) );
477 safestrncpy(new_name, "", sizeof new_name);
479 extract_token(&new_name[strlen(new_name)], args, 0, '|', (sizeof new_name - strlen(new_name)));
481 r = CtdlRenameRoom(CC->room.QRname, new_name, new_floor);
483 if (r == crr_room_not_found) {
484 cprintf("%d Internal error - room not found?\n", ERROR + INTERNAL_ERROR);
486 else if (r == crr_already_exists) {
487 cprintf("%d '%s' already exists.\n",
488 ERROR + ALREADY_EXISTS, new_name);
490 else if (r == crr_noneditable) {
491 cprintf("%d Cannot edit this room.\n", ERROR + NOT_HERE);
493 else if (r == crr_invalid_floor) {
494 cprintf("%d Target floor does not exist.\n",
495 ERROR + INVALID_FLOOR_OPERATION);
497 else if (r == crr_access_denied) {
498 cprintf("%d You do not have permission to edit '%s'\n",
499 ERROR + HIGHER_ACCESS_REQUIRED,
502 else if (r != crr_ok) {
503 cprintf("%d Error: CtdlRenameRoom() returned %d\n",
504 ERROR + INTERNAL_ERROR, r);
511 CtdlGetRoom(&CC->room, new_name);
513 /* Now we have to do a bunch of other stuff */
515 if (num_parms(args) >= 7) {
516 new_order = extract_int(args, 6);
523 CtdlGetRoomLock(&CC->room, CC->room.QRname);
526 extract_token(buf, args, 2, '|', sizeof buf);
528 safestrncpy(CC->room.QRdirname, buf,
529 sizeof CC->room.QRdirname);
532 if (num_parms(args) >= 8) {
533 CC->room.QRdefaultview = extract_int(args, 7);
536 /* Second set of flags */
537 if (num_parms(args) >= 9) {
538 CC->room.QRflags2 = extract_int(args, 8);
542 CC->room.QRflags = (extract_int(args, 3) | QR_INUSE);
543 /* Clean up a client boo-boo: if the client set the room to
544 * guess-name or passworded, ensure that the private flag is
547 if ((CC->room.QRflags & QR_GUESSNAME)
548 || (CC->room.QRflags & QR_PASSWORDED))
549 CC->room.QRflags |= QR_PRIVATE;
551 /* Some changes can't apply to BASEROOM */
552 if (!strncasecmp(CC->room.QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)) {
553 CC->room.QRorder = 0;
554 CC->room.QRpasswd[0] = '\0';
555 CC->room.QRflags &= ~(QR_PRIVATE & QR_PASSWORDED &
556 QR_GUESSNAME & QR_PREFONLY & QR_MAILBOX);
557 CC->room.QRflags |= QR_PERMANENT;
560 /* March order (doesn't apply to AIDEROOM) */
561 if (num_parms(args) >= 7)
562 CC->room.QRorder = (char) new_order;
564 extract_token(buf, args, 1, '|', sizeof buf);
566 safestrncpy(CC->room.QRpasswd, buf, sizeof CC->room.QRpasswd);
567 /* Kick everyone out if the client requested it
568 * (by changing the room's generation number)
570 if (extract_int(args, 4)) {
571 time(&CC->room.QRgen);
574 /* Some changes can't apply to AIDEROOM */
575 if (!strncasecmp(CC->room.QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)) {
576 CC->room.QRorder = 0;
577 CC->room.QRflags &= ~QR_MAILBOX;
578 CC->room.QRflags |= QR_PERMANENT;
581 /* Write the room record back to disk */
582 CtdlPutRoomLock(&CC->room);
584 /* Create a room directory if necessary */
585 if (CC->room.QRflags & QR_DIRECTORY) {
586 snprintf(buf, sizeof buf,"%s/%s", ctdl_file_dir, CC->room.QRdirname);
589 snprintf(buf, sizeof buf, "The room \"%s\" has been edited by %s.\n",
591 (CC->logged_in ? CC->curr_user : "an administrator")
593 CtdlAideMessage(buf, "Room modification Message");
594 cprintf("%d Ok\n", CIT_OK);
598 // get the name of the room admin for this room
599 void cmd_geta(char *cmdbuf) {
600 struct ctdluser usbuf;
602 if (CtdlAccessCheck(ac_logged_in)) return;
604 if (CtdlGetUserByNumber(&usbuf, CC->room.QRroomaide) == 0) {
605 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
608 cprintf("%d \n", CIT_OK);
613 // set the room admin for this room
614 void cmd_seta(char *new_ra) {
615 struct ctdluser usbuf;
620 if (CtdlAccessCheck(ac_room_aide)) return;
622 if (CtdlGetUser(&usbuf, new_ra) != 0) {
626 newu = usbuf.usernum;
629 CtdlGetRoomLock(&CC->room, CC->room.QRname);
631 if (CC->room.QRroomaide != newu) {
634 CC->room.QRroomaide = newu;
635 CtdlPutRoomLock(&CC->room);
637 // We have to post the change notice _after_ writing changes to
638 // the room table, otherwise it would deadlock!
639 if (post_notice == 1) {
640 if (!IsEmptyStr(usbuf.fullname))
641 snprintf(buf, sizeof buf,
642 "%s is now the room admin for \"%s\".\n",
643 usbuf.fullname, CC->room.QRname);
645 snprintf(buf, sizeof buf,
646 "There is now no room admin for \"%s\".\n",
648 CtdlAideMessage(buf, "Admin Room Modification");
650 cprintf("%d Ok\n", CIT_OK);
654 // Retrieve info file for this room (this ought to be upgraded to handle non-plain-text)
655 void cmd_rinf(char *argbuf) {
656 struct CtdlMessage *msg = CtdlFetchMessage(CC->room.msgnum_info, 1);
658 cprintf("%d Info:\n", LISTING_FOLLOWS);
659 CtdlOutputPreLoadedMsg(msg, MT_CITADEL, HEADERS_NONE, 0, 0, 0);
664 cprintf("%d No info file.\n", ERROR + FILE_NOT_FOUND);
669 // admin command: kill the current room
670 void cmd_kill(char *argbuf) {
671 char deleted_room_name[ROOMNAMELEN];
675 kill_ok = extract_int(argbuf, 0);
677 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->room) == 0) {
678 cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
682 if (CC->room.QRflags & QR_MAILBOX) {
683 safestrncpy(deleted_room_name, &CC->room.QRname[11], sizeof deleted_room_name);
686 safestrncpy(deleted_room_name, CC->room.QRname, sizeof deleted_room_name);
689 /* Do the dirty work */
690 CtdlScheduleRoomForDeletion(&CC->room);
692 /* Return to the Lobby */
693 CtdlUserGoto(CtdlGetConfigStr("c_baseroom"), 0, 0, NULL, NULL, NULL, NULL);
695 /* tell the world what we did */
696 snprintf(msg, sizeof msg, "The room \"%s\" has been deleted by %s.\n",
698 (CC->logged_in ? CC->curr_user : "an administrator")
700 CtdlAideMessage(msg, "Room Purger Message");
701 cprintf("%d '%s' deleted.\n", CIT_OK, deleted_room_name);
704 cprintf("%d ok to delete.\n", CIT_OK);
710 void cmd_cre8(char *args) {
712 char new_room_name[ROOMNAMELEN];
714 char new_room_pass[32];
717 char *notification_message = NULL;
720 int avoid_access = 0;
722 cre8_ok = extract_int(args, 0);
723 extract_token(new_room_name, args, 1, '|', sizeof new_room_name);
724 new_room_name[ROOMNAMELEN - 1] = 0;
725 new_room_type = extract_int(args, 2);
726 extract_token(new_room_pass, args, 3, '|', sizeof new_room_pass);
727 avoid_access = extract_int(args, 5);
728 new_room_view = extract_int(args, 6);
729 new_room_pass[9] = 0;
732 if ((IsEmptyStr(new_room_name)) && (cre8_ok == 1)) {
733 cprintf("%d Invalid room name.\n", ERROR + ILLEGAL_VALUE);
737 if (!strcasecmp(new_room_name, MAILROOM)) {
738 cprintf("%d '%s' already exists.\n",
739 ERROR + ALREADY_EXISTS, new_room_name);
743 if (num_parms(args) >= 5) {
744 fl = CtdlGetCachedFloor(extract_int(args, 4));
746 cprintf("%d Invalid floor number.\n",
747 ERROR + INVALID_FLOOR_OPERATION);
750 else if ((fl->f_flags & F_INUSE) == 0) {
751 cprintf("%d Invalid floor number.\n",
752 ERROR + INVALID_FLOOR_OPERATION);
755 new_room_floor = extract_int(args, 4);
759 if (CtdlAccessCheck(ac_logged_in)) return;
761 if (CC->user.axlevel < CtdlGetConfigInt("c_createax") && !CC->internal_pgm) {
762 cprintf("%d You need higher access to create rooms.\n",
763 ERROR + HIGHER_ACCESS_REQUIRED);
767 if ((IsEmptyStr(new_room_name)) && (cre8_ok == 0)) {
768 cprintf("%d Ok to create rooms.\n", CIT_OK);
772 if ((new_room_type < 0) || (new_room_type > 5)) {
773 cprintf("%d Invalid room type.\n", ERROR + ILLEGAL_VALUE);
777 if (new_room_type == 5) {
778 if (CC->user.axlevel < AxAideU) {
779 cprintf("%d Higher access required\n",
780 ERROR + HIGHER_ACCESS_REQUIRED);
785 /* Check to make sure the requested room name doesn't already exist */
786 newflags = CtdlCreateRoom(new_room_name,
787 new_room_type, new_room_pass, new_room_floor,
788 0, avoid_access, new_room_view);
790 cprintf("%d '%s' already exists.\n",
791 ERROR + ALREADY_EXISTS, new_room_name);
796 cprintf("%d OK to create '%s'\n", CIT_OK, new_room_name);
800 /* If we reach this point, the room needs to be created. */
802 newflags = CtdlCreateRoom(new_room_name,
803 new_room_type, new_room_pass, new_room_floor, 1, 0,
806 /* post a message in Aide> describing the new room */
807 notification_message = malloc(1024);
808 snprintf(notification_message, 1024,
809 "A new room called \"%s\" has been created by %s%s%s%s%s%s\n",
811 (CC->logged_in ? CC->curr_user : "an administrator"),
812 ((newflags & QR_MAILBOX) ? " [personal]" : ""),
813 ((newflags & QR_PRIVATE) ? " [private]" : ""),
814 ((newflags & QR_GUESSNAME) ? " [hidden]" : ""),
815 ((newflags & QR_PASSWORDED) ? " Password: " : ""),
816 ((newflags & QR_PASSWORDED) ? new_room_pass : "")
818 CtdlAideMessage(notification_message, "Room Creation Message");
819 free(notification_message);
821 cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
825 // Upload the room banner text for this room.
826 // This should be amended to handle content types other than plain text.
827 void cmd_einf(char *ok) { /* enter info file for current room */
831 if (CtdlAccessCheck(ac_room_aide)) return;
834 cprintf("%d Ok.\n", CIT_OK);
838 StrBuf *NewBanner = NewStrBufPlain("Content-type: text/plain; charset=UTF-8\nContent-transfer-encoding: 8bit\n\n", -1);
840 cprintf("%d Transmit new banner in plain text now.\n", SEND_LISTING);
841 while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
842 StrBufAppendBufPlain(NewBanner, buf, -1, 0);
843 StrBufAppendBufPlain(NewBanner, HKEY("\n"), 0);
846 // We have read the new banner from the user , now save it
847 long new_msgnum = quickie_message("Citadel", NULL, NULL, SYSCONFIGROOM, ChrPtr(NewBanner), FMT_RFC822, "Banner submitted with EINF command");
848 FreeStrBuf(&NewBanner);
850 // Update the room record with a pointer to our new banner
851 CtdlGetRoomLock(&CC->room, CC->room.QRname);
852 long old_msgnum = CC->room.msgnum_info;
853 CC->room.msgnum_info = new_msgnum;
854 CtdlPutRoomLock(&CC->room);
856 // Delete the old one
857 CtdlDeleteMessages(SYSCONFIGROOM, &old_msgnum, 1, "");
861 // cmd_lflr() - List all known floors
862 void cmd_lflr(char *gargs) {
866 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
868 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
870 for (a = 0; a < MAXFLOORS; ++a) {
871 CtdlGetFloor(&flbuf, a);
872 if (flbuf.f_flags & F_INUSE) {
873 cprintf("%d|%s|%d\n", a, flbuf.f_name, flbuf.f_ref_count);
880 // create a new floor
881 void cmd_cflr(char *argbuf) {
882 char new_floor_name[256];
885 int free_slot = (-1);
888 extract_token(new_floor_name, argbuf, 0, '|', sizeof new_floor_name);
889 cflr_ok = extract_int(argbuf, 1);
891 if (CtdlAccessCheck(ac_aide)) return;
893 if (IsEmptyStr(new_floor_name)) {
894 cprintf("%d Blank floor name not allowed.\n",
895 ERROR + ILLEGAL_VALUE);
899 for (a = 0; a < MAXFLOORS; ++a) {
900 CtdlGetFloor(&flbuf, a);
902 /* note any free slots while we're scanning... */
903 if (((flbuf.f_flags & F_INUSE) == 0)
907 /* check to see if it already exists */
908 if ((!strcasecmp(flbuf.f_name, new_floor_name))
909 && (flbuf.f_flags & F_INUSE)) {
910 cprintf("%d Floor '%s' already exists.\n",
911 ERROR + ALREADY_EXISTS,
918 cprintf("%d There is no space available for a new floor.\n",
919 ERROR + INVALID_FLOOR_OPERATION);
923 cprintf("%d ok to create...\n", CIT_OK);
926 lgetfloor(&flbuf, free_slot);
927 flbuf.f_flags = F_INUSE;
928 flbuf.f_ref_count = 0;
929 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
930 lputfloor(&flbuf, free_slot);
931 cprintf("%d %d\n", CIT_OK, free_slot);
936 void cmd_kflr(char *argbuf) {
942 floor_to_delete = extract_int(argbuf, 0);
943 kflr_ok = extract_int(argbuf, 1);
945 if (CtdlAccessCheck(ac_aide)) return;
947 lgetfloor(&flbuf, floor_to_delete);
950 if ((flbuf.f_flags & F_INUSE) == 0) {
951 cprintf("%d Floor %d not in use.\n", ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
954 if (flbuf.f_ref_count != 0) {
955 cprintf("%d Cannot delete; floor contains %d rooms.\n",
956 ERROR + INVALID_FLOOR_OPERATION,
962 cprintf("%d Ok\n", CIT_OK);
965 cprintf("%d Ok to delete...\n", CIT_OK);
972 if ((delete_ok == 1) && (kflr_ok == 1)) {
975 lputfloor(&flbuf, floor_to_delete);
980 void cmd_eflr(char *argbuf) {
985 np = num_parms(argbuf);
987 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
991 if (CtdlAccessCheck(ac_aide)) return;
993 floor_num = extract_int(argbuf, 0);
994 lgetfloor(&flbuf, floor_num);
995 if ((flbuf.f_flags & F_INUSE) == 0) {
996 lputfloor(&flbuf, floor_num);
997 cprintf("%d Floor %d is not in use.\n", ERROR + INVALID_FLOOR_OPERATION, floor_num);
1001 extract_token(flbuf.f_name, argbuf, 1, '|', sizeof flbuf.f_name);
1003 lputfloor(&flbuf, floor_num);
1005 cprintf("%d Ok\n", CIT_OK);
1009 // cmd_stat() - return the modification time of the current room (maybe other things in the future)
1010 void cmd_stat(char *gargs) {
1011 if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
1012 CtdlGetRoom(&CC->room, CC->room.QRname);
1013 cprintf("%d %s|%ld|\n", CIT_OK, CC->room.QRname, CC->room.QRmtime);
1017 // Initialization function, called from modules_init.c
1018 char *ctdl_module_init_rooms(void) {
1020 CtdlRegisterProtoHook(cmd_lrms, "LRMS", "List rooms");
1021 CtdlRegisterProtoHook(cmd_lkra, "LKRA", "List all known rooms");
1022 CtdlRegisterProtoHook(cmd_lkrn, "LKRN", "List known rooms with new messages");
1023 CtdlRegisterProtoHook(cmd_lkro, "LKRO", "List known rooms without new messages");
1024 CtdlRegisterProtoHook(cmd_lzrm, "LZRM", "List zapped rooms");
1025 CtdlRegisterProtoHook(cmd_lprm, "LPRM", "List public rooms");
1026 CtdlRegisterProtoHook(cmd_goto, "GOTO", "Goto a named room");
1027 CtdlRegisterProtoHook(cmd_stat, "STAT", "Get mtime of the current room");
1028 CtdlRegisterProtoHook(cmd_whok, "WHOK", "List users who know this room");
1029 CtdlRegisterProtoHook(cmd_rdir, "RDIR", "List files in room directory");
1030 CtdlRegisterProtoHook(cmd_getr, "GETR", "Get room parameters");
1031 CtdlRegisterProtoHook(cmd_setr, "SETR", "Set room parameters");
1032 CtdlRegisterProtoHook(cmd_geta, "GETA", "Get the room admin name");
1033 CtdlRegisterProtoHook(cmd_seta, "SETA", "Set the room admin for this room");
1034 CtdlRegisterProtoHook(cmd_rinf, "RINF", "Fetch room info file");
1035 CtdlRegisterProtoHook(cmd_kill, "KILL", "Kill (delete) the current room");
1036 CtdlRegisterProtoHook(cmd_cre8, "CRE8", "Create a new room");
1037 CtdlRegisterProtoHook(cmd_einf, "EINF", "Enter info file for the current room");
1038 CtdlRegisterProtoHook(cmd_lflr, "LFLR", "List all known floors");
1039 CtdlRegisterProtoHook(cmd_cflr, "CFLR", "Create a new floor");
1040 CtdlRegisterProtoHook(cmd_kflr, "KFLR", "Kill a floor");
1041 CtdlRegisterProtoHook(cmd_eflr, "EFLR", "Edit a floor");
1043 /* return our id for the log */