From d29bb9de98da9f4b8c4dfc9b05410a0761900528 Mon Sep 17 00:00:00 2001 From: SantaSpeen Date: Wed, 26 Jul 2023 01:51:23 +0300 Subject: [PATCH] Ready Core translations! --- src/core/Client.py | 2 +- src/core/tcp_server.py | 35 +++++------- src/modules/i18n/files/cn.json | 91 +++++++++++++++++------------- src/modules/i18n/files/en.json | 45 +++++++++------ src/modules/i18n/files/ru.json | 13 ++++- src/modules/i18n/i18n-builtins.pyi | 13 ++++- 6 files changed, 117 insertions(+), 82 deletions(-) diff --git a/src/core/Client.py b/src/core/Client.py index 9e4a207..84c5fb8 100644 --- a/src/core/Client.py +++ b/src/core/Client.py @@ -111,7 +111,7 @@ class Client: if not self.__alive: self.log.debug(f"{self.nick}.kick('{reason}') skipped: Not alive;") return - self.log.info(i18n.game_player_kicked.format(reason)) + self.log.info(i18n.client_kicked.format(reason)) await self._send(f"K{reason}") self.__alive = False diff --git a/src/core/tcp_server.py b/src/core/tcp_server.py index 2737d4d..b1eef19 100644 --- a/src/core/tcp_server.py +++ b/src/core/tcp_server.py @@ -24,13 +24,11 @@ class TCPServer: async def auth_client(self, reader, writer): client = self.Core.create_client(reader, writer) - # TODO: i18n - self.log.info(f"Identifying new ClientConnection...") + self.log.info(i18n.core_identifying_connection) data = await client._recv(True) self.log.debug(f"Version: {data}") if data.decode("utf-8") != f"VC{self.Core.client_major_version}": - # TODO: i18n - await client.kick("Outdated Version.") + await client.kick(i18n.core_player_kick_outdated) return False, client else: await client._send(b"S") # Accepted client version @@ -38,8 +36,7 @@ class TCPServer: data = await client._recv(True) self.log.debug(f"Key: {data}") if len(data) > 50: - # TODO: i18n - await client.kick("Invalid Key (too long)!") + await client.kick(i18n.core_player_kick_bad_key) return False, client client._key = data.decode("utf-8") ev.call_event("onPlayerSentKey", player=client) @@ -50,8 +47,7 @@ class TCPServer: res = await response.json() self.log.debug(f"res: {res}") if res.get("error"): - # TODO: i18n - await client.kick('Invalid key! Please restart your game.') + await client.kick(i18n.core_player_kick_invalid_key) return False, client client.nick = res["username"] client.roles = res["roles"] @@ -60,21 +56,20 @@ class TCPServer: # noinspection PyProtectedMember client._update_logger() except Exception as e: - # TODO: i18n self.log.error(f"Auth error: {e}") - await client.kick('Invalid authentication data! Try to reconnect in 5 minutes.') + await client.kick(i18n.core_player_kick_auth_server_fail) return False, client for _client in self.Core.clients: if not _client: continue if _client.nick == client.nick and _client.guest == client.guest: - # TODO: i18n - await client.kick('Stale Client (replaced by new client)') - return False, client + await _client.kick(i18n.core_player_kick_stale) + + client.log.info(i18n.core_player_set_id.format(client.pid)) allow = True - reason = "You are not allowed on the server!" + reason = i18n.core_player_kick_no_allowed_default_reason lua_data = ev.call_lua_event("onPlayerAuth", client.nick, client.roles, client.guest, client.identifiers) for data in lua_data: @@ -90,12 +85,10 @@ class TCPServer: ev.call_event("onPlayerAuthenticated", player=client) if len(self.Core.clients_by_id) > config.Game["players"]: - # TODO: i18n - await client.kick("Server full!") + await client.kick(i18n.core_player_kick_server_full) return False, client else: - # TODO: i18n - self.log.info("Identification success") + self.log.info(i18n.core_identifying_okay) await self.Core.insert_client(client) return True, client @@ -127,8 +120,8 @@ class TCPServer: await writer.drain() writer.close() case _: - # TODO: i18n self.log.error(f"Unknown code: {code}") + self.log.info("Report about that!") writer.close() return False, None @@ -148,7 +141,6 @@ class TCPServer: del cl break except Exception as e: - # TODO: i18n self.log.error("Error while handling connection...") self.log.exception(e) traceback.print_exc() @@ -165,8 +157,7 @@ class TCPServer: async with server: await server.serve_forever() except OSError as e: - # TODO: i18n - self.log.error("Cannot bind port") + self.log.error(i18n.core_bind_failed.format(e)) raise e except KeyboardInterrupt: pass diff --git a/src/modules/i18n/files/cn.json b/src/modules/i18n/files/cn.json index 983c7e4..ff0aece 100644 --- a/src/modules/i18n/files/cn.json +++ b/src/modules/i18n/files/cn.json @@ -1,70 +1,81 @@ { "": "基本阶段", - "hello": "来自 KuiToi-Server 的问候!", - "config_path": "使用 {} 进行配置。", + "hello": "来自KuiToi-Server的问候!", + "config_path": "使用{}进行配置。", "init_ok": "初始化完成。", "start": "服务器已启动!", "stop": "服务器已停止!", "": "服务器认证", - "auth_need_key": "启动需要 BeamMP 密钥!", - "auth_empty_key": "BeamMP 密钥为空!", - "auth_cannot_open_browser": "无法打开浏览器: {}", - "auth_use_link": "使用此链接: {}", + "auth_need_key": "需要BeamMP密钥才能运行!", + "auth_empty_key": "BeamMP密钥为空!", + "auth_cannot_open_browser": "无法打开浏览器:{}", + "auth_use_link": "使用此链接:{}", - "": "GUI 阶段", + "": "GUI阶段", "GUI_yes": "是", "GUI_no": "否", - "GUI_ok": "好的", + "GUI_ok": "确定", "GUI_cancel": "取消", - "GUI_need_key_message": "启动需要 BeamMP 密钥!\n是否要在浏览器中打开链接以获取密钥?", - "GUI_enter_key_message": "请输入密钥:", - "GUI_cannot_open_browser": "无法打开浏览器。\n使用此链接: {}", + "GUI_need_key_message": "需要BeamMP密钥才能运行!\n您是否要在浏览器中打开链接获取密钥?", + "GUI_enter_key_message": "请输入密钥:", + "GUI_cannot_open_browser": "无法打开浏览器。\n请使用此链接:{}", - "": "Web 阶段", - "web_start": "WebAPI 已启动 {} (按 CTRL+C 停止)", + "": "Web阶段", + "web_start": "WebAPI已启动于{}(按CTRL+C停止)", "": "核心短语", + "core_bind_failed": "无法绑定端口。错误:{}", "core_direct_mode": "服务器以直接连接模式启动。", - "core_auth_server_error": "从 BeamMP 认证服务器收到不正确的响应。", - "core_auth_server_refused": "BeamMP 认证服务器拒绝您的密钥。原因: {}", - "core_auth_server_refused_no_reason": "BeamMP 认证服务器未提供原因。", + "core_auth_server_error": "从BeamMP认证服务器接收到无效响应。", + "core_auth_server_refused": "BeamMP认证服务器拒绝了您的密钥。原因:{}", + "core_auth_server_refused_no_reason": "BeamMP认证服务器没有提供原因。", "core_auth_server_refused_direct_node": "服务器仍在运行,但以直接连接模式运行。", - "core_auth_server_no_response": "认证服务器无响应。", - "core_mods_loaded": "{} 个模组已加载。{}Mb", + "core_auth_server_no_response": "无法验证服务器。", + "core_mods_loaded": "已加载{}个模组。{}Mb", + "core_identifying_connection": "正在处理新连接...", + "core_player_kick_outdated": "BeamMP版本不正确。", + "core_player_kick_bad_key": "传递的密钥无效!", + "core_player_kick_invalid_key": "无效的密钥!请重新启动游戏。", + "core_player_kick_auth_server_fail": "BeamMP认证服务器失败!请在5分钟后再次尝试连接。", + "core_player_kick_stale": "过时的客户端。(由新连接替换)", + "core_player_kick_no_allowed_default_reason": "您不受欢迎。拒绝访问。", + "core_player_kick_server_full": "服务器已满。", + "core_player_set_id": "玩家设置ID {}", + "core_identifying_okay": "成功登录。", - "": "游戏短语", - "game_player_kicked": "因为 \"{}\" 被踢出游戏。", - "game_welcome_message": "欢迎 {}!", + "": "游戏内短语", + "game_welcome_message": "欢迎{}!", - "": "客户端短语", - "client_mod_request": "请求模组: {}", - "client_mod_sent": "发送模组: 大小: {}mb, 速度: {}Mb/s ({}秒)", - "client_mod_sent_limit": " (限制 {}Mb/s)", - "client_mod_sent_error": "发送模组时出错: {}", - "client_sync_time": "同步时间 {}秒。", - "client_event_invalid_data": "从事件返回的数据无效: {}", - "client_player_disconnected": "已从服务器断开连接。游戏时间: {} 分钟。", + "": "客户端类短语", + "client_mod_request": "请求模组:{}", + "client_mod_sent": "已发送模组:大小:{}mb,速度:{}Mb/s({}秒)", + "client_mod_sent_limit": "(限制{}Mb/s)", + "client_mod_sent_error": "发送模组时出错:{}", + "client_sync_time": "同步时间{}秒。", + "client_kicked": "因\"{}\"原因被踢出。", + "client_event_invalid_data": "从事件返回的数据无效:{}", + "client_player_disconnected": "离开服务器。游戏时间:{}分钟。", - "": "命令: man", - "man_message_man": "man - 显示 COMMAND 的帮助页面。\n用法:man COMMAND", - "help_message_man": "显示 COMMAND 的帮助页面。", + "": "命令:man", + "man_message_man": "man - 显示COMMAND的帮助页面。\n用法:man COMMAND", + "help_message_man": "显示COMMAND的帮助页面。", "man_for": "帮助页面", - "man_message_not_found": "man: 找不到帮助页面。", - "man_command_not_found": "man: 找不到命令\"{}\"!", + "man_message_not_found": "man:找不到帮助页面。", + "man_command_not_found": "man:找不到命令\"{}\"!", - "": "命令: help", - "man_message_help": "help - 显示命令的名称和简要描述。\n用法:help [--raw]\n`help` 命令显示所有可用命令的列表以及每个命令的简要描述。", - "help_message_help": "显示命令的名称和简要描述。", + "": "命令:help", + "man_message_help": "help - 显示命令的名称和简要说明。\n用法:help [--raw]\n`help`命令显示所有可用命令的名称和简要说明。", + "help_message_help": "显示命令的名称和简要说明。", "help_command": "命令", "help_message": "文本", - "help_message_not_found": "找不到文本。", + "help_message_not_found": "未找到文本。", - "": "命令: stop", + "": "命令:stop", "man_message_stop": "stop - 停止服务器。\n用法:stop", "help_message_stop": "停止服务器。", - "": "命令: exit", + "": "命令:exit", "man_message_exit": "exit - 停止服务器。\n用法:exit", "help_message_exit": "停止服务器。" } \ No newline at end of file diff --git a/src/modules/i18n/files/en.json b/src/modules/i18n/files/en.json index 1b4d3f4..2e7ddb5 100644 --- a/src/modules/i18n/files/en.json +++ b/src/modules/i18n/files/en.json @@ -1,13 +1,13 @@ { "": "Basic phases", "hello": "Hello from KuiToi-Server!", - "config_path": "Use {} for configuration.", + "config_path": "Use {} to configure.", "init_ok": "Initialization completed.", "start": "Server started!", "stop": "Server stopped!", "": "Server auth", - "auth_need_key": "A BeamMP key is required to start!", + "auth_need_key": "BeamMP key is required to run!", "auth_empty_key": "BeamMP key is empty!", "auth_cannot_open_browser": "Failed to open browser: {}", "auth_use_link": "Use this link: {}", @@ -17,7 +17,7 @@ "GUI_no": "No", "GUI_ok": "OK", "GUI_cancel": "Cancel", - "GUI_need_key_message": "A BeamMP key is required to start!\nDo you want to open the link in your browser to obtain the key?", + "GUI_need_key_message": "BeamMP key is required to run!\nDo you want to open the link in your browser to get the key?", "GUI_enter_key_message": "Please enter the key:", "GUI_cannot_open_browser": "Failed to open browser.\nUse this link: {}", @@ -25,40 +25,51 @@ "web_start": "WebAPI started on {} (CTRL+C to stop)", "": "Core phrases", + "core_bind_failed": "Failed to bind port. Error: {}", "core_direct_mode": "Server started in direct connection mode.", - "core_auth_server_error": "Incorrect response received from BeamMP authentication server.", - "core_auth_server_refused": "BeamMP authentication server rejected your key. Reason: {}", - "core_auth_server_refused_no_reason": "BeamMP authentication server did not provide a reason.", - "core_auth_server_refused_direct_node": "Server is still running, but in direct connection mode.", + "core_auth_server_error": "Received invalid response from BeamMP authentication server.", + "core_auth_server_refused": "The BeamMP authentication server refused your key. Reason: {}", + "core_auth_server_refused_no_reason": "The BeamMP authentication server did not provide a reason.", + "core_auth_server_refused_direct_node": "The server is still running, but in direct connection mode.", "core_auth_server_no_response": "Failed to authenticate the server.", - "core_mods_loaded": "{} mods loaded. {}Mb", + "core_mods_loaded": "Loaded {} mods. {}Mb", + "core_identifying_connection": "Processing new connection...", + "core_player_kick_outdated": "Incorrect version of BeamMP.", + "core_player_kick_bad_key": "Invalid key passed!", + "core_player_kick_invalid_key": "Invalid key! Please restart your game.", + "core_player_kick_auth_server_fail": "BeamMP authentication server failed! Please try to connect again in 5 minutes.", + "core_player_kick_stale": "Stale client. (Replaced by new connection)", + "core_player_kick_no_allowed_default_reason": "You are not welcome on this server. Access denied.", + "core_player_kick_server_full": "Server is full.", + "core_player_set_id": "Player set ID {}", + "core_identifying_okay": "Successful login.", "": "In-game phrases", - "game_player_kicked": "Kicked for reason: \"{}\"", "game_welcome_message": "Welcome {}!", "": "Client class phrases", - "client_mod_request": "Mod requested: {}", + "client_mod_request": "Requested mod: {}", "client_mod_sent": "Mod sent: Size: {}mb, Speed: {}Mb/s ({}sec)", "client_mod_sent_limit": " (limit {}Mb/s)", "client_mod_sent_error": "Error sending mod: {}", "client_sync_time": "Sync time {}sec.", + "client_kicked": "Kicked for reason: \"{}\"", "client_event_invalid_data": "Invalid data returned from event: {}", - "client_player_disconnected": "Disconnected from the server. Game time: {} min.", + "client_player_disconnected": "Left the server. Playtime: {} min", "": "Command: man", - "man_message_man": "man - Shows help page for COMMAND.\nUsage: man COMMAND", - "help_message_man": "Shows help page for COMMAND.", + "man_message_man": "man - Shows the help page for COMMAND.\nUsage: man COMMAND", + "help_message_man": "Shows the help page for COMMAND.", "man_for": "Help page for", - "man_message_not_found": "man: No help page found.", + "man_message_not_found": "man: Help page not found.", "man_command_not_found": "man: Command \"{}\" not found!", "": "Command: help", - "man_message_help": "help - Shows the names and brief descriptions of commands.\nUsage: help [--raw]\nThe `help` command displays a list of all available commands and a brief description for each command.", - "help_message_help": "Shows the names and brief descriptions of commands.", + "man_message_help": "help - Shows the names and brief descriptions of commands.\nUsage: help [--raw]\nThe `help` command displays a list of all available commands, with a brief description for each command.", + "help_message_help": "Shows the names and brief descriptions of commands", "help_command": "Command", "help_message": "Text", - "help_message_not_found": "No text found.", + "help_message_not_found": "No text found", "": "Command: stop", "man_message_stop": "stop - Stops the server.\nUsage: stop", diff --git a/src/modules/i18n/files/ru.json b/src/modules/i18n/files/ru.json index 73f71d0..aa02822 100644 --- a/src/modules/i18n/files/ru.json +++ b/src/modules/i18n/files/ru.json @@ -25,6 +25,7 @@ "web_start": "WebAPI запустился на {} (CTRL+C для выключения)", "": "Core phrases", + "core_bind_failed": "Не получилось занять порт. Ошибка: {}", "core_direct_mode": "Сервер запушен в режиме прямого подключения.", "core_auth_server_error": "Поступил не корректный ответ от сервером авторизации BeamMP.", "core_auth_server_refused": "Сервер авторизации BeamMP отклонил ваш ключ. Причина: {}", @@ -32,9 +33,18 @@ "core_auth_server_refused_direct_node": "Сервер всё ещё работает, но в режиме прямого подключения.", "core_auth_server_no_response": "Не получилось авторизовать сервер.", "core_mods_loaded": "Загружено {} модов. {}Мб", + "core_identifying_connection": "Обработка нового подключения...", + "core_player_kick_outdated": "Не подходящая версия BeamMP.", + "core_player_kick_bad_key": "Передан не правильный ключ!", + "core_player_kick_invalid_key": "Неверный ключ! Пожалуйста, перезапустите свою игру.", + "core_player_kick_auth_server_fail": "Сбой сервера аутентификации! Попробуйте снова подключиться через 5 минут.", + "core_player_kick_stale": "Устаревший клиент. (Заменено новым подключением)", + "core_player_kick_no_allowed_default_reason": "Вам не рады на этом сервере. Вход запрещён.", + "core_player_kick_server_full": "Сервер полон.", + "core_player_set_id": "Игрок получил ID {}", + "core_identifying_okay": "Успешный вход.", "": "In-game phrases", - "game_player_kicked": "Кикнут по причине: \"{}\"", "game_welcome_message": "Добро пожаловать {}!", "": "Client class phrases", @@ -43,6 +53,7 @@ "client_mod_sent_limit": " (лимит {}Мб/с)", "client_mod_sent_error": "Ошибка при отправке мода: {}", "client_sync_time": "Время синхронизации {}сек.", + "client_kicked": "Кикнут по причине: \"{}\"", "client_event_invalid_data": "Из ивента вернулись не верные данные: {}", "client_player_disconnected": "Вышел с сервера. Время игры: {} мин", diff --git a/src/modules/i18n/i18n-builtins.pyi b/src/modules/i18n/i18n-builtins.pyi index 3d71a0a..cb1f208 100644 --- a/src/modules/i18n/i18n-builtins.pyi +++ b/src/modules/i18n/i18n-builtins.pyi @@ -26,6 +26,7 @@ class i18n: # Core phrases + core_bind_failed: str core_direct_mode: str core_auth_server_error: str core_auth_server_refused: str @@ -33,10 +34,19 @@ class i18n: core_auth_server_refused_direct_node: str core_auth_server_no_response: str core_mods_loaded: str + core_identifying_connection: str + core_player_kick_outdated: str + core_player_kick_bad_key: str + core_player_kick_invalid_key: str + core_player_kick_auth_server_fail: str + core_player_kick_stale: str + core_player_kick_no_allowed_default_reason: str + core_player_kick_server_full: str + core_player_set_id: str + core_identifying_okay: str # In-game phrases - game_player_kicked: str game_welcome_message: str # Client class phrases @@ -46,6 +56,7 @@ class i18n: client_mod_sent_limit: str client_mod_sent_error: str client_sync_time: str + client_kicked: str client_event_invalid_data: str client_player_disconnected: str