Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

ERC7566 proposes a communication channel for player interaction in on-chain games.

This article translates, summarizes, and expands on the proposal below.

I have also covered a range of other EIPs.

Overview

The proposal describes a Multiplayer Game Communication (MGC) interface. It uses rooms to match and group players, and messages to handle actions between them. With this system, a single smart contract can allow multiple players to play a game on-chain, avoiding reliance on a centralized server that could compromise fairness.

The mechanism works as follows.

Room Creation and Matchmaking

Players first enter a virtual space called a room to participate in a multiplayer game. Rooms identify individual game sessions or groups of players. A matchmaking system can find a suitable room or create a new one based on player skill levels and preferences.

Processing Actions Through Messages

During a game, each player action, such as moving, attacking, or using an item, is represented as a message. A smart contract processes these messages and updates the game state. Player interactions and in-game events can thus be reflected as they are processed on-chain.

Using Smart Contracts

The system uses smart contracts. These are programs that execute on a blockchain. Game rules and transactions between players can be defined in code in advance to support fairness. Game logic can therefore execute transparently and securely on the blockchain without depending on a centralized server.

The proposal aims to use blockchain technology to make multiplayer games fairer and more secure. Removing reliance on centralized servers can also protect game fairness from server outages and operator misconduct.

Motivation

The proposed Multiplayer Game Communication framework (MGC framework) provides a way to run multiplayer games on a blockchain without relying on centralized servers. Its intended benefits and features include the following.

Verifiable Fairness

Access to All Game Data

Players and developers can access game data through a standardized interface. This allows them to verify the fairness of a game independently.

On-Chain Actions

Player actions take place on-chain and are recorded there, helping prevent data tampering and cheating.

Simpler Development

Basic Grouping and Messaging Architecture

The framework provides basic structures for grouping players into rooms and processing actions through messages. Developers can therefore concentrate on the core game logic.

Modular Architecture

A large game can be divided into multiple smart contracts. This makes it possible to build more complex games on-chain.

Extensibility and Customization

Custom Messages

Developers can define custom messages for different games. The system can therefore be extended to meet the needs of a particular game.

Hierarchical Room Data

Each player is assigned a new ID within a room, making player state easier to manage.

Example Implementation

The framework could be used to run multiplayer games such as chess or card games on a blockchain. Players enter a room to participate, and each move or action is recorded on-chain as a message. Game progress is transparent, and all participants can verify fairness.

The framework gives developers a way to use blockchain technology to offer multiplayer games without the constraints of centralized servers or the associated risk of misconduct.

Specification

The principle of Multiplayer Game Communication (MGC) is to reuse the same game logic to update the state of different groups of players. The system consists of two core components: rooms and messages.

Rooms

Containers for Players

A room is a virtual space that holds players. Players first join a room to participate in a game.

Matchmaking and Connected Players

Rooms provide a way to match players and show which players are connected. This makes it easy to see who is participating in a game.

Conditions for Starting a Game

Players can begin playing only after joining a room. A room therefore acts as the space in which a game starts.

Messages

Actions Between Players

Messages represent actions performed between players. These include moving, attacking, using items, and other in-game actions.

Executing Game Actions

Messages execute game behavior and change the state of players within a room. For example, a message representing an attack on another player can reduce that player's health.

Updating Player State

Actions performed through messages directly affect player state. This allows game progress and player interactions to be reflected as they occur.

Although the principle behind MGC is simple, grouping players and managing their actions provides a way to implement multiplayer games on-chain. Developers can offer a fair and transparent game environment without relying on a centralized server.

Multiplayer on-chain game flowchart Source: https://eips.ethereum.org/EIPS/eip-7566

The original diagram is retained; any Japanese labels remain unchanged.

Interface

ts
// SPDX-License-Identifier: CC0-1.0
pragma solidity >=0.8.0;

import "./Types.sol";

interface IMOG {
    /**
     * Create a new room.
     * @dev The entity MUST be assigned a unique Id.
     * @return New room id.
     */
    function createRoom() external returns (uint256);

    /**
     * Get the total number of rooms that have been created.
     * @return Total number of rooms.
     */
    function getRoomCount() external view returns (uint256);

    /**
     * Player joins room.
     * @dev The member MUST be assigned a unique Id.
     * @param _roomId is the id of the room.
     * @return Member id.
     */
    function joinRoom(uint256 _roomId) external returns (uint256);

