diff options
-rw-r--r-- | mbbsd/calendar.c | 38 | ||||
-rw-r--r-- | mbbsd/user.c | 60 |
2 files changed, 92 insertions, 6 deletions
diff --git a/mbbsd/calendar.c b/mbbsd/calendar.c index dad8bc46..a8c63eb3 100644 --- a/mbbsd/calendar.c +++ b/mbbsd/calendar.c @@ -31,22 +31,44 @@ Days(int y, int m, int d) } /** - * return 1 if date is invalid + * return 1 if date and time is invalid */ -int ParseDate(const char *date, int *year, int *month, int *day) +int ParseDateTime(const char *date, int *year, int *month, int *day, + int *hour, int *min, int *sec) { - char *y, *m, *d; + char *y, *m, *d, *hh, *mm, *ss; char buf[128]; char *strtok_pos; strlcpy(buf, date, sizeof(buf)); y = strtok_r(buf, "/", &strtok_pos); if (!y) return 1; m = strtok_r(NULL, "/", &strtok_pos);if (!m) return 1; - d = strtok_r(NULL, "", &strtok_pos); if (!d) return 1; + d = strtok_r(NULL, " ", &strtok_pos); if (!d) return 1; + + if (hour) { + hh = strtok_r(NULL, ":", &strtok_pos); + if (!hh) return 1; + *hour = atoi(hh); + } + if (min ) { + mm = strtok_r(NULL, ":", &strtok_pos); + if (!mm) return 1; + *min = atoi(mm); + } + if (sec ) { + ss = strtok_r(NULL, "", &strtok_pos); + if (!ss) return 1; + *sec = atoi(ss); + } *year = atoi(y); *month = atoi(m); *day = atoi(d); + + if (hour && (*hour < 0 || *hour > 23)) return 1; + if (min && (*min < 0 || *min > 59)) return 1; + if (sec && (*sec < 0 || *sec > 59)) return 1; + if (*year < 1 || *month < 1 || *month > 12 || *day < 1 || *day > MonthDay(*month, is_leap_year(*year))) return 1; @@ -56,6 +78,14 @@ int ParseDate(const char *date, int *year, int *month, int *day) /** * return 1 if date is invalid */ +int ParseDate(const char *date, int *year, int *month, int *day) +{ + return ParseDateTime(date, year, month, day, NULL, NULL, NULL); +} + +/** + * return 1 if date is invalid + */ static int ParseEventDate(const char *date, event_t * t) { diff --git a/mbbsd/user.c b/mbbsd/user.c index 386e5a23..ef73930f 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -821,6 +821,32 @@ uinfo_query(const char *orig_uid, int adminmode, int unum) getdata_buf(y++, 0, "最近光臨機器:", x.lasthost, sizeof(x.lasthost), DOECHO); + while (1) { + struct tm t = {0}; + time4_t clk = x.lastlogin; + localtime4_r(&clk, &t); + snprintf(genbuf, sizeof(genbuf), "%04i/%02i/%02i %02i:%02i:%02i", + t.tm_year + 1900, t.tm_mon+1, t.tm_mday, + t.tm_hour, t.tm_min, t.tm_sec); + if (getdata_str(y, 0, "最近上線時間:", buf, 20, DOECHO, genbuf) != 0) { + int y, m, d, hh, mm, ss; + if (ParseDateTime(buf, &y, &m, &d, &hh, &mm, &ss)) + continue; + t.tm_year = y-1900; + t.tm_mon = m-1; + t.tm_mday = d; + t.tm_hour = hh; + t.tm_min = mm; + t.tm_sec = ss; + clk = mktime(&t); + if (!clk) + continue; + x.lastlogin= clk; + } + y++; + break; + } + snprintf(genbuf, sizeof(genbuf), "%d", x.numlogindays); if (getdata_str(y++, 0, "上線資歷:", buf, 10, DOECHO, genbuf)) if ((tmp = atoi(buf)) >= 0) @@ -831,10 +857,13 @@ uinfo_query(const char *orig_uid, int adminmode, int unum) x.numposts = tmp; #ifdef ASSESS snprintf(genbuf, sizeof(genbuf), "%d", x.badpost); - if (getdata_str(y++, 0, "惡劣文章數:", buf, 10, DOECHO, genbuf)) + if (getdata_str(y, 0, "惡劣文章數:", buf, 10, DOECHO, genbuf)) if ((tmp = atoi(buf)) >= 0) x.badpost = tmp; #endif // ASSESS + move(y-1, 0); clrtobot(); + prints("文章數目: %d (劣: %d)\n", + x.numposts, x.badpost); snprintf(genbuf, sizeof(genbuf), "%d", x.vl_count); if (getdata_str(y++, 0, "違法記錄:", buf, 10, DOECHO, genbuf)) @@ -864,7 +893,7 @@ uinfo_query(const char *orig_uid, int adminmode, int unum) } snprintf(genbuf, sizeof(genbuf), "%d/%d/%d", x.chc_win, x.chc_lose, x.chc_tie); - if (getdata_str(y++, 0, "象棋戰績 勝/敗/和:", buf, 16, DOECHO, + if (getdata_str(y++, 0, " 象棋 戰績 勝/敗/和:", buf, 16, DOECHO, genbuf)) while (1) { char *p; @@ -883,6 +912,33 @@ uinfo_query(const char *orig_uid, int adminmode, int unum) x.chc_tie = atoi(p); break; } + snprintf(genbuf, sizeof(genbuf), + "%d/%d/%d", x.go_win, x.go_lose, x.go_tie); + if (getdata_str(y++, 0, " 圍棋 戰績 勝/敗/和:", buf, 16, DOECHO, + genbuf)) + while (1) { + char *p; + char *strtok_pos; + p = strtok_r(buf, "/\r\n", &strtok_pos); + if (!p) + break; + x.go_win = atoi(p); + p = strtok_r(NULL, "/\r\n", &strtok_pos); + if (!p) + break; + x.go_lose = atoi(p); + p = strtok_r(NULL, "/\r\n", &strtok_pos); + if (!p) + break; + x.go_tie = atoi(p); + break; + } + y -= 3; // rollback games set to get more space + move(y++, 0); clrtobot(); + prints("棋類: (五子棋)%d/%d/%d (象棋)%d/%d/%d (圍棋)%d/%d/%d\n", + x.five_win, x.five_lose, x.five_tie, + x.chc_win, x.chc_lose, x.chc_tie, + x.go_win, x.go_lose, x.go_tie); #ifdef FOREIGN_REG if (getdata_str(y++, 0, "住在 1)台灣 2)其他:", buf, 2, DOECHO, x.uflag2 & FOREIGN ? "2" : "1")) if ((tmp = atoi(buf)) > 0){ |