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