forked from haithun/CoD4X17a_testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsv_punkbuster.c
162 lines (117 loc) · 4.4 KB
/
sv_punkbuster.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
===========================================================================
Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team
This file is part of CoD4X17a-Server source code.
CoD4X17a-Server source code is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
CoD4X17a-Server source code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
===========================================================================
*/
#include "q_shared.h"
#include "qcommon_io.h"
#include "cvar.h"
#include "sys_net.h"
#include "server.h"
#include "g_shared.h"
#include "punkbuster.h"
#include <string.h>
#include <stdlib.h>
#ifndef MAX_PACKETLEN
#define MAX_PACKETLEN 1400
#endif
/*********************************************************************************************/
// Mandatory functions for PunkBuster operation
/*********************************************************************************************/
__cdecl int PbSvSendToAddrPort(char* netdest, unsigned short port, int msgsize, char* message){
char *sourcemsg;
char msg[256];
netadr_t netadr;
__asm("leal -0x836(,%%ebp,1), %%eax\n\t" :"=a"(sourcemsg));
if(!Q_strncmp(sourcemsg, "PunkBuster Server:", 18)){
Q_strncpyz(msg, sourcemsg, sizeof(msg));
if(strstr(msg,"NoGUID*")) //Prevent telling about Players without GUIDs to streaming-servers
return 0;
}
NET_StringToAdr(va("%s:%i", netdest, port), &netadr, NA_UNSPEC);
netadr.sock = 0;
netadr_t *sockadr;
if((sockadr = NET_GetDefaultCommunicationSocket()) != NULL)
netadr.sock = sockadr->sock;
NET_SendPacket(NS_SERVER, msgsize, message, &netadr);
return 0;
}
__cdecl int PbSvSendToClient(int msgsize, char* message, int clientnum){
client_t *cl;
cl = &svs.clients[clientnum];
if(cl->state >= CS_CONNECTED){
byte string[MAX_PACKETLEN];
int i;
// set the OutOfBand header
string[0] = 0xff;
string[1] = 0xff;
string[2] = 0xff;
string[3] = 0xff;
if(msgsize + 4 > MAX_PACKETLEN){
Com_PrintWarning("Buffer Overflow in NET_OutOfBandData %i bytes\n", msgsize);
return 0;
}
for ( i = 0; i < msgsize ; i++ ) {
string[i+4] = message[i];
}
NET_SendPacket( NS_SERVER, i+4, string, &cl->netchan.remoteAddress );
}
return 0;
}
__cdecl char* PbSvGameQuery(int para_01, char* string){
int maxclients;
client_t *cl;
gclient_t *gclient;
string[255] = 0;
int var_01;
if(!string) return NULL;
switch(para_01){
case 0x65:
maxclients = sv_maxclients->integer;
if(!maxclients) return 0;
*string = 0x30;
Com_sprintf(string, 255, "%i", maxclients);
return 0;
case 0x66:
maxclients = sv_maxclients->integer;
var_01 = atoi(string);
Com_Memset(string, 0, 0x68);
if(var_01 < 0 || var_01 > maxclients) return "PB_Error: Query Failed";
cl = &svs.clients[var_01];
if(cl->state < CS_ACTIVE || cl->noPb == qtrue) return "PB_Error: Query Failed";
Q_strncpyz(string, cl->name, 254);
Q_strncpyz(&string[33], cl->pbguid, 221);
Q_strncpyz(&string[66], NET_AdrToString(&cl->netchan.remoteAddress), 188);
return NULL;
case 0x67:
Q_strncpyz(string, Cvar_GetVariantString(string),255);
return NULL;
case 0x72:
maxclients = sv_maxclients->integer;
*string = 0;
var_01 = atoi(string);
if(var_01 < 0 || var_01 > maxclients) return "PB_Error: Query Failed";;
cl = &svs.clients[var_01];
gclient = &level.clients[para_01];
if(cl->state < CS_ACTIVE || cl->noPb) return "PB_Error: Query Failed";;
Com_sprintf(string,255,"ping=%d score=%d", cl->ping, gclient->pers.scoreboard.score);
return NULL;
default:
return NULL;
}
}
void PbCapatureConsoleOutput_wrapper(const char *msg, int msglen)
{
PbCapatureConsoleOutput(msg, 4096);
}