Cube  Diff

Differences From Artifact [e5e63c92dd]:

To Artifact [ef18048f8b]:


1
2
3
4


5
6
7
8
9
10
11
// client processing of the incoming network stream

#include "cube.h"



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

void
neterr(OFString *s)




>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
// client processing of the incoming network stream

#include "cube.h"

#import "DynamicEntity.h"

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

void
neterr(OFString *s)
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
}

// 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(dynent *d)
{
	const float r = player1->radius + d->radius;
	const float dx = player1->o.x - d->o.x;
	const float dy = player1->o.y - d->o.y;
	const float dz = player1->o.z - d->o.z;
	const float rz = player1->aboveeye + d->eyeheight;
	const float fx = (float)fabs(dx), fy = (float)fabs(dy),
	            fz = (float)fabs(dz);
	if (fx < r && fy < r && fz < rz && d->state != CS_DEAD) {
		if (fx < fy)


			d->o.y += dy < 0 ? r - fy : -(r - fy); // push aside
		else

			d->o.x += dx < 0 ? r - fx : -(r - fx);

	}
	int lagtime = lastmillis - d->lastupdate;
	if (lagtime) {
		d->plag = (d->plag * 5 + lagtime) / 6;
		d->lastupdate = lastmillis;
	}
}


void
localservertoclient(
    uchar *buf, int len) // processes any updates from the server
{
	if (ENET_NET_TO_HOST_16(*(ushort *)buf) != len)
		neterr(@"packet length");
	incomingdemodata(buf, len);

	uchar *end = buf + len;
	uchar *p = buf + 2;
	char text[MAXTRANS];
	int cn = -1, type;
	dynent *d = NULL;
	bool mapchanged = false;

	while (p < end)
		switch (type = getint(p)) {
		case SV_INITS2C: // welcome messsage from the server
		{
			cn = getint(p);







|

|
|
|
|
|


|

>
>
|

>
|
>

|

|
|



>

|
<









|







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
}

// 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)
{
	const float r = player1.radius + d.radius;
	const float dx = player1.o.x - d.o.x;
	const float dy = player1.o.y - d.o.y;
	const float dz = player1.o.z - d.o.z;
	const float rz = player1.aboveeye + d.eyeheight;
	const float fx = (float)fabs(dx), fy = (float)fabs(dy),
	            fz = (float)fabs(dz);
	if (fx < r && fy < r && fz < rz && d.state != CS_DEAD) {
		if (fx < fy)
			// push aside
			d.o = OFMakeVector3D(d.o.x,
			    d.o.y + (dy < 0 ? r - fy : -(r - fy)), d.o.z);
		else
			d.o = OFMakeVector3D(
			    d.o.x + (dx < 0 ? r - fx : -(r - fx)), d.o.y,
			    d.o.z);
	}
	int lagtime = lastmillis - d.lastupdate;
	if (lagtime) {
		d.plag = (d.plag * 5 + lagtime) / 6;
		d.lastupdate = lastmillis;
	}
}

// processes any updates from the server
void
localservertoclient(uchar *buf, int len)

{
	if (ENET_NET_TO_HOST_16(*(ushort *)buf) != len)
		neterr(@"packet length");
	incomingdemodata(buf, len);

	uchar *end = buf + len;
	uchar *p = buf + 2;
	char text[MAXTRANS];
	int cn = -1, type;
	DynamicEntity *d = nil;
	bool mapchanged = false;

	while (p < end)
		switch (type = getint(p)) {
		case SV_INITS2C: // welcome messsage from the server
		{
			cn = getint(p);
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
				}
			}
			if (getint(p) == 1)
				conoutf(@"server is FULL, disconnecting..");
			break;
		}


		case SV_POS: // position of another client
		{
			cn = getint(p);
			d = getclient(cn);
			if (!d)
				return;
			d->o.x = getint(p) / DMF;
			d->o.y = getint(p) / DMF;
			d->o.z = getint(p) / DMF;
			d->yaw = getint(p) / DAF;
			d->pitch = getint(p) / DAF;
			d->roll = getint(p) / DAF;
			d->vel.x = getint(p) / DVF;
			d->vel.y = getint(p) / DVF;
			d->vel.z = getint(p) / DVF;
			int f = getint(p);
			d->strafe = (f & 3) == 3 ? -1 : f & 3;
			f >>= 2;
			d->move = (f & 3) == 3 ? -1 : f & 3;
			d->onfloor = (f >> 2) & 1;
			int state = f >> 3;
			if (state == CS_DEAD && d->state != CS_DEAD)
				d->lastaction = lastmillis;
			d->state = state;
			if (!demoplayback)
				updatepos(d);
			break;
		}

		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();
			@autoreleasepool {
				changemapserv(@(text), getint(p));
			}







>
|
<


|

|
|
<
|
|
|
|
|
<

|

|
|

|
|
|





|
>
|

>



|







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
				}
			}
			if (getint(p) == 1)
				conoutf(@"server is FULL, disconnecting..");
			break;
		}

		case SV_POS: {
			// position of another client

			cn = getint(p);
			d = getclient(cn);
			if (d == nil)
				return;
			d.o = OFMakeVector3D(
			    getint(p) / DMF, getint(p) / DMF, getint(p) / DMF);

			d.yaw = getint(p) / DAF;
			d.pitch = getint(p) / DAF;
			d.roll = getint(p) / DAF;
			d.vel = OFMakeVector3D(
			    getint(p) / DVF, getint(p) / DVF, getint(p) / DVF);

			int f = getint(p);
			d.strafe = (f & 3) == 3 ? -1 : f & 3;
			f >>= 2;
			d.move = (f & 3) == 3 ? -1 : f & 3;
			d.onfloor = (f >> 2) & 1;
			int state = f >> 3;
			if (state == CS_DEAD && d.state != CS_DEAD)
				d.lastaction = lastmillis;
			d.state = state;
			if (!demoplayback)
				updatepos(d);
			break;
		}

		case SV_SOUND: {
			OFVector3D loc = d.o;
			playsound(getint(p), &loc);
			break;
		}

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

		case SV_MAPCHANGE:
			sgetstr();
			@autoreleasepool {
				changemapserv(@(text), getint(p));
			}
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
			    stringWithFormat:@"nextmap_%@", getclientmap()];
			OFString *map =
			    getalias(nextmapalias); // look up map in the cycle
			changemap(map != nil ? 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);
			OFVector3D s, e;
			s.x = getint(p) / DMF;
			s.y = getint(p) / DMF;







