diff --git a/src/core/Client.py b/src/core/Client.py
index 576d1ea..c4fcb89 100644
--- a/src/core/Client.py
+++ b/src/core/Client.py
@@ -25,12 +25,20 @@ class Client:
self.__queue_tpc = Queue()
self.__queue_udp = Queue()
- self._tpc_count = 0
- self._udp_count = 0
- self._tpc_count_total = 0
- self._udp_count_total = 0
- self._udp_size_total = 0
- self._tpc_size_total = 0
+ self._tpc_count_recv = 0
+ self._udp_count_recv = 0
+ self._tpc_count_total_recv = 0
+ self._udp_count_total_recv = 0
+ self._udp_size_total_recv = 0.1
+ self._tpc_size_total_recv = 0.1
+
+ # self._tpc_count_sent = 0
+ # self._udp_count_sent = 0
+ self._tpc_count_total_sent = 0
+ self._udp_count_total_sent = 0
+ self._udp_size_total_sent = 0.1
+ self._tpc_size_total_sent = 0.1
+
self.tcp_pps = 0
self.udp_pps = 0
@@ -199,6 +207,8 @@ class Client:
try:
if not udp_sock.is_closing():
# self.log.debug(f'[UDP] {data!r}; {udp_addr}')
+ self._udp_count_total_sent += 1
+ self._udp_size_total_sent += len(data)
udp_sock.sendto(data, udp_addr)
except OSError:
self.log.debug("[UDP] Error sending")
@@ -208,9 +218,12 @@ class Client:
return
header = len(data).to_bytes(4, "little", signed=True)
- # self.log.debug(f'[TCP] {header + data!r}')
+ data = header + data
+ # self.log.debug(f'[TCP] {data!r}')
try:
- writer.write(header + data)
+ self._tpc_count_total_sent += 1
+ self._tpc_size_total_sent += len(data)
+ writer.write(data)
await writer.drain()
return True
except Exception as e:
@@ -753,14 +766,14 @@ class Client:
self.log.warning(f"UDP Unknown code: {code}; {data}")
def _tick_pps(self, _):
- self.tcp_pps = self._tpc_count
- self.udp_pps = self._udp_count
- self._tpc_count = 0
- self._udp_count = 0
+ self.tcp_pps = self._tpc_count_recv
+ self.udp_pps = self._udp_count_recv
+ self._tpc_count_recv = 0
+ self._udp_count_recv = 0
if self.tcp_pps > self._core.target_tps or self.udp_pps > self._core.target_tps:
self.log.warning(f"PPS > TPS; PPS: TPC: {self.tcp_pps}, UDP: {self.udp_pps}")
- async def __tick_player_tpc(self, _):
+ async def __tick_player_tcp(self, _):
try:
if self.__queue_tpc.qsize() > 0:
packet = await self.__queue_tpc.get()
@@ -782,15 +795,15 @@ class Client:
async def _tpc_put(self, packet):
if packet:
- self._tpc_count += 1
- self._tpc_count_total += 1
- self._tpc_size_total += len(packet)
+ self._tpc_count_recv += 1
+ self._tpc_count_total_recv += 1
+ self._tpc_size_total_recv += len(packet)
await self.__queue_tpc.put(packet)
async def _udp_put(self, packet):
- self._udp_count += 1
- self._udp_count_total += 1
- self._udp_size_total += len(packet)
+ self._udp_count_recv += 1
+ self._udp_count_total_recv += 1
+ self._udp_size_total_recv += len(packet)
await self.__queue_udp.put(packet)
async def _looper(self):
@@ -799,7 +812,7 @@ class Client:
await self._send(f"P{self.cid}") # Send clientID
await self._sync_resources()
ev.call_lua_event("onPlayerJoining", self.cid)
- ev.register("serverTick", self.__tick_player_tpc)
+ ev.register("serverTick", self.__tick_player_tcp)
ev.register("serverTick", self.__tick_player_udp)
ev.register("serverTick_1s", self._tick_pps)
await self._recv()
@@ -819,7 +832,7 @@ class Client:
ev.call_lua_event("onPlayerDisconnect", self.cid)
ev.call_event("onPlayerDisconnect", player=self)
await ev.call_async_event("onPlayerDisconnect", player=self)
- ev.unregister(self.__tick_player_tpc)
+ ev.unregister(self.__tick_player_tcp)
ev.unregister(self.__tick_player_udp)
ev.unregister(self._tick_pps)
gt = round((time.monotonic() - self._connect_time) / 60, 2)
@@ -829,8 +842,8 @@ class Client:
del self._core.clients_by_nick[self.nick]
else:
self.log.debug(f"Removing client; Closing connection...")
- self.log.debug(f"TPC: Packets: {self._tpc_count_total}; Size: {self._tpc_size_total}")
- self.log.debug(f"UDP: Packets: {self._udp_size_total}; Size: {self._udp_size_total}")
+ self.log.debug(f"TPC: Recv: {self._tpc_count_total_recv}; {self._tpc_size_total_recv / KB:.4f}kb; Sent: {self._tpc_count_total_sent}; {self._tpc_size_total_sent / KB:.4f}kb;")
+ self.log.debug(f"UDP: Recv: {self._udp_count_total_recv}; {self._udp_size_total_recv / KB:.4f}kb; Sent: {self._udp_count_total_sent}; {self._udp_size_total_sent / KB:.4f}kb;")
await asyncio.sleep(0.001)
try:
self.__writer.close()
diff --git a/src/core/Client.pyi b/src/core/Client.pyi
index 037551d..7a11822 100644
--- a/src/core/Client.pyi
+++ b/src/core/Client.pyi
@@ -21,12 +21,18 @@ class Client:
self.__writer = writer
self.__queue_tpc = Queue()
self.__queue_udp = Queue()
- self._tpc_count = 0
- self._udp_count = 0
- self._tpc_count_total = 0
- self._udp_count_total = 0
- self._udp_size_total = 0
- self._tpc_size_total = 0
+ self._tpc_count_recv = 0
+ self._udp_count_recv = 0
+ self._tpc_count_total_recv = 0
+ self._udp_count_total_recv = 0
+ self._udp_size_total_recv = 0.1
+ self._tpc_size_total_recv = 0.1
+ # self._tpc_count_sent = 0
+ # self._udp_count_sent = 0
+ self._tpc_count_total_sent = 0
+ self._udp_count_total_sent = 0
+ self._udp_size_total_sent = 0.1
+ self._tpc_size_total_sent = 0.1
self.tcp_pps = 0
self.udp_pps = 0
self._udp_sock: Tuple[DatagramTransport | None, Tuple[str, int] | None] = (None, None)
@@ -99,7 +105,7 @@ class Client:
async def _handle_codes_tcp(self, data: bytes) -> None: ...
async def _handle_codes_udp(self, data: bytes) -> None: ...
def _tick_pps(self, _): ...
- async def __tick_player_tpc(self, _): ...
+ async def __tick_player_tcp(self, _): ...
async def __tick_player_udp(self, _): ...
async def _tpc_put(self, data): ...
async def _udp_put(self, data): ...
diff --git a/src/core/__init__.py b/src/core/__init__.py
index 83c8a77..133e01b 100644
--- a/src/core/__init__.py
+++ b/src/core/__init__.py
@@ -9,10 +9,10 @@
__title__ = 'KuiToi-Server'
__description__ = 'BeamingDrive Multiplayer server compatible with BeamMP clients.'
__url__ = 'https://github.com/kuitoi/kuitoi-Server'
-__version__ = '0.4.8 (pre)'
-__build__ = 2664 # Я это считаю лог файлами
+__version__ = '0.4.8'
+__build__ = 2676 # Я это считаю лог файлами
__author__ = 'SantaSpeen'
-__author_email__ = 'admin@kuitoi.su'
+__author_email__ = 'admin@anidev.ru'
__license__ = "FPA"
__copyright__ = 'Copyright 2024 © SantaSpeen (Maxim Khomutov)'
diff --git a/src/core/core.py b/src/core/core.py
index 375b6b4..c5746f7 100644
--- a/src/core/core.py
+++ b/src/core/core.py
@@ -54,7 +54,7 @@ class Core:
self.tcp_pps = 0
self.udp_pps = 0
- self.tps = 10
+ self.tps = 60
self.target_tps = 60
self.lock_upload = False
@@ -291,6 +291,27 @@ class Core:
if self.tick_counter == (60 * self.target_tps):
self.tick_counter = 0
+ def _get_color_tps(self, ticks, d):
+ tps = calc_ticks(ticks, d)
+ half = self.target_tps // 2
+ qw = self.target_tps // 4
+ if tps > half+qw:
+ return f"{tps:.2f}"
+ elif tps > half:
+ return f"{tps:.2f}"
+ elif half > tps:
+ return f"{tps:.2f}"
+
+ def _cmd_tps(self, ticks_2s, ticks_5s, ticks_30s, ticks_60s):
+ t = ["-, ", "-, ", "-."]
+ if len(ticks_5s) > 5 * self.target_tps:
+ t[0] = f"{self._get_color_tps(ticks_5s, 5)}, "
+ if len(ticks_30s) > 30 * self.target_tps:
+ t[1] = f"{self._get_color_tps(ticks_30s, 30)}, "
+ if len(ticks_60s) > 60 * self.target_tps:
+ t[2] = f"{self._get_color_tps(ticks_60s, 60)}."
+ return f"html:{self._get_color_tps(ticks_2s, 2)} TPS; For last 5s, 30s, 60s: " + "".join(t)
+
async def _tick(self):
try:
ticks = 0
@@ -301,10 +322,7 @@ class Core:
ticks_5s = deque(maxlen=5 * int(target_tps) + 1)
ticks_30s = deque(maxlen=30 * int(target_tps) + 1)
ticks_60s = deque(maxlen=60 * int(target_tps) + 1)
- console.add_command("tps", lambda _: f"{calc_ticks(ticks_2s, 2):.2f}TPS; For last 5s, 30s, 60s: "
- f"{calc_ticks(ticks_5s, 5):.2f}, "
- f"{calc_ticks(ticks_30s, 30):.2f}, "
- f"{calc_ticks(ticks_60s, 60):.2f}.",
+ console.add_command("tps", lambda _: self._cmd_tps(ticks_2s, ticks_5s, ticks_30s, ticks_60s),
None, "Print TPS", {"tps": None})
_add_to_sleep = deque([0.0, 0.0, 0.0,], maxlen=3 * int(target_tps))
# _t0 = []
diff --git a/src/core/core.pyi b/src/core/core.pyi
index d24133f..bcca1fc 100644
--- a/src/core/core.pyi
+++ b/src/core/core.pyi
@@ -49,6 +49,8 @@ class Core:
async def _useful_ticks(self, _) -> None: ...
async def __gracefully_kick(self): ...
async def __gracefully_remove(self): ...
+ def _get_color_tps(self, ticks, d): ...
+ async def _cmd_tps(self, ticks_2s, ticks_5s, ticks_30s, ticks_60s) -> str: ...
def _tick(self) -> None: ...
async def heartbeat(self, test=False) -> None: ...
async def kick_cmd(self, args: list) -> None | str: ...