Skip to content

Commit 04b02a6

Browse files
authored
Add: support for Game Info v7 (#27)
1 parent 8fdafdf commit 04b02a6

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

openttd_protocol/protocol/coordinator.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
read_uint8,
99
read_uint16,
1010
read_uint32,
11+
read_uint64,
1112
)
1213
from ..wire.tcp import TCPProtocol
1314
from ..wire.write import (
@@ -19,6 +20,7 @@
1920
write_uint8,
2021
write_uint16,
2122
write_uint32,
23+
write_uint64,
2224
)
2325

2426
log = logging.getLogger(__name__)
@@ -136,9 +138,12 @@ def receive_PACKET_COORDINATOR_SERVER_UPDATE(source, data):
136138

137139
game_info_version, data = read_uint8(data)
138140

139-
if game_info_version < 1 or game_info_version > 6:
141+
if game_info_version < 1 or game_info_version > 7:
140142
raise PacketInvalidData("unknown game info version: ", game_info_version)
141143

144+
if game_info_version >= 7:
145+
ticks_playing, data = read_uint64(data)
146+
142147
if game_info_version >= 6:
143148
newgrf_serialization_type, data = read_uint8(data)
144149

@@ -213,6 +218,10 @@ def receive_PACKET_COORDINATOR_SERVER_UPDATE(source, data):
213218

214219
is_dedicated, data = read_uint8(data)
215220

221+
# Estimate, where possible, for older versions.
222+
if game_info_version < 7:
223+
ticks_playing = max(0, (start_date - game_date) * 74)
224+
216225
if len(data) != 0:
217226
raise PacketInvalidData("more bytes than expected in SERVER_UPDATE; remaining: ", len(data))
218227

@@ -237,6 +246,7 @@ def receive_PACKET_COORDINATOR_SERVER_UPDATE(source, data):
237246
"map_type": map_type,
238247
"gamescript_version": gamescript_version,
239248
"gamescript_name": gamescript_name,
249+
"ticks_playing": ticks_playing,
240250
}
241251

242252
@staticmethod
@@ -248,7 +258,7 @@ def receive_PACKET_COORDINATOR_CLIENT_LISTING(source, data):
248258

249259
game_info_version, data = read_uint8(data)
250260

251-
if game_info_version < 1 or game_info_version > 6:
261+
if game_info_version < 1 or game_info_version > 7:
252262
raise PacketInvalidData("unknown game info version: ", game_info_version)
253263

254264
openttd_version, data = read_string(data)
@@ -433,6 +443,9 @@ async def send_PACKET_COORDINATOR_GC_LISTING(
433443
write_string(data, server.connection_string)
434444
write_uint8(data, game_info_version)
435445

446+
if game_info_version >= 7:
447+
write_uint64(data, server.info["ticks_playing"])
448+
436449
if game_info_version >= 6:
437450
write_uint8(data, NewGRFSerializationType.NST_LOOKUP_ID)
438451

openttd_protocol/protocol/game.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
read_uint8,
99
read_uint16,
1010
read_uint32,
11+
read_uint64,
1112
)
1213
from ..wire.tcp import TCPProtocol
1314
from ..wire.write import (
@@ -56,9 +57,12 @@ class GameProtocol(TCPProtocol):
5657
def receive_PACKET_SERVER_GAME_INFO(source, data):
5758
game_info_version, data = read_uint8(data)
5859

59-
if game_info_version < 1 or game_info_version > 6:
60+
if game_info_version < 1 or game_info_version > 7:
6061
raise PacketInvalidData("unknown game info version: ", game_info_version)
6162

63+
if game_info_version >= 7:
64+
ticks_playing, data = read_uint64(data)
65+
6266
if game_info_version >= 6:
6367
newgrf_serialization_type, data = read_uint8(data)
6468

@@ -133,6 +137,10 @@ def receive_PACKET_SERVER_GAME_INFO(source, data):
133137

134138
is_dedicated, data = read_uint8(data)
135139

140+
# Estimate, where possible, for older versions.
141+
if game_info_version < 7:
142+
ticks_playing = max(0, (start_date - game_date) * 74)
143+
136144
if len(data) != 0:
137145
raise PacketInvalidData("more bytes than expected in SERVER_GAME_INFO; remaining: ", len(data))
138146

@@ -155,6 +163,7 @@ def receive_PACKET_SERVER_GAME_INFO(source, data):
155163
"map_type": map_type,
156164
"gamescript_version": gamescript_version,
157165
"gamescript_name": gamescript_name,
166+
"ticks_playing": ticks_playing,
158167
}
159168

160169
@staticmethod

0 commit comments

Comments
 (0)