AmendHub

jcs

/

subtext

/

amendments

/

477

session+chat: Finally implement sysop paging/answering


jcs made amendment 477 10 months ago
--- chat.c Sun Mar 12 20:08:31 2023 +++ chat.c Mon Apr 10 18:47:33 2023 @@ -45,7 +45,8 @@ chat_broadcast(struct session *s, char *str) !sessions[n]->chatting) continue; if (strcmp(s->chatting_with_node, - sessions[n]->chatting_with_node) != 0) + sessions[n]->chatting_with_node) != 0 && + strcmp(sessions[n]->chatting_with_node, s->node) != 0) continue; chat_printf_line(sessions[n], 1, "%s", str); @@ -158,7 +159,12 @@ chat_start(struct session *s, char *with_node) chatting_with[0] = '\0'; s->chatting_with_node[0] = '\0'; - if (with_node) { + + if (with_node && strcmp(with_node, CHAT_WITH_SYSOP) == 0) { + strlcpy(s->chatting_with_node, CHAT_WITH_SYSOP, + sizeof(s->chatting_with_node)); + strlcpy(chatting_with, "sysop", sizeof(chatting_with)); + } else if (with_node) { for (n = 0; n < MAX_SESSIONS; n++) { if (sessions[n] == NULL || !sessions[n]->logged_in) continue; @@ -179,9 +185,12 @@ chat_start(struct session *s, char *with_node) strlcpy(s->chatting_with_node, with_node, sizeof(s->chatting_with_node)); + } else { + strlcpy(s->chatting_with_node, CHAT_WITH_ALL, + sizeof(s->chatting_with_node)); } - s->chatting = 1; + s->chatting = true; session_logf(s, "Entered chat with %s", chatting_with[0] ? chatting_with : "everyone"); @@ -219,6 +228,12 @@ chat_start(struct session *s, char *with_node) session_flush(s); chat_who(s); + + if (strcmp(s->chatting_with_node, CHAT_WITH_SYSOP) == 0) { + snprintf(chat_tbuf, sizeof(chat_tbuf), + "*** Waiting for sysop to answer page..."); + chat_broadcast(s, chat_tbuf); + } for (;;) { input = session_field_input(s, CHAT_MAX_INPUT - 1, @@ -258,8 +273,8 @@ chat_start(struct session *s, char *with_node) xfree(&input); } - session_logf(s, "Left chat with %s", with_node && with_node[0] ? - with_node : "everyone"); + session_logf(s, "Left chat with %s", chatting_with[0] ? + chatting_with : "everyone"); snprintf(chat_tbuf, sizeof(chat_tbuf), "*** %s%s has left chat", @@ -275,7 +290,7 @@ chat_start(struct session *s, char *with_node) if (s->abort_input && !s->chatting) lagged = true; - s->chatting = 0; + s->chatting = false; memset(s->chatting_with_node, 0, sizeof(s->chatting_with_node)); /* clear chat bar */ @@ -322,7 +337,8 @@ chat_who(struct session *s) !sessions[n]->chatting) continue; if (strcmp(s->chatting_with_node, - sessions[n]->chatting_with_node) != 0) + sessions[n]->chatting_with_node) != 0 && + strcmp(sessions[n]->chatting_with_node, s->node) != 0) continue; len += snprintf(chat_tbuf + len, sizeof(chat_tbuf), "[ %c%-16s ]", --- chat.h Sat Jan 1 18:34:46 2022 +++ chat.h Mon Apr 10 18:41:33 2023 @@ -21,6 +21,9 @@ #include "db.h" #include "session.h" +#define CHAT_WITH_ALL "w/all" +#define CHAT_WITH_SYSOP "page!sysop" + void chat_broadcast(struct session *s, char *str); size_t chat_printf_line(struct session *s, short around_bar, char *format, ...); --- session.c Sat Apr 8 22:53:49 2023 +++ session.c Mon Apr 10 21:17:10 2023 @@ -54,6 +54,7 @@ size_t session_vprintf(struct session *session, const va_list ap); size_t session_expand_var(struct session *session, char *ivar, char **ret, bool *end_expansion); +struct session * session_first_waiting_for_sysop(void); void session_page_sysop(struct session *s); void session_answer_page(struct session *s); void sysop_edit_settings(struct session *s); @@ -1476,7 +1477,7 @@ void session_page_sysop(struct session *s) { char *message = NULL; - + session_printf(s, "{{B}}Page Sysop{{/B}} " "(^C to cancel)\r\n" "{{B}}-------------------------{{/B}}\r\n"); @@ -1493,22 +1494,63 @@ session_page_sysop(struct session *s) if (message == NULL || s->ending) goto page_done; - /* TODO: show message on the screen */ - - /* TODO: enter chat with sysop */ - - session_printf(s, "{{B}}TODO!{{/B}}\r\n"); - session_flush(s); + session_logf(s, "Paging sysop: %s", message); + progress("Page from %s: %s", s->user ? s->user->username : "guest", + message); + SysBeep(30); + uthread_yield(); + + chat_start(s, CHAT_WITH_SYSOP); + page_done: + progress(NULL); + if (message != NULL) xfree(&message); } +struct session * +session_first_waiting_for_sysop(void) +{ + short n; + + for (n = 0; n < MAX_SESSIONS; n++) { + if (sessions[n] == NULL || !sessions[n]->logged_in || + !sessions[n]->chatting) + continue; + if (strcmp(sessions[n]->chatting_with_node, CHAT_WITH_SYSOP) != 0) + continue; + + return sessions[n]; + } + + return NULL; +} + void session_answer_page(struct session *s) { - /* TODO */ + struct session *waiting; + + waiting = session_first_waiting_for_sysop(); + if (waiting == NULL) { + session_printf(s, "No users waiting to chat.\r\n"); + session_flush(s); + return; + } + + progress(NULL); + session_logf(s, "Answering page from %s on %s", + waiting->user ? waiting->user->username : "guest", + waiting->node); + + /* point paging user's chatting_with_node to ours */ + strlcpy(waiting->chatting_with_node, s->node, + sizeof(waiting->chatting_with_node)); + + /* and join the party */ + chat_start(s, waiting->node); } void --- session.h Mon Apr 10 15:55:32 2023 +++ session.h Mon Apr 10 17:59:00 2023 @@ -96,7 +96,7 @@ struct session { bool color; bool transferring_file; bool is_telnet; - char chatting_with_node[10]; + char chatting_with_node[16]; char chat_username[DB_USERNAME_LENGTH + 1]; bool chatting; struct session_log log;