mirror of
https://github.com/solero/houdini.git
synced 2024-11-12 13:48:20 +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 aiocache import cached
|
||||
from datetime import datetime
|
||||
import random
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
|
||||
def get_player_string_key(_, p, player_id):
|
||||
@ -35,9 +38,17 @@ async def get_mascot_string(p, mascot_id: int):
|
||||
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.cooldown(59)
|
||||
async def handle_heartbeat(p):
|
||||
p.heartbeat = time.time()
|
||||
await p.send_xt('h')
|
||||
|
||||
|
||||
|
@ -39,6 +39,7 @@ from houdini.handlers import XTListenerManager, XMLListenerManager, DummyEventLi
|
||||
from houdini.plugins import PluginManager
|
||||
from houdini.commands import CommandManager
|
||||
|
||||
from houdini.handlers.play.player import server_heartbeat
|
||||
|
||||
class Houdini:
|
||||
|
||||
@ -91,6 +92,7 @@ class Houdini:
|
||||
|
||||
self.spawn_rooms = None
|
||||
|
||||
self.heartbeat = None
|
||||
async def start(self):
|
||||
self.config = config
|
||||
|
||||
@ -225,6 +227,7 @@ class Houdini:
|
||||
|
||||
await self.plugins.setup(houdini.plugins)
|
||||
|
||||
self.heartbeat = asyncio.create_task(server_heartbeat(self))
|
||||
async with self.server:
|
||||
await self.server.serve_forever()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user