Implement timeouts
This commit is contained in:
parent
cb9494c89a
commit
dfbe9f6603
@ -20,6 +20,8 @@ class GameMode:
|
|||||||
name: str
|
name: str
|
||||||
mode_function: ModeFunction
|
mode_function: ModeFunction
|
||||||
allow_multitouch: bool
|
allow_multitouch: bool
|
||||||
|
min_time: int
|
||||||
|
max_time: int
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -62,9 +64,9 @@ class Arbiter:
|
|||||||
self.modeswitch_time = None
|
self.modeswitch_time = None
|
||||||
self.clients: dict[WebSocket, ClientState] = dict()
|
self.clients: dict[WebSocket, ClientState] = dict()
|
||||||
|
|
||||||
def mode(self, name: str, allow_multitouch: bool = True):
|
def mode(self, name: str, allow_multitouch: bool = True, min_time=10, max_time=90):
|
||||||
def inner(f: ModeFunction):
|
def inner(f: ModeFunction):
|
||||||
self.modes.append(GameMode(name, f, allow_multitouch))
|
self.modes.append(GameMode(name, f, allow_multitouch, min_time, max_time))
|
||||||
|
|
||||||
return inner
|
return inner
|
||||||
|
|
||||||
@ -118,7 +120,7 @@ class Arbiter:
|
|||||||
self.state.mode = self.current_mode.name
|
self.state.mode = self.current_mode.name
|
||||||
self.update_next_mode()
|
self.update_next_mode()
|
||||||
self.modeswitch_time = datetime.now() + timedelta(
|
self.modeswitch_time = datetime.now() + timedelta(
|
||||||
seconds=settings.arbiter_mode_switch_cycle
|
seconds=random.randint(self.current_mode.min_time, self.current_mode.max_time)
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.current_mode_task:
|
if self.current_mode_task:
|
||||||
@ -151,7 +153,7 @@ class Arbiter:
|
|||||||
arbiter = Arbiter()
|
arbiter = Arbiter()
|
||||||
|
|
||||||
|
|
||||||
@arbiter.mode("democracy", allow_multitouch=False)
|
@arbiter.mode("democracy", allow_multitouch=False, min_time=5*60, max_time=10*60)
|
||||||
async def _(get_input: InputGetter, set_output: OutputSetter):
|
async def _(get_input: InputGetter, set_output: OutputSetter):
|
||||||
while True:
|
while True:
|
||||||
await asyncio.sleep(settings.democracy_vote_cycle)
|
await asyncio.sleep(settings.democracy_vote_cycle)
|
||||||
@ -188,7 +190,7 @@ async def _(get_input: InputGetter, set_output: OutputSetter):
|
|||||||
set_output(output)
|
set_output(output)
|
||||||
|
|
||||||
|
|
||||||
@arbiter.mode("anarchy", allow_multitouch=False)
|
@arbiter.mode("anarchy", allow_multitouch=False, min_time=5*60, max_time=10*60)
|
||||||
async def _(get_input: InputGetter, set_output: OutputSetter):
|
async def _(get_input: InputGetter, set_output: OutputSetter):
|
||||||
while True:
|
while True:
|
||||||
await asyncio.sleep(settings.democracy_vote_cycle)
|
await asyncio.sleep(settings.democracy_vote_cycle)
|
||||||
@ -206,7 +208,7 @@ async def _(get_input: InputGetter, set_output: OutputSetter):
|
|||||||
set_output(output)
|
set_output(output)
|
||||||
|
|
||||||
|
|
||||||
@arbiter.mode("random", allow_multitouch=False)
|
@arbiter.mode("random", allow_multitouch=False, min_time=20, max_time=90)
|
||||||
async def _(get_input: InputGetter, set_output: OutputSetter):
|
async def _(get_input: InputGetter, set_output: OutputSetter):
|
||||||
while True:
|
while True:
|
||||||
await asyncio.sleep(settings.democracy_vote_cycle)
|
await asyncio.sleep(settings.democracy_vote_cycle)
|
||||||
|
Loading…
Reference in New Issue
Block a user