    /**
     * Get the id of a member in a room.
     * @param _roomId is the id of the room.
     * @param _member is the address of a member.
     * @return Member id.
     */
    function getMemberId(uint256 _roomId, address _member)
        external
        view
        returns (uint256);

    /**
     * Check if a member exists in the room.
     * @param _roomId is the id of the room.
     * @param _member is the address of a member.
     * @return true exists, false does not exist.
     */
    function hasMember(uint256 _roomId, address _member)
        external
        view
        returns (bool);

    /**
     * Get all room IDs joined by a member.
     * @param _member is the address of a member.
     * @return An array of room ids.
     */
    function getRoomIds(address _member)
        external
        view
        returns (uint256[] memory);

    /**
     * Get the total number of members in a room.
     * @param _roomId is the id of the room.
     * @return Total members.
     */
    function getMemberCount(uint256 _roomId) external view returns (uint256);

    /**
     * A member sends a message to other members.
     * @dev Define your game logic here and use the content in the message to handle the member's state. The message MUST be assigned a unique Id
     * @param _roomId is the id of the room.
     * @param _to is an array of other member ids.
     * @param _message is the content of the message, encoded by abi.encode.
     * @param _messageTypes is data type array of message content.
     * @return Message id.
     */
    function sendMessage(
        uint256 _roomId,
        uint256[] memory _to,
        bytes memory _message,
        Types.Type[] memory _messageTypes
    ) external returns (uint256);

    /**
     * Get all messages received by a member in the room.
     * @param _roomId is the id of the room.
     * @param _memberId is the id of the member.
     * @return An array of message ids.
     */
    function getMessageIds(uint256 _roomId, uint256 _memberId)
        external
        view
        returns (uint256[] memory);

    /**
     * Get details of a message.
     * @param _roomId is the id of the room.
     * @param _messageId is the id of the message.
     * @return The content of the message.
     * @return Data type array of message content.
     * @return Sender id.
     * @return An array of receiver ids.
     */
    function getMessage(uint256 _roomId, uint256 _messageId)
        external
        view
        returns (
            bytes memory,
            Types.Type[] memory,
            uint256,
            uint256[] memory
        );
}

createRoom

javascript
function createRoom() external returns (uint256);

Overview

Creates a new room.

Details

This function creates a new game room and assigns it a unique ID. The room provides a space where players can match with one another and start a game.

Return Value

  • uint256
    • The unique ID of the newly created room.

getRoomCount

javascript
function getRoomCount() external view returns (uint256);

Overview

Retrieves the total number of rooms created.

Details

This function returns the cumulative number of rooms created so far. The count provides an indication of the number of rooms in the game; it is not necessarily a count of currently active rooms.

Return Value

  • uint256
    • The total number of rooms created.

joinRoom

javascript
function joinRoom(uint256 _roomId) external returns (uint256);

Overview

Allows a player to join a room.

Details

Adds the player to the room with the specified ID. The joining player is assigned an ID unique within that room. This makes it possible to identify and manage individual players in the game.

Parameter

  • _roomId
    • The ID of the room the player wants to join.

Return Value

  • uint256
    • The unique member ID assigned to the player joining the room.

getMemberId

javascript
function getMemberId(uint256 _roomId, address _member) external view returns (uint256);

Overview

Retrieves a member's ID within a room.

Details

Given a room ID and a member address, this function returns that member's unique ID within the room. It allows a player to be identified in a particular room.

Parameters

  • _roomId
    • The ID of the room in which to look up the member ID.
  • _member
    • The address of the member (player) whose ID is requested.

Return Value

  • uint256
    • The specified member's unique ID within the room.

hasMember

javascript
function hasMember(uint256 _roomId, address _member) external view returns (bool);

Overview

Checks whether a member exists in a room.

Details

Given a room ID and a member address, this function checks whether the member is in that room. It can be used to determine whether a particular player is participating in a game.

Parameters

  • _roomId
    • The ID of the room to check.
  • _member
    • The address of the member (player) to check.

Return Value

  • bool
    • true if the member exists in the room; otherwise false.

getRoomIds

javascript
function getRoomIds(address _member) external view returns (uint256[] memory);

Overview

Retrieves the IDs of all rooms a member has joined.

Details

Returns an array containing the IDs of all rooms the specified member (player) has joined. This makes it easy to identify which games a particular player is participating in.

Parameter

  • _member
    • The address of the member whose room IDs are requested.

Return Value

  • uint256[] memory
    • An array of IDs of rooms the specified member has joined.

