GitHub Repository

You can find the Adventure Layer Slither at the following link:
Adventure Layer ECS - Adventure Layer Slither.

The core modules of the Adventure Layer Slither are as follows.

1. Binding Independent Private Keys to Different Wallet Accounts

The Adventure Layer Slither allows binding independent private key accounts to different wallet accounts. Here’s how it works:
  • Private Key Generation and Storage:
    In mud/util.ts, the generatePrivateKey and privateKeyToAccount functions are used to generate a private key and convert it into account information. The private key can be stored in local storage for future use.
  • Private Key Validation:
    Also in mud/util.ts, the assertPrivateKey function is employed to validate the private key, ensuring it is in hexadecimal format and can successfully extract the corresponding address.

Relevant Code Snippet

2. AGL Table Structure

In mud.config.ts, multiple AGL tables are defined, including:
  • Users
  • GameCodeToGameState
  • UserToOthersPositions
  • UserToOwnPositions
  • UserToSnakeDeque
  • Balance
  • UserAccountMapping
A total of 7 AGL tables are used to manage game data.

Code Snippet

3. Main Contracts

IWorld.sol

This interface integrates all systems and associated function selectors that are dynamically registered in the World during deployment.

BalanceSystem.sol

This contract handles balance-related operations for the game, including starting a game, querying balances, setting game fees, and managing player balances.

UsersSystem.sol

This contract manages user-related operations, such as retrieving user data, starting a game, adding users, and generating random numbers.
These contracts work together to manage the game’s balance, state, and user data, providing a comprehensive system for game operations. Here’s the translated document in English:

4.Heartbeat Mechanism Implementation

  1. Contract Task Management:
    • The ManageContractTask function is used to start or stop the polling tasks for the contract, managing these tasks through contractMap.
  2. Heartbeat Mechanism:
    • The startPolling function uses the ABI of the adventureHeatbeat function to package data and periodically send transactions via a timer.
    • The transaction sending is implemented by constructing, signing, and submitting the transaction.
  3. Concurrency Control:
    • The use of sync.Mutex ensures that the transaction sending is thread-safe.
  4. Periodic Invocation:
    • The periodic invocation is implemented through time.Sleep(task.Interval), where Interval is the time interval in milliseconds.
This mechanism ensures that the adventureHeatbeat function can be regularly called at specified time intervals, thus achieving the heartbeat function. Each call may trigger random refreshes of food in the game, among other operations.