Skip to content

General Architecture Principles

The architecture of the game is designed to balance performance and accuracy by leveraging both the client and server. Here are the key principles and guidelines for deciding where to place logic within the game:

Game world & world instance

  • Game World: The game world is the overarching world that contains all information. It defines the rules, lore, assets, data, and mechanics that are shared across all world instances.
  • World Instance: A world instance is a specific instantiation of the game world that is commonly hosted by a client. It contains an environment, characters, and objects that are unique to that instance. It is still governed by the rules and mechanics of the game world.

Client Responsibilities

  • Rendering: The client is responsible for rendering the game world, including graphics, animations, and user interface elements.
  • Input Handling: The client processes player inputs such as movements, actions, and commands.
  • Delegated Authority: Clients can perform specific functions on behalf of the server when hosting a world instance.
  • Server Communication: Clients communicate changes to the server when they perform actions that impact the game world, such as editing character, inventory, or progression.
  • Host Communication: Clients communicate changes to a host when they perform actions that impact the world instance.
  • Client Prediction: Clients predict the outcome of their actions to provide a seamless experience while waiting for server validation.
Critical communication

Under normal circumstances, clients do not communicate for non-critical actions, such as UI changes, animations, or interactions with world objects. This can be excused when a server or host must register or validate these actions.

Guest & Host

Guest Clients - Default mode for clients. - Require authorization for critical actions. - Communicate with the host for updates and validation.

Host Clients - Manage a specific instance of the game world. - Authorize requests impacting all connected clients. - Relay changes to guest clients. - Hosts are assigned statically and reassigned only on disconnection.

Server Responsibilities

  • Authoritative Source: The server maintains the authoritative state of the game world, including player statistics, inventory, and progression.
  • Synchronization: The server ensures all clients experience the same game world by periodically validating and updating client states.
  • Security and Validation: The server validates critical client actions to prevent cheating and maintain game integrity.

Client-Server Communication

  • Optimized Updates: Clients and servers communicate only the changes since the last update.
  • Minimal Communication: When possible, clients may wait for more changes before communication to reduce network traffic and database load. For example:
  • When the player purchases new furniture, the client waits until the player confirms their selection before communicating the purchase to the server.
  • When the player modifies a world object, the client waits until the player confirms their changes before communicating the changes to the server.
  • Delegated Authority Management: The server defines specific functions that can be safely delegated to clients, reducing unnecessary server load.

Enhanced Security Measures

  • Periodic Audits: The server periodically audits player inventories and currency to detect and correct inconsistencies.
  • Cryptographic Validation: Critical transactions are signed and verified using cryptographic techniques to prevent tampering.

Diagrams

Bruh I really gotta break the next one into two graphs; one for Client <--> Host; and one for Host <--> Server.

Communication flow

flowchart LR

  subgraph Client[Guest Client 1]
    direction LR
    Action[Destroy inventory item]
    RemoveItem
    DisplayError
  end

  Action-->|Send request| ReceiveFromClient

  subgraph FromClient[Receive request from Client]
    direction LR
    ReceiveFromClient[Receive]-->HostValidation{Can item be destroyed?}
    HostValidation -->|Yes| AggregrateH[Aggregate changes]
    HostValidation -->|No| RejectH[Reject request] 
  end

  RejectH-->|Send rejection|DisplayError

  AggregrateH-->|Send changes|ReceiveChangeFromHost

  subgraph Server
    direction LR
    ReceiveChangeFromHost[Receive]-->ServerValidation{Validate}
    ServerValidation -->|Valid data change| Database
    ServerValidation -->|Valid request| Function[Execute function]
    ServerValidation -->|Invalid| RejectS
  end

  RejectS-->|Tell host to reject the request|HostValidation
  Function --> |Return answer|ReceiveFromServer

  subgraph FromServer[Receive answer from Server]
    direction RL
    ReceiveFromServer[Receive]-->|Translate|HostFunction{Does server allow the change?}
  end

  HostFunction -->|Yes| RemoveItem
  HostFunction -->|No| DisplayError