getMemberCount

javascript
function getMemberCount(uint256 _roomId) external view returns (uint256);

Overview

Retrieves the number of members in a particular room.

Details

Given a room ID, this function returns the total number of members (players) in that room. It can be used to determine the size of a game or its participant group.

Parameter

  • _roomId
    • The ID of the room whose member count is requested.

Return Value

  • uint256
    • The total number of members in the specified room.

sendMessage

javascript
function sendMessage(uint256 _roomId, uint256[] memory _to, bytes memory _message, Types.Type[] memory _messageTypes) external returns (uint256);

Overview

Allows a member to send a message to other members.

Details

A member sends a message to other members within a particular room. This function supports player state changes according to the game logic as well as communication between players. Every message is assigned a unique ID.

Parameters

  • _roomId
    • The ID of the room in which the message is sent.
  • _to
    • An array of member IDs identifying the recipients.
  • _message
    • The message content.
  • _messageTypes
    • An array of data types describing the message content.

Return Value

  • uint256
    • The unique ID assigned to the sent message.

getMessageIds

javascript
function getMessageIds(uint256 _roomId, uint256 _memberId) external view returns (uint256[] memory);

Overview

Retrieves the IDs of all messages received by a particular member in a room.

Details

Given a room ID and a member ID, this function returns an array of IDs of all messages received by that member. It allows developers to track the communication a player receives during a game.

Parameters

  • _roomId
    • The ID of the room in which to retrieve message IDs.
  • _memberId
    • The ID of the member whose message IDs are requested.

Return Value

  • uint256[] memory
    • An array of IDs of messages received by the specified member.

getMessage

javascript
function getMessage(uint256 _roomId, uint256 _messageId) external view returns (bytes memory, Types.Type[] memory, uint256, uint256[] memory);

Overview

Retrieves the details of a message.

Details

Given a room ID and a message ID, this function returns the message content, data types, sender ID, and an array of recipient IDs. It allows developers to inspect a specific communication within the game.

Parameters

  • _roomId
    • The ID of the room in which to retrieve message details.
  • _messageId
    • The ID of the message whose details are requested.

Return Values

  • bytes memory
    • The message content.
  • Types.Type[] memory
    • An array of data types describing the message content.
  • uint256
    • The sender's ID.
  • uint256[] memory
    • An array of recipient IDs.

Library

The Types.sol library contains an enumeration of Solidity types used by the interface above.

Additional Considerations

This section explains why multiplayer on-chain games are room-based and how player data and in-game actions are handled.

Why Use Rooms?

On-chain games use rooms to group players. Each room provides an independent space within the game, and a player is assigned a new ID each time they enter a distinct room. Developers can create different rooms for new game rounds, tasks, and activities, allowing them to manage different game scenarios flexibly.

Handling Player State and Data

Game state refers here to changes in player data within a game. The sendMessage function is responsible for changing player state. Depending on the game logic, data can be defined locally within a room or globally outside it, giving developers considerable flexibility in game design.

Initializing Player Data

Player data can be initialized in either createRoom or joinRoom. This allows the necessary data to be set when a player joins and ensures the game starts from an appropriate state.

Detecting and Handling Player Departures

Whether a player has left the game can be checked by recording each member's latest message time using block.timestamp or block.number for sendMessage. A message type can be added to sendMessage so that other players can claim that a member is offline and apply a penalty.

Suitable Game Categories

The framework is intended for multiplayer on-chain games rather than serving as a standard for real-time multiplayer games. Suitable game categories depend on the network where the contract is deployed. Some Layer 2 networks process blocks very quickly, making games with more real-time interaction possible. In general, suitable categories include strategy, trading card, turn-based, chess, sandbox, and settlement games (as listed in the original article).

The design of multiplayer on-chain games offers flexibility, extensibility, player data management, and game state updates. Developers can offer players transparent and fair game experiences on-chain without depending on a centralized server.

Implementation

The implementation is available at the following link.

https://eips.ethereum.org/assets/eip-7566/MultiplayerOnchainGame.sol

Citation

Rickey (@HelloRickey), "ERC-7566: Multiplayer Game Communication [DRAFT]," Ethereum Improvement Proposals, no. 7566, November 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7566.

Conclusion

This article covered ERC7566 and its room-based approach to multiplayer game communication. I hope it helped explain the mechanism.

If you have questions, feel free to reach out via Twitter DM.

Twitter @cardene777

I also share technical content on the following platforms.

https://chaldene.net/