-
-
-/*
- * create a new room
- */
-void cmd_cre8(char *args)
-{
- int cre8_ok;
- char new_room_name[ROOMNAMELEN];
- int new_room_type;
- char new_room_pass[32];
- int new_room_floor;
- int new_room_view;
- char *notification_message = NULL;
- unsigned newflags;
- struct floor *fl;
- int avoid_access = 0;
-
- cre8_ok = extract_int(args, 0);
- extract_token(new_room_name, args, 1, '|', sizeof new_room_name);
- new_room_name[ROOMNAMELEN - 1] = 0;
- new_room_type = extract_int(args, 2);
- extract_token(new_room_pass, args, 3, '|', sizeof new_room_pass);
- avoid_access = extract_int(args, 5);
- new_room_view = extract_int(args, 6);
- new_room_pass[9] = 0;
- new_room_floor = 0;
-
- if ((IsEmptyStr(new_room_name)) && (cre8_ok == 1)) {
- cprintf("%d Invalid room name.\n", ERROR + ILLEGAL_VALUE);
- return;
- }
-
- if (!strcasecmp(new_room_name, MAILROOM)) {
- cprintf("%d '%s' already exists.\n",
- ERROR + ALREADY_EXISTS, new_room_name);
- return;
- }
-
- if (num_parms(args) >= 5) {
- fl = CtdlGetCachedFloor(extract_int(args, 4));
- if (fl == NULL) {
- cprintf("%d Invalid floor number.\n",
- ERROR + INVALID_FLOOR_OPERATION);
- return;
- }
- else if ((fl->f_flags & F_INUSE) == 0) {
- cprintf("%d Invalid floor number.\n",
- ERROR + INVALID_FLOOR_OPERATION);
- return;
- } else {
- new_room_floor = extract_int(args, 4);
- }
- }
-
- if (CtdlAccessCheck(ac_logged_in)) return;
-
- if (CC->user.axlevel < config.c_createax && !CC->internal_pgm) {
- cprintf("%d You need higher access to create rooms.\n",
- ERROR + HIGHER_ACCESS_REQUIRED);
- return;
- }
-
- if ((IsEmptyStr(new_room_name)) && (cre8_ok == 0)) {
- cprintf("%d Ok to create rooms.\n", CIT_OK);
- return;
- }
-
- if ((new_room_type < 0) || (new_room_type > 5)) {
- cprintf("%d Invalid room type.\n", ERROR + ILLEGAL_VALUE);
- return;
- }
-
- if (new_room_type == 5) {
- if (CC->user.axlevel < AxAideU) {
- cprintf("%d Higher access required\n",
- ERROR + HIGHER_ACCESS_REQUIRED);
- return;
- }
- }
-
- /* Check to make sure the requested room name doesn't already exist */
- newflags = CtdlCreateRoom(new_room_name,
- new_room_type, new_room_pass, new_room_floor,
- 0, avoid_access, new_room_view);
- if (newflags == 0) {
- cprintf("%d '%s' already exists.\n",
- ERROR + ALREADY_EXISTS, new_room_name);
- return;
- }
-
- if (cre8_ok == 0) {
- cprintf("%d OK to create '%s'\n", CIT_OK, new_room_name);
- return;
- }
-
- /* If we reach this point, the room needs to be created. */
-
- newflags = CtdlCreateRoom(new_room_name,
- new_room_type, new_room_pass, new_room_floor, 1, 0,
- new_room_view);
-
- /* post a message in Aide> describing the new room */
- notification_message = malloc(1024);
- snprintf(notification_message, 1024,
- "A new room called \"%s\" has been created by %s%s%s%s%s%s\n",
- new_room_name,
- (CC->logged_in ? CC->curr_user : "an administrator"),
- ((newflags & QR_MAILBOX) ? " [personal]" : ""),
- ((newflags & QR_PRIVATE) ? " [private]" : ""),
- ((newflags & QR_GUESSNAME) ? " [hidden]" : ""),
- ((newflags & QR_PASSWORDED) ? " Password: " : ""),
- ((newflags & QR_PASSWORDED) ? new_room_pass : "")
- );
- CtdlAideMessage(notification_message, "Room Creation Message");
- free(notification_message);
-
- cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
-}
-
-
-
-void cmd_einf(char *ok)
-{ /* enter info file for current room */
- FILE *fp;
- char infofilename[SIZ];
- char buf[SIZ];
-
- unbuffer_output();
-
- if (CtdlAccessCheck(ac_room_aide)) return;
-
- if (atoi(ok) == 0) {
- cprintf("%d Ok.\n", CIT_OK);
- return;
- }
- assoc_file_name(infofilename, sizeof infofilename, &CC->room, ctdl_info_dir);
- syslog(LOG_DEBUG, "opening\n");
- fp = fopen(infofilename, "w");
- syslog(LOG_DEBUG, "checking\n");
- if (fp == NULL) {
- cprintf("%d Cannot open %s: %s\n",
- ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
- return;
- }
- cprintf("%d Send info...\n", SEND_LISTING);
-
- do {
- client_getln(buf, sizeof buf);
- if (strcmp(buf, "000"))
- fprintf(fp, "%s\n", buf);
- } while (strcmp(buf, "000"));
- fclose(fp);
-
- /* now update the room index so people will see our new info */
- CtdlGetRoomLock(&CC->room, CC->room.QRname); /* lock so no one steps on us */
- CC->room.QRinfo = CC->room.QRhighest + 1L;
- CtdlPutRoomLock(&CC->room);
-}
-
-
-/*
- * cmd_lflr() - List all known floors
- */
-void cmd_lflr(char *gargs)
-{
- int a;
- struct floor flbuf;
-
- if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
-
- cprintf("%d Known floors:\n", LISTING_FOLLOWS);
-
- for (a = 0; a < MAXFLOORS; ++a) {
- CtdlGetFloor(&flbuf, a);
- if (flbuf.f_flags & F_INUSE) {
- cprintf("%d|%s|%d\n",
- a,
- flbuf.f_name,
- flbuf.f_ref_count);
- }
- }
- cprintf("000\n");
-}
-
-
-
-/*
- * create a new floor
- */
-void cmd_cflr(char *argbuf)
-{
- char new_floor_name[256];
- struct floor flbuf;
- int cflr_ok;
- int free_slot = (-1);
- int a;
-
- extract_token(new_floor_name, argbuf, 0, '|', sizeof new_floor_name);
- cflr_ok = extract_int(argbuf, 1);
-
- if (CtdlAccessCheck(ac_aide)) return;
-
- if (IsEmptyStr(new_floor_name)) {
- cprintf("%d Blank floor name not allowed.\n",
- ERROR + ILLEGAL_VALUE);
- return;
- }
-
- for (a = 0; a < MAXFLOORS; ++a) {
- CtdlGetFloor(&flbuf, a);
-
- /* note any free slots while we're scanning... */
- if (((flbuf.f_flags & F_INUSE) == 0)
- && (free_slot < 0))
- free_slot = a;
-
- /* check to see if it already exists */
- if ((!strcasecmp(flbuf.f_name, new_floor_name))
- && (flbuf.f_flags & F_INUSE)) {
- cprintf("%d Floor '%s' already exists.\n",
- ERROR + ALREADY_EXISTS,
- flbuf.f_name);
- return;
- }
- }
-
- if (free_slot < 0) {
- cprintf("%d There is no space available for a new floor.\n",
- ERROR + INVALID_FLOOR_OPERATION);
- return;
- }
- if (cflr_ok == 0) {
- cprintf("%d ok to create...\n", CIT_OK);
- return;
- }
- lgetfloor(&flbuf, free_slot);
- flbuf.f_flags = F_INUSE;
- flbuf.f_ref_count = 0;
- safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
- lputfloor(&flbuf, free_slot);
- cprintf("%d %d\n", CIT_OK, free_slot);
-}
-
-
-
-/*
- * delete a floor
- */
-void cmd_kflr(char *argbuf)
-{
- struct floor flbuf;
- int floor_to_delete;
- int kflr_ok;
- int delete_ok;
-
- floor_to_delete = extract_int(argbuf, 0);
- kflr_ok = extract_int(argbuf, 1);
-
- if (CtdlAccessCheck(ac_aide)) return;
-
- lgetfloor(&flbuf, floor_to_delete);
-
- delete_ok = 1;
- if ((flbuf.f_flags & F_INUSE) == 0) {
- cprintf("%d Floor %d not in use.\n",
- ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
- delete_ok = 0;
- } else {
- if (flbuf.f_ref_count != 0) {
- cprintf("%d Cannot delete; floor contains %d rooms.\n",
- ERROR + INVALID_FLOOR_OPERATION,
- flbuf.f_ref_count);
- delete_ok = 0;
- } else {
- if (kflr_ok == 1) {
- cprintf("%d Ok\n", CIT_OK);
- } else {
- cprintf("%d Ok to delete...\n", CIT_OK);
- }
-
- }
-
- }
-
- if ((delete_ok == 1) && (kflr_ok == 1))
- flbuf.f_flags = 0;
- lputfloor(&flbuf, floor_to_delete);
-}
-
-/*
- * edit a floor
- */
-void cmd_eflr(char *argbuf)
-{
- struct floor flbuf;
- int floor_num;
- int np;
-
- np = num_parms(argbuf);
- if (np < 1) {
- cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
- return;
- }
-
- if (CtdlAccessCheck(ac_aide)) return;
-
- floor_num = extract_int(argbuf, 0);
- lgetfloor(&flbuf, floor_num);
- if ((flbuf.f_flags & F_INUSE) == 0) {
- lputfloor(&flbuf, floor_num);
- cprintf("%d Floor %d is not in use.\n",
- ERROR + INVALID_FLOOR_OPERATION, floor_num);
- return;
- }
- if (np >= 2)
- extract_token(flbuf.f_name, argbuf, 1, '|', sizeof flbuf.f_name);
- lputfloor(&flbuf, floor_num);
-
- cprintf("%d Ok\n", CIT_OK);
-}
-
-
-
-/*
- * cmd_stat() - return the modification time of the current room (maybe other things in the future)
- */
-void cmd_stat(char *gargs)
-{
- if (CtdlAccessCheck(ac_logged_in_or_guest)) return;
- CtdlGetRoom(&CC->room, CC->room.QRname);
- cprintf("%d %s|%ld|\n", CIT_OK, CC->room.QRname, CC->room.QRmtime);
-}
-
-
-
-/*****************************************************************************/
-/* MODULE INITIALIZATION STUFF */
-/*****************************************************************************/
-
-CTDL_MODULE_INIT(room_ops)
-{
- if (!threading) {
- CtdlRegisterProtoHook(cmd_lrms, "LRMS", "List rooms");
- CtdlRegisterProtoHook(cmd_lkra, "LKRA", "List all known rooms");
- CtdlRegisterProtoHook(cmd_lkrn, "LKRN", "List known rooms with new messages");
- CtdlRegisterProtoHook(cmd_lkro, "LKRO", "List known rooms without new messages");
- CtdlRegisterProtoHook(cmd_lzrm, "LZRM", "List zapped rooms");
- CtdlRegisterProtoHook(cmd_lprm, "LPRM", "List public rooms");
- CtdlRegisterProtoHook(cmd_goto, "GOTO", "Goto a named room");
- CtdlRegisterProtoHook(cmd_stat, "STAT", "Get mtime of the current room");
- CtdlRegisterProtoHook(cmd_whok, "WHOK", "List users who know this room");
- CtdlRegisterProtoHook(cmd_rdir, "RDIR", "List files in room directory");
- CtdlRegisterProtoHook(cmd_getr, "GETR", "Get room parameters");
- CtdlRegisterProtoHook(cmd_setr, "SETR", "Set room parameters");
- CtdlRegisterProtoHook(cmd_geta, "GETA", "Get the room admin name");
- CtdlRegisterProtoHook(cmd_seta, "SETA", "Set the room admin for this room");
- CtdlRegisterProtoHook(cmd_rinf, "RINF", "Fetch room info file");
- CtdlRegisterProtoHook(cmd_kill, "KILL", "Kill (delete) the current room");
- CtdlRegisterProtoHook(cmd_cre8, "CRE8", "Create a new room");
- CtdlRegisterProtoHook(cmd_einf, "EINF", "Enter info file for the current room");
- CtdlRegisterProtoHook(cmd_lflr, "LFLR", "List all known floors");
- CtdlRegisterProtoHook(cmd_cflr, "CFLR", "Create a new floor");
- CtdlRegisterProtoHook(cmd_kflr, "KFLR", "Kill a floor");
- CtdlRegisterProtoHook(cmd_eflr, "EFLR", "Edit a floor");
- }
- /* return our Subversion id for the Log */
- return "room_ops";
-}