AmendHub

jcs

/

subtext

/

amendments

/

124

session: Implement persistent days-per-call tallying

Stub out file area response in main menu for now

jcs made amendment 124 5 months ago
--- db.h Tue Jun 7 16:58:05 2022 +++ db.h Tue Jun 7 21:19:50 2022 @@ -46,6 +46,7 @@ #define SL_TYPE 'STSL' #define SL_LOG_RTYPE 'SLOG' +#define SL_TALLY_RTYPE 'STLY' #define BOARD_THREAD_RTYPE 'BDTH' #define BOARD_POST_RTYPE 'BDPS' --- session.c Tue Jun 7 15:41:17 2022 +++ session.c Tue Jun 7 21:39:06 2022 @@ -38,9 +38,6 @@ struct session **sessions = NULL; short nsessions = 0; -unsigned short sessions_tally = 0; -char sessions_tally_day[9] = { 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, @@ -78,6 +75,7 @@ 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; @@ -125,18 +123,23 @@ session_run(struct uthread *uthread, void *arg) panic("bile_write of session log failed: %d", bile_error(db->sessions_bile)); + /* update call tally for today */ date_tm = localtime((time_t *)&Time); strftime(date, sizeof(date), "%Y%m%d", date_tm); - if (strcmp(date, sessions_tally_day) != 0) { - strlcpy(sessions_tally_day, date, sizeof(sessions_tally_day)); - sessions_tally = 0; + if (bile_read(db->sessions_bile, SL_TALLY_RTYPE, 1, (char *)&tally, + sizeof(tally)) != sizeof(tally) || + strcmp(date, tally.date) != 0) { + tally.calls = 0; } - sessions_tally++; + strlcpy(tally.date, date, sizeof(tally.date)); + tally.calls++; + bile_write(db->sessions_bile, SL_TALLY_RTYPE, 1, (char *)&tally, + sizeof(tally)); session_printf(s, "\r\n" - "Welcome, {{B}}%s{{/B}}, you are the %d%s caller today.\r\n", + "Welcome, {{B}}%s{{/B}}, you are the %ld%s caller today.\r\n", s->user ? s->user->username : GUEST_USERNAME, - sessions_tally, ordinal(sessions_tally)); + tally.calls, ordinal(tally.calls)); session_flush(s); main_menu: @@ -169,6 +172,12 @@ get_another_char: case 'C': /* chat */ chat_start(s, NULL); + break; + case 'f': + case 'F': + /* files */ + session_output_string(s, "Coming soon!\r\n"); + session_flush(s); break; case 'g': case 'G': --- session.h Mon May 23 11:28:56 2022 +++ session.h Tue Jun 7 21:21:41 2022 @@ -100,6 +100,11 @@ struct session { extern struct session **sessions; extern short nsessions; +struct session_tally { + char date[9]; + unsigned long calls; +}; + struct session_menu_option { char ret; char key[15];