The problem is that i need to have a bit more control over the chat channels. Im developing an 2d open world so im constantly in the need of figuring out what players receives what messages and so on… Thats why im wondering if its acceptable to send messages through Match state instead of using godots version of RT-chat? It is no performance loss or anything with sending match states in this way?
In this way i can easly handle each message and broadcast them to correct precesces.
Can you explain a bit more about why you would like to use match state to send messages?
If the goal is to send real-time chat messages to only players within a specific match, one solution would be to have those players join a Room chat channel, keyed by the match ID. You can see an example of this in action in our Lobby Guide - Lobby Private Chat.
The reason is that i do have an open world game, one match with a couple of hundred players online at the same time. When one player sending a message in the world, i need to do some calculations of local entities. This is done on the server side by alot of calculations from the Match state. The world is divided into chunks and the math behind this is stored in the Match state.
Only the players within the same chunk or chunkbatches should receive a message.
So esentially i need to have access to the match state to figure out what entities should receive the message. Further down the road i would like to have a guild chat aswell and so on. The server is where all the logic is made. Clients only sends requests and the server calculates stuff
Are the chunks identifiable in any way such as ID? When a player moves from one chunk to the next, could you send them a match state that gives them their new chunk ID (as well as the one they were previously in) with which they could then join a chat room for that chunk?
e.g:
socket.ReceivedMatchState += async state =>
{
const long ENTERED_CHUNK_OP_CODE = 999;
if (state.OpCode == ENTERED_CHUNK_OP_CODE)
{
// Retrieve the previous and new chunk Id from the match state, simplified below for brevity
var previousChunkId = "<PreviousChunkId>";
var newChunkId = "<NewChunkId>";
// Leave the current chat channel
await socket.LeaveChatAsync(previousChunkId);
// Join the chat channel for this chunk
var channel = socket.JoinChatAsync(newChunkId, ChannelType.Room);
}
};
@tom Hmm… now when i think about it each client have access to its local entities. All i have to do is to store the user_id aswell.
So I can assume its NOT preferrable to use match state to send simple messages ?
EDIT:
altough… i can already see some problems here aswell with this approach. lets say if player stands at chunk 5,5 then its “local players” 5,5 including its surrounding chunks. So i cannot have one channel per chunk, its one channel per chunk batch. And this wont work So Match state as messages ???
While you can of course send any data you like to presences in a match via match state, it would not be my recommendation to use it for chat.
Our real-time chat functionality is purpose built and has several advantages over using match state. Some of these advantages include the ability to join multiple channels at once (useful if your players exist in multiple chunks at once, or you wish them to be able to chat in world chat/party chat and guild chat for example), persist chat messages, hide individual users from the channel and act on messages before they are broadcast using hooks (which is useful for things such as profanity filtering).
@tom Okey! Thanks for clearing this one out for me! I think I can do some wiring to make it work in my case aswell! You just said it: One player can join multiple channels. So each chunk could infact have its own channel and i can just merge theese messages into one stream of messages for the local chat! I’ll make it work!