Storing Dispatched Codes/Data

{
Hi,

I am trying to store dispatched codes and data during a match. When a player wants to switch back into any match, the aim is to have the player receive all match state updates and basically the game will play out automatically up to the point where the game was left off (this may sound weird - but it’s how I hope this will work).

In the matchLoop code in the server TS file, whenever a message is sent (i.e. dispatcher.broadcastMessage), I also call another function: saveDispatchedMessages

let matchLoop: nkruntime.MatchLoopFunction = function (context: nkruntime.Context, logger: nkruntime.Logger, nakama: nkruntime.Nakama, dispatcher: nkruntime.MatchDispatcher, tick: number, state: nkruntime.MatchState, messages: nkruntime.MatchMessage[]) {
    let gameState = state as GameState;
    for (let message of messages) {
        dispatcher.broadcastMessage(message.opCode, message.data, null, message.sender);
        saveDispatchedMessages(message.opCode, message.data, context.userId);
    }
    return gameState.endMatch ? null : { state: gameState };
}

The code for the saveDispatchedMessages function is as follows:

function saveDispatchedMessages(code: number, data: ArrayBuffer, userID: string) {

    const matchState = [
        {
            code: code,
            data: data,
        },
]

    var write: nkruntime.StorageWriteRequest = {
        collection: "MatchStates",
        key: "Dispatched",
        value: matchState,
        userId: userID,
        permissionRead: 1,
        permissionWrite: 0,
    }
}

If I want to receive the match states to bring a match up to the point where I left it off. I use this:

let reloadMatchStates: nkruntime.RpcFunction = function (context: nkruntime.Context, logger: nkruntime.Logger, nakama: nkruntime.Nakama, dispatcher: nkruntime.MatchDispatcher, userID: string): string {
    let storageReadReq: nkruntime.StorageReadRequest = {
        collection: "MatchStates",
        key: "Dispatched",
        userId: userID,
    }

    let objects: nkruntime.StorageObject[] = nakama.storageRead([storageReadReq]);

    //goal is to use dispatcher.broadcastMessage for each object
}

And basically I want the server to dispatch.broadcastMessage each of the objects (containing the code and data).

It’s not quite working yet, and I am not 100% sure if this is going to work or if I am on the right track.

It would be awesome to have so advice on this. If there is an example showing how to save each dispatched message and then retrieve this data to resend each previously dispatched message, that would be great.

Once a match ends, I will then delete this saved data.
}

  1. Versions: Nakama {3.5}, {Windows, Mac, Linux binary or Docker}, {client library (SDK) and version}
  2. Server Framework Runtime language (If relevant) {Go, TS/JS, Lua}
{code or log snippet}

:tv: Media:

I actually had same idea for reconnect implementation and went over trying to implement it without the usage of database…
But it failed as soon it hit over 1500 bytes limit per packet, i mean i could have changed that that limitation in match handler is more but didnt want to mess with it.
Instead i am going with different approach…And that is it, since in my case game is server authorative, that means server in its state has “game state”
My job is to make sure data for game state fits in those 1500 bytes, I can represent everything and then upon reconnection send just state and do recreation in the client.
Client syncs up → game proceeds…