Fix old client showing duplicated health bar on new server
authorsapier <Sapier at GMX dot net>
Sat, 10 May 2014 22:35:31 +0000 (00:35 +0200)
committersapier <Sapier at GMX dot net>
Sun, 11 May 2014 20:34:44 +0000 (22:34 +0200)
Fix client not showing hearts and bubbles on connecting to old server
Fix server not remembering hud flags correctly

builtin/game/statbars.lua
src/hud.cpp
src/server.cpp

index ccc192ba4098dfe7b55a1f29d47916daa766106d..c0d49332f8896b3b99bbafc4a6e877b1b75b4171 100644 (file)
@@ -37,6 +37,9 @@ local function initialize_builtin_statbars(player)
 
        if (hud_ids[name] == nil) then
                hud_ids[name] = {}
+               -- flags are not transmitted to client on connect, we need to make sure
+               -- our current flags are transmitted by sending them actively
+               player:hud_set_flags(player:hud_get_flags())
        end
 
        if player:hud_get_flags().healthbar and
index f1d7a32584ca1b483a27472d0cdfb938d322cb0b..7b601ec87e98cfe98290e8c30418e234b98d2a3d 100644 (file)
@@ -414,6 +414,23 @@ void Hud::drawHotbar(u16 playeritem) {
                        drawItems(secondpos, hotbar_itemcount, hotbar_itemcount/2, mainlist, playeritem + 1, 0);
                }
        }
+
+       //////////////////////////// compatibility code to be removed //////////////
+       // this is ugly as hell but there's no other way to keep compatibility to
+       // old servers
+       if ( player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE)
+               drawStatbar(v2s32(floor(0.5 * (float) m_screensize.X + 0.5),
+                               floor(1 * (float) m_screensize.Y + 0.5)),
+                               HUD_CORNER_UPPER, 0, "heart.png",
+                               player->hp, v2s32((-10*24)-25,-(48+24+10)), v2s32(24,24));
+
+       if ((player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE) &&
+                       (player->getBreath() < 11))
+               drawStatbar(v2s32(floor(0.5 * (float) m_screensize.X + 0.5),
+                               floor(1 * (float) m_screensize.Y + 0.5)),
+                               HUD_CORNER_UPPER, 0, "heart.png",
+                               player->getBreath(), v2s32(25,-(48+24+10)), v2s32(24,24));
+       ////////////////////////////////////////////////////////////////////////////
 }
 
 
index 22efca67082e54fe02d0b4be85c109a1dbb0a1a1..d29512d87bb49e832fd7ae743878aefc9fbc9cab 100644 (file)
@@ -3357,6 +3357,10 @@ void Server::SendHUDSetFlags(u16 peer_id, u32 flags, u32 mask)
 
        // Write command
        writeU16(os, TOCLIENT_HUD_SET_FLAGS);
+
+       //////////////////////////// compatibility code to be removed //////////////
+       flags &= ~(HUD_FLAG_HEALTHBAR_VISIBLE | HUD_FLAG_BREATHBAR_VISIBLE);
+       ////////////////////////////////////////////////////////////////////////////
        writeU32(os, flags);
        writeU32(os, mask);
 
@@ -4591,6 +4595,7 @@ bool Server::hudSetFlags(Player *player, u32 flags, u32 mask) {
                return false;
 
        SendHUDSetFlags(player->peer_id, flags, mask);
+       player->hud_flags = flags;
 
        m_script->player_event(player->getPlayerSAO(),"hud_changed");
        return true;