Browse Source

Fix parsing the premium status in newer login protocol versions

Closes #933
Kamil Chojnowski 2 years ago
parent
commit
2bb9fdc82b

+ 15
- 6
modules/client_entergame/characterlist.lua View File

@@ -254,12 +254,21 @@ function CharacterList.create(characters, account, otui)
254 254
   end
255 255
 
256 256
   -- account
257
-  if account.premDays > 0 and account.premDays < 65535 then
258
-    accountStatusLabel:setText(tr("Premium Account (%s) days left", account.premDays))
259
-  elseif account.premDays >= 65535 then
260
-    accountStatusLabel:setText(tr("Lifetime Premium Account"))
261
-  else
262
-    accountStatusLabel:setText(tr('Free Account'))
257
+  local status = ''
258
+  if account.status == AccountStatus.Frozen then
259
+    status = tr(' (Frozen)')
260
+  elseif account.status == AccountStatus.Suspended then
261
+    status = tr(' (Suspended)')
262
+  end
263
+
264
+  if account.subStatus == SubscriptionStatus.Free then
265
+    accountStatusLabel:setText(('%s%s'):format(tr('Free Account'), status))
266
+  elseif account.subStatus == SubscriptionStatus.Premium then
267
+    if account.premDays == 0 or account.premDays == 65535 then
268
+      accountStatusLabel:setText(('%s%s'):format(tr('Gratis Premium Account'), status))
269
+    else
270
+      accountStatusLabel:setText(('%s%s'):format(tr('Premium Account (%s) days left', account.premDays), status))
271
+    end
263 272
   end
264 273
 
265 274
   if account.premDays > 0 and account.premDays <= 7 then

+ 11
- 0
modules/gamelib/const.lua View File

@@ -322,4 +322,15 @@ StoreState = {
322 322
   Timed = 3
323 323
 }
324 324
 
325
+AccountStatus = {
326
+  Ok = 0,
327
+  Frozen = 1,
328
+  Suspended = 2,
329
+}
330
+
331
+SubscriptionStatus = {
332
+  Free = 0,
333
+  Premium = 1,
334
+}
335
+
325 336
 -- @}

+ 15
- 2
modules/gamelib/protocollogin.lua View File

@@ -240,7 +240,20 @@ function ProtocolLogin:parseCharacterList(msg)
240 240
   end
241 241
 
242 242
   local account = {}
243
-  account.premDays = msg:getU16()
243
+  if g_game.getProtocolVersion() > 1077 then
244
+    account.status = msg:getU8()
245
+    account.subStatus = msg:getU8()
246
+
247
+    account.premDays = msg:getU32()
248
+    if account.premDays ~= 0 and account.premDays ~= 65535 then
249
+      account.premDays = math.floor((account.premDays - os.time()) / 86400)
250
+    end
251
+  else
252
+    account.status = AccountStatus.Ok
253
+    account.premDays = msg:getU16()
254
+    account.subStatus = account.premDays > 0 and SubscriptionStatus.Premium or SubscriptionStatus.Free
255
+  end
256
+
244 257
   signalcall(self.onCharacterList, self, characters, account)
245 258
 end
246 259
 
@@ -258,4 +271,4 @@ end
258 271
 function ProtocolLogin:onError(msg, code)
259 272
   local text = translateNetworkError(code, self:isConnecting(), msg)
260 273
   signalcall(self.onLoginError, self, text)
261
-end
274
+end

Loading…
Cancel
Save