Exemple #1
0
    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();
        }
    }
Exemple #2
0
    public async Task Login(string username, string password)
    {
        CurrentLoginStatus = LoginStatus.LOGGING_IN;
        BLEDebug.LogInfo("Logging In");
        FlatJSON fJSON = new FlatJSON();

        fJSON.Add("username", username);
        fJSON.Add("password", password);
        HttpContent req = fJSON.SerializeContent();

        var result = await client.PostAsync("https://echelon.3pointlabs.org/auth/login", req);

        string body = await result.Content.ReadAsStringAsync();

        BLEDebug.LogInfo("Auth " + body);
        fJSON.Deserialize(body);
        fJSON.TryGetStringValue("username", out _PlayerId);
        fJSON.TryGetStringValue("idToken", out idToken);
        fJSON.TryGetStringValue("refreshToken", out refreshToken);
        fJSON.TryGetStringValue("accessToken", out accessToken);
        if (idToken != null)
        {
            // Set Token for Authentication
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(idToken);
            CurrentLoginStatus = LoginStatus.LOGGED_IN;
        }
        else
        {
            CurrentLoginStatus = LoginStatus.FAILED;
        }
    }
    /**
     *  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 void UpdateCustomization(string characterModelId)
    {
        BLEDebug.LogInfo("Sending Customization Update");
        FlatJSON fJSON = new FlatJSON();

        fJSON.Add("PlayerId", PlayerId);
        fJSON.Add("characterModelId", characterModelId);

        Client.SendMessage(Client.NewMessage(OP_CODE_CUSTOMIZATION_UPDATE)
                           .WithDeliveryIntent(DeliveryIntent.Reliable)
                           .WithTargetPlayer(Constants.PLAYER_ID_SERVER)
                           .WithPayload(StringToBytes(fJSON.ToString())));
    }
Exemple #5
0
    public async Task GetCustomization()
    {
        BLEDebug.LogInfo("Getting CharacterModelId");
        FlatJSON            fJSON  = new FlatJSON();
        HttpResponseMessage result = await client.GetAsync("https://echelon.3pointlabs.org/profile/customization");

        string body = await result.Content.ReadAsStringAsync();

        BLEDebug.LogInfo("CharacterModel " + body);
        fJSON.Deserialize(body);

        fJSON.TryGetStringValue("characterModelId", out _CharacterModelId);
    }
    public void UpdateStats(int rotations, int rpm, float[] playerPosition, float progressDistance)
    {
        BLEDebug.LogInfo("Sending Stats Update");
        FlatJSON fJSON = new FlatJSON();

        fJSON.Add("rotations", rotations);
        fJSON.Add("rpm", rpm);
        fJSON.Add("playerPosition", playerPosition);
        fJSON.Add("progressDistance", progressDistance);

        Client.SendMessage(Client.NewMessage(OP_CODE_STATS_UPDATE)
                           .WithDeliveryIntent(DeliveryIntent.Reliable)
                           .WithTargetPlayer(Constants.PLAYER_ID_SERVER)
                           .WithPayload(StringToBytes(fJSON.ToString())));
    }
Exemple #7
0
    public async Task CreateMatchmakingTicket()
    {
        BLEDebug.LogInfo("Creating MatchMaking Ticket");
        FlatJSON fJSON = new FlatJSON();

        HttpContent         req    = fJSON.SerializeContent();
        HttpResponseMessage result = await client.PostAsync("https://echelon.3pointlabs.org/matchmaking/ticket", req);

        string body = await result.Content.ReadAsStringAsync();

        BLEDebug.LogInfo("Ticket" + body);
        fJSON.Deserialize(body);

        fJSON.TryGetStringValue("TicketId", out TicketId);
        fJSON.TryGetStringValue("Status", out _Status);
    }