mud_server.api.models
Pydantic models for API requests and responses.
This module defines all the data models used for API communication between the FastAPI backend and the Gradio frontend. Pydantic models provide: - Automatic request/response validation - Type checking and conversion - Clear API documentation via FastAPI’s automatic OpenAPI schema generation - Serialization/deserialization to/from JSON
Models are organized into two categories: 1. Request models: Data sent FROM the client TO the server 2. Response models: Data sent FROM the server TO the client
Classes
Login request with username and password. |
|
Registration request for creating a new player account. |
|
Registration request for creating a temporary guest account. |
|
Request to select an active character for a session. |
|
Direct login request that binds a session to a world + character. |
|
Request to change the current user's password. |
|
Admin request to manage user accounts. |
|
Admin request to create a new user account. |
|
Admin request to stop the server gracefully. |
|
Request to logout and end the current session. |
|
Request to execute a game command. |
|
Request to send a chat message. |
|
Response to login request. |
|
Response to direct login request. |
|
Response to character selection request. |
|
Response containing the user's characters. |
|
Response to registration request. |
|
Response to guest registration request. |
|
Response to admin user creation request. |
|
Response to game command execution. |
|
Response containing player's current game status. |
|
Response containing list of user accounts. |
|
Admin response containing all user records from database. |
|
Metadata about a single database table. |
|
Admin response containing database table metadata. |
|
Admin response containing rows for a specific database table. |
|
Admin response containing character locations with names. |
|
Admin response containing active session connections. |
|
Request to force-disconnect a session. |
|
Response for a kick session request. |
|
Admin response containing all active sessions from database. |
|
Admin response containing recent chat messages across all rooms. |
|
Response to user management action (role change, ban, unban). |
|
Response to server stop request. |
|
Request to execute an Ollama command. |
|
Response to Ollama command execution. |
|
Request to clear Ollama conversation context for the current session. |
|
Response to clear Ollama context request. |
Module Contents
- class mud_server.api.models.LoginRequest(/, **data)[source]
Bases:
pydantic.BaseModelLogin request with username and password.
- username
Account username (case-sensitive for database lookup)
- password
Plain text password (will be verified against bcrypt hash)
- world_id
Optional world id used to filter characters on login
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.RegisterRequest(/, **data)[source]
Bases:
pydantic.BaseModelRegistration request for creating a new player account.
- username
Desired username (2-20 characters, must be unique)
- password
Desired password (minimum 8 characters)
- password_confirm
Password confirmation (must match password)
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.RegisterGuestRequest(/, **data)[source]
Bases:
pydantic.BaseModelRegistration request for creating a temporary guest account.
- password
Desired password (validated against STANDARD policy)
- password_confirm
Password confirmation (must match password)
- character_name
Initial character name for the guest account
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.SelectCharacterRequest(/, **data)[source]
Bases:
pydantic.BaseModelRequest to select an active character for a session.
- session_id
Active session ID for authentication
- character_id
Character id to bind to the session
- world_id
World id to bind to the session (must match character’s world)
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.LoginDirectRequest(/, **data)[source]
Bases:
pydantic.BaseModelDirect login request that binds a session to a world + character.
- username
Account username (case-sensitive for database lookup)
- password
Plain text password (will be verified against bcrypt hash)
- world_id
Target world id (must be accessible by the user)
- character_name
Existing character name (optional)
- create_character
When true, create the character if missing
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.ChangePasswordRequest(/, **data)[source]
Bases:
pydantic.BaseModelRequest to change the current user’s password.
- session_id
Active session ID for authentication
- old_password
Current password (verified before change)
- new_password
New password (minimum 8 characters, must differ from old)
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.UserManagementRequest(/, **data)[source]
Bases:
pydantic.BaseModelAdmin request to manage user accounts.
Requires admin or superuser permissions. Allows role changes, banning, unbanning, and password changes of user accounts. Superusers can manage all users, admins can only manage users with lower permissions.
- session_id
Active session ID (must have appropriate permission)
- target_username
Username of the account to manage
- action
Management action - one of: - “change_role”: Change user’s role (requires new_role parameter) - “ban” or “deactivate”: Deactivate user account (prevents login, removes active session) - “delete”: Permanently delete user and related data (superuser only) - “unban”: Reactivate previously banned account - “change_password”: Change user’s password (requires new_password parameter)
- new_role
(Optional) New role when action is “change_role” Valid roles: “player”, “worldbuilder”, “admin”, “superuser”
- new_password
(Optional) New password when action is “change_password” Must be at least 8 characters
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.CreateUserRequest(/, **data)[source]
Bases:
pydantic.BaseModelAdmin request to create a new user account.
Requires admin or superuser permissions. Admins may create Player or WorldBuilder accounts. Superusers may create any role, including Admin and Superuser.
Passwords must meet the STANDARD password policy, and password_confirm must match password.
- session_id
Active session ID (must have appropriate permission)
- username
Desired username (2-20 characters, must be unique)
- password
Desired password (must meet STANDARD policy)
- password_confirm
Password confirmation (must match password)
- role
Role to assign to the new account Valid roles: “player”, “worldbuilder”, “admin”, “superuser”
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.ServerStopRequest(/, **data)[source]
Bases:
pydantic.BaseModelAdmin request to stop the server gracefully.
Requires STOP_SERVER permission (admin or superuser only). Server will shutdown 0.5 seconds after sending response to allow the HTTP response to be delivered.
- session_id
Active session ID (must have STOP_SERVER permission)
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.LogoutRequest(/, **data)[source]
Bases:
pydantic.BaseModelRequest to logout and end the current session.
- session_id
Active session ID to be terminated
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.CommandRequest(/, **data)[source]
Bases:
pydantic.BaseModelRequest to execute a game command.
Supports all game commands including movement, inventory management, chat, and special commands. Commands can be prefixed with “/” or not.
- session_id
Active session ID for authentication
- command
Game command to execute, examples: - Movement: “north”, “n”, “south”, “s”, “east”, “e”, “west”, “w”, “up”, “u”, “down”, “d” - Actions: “look”, “inventory”, “get <item>”, “drop <item>” - Chat: “say <message>”, “yell <message>”, “whisper <player> <message>” - Info: “who”, “help”
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.ChatRequest(/, **data)[source]
Bases:
pydantic.BaseModelRequest to send a chat message.
Note: This model is defined but may not be actively used. Chat is typically sent via CommandRequest with “/say” command.
- session_id
Active session ID for authentication
- message
Chat message text
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.LoginResponse(/, **data)[source]
Bases:
pydantic.BaseModelResponse to login request.
- success
True if login succeeded, False otherwise
- message
Welcome message on success, error message on failure
- session_id
(Optional) UUID session identifier on successful login
- role
(Optional) User’s role on successful login (“player”, “worldbuilder”, “admin”, or “superuser”)
- characters
List of available characters for selection
- available_worlds
List of available worlds for selection
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.LoginDirectResponse(/, **data)[source]
Bases:
pydantic.BaseModelResponse to direct login request.
- success
True if login succeeded, False otherwise
- message
Welcome message on success, error message on failure
- session_id
Session identifier on successful login
- role
User’s role on successful login
- character_name
Selected character name on success
- world_id
World bound to the session
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.SelectCharacterResponse(/, **data)[source]
Bases:
pydantic.BaseModelResponse to character selection request.
- success
True if character selected
- message
Success or error message
- character_name
Selected character name on success
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.CharactersResponse(/, **data)[source]
Bases:
pydantic.BaseModelResponse containing the user’s characters.
- characters
List of character summaries
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.RegisterResponse(/, **data)[source]
Bases:
pydantic.BaseModelResponse to registration request.
- success
True if account created, False otherwise
- message
Success confirmation or error details
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.RegisterGuestResponse(/, **data)[source]
Bases:
pydantic.BaseModelResponse to guest registration request.
- success
True if account created, False otherwise
- message
Success confirmation or error details
- username
Generated guest username for login
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.CreateUserResponse(/, **data)[source]
Bases:
pydantic.BaseModelResponse to admin user creation request.
- success
True if account created, False otherwise
- message
Success confirmation or error details
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.CommandResponse(/, **data)[source]
Bases:
pydantic.BaseModelResponse to game command execution.
- success
True if command executed successfully, False for errors
- message
Command result, room description, error message, etc. For movement: includes new room description For inventory: lists items in inventory For chat: confirmation message For errors: explanation of what went wrong
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.StatusResponse(/, **data)[source]
Bases:
pydantic.BaseModelResponse containing player’s current game status.
Used for periodic status updates to keep the UI synchronized.
- Attributes:
active_players: List of usernames currently online current_room: Player’s current room ID (e.g., “spawn”, “forest_1”) inventory: Formatted inventory string (e.g., “Your inventory:
Torch
Rope”)
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.UserListResponse(/, **data)[source]
Bases:
pydantic.BaseModelResponse containing list of user accounts.
Used for admin user management interfaces.
- users
List of user data dictionaries with account information
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.DatabasePlayersResponse(/, **data)[source]
Bases:
pydantic.BaseModelAdmin response containing all user records from database.
Requires VIEW_LOGS permission. Includes account details and character counts.
- players
List of user data dictionaries with fields: - id: Database record ID - username: Account username - password_hash: Truncated password hash (first 20 chars + “…”) - role: User role - account_origin: Account provenance (“visitor”, “admin”, “superuser”, “system”, “legacy”) - is_guest: Guest flag - guest_expires_at: Guest expiry timestamp - character_count: Number of linked characters - created_at: Account creation timestamp - last_login: Last login timestamp - is_active: Account status (True=active, False=banned)
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.DatabaseTableInfo(/, **data)[source]
Bases:
pydantic.BaseModelMetadata about a single database table.
- name
Table name.
- columns
List of column names in order.
- row_count
Number of rows in the table.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.DatabaseTablesResponse(/, **data)[source]
Bases:
pydantic.BaseModelAdmin response containing database table metadata.
Requires VIEW_LOGS permission. Used for table discovery in the admin UI.
- tables
List of DatabaseTableInfo entries.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- tables: list[DatabaseTableInfo]
- class mud_server.api.models.DatabaseTableRowsResponse(/, **data)[source]
Bases:
pydantic.BaseModelAdmin response containing rows for a specific database table.
Requires VIEW_LOGS permission. Includes column names and raw row values.
- table
Table name.
- columns
Column names in order.
- rows
Row values as a list of rows (each row is a list of values).
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.DatabasePlayerLocationsResponse(/, **data)[source]
Bases:
pydantic.BaseModelAdmin response containing character locations with names.
Requires VIEW_LOGS permission. Useful for cross-referencing room occupancy.
- locations
List of dicts with fields: - character_id - character_name - zone_id - room_id - updated_at
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.DatabaseConnectionsResponse(/, **data)[source]
Bases:
pydantic.BaseModelAdmin response containing active session connections.
Requires VIEW_LOGS permission. Includes activity age for dashboards.
- connections
List of session dictionaries with fields: - id - username - session_id - created_at - last_activity - expires_at - client_type - age_seconds
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.KickSessionRequest(/, **data)[source]
Bases:
pydantic.BaseModelRequest to force-disconnect a session.
Requires KICK_USERS permission.
- session_id
Admin’s active session id.
- target_session_id
Session id to disconnect.
- reason
Optional reason for audit/logging.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.KickSessionResponse(/, **data)[source]
Bases:
pydantic.BaseModelResponse for a kick session request.
- success
True if session was removed.
- message
Human-readable result.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.DatabaseSessionsResponse(/, **data)[source]
Bases:
pydantic.BaseModelAdmin response containing all active sessions from database.
Requires VIEW_LOGS permission. Shows who is currently logged in.
- sessions
List of session data dictionaries with fields: - id: Database record ID - username: Logged in account - character_name: Active character for the session (if selected) - session_id: UUID session identifier - created_at: Login timestamp - last_activity: Most recent API request timestamp - expires_at: Session expiry timestamp (NULL means no expiry) - client_type: Client identifier (tui, browser, api)
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.DatabaseChatResponse(/, **data)[source]
Bases:
pydantic.BaseModelAdmin response containing recent chat messages across all rooms.
Requires VIEW_LOGS permission. Useful for moderation and monitoring.
- messages
List of chat message dictionaries with fields: - id: Database record ID - username: Message sender - message: Message text (includes [WHISPER], [YELL] prefixes) - room: Room ID where message was sent - timestamp: Message timestamp
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.UserManagementResponse(/, **data)[source]
Bases:
pydantic.BaseModelResponse to user management action (role change, ban, unban).
- success
True if action completed successfully
- message
Confirmation message or error details
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.ServerStopResponse(/, **data)[source]
Bases:
pydantic.BaseModelResponse to server stop request.
Server will shutdown shortly after sending this response.
- success
True if shutdown initiated
- message
Confirmation message indicating who initiated shutdown
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.OllamaCommandRequest(/, **data)[source]
Bases:
pydantic.BaseModelRequest to execute an Ollama command.
Requires VIEW_LOGS permission (admin or superuser only).
- session_id
Active session ID (must have appropriate permission)
- server_url
URL of the Ollama server (e.g., “http://localhost:11434”)
- command
Ollama command to execute (e.g., “list”, “ps”, “run llama2”)
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.OllamaCommandResponse(/, **data)[source]
Bases:
pydantic.BaseModelResponse to Ollama command execution.
- success
True if command executed successfully
- output
Command output or error message
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.ClearOllamaContextRequest(/, **data)[source]
Bases:
pydantic.BaseModelRequest to clear Ollama conversation context for the current session.
Requires VIEW_LOGS permission (admin or superuser only).
- session_id
Active session ID (must have appropriate permission)
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class mud_server.api.models.ClearOllamaContextResponse(/, **data)[source]
Bases:
pydantic.BaseModelResponse to clear Ollama context request.
- success
True if context was cleared successfully
- message
Confirmation message
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.