mirror of
https://github.com/kuitoi/kuitoi-Server.git
synced 2026-06-18 22:51:03 +00:00
Update en docs
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
# 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).\
|
||||||
|
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.
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
try:
|
||||||
|
import KuiToi
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
kt = KuiToi("Example")
|
||||||
|
log = kt.log
|
||||||
|
config = {"config_version": 0.1, "sql": {"enabled": False, "host": "127.0.0.1", "port": 3363, "database": "fucklua"}}
|
||||||
|
cfg_file = "config.json"
|
||||||
|
|
||||||
|
|
||||||
|
async def my_event_handler(event_data):
|
||||||
|
log.info(f"{event_data}")
|
||||||
|
|
||||||
|
|
||||||
|
async def load():
|
||||||
|
# Инициализация плагина
|
||||||
|
with open(cfg_file, 'w') as f:
|
||||||
|
json.dump(config, f)
|
||||||
|
cgf = config
|
||||||
|
log.info(cgf)
|
||||||
|
ev.register_event("my_event", my_event_handler)
|
||||||
|
log.info("Плагин загружен успешно.")
|
||||||
|
|
||||||
|
|
||||||
|
async def start():
|
||||||
|
# Запуск процессов плагина
|
||||||
|
await ev.call_async_event("my_event")
|
||||||
|
await ev.call_async_event("my_event", "Some data", data="some data too")
|
||||||
|
log.info("Плагин запустился успешно.")
|
||||||
|
|
||||||
|
|
||||||
|
async def unload():
|
||||||
|
# Код завершающий все процессы
|
||||||
|
log.info("Плагин выгружен успешно.")
|
||||||
+28
-27
@@ -1,36 +1,37 @@
|
|||||||
import KuiToi # Import server object
|
import json
|
||||||
|
|
||||||
beam = KuiToi("TestPlugin") # Init plugin with name "TestPlugin"
|
try:
|
||||||
log = beam.log # Use logger from server
|
import KuiToi
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
kt = KuiToi("Example")
|
||||||
|
log = kt.log
|
||||||
|
config = {"config_version": 0.1, "sql": {"enabled": False, "host": "127.0.0.1", "port": 3363, "database": "fucklua"}}
|
||||||
|
cfg_file = "config.json"
|
||||||
|
|
||||||
|
|
||||||
def on_load():
|
def my_event_handler(event_data):
|
||||||
# When plugin initialization Server uses plugin.load() to load plugin.
|
log.info(f"{event_data}")
|
||||||
# def load(): is really needed
|
|
||||||
log.info(beam.name)
|
|
||||||
|
|
||||||
|
|
||||||
# Events handlers
|
def load():
|
||||||
|
# Инициализация плагина
|
||||||
def on_started():
|
with open(cfg_file, 'w') as f:
|
||||||
# Simple event handler
|
json.dump(config, f)
|
||||||
log.info("Server starting...")
|
cgf = config
|
||||||
|
log.info(cgf)
|
||||||
|
ev.register_event("my_event", my_event_handler)
|
||||||
|
log.info("Плагин загружен успешно.")
|
||||||
|
|
||||||
|
|
||||||
# Simple event register
|
def start():
|
||||||
beam.register_event("on_started", on_started)
|
# Запуск процессов плагина
|
||||||
|
ev.call_event("my_event")
|
||||||
|
ev.call_event("my_event", "Some data", data="some data too")
|
||||||
|
log.info("Плагин запустился успешно.")
|
||||||
|
|
||||||
|
|
||||||
def any_func(data=None):
|
def unload():
|
||||||
# Custom event handler
|
# Код завершающий все процессы
|
||||||
log.info(f"Data from any_func: {data}")
|
log.info("Плагин выгружен успешно.")
|
||||||
|
|
||||||
|
|
||||||
# Create custom event
|
|
||||||
beam.register_event("my_event", any_func)
|
|
||||||
|
|
||||||
# Call custom event
|
|
||||||
beam.call_event("my_event")
|
|
||||||
beam.call_event("my_event", "Some data")
|
|
||||||
# This will be an error since any_func accepts only one argument at the input
|
|
||||||
beam.call_event("my_event", "Some data", "Some data1")
|
|
||||||
|
|||||||
+78
-18
@@ -1,32 +1,92 @@
|
|||||||
# Plugins System
|
# Plugin System
|
||||||
|
|
||||||
## Install
|
## Installing the Library with "Stubs"
|
||||||
###### (Lib can't ready to use)
|
###### (This means that it will not work without a server, but the IDE will suggest the API)
|
||||||
|
###### (The library is still under development)
|
||||||
|
|
||||||
* From pip:\
|
* Using pip:\
|
||||||
`$ pip install KuiToi`
|
`$ pip install KuiToi`
|
||||||
* From source:\
|
* From source code:\
|
||||||
`git clone https://github.com/KuiToi/KuiToi-PyLib`
|
`git clone https://github.com/KuiToi/KuiToi-PyLib`
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import KuiToi
|
try:
|
||||||
|
import KuiToi
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
beam = KuiToi("TestPlugin")
|
kt = KuiToi("Example")
|
||||||
logger = beam.log
|
log = kt.log
|
||||||
|
|
||||||
def load(): # Plugins load from here
|
def my_event_handler(event_data):
|
||||||
print(beam.name)
|
log.info(f"{event_data}")
|
||||||
|
|
||||||
def on_started():
|
def load():
|
||||||
logger.info("Server starting...")
|
# Plugin initialization
|
||||||
|
ev.register_event("my_event", my_event_handler)
|
||||||
|
log.info("Plugin loaded successfully.")
|
||||||
|
|
||||||
beam.register_event("on_started", on_started)
|
|
||||||
|
def start():
|
||||||
|
# Running plugin processes
|
||||||
|
ev.call_event("my_event")
|
||||||
|
ev.call_event("my_event", "Some data", data="some data too")
|
||||||
|
log.info("Plugin started successfully.")
|
||||||
|
|
||||||
|
|
||||||
|
def unload():
|
||||||
|
# Code that ends all processes
|
||||||
|
log.info("Plugin unloaded successfully.")
|
||||||
```
|
```
|
||||||
|
|
||||||
* Basic Events: ['on_started', 'on_auth, 'on_stop']
|
* It is recommended to use `open()` after `load()`. Otherwise, use `kt.load()` - creates a file in the `plugin/<plugin_name>/<filename>` folder.
|
||||||
* Create new event : `beam.register_event("my_event", my_event_function)`
|
* Creating your own event: `kt.register_event("my_event", my_event_function)`
|
||||||
* Call event: `beam.call_event("my_event")`
|
* Calling an event: `kt.call_event("my_event")`
|
||||||
* Call event with some data: `beam.call_event("my_event", data, data2)`
|
* Calling an event with data: `kt.call_event("my_event", data, data2=data2)`
|
||||||
* Calls _**can't support**_ like this: `beam.call_event("my_event", data=data)`
|
* Basic events: _Will write later_
|
||||||
|
|
||||||
|
## Async Functions
|
||||||
|
|
||||||
|
Async support is available.
|
||||||
|
|
||||||
|
```python
|
||||||
|
try:
|
||||||
|
import KuiToi
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
kt = KuiToi("Example")
|
||||||
|
log = kt.log
|
||||||
|
|
||||||
|
|
||||||
|
async def my_event_handler(event_data):
|
||||||
|
log.info(f"{event_data}")
|
||||||
|
|
||||||
|
|
||||||
|
async def load():
|
||||||
|
# Plugin initialization
|
||||||
|
ev.register_event("my_event", my_event_handler)
|
||||||
|
log.info("Plugin loaded successfully.")
|
||||||
|
|
||||||
|
|
||||||
|
async def start():
|
||||||
|
# Running plugin processes
|
||||||
|
await ev.call_async_event("my_event")
|
||||||
|
await ev.call_async_event("my_event", "Some data", data="some data too")
|
||||||
|
log.info("Plugin started successfully.")
|
||||||
|
|
||||||
|
|
||||||
|
async def unload():
|
||||||
|
# Code that ends all processes
|
||||||
|
log.info("Plugin unloaded successfully.")
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
A more extensive example can also be found in [async_example.py](./async_example.py).
|
||||||
|
|
||||||
|
* Creating your own event: `kt.register_event("my_event", my_event_function)` (register_event checks for function)
|
||||||
|
* Calling an async event: `kt.call_async_event("my_event")`
|
||||||
|
* Calling an async event with data: `kt.call_async_event("my_event", data, data2=data2)`
|
||||||
|
* Basic async events: _Will write later_
|
||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
# Documentation for KuiToi Server
|
# Documentation for KuiToi Server
|
||||||
|
|
||||||
#### At the moment, the English documentation is out of date and its usage is not recommended.
|
### The documentation is not perfect yet, but it will be one day
|
||||||
|
|
||||||
1. Setup and Start server - [here](setup)
|
1. Setup and Start server - [here](setup)
|
||||||
2. Plugins and Events system - [here](plugins)
|
2. Plugins and Events system - [here](plugins)
|
||||||
3. MultiLanguage - [here](./multilanguage)
|
3. MultiLanguage - [here](./multilanguage)
|
||||||
|
|||||||
+56
-14
@@ -1,18 +1,32 @@
|
|||||||
# Hello from KuiToi Server
|
# Greetings from KuiToi Server
|
||||||
|
|
||||||
## Start
|
## Well, let's begin
|
||||||
|
|
||||||
* Need **Python 3.10.x** to start!
|
###### _(Here are the commands for Linux)_
|
||||||
* After cloning use this:
|
|
||||||
|
* **Python 3.10.x** is required to run the server! It won't work on Python 3.11...
|
||||||
|
* You can check the version of your Python installation with the following command:
|
||||||
```bash
|
```bash
|
||||||
$ python3 --version # Python 3.10.6
|
python3 --version # Python 3.10.6
|
||||||
$ python3 main.py --help # Show help message
|
```
|
||||||
$ python3 main.py # Start server
|
* Clone the repository and navigate to it.
|
||||||
|
* Install everything that's needed.
|
||||||
|
* Then, using my "script", remove all unnecessary files and move to the core source code.
|
||||||
|
```bash
|
||||||
|
git clone -b Stable https://github.com/kuitoi/KuiToi-Server.git && cd KuiToi-Server
|
||||||
|
pip install -r requirements.txt
|
||||||
|
mv ./src/ $HOME/ktsrc/ && rm -rf ./* && mv $HOME/ktsrc/* . && rm -rf $HOME/ktsrc
|
||||||
|
```
|
||||||
|
* Here's how to view information about the server and start it:
|
||||||
|
```bash
|
||||||
|
python3 main.py --help # Displays all available commands
|
||||||
|
python3 main.py # Starts the server
|
||||||
```
|
```
|
||||||
|
|
||||||
## Setup
|
## Configuration
|
||||||
|
|
||||||
* After starting server creating `kuitoi.yaml`; Default:
|
* After starting the server, a `kuitoi.yaml` file will be created.
|
||||||
|
* By default, it looks like this:
|
||||||
```yaml
|
```yaml
|
||||||
!!python/object:modules.ConfigProvider.config_provider.Config
|
!!python/object:modules.ConfigProvider.config_provider.Config
|
||||||
Auth:
|
Auth:
|
||||||
@@ -23,11 +37,39 @@ Game:
|
|||||||
max_cars: 1
|
max_cars: 1
|
||||||
players: 8
|
players: 8
|
||||||
Server:
|
Server:
|
||||||
debug: true
|
debug: false
|
||||||
description: This server uses KuiToi!
|
description: Welcome to KuiToi Server!
|
||||||
|
language: en
|
||||||
name: KuiToi-Server
|
name: KuiToi-Server
|
||||||
server_ip: 0.0.0.0
|
server_ip: 0.0.0.0
|
||||||
server_port: 30814
|
server_port: 30813
|
||||||
```
|
WebAPI:
|
||||||
* Server can't start without BEAM Auth.key
|
enabled: false
|
||||||
|
secret_key: <random_key>
|
||||||
|
server_ip: 127.0.0.1
|
||||||
|
server_port: 8433
|
||||||
|
|
||||||
|
```
|
||||||
|
### Auth
|
||||||
|
|
||||||
|
* If you set `private: false` and do not set a `key`, the server will request a BeamMP key and will not start without it.
|
||||||
|
* By entering a BeamMP key, the server will appear in the launcher list.
|
||||||
|
* You can get a key here: [https://beammp.com/k/keys ↗](https://beammp.com/k/keys)
|
||||||
|
|
||||||
|
### Game
|
||||||
|
|
||||||
|
* `map` specifies only the name of the map. That is, open the mod with the map in `map.zip/levels` - the name of the map will be there, and that's what you need to insert.
|
||||||
|
* `max_cars` - the maximum number of cars per player
|
||||||
|
* `players` - the maximum number of players
|
||||||
|
|
||||||
|
### Server
|
||||||
|
|
||||||
|
* `debug` - should debug messages be displayed (for experienced users only; slightly affects performance)
|
||||||
|
* `description` - server description for the BeamMP launcher
|
||||||
|
* `language` - the language in which the server will run (currently available: en, ru)
|
||||||
|
* `name` - server name for the BeamMP launcher
|
||||||
|
* `server_ip` - the IP address to be used by the server (for experienced users only; defaults to 0.0.0.0)
|
||||||
|
* `server_port` - the port on which the server will run
|
||||||
|
|
||||||
|
### WebAPI
|
||||||
|
##### _Docs are not ready yet_
|
||||||
+14
-2
@@ -1,3 +1,15 @@
|
|||||||
# Web RESP API for the Server
|
Here's the translation of the readme.txt content:
|
||||||
|
|
||||||
In development...
|
# WebAPI for the server
|
||||||
|
|
||||||
|
## Available endpoints
|
||||||
|
|
||||||
|
* `/stop`:
|
||||||
|
* Required parameters:
|
||||||
|
* `secret_key` - The key specified in the server configuration
|
||||||
|
|
||||||
|
|
||||||
|
* `/event.get`
|
||||||
|
* The endpoint is not yet ready
|
||||||
|
* Required parameters:
|
||||||
|
* `secret_key` - The key specified in the server configuration
|
||||||
|
|||||||
Reference in New Issue
Block a user