We are evaluating Nakama for a realtime web game, we are very pleased with the API and the performance (even more pleased with v3.0 and JS/TS support!).
One question we have is how can we add conditions to messages, so we can restrict who can send messages to who through his socket.
For example if we have an open world map with 50 players scattered on the terrain, we would like to add a distance check to how far you can see other players. What would be ideal to us would be:
As soon as a message from a player to server we do a check against the distance of this player from each other player we are about to send it to. If the distance is greater than a limit we don’t send this message to this player.
To be able to do that we imagine we will have to store somewhere in memory the last known position of each player.
Could you let us know if that is possible and what would be the way to do this? Ideally we would prefer to use the new Typescript system on the server, if that’s possible.
option 1:
Client send network message with zone of impact (a bounding box)
Server broadcast the message only to those in the zone of impact
(may have security issues, server need to run checks)
option 2:
Client send network message
Server knows client position and the impact this kind of message has, broadcast only to those in the zone of impact
Option 1 can be an alternative though it may not work well in our case (it won’t handle well close to zone border positions).
Option 2 is what we are curious if it’s doable with Nakama. For that work the server needs to store in memory the last known position for each client? If that’s possible we would like to know how we can do this, more specifically with the Javascript/Typescript server modules.
@Leonidas Welcome! Sounds like your use case is a good fit for the authoritative multiplayer feature. Under this model the clients send messages to the server, and the server decides what to do with them. Essentially the server has full control of the logic, validation, and message flow between players.
That documentation page is still being updated for Nakama 3.0 but you can see a full authoritative match example in TypeScript in the project template example. That template will show you everything you need, including how to define your protocol for messages and how your players would find/create matches.