Hello,
The beta.9 version has just been released!
Several changes have been made but here are the two most important:
Horizontal scaling
A new module named @rpgjs/agones
allows you to spread the maps over several instances. This would allow to have thousands of players in one world. How is it done? It uses Kubernetes and Agones (an overlay created by Ubisoft). This way, a player can switch from one map to another without realizing that he is switching from one server to another. All states are saved in a Redis so that no information is lost when switching from one server to another
More: https://docs.rpgjs.dev/advanced/agones.html
Synchronization with the client and saving of custom properties
Let's take the case that you want to create a new property on the player. For example, the amount of wood collected (a member of the forum with desired this point), three questions arise:
- how to synchronize with the client?
- how to save to database?
- how to keep this data in memory with the server scaling?
Well, now you can use a new parameter on players: props
import { RpgPlayerHooks } from '@rpgjs/server'
declare module '@rpgjs/server' {
export interface RpgPlayer {
nbWood: number
}
}
export const player: RpgPlayerHooks = {
props: {
nbWood: Number
}
}
So, if you give a value, it will be synchronized with the client and you can save this data
player.nbWood = 5
const json = player.save()
console.log(json)
More: https://docs.rpgjs.dev/classes/player.html#props
Update
Update with npm update
Break change:
Now entryPoint
sends a Promise to src/server.ts
.
const rpgGame = await entryPoint(modules, { io, basePath: __dirname, globalConfig })
https://github.com/rpgjs/starter/commit/f95dc04b5970f1af5fa6527f06b9ba0f4c933902#diff-8a8ae07582c9d433ec8c2e5c4310ff8901e604f4965c5b90a49117ad46c47595R25