char from_floor;
int ugpos = uglistsize;
int r; /* IPC result code */
- struct ctdlipcroom *roomrec = NULL;
+ struct ctdlipcroom *room = NULL;
/* store ungoto information */
if (fromungoto == 0) {
}
/* first try an exact match */
- r = CtdlIPCGotoRoom(ipc, towhere, "", &roomrec, aaa);
+ r = CtdlIPCGotoRoom(ipc, towhere, "", &room, aaa);
if (r / 10 == 54) {
newprompt("Enter room password: ", bbb, 9);
- r = CtdlIPCGotoRoom(ipc, towhere, bbb, &roomrec, aaa);
+ r = CtdlIPCGotoRoom(ipc, towhere, bbb, &room, aaa);
if (r / 10 == 54) {
scr_printf("Wrong password.\n");
return;
scr_printf("No room '%s'.\n", towhere);
return;
}
- roomrec = NULL;
- r = CtdlIPCGotoRoom(ipc, bbb, "", &roomrec, aaa);
+ room = NULL;
+ r = CtdlIPCGotoRoom(ipc, bbb, "", &room, aaa);
}
if (r / 100 != 1 && r / 100 != 2) {
scr_printf("%s\n", aaa);
return;
}
- safestrncpy(room_name, roomrec->RRname, ROOMNAMELEN);
- room_flags = roomrec->RRflags;
+ safestrncpy(room_name, room->RRname, ROOMNAMELEN);
+ room_flags = room->RRflags;
from_floor = curr_floor;
- curr_floor = roomrec->RRfloor;
+ curr_floor = room->RRfloor;
remove_march(room_name, 0);
if (!strcasecmp(towhere, "_BASEROOM_"))
remove_march(towhere, 0);
- if (!roomrec->RRunread)
+ if (!room->RRunread)
next_lazy_cmd = 5; /* Don't read new if no new msgs */
if ((from_floor != curr_floor) && (display_name > 0) && (floor_mode == 1)) {
if (floorlist[(int) curr_floor][0] == 0)
}
if (display_name != 2) {
color(BRIGHT_YELLOW);
- scr_printf("%d ", roomrec->RRunread);
+ scr_printf("%d ", room->RRunread);
color(DIM_WHITE);
scr_printf("new of ");
color(BRIGHT_YELLOW);
- scr_printf("%d ", roomrec->RRtotal);
+ scr_printf("%d ", room->RRtotal);
color(DIM_WHITE);
scr_printf("messages.\n");
}
- highest_msg_read = roomrec->RRlastread;
- maxmsgnum = roomrec->RRhighest;
- is_mail = roomrec->RRismailbox;
- is_room_aide = roomrec->RRaide;
- ls = roomrec->RRlastread;
+ highest_msg_read = room->RRlastread;
+ maxmsgnum = room->RRhighest;
+ is_mail = room->RRismailbox;
+ is_room_aide = room->RRaide;
+ ls = room->RRlastread;
/* read info file if necessary */
- if (roomrec->RRinfoupdated > 0)
+ if (room->RRinfoupdated > 0)
readinfo(ipc);
/* check for newly arrived mail if we can */
- newmailcount = roomrec->RRnewmail;
+ newmailcount = room->RRnewmail;
if (newmailcount > 0) {
color(BRIGHT_RED);
if (newmailcount == 1) {
{
char buf[SIZ];
struct march *flist, *fptr;
- struct ctdlipcroom *roomrec; /* Ignored */
+ struct ctdlipcroom *room; /* Ignored */
int r; /* IPC response code */
scr_printf("Forgetting all rooms on %s...\r", &floorlist[ffloor][0]);
return;
}
while (flist) {
- r = CtdlIPCGotoRoom(ipc, flist->march_name, "", &roomrec, buf);
+ r = CtdlIPCGotoRoom(ipc, flist->march_name, "", &room, buf);
if (r / 100 == 2) {
r = CtdlIPCForgetRoom(ipc, buf);
}
+/*
+ * Record compare function for SortOnlineUsers()
+ */
+int idlecmp(const void *rec1, const void *rec2) {
+ time_t i1, i2;
+
+ i1 = extract_long(rec1, 5);
+ i2 = extract_long(rec2, 5);
+
+ if (i1 < i2) return(1);
+ if (i1 > i2) return(-1);
+ return(0);
+}
+
+
+/*
+ * Sort the list of online users by idle time.
+ * This function frees the supplied buffer, and returns a new one
+ * to the caller. The caller is responsible for freeing the returned buffer.
+ */
+char *SortOnlineUsers(char *listing) {
+ int rows;
+ char *sortbuf;
+ char *retbuf;
+ char buf[SIZ];
+ int i;
+
+ rows = num_tokens(listing, '\n');
+ sortbuf = malloc(rows * SIZ);
+ if (sortbuf == NULL) return(listing);
+ retbuf = malloc(rows * SIZ);
+ if (retbuf == NULL) {
+ free(sortbuf);
+ return(listing);
+ }
+
+ /* Copy the list into a fixed-record-size array for sorting */
+ for (i=0; i<rows; ++i) {
+ memset(buf, 0, SIZ);
+ extract_token(buf, listing, i, '\n');
+ memcpy(&sortbuf[i*SIZ], buf, SIZ);
+ }
+
+ /* Do the sort */
+ qsort(sortbuf, rows, SIZ, idlecmp);
+
+ /* Copy back to a \n delimited list */
+ strcpy(retbuf, "");
+ for (i=0; i<rows; ++i) {
+ strcat(retbuf, &sortbuf[i*SIZ]);
+ if (i<(rows-1)) strcat(retbuf, "\n");
+ }
+ return(retbuf);
+}
+
/*
if (!longlist) {
color(BRIGHT_WHITE);
- pprintf("FLG ### User Name Room From host\n");
+ pprintf(" User Name Room Idle From host\n");
color(DIM_WHITE);
- pprintf("--- --- ------------------------- -------------------- ------------------------\n");
+ pprintf(" ------------------------- -------------------- ---- ------------------------\n");
}
r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf);
+ listing = SortOnlineUsers(listing);
if (r / 100 == 1) {
while (strlen(listing) > 0) {
int isidle = 0;
pprintf(" ");
} else {
color(BRIGHT_MAGENTA);
- pprintf("%-3s ", flags);
- color(DIM_WHITE);
- pprintf("%-3d ", extract_int(buf, 0));
+ pprintf("%-3s", flags);
}
last_session = extract_int(buf, 0);
color(BRIGHT_CYAN);
pprintf("%-25s ", username);
color(BRIGHT_MAGENTA);
+ roomname[20] = 0;
+ pprintf("%-20s ", roomname);
if (idletime > rc_idle_threshold) {
- roomname[14] = 0;
- pprintf("%-14s", roomname);
- /* over 10 days, must be gone fishing */
- if (idlehours > 239) {
- pprintf("[fish] ");
+ /* over 1000d, must be gone fishing */
+ if (idlehours > 23999) {
+ pprintf("fish");
+ /* over 10 days */
+ } else if (idlehours > 239) {
+ pprintf("%3ldd",
+ idlehours / 24);
/* over 10 hours */
} else if (idlehours > 9) {
- pprintf("[%1ldd%02ld] ",
+ pprintf("%1ldd%02ld",
idlehours / 24,
idlehours % 24);
/* less than 10 hours */
} else {
- pprintf("[%1ld:%02ld] ",
+ pprintf("%1ld:%02ld",
idlehours, idlemins);
}
- } else {
- roomname[20] = 0;
- pprintf("%-20s ", roomname);
}
+ else {
+ pprintf(" ");
+ }
+ pprintf(" ");
color(BRIGHT_CYAN);
fromhost[24] = '\0';
pprintf("%-24s\n", fromhost);
int stored_password = 0;
char password[SIZ];
struct ctdlipcmisc chek;
- struct usersupp *myself = NULL;
+ struct ctdluser *myself = NULL;
CtdlIPC* ipc; /* Our server connection */
int r; /* IPC result code */