From 32c72860408c08a919abb53a85ed98340864f917 Mon Sep 17 00:00:00 2001 From: <> Date: Sun, 12 Mar 2017 23:20:57 -0700 Subject: [PATCH] Now displays formatted time. --- main.c | 48 ++++++++++++++++++++++++++-------- queries/mleaderboard-ojoin.sql | 2 +- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/main.c b/main.c index 190892c..c69d5c9 100644 --- a/main.c +++ b/main.c @@ -22,11 +22,12 @@ inline char *get_filename(const char *c) { return qout; } -inline void print_tblheader(const char *c) { - char *out; - switch (*c) { +inline int print_tblheader(const char *c) { + char *labels; + int idx = -1; + switch (*c) { default: - out = "\ + labels = "
\ \ \ \ @@ -34,18 +35,20 @@ inline void print_tblheader(const char *c) { \ \ "; + idx = 2; break; case 'm': - out = "


Map List

NameBest TimeHeld By
\ + labels = "
\ \ \ \ \ \ "; + idx = 2; break; case 'p': - out = "


Leaderboard

RankNameTime
\ + labels = "
\ \ \ \ @@ -54,19 +57,42 @@ inline void print_tblheader(const char *c) { "; break; } - printf("%s", out); + printf("%s", labels); + return idx; +} + +// input is an integer as a string. +// the time is in centiseconds. +// this means the longest XDF run this can support is +// 21,474,836.47 seconds +// someone would need to idle in-game for 248 days +void print_time(const char *strcs) { + const unsigned int num = strtoul(strcs, NULL, 10); + unsigned int s = num/100; + const unsigned int cs = num % 100; + const unsigned int min = s/60; + s = s % 60; + if (min > 0) { + printf("", min, s, cs); + } else { + printf("", s, cs); + } } // display and format the results of the query. -void qresult(sqlite3_stmt *sp, const char *c) { +void qresult(sqlite3_stmt * const sp, const char *c) { int e; unsigned int i; - unsigned int cc = sqlite3_column_count(sp); - print_tblheader(c); + unsigned int cc = sqlite3_column_count(sp); + const int cvt = print_tblheader(c); while ((e = sqlite3_step(sp)) == SQLITE_ROW) { printf(""); for (i = 0; i < cc; i++) { - printf("", sqlite3_column_text(sp, i)); + if (i != cvt) { + printf("", sqlite3_column_text(sp, i)); + } else { + print_time(sqlite3_column_text(sp, i)); + } } printf(""); } diff --git a/queries/mleaderboard-ojoin.sql b/queries/mleaderboard-ojoin.sql index 6246bd9..d7b922d 100644 --- a/queries/mleaderboard-ojoin.sql +++ b/queries/mleaderboard-ojoin.sql @@ -1,4 +1,4 @@ -select trank, tvalue, ifnull(alias, "Unregistered Player") +select trank, ifnull(alias, "Unregistered Player"), tvalue from Cts_times, Cts_ranks left join Id2alias on idvalue = cryptokey


Ranks

Name
%u:%.2u.%.2u%u.%.2u
%s%s