diff --git a/qw/include/net_svc.h b/qw/include/net_svc.h index a3ea104e5..6cc730cc3 100644 --- a/qw/include/net_svc.h +++ b/qw/include/net_svc.h @@ -58,7 +58,7 @@ typedef struct net_svc_damage_s typedef struct net_svc_serverdata_s { int protocolversion; - int servercount; + int servercount; // FIXME: rename this const char *gamedir; byte playernum; qboolean spectator; @@ -201,7 +201,10 @@ typedef struct net_svc_deltapacketentities_s net_status_t NET_SVC_Print_Emit (net_svc_print_t *block, sizebuf_t *buf); net_status_t NET_SVC_Print_Parse (net_svc_print_t *block, msg_t *msg); +net_status_t NET_SVC_Damage_Emit (net_svc_damage_t *block, sizebuf_t *buf); net_status_t NET_SVC_Damage_Parse (net_svc_damage_t *block, msg_t *msg); +net_status_t NET_SVC_ServerData_Emit (net_svc_serverdata_t *block, + sizebuf_t *buf); net_status_t NET_SVC_ServerData_Parse (net_svc_serverdata_t *block, msg_t *msg); net_status_t NET_SVC_Sound_Parse (net_svc_sound_t *block, msg_t *msg); net_status_t NET_SVC_SpawnBaseline_Parse (net_svc_spawnbaseline_t *block, diff --git a/qw/source/net_svc.c b/qw/source/net_svc.c index 5270ed7fe..f120ba733 100644 --- a/qw/source/net_svc.c +++ b/qw/source/net_svc.c @@ -69,6 +69,19 @@ NET_SVC_Print_Parse (net_svc_print_t *block, msg_t *msg) return msg->badread; } +net_status_t +NET_SVC_Damage_Emit (net_svc_damage_t *block, sizebuf_t *buf) +{ + int i; + + MSG_WriteByte (buf, block->armor); + MSG_WriteByte (buf, block->blood); + for (i = 0; i < 3; i++) + MSG_WriteCoord (buf, block->from[i]); + + return buf->overflowed; +} + net_status_t NET_SVC_Damage_Parse (net_svc_damage_t *block, msg_t *msg) { @@ -82,6 +95,29 @@ NET_SVC_Damage_Parse (net_svc_damage_t *block, msg_t *msg) return msg->badread; } +net_status_t +NET_SVC_ServerData_Emit (net_svc_serverdata_t *block, sizebuf_t *buf) +{ + MSG_WriteLong (buf, block->protocolversion); + MSG_WriteLong (buf, block->servercount); + MSG_WriteString (buf, block->gamedir); + MSG_WriteByte (buf, block->playernum | (block->spectator ? 128 : 0)); + MSG_WriteString (buf, block->levelname); + + MSG_WriteFloat (buf, block->movevars.gravity); + MSG_WriteFloat (buf, block->movevars.stopspeed); + MSG_WriteFloat (buf, block->movevars.maxspeed); + MSG_WriteFloat (buf, block->movevars.spectatormaxspeed); + MSG_WriteFloat (buf, block->movevars.accelerate); + MSG_WriteFloat (buf, block->movevars.airaccelerate); + MSG_WriteFloat (buf, block->movevars.wateraccelerate); + MSG_WriteFloat (buf, block->movevars.friction); + MSG_WriteFloat (buf, block->movevars.waterfriction); + MSG_WriteFloat (buf, block->movevars.entgravity); + + return buf->overflowed; +} + net_status_t NET_SVC_ServerData_Parse (net_svc_serverdata_t *block, msg_t *msg) { diff --git a/qw/source/sv_send.c b/qw/source/sv_send.c index 54c3bc00a..efa4a9353 100644 --- a/qw/source/sv_send.c +++ b/qw/source/sv_send.c @@ -535,6 +535,7 @@ SV_WriteClientdataToMessage (client_t *client, sizebuf_t *msg) { edict_t *ent, *other; int i; + net_svc_damage_t block; ent = client->edict; @@ -547,13 +548,14 @@ SV_WriteClientdataToMessage (client_t *client, sizebuf_t *msg) // send a damage message if the player got hit this frame if (SVfloat (ent, dmg_take) || SVfloat (ent, dmg_save)) { other = PROG_TO_EDICT (&sv_pr_state, SVentity (ent, dmg_inflictor)); - MSG_WriteByte (msg, svc_damage); - MSG_WriteByte (msg, SVfloat (ent, dmg_save)); - MSG_WriteByte (msg, SVfloat (ent, dmg_take)); + block.armor = SVfloat (ent, dmg_save); + block.blood = SVfloat (ent, dmg_take); for (i = 0; i < 3; i++) - MSG_WriteCoord (msg, SVvector (other, origin)[i] + 0.5 * + block.from[i] = SVvector (other, origin)[i] + 0.5 * (SVvector (other, mins)[i] + - SVvector (other, maxs)[i])); + SVvector (other, maxs)[i]); + MSG_WriteByte (msg, svc_damage); + NET_SVC_Damage_Emit (&block, msg); SVfloat (ent, dmg_take) = 0; SVfloat (ent, dmg_save) = 0; diff --git a/qw/source/sv_user.c b/qw/source/sv_user.c index 15652d685..4fc969c96 100644 --- a/qw/source/sv_user.c +++ b/qw/source/sv_user.c @@ -54,6 +54,7 @@ static const char rcsid[] = #include "compat.h" #include "bothdefs.h" #include "msg_ucmd.h" +#include "net_svc.h" #include "pmove.h" #include "server.h" #include "sv_progs.h" @@ -96,7 +97,7 @@ void SV_New_f (void) { const char *gamedir; - int playernum; + net_svc_serverdata_t block; if (host_client->state == cs_spawned) return; @@ -115,37 +116,23 @@ SV_New_f (void) //NOTE: This doesn't go through ClientReliableWrite since it's before the user //spawns. These functions are written to not overflow if (host_client->num_backbuf) { - SV_Printf ("WARNING %s: [SV_New] Back buffered (%d0, clearing\n", + SV_Printf ("WARNING %s: [SV_New] Back buffered (%d), clearing\n", host_client->name, host_client->netchan.message.cursize); host_client->num_backbuf = 0; SZ_Clear (&host_client->netchan.message); } + // send the serverdata + block.protocolversion = PROTOCOL_VERSION; + block.servercount = svs.spawncount; + block.gamedir = gamedir; + block.playernum = NUM_FOR_EDICT (&sv_pr_state, host_client->edict) - 1; + block.spectator = host_client->spectator; + block.levelname = PR_GetString (&sv_pr_state, + SVstring (sv.edicts, message)); + block.movevars = movevars; MSG_WriteByte (&host_client->netchan.message, svc_serverdata); - MSG_WriteLong (&host_client->netchan.message, PROTOCOL_VERSION); - MSG_WriteLong (&host_client->netchan.message, svs.spawncount); - MSG_WriteString (&host_client->netchan.message, gamedir); - - playernum = NUM_FOR_EDICT (&sv_pr_state, host_client->edict) - 1; - if (host_client->spectator) - playernum |= 128; - MSG_WriteByte (&host_client->netchan.message, playernum); - - // send full levelname - MSG_WriteString (&host_client->netchan.message, - PR_GetString (&sv_pr_state, SVstring (sv.edicts, message))); - - // send the movevars - MSG_WriteFloat (&host_client->netchan.message, movevars.gravity); - MSG_WriteFloat (&host_client->netchan.message, movevars.stopspeed); - MSG_WriteFloat (&host_client->netchan.message, movevars.maxspeed); - MSG_WriteFloat (&host_client->netchan.message, movevars.spectatormaxspeed); - MSG_WriteFloat (&host_client->netchan.message, movevars.accelerate); - MSG_WriteFloat (&host_client->netchan.message, movevars.airaccelerate); - MSG_WriteFloat (&host_client->netchan.message, movevars.wateraccelerate); - MSG_WriteFloat (&host_client->netchan.message, movevars.friction); - MSG_WriteFloat (&host_client->netchan.message, movevars.waterfriction); - MSG_WriteFloat (&host_client->netchan.message, movevars.entgravity); + NET_SVC_ServerData_Emit (&block, &host_client->netchan.message); // send music MSG_WriteByte (&host_client->netchan.message, svc_cdtrack);