Compare commits

...

10 Commits

Author SHA1 Message Date
f145048cc1 FIX #1 2023-08-16 05:11:48 +03:00
68bf7d0d00 More debug info 2023-08-16 05:02:51 +03:00
e9815cdfcf FIX _get_player #1 2023-08-16 05:02:39 +03:00
acb2b45626 linux fix 2023-08-16 01:03:02 +03:00
eb71fda356 0.4.4 -> 0.4.5 2023-08-15 22:56:43 +03:00
cc400d5a12 0.4.3 -> 0.4.4 2023-08-15 22:53:42 +03:00
67b3bd26bb 0.4.3 -> 0.4.4 2023-08-15 22:53:20 +03:00
77250561fb Update build 2023-08-15 22:35:42 +03:00
70dfb9b40c Move translations 2023-08-15 22:34:27 +03:00
3118c74990 Update docs 2023-08-15 22:34:07 +03:00
22 changed files with 135 additions and 149 deletions

View File

@ -1,3 +1,3 @@
# MultiLanguage - i18n支持 # MultiLanguage - i18n支持
在 [example.json](./example.json) 中是 [src/modules/i18n/files/ru.json](../../../src/modules/i18n/files/ru.json) 的副本。如果你想将其翻译成以前未翻译过的语言,或者更新现有的翻译,我将很高兴接受你的拉取请求。 在 [example.json](./example.json) 中是 [src/modules/i18n/files/ru.json](../../../src/translates/ru.json) 的副本。如果你想将其翻译成以前未翻译过的语言,或者更新现有的翻译,我将很高兴接受你的拉取请求。

View File

@ -1,4 +1,4 @@
# MultiLanguage - i18n Support # MultiLanguage - i18n Support
In [example.json](./example.json) you will find a copy of [src/modules/i18n/files/ru.json](../../../src/modules/i18n/files/ru.json).\ In [example.json](./example.json) you will find a copy of [src/modules/i18n/files/ru.json](../../../src/translates/ru.json).\
If you want to translate to a language that has not been translated before or update an existing translation, I would be happy to receive your pull requests. If you want to translate to a language that has not been translated before or update an existing translation, I would be happy to receive your pull requests.

View File

@ -1,4 +1,4 @@
# MultiLanguage - Поддержка i18n # MultiLanguage - Поддержка i18n
В [example.json](./example.json) это копия [src/modules/i18n/files/ru.json](../../../src/modules/i18n/files/ru.json)\ В [example.json](./example.json) это копия [src/modules/i18n/files/ru.json](../../../src/translates/ru.json)\
Если есть желание перевести на не переведённый ранее язык, или обновить уже существующий перевод буду рад вашим пул реквестам. Если есть желание перевести на не переведённый ранее язык, или обновить уже существующий перевод буду рад вашим пул реквестам.

View File

@ -1,7 +1,7 @@
# Developed by KuiToi Dev # Developed by KuiToi Dev
# File core.tcp_server.py # File core.tcp_server.py
# Written by: SantaSpeen # Written by: SantaSpeen
# Core version: 0.4.3 # Core version: 0.4.5
# Licence: FPA # Licence: FPA
# (c) kuitoi.su 2023 # (c) kuitoi.su 2023
import asyncio import asyncio

View File

@ -1,7 +1,7 @@
# Developed by KuiToi Dev # Developed by KuiToi Dev
# File core.tcp_server.py # File core.tcp_server.py
# Written by: SantaSpeen # Written by: SantaSpeen
# Core version: 0.4.3 # Core version: 0.4.5
# Licence: FPA # Licence: FPA
# (c) kuitoi.su 2023 # (c) kuitoi.su 2023
import asyncio import asyncio

View File

