From ae5a425420e3cafd1a9887f02ba60f972cb85ede Mon Sep 17 00:00:00 2001 From: AnnieRuru Date: Sat, 23 Mar 2019 23:27:05 +0800 Subject: Add optional parameter for *gettimestr --- src/map/script.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/map/script.c b/src/map/script.c index bba559df8..aeaf851b1 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -10612,11 +10612,23 @@ static BUILDIN(gettimestr) char *tmpstr; const char *fmtstr; int maxlen; - time_t now = time(NULL); + time_t now; fmtstr=script_getstr(st,2); maxlen=script_getnum(st,3); + if (script_hasdata(st, 4)) { + int timestamp = script_getnum(st, 4); + if (timestamp < 0) { + ShowWarning("buildin_gettimestr: UNIX timestamp must be in positive value.\n"); + return false; + } + + now = (time_t)timestamp; + } else { + now = time(NULL); + } + tmpstr=(char *)aMalloc((maxlen+1)*sizeof(char)); strftime(tmpstr,maxlen,fmtstr,localtime(&now)); tmpstr[maxlen]='\0'; @@ -25378,7 +25390,7 @@ static void script_parse_builtin(void) BUILDIN_DEF(savepoint,"sii"), BUILDIN_DEF(gettimetick,"i"), BUILDIN_DEF(gettime,"i"), - BUILDIN_DEF(gettimestr,"si"), + BUILDIN_DEF(gettimestr, "si?"), BUILDIN_DEF(openstorage,""), BUILDIN_DEF(guildopenstorage,""), BUILDIN_DEF(itemskill,"vi?"), -- cgit v1.2.3-60-g2f50 From 69541a8d14809841434bdb9c131436070f57def3 Mon Sep 17 00:00:00 2001 From: AnnieRuru Date: Sat, 23 Mar 2019 23:27:48 +0800 Subject: white space edit --- src/map/script.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/map/script.c b/src/map/script.c index aeaf851b1..4bd1be6aa 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -10604,9 +10604,9 @@ static BUILDIN(gettime) return true; } -/*========================================== +/* * GetTimeStr("TimeFMT", Length); - *------------------------------------------*/ + */ static BUILDIN(gettimestr) { char *tmpstr; @@ -10614,8 +10614,8 @@ static BUILDIN(gettimestr) int maxlen; time_t now; - fmtstr=script_getstr(st,2); - maxlen=script_getnum(st,3); + fmtstr = script_getstr(st, 2); + maxlen = script_getnum(st, 3); if (script_hasdata(st, 4)) { int timestamp = script_getnum(st, 4); @@ -10629,11 +10629,11 @@ static BUILDIN(gettimestr) now = time(NULL); } - tmpstr=(char *)aMalloc((maxlen+1)*sizeof(char)); - strftime(tmpstr,maxlen,fmtstr,localtime(&now)); - tmpstr[maxlen]='\0'; + tmpstr = (char *)aMalloc((maxlen +1)*sizeof(char)); + strftime(tmpstr, maxlen, fmtstr, localtime(&now)); + tmpstr[maxlen] = '\0'; - script_pushstr(st,tmpstr); + script_pushstr(st, tmpstr); return true; } -- cgit v1.2.3-60-g2f50