Feature #501 ยป 0002-packets-rename-cancel-to-reset.patch
common/generate_packets.py | ||
---|---|---|
return self.packet.is_info
|
||
@property
|
||
def cancel(self) -> "list[str]":
|
||
"""List of packets to cancel when sending or receiving this packet
|
||
def reset_packets(self) -> "list[str]":
|
||
"""List of packets to reset when sending or receiving this packet
|
||
See Packet.cancel"""
|
||
return self.packet.cancel
|
||
See Packet.reset_packets"""
|
||
return self.packet.reset_packets
|
||
@property
|
||
def complex(self) -> bool:
|
||
... | ... | |
copy_to_old = self.get_copy("old", "real_packet")
|
||
# Cancel some is-info packets.
|
||
cancel_part = "".join(
|
||
# Reset some packets' delta state
|
||
reset_part = "".join(
|
||
f"""\
|
||
hash = pc->phs.sent + {cancel_packet_type};
|
||
hash = pc->phs.sent + {reset_packet};
|
||
if (nullptr != *hash) {{
|
||
genhash_remove(*hash, real_packet);
|
||
}}
|
||
"""
|
||
for cancel_packet_type in self.cancel
|
||
for reset_packet in self.reset_packets
|
||
)
|
||
return f"""\
|
||
... | ... | |
{put_other}\
|
||
{copy_to_old}\
|
||
{cancel_part}\
|
||
{reset_part}\
|
||
"""
|
||
def get_receive(self) -> str:
|
||
... | ... | |
for i, field in enumerate(self.other_fields)
|
||
)
|
||
# Cancel some is-info packets.
|
||
cancel_part = "".join(
|
||
# Reset some packets' delta state
|
||
reset_part = "".join(
|
||
f"""\
|
||
hash = pc->phs.received + {cancel_pack};
|
||
hash = pc->phs.received + {reset_packet};
|
||
if (nullptr != *hash) {{
|
||
genhash_remove(*hash, real_packet);
|
||
}}
|
||
"""
|
||
for cancel_pack in self.cancel
|
||
for reset_packet in self.reset_packets
|
||
)
|
||
return f"""\
|
||
... | ... | |
}} else {{
|
||
{copy_to_old}\
|
||
}}
|
||
{cancel_part}\
|
||
{reset_part}\
|
||
"""
|
||
... | ... | |
class Packet:
|
||
"""Represents a single packet type (possibly with multiple variants)"""
|
||
CANCEL_PATTERN = re.compile(r"^cancel\((.*)\)$")
|
||
"""Matches a cancel flag
|
||
RESET_PATTERN = re.compile(r"^reset\((.*)\)$")
|
||
"""Matches a reset flag
|
||
Groups:
|
||
- the packet type to cancel"""
|
||
- the packet type to reset"""
|
||
cfg: ScriptConfig
|
||
"""Configuration used when generating code for this packet"""
|
||
... | ... | |
type_number: int
|
||
"""The numeric ID of this packet type"""
|
||
cancel: "list[str]"
|
||
reset_packets: "list[str]"
|
||
"""List of packet types to drop from the cache when sending or
|
||
receiving this packet type"""
|
||
... | ... | |
self.type = packet_type
|
||
self.type_number = packet_number
|
||
self.cancel = []
|
||
self.reset_packets = []
|
||
dirs: 'set[typing.Literal["sc", "cs"]]' = set()
|
||
for flag in flags_text.split(","):
|
||
... | ... | |
self.handle_per_conn = True
|
||
continue
|
||
mo = __class__.CANCEL_PATTERN.fullmatch(flag)
|
||
mo = __class__.RESET_PATTERN.fullmatch(flag)
|
||
if mo is not None:
|
||
self.cancel.append(mo.group(1))
|
||
self.reset_packets.append(mo.group(1))
|
||
continue
|
||
raise ValueError(f"unrecognized flag for {self.type}: {flag!r}")
|
common/networking/packets.def | ||
---|---|---|
effect if the packets doesn't have the is-info or is-game-info
|
||
flags.
|
||
cancel(PACKET_number): Cancel a packet with the same key (must be the
|
||
same key type at the start of the packet), useful for is-info packets.
|
||
reset(PACKET_number): Reset the stored delta state of a packet with
|
||
the same key (must be the same key fields at the start of the packet);
|
||
useful for is-info packets.
|
||
pre-send:
|
||
post-recv:
|
||
... | ... | |
/************** City packets **********************/
|
||
PACKET_CITY_REMOVE = 30; sc, dsend, lsend, cancel(PACKET_CITY_INFO), cancel(PACKET_WEB_CITY_INFO_ADDITION), cancel(PACKET_CITY_NATIONALITIES), cancel(PACKET_CITY_RALLY_POINT), cancel(PACKET_CITY_SHORT_INFO), handle-via-fields
|
||
PACKET_CITY_REMOVE = 30; sc, dsend, lsend, reset(PACKET_CITY_INFO), reset(PACKET_WEB_CITY_INFO_ADDITION), reset(PACKET_CITY_NATIONALITIES), reset(PACKET_CITY_RALLY_POINT), reset(PACKET_CITY_SHORT_INFO), handle-via-fields
|
||
CITY city_id;
|
||
end
|
||
PACKET_CITY_INFO = 31; sc, lsend, is-game-info, force, cancel(PACKET_CITY_SHORT_INFO)
|
||
PACKET_CITY_INFO = 31; sc, lsend, is-game-info, force, reset(PACKET_CITY_SHORT_INFO)
|
||
CITY id; key
|
||
TILE tile;
|
||
... | ... | |
COUNTER counters[MAX_COUNTERS:count];
|
||
end
|
||
PACKET_CITY_SHORT_INFO = 32; sc, lsend, is-game-info, cancel(PACKET_CITY_INFO), cancel(PACKET_WEB_CITY_INFO_ADDITION), cancel(PACKET_CITY_NATIONALITIES), cancel(PACKET_CITY_RALLY_POINT)
|
||
PACKET_CITY_SHORT_INFO = 32; sc, lsend, is-game-info, reset(PACKET_CITY_INFO), reset(PACKET_WEB_CITY_INFO_ADDITION), reset(PACKET_CITY_NATIONALITIES), reset(PACKET_CITY_RALLY_POINT)
|
||
CITY id; key
|
||
TILE tile;
|
||
... | ... | |
/************** Player packets **********************/
|
||
PACKET_PLAYER_REMOVE = 50; sc, dsend, cancel(PACKET_PLAYER_INFO), handle-via-fields
|
||
PACKET_PLAYER_REMOVE = 50; sc, dsend, reset(PACKET_PLAYER_INFO), handle-via-fields
|
||
PLAYER playerno;
|
||
end
|
||
... | ... | |
STRING inventions[A_LAST + 1];
|
||
end
|
||
PACKET_UNKNOWN_RESEARCH = 66; sc, is-game-info, handle-via-fields, cancel(PACKET_RESEARCH_INFO)
|
||
PACKET_UNKNOWN_RESEARCH = 66; sc, is-game-info, handle-via-fields, reset(PACKET_RESEARCH_INFO)
|
||
RESEARCH id;
|
||
end
|
||
... | ... | |
/************** Unit packets **********************/
|
||
PACKET_UNIT_REMOVE = 62; sc, dsend, lsend, cancel(PACKET_UNIT_INFO), cancel(PACKET_UNIT_SHORT_INFO), handle-via-fields
|
||
PACKET_UNIT_REMOVE = 62; sc, dsend, lsend, reset(PACKET_UNIT_INFO), reset(PACKET_UNIT_SHORT_INFO), handle-via-fields
|
||
UNIT unit_id;
|
||
end
|
||
PACKET_UNIT_INFO = 63; sc, lsend, is-game-info, cancel(PACKET_UNIT_SHORT_INFO)
|
||
PACKET_UNIT_INFO = 63; sc, lsend, is-game-info, reset(PACKET_UNIT_SHORT_INFO)
|
||
UNIT id; key
|
||
PLAYER owner;
|
||
PLAYER nationality;
|
||
... | ... | |
TILE action_decision_tile;
|
||
end
|
||
PACKET_UNIT_SHORT_INFO = 64; sc, lsend, is-game-info, force, cancel(PACKET_UNIT_INFO)
|
||
PACKET_UNIT_SHORT_INFO = 64; sc, lsend, is-game-info, force, reset(PACKET_UNIT_INFO)
|
||
UNIT id; key
|
||
PLAYER owner;
|
||
TILE tile;
|
||
... | ... | |
/*************** Webclient specific packets ****************/
|
||
/* Use range 256:511 for these */
|
||
PACKET_WEB_CITY_INFO_ADDITION = 256; sc, lsend, is-game-info, force, cancel(PACKET_CITY_SHORT_INFO), handle-via-fields, no-handle
|
||
PACKET_WEB_CITY_INFO_ADDITION = 256; sc, lsend, is-game-info, force, reset(PACKET_CITY_SHORT_INFO), handle-via-fields, no-handle
|
||
CITY id; key
|
||
BOOL cma_enabled;
|