Compare commits

..

No commits in common. "7e0c50a04e15a3c33b2051484f87d443d6acffe1" and "719e705bab6faff4b373aecb2925a6e1f665a578" have entirely different histories.

10 changed files with 43 additions and 77 deletions

View File

@ -55,7 +55,7 @@ I didn't like writing plugins in Lua after using Python; it was very inconvenien
- [x] Async support
- [x] Add all events
- [x] MultiLanguage: (i18n support)
- [x] Core
- [ ] Core
- [x] Console
- [x] WebAPI
- [x] Plugins supports:
@ -77,7 +77,7 @@ I didn't like writing plugins in Lua after using Python; it was very inconvenien
- [ ] RCON System:
- [ ] Serving
- [ ] Client
- [x] AES encryption
- [ ] SSL encryption
- [ ] KuiToi System
- [ ] Servers counter
- [ ] Players counter

View File

@ -303,10 +303,10 @@ class Core:
ev.call_event("onServerStopped")
await ev.call_async_event("onServerStopped")
await self.__gracefully_kick()
if config.Options['use_lua']:
ev.call_event("_lua_plugins_unload")
await ev.call_async_event("_plugins_unload")
ev.call_event("_lua_plugins_unload")
self.run = False
self.log.info(i18n.stop)
if config.WebAPI["enabled"]:
asyncio.run(self.web_stop())
# exit(0)

View File

@ -66,6 +66,8 @@ class TCPServer:
if _client.nick == client.nick and _client.guest == client.guest:
await _client.kick(i18n.core_player_kick_stale)
client.log.info(i18n.core_player_set_id.format(client.pid))
allow = True
reason = i18n.core_player_kick_no_allowed_default_reason
@ -88,7 +90,6 @@ class TCPServer:
else:
self.log.info(i18n.core_identifying_okay)
await self.Core.insert_client(client)
client.log.info(i18n.core_player_set_id.format(client.pid))
return True, client

View File

@ -56,12 +56,12 @@ class EventsSystem:
"onInit": [], # onServerStarted
"onShutdown": [], # onServerStopped
"onPlayerAuth": [], # onPlayerAuthenticated
"onPlayerConnecting": [], # No
"onPlayerJoining": [], # No
"onPlayerConnecting": [], # TODO lua onPlayerConnecting
"onPlayerJoining": [], # TODO lua onPlayerJoining
"onPlayerJoin": [], # onPlayerJoin
"onPlayerDisconnect": [], # onPlayerDisconnect
"onPlayerDisconnect": [], # TODO lua onPlayerDisconnect
"onChatMessage": [], # onChatReceive
"onVehicleSpawn": [], # onCarSpawn
"onVehicleSpawn": [], # "onCarSpawn
"onVehicleEdited": [], # onCarEdited
"onVehicleDeleted": [], # onCarDelete
"onVehicleReset": [], # onCarReset
@ -85,7 +85,9 @@ class EventsSystem:
return
if not callable(event_func):
self.log.error(i18n.events_not_callable.format(event_name, f"kt.add_event(\"{event_name}\", function)"))
# TODO: i18n
self.log.error(f"Cannot add event '{event_name}'. "
f"Use `KuiToi.add_event({event_name}', function)` instead. Skipping it...")
return
if async_event or inspect.iscoroutinefunction(event_func):
if event_name not in self.__async_events:
@ -110,10 +112,12 @@ class EventsSystem:
data = await func(event_data)
funcs_data.append(data)
except Exception as e:
self.log.error(i18n.events_calling_error.format(event_name, func.__name__))
# TODO: i18n
self.log.error(f'Error while calling "{event_name}"; In function: "{func.__name__}"')
self.log.exception(e)
else:
self.log.warning(i18n.events_not_found.format(event_name, "kt.call_event()"))
# TODO: i18n
self.log.warning(f"Event {event_name} does not exist, maybe ev.call_event()?. Just skipping it...")
return funcs_data
@ -128,10 +132,12 @@ class EventsSystem:
event_data = {"event_name": event_name, "args": args, "kwargs": kwargs}
funcs_data.append(func(event_data))
except Exception as e:
self.log.error(i18n.events_calling_error.format(event_name, func.__name__))
# TODO: i18n
self.log.error(f'Error while calling "{event_name}"; In function: "{func.__name__}"')
self.log.exception(e)
else:
self.log.warning(i18n.events_not_found.format(event_name, "kt.call_async_event()"))
# TODO: i18n
self.log.warning(f"Event {event_name} does not exist, maybe ev.call_async_event()?. Just skipping it...")
return funcs_data
@ -145,13 +151,21 @@ class EventsSystem:
try:
func = lua.globals()[func_name]
if not func:
self.log.warning(i18n.events_lua_function_not_found.format("", func_name))
self.log.warning(f"Cannot trigger local event: '{func_name}' not found!")
continue
fd = func(*args)
funcs_data.append(fd)
except Exception as e:
self.log.error(i18n.events_lua_calling_error.format(f"{e}", event_name, func_name, f"{args}"))
# TODO: i18n
self.log.error(f'Error: "{e}" - while calling lua event "{event_name}" with arguments: {args} - '
f'in function: "{func_name}"')
# self.log.exception(e)
else:
self.log.warning(i18n.events_not_found.format(event_name, "ev.call_lua_event(), MP.Trigger<>Event()"))
# TODO: i18n
self.log.warning(f"Event {event_name} does not exist, maybe ev.call_lua_event() or MP.Trigger<>Event()?. "
f"Just skipping it...")
return funcs_data

