Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions server/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ def message(self):
"moderation@faforever.com</i>"
)

def to_notice(self):
"""
Return a localized notice payload with a legacy text fallback.
"""
return {
"command": "notice",
"style": "error",
"text": self.message(),
"localization_key": "ban.error",
"ban_reason": self.ban_reason,
"ban_expires_at": self.ban_expiry.isoformat(),
}

def _ban_duration_text(self):
ban_duration = self.ban_expiry - datetime_now()
if ban_duration.days > 365 * 100:
Expand Down
6 changes: 1 addition & 5 deletions server/lobbyconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,7 @@ async def on_message_received(self, message):
"text": e.message
})
except BanError as e:
await self.send({
"command": "notice",
"style": "error",
"text": e.message()
})
await self.send(e.to_notice())
await self.abort(e.message())
except ClientError as e:
self._logger.warning(
Expand Down
6 changes: 6 additions & 0 deletions tests/integration_tests/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ async def test_server_ban(lobby_server, user):
assert msg == {
"command": "notice",
"style": "error",
"localization_key": "ban.error",
"ban_reason": "Test permanent ban",
"ban_expires_at": "9999-12-31T23:59:59+00:00",
"text": (
"You are banned from FAF forever. <br>Reason: <br>Test permanent ban"
"<br><br><i>If you would like to appeal this ban, please send an "
Expand Down Expand Up @@ -76,6 +79,9 @@ async def test_server_ban_token(lobby_server, user, jwk_priv_key, jwk_kid):
assert msg == {
"command": "notice",
"style": "error",
"localization_key": "ban.error",
"ban_reason": "Test permanent ban",
"ban_expires_at": "9999-12-31T23:59:59+00:00",
"text": (
"You are banned from FAF forever. <br>Reason: <br>Test permanent ban"
"<br><br><i>If you would like to appeal this ban, please send an "
Expand Down