Skip to content

Commit

Permalink
Merge pull request #934 from diath/fix_login_protocol
Browse files Browse the repository at this point in the history
Fix parsing the premium status in newer login protocol versions
  • Loading branch information
TheSumm authored Jul 12, 2018
2 parents 1addf3e + 2bb9fdc commit 07b4b78
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
21 changes: 15 additions & 6 deletions modules/client_entergame/characterlist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions modules/gamelib/const.lua
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,15 @@ StoreState = {
Timed = 3
}

AccountStatus = {
Ok = 0,
Frozen = 1,
Suspended = 2,
}

SubscriptionStatus = {
Free = 0,
Premium = 1,
}

-- @}
17 changes: 15 additions & 2 deletions modules/gamelib/protocollogin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -258,4 +271,4 @@ end
function ProtocolLogin:onError(msg, code)
local text = translateNetworkError(code, self:isConnecting(), msg)
signalcall(self.onLoginError, self, text)
end
end

0 comments on commit 07b4b78

Please sign in to comment.