2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
20 // sv_user.c -- server code for moving users
33 void SV_SetIdealPitch (void)
35 float angleval, sinval, cosval, step, dir;
42 if (!((int)host_client->edict->fields.server->flags & FL_ONGROUND))
45 angleval = host_client->edict->fields.server->angles[YAW] * M_PI*2 / 360;
46 sinval = sin(angleval);
47 cosval = cos(angleval);
49 for (i=0 ; i<MAX_FORWARD ; i++)
51 top[0] = host_client->edict->fields.server->origin[0] + cosval*(i+3)*12;
52 top[1] = host_client->edict->fields.server->origin[1] + sinval*(i+3)*12;
53 top[2] = host_client->edict->fields.server->origin[2] + host_client->edict->fields.server->view_ofs[2];
57 bottom[2] = top[2] - 160;
59 tr = SV_Move (top, vec3_origin, vec3_origin, bottom, MOVE_NOMONSTERS, host_client->edict, SUPERCONTENTS_SOLID);
60 // if looking at a wall, leave ideal the way is was
68 z[i] = top[2] + tr.fraction*(bottom[2]-top[2]);
76 if (step > -ON_EPSILON && step < ON_EPSILON)
80 if (dir && ( step-dir > ON_EPSILON || step-dir < -ON_EPSILON ) )
89 host_client->edict->fields.server->idealpitch = 0;
95 host_client->edict->fields.server->idealpitch = -dir * sv_idealpitchscale.value;
98 static vec3_t wishdir, forward, right, up;
99 static float wishspeed;
101 static qboolean onground;
109 void SV_UserFriction (void)
111 float speed, newspeed, control, friction;
115 speed = sqrt(host_client->edict->fields.server->velocity[0]*host_client->edict->fields.server->velocity[0]+host_client->edict->fields.server->velocity[1]*host_client->edict->fields.server->velocity[1]);
119 // if the leading edge is over a dropoff, increase friction
120 start[0] = stop[0] = host_client->edict->fields.server->origin[0] + host_client->edict->fields.server->velocity[0]/speed*16;
121 start[1] = stop[1] = host_client->edict->fields.server->origin[1] + host_client->edict->fields.server->velocity[1]/speed*16;
122 start[2] = host_client->edict->fields.server->origin[2] + host_client->edict->fields.server->mins[2];
123 stop[2] = start[2] - 34;
125 trace = SV_Move (start, vec3_origin, vec3_origin, stop, MOVE_NOMONSTERS, host_client->edict, SV_GenericHitSuperContentsMask(host_client->edict));
127 if (trace.fraction == 1.0)
128 friction = sv_friction.value*sv_edgefriction.value;
130 friction = sv_friction.value;
133 control = speed < sv_stopspeed.value ? sv_stopspeed.value : speed;
134 newspeed = speed - sv.frametime*control*friction;
141 VectorScale(host_client->edict->fields.server->velocity, newspeed, host_client->edict->fields.server->velocity);
149 void SV_Accelerate (void)
152 float addspeed, accelspeed, currentspeed;
154 currentspeed = DotProduct (host_client->edict->fields.server->velocity, wishdir);
155 addspeed = wishspeed - currentspeed;
158 accelspeed = sv_accelerate.value*sv.frametime*wishspeed;
159 if (accelspeed > addspeed)
160 accelspeed = addspeed;
162 for (i=0 ; i<3 ; i++)
163 host_client->edict->fields.server->velocity[i] += accelspeed*wishdir[i];
166 void SV_AirAccelerate (vec3_t wishveloc)
169 float addspeed, wishspd, accelspeed, currentspeed;
171 wishspd = VectorNormalizeLength (wishveloc);
172 if (wishspd > sv_maxairspeed.value)
173 wishspd = sv_maxairspeed.value;
174 currentspeed = DotProduct (host_client->edict->fields.server->velocity, wishveloc);
175 addspeed = wishspd - currentspeed;
178 accelspeed = (sv_airaccelerate.value < 0 ? sv_accelerate.value : sv_airaccelerate.value)*wishspeed * sv.frametime;
179 if (accelspeed > addspeed)
180 accelspeed = addspeed;
182 for (i=0 ; i<3 ; i++)
183 host_client->edict->fields.server->velocity[i] += accelspeed*wishveloc[i];
187 void DropPunchAngle (void)
192 len = VectorNormalizeLength (host_client->edict->fields.server->punchangle);
194 len -= 10*sv.frametime;
197 VectorScale (host_client->edict->fields.server->punchangle, len, host_client->edict->fields.server->punchangle);
199 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.punchvector)))
201 len = VectorNormalizeLength (val->vector);
203 len -= 20*sv.frametime;
206 VectorScale (val->vector, len, val->vector);
215 void SV_FreeMove (void)
220 AngleVectors (host_client->edict->fields.server->v_angle, forward, right, up);
222 for (i = 0; i < 3; i++)
223 host_client->edict->fields.server->velocity[i] = forward[i] * cmd.forwardmove + right[i] * cmd.sidemove;
225 host_client->edict->fields.server->velocity[2] += cmd.upmove;
227 wishspeed = VectorLength(host_client->edict->fields.server->velocity);
228 if (wishspeed > sv_maxspeed.value)
229 VectorScale(host_client->edict->fields.server->velocity, sv_maxspeed.value / wishspeed, host_client->edict->fields.server->velocity);
238 void SV_WaterMove (void)
242 float speed, newspeed, wishspeed, addspeed, accelspeed, temp;
245 AngleVectors (host_client->edict->fields.server->v_angle, forward, right, up);
247 for (i=0 ; i<3 ; i++)
248 wishvel[i] = forward[i]*cmd.forwardmove + right[i]*cmd.sidemove;
250 if (!cmd.forwardmove && !cmd.sidemove && !cmd.upmove)
251 wishvel[2] -= 60; // drift towards bottom
253 wishvel[2] += cmd.upmove;
255 wishspeed = VectorLength(wishvel);
256 if (wishspeed > sv_maxspeed.value)
258 temp = sv_maxspeed.value/wishspeed;
259 VectorScale (wishvel, temp, wishvel);
260 wishspeed = sv_maxspeed.value;
265 speed = VectorLength(host_client->edict->fields.server->velocity);
268 newspeed = speed - sv.frametime * speed * (sv_waterfriction.value < 0 ? sv_friction.value : sv_waterfriction.value);
271 temp = newspeed/speed;
272 VectorScale(host_client->edict->fields.server->velocity, temp, host_client->edict->fields.server->velocity);
277 // water acceleration
281 addspeed = wishspeed - newspeed;
285 VectorNormalize (wishvel);
286 accelspeed = (sv_wateraccelerate.value < 0 ? sv_accelerate.value : sv_wateraccelerate.value) * wishspeed * sv.frametime;
287 if (accelspeed > addspeed)
288 accelspeed = addspeed;
290 for (i=0 ; i<3 ; i++)
291 host_client->edict->fields.server->velocity[i] += accelspeed * wishvel[i];
294 void SV_WaterJump (void)
296 if (sv.time > host_client->edict->fields.server->teleport_time || !host_client->edict->fields.server->waterlevel)
298 host_client->edict->fields.server->flags = (int)host_client->edict->fields.server->flags & ~FL_WATERJUMP;
299 host_client->edict->fields.server->teleport_time = 0;
301 host_client->edict->fields.server->velocity[0] = host_client->edict->fields.server->movedir[0];
302 host_client->edict->fields.server->velocity[1] = host_client->edict->fields.server->movedir[1];
312 void SV_AirMove (void)
316 float fmove, smove, temp;
318 // LordHavoc: correct quake movement speed bug when looking up/down
319 wishvel[0] = wishvel[2] = 0;
320 wishvel[1] = host_client->edict->fields.server->angles[1];
321 AngleVectors (wishvel, forward, right, up);
323 fmove = cmd.forwardmove;
324 smove = cmd.sidemove;
326 // hack to not let you back into teleporter
327 if (sv.time < host_client->edict->fields.server->teleport_time && fmove < 0)
330 for (i=0 ; i<3 ; i++)
331 wishvel[i] = forward[i]*fmove + right[i]*smove;
333 if ((int)host_client->edict->fields.server->movetype != MOVETYPE_WALK)
334 wishvel[2] += cmd.upmove;
336 VectorCopy (wishvel, wishdir);
337 wishspeed = VectorNormalizeLength(wishdir);
338 if (wishspeed > sv_maxspeed.value)
340 temp = sv_maxspeed.value/wishspeed;
341 VectorScale (wishvel, temp, wishvel);
342 wishspeed = sv_maxspeed.value;
345 if (host_client->edict->fields.server->movetype == MOVETYPE_NOCLIP)
348 VectorCopy (wishvel, host_client->edict->fields.server->velocity);
350 else if (onground && (!sv_gameplayfix_qwplayerphysics.integer || !(host_client->edict->fields.server->button2 || !((int)host_client->edict->fields.server->flags & FL_JUMPRELEASED))))
357 // not on ground, so little effect on velocity
358 SV_AirAccelerate (wishvel);
366 the move fields specify an intended velocity in pix/sec
367 the angle fields specify an exact angular motion in degrees
370 void SV_ClientThink (void)
374 SV_ApplyClientMove();
375 // make sure the velocity is sane (not a NaN)
376 SV_CheckVelocity(host_client->edict);
378 // LordHavoc: QuakeC replacement for SV_ClientThink (player movement)
379 if (prog->funcoffsets.SV_PlayerPhysics && sv_playerphysicsqc.integer)
381 prog->globals.server->time = sv.time;
382 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
383 PRVM_ExecuteProgram (prog->funcoffsets.SV_PlayerPhysics, "QC function SV_PlayerPhysics is missing");
384 SV_CheckVelocity(host_client->edict);
388 if (host_client->edict->fields.server->movetype == MOVETYPE_NONE)
391 onground = (int)host_client->edict->fields.server->flags & FL_ONGROUND;
395 // if dead, behave differently
396 if (host_client->edict->fields.server->health <= 0)
399 cmd = host_client->cmd;
402 // show 1/3 the pitch angle and all the roll angle
403 VectorAdd (host_client->edict->fields.server->v_angle, host_client->edict->fields.server->punchangle, v_angle);
404 host_client->edict->fields.server->angles[ROLL] = V_CalcRoll (host_client->edict->fields.server->angles, host_client->edict->fields.server->velocity)*4;
405 if (!host_client->edict->fields.server->fixangle)
407 host_client->edict->fields.server->angles[PITCH] = -v_angle[PITCH]/3;
408 host_client->edict->fields.server->angles[YAW] = v_angle[YAW];
411 if ( (int)host_client->edict->fields.server->flags & FL_WATERJUMP )
414 SV_CheckVelocity(host_client->edict);
419 // Player is (somehow) outside of the map, or flying, or noclipping
420 if (host_client->edict->fields.server->movetype != MOVETYPE_NOCLIP && (host_client->edict->fields.server->movetype == MOVETYPE_FLY || SV_TestEntityPosition (host_client->edict)))
421 //if (host_client->edict->fields.server->movetype == MOVETYPE_NOCLIP || host_client->edict->fields.server->movetype == MOVETYPE_FLY || SV_TestEntityPosition (host_client->edict))
429 if ((host_client->edict->fields.server->waterlevel >= 2) && (host_client->edict->fields.server->movetype != MOVETYPE_NOCLIP))
432 SV_CheckVelocity(host_client->edict);
437 SV_CheckVelocity(host_client->edict);
445 int sv_numreadmoves = 0;
446 usercmd_t sv_readmoves[CL_MAX_USERCMDS];
447 void SV_ReadClientMove (void)
451 usercmd_t *move = &newmove;
453 memset(move, 0, sizeof(*move));
455 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
458 if (sv.protocol != PROTOCOL_QUAKE && sv.protocol != PROTOCOL_QUAKEDP && sv.protocol != PROTOCOL_NEHAHRAMOVIE && sv.protocol != PROTOCOL_DARKPLACES1 && sv.protocol != PROTOCOL_DARKPLACES2 && sv.protocol != PROTOCOL_DARKPLACES3 && sv.protocol != PROTOCOL_DARKPLACES4 && sv.protocol != PROTOCOL_DARKPLACES5 && sv.protocol != PROTOCOL_DARKPLACES6)
459 move->sequence = MSG_ReadLong ();
460 move->time = MSG_ReadFloat ();
461 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
462 move->receivetime = (float)sv.time;
465 Con_Printf("%s move%i #%i %ims (%ims) %i %i '%i %i %i' '%i %i %i'\n", move->time > move->receivetime ? "^3read future" : "^4read normal", sv_numreadmoves + 1, move->sequence, (int)floor((move->time - host_client->cmd.time) * 1000.0 + 0.5), (int)floor(move->time * 1000.0 + 0.5), move->impulse, move->buttons, (int)move->viewangles[0], (int)move->viewangles[1], (int)move->viewangles[2], (int)move->forwardmove, (int)move->sidemove, (int)move->upmove);
467 // limit reported time to current time
468 // (incase the client is trying to cheat)
469 move->time = min(move->time, move->receivetime + sv.frametime);
471 // read current angles
472 for (i = 0;i < 3;i++)
474 if (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE)
475 move->viewangles[i] = MSG_ReadAngle8i();
476 else if (sv.protocol == PROTOCOL_DARKPLACES1)
477 move->viewangles[i] = MSG_ReadAngle16i();
478 else if (sv.protocol == PROTOCOL_DARKPLACES2 || sv.protocol == PROTOCOL_DARKPLACES3)
479 move->viewangles[i] = MSG_ReadAngle32f();
481 move->viewangles[i] = MSG_ReadAngle16i();
483 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
486 move->forwardmove = MSG_ReadCoord16i ();
487 move->sidemove = MSG_ReadCoord16i ();
488 move->upmove = MSG_ReadCoord16i ();
489 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
492 // be sure to bitwise OR them into the move->buttons because we want to
493 // accumulate button presses from multiple packets per actual move
494 if (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE || sv.protocol == PROTOCOL_DARKPLACES1 || sv.protocol == PROTOCOL_DARKPLACES2 || sv.protocol == PROTOCOL_DARKPLACES3 || sv.protocol == PROTOCOL_DARKPLACES4 || sv.protocol == PROTOCOL_DARKPLACES5)
495 move->buttons = MSG_ReadByte ();
497 move->buttons = MSG_ReadLong ();
498 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
501 move->impulse = MSG_ReadByte ();
502 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
504 // PRYDON_CLIENTCURSOR
505 if (sv.protocol != PROTOCOL_QUAKE && sv.protocol != PROTOCOL_QUAKEDP && sv.protocol != PROTOCOL_NEHAHRAMOVIE && sv.protocol != PROTOCOL_DARKPLACES1 && sv.protocol != PROTOCOL_DARKPLACES2 && sv.protocol != PROTOCOL_DARKPLACES3 && sv.protocol != PROTOCOL_DARKPLACES4 && sv.protocol != PROTOCOL_DARKPLACES5)
508 move->cursor_screen[0] = MSG_ReadShort() * (1.0f / 32767.0f);
509 move->cursor_screen[1] = MSG_ReadShort() * (1.0f / 32767.0f);
510 move->cursor_start[0] = MSG_ReadFloat();
511 move->cursor_start[1] = MSG_ReadFloat();
512 move->cursor_start[2] = MSG_ReadFloat();
513 move->cursor_impact[0] = MSG_ReadFloat();
514 move->cursor_impact[1] = MSG_ReadFloat();
515 move->cursor_impact[2] = MSG_ReadFloat();
516 move->cursor_entitynumber = (unsigned short)MSG_ReadShort();
517 if (move->cursor_entitynumber >= prog->max_edicts)
519 Con_DPrintf("SV_ReadClientMessage: client send bad cursor_entitynumber\n");
520 move->cursor_entitynumber = 0;
522 // as requested by FrikaC, cursor_trace_ent is reset to world if the
523 // entity is free at time of receipt
524 if (PRVM_EDICT_NUM(move->cursor_entitynumber)->priv.server->free)
525 move->cursor_entitynumber = 0;
526 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
529 // if the previous move has not been applied yet, we need to accumulate
530 // the impulse/buttons from it
531 if (!host_client->cmd.applied)
534 move->impulse = host_client->cmd.impulse;
535 move->buttons |= host_client->cmd.buttons;
538 // now store this move for later execution
539 // (we have to buffer the moves because of old ones being repeated)
540 if (sv_numreadmoves < CL_MAX_USERCMDS)
541 sv_readmoves[sv_numreadmoves++] = *move;
544 void SV_ExecuteClientMoves(void)
549 double oldframetime2;
550 #ifdef NUM_PING_TIMES
554 if (sv_numreadmoves < 1)
556 // only start accepting input once the player is spawned
557 if (!host_client->spawned)
560 Con_Printf("SV_ExecuteClientMoves: read %i moves at sv.time %f\n", sv_numreadmoves, (float)sv.time);
562 // disable clientside movement prediction in some cases
563 if (ceil(max(sv_readmoves[sv_numreadmoves-1].receivetime - sv_readmoves[sv_numreadmoves-1].time, 0) * 1000.0) < sv_clmovement_minping.integer)
564 host_client->clmovement_disabletimeout = realtime + sv_clmovement_minping_disabletime.value / 1000.0;
565 // several conditions govern whether clientside movement prediction is allowed
566 if (sv_readmoves[sv_numreadmoves-1].sequence && sv_clmovement_enable.integer && sv_clmovement_waitforinput.integer > 0 && host_client->clmovement_disabletimeout <= realtime && host_client->edict->fields.server->movetype == MOVETYPE_WALK && (!(val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.disableclientprediction)) || !val->_float))
568 // process the moves in order and ignore old ones
569 // but always trust the latest move
570 // (this deals with bogus initial move sequences after level change,
571 // where the client will eventually catch up with the level change
572 // and reset its move sequence)
573 for (moveindex = 0;moveindex < sv_numreadmoves;moveindex++)
575 usercmd_t *move = sv_readmoves + moveindex;
576 if (host_client->movesequence < move->sequence || moveindex == sv_numreadmoves - 1)
579 Con_Printf("%smove #%i %ims (%ims) %i %i '%i %i %i' '%i %i %i'\n", (move->time - host_client->cmd.time) > sv.frametime * 1.01 ? "^1" : "^2", move->sequence, (int)floor((move->time - host_client->cmd.time) * 1000.0 + 0.5), (int)floor(move->time * 1000.0 + 0.5), move->impulse, move->buttons, (int)move->viewangles[0], (int)move->viewangles[1], (int)move->viewangles[2], (int)move->forwardmove, (int)move->sidemove, (int)move->upmove);
581 // this is a new move
582 moveframetime = bound(0, move->time - host_client->cmd.time, 0.1);
583 //Con_Printf("movesequence = %i (%i lost), moveframetime = %f\n", move->sequence, move->sequence ? move->sequence - host_client->movesequence - 1 : 0, moveframetime);
584 host_client->cmd = *move;
585 host_client->movesequence = move->sequence;
587 // if using prediction, we need to perform moves when packets are
588 // received, even if multiple occur in one frame
589 // (they can't go beyond the current time so there is no cheat issue
590 // with this approach, and if they don't send input for a while they
591 // start moving anyway, so the longest 'lagaport' possible is
592 // determined by the sv_clmovement_waitforinput cvar)
593 if (moveframetime <= 0)
595 oldframetime = prog->globals.server->frametime;
596 oldframetime2 = sv.frametime;
597 // update ping time for qc to see while executing this move
598 host_client->ping = host_client->cmd.receivetime - host_client->cmd.time;
599 // the server and qc frametime values must be changed temporarily
600 prog->globals.server->frametime = sv.frametime = moveframetime;
601 // if move is more than 50ms, split it into two moves (this matches QWSV behavior and the client prediction)
602 if (sv.frametime > 0.05)
604 prog->globals.server->frametime = sv.frametime = moveframetime * 0.5f;
605 SV_Physics_ClientMove();
607 SV_Physics_ClientMove();
608 sv.frametime = oldframetime2;
609 prog->globals.server->frametime = oldframetime;
610 host_client->clmovement_skipphysicsframes = sv_clmovement_waitforinput.integer;
616 // try to gather button bits from old moves, but only if their time is
617 // advancing (ones with the same timestamp can't be trusted)
618 for (moveindex = 0;moveindex < sv_numreadmoves-1;moveindex++)
620 usercmd_t *move = sv_readmoves + moveindex;
621 if (host_client->cmd.time < move->time)
623 sv_readmoves[sv_numreadmoves-1].buttons |= move->buttons;
625 sv_readmoves[sv_numreadmoves-1].impulse = move->impulse;
628 // now copy the new move
629 host_client->cmd = sv_readmoves[sv_numreadmoves-1];
630 host_client->movesequence = 0;
631 // make sure that normal physics takes over immediately
632 host_client->clmovement_skipphysicsframes = 0;
635 // calculate average ping time
636 host_client->ping = host_client->cmd.receivetime - host_client->cmd.time;
637 #ifdef NUM_PING_TIMES
638 host_client->ping_times[host_client->num_pings % NUM_PING_TIMES] = host_client->cmd.receivetime - host_client->cmd.time;
639 host_client->num_pings++;
640 for (i=0, total = 0;i < NUM_PING_TIMES;i++)
641 total += host_client->ping_times[i];
642 host_client->ping = total / NUM_PING_TIMES;
646 void SV_ApplyClientMove (void)
649 usercmd_t *move = &host_client->cmd;
651 if (!move->receivetime)
654 // note: a move can be applied multiple times if the client packets are
655 // not coming as often as the physics is executed, and the move must be
656 // applied before running qc each time because the id1 qc had a bug where
657 // it clears self.button2 in PlayerJump, causing pogostick behavior if
658 // moves are not applied every time before calling qc
659 move->applied = true;
661 // set the edict fields
662 host_client->edict->fields.server->button0 = move->buttons & 1;
663 host_client->edict->fields.server->button2 = (move->buttons & 2)>>1;
665 host_client->edict->fields.server->impulse = move->impulse;
666 // only send the impulse to qc once
668 VectorCopy(move->viewangles, host_client->edict->fields.server->v_angle);
669 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button3))) val->_float = ((move->buttons >> 2) & 1);
670 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button4))) val->_float = ((move->buttons >> 3) & 1);
671 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button5))) val->_float = ((move->buttons >> 4) & 1);
672 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button6))) val->_float = ((move->buttons >> 5) & 1);
673 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button7))) val->_float = ((move->buttons >> 6) & 1);
674 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button8))) val->_float = ((move->buttons >> 7) & 1);
675 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button9))) val->_float = ((move->buttons >> 11) & 1);
676 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button10))) val->_float = ((move->buttons >> 12) & 1);
677 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button11))) val->_float = ((move->buttons >> 13) & 1);
678 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button12))) val->_float = ((move->buttons >> 14) & 1);
679 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button13))) val->_float = ((move->buttons >> 15) & 1);
680 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button14))) val->_float = ((move->buttons >> 16) & 1);
681 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button15))) val->_float = ((move->buttons >> 17) & 1);
682 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button16))) val->_float = ((move->buttons >> 18) & 1);
683 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.buttonuse))) val->_float = ((move->buttons >> 8) & 1);
684 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.buttonchat))) val->_float = ((move->buttons >> 9) & 1);
685 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.cursor_active))) val->_float = ((move->buttons >> 10) & 1);
686 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.movement))) VectorSet(val->vector, move->forwardmove, move->sidemove, move->upmove);
687 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.cursor_screen))) VectorCopy(move->cursor_screen, val->vector);
688 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.cursor_trace_start))) VectorCopy(move->cursor_start, val->vector);
689 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.cursor_trace_endpos))) VectorCopy(move->cursor_impact, val->vector);
690 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.cursor_trace_ent))) val->edict = PRVM_EDICT_TO_PROG(PRVM_EDICT_NUM(move->cursor_entitynumber));
691 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.ping))) val->_float = host_client->ping * 1000.0;
694 void SV_FrameLost(int framenum)
696 if (host_client->entitydatabase5)
697 EntityFrame5_LostFrame(host_client->entitydatabase5, framenum);
700 void SV_FrameAck(int framenum)
702 if (host_client->entitydatabase)
703 EntityFrame_AckFrame(host_client->entitydatabase, framenum);
704 else if (host_client->entitydatabase4)
705 EntityFrame4_AckFrame(host_client->entitydatabase4, framenum, true);
706 else if (host_client->entitydatabase5)
707 EntityFrame5_AckFrame(host_client->entitydatabase5, framenum);
715 extern void SV_SendServerinfo(client_t *client);
716 extern sizebuf_t vm_tempstringsbuf;
717 void SV_ReadClientMessage(void)
722 //MSG_BeginReading ();
727 if (!host_client->active)
729 // a command caused an error
730 SV_DropClient (false);
736 Con_Print("SV_ReadClientMessage: badread\n");
737 SV_DropClient (false);
741 cmd = MSG_ReadByte ();
745 // apply the moves that were read this frame
746 SV_ExecuteClientMoves();
753 Con_Printf("SV_ReadClientMessage: unknown command char %i\n", cmd);
754 SV_DropClient (false);
761 // allow reliable messages now as the client is done with initial loading
762 if (host_client->sendsignon == 2)
763 host_client->sendsignon = 0;
764 s = MSG_ReadString ();
766 for(p = s; *p; ++p) switch(*p)
775 goto clc_stringcmd_invalid; // newline seen, THEN something else -> possible exploit
780 if (strncasecmp(s, "spawn", 5) == 0
781 || strncasecmp(s, "begin", 5) == 0
782 || strncasecmp(s, "prespawn", 8) == 0)
783 Cmd_ExecuteString (s, src_client);
784 else if (prog->funcoffsets.SV_ParseClientCommand)
786 int restorevm_tempstringsbuf_cursize;
787 restorevm_tempstringsbuf_cursize = vm_tempstringsbuf.cursize;
788 PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(s);
789 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
790 PRVM_ExecuteProgram (prog->funcoffsets.SV_ParseClientCommand, "QC function SV_ParseClientCommand is missing");
791 vm_tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
794 Cmd_ExecuteString (s, src_client);
797 clc_stringcmd_invalid:
798 Con_Printf("Received invalid stringcmd from %s\n", host_client->name);
799 if(developer.integer)
800 Com_HexDumpToConsole((unsigned char *) s, strlen(s));
804 SV_DropClient (false); // client wants to disconnect
811 case clc_ackdownloaddata:
812 start = MSG_ReadLong();
813 num = MSG_ReadShort();
814 if (host_client->download_file && host_client->download_started)
816 if (host_client->download_expectedposition == start)
818 int size = (int)FS_FileSize(host_client->download_file);
819 // a data block was successfully received by the client,
820 // update the expected position on the next data block
821 host_client->download_expectedposition = start + num;
822 // if this was the last data block of the file, it's done
823 if (host_client->download_expectedposition >= FS_FileSize(host_client->download_file))
825 // tell the client that the download finished
826 // we need to calculate the crc now
828 // note: at this point the OS probably has the file
829 // entirely in memory, so this is a faster operation
830 // now than it was when the download started.
832 // it is also preferable to do this at the end of the
833 // download rather than the start because it reduces
834 // potential for Denial Of Service attacks against the
838 FS_Seek(host_client->download_file, 0, SEEK_SET);
839 temp = Mem_Alloc(tempmempool, size);
840 FS_Read(host_client->download_file, temp, size);
841 crc = CRC_Block(temp, size);
843 // calculated crc, send the file info to the client
844 // (so that it can verify the data)
845 Host_ClientCommands(va("\ncl_downloadfinished %i %i %s\n", size, crc, host_client->download_name));
846 Con_DPrintf("Download of %s by %s has finished\n", host_client->download_name, host_client->name);
847 FS_Close(host_client->download_file);
848 host_client->download_file = NULL;
849 host_client->download_name[0] = 0;
850 host_client->download_expectedposition = 0;
851 host_client->download_started = false;
856 // a data block was lost, reset to the expected position
857 // and resume sending from there
858 FS_Seek(host_client->download_file, host_client->download_expectedposition, SEEK_SET);
864 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
865 num = MSG_ReadLong();
866 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
867 if (developer_networkentities.integer >= 10)
868 Con_Printf("recv clc_ackframe %i\n", num);
869 // if the client hasn't progressed through signons yet,
870 // ignore any clc_ackframes we get (they're probably from the
872 if (host_client->spawned && host_client->latestframenum < num)
875 for (i = host_client->latestframenum + 1;i < num;i++)
878 host_client->latestframenum = num;