This is an implementation of a basic web3 game that logs in user with a wallet like Metamask and allows for real-time movement in game.
NodeJS is single-threaded and therefore needs to be deployed as a cluster to make use of all cores. This application is automatically deployed as several processes (one of each core) and load balanced accordingly in order to take advantage of the whole machine.
- All moves go through the backend - no cheating allowed and NFTs/tokens can be awarded safely in the
move
function of cloud.js - Client lag needs to be compensated by the game engine using movement extrapolation and prediction - Read more
- When the game loads the server only gives the client the position of the players that are close to the player playing the game - adjust
DRAW_DISTANCE
incloud.js
to change this. Room for improvement: this DRAW_DISTANCE needs to be set in live-query so when user gets continuous updates its also applied. - Room for improvement: add join/leave logic so players can change rooms
- Server has rate limits so users can't spam endless moves - rate limit is ensured by
MOVE_COOLOFF
constant incloud.js
- this cooloff is per core in the server. There is alsoMOVE_COOLOFF
on client side to ensure the client is rate limiting itself.
- The best would be to limit number of connections for each server to a few hundred (depends on server specs)
- Let the user choose a "world" they want to join - each world runs on a separate server - kinda like Runescape
- Each world is a separate Moralis Server
- Worlds can be added in real time as the user base growth
- Worlds can have different settings - for example PvP enabled/disabled