From 7abe50c954a98f62753d57b142f401f2c52fbb7a Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 21 Jun 2006 02:45:12 +0000 Subject: [PATCH] Applied Matt's patches for the addition of four new client commands for quick navigation between rooms and floors. --- citadel/citadel.c | 209 ++++++++++++++++++++++++++++++++++++-- citadel/citadel.rc | 5 + citadel/clientsocket.h | 2 +- citadel/commands.c | 5 +- citadel/docs/citadel.html | 6 ++ citadel/messages/help | 2 + 6 files changed, 218 insertions(+), 11 deletions(-) diff --git a/citadel/citadel.c b/citadel/citadel.c index d7875992b..6cfe72f9a 100644 --- a/citadel/citadel.c +++ b/citadel/citadel.c @@ -59,6 +59,8 @@ #define IFAIDE if (axlevel>=6) #define IFNAIDE if (axlevel<6) +int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2); + struct march *march = NULL; /* globals associated with the client program */ @@ -301,7 +303,7 @@ void remove_march(char *roomname, int floornum) * Locate the room on the march list which we most want to go to. Each room * is measured given a "weight" of preference based on various factors. */ -char *pop_march(int desired_floor) +char *pop_march(int desired_floor, struct march *_march) { static char TheRoom[ROOMNAMELEN]; int TheFloor = 0; @@ -311,10 +313,10 @@ char *pop_march(int desired_floor) struct march *mptr = NULL; strcpy(TheRoom, "_BASEROOM_"); - if (march == NULL) + if (_march == NULL) return (TheRoom); - for (mptr = march; mptr != NULL; mptr = mptr->next) { + for (mptr = _march; mptr != NULL; mptr = mptr->next) { weight = 0; if ((strcasecmp(mptr->march_name, "_BASEROOM_"))) weight = weight + 10000; @@ -529,7 +531,7 @@ void gotonext(CtdlIPC *ipc) remove_march(room_name, 0); } if (march != NULL) { - strcpy(next_room, pop_march(curr_floor)); + strcpy(next_room, pop_march(curr_floor, march)); } else { strcpy(next_room, "_BASEROOM_"); } @@ -645,9 +647,9 @@ void gotofloor(CtdlIPC *ipc, char *towhere, int mode) if (r / 100 == 1) { struct march *tmp = mptr; - /* TODO: room order is being ignored? */ + /*. . . according to room order */ if (mptr) - strncpy(targ, mptr->march_name, ROOMNAMELEN); + strcpy(targ, pop_march(tofloor, mptr)); while (mptr) { tmp = mptr->next; free(mptr); @@ -666,10 +668,10 @@ void gotofloor(CtdlIPC *ipc, char *towhere, int mode) r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, tofloor, &mptr, buf); if (r / 100 == 1) { struct march *tmp = mptr; - - /* TODO: room order is being ignored? */ + + /*. . . according to room order */ if (mptr) - strncpy(targ, mptr->march_name, ROOMNAMELEN); + strcpy(targ, pop_march(tofloor, mptr)); while (mptr) { tmp = mptr->next; free(mptr); @@ -683,6 +685,179 @@ void gotofloor(CtdlIPC *ipc, char *towhere, int mode) } } +/* + * 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) +{ + 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); + + updatels(ipc); + dotgoto(ipc, rmname, 1, 0); +} + + +/* + * step through floors on system + */ +void gotofloorstep(CtdlIPC *ipc, int direction) +{ + int tofloor; + + if (floorlist[0][0] == 0) + load_floorlist(ipc); + + 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], GF_GOTO); +} + /* * forget all rooms on current floor @@ -1850,6 +2025,22 @@ NEWUSR: if (strlen(rc_password) == 0) { page_user(ipc); break; + case 110: /* <+> Next room */ + gotoroomstep(ipc, 1); + break; + + case 111: /* <-> Previous room */ + gotoroomstep(ipc, 0); + break; + + case 112: /* <>> Next floor */ + gotofloorstep(ipc, 1); + break; + + case 113: /* <<> Previous floor */ + gotofloorstep(ipc, 0); + break; + default: /* allow some math on the command */ /* commands 100... to 100+MAX_EDITORS-1 will call the appropriate editor... in other diff --git a/citadel/citadel.rc b/citadel/citadel.rc index 39278f1cb..774ced13d 100644 --- a/citadel/citadel.rc +++ b/citadel/citadel.rc @@ -369,6 +369,11 @@ cmd=76,0,&.,&Wholist,&Hostname cmd=91,0,&.,&Wholist,&Active cmd=93,0,&.,&Wholist,&Stealth mode +cmd=110,0,&+Next room +cmd=111,0,&-Previous room +cmd=112,0,&>Next floor +cmd=113,0,&' || strbuf[a+1] == '+' || strbuf[a+1] == '-'; + if (mode == 0) { - strcpy(&exp[a], &exp[a + 1]); + strcpy(&exp[a], &exp[a + 1 + noecho]); } if (mode == 1) { exp[a] = '<'; diff --git a/citadel/docs/citadel.html b/citadel/docs/citadel.html index f2c4b5d1f..a04245b4d 100644 --- a/citadel/docs/citadel.html +++ b/citadel/docs/citadel.html @@ -92,6 +92,12 @@ others
RBL checking function design
+ + Matt McBride
+ + additional client features
+
+ Ben Mehlman
diff --git a/citadel/messages/help b/citadel/messages/help index a11b5f89c..4ccc16f0f 100644 --- a/citadel/messages/help +++ b/citadel/messages/help @@ -21,6 +21,8 @@ W Displays who is currently logged in. X Toggle eXpert mode (menus and help blurbs on/off) Z Zap (forget) room. (Removes the room from your list) + + - Goto next, previous room on current floor. + > < Goto next, previous floor. * Enter any locally installed 'doors'. In addition, there are dot commands. You hit the . (dot), then press the -- 2.39.2