From 2bb9fdc82b9a92d4c8792fcee07637f3bbdba293 Mon Sep 17 00:00:00 2001 From: Kamil Chojnowski Date: Mon, 1 Jan 2018 05:10:57 +0100 Subject: [PATCH] Fix parsing the premium status in newer login protocol versions Closes #933 --- modules/client_entergame/characterlist.lua | 21 +++++++++++++++------ modules/gamelib/const.lua | 11 +++++++++++ modules/gamelib/protocollogin.lua | 17 +++++++++++++++-- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/modules/client_entergame/characterlist.lua b/modules/client_entergame/characterlist.lua index a30f666a..c7e4001b 100644 --- a/modules/client_entergame/characterlist.lua +++ b/modules/client_entergame/characterlist.lua @@ -254,12 +254,21 @@ function CharacterList.create(characters, account, otui) end -- account - if account.premDays > 0 and account.premDays < 65535 then - accountStatusLabel:setText(tr("Premium Account (%s) days left", account.premDays)) - elseif account.premDays >= 65535 then - accountStatusLabel:setText(tr("Lifetime Premium Account")) - else - accountStatusLabel:setText(tr('Free Account')) + local status = '' + if account.status == AccountStatus.Frozen then + status = tr(' (Frozen)') + elseif account.status == AccountStatus.Suspended then + status = tr(' (Suspended)') + end + + if account.subStatus == SubscriptionStatus.Free then + accountStatusLabel:setText(('%s%s'):format(tr('Free Account'), status)) + elseif account.subStatus == SubscriptionStatus.Premium then + if account.premDays == 0 or account.premDays == 65535 then + accountStatusLabel:setText(('%s%s'):format(tr('Gratis Premium Account'), status)) + else + accountStatusLabel:setText(('%s%s'):format(tr('Premium Account (%s) days left', account.premDays), status)) + end end if account.premDays > 0 and account.premDays <= 7 then diff --git a/modules/gamelib/const.lua b/modules/gamelib/const.lua index 415ab67a..dbd18531 100644 --- a/modules/gamelib/const.lua +++ b/modules/gamelib/const.lua @@ -322,4 +322,15 @@ StoreState = { Timed = 3 } +AccountStatus = { + Ok = 0, + Frozen = 1, + Suspended = 2, +} + +SubscriptionStatus = { + Free = 0, + Premium = 1, +} + -- @} diff --git a/modules/gamelib/protocollogin.lua b/modules/gamelib/protocollogin.lua index 9d871aa4..8a1cf636 100644 --- a/modules/gamelib/protocollogin.lua +++ b/modules/gamelib/protocollogin.lua @@ -240,7 +240,20 @@ function ProtocolLogin:parseCharacterList(msg) end local account = {} - account.premDays = msg:getU16() + if g_game.getProtocolVersion() > 1077 then + account.status = msg:getU8() + account.subStatus = msg:getU8() + + account.premDays = msg:getU32() + if account.premDays ~= 0 and account.premDays ~= 65535 then + account.premDays = math.floor((account.premDays - os.time()) / 86400) + end + else + account.status = AccountStatus.Ok + account.premDays = msg:getU16() + account.subStatus = account.premDays > 0 and SubscriptionStatus.Premium or SubscriptionStatus.Free + end + signalcall(self.onCharacterList, self, characters, account) end @@ -258,4 +271,4 @@ end function ProtocolLogin:onError(msg, code) local text = translateNetworkError(code, self:isConnecting(), msg) signalcall(self.onLoginError, self, text) -end \ No newline at end of file +end