| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "../qcommon/q_shared.h" |
| 24 |
#include "../qcommon/qcommon.h" |
| 25 |
#include "server.h" |
| 26 |
|
| 27 |
#ifdef LEGACY_PROTOCOL |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
static void SV_Netchan_Encode(client_t *client, msg_t *msg, const char *clientCommandString) |
| 38 |
{ |
| 39 |
long i, index; |
| 40 |
byte key, *string; |
| 41 |
int srdc, sbit; |
| 42 |
qboolean soob; |
| 43 |
|
| 44 |
if ( msg->cursize < SV_ENCODE_START ) { |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
srdc = msg->readcount; |
| 49 |
sbit = msg->bit; |
| 50 |
soob = msg->oob; |
| 51 |
|
| 52 |
msg->bit = 0; |
| 53 |
msg->readcount = 0; |
| 54 |
msg->oob = qfalse; |
| 55 |
|
| 56 |
MSG_ReadLong(msg); |
| 57 |
|
| 58 |
msg->oob = soob; |
| 59 |
msg->bit = sbit; |
| 60 |
msg->readcount = srdc; |
| 61 |
|
| 62 |
string = (byte *) clientCommandString; |
| 63 |
index = 0; |
| 64 |
|
| 65 |
key = client->challenge ^ client->netchan.outgoingSequence; |
| 66 |
for (i = SV_ENCODE_START; i < msg->cursize; i++) { |
| 67 |
|
| 68 |
if (!string[index]) |
| 69 |
index = 0; |
| 70 |
if (string[index] > 127 || string[index] == '%') { |
| 71 |
key ^= '.' << (i & 1); |
| 72 |
} |
| 73 |
else { |
| 74 |
key ^= string[index] << (i & 1); |
| 75 |
} |
| 76 |
index++; |
| 77 |
|
| 78 |
*(msg->data + i) = *(msg->data + i) ^ key; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
static void SV_Netchan_Decode( client_t *client, msg_t *msg ) { |
| 94 |
int serverId, messageAcknowledge, reliableAcknowledge; |
| 95 |
int i, index, srdc, sbit; |
| 96 |
qboolean soob; |
| 97 |
byte key, *string; |
| 98 |
|
| 99 |
srdc = msg->readcount; |
| 100 |
sbit = msg->bit; |
| 101 |
soob = msg->oob; |
| 102 |
|
| 103 |
msg->oob = qfalse; |
| 104 |
|
| 105 |
serverId = MSG_ReadLong(msg); |
| 106 |
messageAcknowledge = MSG_ReadLong(msg); |
| 107 |
reliableAcknowledge = MSG_ReadLong(msg); |
| 108 |
|
| 109 |
msg->oob = soob; |
| 110 |
msg->bit = sbit; |
| 111 |
msg->readcount = srdc; |
| 112 |
|
| 113 |
string = (byte *)client->reliableCommands[ reliableAcknowledge & (MAX_RELIABLE_COMMANDS-1) ]; |
| 114 |
index = 0; |
| 115 |
|
| 116 |
key = client->challenge ^ serverId ^ messageAcknowledge; |
| 117 |
for (i = msg->readcount + SV_DECODE_START; i < msg->cursize; i++) { |
| 118 |
|
| 119 |
if (!string[index]) |
| 120 |
index = 0; |
| 121 |
if (string[index] > 127 || string[index] == '%') { |
| 122 |
key ^= '.' << (i & 1); |
| 123 |
} |
| 124 |
else { |
| 125 |
key ^= string[index] << (i & 1); |
| 126 |
} |
| 127 |
index++; |
| 128 |
|
| 129 |
*(msg->data + i) = *(msg->data + i) ^ key; |
| 130 |
} |
| 131 |
} |
| 132 |
#endif |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
void SV_Netchan_FreeQueue(client_t *client) |
| 142 |
{ |
| 143 |
netchan_buffer_t *netbuf, *next; |
| 144 |
|
| 145 |
for(netbuf = client->netchan_start_queue; netbuf; netbuf = next) |
| 146 |
{ |
| 147 |
next = netbuf->next; |
| 148 |
Z_Free(netbuf); |
| 149 |
} |
| 150 |
|
| 151 |
client->netchan_start_queue = NULL; |
| 152 |
client->netchan_end_queue = &client->netchan_start_queue; |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
void SV_Netchan_TransmitNextInQueue(client_t *client) |
| 161 |
{ |
| 162 |
netchan_buffer_t *netbuf; |
| 163 |
|
| 164 |
Com_DPrintf("#462 Netchan_TransmitNextFragment: popping a queued message for transmit\n"); |
| 165 |
netbuf = client->netchan_start_queue; |
| 166 |
|
| 167 |
#ifdef LEGACY_PROTOCOL |
| 168 |
if(client->compat) |
| 169 |
SV_Netchan_Encode(client, &netbuf->msg, netbuf->clientCommandString); |
| 170 |
#endif |
| 171 |
|
| 172 |
Netchan_Transmit(&client->netchan, netbuf->msg.cursize, netbuf->msg.data); |
| 173 |
|
| 174 |
|
| 175 |
client->netchan_start_queue = netbuf->next; |
| 176 |
if(!client->netchan_start_queue) |
| 177 |
{ |
| 178 |
Com_DPrintf("#462 Netchan_TransmitNextFragment: emptied queue\n"); |
| 179 |
client->netchan_end_queue = &client->netchan_start_queue; |
| 180 |
} |
| 181 |
else |
| 182 |
Com_DPrintf("#462 Netchan_TransmitNextFragment: remaining queued message\n"); |
| 183 |
|
| 184 |
Z_Free(netbuf); |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
int SV_Netchan_TransmitNextFragment(client_t *client) |
| 197 |
{ |
| 198 |
if(client->netchan.unsentFragments) |
| 199 |
{ |
| 200 |
Netchan_TransmitNextFragment(&client->netchan); |
| 201 |
return SV_RateMsec(client); |
| 202 |
} |
| 203 |
else if(client->netchan_start_queue) |
| 204 |
{ |
| 205 |
SV_Netchan_TransmitNextInQueue(client); |
| 206 |
return SV_RateMsec(client); |
| 207 |
} |
| 208 |
|
| 209 |
return -1; |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
void SV_Netchan_Transmit( client_t *client, msg_t *msg) |
| 225 |
{ |
| 226 |
MSG_WriteByte( msg, svc_EOF ); |
| 227 |
|
| 228 |
if(client->netchan.unsentFragments || client->netchan_start_queue) |
| 229 |
{ |
| 230 |
netchan_buffer_t *netbuf; |
| 231 |
Com_DPrintf("#462 SV_Netchan_Transmit: unsent fragments, stacked\n"); |
| 232 |
netbuf = (netchan_buffer_t *) Z_Malloc(sizeof(netchan_buffer_t)); |
| 233 |
|
| 234 |
MSG_Copy(&netbuf->msg, netbuf->msgBuffer, sizeof( netbuf->msgBuffer ), msg); |
| 235 |
#ifdef LEGACY_PROTOCOL |
| 236 |
if(client->compat) |
| 237 |
{ |
| 238 |
Q_strncpyz(netbuf->clientCommandString, client->lastClientCommandString, |
| 239 |
sizeof(netbuf->clientCommandString)); |
| 240 |
} |
| 241 |
#endif |
| 242 |
netbuf->next = NULL; |
| 243 |
|
| 244 |
*client->netchan_end_queue = netbuf; |
| 245 |
client->netchan_end_queue = &(*client->netchan_end_queue)->next; |
| 246 |
} |
| 247 |
else |
| 248 |
{ |
| 249 |
#ifdef LEGACY_PROTOCOL |
| 250 |
if(client->compat) |
| 251 |
SV_Netchan_Encode(client, msg, client->lastClientCommandString); |
| 252 |
#endif |
| 253 |
Netchan_Transmit( &client->netchan, msg->cursize, msg->data ); |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
qboolean SV_Netchan_Process( client_t *client, msg_t *msg ) { |
| 263 |
int ret; |
| 264 |
ret = Netchan_Process( &client->netchan, msg ); |
| 265 |
if (!ret) |
| 266 |
return qfalse; |
| 267 |
|
| 268 |
#ifdef LEGACY_PROTOCOL |
| 269 |
if(client->compat) |
| 270 |
SV_Netchan_Decode(client, msg); |
| 271 |
#endif |
| 272 |
|
| 273 |
return qtrue; |
| 274 |
} |
| 275 |
|