mirror of
https://github.com/solero/houdini.git
synced 2024-11-14 14:48:21 +00:00
Disconnect idle clients after 1 minute
This commit is contained in:
parent
29706065ae
commit
4495779bf1
@ -4,7 +4,10 @@ from houdini.data.penguin import Penguin
|
|||||||
from houdini.constants import ClientType
|
from houdini.constants import ClientType
|
||||||
|
|
||||||
from aiocache import cached
|
from aiocache import cached
|
||||||
|
from datetime import datetime
|
||||||
import random
|
import random
|
||||||
|
import asyncio
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
def get_player_string_key(_, p, player_id):
|
def get_player_string_key(_, p, player_id):
|
||||||
@ -35,9 +38,17 @@ async def get_mascot_string(p, mascot_id: int):
|
|||||||
return string
|
return string
|
||||||
|
|
||||||
|
|
||||||
|
async def server_heartbeat(server):
|
||||||
|
while True:
|
||||||
|
timer = time.time()
|
||||||
|
await asyncio.sleep(61)
|
||||||
|
for penguin in server.penguins_by_id.values():
|
||||||
|
if penguin.heartbeat < timer:
|
||||||
|
await penguin.close()
|
||||||
@handlers.handler(XTPacket('u', 'h'))
|
@handlers.handler(XTPacket('u', 'h'))
|
||||||
@handlers.cooldown(59)
|
@handlers.cooldown(59)
|
||||||
async def handle_heartbeat(p):
|
async def handle_heartbeat(p):
|
||||||
|
p.heartbeat = time.time()
|
||||||
await p.send_xt('h')
|
await p.send_xt('h')
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ from houdini.handlers import XTListenerManager, XMLListenerManager, DummyEventLi
|
|||||||
from houdini.plugins import PluginManager
|
from houdini.plugins import PluginManager
|
||||||
from houdini.commands import CommandManager
|
from houdini.commands import CommandManager
|
||||||
|
|
||||||
|
from houdini.handlers.play.player import server_heartbeat
|
||||||
|
|
||||||
class Houdini:
|
class Houdini:
|
||||||
|
|
||||||
@ -91,6 +92,7 @@ class Houdini:
|
|||||||
|
|
||||||
self.spawn_rooms = None
|
self.spawn_rooms = None
|
||||||
|
|
||||||
|
self.heartbeat = None
|
||||||
async def start(self):
|
async def start(self):
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
@ -225,6 +227,7 @@ class Houdini:
|
|||||||
|
|
||||||
await self.plugins.setup(houdini.plugins)
|
await self.plugins.setup(houdini.plugins)
|
||||||
|
|
||||||
|
self.heartbeat = asyncio.create_task(server_heartbeat(self))
|
||||||
async with self.server:
|
async with self.server:
|
||||||
await self.server.serve_forever()
|
await self.server.serve_forever()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user