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
24 cvar_t sv_edgefriction = {0, "edgefriction", "2", "how much you slow down when nearing a ledge you might fall off"};
25 cvar_t sv_idealpitchscale = {0, "sv_idealpitchscale","0.8", "how much to look up/down slopes and stairs when not using freelook"};
26 cvar_t sv_maxspeed = {CVAR_NOTIFY, "sv_maxspeed", "320", "maximum speed a player can accelerate to when on ground (can be exceeded by tricks)"};
27 cvar_t sv_maxairspeed = {0, "sv_maxairspeed", "30", "maximum speed a player can accelerate to when airborn (note that it is possible to completely stop by moving the opposite direction)"};
28 cvar_t sv_accelerate = {0, "sv_accelerate", "10", "rate at which a player accelerates to sv_maxspeed"};
29 cvar_t sv_airaccelerate = {0, "sv_airaccelerate", "-1", "rate at which a player accelerates to sv_maxairspeed while in the air, if less than 0 the sv_accelerate variable is used instead"};
30 cvar_t sv_wateraccelerate = {0, "sv_wateraccelerate", "-1", "rate at which a player accelerates to sv_maxspeed while in the air, if less than 0 the sv_accelerate variable is used instead"};
31 cvar_t sv_clmovement_enable = {0, "sv_clmovement_enable", "1", "whether to allow clients to use cl_movement prediction, which can cause choppy movement on the server which may annoy other players"};
32 cvar_t sv_clmovement_minping = {0, "sv_clmovement_minping", "0", "if client ping is below this time in milliseconds, then their ability to use cl_movement prediction is disabled for a while (as they don't need it)"};
33 cvar_t sv_clmovement_minping_disabletime = {0, "sv_clmovement_minping_disabletime", "1000", "when client falls below minping, disable their prediction for this many milliseconds (should be at least 1000 or else their prediction may turn on/off frequently)"};
34 cvar_t sv_clmovement_waitforinput = {0, "sv_clmovement_waitforinput", "16", "when a client does not send input for this many frames, force them to move anyway (unlike QuakeWorld)"};
45 void SV_SetIdealPitch (void)
47 float angleval, sinval, cosval, step, dir;
54 if (!((int)host_client->edict->fields.server->flags & FL_ONGROUND))
57 angleval = host_client->edict->fields.server->angles[YAW] * M_PI*2 / 360;
58 sinval = sin(angleval);
59 cosval = cos(angleval);
61 for (i=0 ; i<MAX_FORWARD ; i++)
63 top[0] = host_client->edict->fields.server->origin[0] + cosval*(i+3)*12;
64 top[1] = host_client->edict->fields.server->origin[1] + sinval*(i+3)*12;
65 top[2] = host_client->edict->fields.server->origin[2] + host_client->edict->fields.server->view_ofs[2];
69 bottom[2] = top[2] - 160;
71 tr = SV_Move (top, vec3_origin, vec3_origin, bottom, MOVE_NOMONSTERS, host_client->edict);
72 // if looking at a wall, leave ideal the way is was
80 z[i] = top[2] + tr.fraction*(bottom[2]-top[2]);
88 if (step > -ON_EPSILON && step < ON_EPSILON)
92 if (dir && ( step-dir > ON_EPSILON || step-dir < -ON_EPSILON ) )
101 host_client->edict->fields.server->idealpitch = 0;
107 host_client->edict->fields.server->idealpitch = -dir * sv_idealpitchscale.value;
110 static vec3_t wishdir, forward, right, up;
111 static float wishspeed;
113 static qboolean onground;
121 void SV_UserFriction (void)
123 float speed, newspeed, control, friction;
127 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]);
131 // if the leading edge is over a dropoff, increase friction
132 start[0] = stop[0] = host_client->edict->fields.server->origin[0] + host_client->edict->fields.server->velocity[0]/speed*16;
133 start[1] = stop[1] = host_client->edict->fields.server->origin[1] + host_client->edict->fields.server->velocity[1]/speed*16;
134 start[2] = host_client->edict->fields.server->origin[2] + host_client->edict->fields.server->mins[2];
135 stop[2] = start[2] - 34;
137 trace = SV_Move (start, vec3_origin, vec3_origin, stop, MOVE_NOMONSTERS, host_client->edict);
139 if (trace.fraction == 1.0)
140 friction = sv_friction.value*sv_edgefriction.value;
142 friction = sv_friction.value;
145 control = speed < sv_stopspeed.value ? sv_stopspeed.value : speed;
146 newspeed = speed - sv.frametime*control*friction;
153 VectorScale(host_client->edict->fields.server->velocity, newspeed, host_client->edict->fields.server->velocity);
161 void SV_Accelerate (void)
164 float addspeed, accelspeed, currentspeed;
166 currentspeed = DotProduct (host_client->edict->fields.server->velocity, wishdir);
167 addspeed = wishspeed - currentspeed;
170 accelspeed = sv_accelerate.value*sv.frametime*wishspeed;
171 if (accelspeed > addspeed)
172 accelspeed = addspeed;
174 for (i=0 ; i<3 ; i++)
175 host_client->edict->fields.server->velocity[i] += accelspeed*wishdir[i];
178 void SV_AirAccelerate (vec3_t wishveloc)
181 float addspeed, wishspd, accelspeed, currentspeed;
183 wishspd = VectorNormalizeLength (wishveloc);
184 if (wishspd > sv_maxairspeed.value)
185 wishspd = sv_maxairspeed.value;
186 currentspeed = DotProduct (host_client->edict->fields.server->velocity, wishveloc);
187 addspeed = wishspd - currentspeed;
190 accelspeed = (sv_airaccelerate.value < 0 ? sv_accelerate.value : sv_airaccelerate.value)*wishspeed * sv.frametime;
191 if (accelspeed > addspeed)
192 accelspeed = addspeed;
194 for (i=0 ; i<3 ; i++)
195 host_client->edict->fields.server->velocity[i] += accelspeed*wishveloc[i];
199 void DropPunchAngle (void)
204 len = VectorNormalizeLength (host_client->edict->fields.server->punchangle);
206 len -= 10*sv.frametime;
209 VectorScale (host_client->edict->fields.server->punchangle, len, host_client->edict->fields.server->punchangle);
211 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_punchvector)))
213 len = VectorNormalizeLength (val->vector);
215 len -= 20*sv.frametime;
218 VectorScale (val->vector, len, val->vector);
227 void SV_FreeMove (void)
232 AngleVectors (host_client->edict->fields.server->v_angle, forward, right, up);
234 for (i = 0; i < 3; i++)
235 host_client->edict->fields.server->velocity[i] = forward[i] * cmd.forwardmove + right[i] * cmd.sidemove;
237 host_client->edict->fields.server->velocity[2] += cmd.upmove;
239 wishspeed = VectorLength(host_client->edict->fields.server->velocity);
240 if (wishspeed > sv_maxspeed.value)
241 VectorScale(host_client->edict->fields.server->velocity, sv_maxspeed.value / wishspeed, host_client->edict->fields.server->velocity);
250 void SV_WaterMove (void)
254 float speed, newspeed, wishspeed, addspeed, accelspeed, temp;
257 AngleVectors (host_client->edict->fields.server->v_angle, forward, right, up);
259 for (i=0 ; i<3 ; i++)
260 wishvel[i] = forward[i]*cmd.forwardmove + right[i]*cmd.sidemove;
262 if (!cmd.forwardmove && !cmd.sidemove && !cmd.upmove)
263 wishvel[2] -= 60; // drift towards bottom
265 wishvel[2] += cmd.upmove;
267 wishspeed = VectorLength(wishvel);
268 if (wishspeed > sv_maxspeed.value)
270 temp = sv_maxspeed.value/wishspeed;
271 VectorScale (wishvel, temp, wishvel);
272 wishspeed = sv_maxspeed.value;
277 speed = VectorLength(host_client->edict->fields.server->velocity);
280 newspeed = speed - sv.frametime * speed * sv_waterfriction.value;
283 temp = newspeed/speed;
284 VectorScale(host_client->edict->fields.server->velocity, temp, host_client->edict->fields.server->velocity);
289 // water acceleration
293 addspeed = wishspeed - newspeed;
297 VectorNormalize (wishvel);
298 accelspeed = (sv_wateraccelerate.value < 0 ? sv_accelerate.value : sv_wateraccelerate.value) * wishspeed * sv.frametime;
299 if (accelspeed > addspeed)
300 accelspeed = addspeed;
302 for (i=0 ; i<3 ; i++)
303 host_client->edict->fields.server->velocity[i] += accelspeed * wishvel[i];
306 void SV_WaterJump (void)
308 if (sv.time > host_client->edict->fields.server->teleport_time || !host_client->edict->fields.server->waterlevel)
310 host_client->edict->fields.server->flags = (int)host_client->edict->fields.server->flags & ~FL_WATERJUMP;
311 host_client->edict->fields.server->teleport_time = 0;
313 host_client->edict->fields.server->velocity[0] = host_client->edict->fields.server->movedir[0];
314 host_client->edict->fields.server->velocity[1] = host_client->edict->fields.server->movedir[1];
324 void SV_AirMove (void)
328 float fmove, smove, temp;
330 // LordHavoc: correct quake movement speed bug when looking up/down
331 wishvel[0] = wishvel[2] = 0;
332 wishvel[1] = host_client->edict->fields.server->angles[1];
333 AngleVectors (wishvel, forward, right, up);
335 fmove = cmd.forwardmove;
336 smove = cmd.sidemove;
338 // hack to not let you back into teleporter
339 if (sv.time < host_client->edict->fields.server->teleport_time && fmove < 0)
342 for (i=0 ; i<3 ; i++)
343 wishvel[i] = forward[i]*fmove + right[i]*smove;
345 if ((int)host_client->edict->fields.server->movetype != MOVETYPE_WALK)
346 wishvel[2] += cmd.upmove;
348 VectorCopy (wishvel, wishdir);
349 wishspeed = VectorNormalizeLength(wishdir);
350 if (wishspeed > sv_maxspeed.value)
352 temp = sv_maxspeed.value/wishspeed;
353 VectorScale (wishvel, temp, wishvel);
354 wishspeed = sv_maxspeed.value;
357 if (host_client->edict->fields.server->movetype == MOVETYPE_NOCLIP)
360 VectorCopy (wishvel, host_client->edict->fields.server->velocity);
362 else if (onground && (!sv_gameplayfix_qwplayerphysics.integer || !(host_client->edict->fields.server->button2 || !((int)host_client->edict->fields.server->flags & FL_JUMPRELEASED))))
369 // not on ground, so little effect on velocity
370 SV_AirAccelerate (wishvel);
378 the move fields specify an intended velocity in pix/sec
379 the angle fields specify an exact angular motion in degrees
382 void SV_ClientThink (void)
386 if (host_client->edict->fields.server->movetype == MOVETYPE_NONE)
389 onground = (int)host_client->edict->fields.server->flags & FL_ONGROUND;
393 // if dead, behave differently
394 if (host_client->edict->fields.server->health <= 0)
397 cmd = host_client->cmd;
400 // show 1/3 the pitch angle and all the roll angle
401 VectorAdd (host_client->edict->fields.server->v_angle, host_client->edict->fields.server->punchangle, v_angle);
402 host_client->edict->fields.server->angles[ROLL] = V_CalcRoll (host_client->edict->fields.server->angles, host_client->edict->fields.server->velocity)*4;
403 if (!host_client->edict->fields.server->fixangle)
405 host_client->edict->fields.server->angles[PITCH] = -v_angle[PITCH]/3;
406 host_client->edict->fields.server->angles[YAW] = v_angle[YAW];
409 if ( (int)host_client->edict->fields.server->flags & FL_WATERJUMP )
416 // Player is (somehow) outside of the map, or flying, or noclipping
417 if (host_client->edict->fields.server->movetype != MOVETYPE_NOCLIP && (host_client->edict->fields.server->movetype == MOVETYPE_FLY || SV_TestEntityPosition (host_client->edict)))
418 //if (host_client->edict->fields.server->movetype == MOVETYPE_NOCLIP || host_client->edict->fields.server->movetype == MOVETYPE_FLY || SV_TestEntityPosition (host_client->edict))
426 if ((host_client->edict->fields.server->waterlevel >= 2) && (host_client->edict->fields.server->movetype != MOVETYPE_NOCLIP))
440 qboolean SV_ReadClientMove (void)
442 qboolean kickplayer = false;
444 #ifdef NUM_PING_TIMES
447 double moveframetime;
449 usercmd_t *move = &newmove;
451 memset(move, 0, sizeof(*move));
453 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
456 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)
457 move->sequence = MSG_ReadLong ();
458 move->time = MSG_ReadFloat ();
459 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
460 move->receivetime = (float)sv.time;
462 // limit reported time to current time
463 // (incase the client is trying to cheat)
464 move->time = min(move->time, move->receivetime);
466 // read current angles
467 for (i = 0;i < 3;i++)
469 if (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE)
470 move->viewangles[i] = MSG_ReadAngle8i();
471 else if (sv.protocol == PROTOCOL_DARKPLACES1)
472 move->viewangles[i] = MSG_ReadAngle16i();
473 else if (sv.protocol == PROTOCOL_DARKPLACES2 || sv.protocol == PROTOCOL_DARKPLACES3)
474 move->viewangles[i] = MSG_ReadAngle32f();
476 move->viewangles[i] = MSG_ReadAngle16i();
478 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
481 move->forwardmove = MSG_ReadCoord16i ();
482 move->sidemove = MSG_ReadCoord16i ();
483 move->upmove = MSG_ReadCoord16i ();
484 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
487 // be sure to bitwise OR them into the move->buttons because we want to
488 // accumulate button presses from multiple packets per actual move
489 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)
490 move->buttons = MSG_ReadByte ();
492 move->buttons = MSG_ReadLong ();
493 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
496 move->impulse = MSG_ReadByte ();
497 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
499 // PRYDON_CLIENTCURSOR
500 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)
503 move->cursor_screen[0] = MSG_ReadShort() * (1.0f / 32767.0f);
504 move->cursor_screen[1] = MSG_ReadShort() * (1.0f / 32767.0f);
505 move->cursor_start[0] = MSG_ReadFloat();
506 move->cursor_start[1] = MSG_ReadFloat();
507 move->cursor_start[2] = MSG_ReadFloat();
508 move->cursor_impact[0] = MSG_ReadFloat();
509 move->cursor_impact[1] = MSG_ReadFloat();
510 move->cursor_impact[2] = MSG_ReadFloat();
511 move->cursor_entitynumber = (unsigned short)MSG_ReadShort();
512 if (move->cursor_entitynumber >= prog->max_edicts)
514 Con_DPrintf("SV_ReadClientMessage: client send bad cursor_entitynumber\n");
515 move->cursor_entitynumber = 0;
517 // as requested by FrikaC, cursor_trace_ent is reset to world if the
518 // entity is free at time of receipt
519 if (PRVM_EDICT_NUM(move->cursor_entitynumber)->priv.server->free)
520 move->cursor_entitynumber = 0;
521 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
524 if (move->sequence && move->sequence <= host_client->movesequence)
526 // repeat of old input (to fight packet loss)
530 // if the previous move has not been applied yet, we need to accumulate
531 // the impulse/buttons from it
532 if (!host_client->cmd.applied)
535 move->impulse = host_client->cmd.impulse;
536 move->buttons |= host_client->cmd.impulse;
539 moveframetime = bound(0, move->time - host_client->cmd.time, 0.1);
540 //Con_Printf("movesequence = %i (%i lost), moveframetime = %f\n", move->sequence, move->sequence ? move->sequence - host_client->movesequence - 1 : 0, moveframetime);
542 // disable clientside movement prediction in some cases
543 if (ceil((move->receivetime - move->time) * 1000.0) < sv_clmovement_minping.integer)
544 host_client->clmovement_disabletimeout = realtime + sv_clmovement_minping_disabletime.value / 1000.0;
545 if (!sv_clmovement_enable.integer || host_client->clmovement_disabletimeout > realtime)
548 // calculate average ping time
549 host_client->ping = move->receivetime - move->time;
550 #ifdef NUM_PING_TIMES
551 host_client->ping_times[host_client->num_pings % NUM_PING_TIMES] = move->receivetime - move->time;
552 host_client->num_pings++;
553 for (i=0, total = 0;i < NUM_PING_TIMES;i++)
554 total += host_client->ping_times[i];
555 host_client->ping = total / NUM_PING_TIMES;
558 // only start accepting input once the player is spawned
559 if (host_client->spawned)
561 // at this point we know this input is new and should be stored
562 host_client->cmd = *move;
563 host_client->movesequence = move->sequence;
564 // if using prediction, we need to perform moves when packets are
565 // received, even if multiple occur in one frame
566 // (they can't go beyond the current time so there is no cheat issue
567 // with this approach, and if they don't send input for a while they
568 // start moving anyway, so the longest 'lagaport' possible is
569 // determined by the sv_clmovement_waitforinput cvar)
570 if (host_client->movesequence && sv_clmovement_waitforinput.integer > 0 && moveframetime > 0)
572 double oldframetime = prog->globals.server->frametime;
573 double oldframetime2 = sv.frametime;
574 // the server and qc frametime values must be changed temporarily
575 sv.frametime = moveframetime;
576 prog->globals.server->frametime = moveframetime;
577 SV_Physics_ClientEntity(host_client->edict);
578 sv.frametime = oldframetime2;
579 prog->globals.server->frametime = oldframetime;
580 host_client->clmovement_skipphysicsframes = sv_clmovement_waitforinput.integer;
587 void SV_ApplyClientMove (void)
590 usercmd_t *move = &host_client->cmd;
592 if (!move->receivetime)
595 // note: a move can be applied multiple times if the client packets are
596 // not coming as often as the physics is executed, and the move must be
597 // applied before running qc each time because the id1 qc had a bug where
598 // it clears self.button2 in PlayerJump, causing pogostick behavior if
599 // moves are not applied every time before calling qc
600 move->applied = true;
602 // set the edict fields
603 host_client->edict->fields.server->button0 = move->buttons & 1;
604 host_client->edict->fields.server->button2 = (move->buttons & 2)>>1;
606 host_client->edict->fields.server->impulse = move->impulse;
607 // only send the impulse to qc once
609 VectorCopy(move->viewangles, host_client->edict->fields.server->v_angle);
610 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_button3))) val->_float = ((move->buttons >> 2) & 1);
611 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_button4))) val->_float = ((move->buttons >> 3) & 1);
612 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_button5))) val->_float = ((move->buttons >> 4) & 1);
613 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_button6))) val->_float = ((move->buttons >> 5) & 1);
614 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_button7))) val->_float = ((move->buttons >> 6) & 1);
615 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_button8))) val->_float = ((move->buttons >> 7) & 1);
616 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_button9))) val->_float = ((move->buttons >> 11) & 1);
617 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_button10))) val->_float = ((move->buttons >> 12) & 1);
618 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_button11))) val->_float = ((move->buttons >> 13) & 1);
619 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_button12))) val->_float = ((move->buttons >> 14) & 1);
620 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_button13))) val->_float = ((move->buttons >> 15) & 1);
621 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_button14))) val->_float = ((move->buttons >> 16) & 1);
622 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_button15))) val->_float = ((move->buttons >> 17) & 1);
623 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_button16))) val->_float = ((move->buttons >> 18) & 1);
624 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_buttonuse))) val->_float = ((move->buttons >> 8) & 1);
625 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_buttonchat))) val->_float = ((move->buttons >> 9) & 1);
626 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_cursor_active))) val->_float = ((move->buttons >> 10) & 1);
627 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_movement))) VectorSet(val->vector, move->forwardmove, move->sidemove, move->upmove);
628 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_cursor_screen))) VectorCopy(move->cursor_screen, val->vector);
629 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_cursor_trace_start))) VectorCopy(move->cursor_start, val->vector);
630 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_cursor_trace_endpos))) VectorCopy(move->cursor_impact, val->vector);
631 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_cursor_trace_ent))) val->edict = PRVM_EDICT_TO_PROG(PRVM_EDICT_NUM(move->cursor_entitynumber));
632 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ping))) val->_float = host_client->ping * 1000.0;
635 void SV_FrameLost(int framenum)
637 if (host_client->entitydatabase5)
638 EntityFrame5_LostFrame(host_client->entitydatabase5, framenum);
641 void SV_FrameAck(int framenum)
643 if (host_client->entitydatabase)
644 EntityFrame_AckFrame(host_client->entitydatabase, framenum);
645 else if (host_client->entitydatabase4)
646 EntityFrame4_AckFrame(host_client->entitydatabase4, framenum, true);
647 else if (host_client->entitydatabase5)
648 EntityFrame5_AckFrame(host_client->entitydatabase5, framenum);
656 extern void SV_SendServerinfo(client_t *client);
657 extern sizebuf_t vm_tempstringsbuf;
658 void SV_ReadClientMessage(void)
663 //MSG_BeginReading ();
667 if (!host_client->active)
669 // a command caused an error
670 SV_DropClient (false);
676 Con_Print("SV_ReadClientMessage: badread\n");
677 SV_DropClient (false);
681 cmd = MSG_ReadByte ();
691 Con_Printf("SV_ReadClientMessage: unknown command char %i\n", cmd);
692 SV_DropClient (false);
699 s = MSG_ReadString ();
700 if (strncasecmp(s, "spawn", 5) == 0
701 || strncasecmp(s, "begin", 5) == 0
702 || strncasecmp(s, "prespawn", 8) == 0)
703 Cmd_ExecuteString (s, src_client);
704 else if (SV_ParseClientCommandQC)
706 int restorevm_tempstringsbuf_cursize;
707 restorevm_tempstringsbuf_cursize = vm_tempstringsbuf.cursize;
708 PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(s);
709 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
710 PRVM_ExecuteProgram ((func_t)(SV_ParseClientCommandQC - prog->functions), "QC function SV_ParseClientCommand is missing");
711 vm_tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
714 Cmd_ExecuteString (s, src_client);
718 SV_DropClient (false); // client wants to disconnect
722 // if ReadClientMove returns true, the client tried to speed cheat
723 if (SV_ReadClientMove ())
724 SV_DropClient (false);
727 case clc_ackdownloaddata:
728 start = MSG_ReadLong();
729 num = MSG_ReadShort();
730 if (host_client->download_file && host_client->download_started)
732 if (host_client->download_expectedposition == start)
734 int size = (int)FS_FileSize(host_client->download_file);
735 // a data block was successfully received by the client,
736 // update the expected position on the next data block
737 host_client->download_expectedposition = start + num;
738 // if this was the last data block of the file, it's done
739 if (host_client->download_expectedposition >= FS_FileSize(host_client->download_file))
741 // tell the client that the download finished
742 // we need to calculate the crc now
744 // note: at this point the OS probably has the file
745 // entirely in memory, so this is a faster operation
746 // now than it was when the download started.
748 // it is also preferable to do this at the end of the
749 // download rather than the start because it reduces
750 // potential for Denial Of Service attacks against the
754 FS_Seek(host_client->download_file, 0, SEEK_SET);
755 temp = Mem_Alloc(tempmempool, size);
756 FS_Read(host_client->download_file, temp, size);
757 crc = CRC_Block(temp, size);
759 // calculated crc, send the file info to the client
760 // (so that it can verify the data)
761 Host_ClientCommands(va("\ncl_downloadfinished %i %i %s\n", size, crc, host_client->download_name));
762 Con_DPrintf("Download of %s by %s has finished\n", host_client->download_name, host_client->name);
763 FS_Close(host_client->download_file);
764 host_client->download_file = NULL;
765 host_client->download_name[0] = 0;
766 host_client->download_expectedposition = 0;
767 host_client->download_started = false;
772 // a data block was lost, reset to the expected position
773 // and resume sending from there
774 FS_Seek(host_client->download_file, host_client->download_expectedposition, SEEK_SET);
780 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
781 num = MSG_ReadLong();
782 if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
783 if (developer_networkentities.integer >= 1)
784 Con_Printf("recv clc_ackframe %i\n", num);
785 // if the client hasn't progressed through signons yet,
786 // ignore any clc_ackframes we get (they're probably from the
788 if (host_client->spawned && host_client->latestframenum < num)
791 for (i = host_client->latestframenum + 1;i < num;i++)
794 host_client->latestframenum = num;