Debian Codegraph @

code/client/cl_net_chan.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22
23 #include "../qcommon/q_shared.h"
24 #include "../qcommon/qcommon.h"
25 #include "client.h"
26
27 #ifdef LEGACY_PROTOCOL
28 /*
29 ==============
30 CL_Netchan_Encode
31
32 // first 12 bytes of the data are always:
33 long serverId;
34 long messageAcknowledge;
35 long reliableAcknowledge;
36
37 ==============
38 */
39 static void CL_Netchan_Encode( msg_t *msg ) {
40 int serverId, messageAcknowledge, reliableAcknowledge;
41 int i, index, srdc, sbit, soob;
42 byte key, *string;
43
44 if ( msg->cursize <= CL_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 = 0;
55
56 serverId = MSG_ReadLong(msg);
57 messageAcknowledge = MSG_ReadLong(msg);
58 reliableAcknowledge = MSG_ReadLong(msg);
59
60 msg->oob = soob;
61 msg->bit = sbit;
62 msg->readcount = srdc;
63
64 string = (byte *)clc.serverCommands[ reliableAcknowledge & (MAX_RELIABLE_COMMANDS-1) ];
65 index = 0;
66 //
67 key = clc.challenge ^ serverId ^ messageAcknowledge;
68 for (i = CL_ENCODE_START; i < msg->cursize; i++) {
69 // modify the key with the last received now acknowledged server command
70 if (!string[index])
71 index = 0;
72 if (string[index] > 127 || string[index] == '%') {
73 key ^= '.' << (i & 1);
74 }
75 else {
76 key ^= string[index] << (i & 1);
77 }
78 index++;
79 // encode the data with this key
80 *(msg->data + i) = (*(msg->data + i)) ^ key;
81 }
82 }
83
84 /*
85 ==============
86 CL_Netchan_Decode
87
88 // first four bytes of the data are always:
89 long reliableAcknowledge;
90
91 ==============
92 */
93 static void CL_Netchan_Decode( msg_t *msg ) {
94 long reliableAcknowledge, i, index;
95 byte key, *string;
96 int srdc, sbit, soob;
97
98 srdc = msg->readcount;
99 sbit = msg->bit;
100 soob = msg->oob;
101
102 msg->oob = 0;
103
104 reliableAcknowledge = MSG_ReadLong(msg);
105
106 msg->oob = soob;
107 msg->bit = sbit;
108 msg->readcount = srdc;
109
110 string = (byte *) clc.reliableCommands[ reliableAcknowledge & (MAX_RELIABLE_COMMANDS-1) ];
111 index = 0;
112 // xor the client challenge with the netchan sequence number (need something that changes every message)
113 key = clc.challenge ^ LittleLong( *(unsigned *)msg->data );
114 for (i = msg->readcount + CL_DECODE_START; i < msg->cursize; i++) {
115 // modify the key with the last sent and with this message acknowledged client command
116 if (!string[index])
117 index = 0;
118 if (string[index] > 127 || string[index] == '%') {
119 key ^= '.' << (i & 1);
120 }
121 else {
122 key ^= string[index] << (i & 1);
123 }
124 index++;
125 // decode the data with this key
126 *(msg->data + i) = *(msg->data + i) ^ key;
127 }
128 }
129 #endif
130
131 /*
132 =================
133 CL_Netchan_TransmitNextFragment
134 =================
135 */
136 qboolean CL_Netchan_TransmitNextFragment(netchan_t *chan)
137 {
138 if(chan->unsentFragments)
139 {
140 Netchan_TransmitNextFragment(chan);
141 return qtrue;
142 }
143
144 return qfalse;
145 }
146
147 /*
148 ===============
149 CL_Netchan_Transmit
150 ================
151 */
152 void CL_Netchan_Transmit( netchan_t *chan, msg_t* msg ) {
153 MSG_WriteByte( msg, clc_EOF );
154
155 #ifdef LEGACY_PROTOCOL
156 if(chan->compat)
157 CL_Netchan_Encode(msg);
158 #endif
159
160 Netchan_Transmit(chan, msg->cursize, msg->data);
161
162 // Transmit all fragments without delay
163 while(CL_Netchan_TransmitNextFragment(chan))
164 {
165 Com_DPrintf("WARNING: #462 unsent fragments (not supposed to happen!)\n");
166 }
167 }
168
169 /*
170 =================
171 CL_Netchan_Process
172 =================
173 */
174 qboolean CL_Netchan_Process( netchan_t *chan, msg_t *msg ) {
175 int ret;
176
177 ret = Netchan_Process( chan, msg );
178 if (!ret)
179 return qfalse;
180
181 #ifdef LEGACY_PROTOCOL
182 if(chan->compat)
183 CL_Netchan_Decode(msg);
184 #endif
185
186 return qtrue;
187 }