View File

@ -43,7 +43,7 @@ class EventTimer:
self.mp.TriggerLocalEvent(self.event_name)
# noinspection PyPep8Naming,PyProtectedMember
# noinspection PyPep8Naming
class MP:
def __init__(self, name: str, lua: LuaRuntime):
@ -117,15 +117,19 @@ class MP:
try:
func = self._lua.globals()[func_name]
if not func:
self.log.warning(i18n.events_lua_function_not_found.format(i18n.events_lua_local, func_name))
self.log.warning(f"Cannot trigger local event: '{func_name}' not found!")
continue
fd = func(*args)
funcs_data.append(fd)
except Exception as e:
self.log.error(i18n.events_lua_calling_error.format(f"{e}", event_name, func_name, f"{args}"))
# TODO: i18n
self.log.error(f'Error: "{e}" - while calling lua event "{event_name}" with arguments: {args} - '
f'in function: "{func_name}"')
# self.log.exception(e)
else:
self.log.warning(i18n.events_not_found.format(event_name, "ev.call_lua_event(), MP.Trigger<>Event()"))
# TODO: i18n
self.log.warning(f"Event {event_name} does not exist, maybe ev.call_lua_event() or MP.Trigger<>Event()?. "
f"Just skipping it...")
return self._lua.table_from(funcs_data)
@ -559,7 +563,6 @@ class FS:
return os.path.join(*args)
# noinspection PyProtectedMember
class LuaPluginsLoader:
def __init__(self, plugins_dir):

View File

@ -57,14 +57,7 @@
"client_event_invalid_data": "从事件返回的数据无效:{}",
"client_player_disconnected": "离开服务器。游戏时间:{}分钟。",
"": "事件系统",
"events_not_callable": "无法添加事件\"{}\"。请改用\"{}\"。跳过...",
"events_not_found": "事件\"{}\"未注册。也许{}?跳过...",
"events_calling_error": "调用函数\"{}\"时出错。",
"events_lua_function_not_found": "无法调用{}lua事件 - 未找到\"{}\"。",
"events_lua_local": "本地 ",
"events_lua_calling_error": "错误:\"{}\" - 调用lua事件\"{}\"时出错,函数:\"{}\",参数:{}",
"": "Events system",
"": "插件加载器",

View File

@ -59,13 +59,6 @@
"": "Events system",
"events_not_callable": "Unable to add event \"{}\". Use \"{}\" instead. Skipping...",
"events_not_found": "Event \"{}\" is not registered. Maybe {}? Skipping...",
"events_calling_error": "Error calling \"{}\" in function \"{}\".",
"events_lua_function_not_found": "Unable to call {}lua event - \"{}\" not found.",
"events_lua_local": "local ",
"events_lua_calling_error": "Error: \"{}\" - calling lua event \"{}\", function: \"{}\", arguments: {}",
"": "Plugins loader",
"plugins_not_found_load": "Function \"def load():\" not found.",

View File

@ -59,13 +59,6 @@
"": "Events system",
"events_not_callable": "Невозможно добавить ивент \"{}\". Использую лучше \"{}\". Скип...",
"events_not_found": "Ивент \"{}\" не зарегистрирован. Может {}? Скип...",
"events_calling_error": "Ошибка во время вызова \"{}\" в функции \"{}\".",
"events_lua_function_not_found": "Невозможно вызвать {}lua ивент - \"{}\" не найдена.",
"events_lua_local": "локальный ",
"events_lua_calling_error": "Ошибка: \"{}\" - во время вызова lua ивента \"{}\", функция: \"{}\" , аргументы: {}",
"": "Plugins loader",
"plugins_not_found_load": "Функция \"def load():\" не найдена.",

View File

@ -62,12 +62,7 @@ class i18n:
# Events system
events_not_callable: str
events_not_found: str
events_calling_error: str
events_lua_function_not_found: str
events_lua_local: str
events_lua_calling_error: str
# Plugins loader

View File

@ -106,32 +106,6 @@ class MultiLanguage:
"client_event_invalid_data": "Invalid data returned from event: {}",
"client_player_disconnected": "Left the server. Playtime: {} min",
"": "Events system",
"events_not_callable": "Unable to add event \"{}\". Use \"{}\" instead. Skipping...",
"events_not_found": "Event \"{}\" is not registered. Maybe {}? Skipping...",
"events_calling_error": "Error calling \"{}\" in function \"{}\".",
"events_lua_function_not_found": "Unable to call {}lua event - \"{}\" not found.",
"events_lua_local": "local ",
"events_lua_calling_error": "Error: \"{}\" - calling lua event \"{}\", function: \"{}\", arguments: {}",
"": "Plugins loader",
"plugins_not_found_load": "Function \"def load():\" not found.",
"plugins_not_found_start": "Function \"def start():\" not found.",
"plugins_not_found_unload": "Function \"def unload():\" not found.",
"plugins_kt_invalid": "\"kt\" variable does not belong to the KuiToi class.",
"plugins_invalid": "Plugin \"{}\" cannot be run in KuiToi.",
"plugins_error_loading": "An error occurred while loading the plugin {}: {}",
"": "Lua plugins loader",
"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_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_unload": "Stopping Lua plugin: {}",
"": "Command: man",
"man_message_man": "man - Shows the help page for COMMAND.\nUsage: man COMMAND",
"help_message_man": "Shows the help page for COMMAND.",