I’m having trouble with one particular piece of code that is supposed to be sending a message to a client. Both pieces of code below are from my Realtime Server Script:
function onPlayerAccepted(player) {
logger.info("..New player accepted: " + player.peerId);
const newPlayerMessage = session.newTextGameMessage(OP_CODE_PLAYER_ACCEPTED,
session.getServerId(),
JSON.stringify(galaxyAndLocalPlayerState));
session.sendReliableMessage(newPlayerMessage, player.peerId);
}
The above block within my realtime server script runs when a player is accepted, and the message is successfully received by the client (Unity). On the client side, logs show that OnDataReceived() is called.
RTS Logs for above call:
02 Mar 2022 03:59:32,191 [INFO] (ManhuntServerScript.js) 96: …New player accepted: 1
02 Mar 2022 03:59:32,191 [INFO] (index.js) 333: Received custom game message from sender: -1 with opCode: 100, targetPeerId: 1, targetGroupId: 0
function onMessage(gameMessage) {
switch (gameMessage.opCode) {
case OP_CODE_TRAVEL_REQUEST:
logger.info("..Travel Request Received from Peer " + gameMessage.sender + " to PlanetId: " + gameMessage.getPayloadAsText());
const travelResponseMessage = session.newTextGameMessage(OP_CODE_TRAVEL_BEGIN,
session.getServerId(),
JSON.stringify(playerStates));
session.sendReliableMessage(travelResponseMessage, gameMessage.sender);
break;
default:
logger.info("..Unrecognized Op Code received: " + gameMessage.opCode);
break;
}
}
The above block shows the message is being sent in the server logs, but is not received by the Unity client. I have ensured the op codes match. On the client side, logs show that OnDataReceived() is NOT called.
RTS logs for above call:
02 Mar 2022 03:59:36,628 [INFO] (index.js) 333: Received custom game message from sender: 1 with opCode: 200, targetPeerId: -1, targetGroupId: 0
02 Mar 2022 03:59:36,628 [INFO] (ManhuntServerScript.js) 136: …Travel Request Received from Peer 1 to PlanetId: 2
02 Mar 2022 03:59:36,629 [INFO] (index.js) 333: Received custom game message from sender: -1 with opCode: 102, targetPeerId: 1, targetGroupId: 0
The only thing I can think of is that possibly a realtime server can’t send a message within onMessage() but that seems silly to me.
Thanks in advance for any insight!