@@ -270,26 +270,60 @@ def _extract_map_name(self, data: bytes, server_name: str) -> str:
270
270
print (f"Error extracting map name: { e } " )
271
271
return "Unknown Map"
272
272
273
- def _extract_lap_count (self , data : bytes ) -> int :
273
+ def _extract_game_limit (self , data : bytes , game_mode : str ) -> dict :
274
274
"""
275
- Extracts the lap count from the payload data.
276
- Lap count is encoded in the end byte (offset 96, last byte).
277
- Formula: lap_count = (end_byte & 0xF0) >> 4
275
+ Extracts the game limit from the payload data.
276
+ The limit is encoded in the end byte (offset 96, last byte) and depends on game mode .
277
+ Formula: limit = (end_byte & 0xF0) >> 4
278
278
279
279
:param data: The complete response data
280
- :return: The lap count or 0 if not found
280
+ :param game_mode: The game mode (Race, Derby, Stunt)
281
+ :return: Dictionary with limit information or defaults if not found
281
282
"""
282
283
try :
283
284
if len (data ) >= 1 :
284
285
end_byte = data [- 1 ] # Last byte (offset 96)
285
- # Extract lap count from upper 4 bits
286
- lap_count = (end_byte & 0xF0 ) >> 4
287
- return lap_count
286
+ # Extract limit from upper 4 bits
287
+ limit_value = (end_byte & 0xF0 ) >> 4
288
+
289
+ if game_mode == "Race" :
290
+ return {
291
+ "lap_count" : limit_value ,
292
+ "time_limit" : None ,
293
+ "has_limit" : True
294
+ }
295
+ elif game_mode == "Derby" :
296
+ return {
297
+ "lap_count" : None ,
298
+ "time_limit" : limit_value , # Minutes
299
+ "has_limit" : True
300
+ }
301
+ elif game_mode == "Stunt" :
302
+ return {
303
+ "lap_count" : None ,
304
+ "time_limit" : None ,
305
+ "has_limit" : False
306
+ }
307
+ else :
308
+ # Unknown game mode, return raw value
309
+ return {
310
+ "lap_count" : limit_value ,
311
+ "time_limit" : None ,
312
+ "has_limit" : True
313
+ }
288
314
else :
289
- return 0
315
+ return {
316
+ "lap_count" : None ,
317
+ "time_limit" : None ,
318
+ "has_limit" : False
319
+ }
290
320
except Exception as e :
291
- print (f"Error extracting lap count: { e } " )
292
- return 0
321
+ print (f"Error extracting game limit: { e } " )
322
+ return {
323
+ "lap_count" : None ,
324
+ "time_limit" : None ,
325
+ "has_limit" : False
326
+ }
293
327
294
328
def _parse_response (self , br : BinaryReader , original_data : bytes ) -> Status :
295
329
"""
@@ -320,10 +354,15 @@ def _parse_response(self, br: BinaryReader, original_data: bytes) -> Status:
320
354
map_name = self ._extract_map_name (original_data , server_name )
321
355
info ["map" ] = map_name
322
356
323
- # Extract lap count from the payload
324
- # Lap count is encoded in the end byte (offset 96)
325
- lap_count = self ._extract_lap_count (original_data )
326
- info ["lap_count" ] = lap_count
357
+ # Extract game limits from the payload
358
+ # Limit is encoded in the end byte (offset 96) and depends on game mode:
359
+ # - Race: lap_count (number of laps)
360
+ # - Derby: time_limit (minutes)
361
+ # - Stunt: no limit (unlimited play time)
362
+ game_limits = self ._extract_game_limit (original_data , game_mode )
363
+ info ["lap_count" ] = game_limits ["lap_count" ]
364
+ info ["time_limit" ] = game_limits ["time_limit" ]
365
+ info ["has_limit" ] = game_limits ["has_limit" ]
327
366
328
367
# Read server information
329
368
timestamp = br .read_long_long () # Server timestamp
@@ -379,7 +418,9 @@ def _parse_response(self, br: BinaryReader, original_data: bytes) -> Status:
379
418
info .setdefault ("hostname" , "Unknown Server" )
380
419
info .setdefault ("game_mode" , "Unknown" )
381
420
info .setdefault ("map" , "Unknown Map" )
382
- info .setdefault ("lap_count" , 0 )
421
+ info .setdefault ("lap_count" , None )
422
+ info .setdefault ("time_limit" , None )
423
+ info .setdefault ("has_limit" , False )
383
424
info .setdefault ("max_players" , 8 )
384
425
info .setdefault ("current_players" , 0 )
385
426
info .setdefault ("timestamp" , "0" )
0 commit comments