Skip to content

Commit a163b13

Browse files
committed
Included better Limit showing (Rounds, Minutes etc.)
1 parent 005c2c1 commit a163b13

File tree

1 file changed

+57
-16
lines changed

1 file changed

+57
-16
lines changed

opengsq/protocols/flatout2.py

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -270,26 +270,60 @@ def _extract_map_name(self, data: bytes, server_name: str) -> str:
270270
print(f"Error extracting map name: {e}")
271271
return "Unknown Map"
272272

273-
def _extract_lap_count(self, data: bytes) -> int:
273+
def _extract_game_limit(self, data: bytes, game_mode: str) -> dict:
274274
"""
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
278278
279279
: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
281282
"""
282283
try:
283284
if len(data) >= 1:
284285
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+
}
288314
else:
289-
return 0
315+
return {
316+
"lap_count": None,
317+
"time_limit": None,
318+
"has_limit": False
319+
}
290320
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+
}
293327

294328
def _parse_response(self, br: BinaryReader, original_data: bytes) -> Status:
295329
"""
@@ -320,10 +354,15 @@ def _parse_response(self, br: BinaryReader, original_data: bytes) -> Status:
320354
map_name = self._extract_map_name(original_data, server_name)
321355
info["map"] = map_name
322356

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"]
327366

328367
# Read server information
329368
timestamp = br.read_long_long() # Server timestamp
@@ -379,7 +418,9 @@ def _parse_response(self, br: BinaryReader, original_data: bytes) -> Status:
379418
info.setdefault("hostname", "Unknown Server")
380419
info.setdefault("game_mode", "Unknown")
381420
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)
383424
info.setdefault("max_players", 8)
384425
info.setdefault("current_players", 0)
385426
info.setdefault("timestamp", "0")

0 commit comments

Comments
 (0)