mirror of
https://github.com/kuitoi/kuitoi-Server.git
synced 2026-06-19 15:11:25 +00:00
[+] sent counters
[+] Colored TPS [~] Minor
This commit is contained in:
+36
-23
@@ -25,12 +25,20 @@ class Client:
|
|||||||
self.__queue_tpc = Queue()
|
self.__queue_tpc = Queue()
|
||||||
self.__queue_udp = Queue()
|
self.__queue_udp = Queue()
|
||||||
|
|
||||||
self._tpc_count = 0
|
self._tpc_count_recv = 0
|
||||||
self._udp_count = 0
|
self._udp_count_recv = 0
|
||||||
self._tpc_count_total = 0
|
self._tpc_count_total_recv = 0
|
||||||
self._udp_count_total = 0
|
self._udp_count_total_recv = 0
|
||||||
self._udp_size_total = 0
|
self._udp_size_total_recv = 0.1
|
||||||
self._tpc_size_total = 0
|
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.tcp_pps = 0
|
||||||
self.udp_pps = 0
|
self.udp_pps = 0
|
||||||
|
|
||||||
@@ -199,6 +207,8 @@ class Client:
|
|||||||
try:
|
try:
|
||||||
if not udp_sock.is_closing():
|
if not udp_sock.is_closing():
|
||||||
# self.log.debug(f'[UDP] {data!r}; {udp_addr}')
|
# 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)
|
udp_sock.sendto(data, udp_addr)
|
||||||
except OSError:
|
except OSError:
|
||||||
self.log.debug("[UDP] Error sending")
|
self.log.debug("[UDP] Error sending")
|
||||||
@@ -208,9 +218,12 @@ class Client:
|
|||||||
return
|
return
|
||||||
|
|
||||||
header = len(data).to_bytes(4, "little", signed=True)
|
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:
|
try:
|
||||||
writer.write(header + data)
|
self._tpc_count_total_sent += 1
|
||||||
|
self._tpc_size_total_sent += len(data)
|
||||||
|
writer.write(data)
|
||||||
await writer.drain()
|
await writer.drain()
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -753,14 +766,14 @@ class Client:
|
|||||||
self.log.warning(f"UDP Unknown code: {code}; {data}")
|
self.log.warning(f"UDP Unknown code: {code}; {data}")
|
||||||
|
|
||||||
def _tick_pps(self, _):
|
def _tick_pps(self, _):
|
||||||
self.tcp_pps = self._tpc_count
|
self.tcp_pps = self._tpc_count_recv
|
||||||
self.udp_pps = self._udp_count
|
self.udp_pps = self._udp_count_recv
|
||||||
self._tpc_count = 0
|
self._tpc_count_recv = 0
|
||||||
self._udp_count = 0
|
self._udp_count_recv = 0
|
||||||
if self.tcp_pps > self._core.target_tps or self.udp_pps > self._core.target_tps:
|
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}")
|
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:
|
try:
|
||||||
if self.__queue_tpc.qsize() > 0:
|
if self.__queue_tpc.qsize() > 0:
|
||||||
packet = await self.__queue_tpc.get()
|
packet = await self.__queue_tpc.get()
|
||||||
@@ -782,15 +795,15 @@ class Client:
|
|||||||
|
|
||||||
async def _tpc_put(self, packet):
|
async def _tpc_put(self, packet):
|
||||||
if packet:
|
if packet:
|
||||||
self._tpc_count += 1
|
self._tpc_count_recv += 1
|
||||||
self._tpc_count_total += 1
|
self._tpc_count_total_recv += 1
|
||||||
self._tpc_size_total += len(packet)
|
self._tpc_size_total_recv += len(packet)
|
||||||
await self.__queue_tpc.put(packet)
|
await self.__queue_tpc.put(packet)
|
||||||
|
|
||||||
async def _udp_put(self, packet):
|
async def _udp_put(self, packet):
|
||||||
self._udp_count += 1
|
self._udp_count_recv += 1
|
||||||
self._udp_count_total += 1
|
self._udp_count_total_recv += 1
|
||||||
self._udp_size_total += len(packet)
|
self._udp_size_total_recv += len(packet)
|
||||||
await self.__queue_udp.put(packet)
|
await self.__queue_udp.put(packet)
|
||||||
|
|
||||||
async def _looper(self):
|
async def _looper(self):
|
||||||
@@ -799,7 +812,7 @@ class Client:
|
|||||||
await self._send(f"P{self.cid}") # Send clientID
|
await self._send(f"P{self.cid}") # Send clientID
|
||||||
await self._sync_resources()
|
await self._sync_resources()
|
||||||
ev.call_lua_event("onPlayerJoining", self.cid)
|
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", self.__tick_player_udp)
|
||||||
ev.register("serverTick_1s", self._tick_pps)
|
ev.register("serverTick_1s", self._tick_pps)
|
||||||
await self._recv()
|
await self._recv()
|
||||||
@@ -819,7 +832,7 @@ class Client:
|
|||||||
ev.call_lua_event("onPlayerDisconnect", self.cid)
|
ev.call_lua_event("onPlayerDisconnect", self.cid)
|
||||||
ev.call_event("onPlayerDisconnect", player=self)
|
ev.call_event("onPlayerDisconnect", player=self)
|
||||||
await ev.call_async_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_player_udp)
|
||||||
ev.unregister(self._tick_pps)
|
ev.unregister(self._tick_pps)
|
||||||
gt = round((time.monotonic() - self._connect_time) / 60, 2)
|
gt = round((time.monotonic() - self._connect_time) / 60, 2)
|
||||||
@@ -829,8 +842,8 @@ class Client:
|
|||||||
del self._core.clients_by_nick[self.nick]
|
del self._core.clients_by_nick[self.nick]
|
||||||
else:
|
else:
|
||||||
self.log.debug(f"Removing client; Closing connection...")
|
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"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: Packets: {self._udp_size_total}; Size: {self._udp_size_total}")
|
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)
|
await asyncio.sleep(0.001)
|
||||||
try:
|
try:
|
||||||
self.__writer.close()
|
self.__writer.close()
|
||||||
|
|||||||
+13
-7
@@ -21,12 +21,18 @@ class Client:
|
|||||||
self.__writer = writer
|
self.__writer = writer
|
||||||
self.__queue_tpc = Queue()
|
self.__queue_tpc = Queue()
|
||||||
self.__queue_udp = Queue()
|
self.__queue_udp = Queue()
|
||||||
self._tpc_count = 0
|
self._tpc_count_recv = 0
|
||||||
self._udp_count = 0
|
self._udp_count_recv = 0
|
||||||
self._tpc_count_total = 0
|
self._tpc_count_total_recv = 0
|
||||||
self._udp_count_total = 0
|
self._udp_count_total_recv = 0
|
||||||
self._udp_size_total = 0
|
self._udp_size_total_recv = 0.1
|
||||||
self._tpc_size_total = 0
|
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.tcp_pps = 0
|
||||||
self.udp_pps = 0
|
self.udp_pps = 0
|
||||||
self._udp_sock: Tuple[DatagramTransport | None, Tuple[str, int] | None] = (None, None)
|
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_tcp(self, data: bytes) -> None: ...
|
||||||
async def _handle_codes_udp(self, data: bytes) -> None: ...
|
async def _handle_codes_udp(self, data: bytes) -> None: ...
|
||||||
def _tick_pps(self, _): ...
|
def _tick_pps(self, _): ...
|
||||||
async def __tick_player_tpc(self, _): ...
|
async def __tick_player_tcp(self, _): ...
|
||||||
async def __tick_player_udp(self, _): ...
|
async def __tick_player_udp(self, _): ...
|
||||||
async def _tpc_put(self, data): ...
|
async def _tpc_put(self, data): ...
|
||||||
async def _udp_put(self, data): ...
|
async def _udp_put(self, data): ...
|
||||||
|
|||||||
@@ -9,10 +9,10 @@
|
|||||||
__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.8 (pre)'
|
__version__ = '0.4.8'
|
||||||
__build__ = 2664 # Я это считаю лог файлами
|
__build__ = 2676 # Я это считаю лог файлами
|
||||||
__author__ = 'SantaSpeen'
|
__author__ = 'SantaSpeen'
|
||||||
__author_email__ = 'admin@kuitoi.su'
|
__author_email__ = 'admin@anidev.ru'
|
||||||
__license__ = "FPA"
|
__license__ = "FPA"
|
||||||
__copyright__ = 'Copyright 2024 © SantaSpeen (Maxim Khomutov)'
|
__copyright__ = 'Copyright 2024 © SantaSpeen (Maxim Khomutov)'
|
||||||
|
|
||||||
|
|||||||
+23
-5
@@ -54,7 +54,7 @@ class Core:
|
|||||||
self.tcp_pps = 0
|
self.tcp_pps = 0
|
||||||
self.udp_pps = 0
|
self.udp_pps = 0
|
||||||
|
|
||||||
self.tps = 10
|
self.tps = 60
|
||||||
self.target_tps = 60
|
self.target_tps = 60
|
||||||
|
|
||||||
self.lock_upload = False
|
self.lock_upload = False
|
||||||
@@ -291,6 +291,27 @@ class Core:
|
|||||||
if self.tick_counter == (60 * self.target_tps):
|
if self.tick_counter == (60 * self.target_tps):
|
||||||
self.tick_counter = 0
|
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"<green><b>{tps:.2f}</b></green>"
|
||||||
|
elif tps > half:
|
||||||
|
return f"<yellow><b>{tps:.2f}</b></yellow>"
|
||||||
|
elif half > tps:
|
||||||
|
return f"<red><b>{tps:.2f}</b></red>"
|
||||||
|
|
||||||
|
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):
|
async def _tick(self):
|
||||||
try:
|
try:
|
||||||
ticks = 0
|
ticks = 0
|
||||||
@@ -301,10 +322,7 @@ class Core:
|
|||||||
ticks_5s = deque(maxlen=5 * int(target_tps) + 1)
|
ticks_5s = deque(maxlen=5 * int(target_tps) + 1)
|
||||||
ticks_30s = deque(maxlen=30 * int(target_tps) + 1)
|
ticks_30s = deque(maxlen=30 * int(target_tps) + 1)
|
||||||
ticks_60s = deque(maxlen=60 * 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: "
|
console.add_command("tps", lambda _: self._cmd_tps(ticks_2s, ticks_5s, ticks_30s, ticks_60s),
|
||||||
f"{calc_ticks(ticks_5s, 5):.2f}, "
|
|
||||||
f"{calc_ticks(ticks_30s, 30):.2f}, "
|
|
||||||
f"{calc_ticks(ticks_60s, 60):.2f}.",
|
|
||||||
None, "Print TPS", {"tps": None})
|
None, "Print TPS", {"tps": None})
|
||||||
_add_to_sleep = deque([0.0, 0.0, 0.0,], maxlen=3 * int(target_tps))
|
_add_to_sleep = deque([0.0, 0.0, 0.0,], maxlen=3 * int(target_tps))
|
||||||
# _t0 = []
|
# _t0 = []
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ class Core:
|
|||||||
async def _useful_ticks(self, _) -> None: ...
|
async def _useful_ticks(self, _) -> None: ...
|
||||||
async def __gracefully_kick(self): ...
|
async def __gracefully_kick(self): ...
|
||||||
async def __gracefully_remove(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: ...
|
def _tick(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 kick_cmd(self, args: list) -> None | str: ...
|
||||||
|
|||||||
Reference in New Issue
Block a user