@ -1,8 +1,8 @@
# Developed by KuiToi Dev # Developed by KuiToi Dev
# File core.__init__.py # File core.__init__.py
# Written by: SantaSpeen # Written by: SantaSpeen
# Version 1.4 # Version 1.5
# Core version: 0.4.3 # Core version: 0.4.5
# Licence: FPA # Licence: FPA
# (c) kuitoi.su 2023 # (c) kuitoi.su 2023
# Special thanks to: AI Sage(https://poe.com/Sage), AI falcon-40b-v7(https://OpenBuddy.ai) # Special thanks to: AI Sage(https://poe.com/Sage), AI falcon-40b-v7(https://OpenBuddy.ai)
@ -10,8 +10,8 @@
__title__ = 'KuiToi-Server' __title__ = 'KuiToi-Server'
__description__ = 'BeamingDrive Multiplayer server compatible with BeamMP clients.' __description__ = 'BeamingDrive Multiplayer server compatible with BeamMP clients.'
__url__ = 'https://github.com/kuitoi/kuitoi-Server' __url__ = 'https://github.com/kuitoi/kuitoi-Server'
__version__ = '0.4.3' __version__ = '0.4.5'
__build__ = 2125 # Я это считаю лог файлами __build__ = 2300 # Я это считаю лог файлами
__author__ = 'SantaSpeen' __author__ = 'SantaSpeen'
__author_email__ = 'admin@kuitoi.su' __author_email__ = 'admin@kuitoi.su'
__license__ = "FPA" __license__ = "FPA"

View File

@ -1,7 +1,7 @@
# Developed by KuiToi Dev # Developed by KuiToi Dev
# File core.core.py # File core.core.py
# Written by: SantaSpeen # Written by: SantaSpeen
# Version: 0.4.3 # Version: 0.4.5
# Licence: FPA # Licence: FPA
# (c) kuitoi.su 2023 # (c) kuitoi.su 2023
import asyncio import asyncio

View File

@ -1,7 +1,7 @@
# Developed by KuiToi Dev # Developed by KuiToi Dev
# File core.core.pyi # File core.core.pyi
# Written by: SantaSpeen # Written by: SantaSpeen
# Core version: 0.4.3 # Core version: 0.4.5
# Licence: FPA # Licence: FPA
# (c) kuitoi.su 2023 # (c) kuitoi.su 2023
import asyncio import asyncio

View File

@ -1,7 +1,7 @@
# Developed by KuiToi Dev # Developed by KuiToi Dev
# File core.tcp_server.py # File core.tcp_server.py
# Written by: SantaSpeen # Written by: SantaSpeen
# Core version: 0.4.3 # Core version: 0.4.5
# Licence: FPA # Licence: FPA
# (c) kuitoi.su 2023 # (c) kuitoi.su 2023
import asyncio import asyncio

View File

@ -1,7 +1,7 @@
# Developed by KuiToi Dev # Developed by KuiToi Dev
# File core.tcp_server.pyi # File core.tcp_server.pyi
# Written by: SantaSpeen # Written by: SantaSpeen
# Core version: 0.4.3 # Core version: 0.4.5
# Licence: FPA # Licence: FPA
# (c) kuitoi.su 2023 # (c) kuitoi.su 2023
import asyncio import asyncio

View File

@ -1,7 +1,7 @@
# Developed by KuiToi Dev # Developed by KuiToi Dev
# File core.udp_server.py # File core.udp_server.py
# Written by: SantaSpeen # Written by: SantaSpeen
# Core version: 0.4.3 # Core version: 0.4.5
# Licence: FPA # Licence: FPA
# (c) kuitoi.su 2023 # (c) kuitoi.su 2023
import asyncio import asyncio

View File

@ -1,7 +1,7 @@
# Developed by KuiToi Dev # Developed by KuiToi Dev
# File core.udp_server.py # File core.udp_server.py
# Written by: SantaSpeen # Written by: SantaSpeen
# Core version: 0.4.3 # Core version: 0.4.5
# Licence: FPA # Licence: FPA
# (c) kuitoi.su 2023 # (c) kuitoi.su 2023
import asyncio import asyncio

View File

@ -2,7 +2,7 @@
# File core.utils.py # File core.utils.py
# Written by: SantaSpeen # Written by: SantaSpeen
# Version 1.1 # Version 1.1
# Core version: 0.4.3 # Core version: 0.4.5
# Licence: FPA # Licence: FPA
# (c) kuitoi.su 2023 # (c) kuitoi.su 2023
import datetime import datetime

View File

@ -25,7 +25,8 @@ class Config:
"access_token": secrets.token_hex(16)} "access_token": secrets.token_hex(16)}
def __repr__(self): def __repr__(self):
return "%s(Auth=%r, Game=%r, Server=%r)" % (self.__class__.__name__, self.Auth, self.Game, self.Server) return f"{self.__class__.__name__}(Auth={self.Auth!r}, Game={self.Game!r}, Server={self.Server!r}, " \
f"RCON={self.RCON!r}, Options={self.Options!r}, WebAPI={self.WebAPI!r})"
class ConfigProvider: class ConfigProvider:

