Skip to content

Commit c328a55

Browse files
committed
Move get_messages() from ServerGame to Game
This allows the method to be used by clients, preventing them from ever needing to interact with the unfiltered `Game.messages` field. Hopefully, this prevents any accidental message leakage.
1 parent 224ac10 commit c328a55

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

diplomacy/engine/game.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,12 @@ def is_advice_for_role(message: Message) -> bool:
996996
or message.sender in game_role
997997
}
998998

999+
def get_messages(self, game_role, timestamp_from=None, timestamp_to=None):
1000+
"""Return a filtered dict of current messages for given output game role.
1001+
See method filter_messages() about parameters.
1002+
"""
1003+
return self.filter_messages(self.messages, game_role, timestamp_from, timestamp_to)
1004+
9991005
def get_phase_history(self, from_phase=None, to_phase=None, game_role=None):
10001006
"""Return a list of game phase data from game history between given phases (bounds included).
10011007
Each GamePhaseData object contains game state, messages, orders and order results for a phase.

diplomacy/server/server_game.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,6 @@ def game_can_start(self):
152152
"""
153153
return self.is_game_forming and not self.start_master and self.has_expected_controls_count()
154154

155-
def get_messages(self, game_role, timestamp_from=None, timestamp_to=None):
156-
"""Return a filtered dict of current messages for given output game role.
157-
See method filter_messages() about parameters.
158-
"""
159-
return self.filter_messages(self.messages, game_role, timestamp_from, timestamp_to)
160-
161155
def get_message_history(self, game_role):
162156
"""Return a filtered dict of whole message history for given game role."""
163157
return {

0 commit comments

Comments
 (0)