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
2 changes: 1 addition & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 notice(self):
return {
"command": "notice",
"style": "error",
"text": self.message(),
"i18n_key": "login.error.banned",
"i18n_args": [
self.ban_expiry.isoformat(),
self.ban_reason
],
"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.notice())
await self.abort(e.message())
except ClientError as e:
self._logger.warning(
Expand Down
2 changes: 1 addition & 1 deletion server/protocol/qdatastream.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def pack_message(*args: str) -> bytes:
raise NotImplementedError("Only string serialization is supported")

msg += QDataStreamProtocol.pack_qstring(arg)
return QDataStreamProtocol.pack_block(msg)
return QDataStreamProtocol.pack_block(bytes(msg))

@staticmethod
def encode_message(message: dict) -> bytes:
Expand Down
36 changes: 18 additions & 18 deletions tests/integration_tests/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ async def test_server_ban(lobby_server, user):
proto = await connect_client(lobby_server)
await perform_login(proto, user)
msg = await proto.read_message()
assert msg == {
"command": "notice",
"style": "error",
"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 "
"email to: moderation@faforever.com</i>"
)
}
assert msg["command"] == "notice"
assert msg["style"] == "error"
assert msg["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 "
"email to: moderation@faforever.com</i>"
)
assert msg["i18n_key"] == "login.error.banned"
assert msg["i18n_args"] == [msg["expires_at"], "Test permanent ban"]


@pytest.mark.parametrize("user", [
Expand All @@ -73,15 +73,15 @@ async def test_server_ban_token(lobby_server, user, jwk_priv_key, jwk_kid):
"unique_id": "some_id"
})
msg = await proto.read_message()
assert msg == {
"command": "notice",
"style": "error",
"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 "
"email to: moderation@faforever.com</i>"
)
}
assert msg["command"] == "notice"
assert msg["style"] == "error"
assert msg["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 "
"email to: moderation@faforever.com</i>"
)
assert msg["i18n_key"] == "login.error.banned"
assert msg["i18n_args"] == [msg["expires_at"], "Test permanent ban"]


@pytest.mark.parametrize("user", ["ban_revoked", "ban_expired"])
Expand Down
18 changes: 9 additions & 9 deletions tests/integration_tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,15 +845,15 @@ async def test_server_ban_prevents_hosting(lobby_server, database, command):
await proto.send_message({"command": command})

msg = await proto.read_message()
assert msg == {
"command": "notice",
"style": "error",
"text": (
"You are banned from FAF forever. <br>Reason: <br>Test live ban<br>"
"<br><i>If you would like to appeal this ban, please send an email "
"to: moderation@faforever.com</i>"
)
}
assert msg["command"] == "notice"
assert msg["style"] == "error"
assert msg["i18n_key"] == "login.error.banned"
assert msg["i18n_args"] == [msg["expires_at"], "Test live ban"]
assert msg["text"] == (
"You are banned from FAF forever. <br>Reason: <br>Test live ban<br>"
"<br><i>If you would like to appeal this ban, please send an email "
"to: moderation@faforever.com</i>"
)


@fast_forward(5)
Expand Down
11 changes: 11 additions & 0 deletions tests/unit_tests/test_lobbyconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,17 @@ async def test_abort_connection_if_banned(
"<br><br><i>If you would like to appeal this ban, please send an email "
"to: moderation@faforever.com</i>"
)
assert banned_error.value.notice() == {
"command": "notice",
"style": "error",
"text": banned_error.value.message(),
"i18n_key": "login.error.banned",
"i18n_args": [
banned_error.value.ban_expiry.isoformat(),
"Test permanent ban"
],
"expires_at": banned_error.value.ban_expiry.isoformat()
}

# test user who is banned for another 46 hours
lobbyconnection.player.id = 204
Expand Down
Loading