Ready Core translations!

This commit is contained in:
Maxim Khomutov 2023-07-26 01:51:23 +03:00
parent 189bd0cc30
commit d29bb9de98
6 changed files with 117 additions and 82 deletions

View File

@ -111,7 +111,7 @@ class Client:
if not self.__alive: if not self.__alive:
self.log.debug(f"{self.nick}.kick('{reason}') skipped: Not alive;") self.log.debug(f"{self.nick}.kick('{reason}') skipped: Not alive;")
return return
self.log.info(i18n.game_player_kicked.format(reason)) self.log.info(i18n.client_kicked.format(reason))
await self._send(f"K{reason}") await self._send(f"K{reason}")
self.__alive = False self.__alive = False

View File

@ -24,13 +24,11 @@ class TCPServer:
async def auth_client(self, reader, writer): async def auth_client(self, reader, writer):
client = self.Core.create_client(reader, writer) client = self.Core.create_client(reader, writer)
# TODO: i18n self.log.info(i18n.core_identifying_connection)
self.log.info(f"Identifying new ClientConnection...")
data = await client._recv(True) data = await client._recv(True)
self.log.debug(f"Version: {data}") self.log.debug(f"Version: {data}")
if data.decode("utf-8") != f"VC{self.Core.client_major_version}": if data.decode("utf-8") != f"VC{self.Core.client_major_version}":
# TODO: i18n await client.kick(i18n.core_player_kick_outdated)
await client.kick("Outdated Version.")
return False, client return False, client
else: else:
await client._send(b"S") # Accepted client version await client._send(b"S") # Accepted client version
@ -38,8 +36,7 @@ class TCPServer:
data = await client._recv(True) data = await client._recv(True)
self.log.debug(f"Key: {data}") self.log.debug(f"Key: {data}")
if len(data) > 50: if len(data) > 50:
# TODO: i18n await client.kick(i18n.core_player_kick_bad_key)
await client.kick("Invalid Key (too long)!")
return False, client return False, client
client._key = data.decode("utf-8") client._key = data.decode("utf-8")
ev.call_event("onPlayerSentKey", player=client) ev.call_event("onPlayerSentKey", player=client)
@ -50,8 +47,7 @@ class TCPServer:
res = await response.json() res = await response.json()
self.log.debug(f"res: {res}") self.log.debug(f"res: {res}")
if res.get("error"): if res.get("error"):
# TODO: i18n await client.kick(i18n.core_player_kick_invalid_key)
await client.kick('Invalid key! Please restart your game.')
return False, client return False, client
client.nick = res["username"] client.nick = res["username"]
client.roles = res["roles"] client.roles = res["roles"]
@ -60,21 +56,20 @@ class TCPServer:
# noinspection PyProtectedMember # noinspection PyProtectedMember
client._update_logger() client._update_logger()
except Exception as e: except Exception as e:
# TODO: i18n
self.log.error(f"Auth error: {e}") 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 return False, client
for _client in self.Core.clients: for _client in self.Core.clients:
if not _client: if not _client:
continue continue
if _client.nick == client.nick and _client.guest == client.guest: if _client.nick == client.nick and _client.guest == client.guest:
# TODO: i18n await _client.kick(i18n.core_player_kick_stale)
await client.kick('Stale Client (replaced by new client)')
return False, client client.log.info(i18n.core_player_set_id.format(client.pid))
allow = True 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) lua_data = ev.call_lua_event("onPlayerAuth", client.nick, client.roles, client.guest, client.identifiers)
for data in lua_data: for data in lua_data:
@ -90,12 +85,10 @@ class TCPServer:
ev.call_event("onPlayerAuthenticated", player=client) ev.call_event("onPlayerAuthenticated", player=client)
if len(self.Core.clients_by_id) > config.Game["players"]: if len(self.Core.clients_by_id) > config.Game["players"]:
# TODO: i18n await client.kick(i18n.core_player_kick_server_full)
await client.kick("Server full!")
return False, client return False, client
else: else:
# TODO: i18n self.log.info(i18n.core_identifying_okay)
self.log.info("Identification success")
await self.Core.insert_client(client) await self.Core.insert_client(client)
return True, client return True, client
@ -127,8 +120,8 @@ class TCPServer:
await writer.drain() await writer.drain()
writer.close() writer.close()
case _: case _:
# TODO: i18n
self.log.error(f"Unknown code: {code}") self.log.error(f"Unknown code: {code}")
self.log.info("Report about that!")
writer.close() writer.close()
return False, None return False, None
@ -148,7 +141,6 @@ class TCPServer:
del cl del cl
break break
except Exception as e: except Exception as e:
# TODO: i18n
self.log.error("Error while handling connection...") self.log.error("Error while handling connection...")
self.log.exception(e) self.log.exception(e)
traceback.print_exc() traceback.print_exc()
@ -165,8 +157,7 @@ class TCPServer:
async with server: async with server:
await server.serve_forever() await server.serve_forever()
except OSError as e: except OSError as e:
# TODO: i18n self.log.error(i18n.core_bind_failed.format(e))
self.log.error("Cannot bind port")
raise e raise e
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass

