Skip to content

Commit 6c37e89

Browse files
sapiersapier
sapier
authored and
sapier
committedMay 11, 2014
Fix old client showing duplicated health bar on new server
Fix client not showing hearts and bubbles on connecting to old server Fix server not remembering hud flags correctly
1 parent 167df02 commit 6c37e89

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed
 

‎builtin/game/statbars.lua

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ local function initialize_builtin_statbars(player)
3737

3838
if (hud_ids[name] == nil) then
3939
hud_ids[name] = {}
40+
-- flags are not transmitted to client on connect, we need to make sure
41+
-- our current flags are transmitted by sending them actively
42+
player:hud_set_flags(player:hud_get_flags())
4043
end
4144

4245
if player:hud_get_flags().healthbar and

‎src/hud.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,23 @@ void Hud::drawHotbar(u16 playeritem) {
414414
drawItems(secondpos, hotbar_itemcount, hotbar_itemcount/2, mainlist, playeritem + 1, 0);
415415
}
416416
}
417+
418+
//////////////////////////// compatibility code to be removed //////////////
419+
// this is ugly as hell but there's no other way to keep compatibility to
420+
// old servers
421+
if ( player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE)
422+
drawStatbar(v2s32(floor(0.5 * (float) m_screensize.X + 0.5),
423+
floor(1 * (float) m_screensize.Y + 0.5)),
424+
HUD_CORNER_UPPER, 0, "heart.png",
425+
player->hp, v2s32((-10*24)-25,-(48+24+10)), v2s32(24,24));
426+
427+
if ((player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE) &&
428+
(player->getBreath() < 11))
429+
drawStatbar(v2s32(floor(0.5 * (float) m_screensize.X + 0.5),
430+
floor(1 * (float) m_screensize.Y + 0.5)),
431+
HUD_CORNER_UPPER, 0, "heart.png",
432+
player->getBreath(), v2s32(25,-(48+24+10)), v2s32(24,24));
433+
////////////////////////////////////////////////////////////////////////////
417434
}
418435

419436

‎src/server.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -3357,6 +3357,10 @@ void Server::SendHUDSetFlags(u16 peer_id, u32 flags, u32 mask)
33573357

33583358
// Write command
33593359
writeU16(os, TOCLIENT_HUD_SET_FLAGS);
3360+
3361+
//////////////////////////// compatibility code to be removed //////////////
3362+
flags &= ~(HUD_FLAG_HEALTHBAR_VISIBLE | HUD_FLAG_BREATHBAR_VISIBLE);
3363+
////////////////////////////////////////////////////////////////////////////
33603364
writeU32(os, flags);
33613365
writeU32(os, mask);
33623366

@@ -4591,6 +4595,7 @@ bool Server::hudSetFlags(Player *player, u32 flags, u32 mask) {
45914595
return false;
45924596

45934597
SendHUDSetFlags(player->peer_id, flags, mask);
4598+
player->hud_flags = flags;
45944599

45954600
m_script->player_event(player->getPlayerSAO(),"hud_changed");
45964601
return true;

0 commit comments

Comments
 (0)
Please sign in to comment.