Work time

This commit is contained in:
Maxim Khomutov 2023-07-31 21:37:48 +03:00
parent cdec0b9949
commit 3a42fa13e7
2 changed files with 17 additions and 2 deletions

View File

@ -5,14 +5,16 @@
# Licence: FPA # Licence: FPA
# (c) kuitoi.su 2023 # (c) kuitoi.su 2023
import asyncio import asyncio
import math
import os import os
import random import random
import time
from threading import Thread from threading import Thread
import aiohttp import aiohttp
import uvicorn import uvicorn
from core import utils from core import utils, __version__
from core.Client import Client from core.Client import Client
from core.tcp_server import TCPServer from core.tcp_server import TCPServer
from core.udp_server import UDPServer from core.udp_server import UDPServer
@ -26,6 +28,7 @@ class Core:
def __init__(self): def __init__(self):
self.log = utils.get_logger("core") self.log = utils.get_logger("core")
self.loop = asyncio.get_event_loop() self.loop = asyncio.get_event_loop()
self.start_time = time.monotonic()
self.run = False self.run = False
self.direct = False self.direct = False
self.clients = [] self.clients = []
@ -111,6 +114,8 @@ class Core:
if not client.ready: if not client.ready:
client.is_disconnected() client.is_disconnected()
continue continue
if not client.alive:
await client.kick("You are not alive!")
await client._send(ca) await client._send(ca)
except Exception as e: except Exception as e:
self.log.error("Error in check_alive.") self.log.error("Error in check_alive.")
@ -288,6 +293,7 @@ class Core:
# self.udp.start, # self.udp.start,
f_tasks = [self.tcp.start, self.udp._start, console.start, self.stop_me, self.heartbeat, self.check_alive] f_tasks = [self.tcp.start, self.udp._start, console.start, self.stop_me, self.heartbeat, self.check_alive]
if config.RCON['enabled']: if config.RCON['enabled']:
console.rcon.version = f"KuiToi {__version__}"
rcon = console.rcon(config.RCON['password'], config.RCON['server_ip'], config.RCON['server_port']) rcon = console.rcon(config.RCON['password'], config.RCON['server_ip'], config.RCON['server_port'])
f_tasks.append(rcon.start) f_tasks.append(rcon.start)
for task in f_tasks: for task in f_tasks:
@ -324,6 +330,12 @@ class Core:
ev.call_event("_lua_plugins_unload") ev.call_event("_lua_plugins_unload")
await ev.call_async_event("_plugins_unload") await ev.call_async_event("_plugins_unload")
self.run = False self.run = False
self.log.info(i18n.stop)
if config.WebAPI["enabled"]: if config.WebAPI["enabled"]:
asyncio.run(self.web_stop()) asyncio.run(self.web_stop())
total_time = time.monotonic() - self.start_time
hours = int(total_time // 3600)
minutes = int((total_time % 3600) // 60)
seconds = math.ceil(total_time % 60)
t = f"{'' if not hours else f'{hours} hours, '}{'' if not hours else f'{minutes} min., '}{seconds} sec."
self.log.info(f"Working time: {t}")
self.log.info(i18n.stop)

View File

@ -5,6 +5,7 @@
# Licence: FPA # Licence: FPA
# (c) kuitoi.su 2023 # (c) kuitoi.su 2023
import asyncio import asyncio
import time
from threading import Thread from threading import Thread
from typing import Callable, List, Dict from typing import Callable, List, Dict
@ -16,6 +17,7 @@ from .udp_server import UDPServer
class Core: class Core:
def __init__(self): def __init__(self):
self.start_time = time.monotonic()
self.log = utils.get_logger("core") self.log = utils.get_logger("core")
self.loop = asyncio.get_event_loop() self.loop = asyncio.get_event_loop()
self.run = False self.run = False
@ -45,6 +47,7 @@ class Core:
def start_web() -> None: ... def start_web() -> None: ...
def stop_me(self) -> None: ... def stop_me(self) -> None: ...
async def heartbeat(self, test=False) -> None: ... async def heartbeat(self, test=False) -> None: ...
async def kick_cmd(self, args: list) -> None | str: ...
async def main(self) -> None: ... async def main(self) -> None: ...
def start(self) -> None: ... def start(self) -> None: ...
async def stop(self) -> None: ... async def stop(self) -> None: ...