Cube  Diff

Differences From Artifact [eb9667cf69]:

To Artifact [e92e9ee6ab]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// client processing of the incoming network stream

#include "cube.h"

extern int clientnum;
extern bool c2sinit, senditemstoserver;
extern string toservermap;
extern string clientpassword;

void
neterr(char *s)
{
	conoutf("illegal network message (%s)", s);
	disconnect();
};

void
changemapserv(char *name, int mode) // forced map change from the server
{
	gamemode = mode;












|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// client processing of the incoming network stream

#include "cube.h"

extern int clientnum;
extern bool c2sinit, senditemstoserver;
extern string toservermap;
extern string clientpassword;

void
neterr(char *s)
{
	conoutf(@"illegal network message (%s)", s);
	disconnect();
};

void
changemapserv(char *name, int mode) // forced map change from the server
{
	gamemode = mode;
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
	while (p < end)
		switch (type = getint(p)) {
		case SV_INITS2C: // welcome messsage from the server
		{
			cn = getint(p);
			int prot = getint(p);
			if (prot != PROTOCOL_VERSION) {
				conoutf("you are using a different game "
				        "protocol (you: %d, server: %d)",
				    PROTOCOL_VERSION, prot);
				disconnect();
				return;
			};
			toservermap[0] = 0;
			clientnum = cn; // we are now fully connected
			if (!getint(p))
				strcpy_s(toservermap,
				    getclientmap()); // we are the first client
				                     // on this server, set map
			sgetstr();
			if (text[0] && strcmp(text, clientpassword)) {
				conoutf("you need to set the correct password "
				        "to join this server!");
				disconnect();
				return;
			};
			if (getint(p) == 1) {
				conoutf("server is FULL, disconnecting..");
			};
			break;
		};

		case SV_POS: // position of another client
		{
			cn = getint(p);







|
|












|
|




|







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
	while (p < end)
		switch (type = getint(p)) {
		case SV_INITS2C: // welcome messsage from the server
		{
			cn = getint(p);
			int prot = getint(p);
			if (prot != PROTOCOL_VERSION) {
				conoutf(@"you are using a different game "
				        @"protocol (you: %d, server: %d)",
				    PROTOCOL_VERSION, prot);
				disconnect();
				return;
			};
			toservermap[0] = 0;
			clientnum = cn; // we are now fully connected
			if (!getint(p))
				strcpy_s(toservermap,
				    getclientmap()); // we are the first client
				                     // on this server, set map
			sgetstr();
			if (text[0] && strcmp(text, clientpassword)) {
				conoutf(@"you need to set the correct password "
				        @"to join this server!");
				disconnect();
				return;
			};
			if (getint(p) == 1) {
				conoutf(@"server is FULL, disconnecting..");
			};
			break;
		};

		case SV_POS: // position of another client
		{
			cn = getint(p);
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
163
164
165
166
167
168

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214

215
216
217
218
219
220
221
222
223
224
225
226
227

228
229
230
231
232
233
234
235
236
237
238
239
240
241
242

243
244
245
246
247
248
249
250
251
252
253
254
255
256



257
258
259
260

261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

281
282
283
284
285
286
287

		case SV_SOUND:
			playsound(getint(p), &d->o);
			break;

		case SV_TEXT:
			sgetstr();
			conoutf("%s:\f %s", d->name, text);
			break;

		case SV_MAPCHANGE:
			sgetstr();
			changemapserv(text, getint(p));
			mapchanged = true;
			break;

		case SV_ITEMLIST: {
			int n;
			if (mapchanged) {
				senditemstoserver = false;
				resetspawns();
			};
			while ((n = getint(p)) != -1)
				if (mapchanged)
					setspawn(n, true);
			break;
		};


		case SV_MAPRELOAD: // server requests next map
		{
			getint(p);
			sprintf_sd(nextmapalias)("nextmap_%s", getclientmap());
			char *map =
			    getalias(nextmapalias); // look up map in the cycle
			changemap(map ? map : getclientmap());
			break;
		};


		case SV_INITC2S: // another client either connected or changed
		                 // name/team
		{
			sgetstr();
			if (d->name[0]) // already connected
			{
				if (strcmp(d->name, text))
					conoutf("%s is now known as %s",
					    d->name, text);
			} else // new client
			{
				c2sinit =
				    false; // send new players my info again
				conoutf("connected: %s", text);
			};
			strcpy_s(d->name, text);
			sgetstr();
			strcpy_s(d->team, text);
			d->lifesequence = getint(p);
			break;
		};


		case SV_CDIS:
			cn = getint(p);
			if (!(d = getclient(cn)))
				break;
			conoutf("player %s disconnected",
			    d->name[0] ? d->name : "[incompatible client]");
			zapdynent(players[cn]);
			break;

		case SV_SHOT: {
			int gun = getint(p);
			vec s, e;
			s.x = getint(p) / DMF;
			s.y = getint(p) / DMF;
			s.z = getint(p) / DMF;
			e.x = getint(p) / DMF;
			e.y = getint(p) / DMF;
			e.z = getint(p) / DMF;
			if (gun == GUN_SG)
				createrays(s, e);
			shootv(gun, s, e, d);
			break;
		};


		case SV_DAMAGE: {
			int target = getint(p);
			int damage = getint(p);
			int ls = getint(p);
			if (target == clientnum) {
				if (ls == player1->lifesequence)
					selfdamage(damage, cn, d);
			} else
				playsound(
				    S_PAIN1 + rnd(5), &getclient(target)->o);
			break;
		};


		case SV_DIED: {
			int actor = getint(p);
			if (actor == cn) {
				conoutf("%s suicided", d->name);
			} else if (actor == clientnum) {
				int frags;
				if (isteam(player1->team, d->team)) {
					frags = -1;
					conoutf("you fragged a teammate (%s)",
					    d->name);
				} else {
					frags = 1;
					conoutf("you fragged %s", d->name);
				};

				addmsg(1, 2, SV_FRAGS, player1->frags += frags);
			} else {
				dynent *a = getclient(actor);
				if (a) {
					if (isteam(a->team, d->name)) {
						conoutf("%s fragged his "
						        "teammate (%s)",
						    a->name, d->name);
					} else {
						conoutf("%s fragged %s",
						    a->name, d->name);
					};
				};
			};



			playsound(S_DIE1 + rnd(2), &d->o);
			d->lifesequence++;
			break;
		};


		case SV_FRAGS:
			players[cn]->frags = getint(p);
			break;

		case SV_ITEMPICKUP:
			setspawn(getint(p), false);
			getint(p);
			break;

		case SV_ITEMSPAWN: {
			uint i = getint(p);
			setspawn(i, true);
			if (i >= (uint)ents.length())
				break;
			vec v = {(float)ents[i].x, (float)ents[i].y,
			    (float)ents[i].z};
			playsound(S_ITEMSPAWN, &v);
			break;
		};


		case SV_ITEMACC: // server acknowledges that I picked up this
		                 // item
			realpickup(getint(p), player1);
			break;

		case SV_EDITH: // coop editing messages, should be extended to







|


















<
>









<
>








|





|






<
>





|

















<
>












<
>




|




|



|
<
>





|
|


|

<
<
<
>
>
>



<
>



















<
>







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
163
164
165
166
167

168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
234
235
236
237
238
239
240
241

242
243
244
245
246
247
248
249
250
251
252
253



254
255
256
257
258
259

260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279

280
281
282
283
284
285
286
287

		case SV_SOUND:
			playsound(getint(p), &d->o);
			break;

		case SV_TEXT:
			sgetstr();
			conoutf(@"%s:\f %s", d->name, text);
			break;

		case SV_MAPCHANGE:
			sgetstr();
			changemapserv(text, getint(p));
			mapchanged = true;
			break;

		case SV_ITEMLIST: {
			int n;
			if (mapchanged) {
				senditemstoserver = false;
				resetspawns();
			};
			while ((n = getint(p)) != -1)
				if (mapchanged)
					setspawn(n, true);
			break;

		}

		case SV_MAPRELOAD: // server requests next map
		{
			getint(p);
			sprintf_sd(nextmapalias)("nextmap_%s", getclientmap());
			char *map =
			    getalias(nextmapalias); // look up map in the cycle
			changemap(map ? map : getclientmap());
			break;

		}

		case SV_INITC2S: // another client either connected or changed
		                 // name/team
		{
			sgetstr();
			if (d->name[0]) // already connected
			{
				if (strcmp(d->name, text))
					conoutf(@"%s is now known as %s",
					    d->name, text);
			} else // new client
			{
				c2sinit =
				    false; // send new players my info again
				conoutf(@"connected: %s", text);
			};
			strcpy_s(d->name, text);
			sgetstr();
			strcpy_s(d->team, text);
			d->lifesequence = getint(p);
			break;

		}

		case SV_CDIS:
			cn = getint(p);
			if (!(d = getclient(cn)))
				break;
			conoutf(@"player %s disconnected",
			    d->name[0] ? d->name : "[incompatible client]");
			zapdynent(players[cn]);
			break;

		case SV_SHOT: {
			int gun = getint(p);
			vec s, e;
			s.x = getint(p) / DMF;
			s.y = getint(p) / DMF;
			s.z = getint(p) / DMF;
			e.x = getint(p) / DMF;
			e.y = getint(p) / DMF;
			e.z = getint(p) / DMF;
			if (gun == GUN_SG)
				createrays(s, e);
			shootv(gun, s, e, d);
			break;

		}

		case SV_DAMAGE: {
			int target = getint(p);
			int damage = getint(p);
			int ls = getint(p);
			if (target == clientnum) {
				if (ls == player1->lifesequence)
					selfdamage(damage, cn, d);
			} else
				playsound(
				    S_PAIN1 + rnd(5), &getclient(target)->o);
			break;

		}

		case SV_DIED: {
			int actor = getint(p);
			if (actor == cn) {
				conoutf(@"%s suicided", d->name);
			} else if (actor == clientnum) {
				int frags;
				if (isteam(player1->team, d->team)) {
					frags = -1;
					conoutf(@"you fragged a teammate (%s)",
					    d->name);
				} else {
					frags = 1;
					conoutf(@"you fragged %s", d->name);

				}
				addmsg(1, 2, SV_FRAGS, player1->frags += frags);
			} else {
				dynent *a = getclient(actor);
				if (a) {
					if (isteam(a->team, d->name)) {
						conoutf(@"%s fragged his "
						        @"teammate (%s)",
						    a->name, d->name);
					} else {
						conoutf(@"%s fragged %s",
						    a->name, d->name);



					}
				}
			}
			playsound(S_DIE1 + rnd(2), &d->o);
			d->lifesequence++;
			break;

		}

		case SV_FRAGS:
			players[cn]->frags = getint(p);
			break;

		case SV_ITEMPICKUP:
			setspawn(getint(p), false);
			getint(p);
			break;

		case SV_ITEMSPAWN: {
			uint i = getint(p);
			setspawn(i, true);
			if (i >= (uint)ents.length())
				break;
			vec v = {(float)ents[i].x, (float)ents[i].y,
			    (float)ents[i].z};
			playsound(S_ITEMSPAWN, &v);
			break;

		}

		case SV_ITEMACC: // server acknowledges that I picked up this
		                 // item
			realpickup(getint(p), player1);
			break;

		case SV_EDITH: // coop editing messages, should be extended to
308
309
310
311
312
313
314
315

316
317

318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337

338
339
340
341
342
343
344
				break;
			case SV_EDITD:
				setvdeltaxy(v, b);
				break;
			case SV_EDITE:
				editequalisexy(v != 0, b);
				break;
			};

			break;
		};


		case SV_EDITENT: // coop edit of ent
		{
			uint i = getint(p);
			while ((uint)ents.length() <= i)
				ents.add().type = NOTUSED;
			int to = ents[i].type;
			ents[i].type = getint(p);
			ents[i].x = getint(p);
			ents[i].y = getint(p);
			ents[i].z = getint(p);
			ents[i].attr1 = getint(p);
			ents[i].attr2 = getint(p);
			ents[i].attr3 = getint(p);
			ents[i].attr4 = getint(p);
			ents[i].spawned = false;
			if (ents[i].type == LIGHT || to == LIGHT)
				calclight();
			break;
		};


		case SV_PING:
			getint(p);
			break;

		case SV_PONG:
			addmsg(0, 2, SV_CLIENTPING,







<
>

<
>



















<
>







308
309
310
311
312
313
314

315
316

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336

337
338
339
340
341
342
343
344
				break;
			case SV_EDITD:
				setvdeltaxy(v, b);
				break;
			case SV_EDITE:
				editequalisexy(v != 0, b);
				break;

			}
			break;

		}

		case SV_EDITENT: // coop edit of ent
		{
			uint i = getint(p);
			while ((uint)ents.length() <= i)
				ents.add().type = NOTUSED;
			int to = ents[i].type;
			ents[i].type = getint(p);
			ents[i].x = getint(p);
			ents[i].y = getint(p);
			ents[i].z = getint(p);
			ents[i].attr1 = getint(p);
			ents[i].attr2 = getint(p);
			ents[i].attr3 = getint(p);
			ents[i].attr4 = getint(p);
			ents[i].spawned = false;
			if (ents[i].type == LIGHT || to == LIGHT)
				calclight();
			break;

		}

		case SV_PING:
			getint(p);
			break;

		case SV_PONG:
			addmsg(0, 2, SV_CLIENTPING,
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371

372
373
374
375
376
377
378
379
380
381
382
383
384

385
386
387
388
389
390



		case SV_TIMEUP:
			timeupdate(getint(p));
			break;

		case SV_RECVMAP: {
			sgetstr();
			conoutf("received map \"%s\" from server, reloading..",
			    text);
			int mapsize = getint(p);
			writemap(text, mapsize, p);
			p += mapsize;
			changemapserv(text, gamemode);
			break;
		};


		case SV_SERVMSG:
			sgetstr();
			conoutf("%s", text);
			break;

		case SV_EXT: // so we can messages without breaking previous
		             // clients/servers, if necessary
		{
			for (int n = getint(p); n; n--)
				getint(p);
			break;
		};


		default:
			neterr("type");
			return;
		};
};









|






<
>



|








<
>




<
<
>
>
357
358
359
360
361
362
363
364
365
366
367
368
369
370

371
372
373
374
375
376
377
378
379
380
381
382
383

384
385
386
387
388


389
390

		case SV_TIMEUP:
			timeupdate(getint(p));
			break;

		case SV_RECVMAP: {
			sgetstr();
			conoutf(@"received map \"%s\" from server, reloading..",
			    text);
			int mapsize = getint(p);
			writemap(text, mapsize, p);
			p += mapsize;
			changemapserv(text, gamemode);
			break;

		}

		case SV_SERVMSG:
			sgetstr();
			conoutf(@"%s", text);
			break;

		case SV_EXT: // so we can messages without breaking previous
		             // clients/servers, if necessary
		{
			for (int n = getint(p); n; n--)
				getint(p);
			break;

		}

		default:
			neterr("type");
			return;


		}
}