AmendHub

Download:

jcs

/

subtext

/

amendments

/

550

session: Note each session's current area, show it in 'who' menu


jcs made amendment 550 about 1 year ago
--- console.c Mon Apr 10 22:23:29 2023 +++ console.c Fri Nov 17 11:24:43 2023 @@ -83,6 +83,11 @@ console_init(void) return NULL; } + strlcpy(console->session->location, "Console", + sizeof(console->session->location)); + strlcpy(console->session->log.location, console->session->location, + sizeof(console->session->log.location)); + memset(console->chars, ' ', sizeof(console->chars)); console->ncolumns = DEFAULT_TERMINAL_COLUMNS; console->nlines = DEFAULT_TERMINAL_LINES; --- session.c Thu Aug 3 09:03:02 2023 +++ session.c Fri Nov 17 11:32:32 2023 @@ -46,6 +46,21 @@ static char session_log_tbuf[256]; static const char invalid_option_help[] = "Invalid option (press {{B}}?{{/B}} for help)\r\n"; +/* must match session_area order */ +static const char area_labels[][12] = { + "Main Menu", + "MOTD", + "Boards", + "FTN Boards", + "Chat", + "Mail", + "Files", + "Who", + "Recents", + "Settings", + "Signup" +}; + void session_run(struct uthread *uthread, void *arg); void session_print_menu(struct session *session, bool short_menu); short session_login(struct session *s); @@ -84,6 +99,9 @@ session_create(char *node, char *via, struct node_func strlcpy(session->node, node, sizeof(session->node)); strlcpy(session->log.node, node, sizeof(session->log.node)); strlcpy(session->via, via, sizeof(session->via)); + strlcpy(session->location, "Unknown", sizeof(session->location)); + strlcpy(session->log.location, session->location, + sizeof(session->log.location)); session->last_input_at = session->established_at = Time; session->obuf_canary = 0xffffffff; @@ -125,6 +143,7 @@ session_run(struct uthread *uthread, void *arg) /* until we negotiate otherwise */ s->terminal_columns = DEFAULT_TERMINAL_COLUMNS; s->terminal_lines = DEFAULT_TERMINAL_LINES; + s->area = SESSION_AREA_MAIN_MENU; if (main_menu_options == NULL) panic("No main menu!"); @@ -220,14 +239,17 @@ session_run(struct uthread *uthread, void *arg) } } + s->area = SESSION_AREA_MOTD; session_print_motd(s, false); main_menu: + s->area = SESSION_AREA_MAIN_MENU; session_output(s, "\r\n", 2); session_print_menu(s, false); session_flush(s); while (!done && !s->ending) { + s->area = SESSION_AREA_MAIN_MENU; session_printf(s, "{{B}}Main Menu>{{/B}} "); session_flush(s); @@ -284,12 +306,15 @@ get_another_char: switch (action) { case ACTION_BOARD_SHOW_FIRST: + s->area = SESSION_AREA_BOARDS; board_show(s, 1, NULL); break; case ACTION_CHAT: + s->area = SESSION_AREA_CHAT; chat_start(s, NULL); break; case ACTION_FILES_MENU: + s->area = SESSION_AREA_FILES; folder_list(s); break; case ACTION_GOODBYE: @@ -299,15 +324,19 @@ get_another_char: done = true; break; case ACTION_RECENT_LOGINS: + s->area = SESSION_AREA_RECENT_LOGINS; session_recents(s); break; case ACTION_MAIL_MENU: + s->area = SESSION_AREA_MAIL; mail_menu(s); break; case ACTION_MAIL_COMPOSE: + s->area = SESSION_AREA_MAIL; mail_compose(s, NULL, NULL, NULL, NULL); break; case ACTION_MOTD: + s->area = SESSION_AREA_MOTD; session_print_motd(s, true); break; case ACTION_PAGE_ANSWER: @@ -316,16 +345,20 @@ get_another_char: session_flush(s); break; } + s->area = SESSION_AREA_CHAT; session_answer_page(s); break; case ACTION_PAGE_SEND: session_page_sysop(s); break; case ACTION_SETTINGS: - if (s->user) + if (s->user) { + s->area = SESSION_AREA_SETTINGS; user_settings_menu(s); + } break; case ACTION_SIGNUP: + s->area = SESSION_AREA_SIGNUP; if ((s->user = signup(s))) { session_printf(s, "\r\n" "Welcome, {{B}}%s{{/B}}!\r\n", s->user->username); @@ -333,42 +366,55 @@ get_another_char: } break; case ACTION_WHOS_ONLINE: + s->area = SESSION_AREA_WHO; session_who(s); break; case ACTION_BOARD_LIST_BOARDS: + s->area = SESSION_AREA_BOARDS; board_list_boards(s); break; case ACTION_BOARD_LIST_FTN_AREAS: + s->area = SESSION_AREA_FTN; board_list_ftn_areas(s); break; case ACTION_BOARD_SHOW_1: + s->area = SESSION_AREA_BOARDS; board_show(s, 1, NULL); break; case ACTION_BOARD_SHOW_2: + s->area = SESSION_AREA_BOARDS; board_show(s, 2, NULL); break; case ACTION_BOARD_SHOW_3: + s->area = SESSION_AREA_BOARDS; board_show(s, 3, NULL); break; case ACTION_BOARD_SHOW_4: + s->area = SESSION_AREA_BOARDS; board_show(s, 4, NULL); break; case ACTION_BOARD_SHOW_5: + s->area = SESSION_AREA_BOARDS; board_show(s, 5, NULL); break; case ACTION_BOARD_SHOW_6: + s->area = SESSION_AREA_BOARDS; board_show(s, 6, NULL); break; case ACTION_BOARD_SHOW_7: + s->area = SESSION_AREA_BOARDS; board_show(s, 7, NULL); break; case ACTION_BOARD_SHOW_8: + s->area = SESSION_AREA_BOARDS; board_show(s, 8, NULL); break; case ACTION_BOARD_SHOW_9: + s->area = SESSION_AREA_BOARDS; board_show(s, 9, NULL); break; case ACTION_BOARD_SHOW_10: + s->area = SESSION_AREA_BOARDS; board_show(s, 10, NULL); break; case ACTION_SYSOP_MENU: @@ -1689,7 +1735,7 @@ session_who(struct session *s) session_printf(s, "{{B}}Who's Online{{/B}}\r\n"); session_printf(s, - "{{B}}Node User Via Speed Idle Location{{/B}}\r\n"); + "{{B}}Node User Via Speed Cur Area Idle Location{{/B}}\r\n"); session_flush(s); for (n = 0; n < MAX_SESSIONS; n++) { @@ -1698,23 +1744,24 @@ session_who(struct session *s) idle = Time - sessions[n]->last_input_at; if (idle < 60) - sprintf(idle_s, "%lus", idle); + snprintf(idle_s, sizeof(idle_s), "%lus", idle); else if (idle < (60 * 60)) - sprintf(idle_s, "%lum", idle / 60); + snprintf(idle_s, sizeof(idle_s), "%lum", idle / 60); else if (idle < (60 * 60 * 24)) - sprintf(idle_s, "%luh", idle / (60 * 60)); + snprintf(idle_s, sizeof(idle_s), "%luh", idle / (60 * 60)); else - sprintf(idle_s, "%lud", idle / (60 * 60 * 24)); + snprintf(idle_s, sizeof(idle_s), "%lud", idle / (60 * 60 * 24)); snprintf(username, sizeof(username), "%s%s", sessions[n]->user ? sessions[n]->user->username : GUEST_USERNAME, sessions[n]->user && sessions[n]->user->is_sysop ? " (sysop)" : ""); - session_printf(s, "%-7s %-17s %-7s %-6u %-5s %-32s\r\n", + session_printf(s, "%-7s %-17s %-7s %-6u %-10s %-5s %-22s\r\n", sessions[n]->node, username, sessions[n]->via, sessions[n]->tspeed, + area_labels[sessions[n]->area], idle_s, sessions[n]->location); } --- session.h Wed Jun 14 16:48:55 2023 +++ session.h Fri Nov 17 10:55:03 2023 @@ -29,6 +29,21 @@ enum session_input_state { SESSION_INPUT_CHAR }; +/* must keep sessions area_labels[] in sync */ +enum session_area { + SESSION_AREA_MAIN_MENU, + SESSION_AREA_MOTD, + SESSION_AREA_BOARDS, + SESSION_AREA_FTN, + SESSION_AREA_CHAT, + SESSION_AREA_MAIL, + SESSION_AREA_FILES, + SESSION_AREA_WHO, + SESSION_AREA_RECENT_LOGINS, + SESSION_AREA_SETTINGS, + SESSION_AREA_SIGNUP +}; + #define DEFAULT_TERMINAL_COLUMNS 80 #define DEFAULT_TERMINAL_LINES 24 #define MIN_TERMINAL_COLUMNS 20 @@ -102,6 +117,7 @@ struct session { char chatting_with_node[16]; char chat_username[DB_USERNAME_LENGTH + 1]; bool chatting; + short area; struct session_log log; struct user *user; void *cookie;