From d0fe1fa830366dcb956b735fe0fa76a7775801b5 Mon Sep 17 00:00:00 2001 From: skyjake Date: Sun, 20 Mar 2011 14:31:52 +0200 Subject: [PATCH] Client: Weapons changed via a request to the server Instead of letting the client change weapons on its own, it will now send a request to the server, who will actually carry out the weapon change. --- doomsday/engine/portable/src/cl_mobj.c | 4 ++++ doomsday/engine/portable/src/sv_pool.c | 3 +-- doomsday/plugins/common/include/d_net.h | 3 ++- doomsday/plugins/common/include/d_netcl.h | 2 +- doomsday/plugins/common/src/d_netcl.c | 15 ++++++++++++--- doomsday/plugins/common/src/d_netsv.c | 8 ++++++-- doomsday/plugins/common/src/p_map.c | 2 +- doomsday/plugins/common/src/p_user.c | 21 +++++++++++++++------ doomsday/plugins/jdoom/src/p_pspr.c | 2 +- 9 files changed, 43 insertions(+), 17 deletions(-) diff --git a/doomsday/engine/portable/src/cl_mobj.c b/doomsday/engine/portable/src/cl_mobj.c index 9132503a2e..1d31c1dbd2 100644 --- a/doomsday/engine/portable/src/cl_mobj.c +++ b/doomsday/engine/portable/src/cl_mobj.c @@ -723,6 +723,10 @@ void Cl_ReadMobjDelta2(boolean skip) fastMom = true; } +#ifdef _DEBUG + VERBOSE2( Con_Message("Cl_ReadMobjDelta: Reading mobj delta for %i (df:0x%x edf:0x%x skip:%i)\n", id, df, moreFlags, skip) ); +#endif + if(!skip) { // Get a mobj for this. diff --git a/doomsday/engine/portable/src/sv_pool.c b/doomsday/engine/portable/src/sv_pool.c index dd68dd5bd0..83ac2e6546 100644 --- a/doomsday/engine/portable/src/sv_pool.c +++ b/doomsday/engine/portable/src/sv_pool.c @@ -588,8 +588,7 @@ boolean Sv_RegisterCompareMobj(cregister_t* reg, const mobj_t* s, // Mobj state sent periodically, if it keeps changing. if((!(s->ddFlags & DDMF_MISSILE) && regMo && - Sys_GetTime() - regMo->lastTimeStateSent > (60 + s->thinker.id%35) && - r->state != s->state) || + Sys_GetTime() - regMo->lastTimeStateSent > (60 + s->thinker.id%35) && r->state != s->state) || !Def_SameStateSequence(r->state, s->state)) { df |= MDF_STATE; diff --git a/doomsday/plugins/common/include/d_net.h b/doomsday/plugins/common/include/d_net.h index bead1c77ef..dafdd0ee9a 100644 --- a/doomsday/plugins/common/include/d_net.h +++ b/doomsday/plugins/common/include/d_net.h @@ -103,7 +103,8 @@ typedef struct { // Player action requests. enum { GPA_FIRE = 1, - GPA_USE = 2 + GPA_USE = 2, + GPA_CHANGE_WEAPON = 3 }; // Game state flags. diff --git a/doomsday/plugins/common/include/d_netcl.h b/doomsday/plugins/common/include/d_netcl.h index 5f14bd0869..12c9393255 100644 --- a/doomsday/plugins/common/include/d_netcl.h +++ b/doomsday/plugins/common/include/d_netcl.h @@ -45,6 +45,6 @@ void NetCl_SendPlayerInfo(void); void NetCl_SaveGame(void* data); void NetCl_LoadGame(void* data); void NetCl_Paused(boolean setPause); -void NetCl_PlayerActionRequest(player_t* player, int actionType); +void NetCl_PlayerActionRequest(player_t* player, int actionType, int actionParam); #endif diff --git a/doomsday/plugins/common/src/d_netcl.c b/doomsday/plugins/common/src/d_netcl.c index 3d5887a5dd..b9be3bd90c 100644 --- a/doomsday/plugins/common/src/d_netcl.c +++ b/doomsday/plugins/common/src/d_netcl.c @@ -549,12 +549,14 @@ void NetCl_UpdatePlayerState(byte *data, int plrNum) if(flags & PSF_PENDING_WEAPON) { pl->pendingWeapon = b & 0xf; +#if _DEBUG + Con_Message("NetCl_UpdatePlayerState: pendingweapon=%i\n", pl->pendingWeapon); +#endif } if(flags & PSF_READY_WEAPON) { pl->readyWeapon = b >> 4; - #if _DEBUG Con_Message("NetCl_UpdatePlayerState: readyweapon=%i\n", pl->readyWeapon); #endif @@ -946,7 +948,7 @@ void NetCl_UpdateJumpPower(void *data) * the clients position and angle may not be up to date when a ticcmd * arrives. */ -void NetCl_PlayerActionRequest(player_t *player, int actionType) +void NetCl_PlayerActionRequest(player_t *player, int actionType, int actionParam) { #define MSG_SIZE (28) @@ -974,7 +976,14 @@ void NetCl_PlayerActionRequest(player_t *player, int actionType) *ptr++ = LONG(FLT2FIX(player->plr->lookDir)); // Currently active weapon. - *ptr++ = LONG(player->readyWeapon); + if(actionType == GPA_CHANGE_WEAPON) + { + *ptr++ = LONG(actionParam); + } + else + { + *ptr++ = LONG(player->readyWeapon); + } Net_SendPacket(DDSP_CONFIRM, GPT_ACTION_REQUEST, msg, MSG_SIZE); diff --git a/doomsday/plugins/common/src/d_netsv.c b/doomsday/plugins/common/src/d_netsv.c index 0ef4b2917b..0ea9f9e305 100644 --- a/doomsday/plugins/common/src/d_netsv.c +++ b/doomsday/plugins/common/src/d_netsv.c @@ -1411,9 +1411,9 @@ void NetSv_DoAction(int player, const char *data) #ifdef _DEBUG Con_Message("NetSv_DoAction: player=%i, type=%i, xyz=(%.1f,%.1f,%.1f)\n " - "angle=%x lookDir=%g\n", + "angle=%x lookDir=%g weapon=%i\n", player, type, pos[VX], pos[VY], pos[VZ], - angle, lookDir); + angle, lookDir, readyWeapon); #endif if(pl->playerState == PST_DEAD) @@ -1448,6 +1448,10 @@ void NetSv_DoAction(int player, const char *data) P_FireWeapon(pl); } break; + + case GPA_CHANGE_WEAPON: + pl->brain.changeWeapon = readyWeapon; + break; } } diff --git a/doomsday/plugins/common/src/p_map.c b/doomsday/plugins/common/src/p_map.c index b4891b81bb..ee92dd244d 100644 --- a/doomsday/plugins/common/src/p_map.c +++ b/doomsday/plugins/common/src/p_map.c @@ -2275,7 +2275,7 @@ void P_UseLines(player_t* player) Con_Message("P_UseLines: Sending a use request for player %i.\n", player - players); #endif - NetCl_PlayerActionRequest(player, GPA_USE); + NetCl_PlayerActionRequest(player, GPA_USE, 0); return; } diff --git a/doomsday/plugins/common/src/p_user.c b/doomsday/plugins/common/src/p_user.c index ec37e958aa..e3c72b44c0 100644 --- a/doomsday/plugins/common/src/p_user.c +++ b/doomsday/plugins/common/src/p_user.c @@ -615,7 +615,7 @@ void P_DeathThink(player_t* player) { if(IS_CLIENT) { - NetCl_PlayerActionRequest(player, GPA_USE); + NetCl_PlayerActionRequest(player, GPA_USE, 0); } else { @@ -1339,7 +1339,8 @@ void P_PlayerThinkWeapons(player_t* player) #else if(brain->changeWeapon != WT_NOCHANGE) #endif - { // Direct slot selection. + { + // Direct slot selection. weapontype_t cand, first; // Is this a same-slot weapon cycle? @@ -1364,16 +1365,24 @@ void P_PlayerThinkWeapons(player_t* player) first); } else if(brain->cycleWeapon) - { // Linear cycle. + { + // Linear cycle. newweapon = P_PlayerFindWeapon(player, brain->cycleWeapon < 0); } if(newweapon != WT_NOCHANGE && newweapon != player->readyWeapon) { - if(weaponInfo[newweapon][player->class_].mode[0].gameModeBits - & gameModeBits) + if(weaponInfo[newweapon][player->class_].mode[0].gameModeBits & gameModeBits) { - player->pendingWeapon = newweapon; + if(IS_CLIENT) + { + // Just send a request. + NetCl_PlayerActionRequest(player, GPA_CHANGE_WEAPON, newweapon); + } + else + { + player->pendingWeapon = newweapon; + } } } diff --git a/doomsday/plugins/jdoom/src/p_pspr.c b/doomsday/plugins/jdoom/src/p_pspr.c index f09307d0e1..be07368a3e 100644 --- a/doomsday/plugins/jdoom/src/p_pspr.c +++ b/doomsday/plugins/jdoom/src/p_pspr.c @@ -157,7 +157,7 @@ void P_FireWeapon(player_t *player) if(!P_CheckAmmo(player)) return; - NetCl_PlayerActionRequest(player, GPA_FIRE); + NetCl_PlayerActionRequest(player, GPA_FIRE, 0); // Psprite state. player->plr->pSprites[0].state = DDPSP_FIRE;