server module

Server package.

server.handlers

Handlers package.

Handlers are classes that manages different objects on the server-side. For instance, they can be responsible for updating the player when a local player packet is sent by the client. The handler will then recuperate that packet and extract its contents to update the server-side player. (Yes, I know this makes the server less authoritative and prone to cheating, but I don’t know about the idea of sending millions of packets to a server whenever a player moves, and then some algorithm that predicts the player’s movement whilst the packets are being processed on the server-side (a.k.a. client predictions)).

server.handlers.player_handler

Module name: player_handler

This module handles the server-side player object.

class game.server.handlers.player_handler.PlayerHandler

Bases: object

Class for creating the player handler.

get_player(player_name: str) dict[str, int | dict | None]

Return player dict by player name if they exist, None otherwise.

get_players(compressed=False) list[dict] | bytes

Return the players list.

track_player(player: dict) str

Track the specified player by adding them to the players list.

untrack_player(player_name: str) None

Untrack the player by removing them from the players list, if possible.

update_player(player: dict) None

Update the player attributes with the received player object, if possible.

update_player_position(player_packet: dict) None

Update the player position attribute with the received player packet, if possible.

server.handlers.world_handler

Module name: world_handler

This module handles the server-side world object.

class game.server.handlers.world_handler.WorldHandler

Bases: object

Class for a creating the world handler.

create_world(seed: str, theme: dict, size: str) None

Create a new server world.

get_map_data(only_dynatile=False) bytes

Return the map data in bytes.

get_world() World

Return the world object.

set_world(world: World) None

Set the server world.

update_broken_tile(player_dict: dict) None

Update the map’s tile data with the received player dict to take into account a broken tile.

server.server

Module name: server

This module handles the server and updates its state. It also calls the server tasks that send data packets to the client.

(See data/states/server_states for the different server states.) (See server/tasks for the different server tasks.)

class game.server.server.Server

Bases: object

Class for creating a new Server.

client_handler(conn, addr) None

Handle incoming server clients.

run(state, _seed: str, theme: dict, size: str) None

Run the server and listen for connections.

safe_closure() None

Safely close the server when no players are online after a certain amount of time.

start(_seed: str, theme: dict, size: str) None

Prepare the server.

stop() None

Stop the server if it’s running, otherwise don’t do anything.

server.tasks

Module name: tasks

This module defines all the server-side tasks when a connection is being established with a client, or whilst a client is connected. These tasks check the authenticity of the client and any potential errors, as well as send various required packets of game data, requests and responses. These packets are built using the different packet builders.

(See network/builders for the different packet builders.) (See network/protocol for the different requests and responses.)

class game.server.tasks.ServerTasks

Bases: object

Class for regrouping all server-side requests.

static disconnection(data: bytes) bool

Task for disconnecting a player.

static game_state(conn, data: bytes, player_handler: PlayerHandler, world_handler: WorldHandler) bool

Task for sending the overall game state to a client.

static incoming_packets(conn, data: bytes, player_handler: PlayerHandler, world_handler: WorldHandler) bool

Task for handling incoming packets. Return True if packet is received and is valid, otherwise False

static local_game_state(conn)

Task for requesting a local game state. This is only for specific needs like player data.

static map_data(conn, addr, world_handler: WorldHandler) None

Task for sending map data to a client.

static player_join(conn, player_handler: PlayerHandler) str

Task for joining a client player to the server. Returns the received player name.

static recognition(conn, addr) bool

Task for checking for player authenticity.