View File

@ -15,7 +15,10 @@ from prompt_toolkit import PromptSession, print_formatted_text, HTML
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.completion import NestedCompleter from prompt_toolkit.completion import NestedCompleter
from prompt_toolkit.history import FileHistory from prompt_toolkit.history import FileHistory
from prompt_toolkit.output.win32 import NoConsoleScreenBufferError try:
from prompt_toolkit.output.win32 import NoConsoleScreenBufferError
except AssertionError:
class NoConsoleScreenBufferError(Exception): ...
from prompt_toolkit.patch_stdout import patch_stdout from prompt_toolkit.patch_stdout import patch_stdout
from core import get_logger from core import get_logger

View File

@ -141,7 +141,7 @@ class EventsSystem:
return funcs_data return funcs_data
def call_lua_event(self, event_name, *args): def call_lua_event(self, event_name, *args):
self.log.debug(f"Calling lua event: '{event_name}'") self.log.debug(f"Calling lua event: '{event_name} ({args})'")
funcs_data = [] funcs_data = []
if event_name in self.__lua_events.keys(): if event_name in self.__lua_events.keys():
for data in self.__lua_events[event_name]: for data in self.__lua_events[event_name]:

View File

@ -110,7 +110,7 @@ class MP:
def TriggerLocalEvent(self, event_name, *args): def TriggerLocalEvent(self, event_name, *args):
self.log.debug("request TriggerLocalEvent()") self.log.debug("request TriggerLocalEvent()")
self.log.debug(f"Calling local lua event: '{event_name}'") self.log.debug(f"Calling local lua event: '{event_name} ({args})'")
funcs_data = [] funcs_data = []
if event_name in self._local_events.keys(): if event_name in self._local_events.keys():
for func_name in self._local_events[event_name]: for func_name in self._local_events[event_name]:
@ -157,7 +157,7 @@ class MP:
to_all = False to_all = False
if player_id < 0: if player_id < 0:
to_all = True to_all = True
client = client[0] client = client[0] if len(client) > 0 else None
if client and event_name and data: if client and event_name and data:
t = self.loop.create_task(client.send_event(event_name, data, to_all=to_all)) t = self.loop.create_task(client.send_event(event_name, data, to_all=to_all))
self.tasks.append(t) self.tasks.append(t)
@ -168,7 +168,7 @@ class MP:
return False, "Can't found event_name or data" return False, "Can't found event_name or data"
def TriggerClientEventJson(self, player_id, event_name, data): def TriggerClientEventJson(self, player_id, event_name, data):
self.log.debug("request TriggerClientEventJson()") self.log.debug(f"request TriggerClientEventJson({player_id, event_name, data})")
data = self._lua.globals().Util.JsonEncode(data) data = self._lua.globals().Util.JsonEncode(data)
self.TriggerClientEvent(player_id, event_name, data) self.TriggerClientEvent(player_id, event_name, data)
@ -232,7 +232,7 @@ class MP:
def GetPlayers(self): def GetPlayers(self):
self.log.debug("request GetPlayers()") self.log.debug("request GetPlayers()")
clients = ev.call_event("_get_players", cid=-1) clients = ev.call_event("_get_player", cid=-1)[0]
return self._lua.table_from(clients) return self._lua.table_from(clients)
def IsPlayerGuest(self, player_id) -> bool: def IsPlayerGuest(self, player_id) -> bool:
@ -312,12 +312,18 @@ class Util:
return {k: v for k, v in new_dict.items() if v is not None} return {k: v for k, v in new_dict.items() if v is not None}
def JsonEncode(self, table): def JsonEncode(self, table):
data = {}
try:
self.log.debug("requesting JsonEncode()") self.log.debug("requesting JsonEncode()")
if all(isinstance(k, int) for k in table.keys()): if all(isinstance(k, int) for k in table.keys()):
data = self._recursive_list_encode(table) data = self._recursive_list_encode(table)
else: else:
data = self._recursive_dict_encode(table) data = self._recursive_dict_encode(table)
return json.dumps(data) except Exception as e:
self.log.exception(e)
data = json.dumps(data)
self.log.debug(f"Encoded: {data}")
return data
def JsonDecode(self, string): def JsonDecode(self, string):
self.log.debug("requesting JsonDecode()") self.log.debug("requesting JsonDecode()")

