+/*
+ * Indexing mechanism for a room list, called by gotoroomstep()
+ */
+void room_tree_list_query(struct ctdlroomlisting *rp, char *findrmname, int findrmslot, char *rmname, int *rmslot, int *rmtotal)
+{
+ char roomname[ROOMNAMELEN];
+ static int cur_rmslot = 0;
+
+ if (rp == NULL) {
+ cur_rmslot = 0;
+ return;
+ }
+
+ if (rp->lnext != NULL) {
+ room_tree_list_query(rp->lnext, findrmname, findrmslot, rmname, rmslot, rmtotal);
+ }
+
+ if (sigcaught == 0) {
+ strcpy(roomname, rp->rlname);
+
+ if (rmname != NULL) {
+ if (cur_rmslot == findrmslot) {
+ strcpy(rmname, roomname);
+ }
+ }
+ if (rmslot != NULL) {
+ if (!strcmp(roomname, findrmname)) {
+ *rmslot = cur_rmslot;
+ }
+ }
+ cur_rmslot++;
+ }
+
+ if (rp->rnext != NULL) {
+ room_tree_list_query(rp->rnext, findrmname, findrmslot, rmname, rmslot, rmtotal);
+ }
+
+ if ((rmname == NULL) && (rmslot == NULL))
+ free(rp);
+
+ if (rmtotal != NULL) {
+ *rmtotal = cur_rmslot;
+ }
+}
+
+/*
+ * step through rooms on current floor
+ */
+void gotoroomstep(CtdlIPC *ipc, int direction, int mode)
+{
+ struct march *listing = NULL;
+ struct march *mptr;
+ int r; /* IPC response code */
+ char buf[SIZ];
+ struct ctdlroomlisting *rl = NULL;
+ struct ctdlroomlisting *rp;
+ struct ctdlroomlisting *rs;
+ int list_it;
+ char rmname[ROOMNAMELEN];
+ int rmslot;
+ int rmtotal;
+
+ /* Ask the server for a room list */
+ r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
+ if (r / 100 != 1) {
+ listing = NULL;
+ }
+
+ load_floorlist(ipc);
+
+ for (mptr = listing; mptr != NULL; mptr = mptr->next) {
+ list_it = 1;
+
+ if ( floor_mode
+ && (mptr->march_floor != curr_floor))
+ list_it = 0;
+
+ if (list_it) {
+ rp = malloc(sizeof(struct ctdlroomlisting));
+ strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
+ rp->rlflags = mptr->march_flags;
+ rp->rlfloor = mptr->march_floor;
+ rp->rlorder = mptr->march_order;
+ rp->lnext = NULL;
+ rp->rnext = NULL;
+
+ rs = rl;
+ if (rl == NULL) {
+ rl = rp;
+ } else {
+ while (rp != NULL) {
+ if (rordercmp(rp, rs) < 0) {
+ if (rs->lnext == NULL) {
+ rs->lnext = rp;
+ rp = NULL;
+ } else {
+ rs = rs->lnext;
+ }
+ } else {
+ if (rs->rnext == NULL) {
+ rs->rnext = rp;
+ rp = NULL;
+ } else {
+ rs = rs->rnext;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* Find position of current room */
+ room_tree_list_query(NULL, NULL, 0, NULL, NULL, NULL);
+ room_tree_list_query(rl, room_name, 0, NULL, &rmslot, &rmtotal);
+
+ if (direction == 0) { /* Previous room */
+ /* If we're at the first room, wrap to the last room */
+ if (rmslot == 0) {
+ rmslot = rmtotal - 1;
+ } else {
+ rmslot--;
+ }
+ } else { /* Next room */
+ /* If we're at the last room, wrap to the first room */
+ if (rmslot == rmtotal - 1) {
+ rmslot = 0;
+ } else {
+ rmslot++;
+ }
+ }
+
+ /* Get name of next/previous room */
+ room_tree_list_query(NULL, NULL, 0, NULL, NULL, NULL);
+ room_tree_list_query(rl, NULL, rmslot, rmname, NULL, NULL);
+
+ /* Free the tree */
+ room_tree_list_query(rl, NULL, 0, NULL, NULL, NULL);
+
+ if (mode == 0) { /* not skipping */
+ updatels(ipc);
+ } else {
+ if (rc_alt_semantics) {
+ updatelsa(ipc);
+ }
+ }
+
+ /* Free the room list */
+ while (listing) {
+ mptr = listing->next;
+ free(listing);
+ listing = mptr;
+ };
+
+ dotgoto(ipc, rmname, 1, 0);
+}
+
+
+/*
+ * step through floors on system
+ */
+void gotofloorstep(CtdlIPC *ipc, int direction, int mode)
+{
+ int tofloor;
+
+ if (floorlist[0][0] == 0)
+ load_floorlist(ipc);
+
+ empty_keep_going:
+
+ if (direction == 0) { /* Previous floor */
+ if (curr_floor) tofloor = curr_floor - 1;
+ else tofloor = 127;
+
+ while (!floorlist[tofloor][0]) tofloor--;
+ } else { /* Next floor */
+ if (curr_floor < 127) tofloor = curr_floor + 1;
+ else tofloor = 0;
+
+ while (!floorlist[tofloor][0] && tofloor < 127) tofloor++;
+ if (!floorlist[tofloor][0]) tofloor = 0;
+ }
+ /* ;g works when not in floor mode so . . . */
+ if (!floor_mode) {
+ scr_printf("(%s)\n", floorlist[tofloor] );
+ }
+
+ gotofloor(ipc, floorlist[tofloor], mode);
+ if (curr_floor != tofloor) { /* gotofloor failed */
+ curr_floor = tofloor;
+ goto empty_keep_going;
+ }
+}
+
+/*
+ * Display user 'preferences'.
+ */
+extern int rc_prompt_control;
+void read_config(CtdlIPC *ipc)
+{
+ char buf[SIZ];
+ char *resp = NULL;
+ int r; /* IPC response code */
+ char _fullname[USERNAME_SIZE];
+ long _usernum;
+ int _axlevel, _timescalled, _posted;
+ time_t _lastcall;
+ struct ctdluser *user = NULL;
+
+ /* get misc user info */
+ r = CtdlIPCGetBio(ipc, fullname, &resp, buf);
+ if (r / 100 != 1) {
+ pprintf("%s\n", buf);
+ return;
+ }
+ extract_token(_fullname, buf, 1, '|', sizeof fullname);
+ _usernum = extract_long(buf, 2);
+ _axlevel = extract_int(buf, 3);
+ _lastcall = extract_long(buf, 4);
+ _timescalled = extract_int(buf, 5);
+ _posted = extract_int(buf, 6);
+ free(resp);
+ resp = NULL;
+
+ /* get preferences */
+ r = CtdlIPCGetConfig(ipc, &user, buf);
+ if (r / 100 != 2) {
+ scr_printf("%s\n", buf);
+ free(user);
+ return;
+ }
+
+ /* show misc user info */
+ scr_printf("%s\nAccess level: %d (%s)\n"
+ "User #%ld / %d Calls / %d Posts",
+ _fullname, _axlevel, axdefs[(int) _axlevel],
+ _usernum, _timescalled, _posted);
+ if (_lastcall > 0L) {
+ scr_printf(" / Curr login: %s",
+ asctime(localtime(&_lastcall)));
+ }
+ scr_printf("\n");
+
+ /* show preferences */
+ scr_printf("Your screen width: "); color(BRIGHT_CYAN); scr_printf("%d", /*user->USscreenwidth*/ screenwidth); color(DIM_WHITE);
+ scr_printf(", height: "); color(BRIGHT_CYAN); scr_printf("%d\n", /*user->USscreenheight*/ screenheight); color(DIM_WHITE);
+ scr_printf("Are you an experienced Citadel user: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_EXPERT) ? "Yes" : "No"); color(DIM_WHITE);
+ scr_printf("Print last old message on New message request: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_LASTOLD)? "Yes" : "No"); color(DIM_WHITE);
+ scr_printf("Prompt after each message: "); color(BRIGHT_CYAN); scr_printf("%s\n", (!(user->flags & US_NOPROMPT))? "Yes" : "No"); color(DIM_WHITE);
+ if ((user->flags & US_NOPROMPT) == 0) {
+ scr_printf("Use 'disappearing' prompts: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_DISAPPEAR)? "Yes" : "No"); color(DIM_WHITE);
+ }
+ scr_printf("Pause after each screenful of text: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_PAGINATOR)? "Yes" : "No"); color(DIM_WHITE);
+ if (rc_prompt_control == 3 && (user->flags & US_PAGINATOR)) {
+ scr_printf("<N>ext and <S>top work at paginator prompt: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_PROMPTCTL)? "Yes" : "No"); color(DIM_WHITE);
+ }
+ if (rc_floor_mode == RC_DEFAULT) {
+ scr_printf("View rooms by floor: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_FLOORS)? "Yes" : "No"); color(DIM_WHITE);
+ }
+ if (rc_ansi_color == 3) {
+ scr_printf("Enable color support: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_COLOR)? "Yes" : "No"); color(DIM_WHITE);
+ }
+ scr_printf("Be unlisted in userlog: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_UNLISTED)? "Yes" : "No"); color(DIM_WHITE);
+ if (!IsEmptyStr(editor_paths[0])) {
+ scr_printf("Always enter messages with the full-screen editor: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_EXTEDIT)? "Yes" : "No"); color(DIM_WHITE);
+ }
+ free(user);
+}
+
+/*
+ * Display system statistics.
+ */
+void system_info(CtdlIPC *ipc)
+{
+ char buf[SIZ];
+ char *resp = NULL;
+ size_t bytes;
+ int mrtg_users, mrtg_active_users;
+ char mrtg_server_uptime[40];
+ long mrtg_himessage;
+ int ret; /* IPC response code */
+
+ /* get #users, #active & server uptime */
+ ret = CtdlIPCGenericCommand(ipc, "MRTG|users", NULL, 0, &resp, &bytes, buf);
+ mrtg_users = extract_int(resp, 0);
+ remove_token(resp, 0, '\n');
+ mrtg_active_users = extract_int(resp, 0);
+ remove_token(resp, 0, '\n');
+ extract_token(mrtg_server_uptime, resp, 0, '\n', sizeof mrtg_server_uptime);
+ free(resp);
+ resp = NULL;
+
+ /* get high message# */
+ ret = CtdlIPCGenericCommand(ipc, "MRTG|messages", NULL, 0, &resp, &bytes, buf);
+ mrtg_himessage = extract_long(resp, 0);
+ free(resp);
+ resp = NULL;
+
+ /* refresh server info just in case */
+ CtdlIPCServerInfo(ipc, buf);
+
+ scr_printf("You are connected to %s (%s) @%s\n", ipc->ServInfo.nodename, ipc->ServInfo.humannode, ipc->ServInfo.fqdn);
+ scr_printf("running %s with text client v%.2f,\n", ipc->ServInfo.software, (float)REV_LEVEL/100);
+ scr_printf("and located in %s.\n", ipc->ServInfo.site_location);
+ scr_printf("Connected users %d / Active users %d / Highest message #%ld\n", mrtg_users, mrtg_active_users, mrtg_himessage);
+ scr_printf("Server uptime: %s\n", mrtg_server_uptime);
+ scr_printf("Your system administrator is %s.\n", ipc->ServInfo.sysadm);
+ scr_printf("Copyright (C)1987-2007 by the Citadel development team\n");
+}