View File

@ -1,70 +1,81 @@
{ {
"": "基本阶段", "": "基本阶段",
"hello": "来自 KuiToi-Server 的问候!", "hello": "来自KuiToi-Server的问候",
"config_path": "使用 {} 进行配置。", "config_path": "使用{}进行配置。",
"init_ok": "初始化完成。", "init_ok": "初始化完成。",
"start": "服务器已启动!", "start": "服务器已启动!",
"stop": "服务器已停止!", "stop": "服务器已停止!",
"": "服务器认证", "": "服务器认证",
"auth_need_key": "启动需要 BeamMP 密钥!", "auth_need_key": "需要BeamMP密钥才能运行",
"auth_empty_key": "BeamMP 密钥为空!", "auth_empty_key": "BeamMP密钥为空!",
"auth_cannot_open_browser": "无法打开浏览器: {}", "auth_cannot_open_browser": "无法打开浏览器{}",
"auth_use_link": "使用此链接: {}", "auth_use_link": "使用此链接{}",
"": "GUI 阶段", "": "GUI阶段",
"GUI_yes": "是", "GUI_yes": "是",
"GUI_no": "否", "GUI_no": "否",
"GUI_ok": "好的", "GUI_ok": "确定",
"GUI_cancel": "取消", "GUI_cancel": "取消",
"GUI_need_key_message": "启动需要 BeamMP 密钥!\n是否要在浏览器中打开链接获取密钥?", "GUI_need_key_message": "需要BeamMP密钥才能运行\n是否要在浏览器中打开链接获取密钥?",
"GUI_enter_key_message": "请输入密钥:", "GUI_enter_key_message": "请输入密钥",
"GUI_cannot_open_browser": "无法打开浏览器。\n使用此链接: {}", "GUI_cannot_open_browser": "无法打开浏览器。\n请使用此链接:{}",
"": "Web 阶段", "": "Web阶段",
"web_start": "WebAPI 已启动 {} (按 CTRL+C 停止)", "web_start": "WebAPI已启动于{}按CTRL+C停止",
"": "核心短语", "": "核心短语",
"core_bind_failed": "无法绑定端口。错误:{}",
"core_direct_mode": "服务器以直接连接模式启动。", "core_direct_mode": "服务器以直接连接模式启动。",
"core_auth_server_error": "从 BeamMP 认证服务器收到不正确的响应。", "core_auth_server_error": "从BeamMP认证服务器接收到无效响应。",
"core_auth_server_refused": "BeamMP 认证服务器拒绝您的密钥。原因: {}", "core_auth_server_refused": "BeamMP认证服务器拒绝了您的密钥。原因:{}",
"core_auth_server_refused_no_reason": "BeamMP 认证服务器未提供原因。", "core_auth_server_refused_no_reason": "BeamMP认证服务器没有提供原因。",
"core_auth_server_refused_direct_node": "服务器仍在运行,但以直接连接模式运行。", "core_auth_server_refused_direct_node": "服务器仍在运行,但以直接连接模式运行。",
"core_auth_server_no_response": "认证服务器无响应。", "core_auth_server_no_response": "无法验证服务器。",
"core_mods_loaded": "{} 个模组已加载。{}Mb", "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_request": "请求模组:{}",
"client_mod_sent": "发送模组: 大小: {}mb, 速度: {}Mb/s ({}秒)", "client_mod_sent": "已发送模组:大小:{}mb速度{}Mb/s{}秒)",
"client_mod_sent_limit": " (限制 {}Mb/s)", "client_mod_sent_limit": "(限制{}Mb/s",
"client_mod_sent_error": "发送模组时出错: {}", "client_mod_sent_error": "发送模组时出错:{}",
"client_sync_time": "同步时间 {}秒。", "client_sync_time": "同步时间{}秒。",
"client_event_invalid_data": "从事件返回的数据无效: {}", "client_kicked": "因\"{}\"原因被踢出。",
"client_player_disconnected": "已从服务器断开连接。游戏时间: {} 分钟。", "client_event_invalid_data": "从事件返回的数据无效:{}",
"client_player_disconnected": "离开服务器。游戏时间:{}分钟。",
"": "命令: man", "": "命令man",
"man_message_man": "man - 显示 COMMAND 的帮助页面。\n用法man COMMAND", "man_message_man": "man - 显示COMMAND的帮助页面。\n用法man COMMAND",
"help_message_man": "显示 COMMAND 的帮助页面。", "help_message_man": "显示COMMAND的帮助页面。",
"man_for": "帮助页面", "man_for": "帮助页面",
"man_message_not_found": "man: 找不到帮助页面。", "man_message_not_found": "man找不到帮助页面。",
"man_command_not_found": "man: 找不到命令\"{}\"", "man_command_not_found": "man找不到命令\"{}\"",
"": "命令: help", "": "命令help",
"man_message_help": "help - 显示命令的名称和简要描述。\n用法help [--raw]\n`help` 命令显示所有可用命令的列表以及每个命令的简要描述。", "man_message_help": "help - 显示命令的名称和简要说明。\n用法help [--raw]\n`help`命令显示所有可用命令的名称和简要说明。",
"help_message_help": "显示命令的名称和简要描述。", "help_message_help": "显示命令的名称和简要说明。",
"help_command": "命令", "help_command": "命令",
"help_message": "文本", "help_message": "文本",
"help_message_not_found": "到文本。", "help_message_not_found": "找到文本。",
"": "命令: stop", "": "命令stop",
"man_message_stop": "stop - 停止服务器。\n用法stop", "man_message_stop": "stop - 停止服务器。\n用法stop",
"help_message_stop": "停止服务器。", "help_message_stop": "停止服务器。",
"": "命令: exit", "": "命令exit",
"man_message_exit": "exit - 停止服务器。\n用法exit", "man_message_exit": "exit - 停止服务器。\n用法exit",
"help_message_exit": "停止服务器。" "help_message_exit": "停止服务器。"
} }

