From ffd01051033168df426df6027ffcb409f4ab537b Mon Sep 17 00:00:00 2001 From: skyjake Date: Fri, 23 Dec 2011 11:46:53 +0200 Subject: [PATCH] Server: Fixed weapon change mixup The server should not redo the weapon change logic as it already have been done by the client. Fixes the problem where the client's DB Shotgun was performing like a normal Shotgun (server had re-swapped it back to the other slot). --- doomsday/plugins/common/include/common.h | 2 ++ doomsday/plugins/common/src/mobj.c | 2 +- doomsday/plugins/common/src/p_player.c | 2 +- doomsday/plugins/common/src/p_user.c | 19 ++++++++++++++++--- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/doomsday/plugins/common/include/common.h b/doomsday/plugins/common/include/common.h index ee18176e23..a2ae46614c 100644 --- a/doomsday/plugins/common/include/common.h +++ b/doomsday/plugins/common/include/common.h @@ -26,6 +26,8 @@ #define WEAPONBOTTOM (128) // from p_pspr.c +#define IS_NETWORK_SERVER (DD_GetInteger(DD_SERVER) && DD_GetInteger(DD_NETGAME)) + #if __JDOOM__ # include "jdoom.h" #elif __JDOOM64__ diff --git a/doomsday/plugins/common/src/mobj.c b/doomsday/plugins/common/src/mobj.c index fdc51e21b8..fbb1d9e15f 100644 --- a/doomsday/plugins/common/src/mobj.c +++ b/doomsday/plugins/common/src/mobj.c @@ -126,7 +126,7 @@ void Mobj_XYMoveStopping(mobj_t* mo) // Stop player walking animation (only real players). if(!isVoodooDoll && player && belowStandSpeed && !isMovingPlayer && - !(IS_NETGAME && IS_SERVER)) // Netgame servers use logic elsewhere for player animation. + !IS_NETWORK_SERVER) // Netgame servers use logic elsewhere for player animation. { // If in a walking frame, stop moving. if(P_PlayerInWalkState(player)) diff --git a/doomsday/plugins/common/src/p_player.c b/doomsday/plugins/common/src/p_player.c index 14510e5e28..f47ba38b7b 100644 --- a/doomsday/plugins/common/src/p_player.c +++ b/doomsday/plugins/common/src/p_player.c @@ -407,7 +407,7 @@ weapontype_t P_MaybeChangeWeapon(player_t *player, weapontype_t weapon, weaponinfo_t *winf; boolean found; - if(IS_NETGAME && IS_SERVER) + if(IS_NETWORK_SERVER) { // This is done on clientside. NetSv_MaybeChangeWeapon(player - players, weapon, ammo, force); diff --git a/doomsday/plugins/common/src/p_user.c b/doomsday/plugins/common/src/p_user.c index 4c974cafa6..0537d74ed7 100644 --- a/doomsday/plugins/common/src/p_user.c +++ b/doomsday/plugins/common/src/p_user.c @@ -473,7 +473,7 @@ void P_MovePlayer(player_t *player) if(!plrmo) return; - if(IS_NETGAME && IS_SERVER) + if(IS_NETWORK_SERVER) { // Server starts the walking animation for remote players. if((!FEQUAL(dp->forwardMove, 0) || !FEQUAL(dp->sideMove, 0)) && @@ -1313,6 +1313,19 @@ void P_PlayerThinkWeapons(player_t* player) weapontype_t oldweapon = player->pendingWeapon; weapontype_t newweapon = WT_NOCHANGE; + if(IS_NETWORK_SERVER) + { + // Weapon change logic has already been done by the client. + newweapon = brain->changeWeapon; + + if(!player->weapons[newweapon].owned) + { + Con_Message("P_PlayerThinkWeapons: Player %i tried to change to unowned weapon %i!\n", + (int)(player - players), newweapon); + newweapon = WT_NOCHANGE; + } + } + else // Check for weapon change. #if __JHERETIC__ || __JHEXEN__ if(brain->changeWeapon != WT_NOCHANGE && !player->morphTics) @@ -1321,7 +1334,7 @@ void P_PlayerThinkWeapons(player_t* player) #endif { // Direct slot selection. - weapontype_t cand, first; + weapontype_t cand, first; // Is this a same-slot weapon cycle? if(P_GetWeaponSlot(brain->changeWeapon) == @@ -1382,7 +1395,7 @@ void P_PlayerThinkWeapons(player_t* player) void P_PlayerThinkUse(player_t *player) { - if(IS_NETGAME && IS_SERVER && player != &players[CONSOLEPLAYER]) + if(IS_NETWORK_SERVER && player != &players[CONSOLEPLAYER]) { // Clients send use requests instead. return;