Client

To get started a WebSocket connection must be established with the Messages-app.

The following query parameters are required:

  • environment (development, staging, or production)
  • operatorId (can be found in the launch query)
  • gameId (can be found in the launch query)
  • connectionToken (must be created on the client, and must be unique based on the following combination: operatorId_gameId_environment_connectionToken)

The connectionToken is primarily used for re-mapping the connection if the connectionId changed during a reconnect, and stopping the "player-disconnected" event from firing.

This will give us a connection looking like this:

var connection = new HubConnectionBuilder()
                .WithUrl("https://cloud.fireballserver.com/messages-net/messages?environment=development&operatorId=72c43a89-585e-4cf9-8fab-dcc1740eec40&gameId=c61b4556-5816-44bc-845b-39083f19956b&connectionToken=" + Guid.NewGuid().ToString())
                .Build();

Receiving messages, and acknowledgement

In order to start receiving a message, the client will have to start listening on the ReceiveMessage channel.

It is important to note that the service requires acknowledgment of the message upon arrival. This is done by sending a message to the AcknowledgeMessage channel, with the WsMessageId from the ReceivedMessage.

We have put it all together in an example below where the client receives a message and acknowledges it:

connection.On<string>("ReceiveMessage", async (messageJson) =>
{
  var message = JsonConvert.DeserializeObject<MessageBody>(messageJson);
  await connection.InvokeAsync("AcknowledgeMessage", message.WsMessageId);
  //Process message
}

Message model

The message model sent on the ReceiveMessage channel looks like this:

public class MessageBody
{
  public string WsMessageId { get; set; }
  public dynamic Message { get; set; }
  public string ActionId { get; set; }
}

The WsMessageId is used for acknowledging the message, through the AcknowledgeMessage channel, and the Message is the raw unaltered message sent through the Messages-app API, from which the ActionId also comes.

The "player-disconnected" event

The player-disconnected model looks like this:

public class PlayerDisconnected
{
  public Guid ActionId { get; set; }
  public string PlayerId { get; set; }
  public string GameId { get; set; }
  public string Environment { get; set; }
  public string OperatorId { get; set; }
  public string GameSession { get; set; }
  public string ConnectionToken { get; set; }
  public string ConnectionId { get; set; }
  public string Currency { get; set; }
  public dynamic Extra { get; set; }
  public long MessageTimestamp { get; set; } = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  public string Name { get; set; } = "player-disconnected";
}

The event is sent to the Game Cloud Function when a connection has been dropped for more than 15 seconds without a reconnect. This could be used to replace the player with a robot or end/clean up the game/session.

Test data

KeyValue
Environmentdevelopment
OperatorId72c43a89-585e-4cf9-8fab-dcc1740eec40
GameIdc61b4556-5816-44bc-845b-39083f19956b
ConnectionToken6a5dfda9-c39e-4ff6-ae31-82ae15868cbd
CurrencyDKK