View File

@ -1,13 +1,13 @@
{ {
"": "Basic phases", "": "Basic phases",
"hello": "Hello from KuiToi-Server!", "hello": "Hello from KuiToi-Server!",
"config_path": "Use {} for configuration.", "config_path": "Use {} to configure.",
"init_ok": "Initialization completed.", "init_ok": "Initialization completed.",
"start": "Server started!", "start": "Server started!",
"stop": "Server stopped!", "stop": "Server stopped!",
"": "Server auth", "": "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_empty_key": "BeamMP key is empty!",
"auth_cannot_open_browser": "Failed to open browser: {}", "auth_cannot_open_browser": "Failed to open browser: {}",
"auth_use_link": "Use this link: {}", "auth_use_link": "Use this link: {}",
@ -17,7 +17,7 @@
"GUI_no": "No", "GUI_no": "No",
"GUI_ok": "OK", "GUI_ok": "OK",
"GUI_cancel": "Cancel", "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_enter_key_message": "Please enter the key:",
"GUI_cannot_open_browser": "Failed to open browser.\nUse this link: {}", "GUI_cannot_open_browser": "Failed to open browser.\nUse this link: {}",
@ -25,40 +25,51 @@
"web_start": "WebAPI started on {} (CTRL+C to stop)", "web_start": "WebAPI started on {} (CTRL+C to stop)",
"": "Core phrases", "": "Core phrases",
"core_bind_failed": "Failed to bind port. Error: {}",
"core_direct_mode": "Server started in direct connection mode.", "core_direct_mode": "Server started in direct connection mode.",
"core_auth_server_error": "Incorrect response received from BeamMP authentication server.", "core_auth_server_error": "Received invalid response from BeamMP authentication server.",
"core_auth_server_refused": "BeamMP authentication server rejected your key. Reason: {}", "core_auth_server_refused": "The BeamMP authentication server refused your key. Reason: {}",
"core_auth_server_refused_no_reason": "BeamMP authentication server did not provide a reason.", "core_auth_server_refused_no_reason": "The 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_refused_direct_node": "The server is still running, but in direct connection mode.",
"core_auth_server_no_response": "Failed to authenticate the server.", "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", "": "In-game phrases",
"game_player_kicked": "Kicked for reason: \"{}\"",
"game_welcome_message": "Welcome {}!", "game_welcome_message": "Welcome {}!",
"": "Client class phrases", "": "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": "Mod sent: Size: {}mb, Speed: {}Mb/s ({}sec)",
"client_mod_sent_limit": " (limit {}Mb/s)", "client_mod_sent_limit": " (limit {}Mb/s)",
"client_mod_sent_error": "Error sending mod: {}", "client_mod_sent_error": "Error sending mod: {}",
"client_sync_time": "Sync time {}sec.", "client_sync_time": "Sync time {}sec.",
"client_kicked": "Kicked for reason: \"{}\"",
"client_event_invalid_data": "Invalid data returned from event: {}", "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", "": "Command: man",
"man_message_man": "man - Shows help page for COMMAND.\nUsage: man COMMAND", "man_message_man": "man - Shows the help page for COMMAND.\nUsage: man COMMAND",
"help_message_man": "Shows help page for COMMAND.", "help_message_man": "Shows the help page for COMMAND.",
"man_for": "Help page for", "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!", "man_command_not_found": "man: Command \"{}\" not found!",
"": "Command: help", "": "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.", "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_message_help": "Shows the names and brief descriptions of commands",
"help_command": "Command", "help_command": "Command",
"help_message": "Text", "help_message": "Text",
"help_message_not_found": "No text found.", "help_message_not_found": "No text found",
"": "Command: stop", "": "Command: stop",
"man_message_stop": "stop - Stops the server.\nUsage: stop", "man_message_stop": "stop - Stops the server.\nUsage: stop",

View File

@ -25,6 +25,7 @@
"web_start": "WebAPI запустился на {} (CTRL+C для выключения)", "web_start": "WebAPI запустился на {} (CTRL+C для выключения)",
"": "Core phrases", "": "Core phrases",
"core_bind_failed": "Не получилось занять порт. Ошибка: {}",
"core_direct_mode": "Сервер запушен в режиме прямого подключения.", "core_direct_mode": "Сервер запушен в режиме прямого подключения.",
"core_auth_server_error": "Поступил не корректный ответ от сервером авторизации BeamMP.", "core_auth_server_error": "Поступил не корректный ответ от сервером авторизации BeamMP.",
"core_auth_server_refused": "Сервер авторизации BeamMP отклонил ваш ключ. Причина: {}", "core_auth_server_refused": "Сервер авторизации BeamMP отклонил ваш ключ. Причина: {}",
@ -32,9 +33,18 @@
"core_auth_server_refused_direct_node": "Сервер всё ещё работает, но в режиме прямого подключения.", "core_auth_server_refused_direct_node": "Сервер всё ещё работает, но в режиме прямого подключения.",
"core_auth_server_no_response": "Не получилось авторизовать сервер.", "core_auth_server_no_response": "Не получилось авторизовать сервер.",
"core_mods_loaded": "Загружено {} модов. {}Мб", "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", "": "In-game phrases",
"game_player_kicked": "Кикнут по причине: \"{}\"",
"game_welcome_message": "Добро пожаловать {}!", "game_welcome_message": "Добро пожаловать {}!",
"": "Client class phrases", "": "Client class phrases",
@ -43,6 +53,7 @@
"client_mod_sent_limit": " (лимит {}Мб/с)", "client_mod_sent_limit": " (лимит {}Мб/с)",
"client_mod_sent_error": "Ошибка при отправке мода: {}", "client_mod_sent_error": "Ошибка при отправке мода: {}",
"client_sync_time": "Время синхронизации {}сек.", "client_sync_time": "Время синхронизации {}сек.",
"client_kicked": "Кикнут по причине: \"{}\"",
"client_event_invalid_data": "Из ивента вернулись не верные данные: {}", "client_event_invalid_data": "Из ивента вернулись не верные данные: {}",
"client_player_disconnected": "Вышел с сервера. Время игры: {} мин", "client_player_disconnected": "Вышел с сервера. Время игры: {} мин",

View File

@ -26,6 +26,7 @@ class i18n:
# Core phrases # Core phrases
core_bind_failed: str
core_direct_mode: str core_direct_mode: str
core_auth_server_error: str core_auth_server_error: str
core_auth_server_refused: str core_auth_server_refused: str
@ -33,10 +34,19 @@ class i18n:
core_auth_server_refused_direct_node: str core_auth_server_refused_direct_node: str
core_auth_server_no_response: str core_auth_server_no_response: str
core_mods_loaded: 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 # In-game phrases
game_player_kicked: str
game_welcome_message: str game_welcome_message: str
# Client class phrases # Client class phrases
@ -46,6 +56,7 @@ class i18n:
client_mod_sent_limit: str client_mod_sent_limit: str
client_mod_sent_error: str client_mod_sent_error: str
client_sync_time: str client_sync_time: str
client_kicked: str
client_event_invalid_data: str client_event_invalid_data: str
client_player_disconnected: str client_player_disconnected: str