|
|
<

|

|
|
|


|
|
>


|

|
|





|

|
|
|







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
			    stringWithFormat:@"nextmap_%@", getclientmap()];
			OFString *map =
			    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: {

			sgetstr();
			if (d.name.length > 0) {
				// already connected
				if (![d.name isEqual:@(text)])
					conoutf(@"%@ is now known as %s",
					    d.name, text);
			} else {
				// new client

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

		case SV_CDIS:
			cn = getint(p);
			if ((d = getclient(cn)) == nil)
				break;
			conoutf(@"player %@ disconnected",
			    d.name.length ? d.name : @"[incompatible client]");
			players[cn] = [OFNull null];
			break;

		case SV_SHOT: {
			int gun = getint(p);
			OFVector3D s, e;
			s.x = getint(p) / DMF;
			s.y = getint(p) / DMF;
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
		}

		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;








|

|
>
|
<
>






|


|

|
|


|

|
>

|
|
|
|
|
|
|
|
|
|
|
<
>
|
|




|







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
		}

		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 {
				OFVector3D loc = getclient(target).o;
				playsound(S_PAIN1 + rnd(5), &loc);

			}
			break;
		}

		case SV_DIED: {
			int actor = getint(p);
			if (actor == cn) {
				conoutf(@"%@ suicided", d.name);
			} else if (actor == clientnum) {
				int frags;
				if (isteam(player1.team, d.team)) {
					frags = -1;
					conoutf(@"you fragged a teammate (%@)",
					    d.name);
				} else {
					frags = 1;
					conoutf(@"you fragged %@", d.name);
				}
				addmsg(
				    1, 2, SV_FRAGS, (player1.frags += frags));
			} else {
				DynamicEntity *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.o;
			playsound(S_DIE1 + rnd(2), &loc);
			d.lifesequence++;
			break;
		}

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

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

344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364

		case SV_PING:
			getint(p);
			break;

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

		case SV_CLIENTPING:
			players[cn]->ping = getint(p);
			break;

		case SV_GAMEMODE:
			nextmode = getint(p);
			break;

		case SV_TIMEUP:







|
|




|







352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372

		case SV_PING:
			getint(p);
			break;

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

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

		case SV_GAMEMODE:
			nextmode = getint(p);
			break;

		case SV_TIMEUP: