/** * Handle data received from the Realtime server */ private void OnDataReceived(object sender, DataReceivedEventArgs e) { FlatJSON fJSON = new FlatJSON(); BLEDebug.LogInfo("OPCODE " + e.OpCode + " Received, Data:" + BytesToString(e.Data)); switch (e.OpCode) { // handle message based on OpCode case OP_CODE_PLAYER_ACCEPTED: _peerId = e.Sender; OnPlayerAccepted(peerId); break; case OP_CODE_PLAYER_DISCONNECTED: Int32.TryParse(BytesToString(e.Data), out _peerId); OnPlayerDisconnected(peerId); break; case OP_CODE_RACE_START: OnRaceStart(); break; case OP_CODE_RACE_END: OnRaceEnd(); break; case OP_CODE_TIME_TILL_TERMINATE: int time; Int32.TryParse(BytesToString(e.Data), out time); OnNotifyTimeTillTerminate(time); break; case OP_CODE_STATS_UPDATE: fJSON.Deserialize(BytesToString(e.Data)); fJSON.TryGetIntValue("rotations", out int rotations); fJSON.TryGetIntValue("rpm", out int rpm); fJSON.TryGetFloatArray("playerPosition", out float[] playerPosition); fJSON.TryGetFloatValue("progressDistance", out float progressDistance); OnStatsUpdate(e.Sender, rotations, rpm, playerPosition, progressDistance); break; case OP_CODE_CUSTOMIZATION_UPDATE: fJSON.Deserialize(BytesToString(e.Data)); fJSON.TryGetStringValue("PlayerId", out string customplayer); fJSON.TryGetStringValue("characterModelId", out string characterModel); OnCustomizationUpdate(e.Sender, customplayer, characterModel); break; default: BLEDebug.LogWarning("Unknown OPCODE Received"); break; } }
public async Task CheckMatchmakingTicketStatus() { BLEDebug.LogInfo("Checking MatchMaking Ticket Status"); FlatJSON fJSON = new FlatJSON(); fJSON.Add("TicketId", TicketId); HttpContent req = fJSON.SerializeContent(); HttpResponseMessage result = await client.PostAsync("https://echelon.3pointlabs.org/matchmaking/status", req); string body = await result.Content.ReadAsStringAsync(); BLEDebug.LogInfo("Ticket " + body); fJSON.Deserialize(body); fJSON.TryGetStringValue("Status", out _Status); if (Status == "COMPLETED") { fJSON.TryGetStringValue("GameSessionArn", out _GameSessionArn); fJSON.TryGetStringValue("IpAddress", out _IpAddress); fJSON.TryGetStringValue("DnsName", out _DnsName); fJSON.TryGetIntValue("Port", out _TcpPort); fJSON.TryGetStringValue("PlayerSessionId", out _PlayerSessionId); FindAvailableUDPPort(); } }