123
This commit is contained in:
278
PunkBuster/pbcl.cpp
Normal file
278
PunkBuster/pbcl.cpp
Normal file
@@ -0,0 +1,278 @@
|
||||
// Copyright (C) 2001-2003 Even Balance, Inc.
|
||||
//
|
||||
//
|
||||
// pbcl.cpp
|
||||
//
|
||||
// EVEN BALANCE - T.RAY
|
||||
//
|
||||
|
||||
|
||||
|
||||
#define _cplusplus
|
||||
|
||||
|
||||
|
||||
#include "pbmd5.h"
|
||||
|
||||
#if !defined(NOT_USE_PUNKBUSTER_SDK)
|
||||
|
||||
#define PbSdk_DEFINED
|
||||
#include "pbsdk.h"
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
|
||||
|
||||
|
||||
//
|
||||
// PbClGameCommand
|
||||
//
|
||||
extern void PBpakNames ( char *buf ) ;
|
||||
char * __cdecl PbClGameCommand ( char *Cmd , char *Result )
|
||||
{
|
||||
char *arg1 = Result ;
|
||||
while ( *arg1 == ' ' ) ++arg1 ;
|
||||
while ( *arg1 && *arg1 != ' ' ) ++arg1 ;
|
||||
while ( *arg1 == ' ' ) ++arg1 ;
|
||||
|
||||
if ( !stricmp ( Cmd , "set_cl_punkbuster" ) ) pbsdk->pb_SetClPunkBuster ( Result ) ;
|
||||
else if ( !stricmp ( Cmd , "pakNames" ) )
|
||||
PBpakNames ( Result ) ;//note: Result must be 1025+ bytes for this one
|
||||
else if ( !stricmp ( Cmd , "Cvar_Set" ) ) pbsdk->pb_CvarSet ( Result , arg1 ) ;
|
||||
else if ( !stricmp ( Cmd , "Cmd_Exec" ) ) pbsdk->pb_ExecCmd ( Result ) ;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//extern int PbSearchBindings ( char *subtext , int iStart ) ; //cl_keys.c
|
||||
//
|
||||
// PbClGameQuery
|
||||
//
|
||||
// assumes Data points to buffer at least as large as PB_Q_MAXRESULTLEN+1
|
||||
//
|
||||
char * __cdecl PbClGameQuery ( int Qtype , char *Data )
|
||||
{
|
||||
if ( Data == NULL ) return NULL ;
|
||||
|
||||
Data[PB_Q_MAXRESULTLEN] = 0 ;
|
||||
|
||||
char *arg2 = Data , *name , *string , *resetString ;
|
||||
int i , n , flags ;
|
||||
|
||||
while ( *arg2 && *arg2 != ' ' ) ++arg2 ;
|
||||
while ( *arg2 == ' ' ) ++arg2 ;
|
||||
switch ( Qtype ) {
|
||||
case PB_Q_CVAR: strncpy ( Data , pbsdk->pb_GetCvarValue ( Data ) , PB_Q_MAXRESULTLEN ) ; break ;
|
||||
case PB_Q_SINFO: strncpy ( Data , pbsdk->pb_GetKeyValue ( pbsdk->pb_GetServerInfo() , Data ) , PB_Q_MAXRESULTLEN ) ; break ;
|
||||
case PB_Q_SADDR: strncpy ( Data , pbsdk->pb_GetServerAddr() , PB_Q_MAXRESULTLEN ) ; break ;
|
||||
case PB_Q_SEARCHBINDINGS:
|
||||
n = pbsdk->pb_GetMaxKeys() ;
|
||||
for ( i = atoi ( Data ) ; i < n ; i++ )
|
||||
if ( stristr ( pbsdk->pb_GetKeyBinding ( i ) , arg2 ) != NULL ) {
|
||||
itoa ( i , Data , 10 ) ;
|
||||
return NULL ;
|
||||
}
|
||||
itoa ( -1 , Data , 10 ) ;
|
||||
break ;
|
||||
case PB_Q_GETBINDING:
|
||||
strncpy ( Data , pbsdk->pb_GetKeyBinding ( atoi ( Data ) ) , PB_Q_MAXRESULTLEN ) ; break ;
|
||||
case PB_Q_KEYNAME:
|
||||
strncpy ( Data , pbsdk->pb_GetKeyName ( atoi ( Data ) ) , PB_Q_MAXRESULTLEN ) ; break ;
|
||||
case PB_Q_SEARCHCVARS:
|
||||
if ( ! (*Data) ) break ;
|
||||
while ( pbsdk->pb_CvarWalk ( &name , &string , &flags , &resetString ) ) {
|
||||
if ( name == NULL || string == NULL ) continue ;
|
||||
if ( !(*name) || !(*string) ) continue ;
|
||||
if ( stristr ( string , Data ) != NULL ) {
|
||||
strncpy ( Data , name , PB_Q_MAXRESULTLEN ) ;
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
*Data = 0 ;
|
||||
break ;
|
||||
case PB_Q_CVARVALID: return pbsdk->pb_CvarValidate ( Data ) ;
|
||||
case PB_Q_CVARFLAGS: //note: this query type returns NULL when done only, cvar name otherwise
|
||||
if ( pbsdk->pb_CvarWalk ( &name , &string , &flags , &resetString ) == 0 ) return NULL ;
|
||||
if ( name == NULL ) name = "" ;
|
||||
itoa ( flags , Data , 10 ) ;
|
||||
return name ;
|
||||
case PB_Q_CVARDEFAULTS: //note: this query type returns NULL when done only, cvar name otherwise
|
||||
if ( pbsdk->pb_CvarWalk ( &name , &string , &flags , &resetString ) == 0 ) return NULL ;
|
||||
if ( name == NULL || string == NULL || resetString == NULL ) name = string = resetString = "" ;
|
||||
if ( !strcmp ( string , resetString ) ) *Data = 0 ;
|
||||
else {
|
||||
strncpy ( Data + 1 , resetString , PB_Q_MAXRESULTLEN - 2 ) ;
|
||||
Data[0] = '"' ;
|
||||
strcat ( Data , "\"" ) ;
|
||||
}
|
||||
return name ;
|
||||
case PB_Q_EXEINSTANCE:
|
||||
#ifdef __PBWIN32__
|
||||
return (char *) pbsdk->exeInstance ;
|
||||
#else
|
||||
strncpy ( Data , (char *) pbsdk->exeInstance , PB_Q_MAXRESULTLEN ) ;
|
||||
return NULL ;
|
||||
#endif
|
||||
case PB_Q_DLLHANDLE: return (char *) pbsdk->pb_DllHandle ( Data ) ;
|
||||
default: *Data = 0 ; break ;
|
||||
}
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
//
|
||||
// PbClGameMsg
|
||||
//
|
||||
char * __cdecl PbClGameMsg ( char *Msg , int Type )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return NULL ;
|
||||
|
||||
Type;//reserved
|
||||
pbsdk->pb_Outf ( "%s: %s\n" , pbsdk->pbcl.m_msgPrefix , Msg ) ;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// PbClSendToServer
|
||||
//
|
||||
char * __cdecl PbClSendToServer ( int DataLen , char *Data )
|
||||
{
|
||||
pbsdk->pb_SendClPacket ( DataLen , Data ) ;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// PbClSendToAddrPort
|
||||
//
|
||||
char * __cdecl PbClSendToAddrPort ( char *addr , unsigned short port , int DataLen , char *Data )
|
||||
{
|
||||
pbsdk->pb_SendUdpPacket ( addr , port , DataLen , Data , 1 ) ;//1 means coming from client
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Function wrappers used to call C++ functions from C
|
||||
// these are declared in pbcommon.h
|
||||
|
||||
extern "C" {
|
||||
|
||||
void __cdecl PbClAddEvent ( int event , int datalen , char *data )
|
||||
{
|
||||
if ( pbsdk == NULL ) return ;
|
||||
pbsdk->pbcl.AddPbEvent ( event , datalen , data , 0 ) ;
|
||||
}
|
||||
|
||||
int __cdecl PbTrapPreExecCmd ( char *cmdtext )//return 0 if game should continue exec'ing the command, 1 if not
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return 0 ;
|
||||
if ( pbsdk->pbcl.m_TrapPreExecCmd == NULL ) return 0 ;
|
||||
return pbsdk->pbcl.m_TrapPreExecCmd ( &pbsdk->pbcl , cmdtext ) ;
|
||||
}
|
||||
|
||||
void __cdecl PbClientTrapConsole ( char *msg , int msglen )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return ;
|
||||
if ( pbsdk->pbcl.m_TrapConsole == NULL ) return ;
|
||||
pbsdk->pbcl.m_TrapConsole ( &pbsdk->pbcl , msg , msglen ) ;
|
||||
}
|
||||
|
||||
void __cdecl PbClientInitialize ( void *exeInst )
|
||||
{
|
||||
if ( pbsdk == NULL ) return ;
|
||||
|
||||
pbsdk->exeInstance = exeInst ;
|
||||
pbsdk->pbcl.pbsvptr = &pbsdk->pbsv ;
|
||||
pbsdk->pbcl.initialize() ;
|
||||
|
||||
pbsdk->pb_getBasePath ( pbsdk->pbcl.m_basepath , PB_Q_MAXRESULTLEN ) ;
|
||||
pbsdk->pb_getHomePath ( pbsdk->pbcl.m_homepath , PB_Q_MAXRESULTLEN ) ;
|
||||
|
||||
PbClAddEvent ( PB_EV_CONFIG , 0 , "" ) ;
|
||||
if ( pbsdk->pbcl.m_ClInstance == NULL ) pbsdk->pb_SetClPunkBuster ( "0" ) ;
|
||||
}
|
||||
|
||||
void __cdecl PbClientProcessEvents ( void )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return ;
|
||||
pbsdk->pbcl.ProcessPbEvents() ;
|
||||
}
|
||||
|
||||
void __cdecl PbClientForceProcess ( void )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return ;
|
||||
pbsdk->pbcl.ProcessPbEvents ( -1 ) ;
|
||||
}
|
||||
|
||||
//added for Enemy Territory - PB knows max pktlen is 1024
|
||||
void __cdecl PbClientConnecting ( int status , char *pkt , int *pktlen )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return ;
|
||||
if ( pbsdk->pbcl.m_ClientConnect == NULL ) return ;
|
||||
pbsdk->pbcl.m_ClientConnect ( &pbsdk->pbcl , status , pkt , pktlen ) ;
|
||||
}
|
||||
|
||||
void __cdecl PbClientCompleteCommand ( char *buf , int buflen )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return ;
|
||||
pbsdk->pbcl.AddPbEvent ( PB_EV_CMDCOMPL , buflen , buf ) ;
|
||||
}
|
||||
|
||||
void __cdecl md5Digest2text ( MD5_CTX *m , char *textbuf )//assumes textbuf is 33+ chars
|
||||
{
|
||||
sprintf ( textbuf , "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||
(int) m->digest[0] , (int) m->digest[1] , (int) m->digest[2] , (int) m->digest[3] ,
|
||||
(int) m->digest[4] , (int) m->digest[5] , (int) m->digest[6] , (int) m->digest[7] ,
|
||||
(int) m->digest[8] , (int) m->digest[9] , (int) m->digest[10] , (int) m->digest[11] ,
|
||||
(int) m->digest[12] , (int) m->digest[13] , (int) m->digest[14] , (int) m->digest[15] ) ;
|
||||
}
|
||||
|
||||
char * __cdecl PbSetGuid ( char *nums , int len )//updated for ET
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return "" ;
|
||||
MD5_CTX m ;
|
||||
MD5Init ( &m , 11961507 ) ;
|
||||
MD5Update ( &m , (unsigned char *) nums , len ) ;
|
||||
MD5Final ( &m ) ;
|
||||
md5Digest2text ( &m , pbsdk->pbcl.m_guid ) ;
|
||||
MD5Init ( &m , 334422 ) ;
|
||||
MD5Update ( &m , (unsigned char *) pbsdk->pbcl.m_guid , strlen ( pbsdk->pbcl.m_guid ) ) ;
|
||||
MD5Final ( &m ) ;
|
||||
md5Digest2text ( &m , pbsdk->pbcl.m_guid ) ;
|
||||
return pbsdk->pbcl.m_guid ;
|
||||
}
|
||||
|
||||
int __cdecl isPbClEnabled ( void )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return 0 ;
|
||||
return (int) pbsdk->pbcl.AddPbEvent ( PB_EV_ISENABLED , 0 , NULL ) ;
|
||||
}
|
||||
|
||||
int __cdecl getPbGuidAge ( void )
|
||||
{
|
||||
if ( !isPbClEnabled() ) return -2 ;
|
||||
return (int) pbsdk->pbcl.AddPbEvent ( PB_EV_GUIDAGE , 0 , NULL ) ;//returns -1 if bad/missing cdkey
|
||||
}
|
||||
|
||||
void __cdecl EnablePbCl ( void )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return ;
|
||||
pbsdk->pbcl.AddPbEvent ( PB_EV_ENABLE , 0 , NULL ) ;
|
||||
}
|
||||
|
||||
void __cdecl DisablePbCl ( void )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return ;
|
||||
pbsdk->pbcl.AddPbEvent ( PB_EV_DISABLE , 0 , NULL ) ;
|
||||
}
|
||||
|
||||
} //extern "C"
|
||||
|
||||
#endif //#ifdef __WITHPB__
|
||||
#endif // NOT_USE_PUNKBUSTER_SDK
|
||||
296
PunkBuster/pbcl.h
Normal file
296
PunkBuster/pbcl.h
Normal file
@@ -0,0 +1,296 @@
|
||||
// Copyright (C) 2001-2003 Even Balance, Inc.
|
||||
//
|
||||
//
|
||||
// pbcl.h
|
||||
//
|
||||
// EVEN BALANCE - T.RAY
|
||||
//
|
||||
// The only file in the game project that needs to include this file is pbcl.cpp
|
||||
//
|
||||
|
||||
|
||||
#ifndef __PBCL_H__
|
||||
#define __PBCL_H__
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "pbcommon.h"
|
||||
|
||||
|
||||
#if !defined(NOT_USE_PUNKBUSTER_SDK)
|
||||
|
||||
#ifdef __PBWIN32__
|
||||
#include <direct.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifdef __PBLINUX__
|
||||
#include <unistd.h>
|
||||
#include "CryLibrary.h"
|
||||
#endif
|
||||
#ifdef __PBMAC__
|
||||
#include <unistd.h>
|
||||
#include "../macosx/dlfcn.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
|
||||
|
||||
|
||||
#ifdef _cplusplus
|
||||
|
||||
|
||||
|
||||
#ifndef __PBDLL__
|
||||
extern char *ca ( void *cp , int ticklimit ) ;
|
||||
extern char *cb ( void *cp , int event , int datalen , char *data , int retry ) ;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Class/Struct Definitions
|
||||
//
|
||||
struct stPbCl {
|
||||
int m_clId ;
|
||||
void *m_Md5 ;
|
||||
void *m_ClInstance , *m_AgInstance ;
|
||||
int m_ReloadClient ;
|
||||
char m_guid[PB_GUIDLEN+1] , m_msgPrefix[PB_MISCLEN+1] , m_CdKeyNums[17] ,
|
||||
m_basepath[PB_Q_MAXRESULTLEN+4] , m_homepath[PB_Q_MAXRESULTLEN+4] , m_cwd[PB_Q_MAXRESULTLEN+4] ;
|
||||
|
||||
unsigned int rk1 , rk2 , rk3 , rk4 ;
|
||||
|
||||
//func ptrs
|
||||
tdPbGameCommand m_GameCommand ;
|
||||
tdPbGameQuery m_GameQuery ;
|
||||
tdPbGameMsg m_GameMsg ;
|
||||
tdPbSendToServer m_SendToServer ;
|
||||
tdPbAddClEvent m_AddPbEvent ;
|
||||
tdPbProcessPbEvents m_ProcessPbEvents ;
|
||||
tdPbSendToAddrPort m_SendToAddrPort ;
|
||||
tdPbGlQuery m_GlQuery ;
|
||||
tdPbClientConnect m_ClientConnect ;
|
||||
tdPbTrapPreExecCmd m_TrapPreExecCmd ;
|
||||
tdPbTrapConsole m_TrapConsole ;
|
||||
|
||||
void *pbsvptr ;
|
||||
|
||||
inline char *getBasePath ( char *path ) {
|
||||
strncpy ( path , m_basepath , PB_Q_MAXRESULTLEN ) ;
|
||||
path[PB_Q_MAXRESULTLEN] = 0 ;
|
||||
if ( !(*path) ) getcwd ( path , PB_Q_MAXRESULTLEN - 4 ) ;
|
||||
if ( *path && path[strlen(path)-1] != *pbDIRSEP ) strcat ( path , pbDIRSEP ) ;
|
||||
strcat ( path , "pb" pbDIRSEP ) ;
|
||||
return path ;
|
||||
}
|
||||
|
||||
inline char *getHomePath ( char *path ) {
|
||||
strncpy ( path , m_homepath , PB_Q_MAXRESULTLEN ) ;
|
||||
path[PB_Q_MAXRESULTLEN] = 0 ;
|
||||
if ( !(*path) ) getcwd ( path , PB_Q_MAXRESULTLEN - 4 ) ;
|
||||
if ( *path && path[strlen(path)-1] != *pbDIRSEP ) strcat ( path , pbDIRSEP ) ;
|
||||
strcat ( path , "pb" pbDIRSEP ) ;
|
||||
return path ;
|
||||
}
|
||||
|
||||
inline char *makefn ( char *buf , char *fn ) { //assumes buf is large enough to hold cwd + fn + overhead
|
||||
if ( !(*m_cwd) ) {
|
||||
getHomePath ( m_cwd ) ;
|
||||
}
|
||||
strcpy ( buf , m_cwd ) ;
|
||||
strcat ( buf , fn ) ;
|
||||
return buf ;
|
||||
}
|
||||
|
||||
inline void UnloadAgentDll ( void ) {
|
||||
if ( m_AgInstance == NULL ) return ;
|
||||
#ifdef __PBWIN32__
|
||||
FreeLibrary ( (HINSTANCE) m_AgInstance ) ;
|
||||
#endif
|
||||
#ifdef __PBLINUX__
|
||||
dlclose ( m_AgInstance ) ;
|
||||
#endif
|
||||
#ifdef __PBMAC__
|
||||
dlclose ( m_AgInstance ) ;
|
||||
#endif
|
||||
m_AgInstance = NULL ;
|
||||
}
|
||||
|
||||
inline void LoadAgentDll ( void ) {
|
||||
if ( m_AgInstance != NULL ) return ;
|
||||
UnloadAgentDll() ;
|
||||
|
||||
char fn[PB_Q_MAXRESULTLEN*2+1] ;
|
||||
|
||||
#ifdef __PBWIN32__
|
||||
m_AgInstance = LoadLibraryA ( makefn ( fn , "pbag" pbDLLEXT ) ) ;
|
||||
#endif
|
||||
#ifdef __PBLINUX__
|
||||
m_AgInstance = ::dlopen ( makefn ( fn , "pbag" pbDLLEXT ) , RTLD_LAZY ) ;
|
||||
#endif
|
||||
#ifdef __PBMAC__
|
||||
m_AgInstance = dlopen ( makefn ( fn , "pbag" pbDLLEXT ) , RTLD_LAZY ) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef __PBDLL__ //the following functions are not needed by the PB DLLs
|
||||
|
||||
inline void uninitialize ( void ) {//also initializes game-side func ptrs
|
||||
m_GameCommand = NULL ;
|
||||
m_GameQuery = NULL ;
|
||||
m_GameMsg = NULL ;
|
||||
m_SendToServer = NULL ;
|
||||
}
|
||||
|
||||
inline void initialize ( void ) {
|
||||
uninitialize() ;
|
||||
m_GameCommand = PbClGameCommand ;
|
||||
m_GameQuery = PbClGameQuery ;
|
||||
m_GameMsg = PbClGameMsg ;
|
||||
m_SendToServer = PbClSendToServer ;
|
||||
m_SendToAddrPort = PbClSendToAddrPort ;
|
||||
//note: m_GlQuery is set in pbsdk.h
|
||||
}
|
||||
|
||||
inline void UnloadClientDll ( void ) {
|
||||
m_ProcessPbEvents = NULL ;
|
||||
m_AddPbEvent = NULL ;
|
||||
m_ClientConnect = NULL ;
|
||||
m_TrapPreExecCmd = NULL ;
|
||||
m_TrapConsole = NULL ;
|
||||
if ( m_ClInstance == NULL ) return ;
|
||||
|
||||
#ifdef __PBWIN32__
|
||||
FreeLibrary ( (HMODULE) m_ClInstance ) ;
|
||||
#endif
|
||||
#ifdef __PBLINUX__
|
||||
dlclose ( m_ClInstance ) ;
|
||||
#endif
|
||||
#ifdef __PBMAC__
|
||||
dlclose ( m_ClInstance ) ;
|
||||
#endif
|
||||
m_ClInstance = NULL ;
|
||||
}
|
||||
|
||||
inline char *LoadClientDll ( void ) {
|
||||
if ( m_ClInstance != NULL ) return NULL ;
|
||||
UnloadClientDll() ;
|
||||
|
||||
char fn[PB_Q_MAXRESULTLEN*2+1] , extrafn[PB_Q_MAXRESULTLEN*2+1] ;
|
||||
|
||||
//check for replacement (updated) dll file and rename if necessary
|
||||
//load PB client dll and retrieve exported function pointers
|
||||
FILE *f = fopen ( makefn ( fn , "pbclnew" pbDLLEXT ) , "rb" ) ;
|
||||
if ( f != NULL ) {
|
||||
fclose ( f ) ;
|
||||
setRW ( makefn ( fn , "pbclold" pbDLLEXT ) ) ;
|
||||
remove ( makefn ( fn , "pbclold" pbDLLEXT ) ) ;
|
||||
rename ( makefn ( fn , "pbcl" pbDLLEXT ) , makefn ( extrafn , "pbclold" pbDLLEXT ) ) ;
|
||||
setRW ( makefn ( fn , "pbcl" pbDLLEXT ) ) ;
|
||||
remove ( makefn ( fn , "pbcl" pbDLLEXT ) ) ;
|
||||
rename ( makefn ( fn , "pbclnew" pbDLLEXT ) , makefn ( extrafn , "pbcl" pbDLLEXT ) ) ;
|
||||
}
|
||||
#ifdef __PBWIN32__
|
||||
m_ClInstance = LoadLibraryA ( makefn ( fn , "pbcl" pbDLLEXT ) ) ;
|
||||
if ( m_ClInstance == NULL ) return PbsClDllLoadFail ;
|
||||
m_ProcessPbEvents = (tdPbProcessPbEvents) GetProcAddress ( (HINSTANCE) m_ClInstance , "ca" ) ;
|
||||
m_AddPbEvent = (tdPbAddClEvent) GetProcAddress ( (HINSTANCE) m_ClInstance , "cb" ) ;
|
||||
#endif
|
||||
#ifdef __PBLINUX__
|
||||
m_ClInstance = ::dlopen ( makefn ( fn , "pbcl" pbDLLEXT ) , RTLD_LAZY ) ;
|
||||
if ( m_ClInstance == NULL ) return PbsClDllLoadFail ;
|
||||
m_ProcessPbEvents = (tdPbProcessPbEvents) dlsym ( m_ClInstance , "ca" ) ;
|
||||
m_AddPbEvent = (tdPbAddClEvent) dlsym ( m_ClInstance , "cb" ) ;
|
||||
#endif
|
||||
#ifdef __PBMAC__
|
||||
m_ClInstance = dlopen ( makefn ( fn , "pbcl" pbDLLEXT ) , RTLD_LAZY ) ;
|
||||
if ( m_ClInstance == NULL ) return PbsClDllLoadFail ;
|
||||
m_ProcessPbEvents = (tdPbProcessPbEvents) dlsym ( m_ClInstance , "_ca" ) ;
|
||||
m_AddPbEvent = (tdPbAddClEvent) dlsym ( m_ClInstance , "_cb" ) ;
|
||||
#endif
|
||||
|
||||
if ( m_ProcessPbEvents == NULL || m_AddPbEvent == NULL ) {
|
||||
UnloadClientDll() ;
|
||||
return PbsClDllProcFail ;
|
||||
}
|
||||
|
||||
m_ReloadClient = 0 ;
|
||||
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
inline char *AddPbEvent ( int type , int datalen , char *data , int retry = 0 ) {
|
||||
if ( m_GameCommand == NULL ) return NULL ;//not considered an error, this signifies that PB is disabled
|
||||
|
||||
if ( m_ReloadClient || m_ClInstance == NULL ) {
|
||||
if ( m_ClInstance != NULL ) {
|
||||
UnloadClientDll() ;
|
||||
return NULL ;
|
||||
}
|
||||
char *res = LoadClientDll() ;
|
||||
if ( res != NULL ) {
|
||||
if ( type == PB_EV_ISENABLED ) return (char *) 0 ;
|
||||
return res ;
|
||||
}
|
||||
}
|
||||
|
||||
return m_AddPbEvent ( this , type , datalen , data , retry ) ;
|
||||
}
|
||||
|
||||
inline char *ProcessPbEvents ( int TickLimit = 0 ) {
|
||||
if ( m_GameCommand == NULL ) return NULL ;//not considered an error, this signifies that PB is disabled
|
||||
if ( m_ClInstance == NULL ) {
|
||||
if ( m_ReloadClient ) AddPbEvent ( PB_EV_CONFIG , 0 , "" ) ;
|
||||
return NULL ;//no events have been successfully added so nothing to process
|
||||
}
|
||||
|
||||
if ( m_ReloadClient ) {
|
||||
UnloadClientDll() ;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
return m_ProcessPbEvents ( this , TickLimit ) ;
|
||||
}
|
||||
|
||||
inline void init ( void ) {
|
||||
memset ( this , 0 , sizeof ( stPbCl ) ) ;
|
||||
m_clId = PB_CL_ID ;
|
||||
strcpy ( m_msgPrefix , "PunkBuster Client" ) ;
|
||||
m_ClInstance = m_AgInstance = NULL ;
|
||||
m_ReloadClient = 1 ;
|
||||
uninitialize() ;
|
||||
m_Md5 = NULL ;
|
||||
m_AddPbEvent = NULL ;
|
||||
m_ProcessPbEvents = NULL ;
|
||||
m_SendToAddrPort = NULL ;
|
||||
m_GlQuery = NULL ;
|
||||
m_ClientConnect = NULL ;
|
||||
m_TrapPreExecCmd = NULL ;
|
||||
m_TrapConsole = NULL ;
|
||||
}
|
||||
|
||||
inline stPbCl() {
|
||||
init() ;
|
||||
}
|
||||
|
||||
inline ~stPbCl() {
|
||||
UnloadClientDll() ;
|
||||
UnloadAgentDll() ;
|
||||
}
|
||||
|
||||
#endif //#ifndef __PBDLL__
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
#endif //#ifdef _cplusplus
|
||||
#endif //#ifdef __WITHPB__
|
||||
#endif //#ifndef __PBCL_H__
|
||||
|
||||
#endif // NOT_USE_PUNKBUSTER_SDK
|
||||
414
PunkBuster/pbcommon.h
Normal file
414
PunkBuster/pbcommon.h
Normal file
@@ -0,0 +1,414 @@
|
||||
// Copyright (C) 2001-2003 Even Balance, Inc.
|
||||
//
|
||||
//
|
||||
// pbcommon.h
|
||||
//
|
||||
// EVEN BALANCE - T.RAY
|
||||
//
|
||||
|
||||
|
||||
|
||||
//NOTE: Comment the following line to completely remove PB from the game source build
|
||||
#define __WITH_PB__
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
|
||||
|
||||
|
||||
#ifndef __PBCOMMON__
|
||||
#define __PBCOMMON__
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
extern int isPBmultiplayerMode ( void ) ;//defined in PunkBusterInterface.cpp
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if !defined(NOT_USE_PUNKBUSTER_SDK)
|
||||
//
|
||||
// Ugly Platform dependency handling
|
||||
//
|
||||
#if defined (LINUX)
|
||||
#define __linux__
|
||||
#endif
|
||||
#if defined (_WIN32)
|
||||
#define __PBWIN32__
|
||||
#elif defined (__linux__)
|
||||
#define __PBLINUX__
|
||||
#else
|
||||
#define __PBMAC__
|
||||
#endif
|
||||
#ifdef __PBWIN32__
|
||||
#include <direct.h>
|
||||
#include <tchar.h>
|
||||
#include <io.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#ifndef __PBDLL__
|
||||
#define pbDLLEXT ".dll"
|
||||
#define pbDIRSEP "\\"
|
||||
#else
|
||||
#define TCHAR char
|
||||
#endif
|
||||
#endif //#ifdef __PBWIN32__
|
||||
#ifdef __PBLINUX__
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#ifndef __PBDLL__
|
||||
#define pbDLLEXT ".so"
|
||||
#define pbDIRSEP "/"
|
||||
#define stricmp strcasecmp
|
||||
#define strnicmp strncasecmp
|
||||
#endif
|
||||
#endif //#ifdef __PBLINUX__
|
||||
#ifdef __PBMAC__
|
||||
#ifndef __PBDLL__
|
||||
#define pbDLLEXT ".mac"
|
||||
#define pbDIRSEP ":"
|
||||
#define stricmp _stricmp
|
||||
#define strnicmp _strnicmp
|
||||
#endif
|
||||
#endif //#ifdef __PBMAC__
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Forward Function Declarations - PB functions called from inside game engine, defined in pbcl.cpp and pbsv.cpp
|
||||
//
|
||||
|
||||
extern "C" {
|
||||
|
||||
extern void __cdecl PbClientInitialize ( void *exeInst ) ;
|
||||
extern void __cdecl PbClAddEvent ( int event , int datalen , char *data ) ;
|
||||
extern void __cdecl PbClientProcessEvents ( void ) ;
|
||||
extern int __cdecl PbTrapPreExecCmd ( char *cmdtext ) ;
|
||||
extern void __cdecl PbClientTrapConsole ( char *msg , int msglen ) ;
|
||||
extern void __cdecl PbClientForceProcess ( void ) ;
|
||||
extern void __cdecl PBClientConnecting ( int , char * , int * ) ;
|
||||
extern void __cdecl PbClientCompleteCommand ( char *buf , int buflen ) ;
|
||||
extern int __cdecl isPbClEnabled ( void ) ;
|
||||
extern int __cdecl getPbGuidAge ( void ) ;
|
||||
extern void __cdecl EnablePbCl ( void ) ;
|
||||
extern void __cdecl DisablePbCl ( void ) ;
|
||||
extern char * __cdecl PbSetGuid ( char *nums , int len ) ;
|
||||
|
||||
extern void __cdecl PbServerInitialize ( void ) ;
|
||||
extern void __cdecl PbSvAddEvent ( int event , int clientIndex , int datalen , char *data ) ;
|
||||
extern void __cdecl PbPassConnectString ( char *fromAddr , char *connectString ) ;
|
||||
extern char * __cdecl PbAuthClient ( char *fromAddr , int cl_pb , char *cl_guid ) ;
|
||||
extern void __cdecl PbServerProcessEvents ( void ) ;
|
||||
extern void __cdecl PbServerForceProcess ( void ) ;
|
||||
extern void __cdecl PbServerCompleteCommand ( char *buf , int buflen ) ;
|
||||
extern int __cdecl isPbSvEnabled ( void ) ;
|
||||
extern void __cdecl EnablePbSv ( void ) ;
|
||||
extern void __cdecl DisablePbSv ( void ) ;
|
||||
extern void __cdecl PbCaptureConsoleOutput ( char *msg , int msglen ) ;
|
||||
|
||||
} //extern "C"
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Typedefs
|
||||
//
|
||||
|
||||
// game-side func typedefs
|
||||
typedef char *(__cdecl *tdPbGameCommand) ( char * , char * ) ;
|
||||
typedef char *(__cdecl *tdPbGameQuery) ( int , char * ) ;
|
||||
typedef char *(__cdecl *tdPbGameMsg) ( char * , int ) ;
|
||||
typedef char *(__cdecl *tdPbSendToServer) ( int , char * ) ;
|
||||
typedef char *(__cdecl *tdPbSendToClient) ( int , char * , int ) ;
|
||||
typedef char *(__cdecl *tdPbSendToAddrPort) ( char * , unsigned short , int , char * ) ;
|
||||
|
||||
// pb-side func typedefs
|
||||
typedef char *(*tdPbAddClEvent) ( void * , int , int , char * , int ) ;
|
||||
typedef char *(*tdPbAddSvEvent) ( void * , int , int , int , char * , int ) ;
|
||||
typedef char *(*tdPbProcessPbEvents) ( void * , int ) ;
|
||||
typedef char *(*tdPbGlQuery) ( int ) ;
|
||||
typedef char *(*tdPbClientConnect) ( void * , int , char * , int * ) ;
|
||||
typedef char *(*tdPbPassConnectString) ( void * , char * , char * ) ;
|
||||
typedef char *(*tdPbAuthClient) ( void * , char * , int , char * ) ;
|
||||
typedef int (*tdPbTrapPreExecCmd) ( void * , char * ) ;
|
||||
typedef void (*tdPbTrapConsole) ( void * , char * , int ) ;
|
||||
|
||||
|
||||
|
||||
//
|
||||
// External Functions used by Classes (definitions in pbcl.cpp and pbsv.cpp)
|
||||
//
|
||||
extern char * __cdecl PbClGameCommand ( char * , char * ) ;
|
||||
extern char * __cdecl PbClGameQuery ( int , char * ) ;
|
||||
extern char * __cdecl PbClGameMsg ( char * , int ) ;
|
||||
extern char * __cdecl PbClSendToServer ( int , char * ) ;
|
||||
extern char * __cdecl PbClSendToAddrPort ( char * , unsigned short , int , char * ) ;
|
||||
|
||||
extern char * __cdecl PbSvGameCommand ( char * , char * ) ;
|
||||
extern char * __cdecl PbSvGameQuery ( int , char * ) ;
|
||||
extern char * __cdecl PbSvGameMsg ( char * , int ) ;
|
||||
extern char * __cdecl PbSvSendToClient ( int , char * , int ) ;
|
||||
extern char * __cdecl PbSvSendToAddrPort ( char * , unsigned short , int , char * ) ;
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Defines (Error Messages)
|
||||
//
|
||||
#define PbsQueryFail "PB Error: Query Failed"
|
||||
#define PbsClDllLoadFail "PB Error: Client DLL Load Failure"
|
||||
#define PbsClDllProcFail "PB Error: Client DLL Get Procedure Failure"
|
||||
#define PbsSvDllLoadFail "PB Error: Server DLL Load Failure"
|
||||
#define PbsSvDllProcFail "PB Error: Server DLL Get Procedure Failure"
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Defines (Game Query-related)
|
||||
//
|
||||
#define PB_Q_MAXRESULTLEN 255
|
||||
#define PB_Q_MAXCLIENTS 101
|
||||
#define PB_Q_CLIENT 102
|
||||
#define PB_Q_CVAR 103
|
||||
#define PB_Q_SINFO 104
|
||||
#define PB_Q_SADDR 105
|
||||
#define PB_Q_SEARCHBINDINGS 106
|
||||
#define PB_Q_GETBINDING 107
|
||||
#define PB_Q_KEYNAME 108
|
||||
#define PB_Q_SEARCHCVARS 109
|
||||
#define PB_Q_CVARFLAGS 110
|
||||
#define PB_Q_CVARDEFAULTS 111
|
||||
#define PB_Q_EXEINSTANCE 112
|
||||
#define PB_Q_DLLHANDLE 113
|
||||
#define PB_Q_STATS 114
|
||||
#define PB_Q_CVARVALID 115
|
||||
#define PB_Q_FILEMD5 116
|
||||
#define PB_Q_TEXTUREMD5 117
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Defines (Event-related)
|
||||
//
|
||||
#define PB_EV_PACKET 13
|
||||
#define PB_EV_CMD 14
|
||||
#define PB_EV_STAT 15
|
||||
#define PB_EV_CONFIG 16
|
||||
|
||||
#define PB_EV_CMDCOMPL 51
|
||||
|
||||
// UI subset
|
||||
#define PB_EV_UISUBSET 113
|
||||
#define PB_EV_ISENABLED 113
|
||||
#define PB_EV_ENABLE 117
|
||||
#define PB_EV_DISABLE 118
|
||||
#define PB_EV_GUIDAGE 119
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Defines (Message-related)
|
||||
//
|
||||
#define PB_MSG_CONSOLE 1
|
||||
#define PB_MSG_SCREEN 2
|
||||
#define PB_MSG_LOG 4
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Defines (Misc)
|
||||
//
|
||||
#define PB_MISCLEN 31
|
||||
#define PB_NAMELEN 32
|
||||
#define PB_GUIDLEN 32
|
||||
#define PB_MAXPKTLEN 1024
|
||||
//The following two ID values are provided by Even Balance and must be matched to the
|
||||
//values embedded in the Even Balance provided PunkBuster DLLs for the game
|
||||
#define PB_SV_ID 0x357AFE1B
|
||||
#define PB_CL_ID 0x264B8BA6
|
||||
|
||||
|
||||
|
||||
//
|
||||
//PB Client OpenGL Query Facility
|
||||
//
|
||||
#define PB_GL_READPIXELS 101
|
||||
#define PB_GL_WIDTH 102
|
||||
#define PB_GL_HEIGHT 103
|
||||
#define PB_GL_RGB 104
|
||||
#define PB_GL_UB 105
|
||||
#define PB_GL_D3DDEV 106
|
||||
|
||||
|
||||
|
||||
//
|
||||
// PB Server Integration Structs
|
||||
//
|
||||
typedef struct Pb_Sv_Client_s {
|
||||
char name[PB_NAMELEN+1] , guid[PB_GUIDLEN+1] , ip[PB_NAMELEN+1] ;
|
||||
int slotIndex ;
|
||||
} stPb_Sv_Client ;
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Forward (External) Declaration for PBsdk_SetPointers() - must be defined in each game module
|
||||
//
|
||||
extern "C" void PBsdk_getPbSdkPointer ( char *fn , unsigned int Flag ) ;
|
||||
extern "C" void PBsdk_SetPointers ( void *pbinterface ) ;
|
||||
|
||||
|
||||
|
||||
#ifndef __PBDLL__
|
||||
#ifndef __TRSTR__
|
||||
//
|
||||
// stristr
|
||||
//
|
||||
// case insensitive variation of strstr() function
|
||||
//
|
||||
inline char *stristr ( char *haystack , char *needle )
|
||||
{
|
||||
char l[2] = "x" , u[2] = "X" , *cp , *lcp = NULL ;
|
||||
int nsl ;
|
||||
|
||||
if ( haystack == NULL || needle == NULL || !(*needle) ) return haystack ;
|
||||
nsl = strlen ( needle ) ;
|
||||
*l = (char) tolower ( *needle ) ;
|
||||
for ( cp = haystack ; lcp == NULL ; ++cp ) {
|
||||
cp = strstr ( cp , l ) ;
|
||||
if ( cp == NULL ) break ;
|
||||
if ( !strnicmp ( cp , needle , nsl ) ) lcp = cp ;
|
||||
}
|
||||
*u = (char) toupper ( *needle ) ;
|
||||
if ( *l == *u ) return lcp ;
|
||||
for ( cp = haystack ; ; ++cp ) {
|
||||
cp = strstr ( cp , u ) ;
|
||||
if ( cp == NULL ) break ;
|
||||
if ( !strnicmp ( cp , needle , nsl ) ) {
|
||||
if ( lcp == NULL ) return cp ;
|
||||
if ( cp < lcp ) return cp ;
|
||||
return lcp ;
|
||||
}
|
||||
}
|
||||
return lcp ;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//
|
||||
// PbCopyFile
|
||||
//
|
||||
// returns 1 if successful, 0 if failed
|
||||
//
|
||||
inline int PbCopyFile ( char *sfn , char *tfn , int sizeLimit = 0 )
|
||||
{
|
||||
FILE *fs = fopen ( sfn , "rb" ) ;
|
||||
int success = 0 ;
|
||||
if ( fs != NULL ) {
|
||||
FILE *ft = fopen ( tfn , "wb" ) ;
|
||||
if ( ft != NULL ) {
|
||||
fseek ( fs , 0 , SEEK_END ) ;
|
||||
int siz = ftell ( fs ) ;
|
||||
if ( siz > 0 ) {
|
||||
if ( sizeLimit == 0 || siz < sizeLimit ) {
|
||||
char *buf = new char [ siz ] ;
|
||||
if ( buf != NULL ) {
|
||||
fseek ( fs , 0 , SEEK_SET ) ;
|
||||
int rb = fread ( buf , 1 , siz , fs ) ;
|
||||
int wb = fwrite ( buf , 1 , rb , ft ) ;
|
||||
delete buf ;
|
||||
if ( wb == siz ) success = 1 ;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose ( ft ) ;
|
||||
}
|
||||
fclose ( fs ) ;
|
||||
}
|
||||
return success ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// setRW
|
||||
//
|
||||
inline void setRW ( char *fn )
|
||||
{
|
||||
#ifdef __PBWIN32__
|
||||
_chmod ( fn , _S_IREAD | _S_IWRITE ) ;
|
||||
#endif
|
||||
#ifdef __PBLINUX__
|
||||
chmod ( fn , S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH ) ;
|
||||
#endif
|
||||
#ifdef __PBMAC__
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifndef __PBDLL__
|
||||
//
|
||||
// TCHARchar
|
||||
//
|
||||
// provided to convert from unicode and other wide-byte strings to standard zero-delimted ascii char string arrays used by PB
|
||||
//
|
||||
#if defined(LINUX)
|
||||
#undef TCHAR
|
||||
inline char * TCHARchar(const unsigned short *t, char *cs, int maxlenminus1)
|
||||
{
|
||||
memset ( cs , 0 , maxlenminus1 + 1 ) ;
|
||||
int i ;
|
||||
for ( i = 0 ; t[i] && i < maxlenminus1 ; i++ )
|
||||
cs[i] = (char) t[i] ;
|
||||
return cs ;
|
||||
}
|
||||
#define TCHAR wchar_t;
|
||||
#else
|
||||
inline char * TCHARchar(const TCHAR *t, char *cs, int maxlenminus1)
|
||||
{
|
||||
memset ( cs , 0 , maxlenminus1 + 1 ) ;
|
||||
int i ;
|
||||
for ( i = 0 ; t[i] && i < maxlenminus1 ; i++ )
|
||||
cs[i] = (char) t[i] ;
|
||||
return cs ;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//
|
||||
// dbLog
|
||||
//
|
||||
inline void dbLog ( char *fn , char *fmtstr , ... )
|
||||
{
|
||||
FILE *f = fopen ( fn , "abc" ) ;
|
||||
if ( f == NULL ) return ;
|
||||
|
||||
char buf[4150] ;
|
||||
va_list va ;
|
||||
|
||||
va_start ( va , fmtstr ) ;
|
||||
if ( strlen ( fmtstr ) > 2048 ) {
|
||||
strncpy ( buf , fmtstr , 4096 ) ;
|
||||
buf[4096] = 0 ;
|
||||
} else vsprintf ( buf , fmtstr , va ) ;
|
||||
|
||||
fprintf ( f , "%s\r\n" , buf ) ;
|
||||
fflush ( f ) ;
|
||||
fclose ( f ) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif //#ifndef __PBCOMMON__
|
||||
#endif //#ifdef __WITH_PB__
|
||||
#endif // NOT_USE_PUNKBUSTER_SDK
|
||||
257
PunkBuster/pbmd5.cpp
Normal file
257
PunkBuster/pbmd5.cpp
Normal file
@@ -0,0 +1,257 @@
|
||||
// PunkBuster Implementation of MD5 by RSA Data Security, Inc.
|
||||
//
|
||||
|
||||
//
|
||||
// md5.cpp
|
||||
//
|
||||
// style modified by Tony Ray, January 2001
|
||||
// added support for randomizing initialization constants in MD5Init()
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
** md5.c **
|
||||
** RSA Data Security, Inc. MD5 Message Digest Algorithm **
|
||||
** Created: 2/17/90 RLR **
|
||||
** Revised: 1/91 SRD,AJ,BSK,JT Reference C Version **
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
|
||||
** **
|
||||
** License to copy and use this software is granted provided that **
|
||||
** it is identified as the "RSA Data Security, Inc. MD5 Message **
|
||||
** Digest Algorithm" in all material mentioning or referencing this **
|
||||
** software or this function. **
|
||||
** **
|
||||
** License is also granted to make and use derivative works **
|
||||
** provided that such works are identified as "derived from the RSA **
|
||||
** Data Security, Inc. MD5 Message Digest Algorithm" in all **
|
||||
** material mentioning or referencing the derived work. **
|
||||
** **
|
||||
** RSA Data Security, Inc. makes no representations concerning **
|
||||
** either the merchantability of this software or the suitability **
|
||||
** of this software for any particular purpose. It is provided "as **
|
||||
** is" without express or implied warranty of any kind. **
|
||||
** **
|
||||
** These notices must be retained in any copies of any part of this **
|
||||
** documentation and/or software. **
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
#include "pbmd5.h"
|
||||
|
||||
#if !defined(NOT_USE_PUNKBUSTER_SDK)
|
||||
|
||||
static unsigned char PADDING[64] = {
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
/* F, G and H are basic MD5 functions: selection, majority, parity */
|
||||
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define I(x, y, z) ((y) ^ ((x) | (~z)))
|
||||
|
||||
/* ROTATE_LEFT rotates x left n bits */
|
||||
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
|
||||
/* Rotation is separate from addition to prevent recomputation */
|
||||
|
||||
#define FF(a, b, c, d, x, s, ac) {(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
|
||||
#define GG(a, b, c, d, x, s, ac) {(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
|
||||
#define HH(a, b, c, d, x, s, ac) {(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
|
||||
#define II(a, b, c, d, x, s, ac) {(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
|
||||
|
||||
|
||||
/* Basic MD5 step. Transform buf based on in.
|
||||
*/
|
||||
static void Transform (UINT4 *buf, UINT4 *in)
|
||||
{
|
||||
UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
|
||||
|
||||
/* Round 1 */
|
||||
#define S11 7
|
||||
#define S12 12
|
||||
#define S13 17
|
||||
#define S14 22
|
||||
FF ( a, b, c, d, in[ 0], S11, (UINT4) 3614090360u); /* 1 */
|
||||
FF ( d, a, b, c, in[ 1], S12, (UINT4) 3905402710u); /* 2 */
|
||||
FF ( c, d, a, b, in[ 2], S13, (UINT4) 606105819u); /* 3 */
|
||||
FF ( b, c, d, a, in[ 3], S14, (UINT4) 3250441966u); /* 4 */
|
||||
FF ( a, b, c, d, in[ 4], S11, (UINT4) 4118548399u); /* 5 */
|
||||
FF ( d, a, b, c, in[ 5], S12, (UINT4) 1200080426u); /* 6 */
|
||||
FF ( c, d, a, b, in[ 6], S13, (UINT4) 2821735955u); /* 7 */
|
||||
FF ( b, c, d, a, in[ 7], S14, (UINT4) 4249261313u); /* 8 */
|
||||
FF ( a, b, c, d, in[ 8], S11, (UINT4) 1770035416u); /* 9 */
|
||||
FF ( d, a, b, c, in[ 9], S12, (UINT4) 2336552879u); /* 10 */
|
||||
FF ( c, d, a, b, in[10], S13, (UINT4) 4294925233u); /* 11 */
|
||||
FF ( b, c, d, a, in[11], S14, (UINT4) 2304563134u); /* 12 */
|
||||
FF ( a, b, c, d, in[12], S11, (UINT4) 1804603682u); /* 13 */
|
||||
FF ( d, a, b, c, in[13], S12, (UINT4) 4254626195u); /* 14 */
|
||||
FF ( c, d, a, b, in[14], S13, (UINT4) 2792965006u); /* 15 */
|
||||
FF ( b, c, d, a, in[15], S14, (UINT4) 1236535329u); /* 16 */
|
||||
|
||||
/* Round 2 */
|
||||
#define S21 5
|
||||
#define S22 9
|
||||
#define S23 14
|
||||
#define S24 20
|
||||
GG ( a, b, c, d, in[ 1], S21, (UINT4) 4129170786u); /* 17 */
|
||||
GG ( d, a, b, c, in[ 6], S22, (UINT4) 3225465664u); /* 18 */
|
||||
GG ( c, d, a, b, in[11], S23, (UINT4) 643717713u); /* 19 */
|
||||
GG ( b, c, d, a, in[ 0], S24, (UINT4) 3921069994u); /* 20 */
|
||||
GG ( a, b, c, d, in[ 5], S21, (UINT4) 3593408605u); /* 21 */
|
||||
GG ( d, a, b, c, in[10], S22, (UINT4) 38016083u); /* 22 */
|
||||
GG ( c, d, a, b, in[15], S23, (UINT4) 3634488961u); /* 23 */
|
||||
GG ( b, c, d, a, in[ 4], S24, (UINT4) 3889429448u); /* 24 */
|
||||
GG ( a, b, c, d, in[ 9], S21, (UINT4) 568446438u); /* 25 */
|
||||
GG ( d, a, b, c, in[14], S22, (UINT4) 3275163606u); /* 26 */
|
||||
GG ( c, d, a, b, in[ 3], S23, (UINT4) 4107603335u); /* 27 */
|
||||
GG ( b, c, d, a, in[ 8], S24, (UINT4) 1163531501u); /* 28 */
|
||||
GG ( a, b, c, d, in[13], S21, (UINT4) 2850285829u); /* 29 */
|
||||
GG ( d, a, b, c, in[ 2], S22, (UINT4) 4243563512u); /* 30 */
|
||||
GG ( c, d, a, b, in[ 7], S23, (UINT4) 1735328473u); /* 31 */
|
||||
GG ( b, c, d, a, in[12], S24, (UINT4) 2368359562u); /* 32 */
|
||||
|
||||
/* Round 3 */
|
||||
#define S31 4
|
||||
#define S32 11
|
||||
#define S33 16
|
||||
#define S34 23
|
||||
HH ( a, b, c, d, in[ 5], S31, (UINT4) 4294588738u); /* 33 */
|
||||
HH ( d, a, b, c, in[ 8], S32, (UINT4) 2272392833u); /* 34 */
|
||||
HH ( c, d, a, b, in[11], S33, (UINT4) 1839030562u); /* 35 */
|
||||
HH ( b, c, d, a, in[14], S34, (UINT4) 4259657740u); /* 36 */
|
||||
HH ( a, b, c, d, in[ 1], S31, (UINT4) 2763975236u); /* 37 */
|
||||
HH ( d, a, b, c, in[ 4], S32, (UINT4) 1272893353u); /* 38 */
|
||||
HH ( c, d, a, b, in[ 7], S33, (UINT4) 4139469664u); /* 39 */
|
||||
HH ( b, c, d, a, in[10], S34, (UINT4) 3200236656u); /* 40 */
|
||||
HH ( a, b, c, d, in[13], S31, (UINT4) 681279174u); /* 41 */
|
||||
HH ( d, a, b, c, in[ 0], S32, (UINT4) 3936430074u); /* 42 */
|
||||
HH ( c, d, a, b, in[ 3], S33, (UINT4) 3572445317u); /* 43 */
|
||||
HH ( b, c, d, a, in[ 6], S34, (UINT4) 76029189u); /* 44 */
|
||||
HH ( a, b, c, d, in[ 9], S31, (UINT4) 3654602809u); /* 45 */
|
||||
HH ( d, a, b, c, in[12], S32, (UINT4) 3873151461u); /* 46 */
|
||||
HH ( c, d, a, b, in[15], S33, (UINT4) 530742520u); /* 47 */
|
||||
HH ( b, c, d, a, in[ 2], S34, (UINT4) 3299628645u); /* 48 */
|
||||
|
||||
/* Round 4 */
|
||||
#define S41 6
|
||||
#define S42 10
|
||||
#define S43 15
|
||||
#define S44 21
|
||||
II ( a, b, c, d, in[ 0], S41, (UINT4) 4096336452u); /* 49 */
|
||||
II ( d, a, b, c, in[ 7], S42, (UINT4) 1126891415u); /* 50 */
|
||||
II ( c, d, a, b, in[14], S43, (UINT4) 2878612391u); /* 51 */
|
||||
II ( b, c, d, a, in[ 5], S44, (UINT4) 4237533241u); /* 52 */
|
||||
II ( a, b, c, d, in[12], S41, (UINT4) 1700485571u); /* 53 */
|
||||
II ( d, a, b, c, in[ 3], S42, (UINT4) 2399980690u); /* 54 */
|
||||
II ( c, d, a, b, in[10], S43, (UINT4) 4293915773u); /* 55 */
|
||||
II ( b, c, d, a, in[ 1], S44, (UINT4) 2240044497u); /* 56 */
|
||||
II ( a, b, c, d, in[ 8], S41, (UINT4) 1873313359u); /* 57 */
|
||||
II ( d, a, b, c, in[15], S42, (UINT4) 4264355552u); /* 58 */
|
||||
II ( c, d, a, b, in[ 6], S43, (UINT4) 2734768916u); /* 59 */
|
||||
II ( b, c, d, a, in[13], S44, (UINT4) 1309151649u); /* 60 */
|
||||
II ( a, b, c, d, in[ 4], S41, (UINT4) 4149444226u); /* 61 */
|
||||
II ( d, a, b, c, in[11], S42, (UINT4) 3174756917u); /* 62 */
|
||||
II ( c, d, a, b, in[ 2], S43, (UINT4) 718787259u); /* 63 */
|
||||
II ( b, c, d, a, in[ 9], S44, (UINT4) 3951481745u); /* 64 */
|
||||
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
}
|
||||
|
||||
void MD5Init (MD5_CTX *mdContext, unsigned int pseudoRandomNumber )
|
||||
{
|
||||
mdContext->i[0] = mdContext->i[1] = (UINT4)0;
|
||||
|
||||
/* Load magic initialization constants.
|
||||
*/
|
||||
mdContext->buf[0] = (UINT4)0x67452301 + pseudoRandomNumber * 11 ;
|
||||
mdContext->buf[1] = (UINT4)0xefcdab89 + pseudoRandomNumber * 71 ;
|
||||
mdContext->buf[2] = (UINT4)0x98badcfe + pseudoRandomNumber * 37 ;
|
||||
mdContext->buf[3] = (UINT4)0x10325476 + pseudoRandomNumber * 97 ;
|
||||
}
|
||||
|
||||
void MD5Update (MD5_CTX *mdContext, unsigned char *inBuf, unsigned int inLen)
|
||||
{
|
||||
UINT4 in[16];
|
||||
int mdi;
|
||||
unsigned int i, ii;
|
||||
|
||||
/* compute number of bytes mod 64 */
|
||||
mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
|
||||
|
||||
/* update number of bits */
|
||||
if ((mdContext->i[0] + ((UINT4)inLen << 3)) < mdContext->i[0])
|
||||
mdContext->i[1]++;
|
||||
mdContext->i[0] += ((UINT4)inLen << 3);
|
||||
mdContext->i[1] += ((UINT4)inLen >> 29);
|
||||
|
||||
while (inLen--) {
|
||||
/* add new character to buffer, increment mdi */
|
||||
mdContext->in[mdi++] = *inBuf++;
|
||||
|
||||
/* transform if necessary */
|
||||
if (mdi == 0x40) {
|
||||
for (i = 0, ii = 0; i < 16; i++, ii += 4)
|
||||
in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
|
||||
(((UINT4)mdContext->in[ii+2]) << 16) |
|
||||
(((UINT4)mdContext->in[ii+1]) << 8) |
|
||||
((UINT4)mdContext->in[ii]);
|
||||
Transform (mdContext->buf, in);
|
||||
mdi = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MD5Final (MD5_CTX *mdContext)
|
||||
{
|
||||
UINT4 in[16];
|
||||
int mdi;
|
||||
unsigned int i, ii;
|
||||
unsigned int padLen;
|
||||
|
||||
/* save number of bits */
|
||||
in[14] = mdContext->i[0];
|
||||
in[15] = mdContext->i[1];
|
||||
|
||||
/* compute number of bytes mod 64 */
|
||||
mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
|
||||
|
||||
/* pad out to 56 mod 64 */
|
||||
padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
|
||||
MD5Update (mdContext, PADDING, padLen);
|
||||
|
||||
/* append length in bits and transform */
|
||||
for (i = 0, ii = 0; i < 14; i++, ii += 4)
|
||||
in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
|
||||
(((UINT4)mdContext->in[ii+2]) << 16) |
|
||||
(((UINT4)mdContext->in[ii+1]) << 8) |
|
||||
((UINT4)mdContext->in[ii]);
|
||||
Transform (mdContext->buf, in);
|
||||
|
||||
/* store buffer in digest */
|
||||
for (i = 0, ii = 0; i < 4; i++, ii += 4) {
|
||||
mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xFF);
|
||||
mdContext->digest[ii+1] =
|
||||
(unsigned char)((mdContext->buf[i] >> 8) & 0xFF);
|
||||
mdContext->digest[ii+2] =
|
||||
(unsigned char)((mdContext->buf[i] >> 16) & 0xFF);
|
||||
mdContext->digest[ii+3] =
|
||||
(unsigned char)((mdContext->buf[i] >> 24) & 0xFF);
|
||||
}
|
||||
}
|
||||
#endif // NOT_USE_PUNKBUSTER_SDK
|
||||
64
PunkBuster/pbmd5.h
Normal file
64
PunkBuster/pbmd5.h
Normal file
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// md5.h
|
||||
//
|
||||
// style modified by Tony Ray, January 2001
|
||||
// added support for randomizing initialization constants in MD5Init()
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
** md5.h -- Header file for implementation of MD5 **
|
||||
** RSA Data Security, Inc. MD5 Message Digest Algorithm **
|
||||
** Created: 2/17/90 RLR **
|
||||
** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version **
|
||||
** Revised (for MD5): RLR 4/27/91 **
|
||||
** -- G modified to have y&~z instead of y&z **
|
||||
** -- FF, GG, HH modified to add in last register done **
|
||||
** -- Access pattern: round 2 works mod 5, round 3 works mod 3 **
|
||||
** -- distinct additive constant for each step **
|
||||
** -- round 4 added, working mod 7 **
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
|
||||
** **
|
||||
** License to copy and use this software is granted provided that **
|
||||
** it is identified as the "RSA Data Security, Inc. MD5 Message **
|
||||
** Digest Algorithm" in all material mentioning or referencing this **
|
||||
** software or this function. **
|
||||
** **
|
||||
** License is also granted to make and use derivative works **
|
||||
** provided that such works are identified as "derived from the RSA **
|
||||
** Data Security, Inc. MD5 Message Digest Algorithm" in all **
|
||||
** material mentioning or referencing the derived work. **
|
||||
** **
|
||||
** RSA Data Security, Inc. makes no representations concerning **
|
||||
** either the merchantability of this software or the suitability **
|
||||
** of this software for any particular purpose. It is provided "as **
|
||||
** is" without express or implied warranty of any kind. **
|
||||
** **
|
||||
** These notices must be retained in any copies of any part of this **
|
||||
** documentation and/or software. **
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
#include <platform.h>
|
||||
|
||||
#if !defined(NOT_USE_PUNKBUSTER_SDK)
|
||||
/* typedef a 32 bit type */
|
||||
typedef unsigned int UINT4;
|
||||
|
||||
/* Data structure for MD5 (Message Digest) computation */
|
||||
typedef struct {
|
||||
UINT4 i[2]; /* number of _bits_ handled mod 2^64 */
|
||||
UINT4 buf[4]; /* scratch buffer */
|
||||
unsigned char in[64]; /* input buffer */
|
||||
unsigned char digest[16]; /* actual digest after MD5Final call */
|
||||
} MD5_CTX;
|
||||
|
||||
void MD5Init (MD5_CTX *mdContext, unsigned int pseudoRandomNumber = 0 ) ;
|
||||
void MD5Update (MD5_CTX *mdContext, unsigned char *inBuf, unsigned int inLen) ;
|
||||
void MD5Final (MD5_CTX *mdContext) ;
|
||||
|
||||
#endif // NOT_USE_PUNKBUSTER_SDK
|
||||
517
PunkBuster/pbsdk.cpp
Normal file
517
PunkBuster/pbsdk.cpp
Normal file
@@ -0,0 +1,517 @@
|
||||
//
|
||||
// pbsdk.cpp
|
||||
//
|
||||
// PunkBuster / Game Integration SDK
|
||||
//
|
||||
// <20> Copyright 2003-2004 Even Balance, Inc. All Rights Reserved.
|
||||
//
|
||||
// This Software Development Kit (SDK) is proprietary and confidential. It may not be used,
|
||||
// transferred, displayed or otherwise distributed in any manner except by express written
|
||||
// consent of Even Balance, Inc.
|
||||
//
|
||||
// created MAR 27 2003 by T.Ray @ Even Balance
|
||||
// last modified MAR 05 2004 by T.Ray @ Even Balance
|
||||
//
|
||||
|
||||
|
||||
#include "../CryNetwork/StdAfx.h"
|
||||
|
||||
#if !defined(NOT_USE_PUNKBUSTER_SDK)
|
||||
#include "../CryNetwork/PunkBusterInterface.h"
|
||||
|
||||
|
||||
|
||||
#define DEFINE_PbSdk /* this define is used once in all game modules (usually where the main() function is defined) */
|
||||
#include "pbsdk.h"
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_getBasePath
|
||||
//
|
||||
extern "C" char *PBsdk_getBasePath ( char *path , int maxlen )
|
||||
{
|
||||
if ( *path == 0 ) { //only populate if empty
|
||||
getcwd ( path , maxlen ) ;
|
||||
}
|
||||
|
||||
return path ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
extern void PBgetHomePath ( char *path , int maxlen ) ;
|
||||
//
|
||||
// PBsdk_getHomePath
|
||||
//
|
||||
extern "C" char *PBsdk_getHomePath ( char *path , int maxlen )
|
||||
{
|
||||
if ( *path == 0 ) { //only populate if empty
|
||||
PBgetHomePath ( path , maxlen ) ;
|
||||
if ( *path == 0 ) getcwd ( path , maxlen ) ;
|
||||
}
|
||||
|
||||
return path ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_Out
|
||||
//
|
||||
void PBoutgame ( char *text , int hudAlso ) ;//defined in PunkBusterInterface.cpp
|
||||
extern void Com_Printf( const char *msg, ... ) ;
|
||||
void Com_Printf( const char *msg, ... ) { }
|
||||
//
|
||||
extern "C" void PBsdk_Out ( char *msg )
|
||||
{
|
||||
if ( pbsdk->pbinterface == NULL ) return ;
|
||||
|
||||
char *cp = msg ;
|
||||
int hudAlso = 1 ;
|
||||
if ( !strnicmp ( msg , "[skipnotify]" , 12 ) ) {
|
||||
hudAlso = 0 ;
|
||||
cp += 12 ;
|
||||
}
|
||||
PBoutgame ( msg , hudAlso ) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_SendUdpPacket
|
||||
//
|
||||
extern void Sys_PBSendUdpPacket ( char *addr , unsigned short port , int datalen , char *data , int isFromClient ) ;
|
||||
//
|
||||
extern "C" void PBsdk_SendUdpPacket ( char *addr , unsigned short port , int datalen , char *data , int isFromClient )
|
||||
{
|
||||
Sys_PBSendUdpPacket ( addr , port , datalen , data , isFromClient ) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
extern void PBsendPktToServer ( int datalen , char *data ) ;
|
||||
extern int PBisLocalServer ( void ) ;
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_SendClPacket
|
||||
//
|
||||
extern "C" void PBsdk_SendClPacket ( int datalen , char *data )
|
||||
{
|
||||
if ( pbsdk == NULL ) return ;
|
||||
if ( PBisLocalServer () ) {
|
||||
int i ;
|
||||
for ( i = 0 ; i < PB_MAX_CLIENTS ; i++ ) if ( !stricmp ( "localhost" , pbsdk->pbsv.m_client[i].pbc.ip ) ) break ;
|
||||
if ( i < PB_MAX_CLIENTS ) PbSvAddEvent ( PB_EV_PACKET , i , datalen , data ) ;
|
||||
} else {
|
||||
PBsendPktToServer ( datalen , data ) ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
extern void PBsendPktToClient ( int datalen , char *data , char *addr ) ;
|
||||
/*SDK-sendsvpacket
|
||||
*/
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_SendSvPacket
|
||||
//
|
||||
extern "C" void PBsdk_SendSvPacket ( int datalen , char *data , int index )
|
||||
{
|
||||
if ( pbsdk == NULL ) return ;
|
||||
char *addr = pbsdk->pbsv.m_client[index].pbc.ip ;
|
||||
if ( *addr == 0 ) return ;
|
||||
if ( !stricmp ( addr , "localhost" ) ) {
|
||||
PbClAddEvent ( PB_EV_PACKET , datalen , data ) ;
|
||||
} else {
|
||||
PBsendPktToClient ( datalen , data , addr ) ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_CvarSet
|
||||
//
|
||||
extern void PBcvar_Set ( const char *cvar , const char *value ) ; //sample forward declaration
|
||||
//
|
||||
extern "C" void PBsdk_CvarSet ( const char *varName , const char *value )
|
||||
{
|
||||
PBcvar_Set ( varName , value ) ; //sample function call
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_SetClPunkBuster
|
||||
//
|
||||
extern "C" void PBsdk_SetClPunkBuster ( char *value )
|
||||
{
|
||||
PBsdk_CvarSet ( "cl_punkbuster" , value ) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_SetSvPunkBuster
|
||||
//
|
||||
//
|
||||
extern "C" void PBsdk_SetSvPunkBuster ( char *value )
|
||||
{
|
||||
PBsdk_CvarSet ( "sv_punkbuster" , value ) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_ExecCmd
|
||||
//
|
||||
extern void PBcmd_execString ( const char *text ) ; //sample forward declaration
|
||||
//
|
||||
extern "C" void PBsdk_ExecCmd ( const char *cmd )
|
||||
{
|
||||
PBcmd_execString ( cmd ) ; //sample function call
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_CvarValidate
|
||||
//
|
||||
extern char *PbCvarValidate ( char *buf ) ; //sample forward declaration
|
||||
char *PbCvarValidate ( char *buf ){*buf=0; return buf;} //empty function - remove
|
||||
//
|
||||
extern "C" char *PBsdk_CvarValidate ( char *buf )
|
||||
{
|
||||
return PbCvarValidate ( buf ) ; //sample function call
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_CvarWalk
|
||||
//
|
||||
extern int PBcvarWalk ( char **name , char **string , int *flags , char **resetString ) ; //sample forward declaration
|
||||
//
|
||||
extern "C" int PBsdk_CvarWalk ( char **name , char **string , int *flags , char **resetString )
|
||||
{
|
||||
return PBcvarWalk ( name , string , flags , resetString ) ; //sample function call
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_GetKeyName
|
||||
//
|
||||
extern int PBbindStuff ( int type , const char **data ) ;
|
||||
char *Key_KeynumToString( int keynum ) {return "";}
|
||||
//
|
||||
extern "C" char *PBsdk_GetKeyName ( int keynum )
|
||||
{
|
||||
static const char *data ;
|
||||
char buf[50] ;
|
||||
itoa ( keynum , buf , 10 ) ;
|
||||
data = buf ;
|
||||
PBbindStuff ( 2 , &data ) ;
|
||||
return (char *) data ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_GetKeyBinding
|
||||
//
|
||||
extern "C" char *PBsdk_GetKeyBinding ( int keynum )
|
||||
{
|
||||
static const char *data ;
|
||||
char buf[50] ;
|
||||
itoa ( keynum , buf , 10 ) ;
|
||||
data = buf ;
|
||||
PBbindStuff ( 3 , &data ) ;
|
||||
return (char *) data ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_GetMaxKeys
|
||||
//
|
||||
int PbMaxKeys ( void ) {return 0;}
|
||||
//
|
||||
extern "C" int PBsdk_GetMaxKeys ( void )
|
||||
{
|
||||
return PBbindStuff ( 1 , NULL ) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_GetServerAddr
|
||||
//
|
||||
char *PBserverIp ( int bClient = false ) ;
|
||||
extern "C" char *PBsdk_GetServerAddr ( void )
|
||||
{
|
||||
return PBserverIp() ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_GetKeyValue
|
||||
//
|
||||
const char *PBkeyValue ( char *notused , char *key ) ;
|
||||
extern "C" char *PBsdk_GetKeyValue ( char *s , char *k )
|
||||
{
|
||||
return (char *) PBkeyValue ( s , k ) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_GetServerInfo
|
||||
//
|
||||
extern char *PB_Q_Serverinfo ( void ) ;
|
||||
char *PB_Q_Serverinfo ( void ){ return "" ;}
|
||||
//
|
||||
extern "C" char *PBsdk_GetServerInfo ( void )
|
||||
{
|
||||
return PB_Q_Serverinfo() ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_GetCvarValue
|
||||
//
|
||||
extern char *PBcvar_VariableString( const char *var_name ) ;
|
||||
extern char *PBgameVer ( void ) ;
|
||||
extern char *PBserverHostname ( void ) ;
|
||||
//
|
||||
extern "C" char *PBsdk_GetCvarValue ( char *var_name )
|
||||
{
|
||||
//special cases
|
||||
if ( !stricmp ( var_name , "version" ) ) return ( strcpy ( var_name , PBgameVer() ) ) ;
|
||||
if ( !stricmp ( var_name , "name" ) ) {
|
||||
char *cp = PBcvar_VariableString ( "p_name" ) ;
|
||||
if ( *cp == 0 ) cp = "Jack Carver" ;
|
||||
return cp ;
|
||||
}
|
||||
if ( !stricmp ( var_name , "sv_hostname" ) ) {
|
||||
strcpy ( var_name , "sv_name" ) ;
|
||||
char *cp = PBcvar_VariableString ( var_name ) ;
|
||||
if ( *cp == 0 ) cp = PBserverHostname() ;
|
||||
return cp ;
|
||||
}
|
||||
if ( !stricmp ( var_name , "server" ) ) return PBserverIp ( true ) ;
|
||||
|
||||
//redirects
|
||||
if ( !stricmp ( var_name , "mapname" ) ) strcpy ( var_name , "g_levelName" ) ;
|
||||
|
||||
return PBcvar_VariableString ( var_name ) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_GlQuery
|
||||
//
|
||||
extern char *PBqueryGL ( int type ) ;
|
||||
extern "C" char *PBsdk_GlQuery ( int queryType )
|
||||
{
|
||||
return PBqueryGL ( queryType ) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_DropClient
|
||||
//
|
||||
extern void PBdropClient ( int clientIndex , char *reason ) ;
|
||||
//
|
||||
extern "C" void PBsdk_DropClient ( int clientIndex , char *reason )
|
||||
{
|
||||
PBdropClient ( clientIndex , reason ) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
extern int PBgetClientInfo ( stPb_Sv_Client *c ) ;
|
||||
//
|
||||
// PBsdk_GetClientInfo
|
||||
//
|
||||
extern "C" int PBsdk_GetClientInfo ( int svsIndex , stPb_Sv_Client *c )
|
||||
{
|
||||
memset ( c , 0 , sizeof ( *c ) ) ; //clear structure
|
||||
if ( svsIndex < 0 || svsIndex >= PB_MAX_CLIENTS ) return 0 ; //return on invalid index
|
||||
if ( *pbsdk->pbsv.m_client[svsIndex].pbc.ip ) { //player in this slot?
|
||||
strcpy ( c->ip , pbsdk->pbsv.m_client[svsIndex].pbc.ip ) ; //populate ip/guid with prior values
|
||||
strcpy ( c->guid , pbsdk->pbsv.m_client[svsIndex].pbc.guid ) ;
|
||||
int gci = PBgetClientInfo ( c ) ; //populate name field
|
||||
if ( gci ) {
|
||||
strcpy ( pbsdk->pbsv.m_client[svsIndex].pbc.name , c->name ) ;//name can change so we update our internal array structure each frame
|
||||
strcpy ( pbsdk->pbsv.m_client[svsIndex].pbc.guid , c->guid ) ;//guid is persistent and stored in pbc.guid
|
||||
} else *c->ip = 0 ; //player not set up yet (i.e. GetSlotInfo returned false)
|
||||
}
|
||||
return 1 ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_GetClientStats
|
||||
//
|
||||
extern int PBgetStats ( int svsIndex , char *Data ) ;
|
||||
//
|
||||
extern "C" int PBsdk_GetClientStats ( int index , char *data )
|
||||
{
|
||||
if ( index < 0 || index >= PB_MAX_CLIENTS ) return 0 ; //return on invalid index
|
||||
if ( *pbsdk->pbsv.m_client[index].pbc.ip == 0 ) return 0 ; //no client at this index
|
||||
return PBgetStats ( index , data ) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//
|
||||
// PbSvAddClient
|
||||
//
|
||||
//NOTE: This function adds the player to PB's internal array used to track reliable slot numbers
|
||||
int PbSvAddClient ( char *addr , char *name , char *guid )
|
||||
{
|
||||
if ( pbsdk == NULL || *addr == 0 ) return 0 ;
|
||||
|
||||
int i , j = -1 ;
|
||||
for ( i = 0 ; i < PB_MAX_CLIENTS ; i++ ) {
|
||||
if ( !stricmp ( addr , pbsdk->pbsv.m_client[i].pbc.ip ) ) {
|
||||
char buf[1025] ;
|
||||
sprintf ( buf , "ERROR: Game is reporting duplicate player IP:Port %s as new connection" , addr ) ;
|
||||
PBoutgame ( buf , 1 ) ;
|
||||
return 0 ;
|
||||
}
|
||||
if ( *pbsdk->pbsv.m_client[i].pbc.ip == 0 && j < 0 ) j = i ;
|
||||
}
|
||||
if ( j < 0 ) return 0 ;//all slots full
|
||||
|
||||
strncpy ( pbsdk->pbsv.m_client[j].pbc.ip , addr , PB_NAMELEN ) ;
|
||||
pbsdk->pbsv.m_client[j].pbc.ip[PB_NAMELEN] = 0 ;
|
||||
strncpy ( pbsdk->pbsv.m_client[j].pbc.name , name , PB_NAMELEN ) ;
|
||||
pbsdk->pbsv.m_client[j].pbc.name[PB_NAMELEN] = 0 ;
|
||||
strncpy ( pbsdk->pbsv.m_client[j].pbc.guid , guid , PB_GUIDLEN ) ;
|
||||
pbsdk->pbsv.m_client[j].pbc.guid[PB_GUIDLEN] = 0 ;
|
||||
return j + 1 ;//return PB slot # (1 to max)
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// PbSvRemoveClient
|
||||
//
|
||||
//NOTE: This function removes the player from PB's internal array - see PBsdk_DropClient below for kicks
|
||||
int PbSvRemoveClient ( char *addr )
|
||||
{
|
||||
if ( pbsdk == NULL ) return 0 ;
|
||||
int i ;
|
||||
for ( i = 0 ; i < PB_MAX_CLIENTS ; i++ ) {
|
||||
if ( strcmp ( pbsdk->pbsv.m_client[i].pbc.ip , addr ) ) continue ;
|
||||
memset ( &pbsdk->pbsv.m_client[i].pbc , 0 , sizeof ( pbsdk->pbsv.m_client[i].pbc ) ) ;
|
||||
return i + 1 ;//return PB slot # (1 to max)
|
||||
}
|
||||
return 0 ;//return 0 means client pointer not found in array (should never happen)
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
//
|
||||
// PBsdk_SetPointers
|
||||
//
|
||||
extern "C" void PBsdk_SetPointers ( void *pbinterface )
|
||||
{
|
||||
static int tries = 0 ;
|
||||
|
||||
if ( pbsdk != NULL ) return ; //already accomplished
|
||||
|
||||
if ( tries >= 3 ) return ; //after 3 tries, give up
|
||||
|
||||
++tries ;
|
||||
|
||||
if ( pbinterface == NULL ) return ;
|
||||
|
||||
pbsdk = &PbSdkInstance ;
|
||||
// PBsdk_getPbSdkPointer ( "module_filename_goes_here" , 0 ) ;/*note use non-zero for Flag if desired*/
|
||||
|
||||
if ( pbsdk == NULL ) return ; //failed to get pointer to struct instance
|
||||
|
||||
pbsdk->pbinterface = pbinterface ;
|
||||
|
||||
//uncomment lines from the following section that are to be defined in "this" game module
|
||||
pbsdk->m_CvarSet = PBsdk_CvarSet ;
|
||||
// pbsdk->m_CvarValidate = PBsdk_CvarValidate ;
|
||||
pbsdk->m_CvarWalk = PBsdk_CvarWalk ;
|
||||
pbsdk->m_DropClient = PBsdk_DropClient ;
|
||||
pbsdk->m_ExecCmd = PBsdk_ExecCmd ;
|
||||
pbsdk->m_getBasePath = PBsdk_getBasePath ;
|
||||
pbsdk->m_GetClientInfo = PBsdk_GetClientInfo ;
|
||||
pbsdk->m_GetClientStats = PBsdk_GetClientStats ;
|
||||
pbsdk->m_GetCvarValue = PBsdk_GetCvarValue ;
|
||||
pbsdk->m_getHomePath = PBsdk_getHomePath ;
|
||||
pbsdk->m_GetKeyBinding = PBsdk_GetKeyBinding ;
|
||||
pbsdk->m_GetKeyName = PBsdk_GetKeyName ;
|
||||
pbsdk->m_GetKeyValue = PBsdk_GetKeyValue ;
|
||||
// pbsdk->m_GetMaxClients = PBsdk_GetMaxClients ;
|
||||
pbsdk->m_GetMaxKeys = PBsdk_GetMaxKeys ;
|
||||
pbsdk->m_GetServerAddr = PBsdk_GetServerAddr ;
|
||||
// pbsdk->m_GetServerInfo = PBsdk_GetServerInfo ;
|
||||
pbsdk->m_GlQuery = PBsdk_GlQuery ;
|
||||
pbsdk->m_Out = PBsdk_Out ;
|
||||
pbsdk->m_SendClPacket = PBsdk_SendClPacket ;
|
||||
pbsdk->m_SendSvPacket = PBsdk_SendSvPacket ;
|
||||
pbsdk->m_SendUdpPacket = PBsdk_SendUdpPacket ;
|
||||
pbsdk->m_SetClPunkBuster = PBsdk_SetClPunkBuster ;
|
||||
pbsdk->m_SetSvPunkBuster = PBsdk_SetSvPunkBuster ;
|
||||
}
|
||||
#endif
|
||||
#endif // NOT_USE_PUNKBUSTER_SDK
|
||||
271
PunkBuster/pbsdk.h
Normal file
271
PunkBuster/pbsdk.h
Normal file
@@ -0,0 +1,271 @@
|
||||
// Copyright (C) 2001-2003 Even Balance, Inc.
|
||||
//
|
||||
//
|
||||
// pbsdk.h
|
||||
//
|
||||
// EVEN BALANCE - T.RAY
|
||||
//
|
||||
|
||||
|
||||
#define _cplusplus
|
||||
#include "pbcl.h"
|
||||
#include "pbsv.h"
|
||||
|
||||
#if !defined(NOT_USE_PUNKBUSTER_SDK)
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
|
||||
int PbSvAddClient ( char *addr , char *name , char *guid ) ;
|
||||
int PbSvRemoveClient ( char *addr ) ;
|
||||
|
||||
|
||||
//
|
||||
// PB Integration Points - Typedefs
|
||||
//
|
||||
typedef char *(*PBtd_getBasePath) ( char *path , int maxlen ) ;
|
||||
typedef char *(*PBtd_getHomePath) ( char *path , int maxlen ) ;
|
||||
typedef void (*PBtd_CvarSet) ( const char *varName , const char *value ) ;
|
||||
typedef void (*PBtd_SetClPunkBuster) ( char *value ) ;
|
||||
typedef void (*PBtd_ExecCmd) ( const char *cmd ) ;
|
||||
typedef void *(*PBtd_DllHandle) ( const char *modname ) ;
|
||||
typedef char *(*PBtd_CvarValidate) ( char *buf ) ;
|
||||
typedef int (*PBtd_CvarWalk) ( char **name , char **string , int *flags , char **resetString ) ;
|
||||
typedef char *(*PBtd_GetKeyName) ( int keynum ) ;
|
||||
typedef char *(*PBtd_GetKeyBinding) ( int keynum ) ;
|
||||
typedef int (*PBtd_GetMaxKeys) ( void ) ;
|
||||
typedef char *(*PBtd_GetServerAddr) ( void ) ;
|
||||
typedef char *(*PBtd_GetKeyValue) ( char *s , char *k ) ;
|
||||
typedef char *(*PBtd_GetServerInfo) ( void ) ;
|
||||
typedef char *(*PBtd_GetCvarValue) ( char *var_name ) ;
|
||||
typedef void (*PBtd_Out) ( char *msg ) ;
|
||||
typedef void (*PBtd_SendClPacket) ( int datalen , char *data ) ;
|
||||
typedef void (*PBtd_SendUdpPacket) ( char *addr , unsigned short port , int datalen , char *data , int isFromClient ) ;
|
||||
typedef char *(*PBtd_GlQuery) ( int queryType ) ;
|
||||
typedef void (*PBtd_SetSvPunkBuster) ( char *val ) ;
|
||||
typedef void (*PBtd_DropClient) ( int clientIndex , char *reason ) ;
|
||||
typedef int (*PBtd_GetMaxClients) ( void ) ;
|
||||
typedef int (*PBtd_GetClientInfo) ( int index , stPb_Sv_Client *c ) ;
|
||||
typedef int (*PBtd_GetClientStats) ( int index , char *data ) ;
|
||||
typedef void (*PBtd_SendSvPacket) ( int datalen , char *data , int index ) ;
|
||||
|
||||
|
||||
|
||||
#define CONST_PBSDKID 0xFF80FF1E
|
||||
#define PBNULLFUNC "NULL Function Pointer"
|
||||
|
||||
|
||||
|
||||
struct stPbSdk {
|
||||
unsigned int PBSDKID ;
|
||||
stPbCl pbcl ;
|
||||
stPbSv pbsv ;
|
||||
unsigned int flags ;
|
||||
void *exeInstance ;
|
||||
char *ConsoleCaptureBuf ;
|
||||
int ConsoleCaptureBufLen ;
|
||||
void *pbinterface ;
|
||||
|
||||
PBtd_getBasePath m_getBasePath ;
|
||||
PBtd_getHomePath m_getHomePath ;
|
||||
PBtd_CvarSet m_CvarSet ;
|
||||
PBtd_SetClPunkBuster m_SetClPunkBuster ;
|
||||
PBtd_ExecCmd m_ExecCmd ;
|
||||
PBtd_DllHandle m_DllHandle ;
|
||||
PBtd_CvarValidate m_CvarValidate ;
|
||||
PBtd_CvarWalk m_CvarWalk ;
|
||||
PBtd_GetKeyName m_GetKeyName ;
|
||||
PBtd_GetKeyBinding m_GetKeyBinding ;
|
||||
PBtd_GetMaxKeys m_GetMaxKeys ;
|
||||
PBtd_GetServerAddr m_GetServerAddr ;
|
||||
PBtd_GetKeyValue m_GetKeyValue ;
|
||||
PBtd_GetServerInfo m_GetServerInfo ;
|
||||
PBtd_GetCvarValue m_GetCvarValue ;
|
||||
PBtd_Out m_Out ;
|
||||
PBtd_SendClPacket m_SendClPacket ;
|
||||
PBtd_SendUdpPacket m_SendUdpPacket ;
|
||||
PBtd_GlQuery m_GlQuery ;
|
||||
PBtd_SetSvPunkBuster m_SetSvPunkBuster ;
|
||||
PBtd_DropClient m_DropClient ;
|
||||
PBtd_GetMaxClients m_GetMaxClients ;
|
||||
PBtd_GetClientInfo m_GetClientInfo ;
|
||||
PBtd_GetClientStats m_GetClientStats ;
|
||||
PBtd_SendSvPacket m_SendSvPacket ;
|
||||
|
||||
char *pb_getBasePath ( char *path , int maxlen ) {
|
||||
if ( m_getBasePath == NULL ) {
|
||||
*path = 0 ;
|
||||
return PBNULLFUNC ;
|
||||
}
|
||||
return m_getBasePath ( path , maxlen ) ;
|
||||
}
|
||||
char *pb_getHomePath ( char *path , int maxlen ) {
|
||||
if ( m_getHomePath == NULL ) {
|
||||
*path = 0 ;
|
||||
return PBNULLFUNC ;
|
||||
}
|
||||
return m_getHomePath ( path , maxlen ) ;
|
||||
}
|
||||
void pb_CvarSet ( const char *varName , const char *value ) {
|
||||
if ( m_CvarSet == NULL ) return ;
|
||||
m_CvarSet ( varName , value ) ;
|
||||
}
|
||||
void pb_SetClPunkBuster ( char *value ) {
|
||||
if ( m_SetClPunkBuster == NULL ) return ;
|
||||
m_SetClPunkBuster ( value ) ;
|
||||
}
|
||||
void pb_ExecCmd ( const char *cmd ) {
|
||||
if ( m_ExecCmd == NULL ) return ;
|
||||
m_ExecCmd ( cmd ) ;
|
||||
}
|
||||
void *pb_DllHandle ( const char *modname ) {
|
||||
if ( m_DllHandle == NULL ) return NULL ;
|
||||
return m_DllHandle ( modname ) ;
|
||||
}
|
||||
char *pb_CvarValidate ( char *buf ) {
|
||||
if ( m_CvarValidate == NULL ) {
|
||||
*buf = 0 ;
|
||||
return buf ;
|
||||
}
|
||||
return m_CvarValidate ( buf ) ;
|
||||
}
|
||||
int pb_CvarWalk ( char **name , char **string , int *flags , char **resetString ) {
|
||||
if ( m_CvarWalk == NULL ) return 0 ;
|
||||
return m_CvarWalk ( name , string , flags , resetString ) ;
|
||||
}
|
||||
char *pb_GetKeyName ( int keynum ) {
|
||||
if ( m_GetKeyName == NULL ) return "" ;
|
||||
return m_GetKeyName ( keynum ) ;
|
||||
}
|
||||
char *pb_GetKeyBinding ( int keynum ) {
|
||||
if ( m_GetKeyBinding == NULL ) return "" ;
|
||||
return m_GetKeyBinding ( keynum ) ;
|
||||
}
|
||||
int pb_GetMaxKeys ( void ) {
|
||||
if ( m_GetMaxKeys == NULL ) return 0 ;
|
||||
return m_GetMaxKeys() ;
|
||||
}
|
||||
char *pb_GetServerAddr ( void ) {
|
||||
if ( m_GetServerAddr == NULL ) return "" ;
|
||||
return m_GetServerAddr() ;
|
||||
}
|
||||
char *pb_GetKeyValue ( char *s , char *k ) {
|
||||
if ( m_GetKeyValue == NULL ) return "" ;
|
||||
return m_GetKeyValue ( s , k ) ;
|
||||
}
|
||||
char *pb_GetServerInfo ( void ) {
|
||||
if ( m_GetServerInfo == NULL ) return "" ;
|
||||
return m_GetServerInfo() ;
|
||||
}
|
||||
char *pb_GetCvarValue ( char *var_name ) {
|
||||
if ( m_GetCvarValue == NULL ) return "" ;
|
||||
return m_GetCvarValue ( var_name ) ;
|
||||
}
|
||||
void pb_Outf ( char *msg , ... ) {
|
||||
if ( m_Out == NULL ) return ;
|
||||
|
||||
char buf[4150] ;
|
||||
va_list va ;
|
||||
va_start ( va , msg ) ;
|
||||
if ( strlen ( msg ) > 2048 ) {
|
||||
strncpy ( buf , msg , 4096 ) ;
|
||||
buf[4096] = 0 ;
|
||||
} else _vsnprintf ( buf , 4096 , msg , va ) ;
|
||||
m_Out ( buf ) ;
|
||||
}
|
||||
void pb_SendClPacket ( int datalen , char *data ) {
|
||||
if ( m_SendClPacket == NULL ) return ;
|
||||
m_SendClPacket ( datalen , data ) ;
|
||||
}
|
||||
void pb_SendUdpPacket ( char *addr , unsigned short port , int datalen , char *data , int isFromClient ) {
|
||||
if ( m_SendUdpPacket == NULL ) return ;
|
||||
m_SendUdpPacket ( addr , port , datalen , data , isFromClient ) ;
|
||||
}
|
||||
char *pb_GlQuery ( int queryType ) {
|
||||
if ( m_GlQuery == NULL ) return NULL ;
|
||||
return m_GlQuery ( queryType ) ;
|
||||
}
|
||||
void pb_SetSvPunkBuster ( char *val ) {
|
||||
if ( m_SetSvPunkBuster == NULL ) return ;
|
||||
m_SetSvPunkBuster ( val ) ;
|
||||
}
|
||||
void pb_DropClient ( int clientIndex , char *reason ) {
|
||||
if ( m_DropClient == NULL ) return ;
|
||||
m_DropClient ( clientIndex , reason ) ;
|
||||
}
|
||||
int pb_GetMaxClients ( void ) {
|
||||
if ( m_GetMaxClients == NULL ) return 0 ;
|
||||
return m_GetMaxClients() ;
|
||||
}
|
||||
int pb_GetClientInfo ( int index , stPb_Sv_Client *c ) {
|
||||
if ( m_GetClientInfo == NULL ) return 0 ;
|
||||
return m_GetClientInfo ( index , c ) ;
|
||||
}
|
||||
int pb_GetClientStats ( int index , char *data ) {
|
||||
if ( m_GetClientStats == NULL ) return 0 ;
|
||||
return m_GetClientStats ( index , data ) ;
|
||||
}
|
||||
void pb_SendSvPacket ( int datalen , char *data , int index ) {
|
||||
if ( m_SendSvPacket == NULL ) return ;
|
||||
m_SendSvPacket ( datalen , data , index ) ;
|
||||
}
|
||||
|
||||
//constructor
|
||||
stPbSdk() {
|
||||
memset ( this , 0 , sizeof ( stPbSdk ) ) ;
|
||||
PBSDKID = CONST_PBSDKID ;
|
||||
pbsv.init() ;
|
||||
pbcl.init() ;
|
||||
pbcl.m_GlQuery = m_GlQuery ;
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
extern stPbSdk *pbsdk ;
|
||||
|
||||
|
||||
|
||||
//One game source module should "#define DEFINE_PbSdk" before including this file so that only one
|
||||
// instance of the following struct and function are each defined in the game project.
|
||||
//Usually, the source module containing the main() or WinMain() function will serve in that role.
|
||||
#ifdef DEFINE_PbSdk
|
||||
|
||||
//single instance of stPbSdk
|
||||
stPbSdk PbSdkInstance ;
|
||||
stPbSdk *pbsdk = NULL ;//&PbSdkInstance ;
|
||||
#define PbSdk_DEFINED
|
||||
|
||||
#if(0)//todotr
|
||||
/*SDK-pbexport
|
||||
|
||||
This function is provided for games that need PB integration code inside multiple game components (i.e. EXE and/or DLLs)
|
||||
|
||||
It should be removed if not needed.
|
||||
|
||||
*/
|
||||
//
|
||||
// pb_Export
|
||||
//
|
||||
extern "C"
|
||||
#ifdef __PBWIN32__
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
char *pb_Export ( void )
|
||||
{
|
||||
return (char *) pbsdk ;
|
||||
}
|
||||
#endif //#ifdef DEFINE_PbSdk
|
||||
#endif
|
||||
|
||||
|
||||
//source modules other than the 'main' one (see above) will have one instance of a pointer to the stPbSdk struct
|
||||
//this pointer will be populated by a call to PBsdk_getPbSdkPointer() (see below)
|
||||
#ifndef PbSdk_DEFINED
|
||||
#define PbSdk_DEFINED
|
||||
stPbSdk *pbsdk = NULL ;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif //#ifdef __WITH_PB__
|
||||
#endif // NOT_USE_PUNKBUSTER_SDK
|
||||
225
PunkBuster/pbsv.cpp
Normal file
225
PunkBuster/pbsv.cpp
Normal file
@@ -0,0 +1,225 @@
|
||||
// Copyright (C) 2001-2003 Even Balance, Inc.
|
||||
//
|
||||
//
|
||||
// pbsv.cpp
|
||||
//
|
||||
// EVEN BALANCE - T.RAY
|
||||
//
|
||||
|
||||
|
||||
#define _cplusplus
|
||||
|
||||
|
||||
|
||||
#define PbSdk_DEFINED
|
||||
#include "pbsdk.h"
|
||||
|
||||
#if !defined(NOT_USE_PUNKBUSTER_SDK)
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Functions and wrappers
|
||||
// these are declared in pbcommon.h
|
||||
|
||||
extern "C" {
|
||||
|
||||
void __cdecl PbSvAddEvent ( int event , int clientIndex , int datalen , char *data )
|
||||
{
|
||||
if ( pbsdk == NULL ) return ;
|
||||
pbsdk->pbsv.AddPbEvent ( event , clientIndex , datalen , data , 0 ) ;
|
||||
}
|
||||
|
||||
void __cdecl PbServerInitialize ( void )
|
||||
{
|
||||
if ( pbsdk == NULL ) return ;
|
||||
pbsdk->pbsv.initialize() ;
|
||||
|
||||
pbsdk->pb_getBasePath ( pbsdk->pbsv.m_basepath , PB_Q_MAXRESULTLEN ) ;
|
||||
pbsdk->pb_getHomePath ( pbsdk->pbsv.m_homepath , PB_Q_MAXRESULTLEN ) ;
|
||||
|
||||
PbSvAddEvent ( PB_EV_CONFIG , -1 , 0 , "" ) ;
|
||||
if ( pbsdk->pbsv.m_AddPbEvent == NULL ) pbsdk->pb_SetSvPunkBuster ( "0" ) ;
|
||||
}
|
||||
|
||||
void __cdecl PbServerProcessEvents ( void )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return ;
|
||||
pbsdk->pbsv.ProcessPbEvents() ;
|
||||
}
|
||||
|
||||
void __cdecl PbServerForceProcess ( void )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return ;
|
||||
pbsdk->pbsv.ProcessPbEvents ( -1 ) ;
|
||||
}
|
||||
|
||||
void __cdecl PbServerCompleteCommand ( char *buf , int buflen )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return ;
|
||||
pbsdk->pbsv.AddPbEvent ( PB_EV_CMDCOMPL , -1 , buflen , buf ) ;
|
||||
}
|
||||
|
||||
void __cdecl PbPassConnectString ( char *fromAddr , char *connectString )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return ;
|
||||
if ( pbsdk->pbsv.m_PassConnectString == NULL ) return ;//means PB not installed/enabled
|
||||
pbsdk->pbsv.m_PassConnectString ( &pbsdk->pbsv , fromAddr , connectString ) ;
|
||||
}
|
||||
|
||||
char * __cdecl PbAuthClient ( char *fromAddr , int cl_pb , char *cl_guid )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return NULL ;
|
||||
if ( pbsdk->pbsv.m_AuthClient == NULL ) return NULL ;//means PB not installed/enabled
|
||||
return pbsdk->pbsv.m_AuthClient ( &pbsdk->pbsv , fromAddr , cl_pb , cl_guid ) ;
|
||||
}
|
||||
|
||||
int __cdecl isPbSvEnabled ( void )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return 0 ;
|
||||
return (int) pbsdk->pbsv.AddPbEvent ( PB_EV_ISENABLED , -1 , 0 , NULL ) ;
|
||||
}
|
||||
|
||||
void __cdecl EnablePbSv ( void )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return ;
|
||||
pbsdk->pbsv.AddPbEvent ( PB_EV_ENABLE , -1 , 0 , NULL ) ;
|
||||
}
|
||||
|
||||
void __cdecl DisablePbSv ( void )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return ;
|
||||
pbsdk->pbsv.AddPbEvent ( PB_EV_DISABLE , -1 , 0 , NULL ) ;
|
||||
}
|
||||
|
||||
} //extern "C"
|
||||
|
||||
extern void __cdecl PbClientTrapConsole ( char *msg , int msglen ) ;//in pbcl.cpp
|
||||
void __cdecl PbCaptureConsoleOutput ( char *msg , int msglen )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return ;
|
||||
|
||||
if ( pbsdk->pbcl.m_ReloadClient == 0 ) PbClientTrapConsole ( msg , msglen ) ;
|
||||
|
||||
if ( pbsdk->pbsv.m_ReloadServer == 0 ) if ( pbsdk->pbsv.m_TrapConsole != NULL ) pbsdk->pbsv.m_TrapConsole ( &pbsdk->pbsv , msg , msglen ) ;
|
||||
|
||||
if ( *msg == '/' || *msg == '\\' ) ++msg , --msglen ;
|
||||
if ( !strnicmp ( msg , "pb_" , 3 ) ) {
|
||||
if ( !strnicmp ( msg + 3 , "sv_" , 3 ) ) {
|
||||
if ( pbsdk->pbsv.m_TrapConsole != NULL ) PbSvAddEvent ( PB_EV_CMD , -1 , msglen , msg ) ;
|
||||
} else {
|
||||
if ( pbsdk->pbcl.m_ReloadClient == 0 ) PbClAddEvent ( PB_EV_CMD , msglen , msg ) ;
|
||||
}
|
||||
}
|
||||
|
||||
if ( pbsdk->ConsoleCaptureBuf == NULL ) return ;
|
||||
int sl = strlen ( pbsdk->ConsoleCaptureBuf ) ;
|
||||
if ( sl + (int) strlen ( msg ) + 1 >= pbsdk->ConsoleCaptureBufLen ) return ;
|
||||
strcpy ( pbsdk->ConsoleCaptureBuf + sl , msg ) ;
|
||||
strcat ( pbsdk->ConsoleCaptureBuf , "\n" ) ;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// PbSvGameCommand
|
||||
//
|
||||
extern void PBpakNames ( char *buf ) ;
|
||||
char * __cdecl PbSvGameCommand ( char *Cmd , char *Result )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return NULL ;
|
||||
if ( !stricmp ( Cmd , "set_sv_punkbuster" ) ) pbsdk->pb_SetSvPunkBuster ( Result ) ;
|
||||
else if ( !stricmp ( Cmd , "pakNames" ) ) PBpakNames ( Result ) ;//note: Result must be 1025+ bytes for this one
|
||||
else if ( !stricmp ( Cmd , "ConCapBufLen" ) ) pbsdk->ConsoleCaptureBufLen = (int) Result ;
|
||||
else if ( !stricmp ( Cmd , "ConCapBuf" ) ) pbsdk->ConsoleCaptureBuf = Result ;
|
||||
else if ( !stricmp ( Cmd , "Cmd_Exec" ) ) {
|
||||
int pb = !strnicmp ( Result , "pb_" , 3 ) ;
|
||||
pbsdk->pb_ExecCmd ( Result ) ;
|
||||
if ( pb ) PbServerForceProcess() ;
|
||||
} else {
|
||||
char *arg1 = Result ;
|
||||
while ( *arg1 == ' ' ) ++arg1 ;
|
||||
while ( *arg1 && *arg1 != ' ' ) ++arg1 ;
|
||||
char *endResult = arg1 ;
|
||||
while ( *arg1 == ' ' ) ++arg1 ;
|
||||
|
||||
if ( !stricmp ( Cmd , "DropClient" ) ) pbsdk->pb_DropClient ( atoi ( Result ) , arg1 ) ;
|
||||
else if ( !stricmp ( Cmd , "Cvar_Set" ) ) {
|
||||
char hold = *endResult ;
|
||||
*endResult = 0 ;
|
||||
pbsdk->pb_CvarSet ( Result , arg1 ) ;
|
||||
*endResult = hold ;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// PbSvGameQuery
|
||||
//
|
||||
// assumes Data buffer is appropriately size/allocated for Qtype call
|
||||
char * __cdecl PbSvGameQuery ( int Qtype , char *Data )
|
||||
{
|
||||
Data[PB_Q_MAXRESULTLEN] = 0 ;
|
||||
|
||||
int i ;
|
||||
switch ( Qtype ) {
|
||||
case PB_Q_MAXCLIENTS: itoa ( PB_MAX_CLIENTS , Data , 10 ) ; break ;
|
||||
case PB_Q_CLIENT:
|
||||
i = atoi ( Data ) ;
|
||||
if ( !pbsdk->pb_GetClientInfo ( i , (stPb_Sv_Client *) Data ) ) return PbsQueryFail ;
|
||||
break ;
|
||||
case PB_Q_CVAR: strncpy ( Data , pbsdk->pb_GetCvarValue ( Data ) , PB_Q_MAXRESULTLEN ) ; break ;
|
||||
case PB_Q_STATS:
|
||||
i = atoi ( Data ) ;
|
||||
if ( !pbsdk->pb_GetClientStats ( i , Data ) ) return PbsQueryFail ;
|
||||
break ;
|
||||
}
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// PbSvGameMsg
|
||||
//
|
||||
char * __cdecl PbSvGameMsg ( char *Msg , int Type )
|
||||
{
|
||||
if ( !isPBmultiplayerMode() ) return NULL ;
|
||||
|
||||
Type;//reserved
|
||||
pbsdk->pb_Outf ( "%s: %s\n" , pbsdk->pbsv.m_msgPrefix , Msg ) ;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// PbSvSendToClient
|
||||
//
|
||||
char * __cdecl PbSvSendToClient ( int DataLen , char *Data , int clientIndex )
|
||||
{
|
||||
pbsdk->pb_SendSvPacket ( DataLen , Data , clientIndex ) ;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// PbSvSendToAddrPort
|
||||
//
|
||||
char * __cdecl PbSvSendToAddrPort ( char *addr , unsigned short port , int DataLen , char *Data )
|
||||
{
|
||||
pbsdk->pb_SendUdpPacket ( addr , port , DataLen , Data , 0 ) ; //convert bits to bytes
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //#ifdef __WITHPB__
|
||||
#endif // NOT_USE_PUNKBUSTER_SDK
|
||||
444
PunkBuster/pbsv.h
Normal file
444
PunkBuster/pbsv.h
Normal file
@@ -0,0 +1,444 @@
|
||||
// Copyright (C) 2001-2003 Even Balance, Inc.
|
||||
//
|
||||
//
|
||||
// pbsv.h
|
||||
//
|
||||
// EVEN BALANCE - T.RAY
|
||||
//
|
||||
// The only file in the game project that needs to include this file is pbsv.cpp
|
||||
//
|
||||
|
||||
|
||||
|
||||
#ifndef __PBSV_H__
|
||||
#define __PBSV_H__
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "pbcommon.h"
|
||||
|
||||
#if !defined(NOT_USE_PUNKBUSTER_SDK)
|
||||
|
||||
#ifdef __PBWIN32__
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifdef __PBLINUX__
|
||||
#include <unistd.h>
|
||||
#include <dlfcn.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef __PBMAC__
|
||||
#include "../macosx/dlfcn.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __WITH_PB__
|
||||
|
||||
|
||||
|
||||
#ifdef _cplusplus
|
||||
|
||||
|
||||
|
||||
#if !defined(_WIN32) && !defined(__TRMACH__)
|
||||
#define _cdecl
|
||||
#define stricmp strcasecmp
|
||||
#define strnicmp strncasecmp
|
||||
#ifndef __TRLTOA__
|
||||
#define __TRLTOA__
|
||||
//
|
||||
// ltoa
|
||||
//
|
||||
// assumes buffer a is large enough to hold ascii representation of i
|
||||
//
|
||||
inline char *ltoa ( int i , char *a , int radix )
|
||||
{
|
||||
if ( a == NULL ) return NULL ;
|
||||
strcpy ( a , "0" ) ;
|
||||
if ( i && radix > 1 && radix < 37 ) {
|
||||
char buf[35] ;
|
||||
unsigned int u = i , p = 34 ;
|
||||
buf[p] = 0 ;
|
||||
if ( i < 0 && radix == 10 ) u = -i ;
|
||||
while ( u ) {
|
||||
unsigned int d = u % radix ;
|
||||
buf[--p] = d < 10 ? '0' + d : 'a' + d - 10 ;
|
||||
u /= radix ;
|
||||
}
|
||||
if ( i < 0 && radix == 10 ) buf[--p] = '-' ;
|
||||
strcpy ( a , buf + p ) ;
|
||||
}
|
||||
return a ;
|
||||
}
|
||||
#define itoa ltoa
|
||||
#endif
|
||||
#endif //#ifndef _WIN32
|
||||
|
||||
|
||||
|
||||
#ifndef __PBDLL__
|
||||
extern char *sa ( void *cp , int ticklimit ) ;
|
||||
extern char *sb ( void *cp , int event , int clientIndex , int datalen , char *data , int retry ) ;
|
||||
#endif
|
||||
|
||||
#define PB_MAX_CLIENTS 64
|
||||
|
||||
//
|
||||
// Class/Struct Definitions
|
||||
//
|
||||
struct stPbSvClSlot {
|
||||
stPb_Sv_Client pbc ;
|
||||
} ;
|
||||
|
||||
struct stPbSv {
|
||||
unsigned int m_svId ;
|
||||
void *m_Md5 ;
|
||||
void *m_SvInstance , *m_ClInstance , *m_AgInstance ;
|
||||
char m_msgPrefix[PB_MISCLEN+1] , m_basepath[PB_Q_MAXRESULTLEN+4] , m_homepath[PB_Q_MAXRESULTLEN+4] , m_cwd[PB_Q_MAXRESULTLEN+4] ;
|
||||
int m_ReloadServer ;
|
||||
|
||||
//func ptrs
|
||||
tdPbGameCommand m_GameCommand ;//game
|
||||
tdPbGameQuery m_GameQuery ;//game
|
||||
tdPbGameMsg m_GameMsg ;//game
|
||||
tdPbSendToClient m_SendToClient ;//game
|
||||
tdPbAddSvEvent m_AddPbEvent ;//dll
|
||||
tdPbProcessPbEvents m_ProcessPbEvents ;//dll
|
||||
tdPbSendToAddrPort m_SendToAddrPort ;//game
|
||||
tdPbPassConnectString m_PassConnectString ;//dll
|
||||
tdPbAuthClient m_AuthClient ;//dll
|
||||
tdPbTrapConsole m_TrapConsole ;//dll
|
||||
|
||||
void *m_Agent ;
|
||||
|
||||
stPbSvClSlot m_client[PB_MAX_CLIENTS] ;
|
||||
|
||||
inline void copyIfNotExists ( char *fn , char *basepath ) {
|
||||
char fromFn[PB_Q_MAXRESULTLEN*2+1] , toFn[PB_Q_MAXRESULTLEN*2+1] ;
|
||||
strcpy ( toFn , m_cwd ) ;
|
||||
strcat ( toFn , fn ) ;
|
||||
FILE *f = fopen ( toFn , "rb" ) ;
|
||||
if ( f != NULL ) fclose ( f ) ;
|
||||
else {
|
||||
strcpy ( fromFn , basepath ) ;
|
||||
strcat ( fromFn , fn ) ;
|
||||
PbCopyFile ( fromFn , toFn ) ;
|
||||
}
|
||||
}
|
||||
|
||||
inline char *getBasePath ( char *path ) {
|
||||
strncpy ( path , m_basepath , PB_Q_MAXRESULTLEN ) ;
|
||||
path[PB_Q_MAXRESULTLEN] = 0 ;
|
||||
if ( !(*path) ) getcwd ( path , PB_Q_MAXRESULTLEN - 4 ) ;
|
||||
if ( *path && path[strlen(path)-1] != *pbDIRSEP ) strcat ( path , pbDIRSEP ) ;
|
||||
strcat ( path , "pb" pbDIRSEP ) ;
|
||||
return path ;
|
||||
}
|
||||
|
||||
inline char *getHomePath ( void ) {
|
||||
strncpy ( m_cwd , m_homepath , PB_Q_MAXRESULTLEN ) ;
|
||||
m_cwd[PB_Q_MAXRESULTLEN] = 0 ;
|
||||
if ( !(*m_cwd) ) getcwd ( m_cwd , PB_Q_MAXRESULTLEN - 4 ) ;
|
||||
if ( *m_cwd && m_cwd[strlen(m_cwd)-1] != *pbDIRSEP ) strcat ( m_cwd , pbDIRSEP ) ;
|
||||
strcat ( m_cwd , "pb" pbDIRSEP ) ;
|
||||
return m_cwd ;
|
||||
}
|
||||
|
||||
inline char *makefn ( char *buf , char *fn ) { //assumes buf is large enough to hold cwd + fn + overhead
|
||||
if ( !(*m_cwd) ) {
|
||||
getHomePath() ;
|
||||
|
||||
char basepath[PB_Q_MAXRESULTLEN+4] ;
|
||||
getBasePath ( basepath ) ;
|
||||
if ( stricmp ( basepath , m_cwd ) && *basepath && *m_cwd ) {
|
||||
#ifdef __PBWIN32__
|
||||
mkdir ( m_cwd ) ;
|
||||
#endif
|
||||
#ifdef __PBLINUX__
|
||||
mkdir ( m_cwd , 511 ) ;
|
||||
#endif
|
||||
#ifdef __PBMAC__
|
||||
if ( m_cwd[strlen(m_cwd)-1] == *pbDIRSEP ) m_cwd[strlen(m_cwd)-1] = 0 ;
|
||||
mkdir ( m_cwd , 511 ) ;
|
||||
strcat ( m_cwd , pbDIRSEP ) ;
|
||||
#endif
|
||||
copyIfNotExists ( "pbsv" pbDLLEXT , basepath ) ;
|
||||
copyIfNotExists ( "pbcl" pbDLLEXT , basepath ) ;
|
||||
copyIfNotExists ( "pbag" pbDLLEXT , basepath ) ;
|
||||
}
|
||||
}
|
||||
strcpy ( buf , m_cwd ) ;
|
||||
strcat ( buf , fn ) ;
|
||||
return buf ;
|
||||
}
|
||||
|
||||
inline void UnloadClientDll ( void ) {
|
||||
#ifdef __PBWIN32__
|
||||
if ( m_ClInstance != NULL ) FreeLibrary ( (HMODULE) m_ClInstance ) ;
|
||||
#endif
|
||||
#ifdef __PBLINUX__
|
||||
if ( m_ClInstance != NULL ) dlclose ( m_ClInstance ) ;
|
||||
#endif
|
||||
#ifdef __PBMAC__
|
||||
if ( m_ClInstance != NULL ) dlclose ( m_ClInstance ) ;
|
||||
#endif
|
||||
m_ClInstance = NULL ;
|
||||
}
|
||||
|
||||
inline char *LoadClientDll ( void ) {
|
||||
if ( m_ClInstance != NULL ) return NULL ;
|
||||
UnloadClientDll() ;
|
||||
|
||||
//check for replacement (updated) dll files and rename if necessary
|
||||
|
||||
char fn[PB_Q_MAXRESULTLEN*2+1] , extrafn[PB_Q_MAXRESULTLEN*2+1] ;
|
||||
|
||||
FILE *f = fopen ( makefn ( fn , "pbclsnew" pbDLLEXT ) , "rb" ) ;
|
||||
if ( f != NULL ) {
|
||||
fclose ( f ) ;
|
||||
setRW ( makefn ( fn , "pbclsold" pbDLLEXT ) ) ;
|
||||
remove ( makefn ( fn , "pbclsold" pbDLLEXT ) ) ;
|
||||
rename ( makefn ( fn , "pbcls" pbDLLEXT ) , makefn ( extrafn , "pbclsold" pbDLLEXT ) ) ;
|
||||
setRW ( makefn ( fn , "pbcls" pbDLLEXT ) ) ;
|
||||
remove ( makefn ( fn , "pbcls" pbDLLEXT ) ) ;
|
||||
rename ( makefn ( fn , "pbclsnew" pbDLLEXT ) , makefn ( extrafn , "pbcls" pbDLLEXT ) ) ;
|
||||
}
|
||||
makefn ( fn , "pbcls" pbDLLEXT ) ;
|
||||
#ifdef __PBWIN32__
|
||||
m_ClInstance = LoadLibraryA ( fn ) ;
|
||||
#endif
|
||||
#ifdef __PBLINUX__
|
||||
m_ClInstance = ::dlopen ( fn , RTLD_LAZY ) ;
|
||||
#endif
|
||||
#ifdef __PBMAC__
|
||||
m_ClInstance = dlopen ( fn , RTLD_LAZY ) ;
|
||||
#endif
|
||||
if ( m_ClInstance != NULL ) return NULL ;
|
||||
return PbsSvDllLoadFail ;
|
||||
}
|
||||
|
||||
inline void UnloadAgentDll ( void ) {
|
||||
m_Agent = NULL ;
|
||||
#ifdef __PBWIN32__
|
||||
if ( m_AgInstance != NULL ) FreeLibrary ( (HMODULE) m_AgInstance ) ;
|
||||
#endif
|
||||
#ifdef __PBLINUX__
|
||||
if ( m_AgInstance != NULL ) dlclose ( m_AgInstance ) ;
|
||||
#endif
|
||||
#ifdef __PBMAC__
|
||||
if ( m_AgInstance != NULL ) dlclose ( m_AgInstance ) ;
|
||||
#endif
|
||||
m_AgInstance = NULL ;
|
||||
}
|
||||
|
||||
inline char *LoadAgentDll ( void ) {
|
||||
if ( m_AgInstance != NULL ) return NULL ;
|
||||
UnloadAgentDll() ;
|
||||
|
||||
//check for replacement (updated) dll files and rename if necessary
|
||||
|
||||
char fn[PB_Q_MAXRESULTLEN*2+1] , extrafn[PB_Q_MAXRESULTLEN*2+1] ;
|
||||
|
||||
FILE *f = fopen ( makefn ( fn , "pbagsnew" pbDLLEXT ) , "rb" ) ;
|
||||
if ( f != NULL ) {
|
||||
fclose ( f ) ;
|
||||
setRW ( makefn ( fn , "pbagsold" pbDLLEXT ) ) ;
|
||||
remove ( makefn ( fn , "pbagsold" pbDLLEXT ) ) ;
|
||||
rename ( makefn ( fn , "pbags" pbDLLEXT ) , makefn ( extrafn , "pbagsold" pbDLLEXT ) ) ;
|
||||
setRW ( makefn ( fn , "pbags" pbDLLEXT ) ) ;
|
||||
remove ( makefn ( fn , "pbags" pbDLLEXT ) ) ;
|
||||
rename ( makefn ( fn , "pbagsnew" pbDLLEXT ) , makefn ( extrafn , "pbags" pbDLLEXT ) ) ;
|
||||
}
|
||||
makefn ( fn , "pbags" pbDLLEXT ) ;
|
||||
#ifdef __PBWIN32__
|
||||
m_AgInstance = LoadLibraryA ( fn ) ;
|
||||
if ( m_AgInstance != NULL ) {
|
||||
m_Agent = GetProcAddress ( (HMODULE) m_AgInstance , "a" ) ;
|
||||
if ( m_Agent != NULL ) return NULL ;
|
||||
UnloadAgentDll() ;
|
||||
}
|
||||
#endif
|
||||
#ifdef __PBLINUX__
|
||||
m_AgInstance = ::dlopen ( fn , RTLD_LAZY ) ;
|
||||
if ( m_AgInstance != NULL ) {
|
||||
m_Agent = dlsym ( m_AgInstance , "a" ) ;
|
||||
if ( m_Agent != NULL ) return NULL ;
|
||||
UnloadAgentDll() ;
|
||||
}
|
||||
#endif
|
||||
#ifdef __PBMAC__
|
||||
m_AgInstance = dlopen ( fn , RTLD_LAZY ) ;
|
||||
if ( m_AgInstance != NULL ) {
|
||||
m_Agent = dlsym ( m_AgInstance , "_a" ) ;
|
||||
if ( m_Agent != NULL ) return NULL ;
|
||||
UnloadAgentDll() ;
|
||||
}
|
||||
#endif
|
||||
return PbsSvDllLoadFail ;
|
||||
}
|
||||
|
||||
#ifndef __PBDLL__ //the following functions are not needed by the PB DLLs
|
||||
|
||||
inline void uninitialize ( void ) {//also initializes game-side func ptrs
|
||||
m_GameCommand = NULL ;
|
||||
m_GameQuery = NULL ;
|
||||
m_GameMsg = NULL ;
|
||||
m_SendToClient = NULL ;
|
||||
m_SendToAddrPort = NULL ;
|
||||
m_PassConnectString = NULL ;
|
||||
m_AuthClient = NULL ;
|
||||
m_TrapConsole = NULL ;
|
||||
m_Md5 = NULL ;
|
||||
}
|
||||
|
||||
inline void initialize ( void ) {
|
||||
uninitialize() ;
|
||||
m_GameCommand = PbSvGameCommand ;
|
||||
m_GameQuery = PbSvGameQuery ;
|
||||
m_GameMsg = PbSvGameMsg ;
|
||||
m_SendToClient = PbSvSendToClient ;
|
||||
m_SendToAddrPort = PbSvSendToAddrPort ;
|
||||
}
|
||||
|
||||
inline void UnloadServerDll ( void ) {
|
||||
m_ProcessPbEvents = NULL ;
|
||||
m_AddPbEvent = NULL ;
|
||||
|
||||
m_PassConnectString = NULL ;
|
||||
m_AuthClient = NULL ;
|
||||
m_TrapConsole = NULL ;
|
||||
m_Md5 = NULL ;
|
||||
|
||||
#ifdef __PBWIN32__
|
||||
if ( m_SvInstance != NULL ) FreeLibrary ( (HMODULE) m_SvInstance ) ;
|
||||
#endif
|
||||
#ifdef __PBLINUX__
|
||||
if ( m_SvInstance != NULL ) dlclose ( m_SvInstance ) ;
|
||||
#endif
|
||||
#ifdef __PBMAC__
|
||||
if ( m_SvInstance != NULL ) dlclose ( m_SvInstance ) ;
|
||||
#endif
|
||||
m_SvInstance = NULL ;
|
||||
}
|
||||
|
||||
inline char *LoadServerDll ( void ) {
|
||||
if ( m_SvInstance != NULL ) return NULL ;
|
||||
UnloadServerDll() ;
|
||||
|
||||
char fn[PB_Q_MAXRESULTLEN*2+1] , extrafn[PB_Q_MAXRESULTLEN*2+1] ;
|
||||
|
||||
//check for replacement (updated) dll file and rename if necessary
|
||||
//load PB server dll and retrieve exported function pointers
|
||||
FILE *f = fopen ( makefn ( fn , "pbsvnew" pbDLLEXT ) , "rb" ) ;
|
||||
if ( f != NULL ) {
|
||||
fclose ( f ) ;
|
||||
setRW ( makefn ( fn , "pbsvold" pbDLLEXT ) ) ;
|
||||
remove ( makefn ( fn , "pbsvold" pbDLLEXT ) ) ;
|
||||
rename ( makefn ( fn , "pbsv" pbDLLEXT ) , makefn ( extrafn , "pbsvold" pbDLLEXT ) ) ;
|
||||
setRW ( makefn ( fn , "pbsv" pbDLLEXT ) ) ;
|
||||
remove ( makefn ( fn , "pbsv" pbDLLEXT ) ) ;
|
||||
rename ( makefn ( fn , "pbsvnew" pbDLLEXT ) , makefn ( extrafn , "pbsv" pbDLLEXT ) ) ;
|
||||
}
|
||||
#ifdef __PBWIN32__
|
||||
m_SvInstance = LoadLibraryA ( makefn ( fn , "pbsv" pbDLLEXT ) ) ;
|
||||
if ( m_SvInstance == NULL ) return PbsSvDllLoadFail ;
|
||||
m_ProcessPbEvents = (tdPbProcessPbEvents) GetProcAddress ( (HINSTANCE) m_SvInstance , "sa" ) ;
|
||||
m_AddPbEvent = (tdPbAddSvEvent) GetProcAddress ( (HINSTANCE) m_SvInstance , "sb" ) ;
|
||||
#endif
|
||||
#ifdef __PBLINUX__
|
||||
m_SvInstance = ::dlopen ( makefn ( fn , "pbsv" pbDLLEXT ) , RTLD_LAZY ) ;
|
||||
if ( m_SvInstance == NULL ) return PbsSvDllLoadFail ;
|
||||
m_ProcessPbEvents = (tdPbProcessPbEvents) dlsym ( m_SvInstance , "sa" ) ;
|
||||
m_AddPbEvent = (tdPbAddSvEvent) dlsym ( m_SvInstance , "sb" ) ;
|
||||
#endif
|
||||
#ifdef __PBMAC__
|
||||
m_SvInstance = dlopen ( makefn ( fn , "pbsv" pbDLLEXT ) , RTLD_LAZY ) ;
|
||||
if ( m_SvInstance == NULL ) return PbsSvDllLoadFail ;
|
||||
m_ProcessPbEvents = (tdPbProcessPbEvents) dlsym ( m_SvInstance , "_sa" ) ;
|
||||
m_AddPbEvent = (tdPbAddSvEvent) dlsym ( m_SvInstance , "_sb" ) ;
|
||||
#endif
|
||||
|
||||
if ( m_ProcessPbEvents == NULL || m_AddPbEvent == NULL ) {
|
||||
UnloadServerDll() ;
|
||||
return PbsSvDllProcFail ;
|
||||
}
|
||||
|
||||
m_ReloadServer = 0 ;
|
||||
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
inline char *AddPbEvent ( int type , int clientIndex , int datalen , char *data , int retry = 0 ) {
|
||||
if ( m_GameCommand == NULL ) return NULL ;//not considered an error, this signifies that PB is disabled
|
||||
|
||||
if ( m_ReloadServer || m_SvInstance == NULL ) {
|
||||
if ( m_SvInstance != NULL ) {
|
||||
UnloadServerDll() ;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
char *res = LoadServerDll() ;
|
||||
if ( res != NULL ) {
|
||||
if ( type == PB_EV_ISENABLED ) return (char *) 0 ;
|
||||
return res ;
|
||||
}
|
||||
}
|
||||
|
||||
return m_AddPbEvent ( this , type , clientIndex , datalen , data , retry ) ;
|
||||
}
|
||||
|
||||
inline char *ProcessPbEvents ( int TickLimit = 0 ) {
|
||||
if ( m_GameCommand == NULL ) return NULL ;//not considered an error, this signifies that PB is disabled
|
||||
if ( m_SvInstance == NULL ) {
|
||||
if ( m_ReloadServer ) AddPbEvent ( PB_EV_CONFIG , -1 , 0 , "" ) ;
|
||||
return NULL ;//no events have been successfully added so nothing to process
|
||||
}
|
||||
|
||||
if ( m_ReloadServer ) {
|
||||
UnloadServerDll() ;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
char *ret = m_ProcessPbEvents ( this , TickLimit ) ;
|
||||
|
||||
if ( m_ReloadServer ) {
|
||||
UnloadServerDll() ;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
return ret ;
|
||||
}
|
||||
|
||||
inline void init ( void ) {
|
||||
m_svId = PB_SV_ID ;
|
||||
strcpy ( m_msgPrefix , "PunkBuster Server" ) ;
|
||||
m_SvInstance = NULL ;
|
||||
m_ReloadServer = 1 ;
|
||||
uninitialize() ;
|
||||
}
|
||||
|
||||
inline stPbSv() {
|
||||
init() ;
|
||||
}
|
||||
|
||||
inline ~stPbSv() {
|
||||
UnloadServerDll() ;
|
||||
UnloadClientDll() ;
|
||||
UnloadAgentDll() ;
|
||||
}
|
||||
|
||||
#endif //#ifndef __PBDLL__
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
#endif //#ifdef _cplusplus
|
||||
#endif //#ifdef __WITHPB__
|
||||
#endif //#ifndef __PBSV_H__
|
||||
#endif // NOT_USE_PUNKBUSTER_SDK
|
||||
Reference in New Issue
Block a user