diff --git a/Pipfile.lock b/Pipfile.lock
index 615d5a42b..91020093f 100644
--- a/Pipfile.lock
+++ b/Pipfile.lock
@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
- "sha256": "67adacda446396d91de50fe41c426c738226113aa0b3e3f16a00f2141ff7bc8a"
+ "sha256": "a187fb4a62ec0cc2dab78542af7c21eb559388bac49e0f84f35f656aa1e19200"
},
"pipfile-spec": 6,
"requires": {
diff --git a/server/exceptions.py b/server/exceptions.py
index ff7a7cc57..f31e27df9 100644
--- a/server/exceptions.py
+++ b/server/exceptions.py
@@ -39,6 +39,19 @@ def message(self):
"moderation@faforever.com"
)
+ 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:
diff --git a/server/lobbyconnection.py b/server/lobbyconnection.py
index 5b5ec2e10..17f581679 100644
--- a/server/lobbyconnection.py
+++ b/server/lobbyconnection.py
@@ -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(
diff --git a/server/protocol/qdatastream.py b/server/protocol/qdatastream.py
index 999d2313c..6adea3227 100644
--- a/server/protocol/qdatastream.py
+++ b/server/protocol/qdatastream.py
@@ -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:
diff --git a/tests/integration_tests/test_login.py b/tests/integration_tests/test_login.py
index 0d7c5c843..45f768bd7 100644
--- a/tests/integration_tests/test_login.py
+++ b/tests/integration_tests/test_login.py
@@ -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.
Reason:
Test permanent ban"
- "
If you would like to appeal this ban, please send an "
- "email to: moderation@faforever.com"
- )
- }
+ assert msg["command"] == "notice"
+ assert msg["style"] == "error"
+ assert msg["text"] == (
+ "You are banned from FAF forever.
Reason:
Test permanent ban"
+ "
If you would like to appeal this ban, please send an "
+ "email to: moderation@faforever.com"
+ )
+ assert msg["i18n_key"] == "login.error.banned"
+ assert msg["i18n_args"] == [msg["expires_at"], "Test permanent ban"]
@pytest.mark.parametrize("user", [
@@ -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.
Reason:
Test permanent ban"
- "
If you would like to appeal this ban, please send an "
- "email to: moderation@faforever.com"
- )
- }
+ assert msg["command"] == "notice"
+ assert msg["style"] == "error"
+ assert msg["text"] == (
+ "You are banned from FAF forever.
Reason:
Test permanent ban"
+ "
If you would like to appeal this ban, please send an "
+ "email to: moderation@faforever.com"
+ )
+ 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"])
diff --git a/tests/integration_tests/test_server.py b/tests/integration_tests/test_server.py
index ae00663bb..385ede861 100644
--- a/tests/integration_tests/test_server.py
+++ b/tests/integration_tests/test_server.py
@@ -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.
Reason:
Test live ban
"
- "
If you would like to appeal this ban, please send an email "
- "to: moderation@faforever.com"
- )
- }
+ 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.
Reason:
Test live ban
"
+ "
If you would like to appeal this ban, please send an email "
+ "to: moderation@faforever.com"
+ )
@fast_forward(5)
diff --git a/tests/unit_tests/test_lobbyconnection.py b/tests/unit_tests/test_lobbyconnection.py
index ea764e84d..53d8690a3 100644
--- a/tests/unit_tests/test_lobbyconnection.py
+++ b/tests/unit_tests/test_lobbyconnection.py
@@ -1308,6 +1308,17 @@ async def test_abort_connection_if_banned(
"
If you would like to appeal this ban, please send an email "
"to: moderation@faforever.com"
)
+ 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