mirror of
https://github.com/kuitoi/kuitoi-Server.git
synced 2025-08-17 08:15:42 +00:00
Minor updates;
Memory fix.. :) UDP Fix;
This commit is contained in:
parent
43fd56f327
commit
e440cdf022
@ -40,11 +40,6 @@ class Client:
|
||||
self._connect_time = 0
|
||||
self._last_position = {}
|
||||
|
||||
ev.register_event("onServerStopped", self.__gracefully_kick)
|
||||
|
||||
async def __gracefully_kick(self, _):
|
||||
await self.kick("Server shutdown!")
|
||||
|
||||
@property
|
||||
def _writer(self):
|
||||
return self.__writer
|
||||
@ -689,8 +684,8 @@ class Client:
|
||||
# TODO: i18n
|
||||
self.log.info(f"Disconnected, online time: {round((time.monotonic() - self._connect_time) / 60, 2)}min.")
|
||||
self.__Core.clients[self.cid] = None
|
||||
self.__Core.clients_by_id.pop(self.cid)
|
||||
self.__Core.clients_by_nick.pop(self.nick)
|
||||
del self.__Core.clients_by_id[self.cid]
|
||||
del self.__Core.clients_by_nick[self.nick]
|
||||
else:
|
||||
self.log.debug(f"Removing client; Closing connection...")
|
||||
try:
|
||||
|
@ -116,6 +116,12 @@ class Core:
|
||||
self.log.error("Error in check_alive.")
|
||||
self.log.exception(e)
|
||||
|
||||
async def __gracefully_kick(self, _):
|
||||
for client in self.clients:
|
||||
if not client:
|
||||
continue
|
||||
await client.kick("Server shutdown!")
|
||||
|
||||
@staticmethod
|
||||
def start_web():
|
||||
uvconfig = uvicorn.Config("modules.WebAPISystem.app:web_app",
|
||||
@ -297,6 +303,7 @@ class Core:
|
||||
ev.call_lua_event("onShutdown")
|
||||
ev.call_event("onServerStopped")
|
||||
await ev.call_async_event("onServerStopped")
|
||||
await self.__gracefully_kick()
|
||||
await ev.call_async_event("_plugins_unload")
|
||||
ev.call_event("_lua_plugins_unload")
|
||||
self.run = False
|
||||
|
@ -40,6 +40,7 @@ class Core:
|
||||
def create_client(self, *args, **kwargs) -> Client: ...
|
||||
def get_clients_list(self, need_cid=False) -> str: ...
|
||||
async def check_alive(self) -> None: ...
|
||||
async def __gracefully_kick(self): ...
|
||||
@staticmethod
|
||||
def start_web() -> None: ...
|
||||
def stop_me(self) -> None: ...
|
||||
|
@ -59,9 +59,10 @@ class UDPServer(asyncio.DatagramTransport):
|
||||
case _:
|
||||
self.log.debug(f"[{cid}] Unknown code: {code}")
|
||||
else:
|
||||
self.log.debug(f"Client not found.")
|
||||
self.log.debug(f"[{cid}] Client not found.")
|
||||
|
||||
except Exception as e:
|
||||
|
||||
self.log.error(f"Error handle_datagram: {e}")
|
||||
|
||||
def datagram_received(self, *args, **kwargs):
|
||||
@ -80,8 +81,9 @@ class UDPServer(asyncio.DatagramTransport):
|
||||
|
||||
async def _start(self):
|
||||
self.log.debug("Starting UDP server.")
|
||||
try:
|
||||
while self.Core.run:
|
||||
try:
|
||||
|
||||
await asyncio.sleep(0.2)
|
||||
|
||||
d = UDPServer
|
||||
@ -97,15 +99,14 @@ class UDPServer(asyncio.DatagramTransport):
|
||||
self.run = True
|
||||
while not self.transport.is_closing():
|
||||
await asyncio.sleep(0.2)
|
||||
|
||||
except OSError as e:
|
||||
self.log.error("Cannot bind port or other error")
|
||||
self.log.exception(e)
|
||||
self.run = False
|
||||
self.Core.run = False
|
||||
self.log.error(f"Cannot bind port or other error: {e}")
|
||||
except Exception as e:
|
||||
self.log.error(f"Error: {e}")
|
||||
self.log.exception(e)
|
||||
finally:
|
||||
self.run = False
|
||||
self.Core.run = False
|
||||
|
||||
def _stop(self):
|
||||
self.log.debug("Stopping UDP server")
|
||||
|
Loading…
x
Reference in New Issue
Block a user