0

I'm taking Webhook from the FACEIT platform and I'm getting something like this

stdClass Object
(
    [transaction_id] => dfba5d34-39ff-4caf-bd16-fcca57260a76
    [event] => match_status_ready
    [event_id] => 313d9c29-4c71-4275-adc5-8cd4111f08a6
    [third_party_id] => 48b264cb-e604-405c-a24f-34a550304790
    [app_id] => e3f16440-0c96-4869-9f89-78c1753a9ff5
    [timestamp] => 2021-02-08T20:50:34Z
    [retry_count] => 2
    [version] => 1
    [payload] => stdClass Object
        (
            [id] => 1-e383d04b-28d7-4e6d-b72a-2b8c08c8e8bf
            [organizer_id] => edc12227-3b07-4c5e-9325-f223025628f3
            [region] => EU
            [game] => csgo
            [version] => 16
            [entity] => stdClass Object
                (
                    [id] => ada458d4-34c4-47ab-84a1-1ab87626c829
                    [name] => ECL Division 2
                    [type] => hub
                )

            [teams] => Array
                (
                    [0] => stdClass Object
                        (
                            [id] => d5597dd7-a5db-4602-b411-ceea05451002
                            [name] => team_-finn
                            [type] => 
                            [avatar] => https://assets.faceit-cdn.net/avatars/d5597dd7-a5db-4602-b411-ceea05451002_1591229111372.jpg
                            [leader_id] => d5597dd7-a5db-4602-b411-ceea05451002
                            [co_leader_id] => 
                            [roster] => Array
                                (
                                    [0] => stdClass Object
                                        (
                                            [id] => 3da45845-3733-4b69-9b69-c25ea2181c4a
                                            [nickname] => Bolitho
                                            [avatar] => https://assets.faceit-cdn.net/avatars/3da45845-3733-4b69-9b69-c25ea2181c4a_1606685453491.jpg
                                            [game_id] => 76561198178207317
                                            [game_name] => C. Bolitho
                                            [game_skill_level] => 8
                                            [membership] => 
                                            [anticheat_required] => 1
                                        )

                                    [1] => stdClass Object
                                        (
                                            [id] => f3b13a97-f287-4fef-9d1b-2b06e6a7c184
                                            [nickname] => Kronos
                                            [avatar] => https://assets.faceit-cdn.net/avatars/f3b13a97-f287-4fef-9d1b-2b06e6a7c184_1611088029728.jpg
                                            [game_id] => 76561198064664568
                                            [game_name] => Brawlhalla > CS
                                            [game_skill_level] => 8
                                            [membership] => 
                                            [anticheat_required] => 1
                                        )

                                    [2] => stdClass Object
                                        (
                                            [id] => 02df4fd6-e47e-44e1-bf35-1e4bb54becfb
                                            [nickname] => 180_Headshot
                                            [avatar] => https://assets.faceit-cdn.net/avatars/02df4fd6-e47e-44e1-bf35-1e4bb54becfb_1611591673793.jpg
                                            [game_id] => 76561198263064464
                                            [game_name] => 76561198263064464
                                            [game_skill_level] => 7
                                            [membership] => 
                                            [anticheat_required] => 1
                                        )

                                    [3] => stdClass Object
                                        (
                                            [id] => d5597dd7-a5db-4602-b411-ceea05451002
                                            [nickname] => -finn
                                            [avatar] => https://assets.faceit-cdn.net/avatars/d5597dd7-a5db-4602-b411-ceea05451002_1591229111372.jpg
                                            [game_id] => 76561198284594110
                                            [game_name] => finn
                                            [game_skill_level] => 6
                                            [membership] => 
                                            [anticheat_required] => 1
                                        )

                                    [4] => stdClass Object
                                        (
                                            [id] => cd20ef72-3a7d-40df-9102-1480a591866f
                                            [nickname] => -jonas_
                                            [avatar] => https://assets.faceit-cdn.net/avatars/cd20ef72-3a7d-40df-9102-1480a591866f_1608470890103.jpg
                                            [game_id] => 76561198316676876
                                            [game_name] => j0nas21
                                            [game_skill_level] => 5
                                            [membership] => 
                                            [anticheat_required] => 1
                                        )

                                )

                            [substitutions] => 0
                            [substitutes] => 
                        )

                    [1] => stdClass Object
                        (
                            [id] => 5cc910f4-c71b-48ab-9733-4efc7917153c
                            [name] => team_LUKR-
                            [type] => 
                            [avatar] => https://assets.faceit-cdn.net/avatars/5cc910f4-c71b-48ab-9733-4efc7917153c_1611317469316.jpg
                            [leader_id] => 5cc910f4-c71b-48ab-9733-4efc7917153c
                            [co_leader_id] => 
                            [roster] => Array
                                (
                                    [0] => stdClass Object
                                        (
                                            [id] => 5e0822a6-7cac-43d3-8e11-4846f09e0718
                                            [nickname] => flunke_
                                            [avatar] => https://assets.faceit-cdn.net/avatars/5e0822a6-7cac-43d3-8e11-4846f09e0718_1591995725180.jpg
                                            [game_id] => 76561198060789527
                                            [game_name] => flunke
                                            [game_skill_level] => 7
                                            [membership] => 
                                            [anticheat_required] => 1
                                        )

                                    [1] => stdClass Object
                                        (
                                            [id] => 55910238-2a72-4642-aa0d-5b14870fb2d5
                                            [nickname] => zkunky
                                            [avatar] => https://assets.faceit-cdn.net/avatars/55910238-2a72-4642-aa0d-5b14870fb2d5_1608502753847.jpg
                                            [game_id] => 76561198078177475
                                            [game_name] => winch
                                            [game_skill_level] => 5
                                            [membership] => 
                                            [anticheat_required] => 1
                                        )

                                    [2] => stdClass Object
                                        (
                                            [id] => 5cc910f4-c71b-48ab-9733-4efc7917153c
                                            [nickname] => LUKR-
                                            [avatar] => https://assets.faceit-cdn.net/avatars/5cc910f4-c71b-48ab-9733-4efc7917153c_1611317469316.jpg
                                            [game_id] => 76561198031152268
                                            [game_name] => lukr
                                            [game_skill_level] => 7
                                            [membership] => 
                                            [anticheat_required] => 1
                                        )

                                    [3] => stdClass Object
                                        (
                                            [id] => 030ca481-1369-4393-b928-dd984dbb311c
                                            [nickname] => tomasinio
                                            [avatar] => https://assets.faceit-cdn.net/avatars/030ca481-1369-4393-b928-dd984dbb311c_1612353173993.jpg
                                            [game_id] => 76561198346093855
                                            [game_name] => tomasinio
                                            [game_skill_level] => 5
                                            [membership] => 
                                            [anticheat_required] => 1
                                        )

                                    [4] => stdClass Object
                                        (
                                            [id] => 439b5a1c-dd69-49cd-bb3c-d2b47cfe7b14
                                            [nickname] => NARUTA0
                                            [avatar] => https://assets.faceit-cdn.net/avatars/439b5a1c-dd69-49cd-bb3c-d2b47cfe7b14_1612758081953.jpg
                                            [game_id] => 76561198118696706
                                            [game_name] => ² cs.money
                                            [game_skill_level] => 8
                                            [membership] => 
                                            [anticheat_required] => 1
                                        )

                                )

                            [substitutions] => 0
                            [substitutes] => 
                        )

                )

            [created_at] => 2021-02-08T20:47:16Z
            [updated_at] => 2021-02-08T20:50:33Z
        )

)

