From 2693099db768480693bc6b483950e62a29a3b150 Mon Sep 17 00:00:00 2001 From: Alina Lenk Date: Sat, 27 Apr 2024 02:51:19 +0200 Subject: [PATCH 2/2] packets: rename "cancel" to "reset" See RM #501 Signed-off-by: Alina Lenk --- common/generate_packets.py | 42 +++++++++++++++++------------------ common/networking/packets.def | 23 ++++++++++--------- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/common/generate_packets.py b/common/generate_packets.py index c3bba29375..5dd756e5a6 100755 --- a/common/generate_packets.py +++ b/common/generate_packets.py @@ -2502,11 +2502,11 @@ class Variant: 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: @@ -2913,16 +2913,16 @@ if (different == 0) {{ 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"""\ @@ -2957,7 +2957,7 @@ if (e) {{ {put_other}\ {copy_to_old}\ -{cancel_part}\ +{reset_part}\ """ def get_receive(self) -> str: @@ -3062,16 +3062,16 @@ if (e) {{ 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"""\ @@ -3097,7 +3097,7 @@ if (nullptr == old) {{ }} else {{ {copy_to_old}\ }} -{cancel_part}\ +{reset_part}\ """ @@ -3130,11 +3130,11 @@ class Directions(Enum): 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""" @@ -3148,7 +3148,7 @@ class 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""" @@ -3214,7 +3214,7 @@ class Packet: 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(","): @@ -3262,9 +3262,9 @@ class Packet: 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}") diff --git a/common/networking/packets.def b/common/networking/packets.def index 686343fbc5..235b9f252a 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -89,8 +89,9 @@ Syntax: 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: @@ -708,11 +709,11 @@ end /************** 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; @@ -794,7 +795,7 @@ PACKET_CITY_UPDATE_COUNTERS = 514; sc, lsend, is-game-info 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; @@ -915,7 +916,7 @@ end /************** 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 @@ -1034,7 +1035,7 @@ PACKET_RESEARCH_INFO = 60; sc, lsend, is-game-info 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 @@ -1048,11 +1049,11 @@ 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; @@ -1094,7 +1095,7 @@ PACKET_UNIT_INFO = 63; sc, lsend, is-game-info, cancel(PACKET_UNIT_SHORT_INFO) 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; @@ -2417,7 +2418,7 @@ end /*************** 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; -- 2.34.1