Skip to content

Commit

Permalink
Changing QVM API version to 10 due to i've add int QVMstrftime( char …
Browse files Browse the repository at this point in the history
…*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.
  • Loading branch information
qqshka committed Oct 4, 2006
1 parent ea615cb commit 68a2d11
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
10 changes: 7 additions & 3 deletions source/g_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand All @@ -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
//
Expand Down Expand Up @@ -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
Expand Down
49 changes: 47 additions & 2 deletions source/pr2_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
//===========================================================================
Expand Down Expand Up @@ -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]);

Expand Down

0 comments on commit 68a2d11

Please sign in to comment.