And I'm trying to update database row "Game" to 1 if the player with id is in that game

so I tried with this, I'm not getting any error but, my Game row is not updating.

<?php
include "connect_db.php";
header('Content-Type: application/json');
$request = file_get_contents('php://input');
$data = json_decode($request);

if(!empty($data)){
    $req_dump = print_r($data, true);
    $fp = file_put_contents('request.log', $req_dump);
    if($data->event == 'match_status_ready')
    {
            for($i=0; $i<count($data->payload->teams); $i++){
                for($j=0; $j<count($data->payload->teams[$i]->roster); $j++){
                    $sqlupdate[$j] = "UPDATE Korisnici SET Game='1' WHERE faceit_playerid =".$data->payload->teams[$i]->roster[$j]->id;
                    $conn->query($sqlupdate[$j]);
                    /*$message = "Tim[". $i ."] Igrač[". $j ."] - ". $data->payload->teams[$i]->roster[$j]->id ."\n";
                    file_put_contents('status.log', $message, FILE_APPEND);*/
                }
            }
            $curl = curl_init("discord-webhook-url");
            curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($curl, CURLOPT_HEADER, 0);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode(array("content" => "!matchid ". $data->payload->id ." ".$data->event)));
            echo curl_exec($curl);   
    }
    
    else if($data->event == 'match_status_finished' || $data->event == 'match_status_cancelled')
    {
            for($i=0; $i<count($data->payload->teams); $i++){
                for($j=0; $j<count($data->payload->teams[$i]->roster); $j++){
                    $sqlupdate = "UPDATE Korisnici SET Game='0' WHERE faceit_playerid =".$data->payload->teams[$i]->roster[$j]->id;
                    $conn->query($sqlupdate);
                }
            }
        $curl = curl_init("discord-webhook-url");
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode(array("content" => "!matchid ". $data->payload->id ." ".$data->event)));
        echo curl_exec($curl);
    }
    sleep(3);
}
else { echo "Link je prazan !"; }
?>

