From 68a2d11b3de41e632a127f6a219da10690e02b54 Mon Sep 17 00:00:00 2001 From: Ivan Bolsunov Date: Wed, 4 Oct 2006 23:03:44 +0000 Subject: [PATCH] Changing QVM API version to 10 due to i've add int QVMstrftime( char *valbuff, int sizebuff, const char *fmt, int offset ), allows me get system date/time in form i want, old mods may work without changes/recompilation. --- source/g_public.h | 10 +++++++--- source/pr2_cmds.c | 49 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/source/g_public.h b/source/g_public.h index 7103f7d6..5948eec0 100644 --- a/source/g_public.h +++ b/source/g_public.h @@ -20,7 +20,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * - * $Id: g_public.h,v 1.8 2006/05/15 00:00:46 qqshka Exp $ + * $Id: g_public.h,v 1.9 2006/10/04 23:03:44 qqshka Exp $ */ #ifndef __G_PUBLIC_H__ @@ -31,11 +31,13 @@ // // g_public.h -- game module information visible to server -#define GAME_API_VERSION 9 +#define GAME_API_VERSION 10 //=============================================================== +// !!! new traps comes to end of list !!! + // // system traps provided by the main engine // @@ -129,9 +131,11 @@ typedef enum G_Add_Bot, G_Remove_Bot, G_SetBotUserInfo, - G_SetBotCMD + G_SetBotCMD, + G_QVMstrftime } gameImport_t; +// !!! new things comes to end of list !!! // // functions exported by the game subsystem diff --git a/source/pr2_cmds.c b/source/pr2_cmds.c index f43def16..327117ad 100644 --- a/source/pr2_cmds.c +++ b/source/pr2_cmds.c @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * - * $Id: pr2_cmds.c,v 1.34 2006/08/13 00:15:21 qqshka Exp $ + * $Id: pr2_cmds.c,v 1.35 2006/10/04 23:03:44 qqshka Exp $ */ #ifdef USE_PR2 @@ -2368,6 +2368,50 @@ void PF2_SetBotCMD( byte * base, unsigned int mask, pr2val_t * stack, pr2val_t * } } +//========================================= +// some time support in QVM +//========================================= + +/* +============== +PF2_QVMstrftime +============== +*/ +void PF2_QVMstrftime(byte* base, unsigned int mask, pr2val_t* stack, pr2val_t*retval) +//(char *valbuff, int sizebuff, char *fmt, int offset) +{ + char *valbuff = VM_POINTER(base,mask,stack[0].string); + int sizebuff = stack[1]._int; + char *fmt = VM_POINTER(base,mask,stack[2].string); + int offset = stack[3]._int; + + struct tm *newtime; + time_t long_time; + + if (sizebuff <= 0 || !valbuff) { + Con_DPrintf("PF2_QVMstrftime: wrong buffer\n"); + return; + } + + time(&long_time); + long_time += offset; + newtime = localtime(&long_time); + + if (!newtime) + { + valbuff[0] = 0; // or may be better set to "#bad date#" ? + return; + } + + retval->_int = strftime(valbuff, sizebuff-1, fmt, newtime); + + if (!retval->_int) { + valbuff[0] = 0; // or may be better set to "#bad date#" ? + Con_DPrintf("PF2_QVMstrftime: buffer size too small\n"); + return; + } +} + //=========================================================================== // SysCalls //=========================================================================== @@ -2459,7 +2503,8 @@ pr2_trapcall_t pr2_API[]= PF2_Add_Bot, PF2_Remove_Bot, PF2_SetBotUserInfo, - PF2_SetBotCMD + PF2_SetBotCMD, + PF2_QVMstrftime // G_QVMstrftime }; int pr2_numAPI = sizeof(pr2_API)/sizeof(pr2_API[0]);