Cube  Diff

Differences From Artifact [be4039eb8e]:

To Artifact [ffe8228e75]:


1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13
14






+







// client processing of the incoming network stream

#include "cube.h"

#import "DynamicEntity.h"
#import "Entity.h"
#import "Player.h"

extern int clientnum;
extern bool c2sinit, senditemstoserver;
extern OFString *toservermap;
extern OFString *clientpassword;

void
33
34
35
36
37
38
39

40
41
42
43
44
45
46
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48







+







// update the position of other clients in the game in our world
// don't care if he's in the scenery or other players,
// just don't overlap with our client

void
updatepos(DynamicEntity *d)
{
	Player *player1 = Player.player1;
	const float r = player1.radius + d.radius;
	const float dx = player1.origin.x - d.origin.x;
	const float dy = player1.origin.y - d.origin.y;
	const float dz = player1.origin.z - d.origin.z;
	const float rz = player1.aboveEye + d.eyeHeight;
	const float fx = (float)fabs(dx), fy = (float)fabs(dy),
	            fz = (float)fabs(dz);
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
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







+

-
+

-
+

-
+







-
+

-
-
+
+







			    getalias(nextmapalias); // look up map in the cycle
			changemap(map != nil ? map : getclientmap());
			break;
		}

		// another client either connected or changed name/team
		case SV_INITC2S: {
			Player *d_ = (Player *)d;
			sgetstr();
			if (d.name.length > 0) {
			if (d_.name.length > 0) {
				// already connected
				if (![d.name isEqual:@(text)])
				if (![d_.name isEqual:@(text)])
					conoutf(@"%@ is now known as %s",
					    d.name, text);
					    d_.name, text);
			} else {
				// new client

				// send new players my info again
				c2sinit = false;
				conoutf(@"connected: %s", text);
			}
			d.name = @(text);
			d_.name = @(text);
			sgetstr();
			d.team = @(text);
			d.lifeSequence = getint(&p);
			d_.team = @(text);
			d_.lifeSequence = getint(&p);
			break;
		}

		case SV_CDIS:
			cn = getint(&p);
			if ((d = getclient(cn)) == nil)
				break;
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
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







-
+









+


-
+


-
+


-
+


-
+

-
-
+
+

-
+










-
+

-
+







		}

		case SV_DAMAGE: {
			int target = getint(&p);
			int damage = getint(&p);
			int ls = getint(&p);
			if (target == clientnum) {
				if (ls == player1.lifeSequence)
				if (ls == Player.player1.lifeSequence)
					selfdamage(damage, cn, d);
			} else {
				OFVector3D loc = getclient(target).origin;
				playsound(S_PAIN1 + rnd(5), &loc);
			}
			break;
		}

		case SV_DIED: {
			Player *d_ = (Player *)d;
			int actor = getint(&p);
			if (actor == cn) {
				conoutf(@"%@ suicided", d.name);
				conoutf(@"%@ suicided", d_.name);
			} else if (actor == clientnum) {
				int frags;
				if (isteam(player1.team, d.team)) {
				if (isteam(Player.player1.team, d_.team)) {
					frags = -1;
					conoutf(@"you fragged a teammate (%@)",
					    d.name);
					    d_.name);
				} else {
					frags = 1;
					conoutf(@"you fragged %@", d.name);
					conoutf(@"you fragged %@", d_.name);
				}
				addmsg(
				    1, 2, SV_FRAGS, (player1.frags += frags));
				addmsg(1, 2, SV_FRAGS,
				    (Player.player1.frags += frags));
			} else {
				DynamicEntity *a = getclient(actor);
				Player *a = getclient(actor);
				if (a != nil) {
					if (isteam(a.team, d.name))
						conoutf(@"%@ fragged his "
						        @"teammate (%@)",
						    a.name, d.name);
					else
						conoutf(@"%@ fragged %@",
						    a.name, d.name);
				}
			}
			OFVector3D loc = d.origin;
			OFVector3D loc = d_.origin;
			playsound(S_DIE1 + rnd(2), &loc);
			d.lifeSequence++;
			d_.lifeSequence++;
			break;
		}

		case SV_FRAGS:
			[players[cn] setFrags:getint(&p)];
			break;

291
292
293
294
295
296
297
298

299
300
301
302
303
304
305
295
296
297
298
299
300
301

302
303
304
305
306
307
308
309







-
+







			OFVector3D v =
			    OFMakeVector3D(ents[i].x, ents[i].y, ents[i].z);
			playsound(S_ITEMSPAWN, &v);
			break;
		}
		// server acknowledges that I picked up this item
		case SV_ITEMACC:
			realpickup(getint(&p), player1);
			realpickup(getint(&p), Player.player1);
			break;

		case SV_EDITH: // coop editing messages, should be extended to
		               // include all possible editing ops
		case SV_EDITT:
		case SV_EDITS:
		case SV_EDITD:
357
358
359
360
361
362
363
364
365


366
367
368
369
370
371
372
361
362
363
364
365
366
367


368
369
370
371
372
373
374
375
376







-
-
+
+








		case SV_PING:
			getint(&p);
			break;

		case SV_PONG:
			addmsg(0, 2, SV_CLIENTPING,
			    player1.ping =
			        (player1.ping * 5 + lastmillis - getint(&p)) /
			    Player.player1.ping = (Player.player1.ping * 5 +
			                              lastmillis - getint(&p)) /
			        6);
			break;

		case SV_CLIENTPING:
			[players[cn] setPing:getint(&p)];
			break;