When I put it into log I'm getting a right thing

Tim[0] Igrač[0] - c8d41fb0-df78-4b53-a1ef-1b007f7d8f7b
Tim[0] Igrač[1] - edfeb779-89e7-485d-bbc8-64d99e3356ba
Tim[0] Igrač[2] - 13144f2a-e8b3-4469-816c-9af61caedb58
Tim[0] Igrač[3] - 268b7ac8-48dc-4bcf-995a-de00244e8cf7
Tim[0] Igrač[4] - ab056dc5-3cab-4568-9d2e-ddb405904500
Tim[1] Igrač[0] - 7196b459-4b4c-4a1b-8f46-9bb37a243c65
Tim[1] Igrač[1] - d8fe30bb-2a72-4169-9d30-1a6c82c6d0af
Tim[1] Igrač[2] - 7b4d7693-3646-4010-931c-e6f7c2790206
Tim[1] Igrač[3] - 4f789940-e122-4470-9347-82f21611132e
Tim[1] Igrač[4] - 4ccc9f0f-3536-4a1d-8386-a630cf2be337

Can anyone help me? I'm really disappointed...

1

2 Answers 2

1

Thanks sir, i finnaly got it on another way, is it allright ?

$stmt = $conn->prepare("UPDATE Korisnici SET Game='1' WHERE faceit_playerid=?");
        $stmt->bind_param('s', $faceitid);
        foreach ($data->payload->teams as $team){
            foreach ($team->roster as $player){
                /*$sqlupdate = "UPDATE Korisnici SET Game='1' WHERE faceit_playerid=" . $player->id;
                $conn->query($sqlupdate);*/
                $faceitid = $player->id;
                $stmt->execute();
            }
        }
        $stmt->close();

EDIT: How can i bypass too many connections with this ?

Sign up to request clarification or add additional context in comments.

Comments

0

Try logging the SQL query, instead of the values. This should help you see what you're actually telling the DBMS to do. You may find that you're sending it the wrong values.

Also, instead of a couple of numerical for loops, try this:

foreach ($data->payload->teams as $team){
    foreach ($team->roster as $player){
        $sqlupdate = "UPDATE Korisnici SET Game='1' WHERE faceit_playerid =" . $player->id;
        $conn->query($sqlupdate);
    }
}

1 Comment

Make sure to use bind_param after you define the variable. $faceitid = $player->id; THEN $stmt->bind_param('s', $faceitid); THEN $stmt->execute();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.