View File

@ -8,6 +8,7 @@
# (c) kuitoi.su 2023 # (c) kuitoi.su 2023
import builtins import builtins
import json import json
import os
from json import JSONDecodeError from json import JSONDecodeError
from core.utils import get_logger from core.utils import get_logger
@ -25,43 +26,21 @@ class i18n:
class MultiLanguage: class MultiLanguage:
def __init__(self, language: str = None, files_dir="modules/i18n/files/", encoding=None): def __init__(self, language: str = None, files_dir="translates/", encoding=None):
if encoding is None: if encoding is None:
encoding = config.enc encoding = config.enc
if language is None: if language is None:
language = "en" language = "en"
self.__data = {}
self.__i18n = None
self.__encoding = encoding
self.language = language
self.files_dir = files_dir
self.log = get_logger("i18n")
self.set_language(language)
def set_language(self, language):
if language is None:
language = "en"
self.log.debug(f"set_language({language})")
self.language = language
if language != "en":
self.open_file()
else:
# noinspection PyDictDuplicateKeys
self.__data = { self.__data = {
"": "Basic phases",
"hello": "Hello from KuiToi-Server!", "hello": "Hello from KuiToi-Server!",
"config_path": "Use {} to configure.", "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",
"auth_need_key": "BeamMP key is required to run!", "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: {}",
"": "GUI phases",
"GUI_yes": "Yes", "GUI_yes": "Yes",
"GUI_no": "No", "GUI_no": "No",
"GUI_ok": "OK", "GUI_ok": "OK",
@ -69,11 +48,7 @@ class MultiLanguage:
"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_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: {}",
"": "Web phases",
"web_start": "WebAPI started on {} (CTRL+C to stop)", "web_start": "WebAPI started on {} (CTRL+C to stop)",
"": "Core phrases",
"core_bind_failed": "Failed to bind port. Error: {}", "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": "Received invalid response from BeamMP authentication server.", "core_auth_server_error": "Received invalid response from BeamMP authentication server.",
@ -92,11 +67,7 @@ class MultiLanguage:
"core_player_kick_server_full": "Server is full.", "core_player_kick_server_full": "Server is full.",
"core_player_set_id": "Player set ID {}", "core_player_set_id": "Player set ID {}",
"core_identifying_okay": "Successful login.", "core_identifying_okay": "Successful login.",
"": "In-game phrases",
"game_welcome_message": "Welcome {}!", "game_welcome_message": "Welcome {}!",
"": "Client class phrases",
"client_mod_request": "Requested mod: {}", "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)",
@ -105,55 +76,60 @@ class MultiLanguage:
"client_kicked": "Kicked for reason: \"{}\"", "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": "Left the server. Playtime: {} min", "client_player_disconnected": "Left the server. Playtime: {} min",
"": "Events system",
"events_not_callable": "Unable to add event \"{}\". Use \"{}\" instead. Skipping...", "events_not_callable": "Unable to add event \"{}\". Use \"{}\" instead. Skipping...",
"events_not_found": "Event \"{}\" is not registered. Maybe {}? Skipping...", "events_not_found": "Event \"{}\" is not registered. Maybe {}? Skipping...",
"events_calling_error": "Error calling \"{}\" in function \"{}\".", "events_calling_error": "Error calling \"{}\" in function \"{}\".",
"events_lua_function_not_found": "Unable to call {}lua event - \"{}\" not found.", "events_lua_function_not_found": "Unable to call {}lua event - \"{}\" not found.",
"events_lua_local": "local ", "events_lua_local": "local ",
"events_lua_calling_error": "Error: \"{}\" - calling lua event \"{}\", function: \"{}\", arguments: {}", "events_lua_calling_error": "Error: \"{}\" - calling lua event \"{}\", function: \"{}\", arguments: {}",
"": "Plugins loader",
"plugins_not_found_load": "Function \"def load():\" not found.", "plugins_not_found_load": "Function \"def load():\" not found.",
"plugins_not_found_start": "Function \"def start():\" not found.", "plugins_not_found_start": "Function \"def start():\" not found.",
"plugins_not_found_unload": "Function \"def unload():\" not found.", "plugins_not_found_unload": "Function \"def unload():\" not found.",
"plugins_kt_invalid": "\"kt\" variable does not belong to the KuiToi class.", "plugins_kt_invalid": "\"kt\" variable does not belong to the KuiToi class.",
"plugins_invalid": "Plugin \"{}\" cannot be run in KuiToi.", "plugins_invalid": "Plugin \"{}\" cannot be run in KuiToi.",
"plugins_error_loading": "An error occurred while loading the plugin {}: {}", "plugins_error_loading": "An error occurred while loading the plugin {}: {}",
"": "Lua plugins loader",
"plugins_lua_enabled": "You have enabled Lua plugin support.", "plugins_lua_enabled": "You have enabled Lua plugin support.",
"plugins_lua_nuances_warning": "There are some nuances when working with Kuiti. If you have a suggestion for their solution, and it is related to KuiToi, please contact the developer.", "plugins_lua_nuances_warning": "There are some nuances when working with Kuiti. If you have a suggestion for their solution, and it is related to KuiToi, please contact the developer.",
"plugins_lua_legacy_config_create_warning": "Some BeamMP plugins require a properly configured ServerConfig.toml file to function.", "plugins_lua_legacy_config_create_warning": "Some BeamMP plugins require a properly configured ServerConfig.toml file to function.",
"plugins_lua_legacy_config_create": "Creating it.", "plugins_lua_legacy_config_create": "Creating it.",
"plugins_lua_unload": "Stopping Lua plugin: {}", "plugins_lua_unload": "Stopping Lua plugin: {}",
"": "Command: man",
"man_message_man": "man - Shows the help page for COMMAND.\nUsage: man COMMAND", "man_message_man": "man - Shows the help page for COMMAND.\nUsage: man COMMAND",
"help_message_man": "Shows the 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: Help page not 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",
"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.", "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",
"man_message_stop": "stop - Stops the server.\nUsage: stop", "man_message_stop": "stop - Stops the server.\nUsage: stop",
"help_message_stop": "Stops the server.", "help_message_stop": "Stops the server.",
"": "Command: exit",
"man_message_exit": "exit - Stops the server.\nUsage: exit", "man_message_exit": "exit - Stops the server.\nUsage: exit",
"help_message_exit": "Stops the server." "help_message_exit": "Stops the server."
} }
self.__en_data = self.__data.copy()
self.__i18n = None
self.__encoding = encoding
self.language = language
if not os.path.exists(files_dir):
os.makedirs(files_dir)
if not os.path.exists(files_dir + "en.json"):
with open(files_dir + "en.json", "w") as f:
f.write(json.dumps(self.__en_data, indent=2))
self.files_dir = files_dir
self.log = get_logger("i18n")
self.fi = False
self.set_language(language)
def set_language(self, language="en"):
if self.language == language and self.fi:
return
else:
self.fi = True
self.log.debug(f"set_language({language})")
self.language = language
self.open_file()
self.__i18n = i18n(self.__data) self.__i18n = i18n(self.__data)
def open_file(self): def open_file(self):
@ -165,9 +141,9 @@ class MultiLanguage:
return return
except JSONDecodeError: except JSONDecodeError:
self.log.error( self.log.error(
f"Localisation \"{self.language}.json\" have JsonDecodeError. Using default localisation: en.") f"Localisation \"{file}\" have JsonDecodeError. Using default localisation: en.")
except FileNotFoundError: except FileNotFoundError:
self.log.warning(f"Localisation \"{self.language}.json\" not found; Using default localisation: en.") self.log.warning(f"Localisation \"{file}\" not found; Using default localisation: en.")
self.set_language("en") self.set_language("en")
def builtins_hook(self) -> None: def builtins_hook(self) -> None:

View File

@ -1,6 +1,6 @@
# pip install pyinstaller-versionfile # pip install pyinstaller-versionfile
# create-version-file win-metadata.yml --outfile win-ver_info.txt # create-version-file win-metadata.yml --outfile win-ver_info.txt
Version: 0.4.3 Version: 0.4.5
CompanyName: KuiToi CompanyName: KuiToi
FileDescription: KuiToi Server FileDescription: KuiToi Server
InternalName: KuiToi Server InternalName: KuiToi Server