added r_rtworld, r_rtworldshadows, r_rtdlight, r_rtdlightshadows, and r_lightmapinten...
[xonotic/darkplaces.git] / sv_user.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 // sv_user.c -- server code for moving users
21
22 #include "quakedef.h"
23
24 edict_t *sv_player;
25
26 cvar_t sv_edgefriction = {0, "edgefriction", "2"};
27 cvar_t sv_deltacompress = {0, "sv_deltacompress", "1"};
28 cvar_t sv_idealpitchscale = {0, "sv_idealpitchscale","0.8"};
29 cvar_t sv_maxspeed = {CVAR_NOTIFY, "sv_maxspeed", "320"};
30 cvar_t sv_accelerate = {0, "sv_accelerate", "10"};
31
32 static usercmd_t cmd;
33
34
35 /*
36 ===============
37 SV_SetIdealPitch
38 ===============
39 */
40 #define MAX_FORWARD     6
41 void SV_SetIdealPitch (void)
42 {
43         float   angleval, sinval, cosval;
44         trace_t tr;
45         vec3_t  top, bottom;
46         float   z[MAX_FORWARD];
47         int             i, j;
48         int             step, dir, steps;
49
50         if (!((int)sv_player->v->flags & FL_ONGROUND))
51                 return;
52
53         angleval = sv_player->v->angles[YAW] * M_PI*2 / 360;
54         sinval = sin(angleval);
55         cosval = cos(angleval);
56
57         for (i=0 ; i<MAX_FORWARD ; i++)
58         {
59                 top[0] = sv_player->v->origin[0] + cosval*(i+3)*12;
60                 top[1] = sv_player->v->origin[1] + sinval*(i+3)*12;
61                 top[2] = sv_player->v->origin[2] + sv_player->v->view_ofs[2];
62
63                 bottom[0] = top[0];
64                 bottom[1] = top[1];
65                 bottom[2] = top[2] - 160;
66
67                 tr = SV_Move (top, vec3_origin, vec3_origin, bottom, MOVE_NOMONSTERS, sv_player);
68                 // if looking at a wall, leave ideal the way is was
69                 if (tr.startsolid)
70                         return;
71
72                 // near a dropoff
73                 if (tr.fraction == 1)
74                         return;
75
76                 z[i] = top[2] + tr.fraction*(bottom[2]-top[2]);
77         }
78
79         dir = 0;
80         steps = 0;
81         for (j=1 ; j<i ; j++)
82         {
83                 step = z[j] - z[j-1];
84                 if (step > -ON_EPSILON && step < ON_EPSILON)
85                         continue;
86
87                 // mixed changes
88                 if (dir && ( step-dir > ON_EPSILON || step-dir < -ON_EPSILON ) )
89                         return;
90
91                 steps++;
92                 dir = step;
93         }
94
95         if (!dir)
96         {
97                 sv_player->v->idealpitch = 0;
98                 return;
99         }
100
101         if (steps < 2)
102                 return;
103         sv_player->v->idealpitch = -dir * sv_idealpitchscale.value;
104 }
105
106 #if 1
107 static vec3_t wishdir, forward, right, up;
108 static float wishspeed;
109
110 static qboolean onground;
111
112 /*
113 ==================
114 SV_UserFriction
115
116 ==================
117 */
118 void SV_UserFriction (void)
119 {
120         float speed, newspeed, control, friction;
121         vec3_t start, stop;
122         trace_t trace;
123
124         speed = sqrt(sv_player->v->velocity[0]*sv_player->v->velocity[0]+sv_player->v->velocity[1]*sv_player->v->velocity[1]);
125         if (!speed)
126                 return;
127
128         // if the leading edge is over a dropoff, increase friction
129         start[0] = stop[0] = sv_player->v->origin[0] + sv_player->v->velocity[0]/speed*16;
130         start[1] = stop[1] = sv_player->v->origin[1] + sv_player->v->velocity[1]/speed*16;
131         start[2] = sv_player->v->origin[2] + sv_player->v->mins[2];
132         stop[2] = start[2] - 34;
133
134         trace = SV_Move (start, vec3_origin, vec3_origin, stop, MOVE_NOMONSTERS, sv_player);
135
136         if (trace.fraction == 1.0)
137                 friction = sv_friction.value*sv_edgefriction.value;
138         else
139                 friction = sv_friction.value;
140
141         // apply friction
142         control = speed < sv_stopspeed.value ? sv_stopspeed.value : speed;
143         newspeed = speed - sv.frametime*control*friction;
144
145         if (newspeed < 0)
146                 newspeed = 0;
147         else
148                 newspeed /= speed;
149
150         VectorScale(sv_player->v->velocity, newspeed, sv_player->v->velocity);
151 }
152
153 /*
154 ==============
155 SV_Accelerate
156 ==============
157 */
158 void SV_Accelerate (void)
159 {
160         int i;
161         float addspeed, accelspeed, currentspeed;
162
163         currentspeed = DotProduct (sv_player->v->velocity, wishdir);
164         addspeed = wishspeed - currentspeed;
165         if (addspeed <= 0)
166                 return;
167         accelspeed = sv_accelerate.value*sv.frametime*wishspeed;
168         if (accelspeed > addspeed)
169                 accelspeed = addspeed;
170
171         for (i=0 ; i<3 ; i++)
172                 sv_player->v->velocity[i] += accelspeed*wishdir[i];
173 }
174
175 void SV_AirAccelerate (vec3_t wishveloc)
176 {
177         int i;
178         float addspeed, wishspd, accelspeed, currentspeed;
179
180         wishspd = VectorNormalizeLength (wishveloc);
181         if (wishspd > 30)
182                 wishspd = 30;
183         currentspeed = DotProduct (sv_player->v->velocity, wishveloc);
184         addspeed = wishspd - currentspeed;
185         if (addspeed <= 0)
186                 return;
187         accelspeed = sv_accelerate.value*wishspeed * sv.frametime;
188         if (accelspeed > addspeed)
189                 accelspeed = addspeed;
190
191         for (i=0 ; i<3 ; i++)
192                 sv_player->v->velocity[i] += accelspeed*wishveloc[i];
193 }
194
195
196 void DropPunchAngle (void)
197 {
198         float len;
199         eval_t *val;
200
201         len = VectorNormalizeLength (sv_player->v->punchangle);
202
203         len -= 10*sv.frametime;
204         if (len < 0)
205                 len = 0;
206         VectorScale (sv_player->v->punchangle, len, sv_player->v->punchangle);
207
208         if ((val = GETEDICTFIELDVALUE(sv_player, eval_punchvector)))
209         {
210                 len = VectorNormalizeLength (val->vector);
211
212                 len -= 20*sv.frametime;
213                 if (len < 0)
214                         len = 0;
215                 VectorScale (val->vector, len, val->vector);
216         }
217 }
218
219 /*
220 ===================
221 SV_FreeMove
222 ===================
223 */
224 void SV_FreeMove (void)
225 {
226         int i;
227         float wishspeed;
228
229         AngleVectors (sv_player->v->v_angle, forward, right, up);
230
231         for (i = 0; i < 3; i++)
232                 sv_player->v->velocity[i] = forward[i] * cmd.forwardmove + right[i] * cmd.sidemove;
233
234         sv_player->v->velocity[2] += cmd.upmove;
235
236         wishspeed = VectorLength(sv_player->v->velocity);
237         if (wishspeed > sv_maxspeed.value)
238                 VectorScale(sv_player->v->velocity, sv_maxspeed.value / wishspeed, sv_player->v->velocity);
239 }
240
241 /*
242 ===================
243 SV_WaterMove
244
245 ===================
246 */
247 void SV_WaterMove (void)
248 {
249         int i;
250         vec3_t wishvel;
251         float speed, newspeed, wishspeed, addspeed, accelspeed, temp;
252
253         // user intentions
254         AngleVectors (sv_player->v->v_angle, forward, right, up);
255
256         for (i=0 ; i<3 ; i++)
257                 wishvel[i] = forward[i]*cmd.forwardmove + right[i]*cmd.sidemove;
258
259         if (!cmd.forwardmove && !cmd.sidemove && !cmd.upmove)
260                 wishvel[2] -= 60;               // drift towards bottom
261         else
262                 wishvel[2] += cmd.upmove;
263
264         wishspeed = VectorLength(wishvel);
265         if (wishspeed > sv_maxspeed.value)
266         {
267                 temp = sv_maxspeed.value/wishspeed;
268                 VectorScale (wishvel, temp, wishvel);
269                 wishspeed = sv_maxspeed.value;
270         }
271         wishspeed *= 0.7;
272
273         // water friction
274         speed = VectorLength(sv_player->v->velocity);
275         if (speed)
276         {
277                 newspeed = speed - sv.frametime * speed * sv_friction.value;
278                 if (newspeed < 0)
279                         newspeed = 0;
280                 temp = newspeed/speed;
281                 VectorScale(sv_player->v->velocity, temp, sv_player->v->velocity);
282         }
283         else
284                 newspeed = 0;
285
286         // water acceleration
287         if (!wishspeed)
288                 return;
289
290         addspeed = wishspeed - newspeed;
291         if (addspeed <= 0)
292                 return;
293
294         VectorNormalize (wishvel);
295         accelspeed = sv_accelerate.value * wishspeed * sv.frametime;
296         if (accelspeed > addspeed)
297                 accelspeed = addspeed;
298
299         for (i=0 ; i<3 ; i++)
300                 sv_player->v->velocity[i] += accelspeed * wishvel[i];
301 }
302
303 void SV_WaterJump (void)
304 {
305         if (sv.time > sv_player->v->teleport_time || !sv_player->v->waterlevel)
306         {
307                 sv_player->v->flags = (int)sv_player->v->flags & ~FL_WATERJUMP;
308                 sv_player->v->teleport_time = 0;
309         }
310         sv_player->v->velocity[0] = sv_player->v->movedir[0];
311         sv_player->v->velocity[1] = sv_player->v->movedir[1];
312 }
313
314
315 /*
316 ===================
317 SV_AirMove
318
319 ===================
320 */
321 void SV_AirMove (void)
322 {
323         int i;
324         vec3_t wishvel;
325         float fmove, smove, temp;
326
327         // LordHavoc: correct quake movement speed bug when looking up/down
328         wishvel[0] = wishvel[2] = 0;
329         wishvel[1] = sv_player->v->angles[1];
330         AngleVectors (wishvel, forward, right, up);
331
332         fmove = cmd.forwardmove;
333         smove = cmd.sidemove;
334
335 // hack to not let you back into teleporter
336         if (sv.time < sv_player->v->teleport_time && fmove < 0)
337                 fmove = 0;
338
339         for (i=0 ; i<3 ; i++)
340                 wishvel[i] = forward[i]*fmove + right[i]*smove;
341
342         if ((int)sv_player->v->movetype != MOVETYPE_WALK)
343                 wishvel[2] += cmd.upmove;
344
345         VectorCopy (wishvel, wishdir);
346         wishspeed = VectorNormalizeLength(wishdir);
347         if (wishspeed > sv_maxspeed.value)
348         {
349                 temp = sv_maxspeed.value/wishspeed;
350                 VectorScale (wishvel, temp, wishvel);
351                 wishspeed = sv_maxspeed.value;
352         }
353
354         if (sv_player->v->movetype == MOVETYPE_NOCLIP)
355         {
356                 // noclip
357                 VectorCopy (wishvel, sv_player->v->velocity);
358         }
359         else if ( onground )
360         {
361                 SV_UserFriction ();
362                 SV_Accelerate ();
363         }
364         else
365         {
366                 // not on ground, so little effect on velocity
367                 SV_AirAccelerate (wishvel);
368         }
369 }
370
371 /*
372 ===================
373 SV_ClientThink
374
375 the move fields specify an intended velocity in pix/sec
376 the angle fields specify an exact angular motion in degrees
377 ===================
378 */
379 void SV_ClientThink (void)
380 {
381         vec3_t v_angle;
382
383         if (sv_player->v->movetype == MOVETYPE_NONE)
384                 return;
385
386         onground = (int)sv_player->v->flags & FL_ONGROUND;
387
388         DropPunchAngle ();
389
390         // if dead, behave differently
391         if (sv_player->v->health <= 0)
392                 return;
393
394         cmd = host_client->cmd;
395
396         // angles
397         // show 1/3 the pitch angle and all the roll angle
398         VectorAdd (sv_player->v->v_angle, sv_player->v->punchangle, v_angle);
399         sv_player->v->angles[ROLL] = V_CalcRoll (sv_player->v->angles, sv_player->v->velocity)*4;
400         if (!sv_player->v->fixangle)
401         {
402                 sv_player->v->angles[PITCH] = -v_angle[PITCH]/3;
403                 sv_player->v->angles[YAW] = v_angle[YAW];
404         }
405
406         if ( (int)sv_player->v->flags & FL_WATERJUMP )
407         {
408                 SV_WaterJump ();
409                 return;
410         }
411
412         /*
413         // Player is (somehow) outside of the map, or flying, or noclipping
414         if (sv_player->v->movetype != MOVETYPE_NOCLIP && (sv_player->v->movetype == MOVETYPE_FLY || SV_TestEntityPosition (sv_player)))
415         //if (sv_player->v->movetype == MOVETYPE_NOCLIP || sv_player->v->movetype == MOVETYPE_FLY || SV_TestEntityPosition (sv_player))
416         {
417                 SV_FreeMove ();
418                 return;
419         }
420         */
421
422         // walk
423         if ((sv_player->v->waterlevel >= 2) && (sv_player->v->movetype != MOVETYPE_NOCLIP))
424         {
425                 SV_WaterMove ();
426                 return;
427         }
428
429         SV_AirMove ();
430 }
431
432 #else
433
434 extern cvar_t cl_rollspeed;
435 extern cvar_t cl_rollangle;
436 void SV_ClientThink(void)
437 {
438         int j;
439         vec3_t wishvel, wishdir, v, v_forward, v_right, v_up, start, stop;
440         float wishspeed, f, limit;
441         trace_t trace;
442
443         if (sv_player->v->movetype == MOVETYPE_NONE)
444                 return;
445
446         f = DotProduct(sv_player->v->punchangle, sv_player->v->punchangle);
447         if (f)
448         {
449                 limit = sqrt(f);
450                 f = (limit - 10 * sv.frametime);
451                 f /= limit;
452                 f = max(0, f);
453                 VectorScale(sv_player->v->punchangle, f, sv_player->v->punchangle);
454         }
455
456         // if dead, behave differently
457         if (sv_player->v->health <= 0)
458                 return;
459
460         AngleVectors(sv_player->v->v_angle, v_forward, v_right, v_up);
461         // show 1/3 the pitch angle and all the roll angle
462         f = DotProduct(sv_player->v->velocity, v_right) * (1.0 / cl_rollspeed.value);
463         sv_player->v->angles[2] = bound(-1, f, 1) * cl_rollangle.value * 4;
464         if (!sv_player->v->fixangle)
465         {
466                 sv_player->v->angles[0] = (sv_player->v->v_angle[0] + sv_player->v->punchangle[0]) * -0.333;
467                 sv_player->v->angles[1] = sv_player->v->v_angle[1] + sv_player->v->punchangle[1];
468         }
469
470         if ((int)sv_player->v->flags & FL_WATERJUMP)
471         {
472                 sv_player->v->velocity[0] = sv_player->v->movedir[0];
473                 sv_player->v->velocity[1] = sv_player->v->movedir[1];
474                 if (sv.time > sv_player->v->teleport_time || sv_player->v->waterlevel == 0)
475                 {
476                         sv_player->v->flags = (int)sv_player->v->flags - ((int)sv_player->v->flags & FL_WATERJUMP);
477                         sv_player->v->teleport_time = 0;
478                 }
479                 return;
480         }
481
482         // swim
483         if (sv_player->v->waterlevel >= 2)
484         if (sv_player->v->movetype != MOVETYPE_NOCLIP)
485         {
486                 if (host_client->cmd.forwardmove == 0 && host_client->cmd.sidemove == 0 && host_client->cmd.upmove == 0)
487                 {
488                         // drift towards bottom
489                         wishvel[0] = 0;
490                         wishvel[1] = 0;
491                         wishvel[2] = -60;
492                 }
493                 else
494                 {
495                         for (j = 0;j < 3;j++)
496                                 wishvel[j] = v_forward[j] * host_client->cmd.forwardmove + v_right[j] * host_client->cmd.sidemove;
497                         wishvel[2] += host_client->cmd.upmove;
498                 }
499
500                 wishspeed = VectorLength(wishvel);
501                 wishspeed = min(wishspeed, sv_maxspeed.value) * 0.7;
502
503                 // water friction
504                 f = VectorLength(sv_player->v->velocity) * (1 - sv.frametime * sv_friction.value);
505                 if (f > 0)
506                         f /= VectorLength(sv_player->v->velocity);
507                 else
508                         f = 0;
509                 VectorScale(sv_player->v->velocity, f, sv_player->v->velocity);
510
511                 // water acceleration
512                 if (wishspeed <= f)
513                         return;
514
515                 f = wishspeed - f;
516                 limit = sv_accelerate.value * wishspeed * sv.frametime;
517                 if (f > limit)
518                         f = limit;
519                 limit = VectorLength(wishvel);
520                 if (limit)
521                         f /= limit;
522                 VectorMA(sv_player->v->velocity, f, wishvel, sv_player->v->velocity);
523                 return;
524         }
525
526         // if not flying, move horizontally only
527         if (sv_player->v->movetype != MOVETYPE_FLY)
528         {
529                 VectorClear(wishvel);
530                 wishvel[1] = sv_player->v->v_angle[1];
531                 AngleVectors(wishvel, v_forward, v_right, v_up);
532         }
533
534         // hack to not let you back into teleporter
535         VectorScale(v_right, host_client->cmd.sidemove, wishvel);
536         if (sv.time >= sv_player->v->teleport_time || host_client->cmd.forwardmove > 0)
537                 VectorMA(wishvel, host_client->cmd.forwardmove, v_forward, wishvel);
538         if (sv_player->v->movetype != MOVETYPE_WALK)
539                 wishvel[2] += cmd.upmove;
540
541         VectorCopy(wishvel, wishdir);
542         VectorNormalize(wishdir);
543         wishspeed = VectorLength(wishvel);
544         if (wishspeed > sv_maxspeed.value)
545                 wishspeed = sv_maxspeed.value;
546
547         if (sv_player->v->movetype == MOVETYPE_NOCLIP || sv_player->v->movetype == MOVETYPE_FLY)
548         {
549                 VectorScale(wishdir, wishspeed, sv_player->v->velocity);
550                 return;
551         }
552
553         if ((int)sv_player->v->flags & FL_ONGROUND) // walking
554         {
555                 // friction
556                 f = sv_player->v->velocity[0] * sv_player->v->velocity[0] + sv_player->v->velocity[1] * sv_player->v->velocity[1];
557                 if (f)
558                 {
559                         f = sqrt(f);
560                         VectorCopy(sv_player->v->velocity, v);
561                         v[2] = 0;
562
563                         // if the leading edge is over a dropoff, increase friction
564                         limit = 16.0f / f;
565                         VectorMA(sv_player->v->origin, limit, v, v);
566                         v[2] += sv_player->v->mins[2];
567
568                         VectorCopy(v, start);
569                         VectorCopy(v, stop);
570                         stop[2] -= 34;
571                         trace = SV_Move(start, vec3_origin, vec3_origin, stop, MOVE_NOMONSTERS, sv_player);
572
573                         // apply friction
574                         if (f < sv_stopspeed.value)
575                                 f = sv_stopspeed.value / f;
576                         else
577                                 f = 1;
578                         if (trace.fraction == 1)
579                                 f *= sv_edgefriction.value;
580                         f = 1 - sv.frametime * f * sv_friction.value;
581
582                         if (f < 0)
583                                 f = 0;
584                         VectorScale(sv_player->v->velocity, f, sv_player->v->velocity);
585                 }
586         }
587         else // airborn
588                 wishspeed = min(wishspeed, 30);
589
590         // ground or air acceleration
591         f = wishspeed - DotProduct(sv_player->v->velocity, wishdir);
592         if (f > 0)
593         {
594                 limit = sv_accelerate.value * sv.frametime * wishspeed;
595                 if (f > limit)
596                         f = limit;
597                 VectorMA(sv_player->v->velocity, f, wishdir, sv_player->v->velocity);
598         }
599 }
600 #endif
601
602 /*
603 ===================
604 SV_ReadClientMove
605 ===================
606 */
607 void SV_ReadClientMove (usercmd_t *move)
608 {
609         int i;
610         vec3_t angle;
611         int bits;
612         eval_t *val;
613         float total;
614
615         // read ping time
616         if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
617         host_client->ping_times[host_client->num_pings % NUM_PING_TIMES] = sv.time - MSG_ReadFloat ();
618         if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
619         host_client->num_pings++;
620         for (i=0, total = 0;i < NUM_PING_TIMES;i++)
621                 total += host_client->ping_times[i];
622         // can be used for prediction
623         host_client->ping = total / NUM_PING_TIMES;
624         if ((val = GETEDICTFIELDVALUE(sv_player, eval_ping)))
625                 val->_float = host_client->ping * 1000.0;
626
627         // read current angles
628         for (i = 0;i < 3;i++)
629         {
630                 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
631                 if (sv.protocol == PROTOCOL_QUAKE)
632                         angle[i] = MSG_ReadAngle8i();
633                 else if (sv.protocol == PROTOCOL_DARKPLACES2 || sv.protocol == PROTOCOL_DARKPLACES3)
634                         angle[i] = MSG_ReadAngle32f();
635                 else if (sv.protocol == PROTOCOL_DARKPLACES1 || sv.protocol == PROTOCOL_DARKPLACES4 || sv.protocol == PROTOCOL_DARKPLACES5)
636                         angle[i] = MSG_ReadAngle16i();
637                 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
638         }
639
640         VectorCopy (angle, sv_player->v->v_angle);
641
642         // read movement
643         if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
644         move->forwardmove = MSG_ReadCoord16i ();
645         if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
646         move->sidemove = MSG_ReadCoord16i ();
647         if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
648         move->upmove = MSG_ReadCoord16i ();
649         if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
650         if ((val = GETEDICTFIELDVALUE(sv_player, eval_movement)))
651         {
652                 val->vector[0] = move->forwardmove;
653                 val->vector[1] = move->sidemove;
654                 val->vector[2] = move->upmove;
655         }
656
657         // read buttons
658         bits = MSG_ReadByte ();
659         if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
660         sv_player->v->button0 = bits & 1;
661         sv_player->v->button2 = (bits & 2)>>1;
662         // LordHavoc: added 6 new buttons
663         if ((val = GETEDICTFIELDVALUE(sv_player, eval_button3))) val->_float = ((bits >> 2) & 1);
664         if ((val = GETEDICTFIELDVALUE(sv_player, eval_button4))) val->_float = ((bits >> 3) & 1);
665         if ((val = GETEDICTFIELDVALUE(sv_player, eval_button5))) val->_float = ((bits >> 4) & 1);
666         if ((val = GETEDICTFIELDVALUE(sv_player, eval_button6))) val->_float = ((bits >> 5) & 1);
667         if ((val = GETEDICTFIELDVALUE(sv_player, eval_button7))) val->_float = ((bits >> 6) & 1);
668         if ((val = GETEDICTFIELDVALUE(sv_player, eval_button8))) val->_float = ((bits >> 7) & 1);
669
670         i = MSG_ReadByte ();
671         if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
672         if (i)
673                 sv_player->v->impulse = i;
674 }
675
676 /*
677 ===================
678 SV_ReadClientMessage
679 ===================
680 */
681 extern void SV_SendServerinfo(client_t *client);
682 void SV_ReadClientMessage(void)
683 {
684         int cmd, num;
685         char *s;
686
687         //MSG_BeginReading ();
688
689         for(;;)
690         {
691                 if (!host_client->active)
692                 {
693                         // a command caused an error
694                         SV_DropClient (false);
695                         return;
696                 }
697
698                 if (msg_badread)
699                 {
700                         Con_Print("SV_ReadClientMessage: badread\n");
701                         SV_DropClient (false);
702                         return;
703                 }
704
705                 cmd = MSG_ReadChar ();
706                 if (cmd == -1)
707                 {
708                         // end of message
709                         break;
710                 }
711
712                 switch (cmd)
713                 {
714                 default:
715                         Con_Printf("SV_ReadClientMessage: unknown command char %i\n", cmd);
716                         SV_DropClient (false);
717                         return;
718
719                 case clc_nop:
720                         break;
721
722                 case clc_stringcmd:
723                         s = MSG_ReadString ();
724                         if (strncasecmp(s, "spawn", 5) == 0
725                          || strncasecmp(s, "begin", 5) == 0
726                          || strncasecmp(s, "prespawn", 8) == 0)
727                                 Cmd_ExecuteString (s, src_client);
728                         else if (SV_ParseClientCommandQC)
729                         {
730                                 G_INT(OFS_PARM0) = PR_SetString(s);
731                                 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
732                                 PR_ExecuteProgram ((func_t)(SV_ParseClientCommandQC - pr_functions), "");
733                         }
734                         else if (strncasecmp(s, "status", 6) == 0
735                          || strncasecmp(s, "name", 4) == 0
736                          || strncasecmp(s, "say", 3) == 0
737                          || strncasecmp(s, "say_team", 8) == 0
738                          || strncasecmp(s, "tell", 4) == 0
739                          || strncasecmp(s, "color", 5) == 0
740                          || strncasecmp(s, "kill", 4) == 0
741                          || strncasecmp(s, "pause", 5) == 0
742                          || strncasecmp(s, "kick", 4) == 0
743                          || strncasecmp(s, "ping", 4) == 0
744                          || strncasecmp(s, "ban", 3) == 0
745                          || strncasecmp(s, "pmodel", 6) == 0
746                          || strncasecmp(s, "rate", 4) == 0
747                          || (gamemode == GAME_NEHAHRA && (strncasecmp(s, "max", 3) == 0 || strncasecmp(s, "monster", 7) == 0 || strncasecmp(s, "scrag", 5) == 0 || strncasecmp(s, "gimme", 5) == 0 || strncasecmp(s, "wraith", 6) == 0))
748                          || (gamemode != GAME_NEHAHRA && (strncasecmp(s, "god", 3) == 0 || strncasecmp(s, "notarget", 8) == 0 || strncasecmp(s, "fly", 3) == 0 || strncasecmp(s, "give", 4) == 0 || strncasecmp(s, "noclip", 6) == 0)))
749                                 Cmd_ExecuteString (s, src_client);
750                         else
751                                 Con_Printf("%s tried to %s\n", host_client->name, s);
752                         break;
753
754                 case clc_disconnect:
755                         SV_DropClient (false); // client wants to disconnect
756                         return;
757
758                 case clc_move:
759                         SV_ReadClientMove (&host_client->cmd);
760                         break;
761
762                 case clc_ackentities:
763                         if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
764                         num = MSG_ReadLong();
765                         if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
766                         if (developer_networkentities.integer >= 1)
767                                 Con_Printf("recv clc_ackentities %i\n", num);
768                         if (host_client->entitydatabase)
769                                 EntityFrame_AckFrame(host_client->entitydatabase, num);
770                         else if (host_client->entitydatabase4)
771                                 EntityFrame4_AckFrame(host_client->entitydatabase4, host_client->entitydatabase4->ackframenum, true);
772                         else if (host_client->entitydatabase5)
773                                 EntityFrame5_AckFrame(host_client->entitydatabase5, num, host_client - svs.clients + 1);
774                         break;
775                 }
776         }
777 }
778
779 /*
780 ==================
781 SV_RunClients
782 ==================
783 */
784 void SV_RunClients (void)
785 {
786         int i;
787
788         for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
789         {
790                 if (!host_client->active)
791                         continue;
792
793                 if (!host_client->spawned)
794                 {
795                         // clear client movement until a new packet is received
796                         memset (&host_client->cmd, 0, sizeof(host_client->cmd));
797                         continue;
798                 }
799
800                 if (sv.frametime)
801                 {
802                         sv_player = host_client->edict;
803
804                         // LordHavoc: QuakeC replacement for SV_ClientThink (player movement)
805                         if (SV_PlayerPhysicsQC)
806                         {
807                                 pr_global_struct->time = sv.time;
808                                 pr_global_struct->self = EDICT_TO_PROG(sv_player);
809                                 PR_ExecuteProgram ((func_t)(SV_PlayerPhysicsQC - pr_functions), "");
810                         }
811                         else
812                                 SV_ClientThink ();
813
814                         SV_CheckVelocity(sv_player);
815
816                         // LordHavoc: a hack to ensure that the (rather silly) id1 quakec
817                         // player_run/player_stand1 does not horribly malfunction if the
818                         // velocity becomes a number that is both == 0 and != 0
819                         // (sounds to me like NaN but to be absolutely safe...)
820                         if (DotProduct(sv_player->v->velocity, sv_player->v->velocity) < 0.0001)
821                                 VectorClear(sv_player->v->velocity);
822                 }
823         }
824 }
825