AmendHub

Download:

jcs

/

subtext

/

amendments

/

174

logger: Keep title updated with some call information


jcs made amendment 174 about 1 year ago
--- console.c Thu Jun 23 14:01:25 2022 +++ console.c Fri Jun 24 09:47:08 2022 @@ -100,8 +100,6 @@ console_init(void) focusable->close = console_close; console->focusable = focusable; add_focusable(focusable); - TextFont(TEXT_FONT); - TextSize(TEXT_SIZE); console->session = session_create("console", "console", &console_node_funcs); --- logger.c Tue Jun 21 15:43:14 2022 +++ logger.c Fri Jun 24 16:38:46 2022 @@ -47,13 +47,14 @@ logger_init(void) bounds.right = screenBits.bounds.right - padding - 1; bounds.bottom = screenBits.bounds.bottom - padding - 1; - snprintf(title, sizeof(title), "%s: %s", PROGRAM_NAME, db->config.name); + snprintf(title, sizeof(title), "%s", db->config.name); logger->win = NewWindow(0L, &bounds, CtoPstr(title), false, documentProc, (WindowPtr)-1L, true, 0); if (!logger->win) panic("Can't create logger window"); SetPort(logger->win); + TextFont(LOGGER_FONT); TextSize(LOGGER_FONT_SIZE); @@ -172,6 +173,36 @@ logger_update(struct focusable *focusable, EventRecord } SetPort(old_port); +} + +void +logger_update_title(void) +{ + static char logger_title[64]; + short n, uprinted = 0; + + snprintf(logger_title, sizeof(logger_title), + "%s | %ld Call%s | ", db->config.name, + session_today_tally.calls, session_today_tally.calls == 1 ? "" : "s"); + + for (n = 0; n < MAX_SESSIONS; n++) { + if (sessions[n] == NULL || !sessions[n]->logged_in) + continue; + + if (uprinted++) + strlcat(logger_title, ", ", sizeof(logger_title)); + else + strlcat(logger_title, "Logged in: ", sizeof(logger_title)); + + strlcat(logger_title, + sessions[n]->user ? sessions[n]->user->username : "guest", + sizeof(logger_title)); + } + + if (uprinted == 0) + strlcat(logger_title, "No one connected", sizeof(logger_title)); + + SetWTitle(logger->win, CtoPstr(logger_title)); } void --- logger.h Tue Apr 26 15:42:38 2022 +++ logger.h Fri Jun 24 10:14:37 2022 @@ -35,5 +35,6 @@ struct logger * logger_init(void); size_t logger_vprintf(struct logger *logger, const char *format, va_list ap); size_t logger_printf(struct logger *logger, const char *format, ...); +void logger_update_title(void); #endif --- main.c Wed Jun 22 15:23:13 2022 +++ main.c Fri Jun 24 16:39:24 2022 @@ -97,10 +97,13 @@ main(void) _atexit(handle_exit); + session_load_tally(); + logger = logger_init(); logger_printf(logger, "[db] Updating username cache"); user_cache_usernames(); - + logger_update_title(); + if (db->config.telnet_port) telnet_init(); if (db->config.modem_port) --- session.c Thu Jun 23 14:18:57 2022 +++ session.c Fri Jun 24 16:25:05 2022 @@ -38,6 +38,8 @@ struct session *sessions[MAX_SESSIONS] = { 0 }; short nsessions = 0; +struct session_tally session_today_tally = { 0 }; + void session_run(struct uthread *uthread, void *arg); short session_login(struct session *s); size_t session_expand_var(struct session *session, char *ivar, char **ret, @@ -47,6 +49,24 @@ void session_answer_page(struct session *s); void sysop_edit_settings(struct session *s); bool session_idled_out(struct session *session); +void +session_load_tally(void) +{ + char date[9]; + struct tm *date_tm; + + date_tm = localtime((time_t *)&Time); + strftime(date, sizeof(date), "%Y%m%d", date_tm); + if (bile_read(db->sessions_bile, SL_TALLY_RTYPE, 1, + (char *)&session_today_tally, + sizeof(session_today_tally)) != sizeof(session_today_tally) || + strcmp(date, session_today_tally.date) != 0) { + strlcpy(session_today_tally.date, date, + sizeof(session_today_tally.date)); + session_today_tally.calls = 0; + } +} + struct session * session_create(char *node, char *via, struct node_funcs *node_funcs) { @@ -86,7 +106,6 @@ void session_run(struct uthread *uthread, void *arg) { struct session *s = (struct session *)arg; - struct session_tally tally; char date[9]; struct tm *date_tm; unsigned short c, last_c = 0; @@ -115,6 +134,7 @@ session_run(struct uthread *uthread, void *arg) } s->logged_in = 1; + logger_update_title(); /* update session log */ if (s->user) { @@ -139,20 +159,19 @@ session_run(struct uthread *uthread, void *arg) /* update call tally for today */ date_tm = localtime((time_t *)&Time); strftime(date, sizeof(date), "%Y%m%d", date_tm); - if (bile_read(db->sessions_bile, SL_TALLY_RTYPE, 1, (char *)&tally, - sizeof(tally)) != sizeof(tally) || - strcmp(date, tally.date) != 0) { - tally.calls = 0; + if (strcmp(date, session_today_tally.date) != 0) { + strlcpy(session_today_tally.date, date, + sizeof(session_today_tally.date)); + session_today_tally.calls = 0; } - strlcpy(tally.date, date, sizeof(tally.date)); - tally.calls++; - bile_write(db->sessions_bile, SL_TALLY_RTYPE, 1, (char *)&tally, - sizeof(tally)); + session_today_tally.calls++; + bile_write(db->sessions_bile, SL_TALLY_RTYPE, 1, + (char *)&session_today_tally, sizeof(session_today_tally)); session_printf(s, "\r\n" "Welcome, {{B}}%s{{/B}}, you are the %ld%s caller today.\r\n", s->user ? s->user->username : GUEST_USERNAME, - tally.calls, ordinal(tally.calls)); + session_today_tally.calls, ordinal(session_today_tally.calls)); session_flush(s); main_menu: @@ -320,6 +339,8 @@ session_close(struct session *session) nsessions--; free(session); + + logger_update_title(); } void --- session.h Thu Jun 23 13:39:31 2022 +++ session.h Fri Jun 24 11:26:42 2022 @@ -107,6 +107,7 @@ struct session_tally { char date[9]; unsigned long calls; }; +extern struct session_tally session_today_tally; struct session_menu_option { char ret; @@ -114,6 +115,7 @@ struct session_menu_option { char title[100]; }; +void session_load_tally(void); struct session * session_create(char *node, char *via, struct node_funcs *node_funcs); void session_close(struct session *session); --- settings.c Wed Jun 22 17:18:41 2022 +++ settings.c Fri Jun 24 09:48:13 2022 @@ -462,8 +462,6 @@ view_editor_mouse_down(struct focusable *focusable, Ev switch (part = FindControl(p, view_editor->win, &control)) { case inButton: - TextFont(applFont); - TextSize(11); if (TrackControl(control, p, 0L)) { if (control == view_editor->save_button) view_editor_save(focusable, NULL);