frost.server package¶
Subpackages¶
Submodules¶
frost.server.auth module¶
-
frost.server.auth.auth_required(func: Callable) → Callable¶ A decorator to ensure a client is logged in with valid authentication before running the wrapped function. Automatically passes through the user’s ID (
id_) and token (token) as arguments.- Parameters
func (Callable) – The function being wrapped
- Returns
The inner execute function
- Return type
Callable
frost.server.cogs module¶
-
class
frost.server.cogs.Auth¶ Bases:
frost.ext.cog.CogDeals with user authentication.
route='authentication'-
login(**kwargs: Any) → None¶ Logs in a user with the given username and password.
- Parameters
data (Dict[str, Any]) – Data received from the client
-
register(**kwargs: Any) → None¶ Registers a new user with the given username and password.
- Parameters
data (Dict[str, Any]) – Data received from the client
-
route= 'authentication'¶
-
-
class
frost.server.cogs.Msgs¶ Bases:
frost.ext.cog.CogDeals with user messages.
route='messages'-
get_room_msgs(token: str, id_: str, max_: int = 100, **kwargs: Any) → None¶ Gets up to
max_previous messages from a specific room.- Parameters
data (Dict[str, Any]) – Data received from the client
max (int, optional) – The maximum number of messages to get from a room, defaults to 50
token (str) – The user’s token, autofilled by
frost.server.auth.auth_required()id (str) – The user’s ID, autofilled by
frost.server.auth.auth_required()
-
route= 'messages'¶
-
send_msg(token: str, id_: str, **kwargs: Any) → None¶ Saves the message received from a client and sends it off to other users in the room.
- Parameters
data (Dict[str, Any]) – Data received from a client
token (str) – The user’s token, autofilled by
frost.server.auth.auth_required()id (str) – The user’s ID, autofilled by
frost.server.auth.auth_required()
-
-
class
frost.server.cogs.Rooms¶ Bases:
frost.ext.cog.CogDeals with room within a server.
route='rooms'-
create(token: str, id_: str, **kwargs: Any) → None¶ Creates a new room in the server.
- Parameters
data (Dict[str, Any]) – Data received from a client
token (str) – The user’s token, autofilled by
frost.server.auth.auth_required()id (str) – The user’s ID, autofilled by
frost.server.auth.auth_required()
-
get_all_joined(token: str, id_: str, **kwargs: Any) → None¶ Get the all the rooms a specific user has joined.
- Parameters
data (Dict[str, Any]) – Data received from a client
token (str) – The user’s token, autofilled by
frost.server.auth.auth_required()id (str) – The user’s ID, autofilled by
frost.server.auth.auth_required()
-
get_invite_code(token: str, id_: str, **kwargs: Any) → None¶ Get the invite code of a specific room in the server. Only an owner can request for their own room’s invite code.
- Parameters
data (Dict[str, Any]) – Data received from a client
token (str) – The user’s token, autofilled by
frost.server.auth.auth_required()id (str) – The user’s ID, autofilled by
frost.server.auth.auth_required()
-
get_members(token: str, id_: str, **kwargs: Any) → None¶ Get all the members of a specific room the user has joined.
- Parameters
data (Dict[str, Any]) – Data received from a client
token (str) – The user’s token, autofilled by
frost.server.auth.auth_required()id (str) – The user’s ID, autofilled by
frost.server.auth.auth_required()
-
join(token: str, id_: str, **kwargs: Any) → None¶ Join an existing room within the server with an invite code.
- Parameters
data (Dict[str, Any]) – Data received from a client
token (str) – The user’s token, autofilled by
frost.server.auth.auth_required()id (str) – The user’s ID, autofilled by
frost.server.auth.auth_required()
-
leave(token: str, id_: str, **kwargs: Any) → None¶ Leave a specific room within the server.
- Parameters
data (Dict[str, Any]) – Data received from a client
token (str) – The user’s token, autofilled by
frost.server.auth.auth_required()id (str) – The user’s ID, autofilled by
frost.server.auth.auth_required()
-
route= 'rooms'¶
-
frost.server.headers module¶
frost.server.logger module¶
The logger for the server (logger).
frost.server.objects module¶
-
class
frost.server.objects.Memory¶ Bases:
objectStores information that needs to be passed around and easily accessible.
-
all_users= {}¶ All connected users.
-
logged_in_users= {}¶ All logged in users.
-
-
class
frost.server.objects.UserObj(addr: Tuple[str, int], conn: socket.socket, id_: Optional[int] = None, username: Optional[str] = None)¶ Bases:
objectRepresents a user.
- Parameters
addr (Tuple[str, int]) – The IP address and port of the connected user
conn ('socket.socket') – The socket instance of the connected user
id (Optional[int]) – The user’s ID, defaults to None
username (Optional[str]) – The user’s username, defaults to None
-
property
is_logged_in¶ Returns whether or not the user is logged in.
- Returns
Whether or not the user is logged in
- Return type
bool
-
login(id_: int, username: str) → None¶ Sets the user’s ID and username, “logging them in”.
- Parameters
id (int) – The user’s ID
username (str) – The user’s username
frost.server.server module¶
-
class
frost.server.server.FrostServer(file: str)¶ Bases:
frost.server.socketio.base_server.BaseServerThe Frost server.
- Parameters
file (str) – The
__file__of the file this is imported in
-
on_user_connect(conn: socket.socket, addr: Tuple[str, int]) → None¶ Handles the connection of a client and executes tasks accordingly.
- Parameters
conn ('socket.socket') – The client’s connection
addr (Tuple[str, int]) – The user’s IP address and port
-
run(ip: str = '127.0.0.1', port: int = 5555) → None¶ Runs the FrostServer.
- Parameters
ip (str, optional) – The IP for the server to bind to, defaults to ‘127.0.0.1’
port (int, optional) – The port for the server to bind to, defaults to 5555
-
frost.server.server.send_partial(send_func: Callable, conn: socket.socket) → Callable¶ A partial function to auto fill the
connparameter offrost.server.socketio.base_server.BaseServer()- Parameters
send_func (Callable) – The send function that sends data to the client
conn (socket.socket) – A specific client’s connection
- Returns
The inner execute function
- Return type
Callable
Module contents¶
-
class
frost.server.FrostServer(file: str)¶ Bases:
frost.server.socketio.base_server.BaseServerThe Frost server.
- Parameters
file (str) – The
__file__of the file this is imported in
-
on_user_connect(conn: socket.socket, addr: Tuple[str, int]) → None¶ Handles the connection of a client and executes tasks accordingly.
- Parameters
conn ('socket.socket') – The client’s connection
addr (Tuple[str, int]) – The user’s IP address and port
-
run(ip: str = '127.0.0.1', port: int = 5555) → None¶ Runs the FrostServer.
- Parameters
ip (str, optional) – The IP for the server to bind to, defaults to ‘127.0.0.1’
port (int, optional) – The port for the server to bind to, defaults to 5555
-
class
frost.server.Status¶ Bases:
enum.EnumThe status enums
-
DUPLICATE_ROOM_NAME: int = 6¶
-
DUPLICATE_USERNAME: int = 3¶
-
EMPTY_ROOM_NAME: int = 5¶
-
INVALID_AUTH: int = 1¶
-
INVALID_INVITE: int = 7¶
-
PERMISSION_DENIED: int = 2¶
-
ROOM_NOT_FOUND: int = 4¶
-
SUCCESS: int = 0¶
-
-
class
frost.server.threaded(*args: Any, **kwargs: Any)¶ Bases:
objectA decorator to thread a function/method.
-
frost.server.auth_required(func: Callable) → Callable¶ A decorator to ensure a client is logged in with valid authentication before running the wrapped function. Automatically passes through the user’s ID (
id_) and token (token) as arguments.- Parameters
func (Callable) – The function being wrapped
- Returns
The inner execute function
- Return type
Callable