Source code for bacommon.docui.routes.classichost
# Released under the MIT License. See LICENSE for details.
#
"""Routes for the classic host doc-ui domain.
Pages a game host serves its connected clients over the game
connection (see ``bacommon.hostui``): the defaults classic hosts ship
with. Hosts may serve other routes of their own alongside these.
"""
from __future__ import annotations # Docs-generation hack.
from dataclasses import dataclass
from typing import Annotated, override
from efro.dataclassio import ioprepped, IOAttrs
import bacommon.docui.v2 as dui2
from bacommon.docui.routes import DocUIRoute, family_members
[docs]
class ClassicHostRoute(DocUIRoute):
"""Family class for classic host routes."""
[docs]
@override
@classmethod
def get_route_types(cls) -> tuple[type[DocUIRoute], ...]:
return family_members(AnyClassicHostRoute)
# (Window layout: the route default, wide.)
[docs]
@ioprepped
@dataclass
class Stats(ClassicHostRoute, path='/stats'):
"""Who is in the party and how their connections are doing."""
[docs]
@ioprepped
@dataclass
class KickVote(ClassicHostRoute, path='/kickvote'):
"""Start or follow a vote to kick someone.
Clients open this with ``client_id`` set to whoever they chose to
kick; without one it shows any vote in progress.
"""
client_id: int | None = None
[docs]
@ioprepped
@dataclass
class KickVoteStart(
ClassicHostRoute, path='/kickvote', method=dui2.RequestMethod.POST
):
"""Start a vote to kick a client."""
client_id: int
[docs]
@ioprepped
@dataclass
class KickVoteCast(
ClassicHostRoute, path='/kickvote/vote', method=dui2.RequestMethod.POST
):
"""Vote in the kick vote in progress."""
yes: bool
AnyClassicHostRoute = Stats | KickVote | KickVoteStart | KickVoteCast
# Docs-generation hack; import some stuff that we likely only forward-declared
# in our actual source code so that docs tools can find it.
from typing import (Coroutine, Any, Literal, Callable,
Generator, Awaitable, Sequence, Self, TypeIs)
import asyncio
from concurrent.futures import Future
from pathlib import Path
from enum import Enum