Passed
Push — v3 ( 286f4e...3249be )
by
unknown
35:12
created

Arksa::processResponse()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 37
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 37
rs 9.552
cc 3
nc 2
nop 0
1
<?php
2
3
/**
4
 * This file is part of GameQ.
5
 *
6
 * GameQ is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * GameQ is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
namespace GameQ\Protocols;
21
22
use GameQ\Exception\Protocol as Exception;
23
use GameQ\Result;
24
25
/**
26
 * ARK: Survival Ascended Protocol Class
27
 *
28
 * Extends the EOS protocol and adds ARK-specific server response processing.
29
 *
30
 * @package GameQ\Protocols
31
 * @author  H.Rouatbi
32
 */
33
class Arksa extends Eos
34
{
35
    /**
36
     * The protocol being used
37
     *
38
     * @var string
39
     */
40
    protected $protocol = 'arksa';
41
42
    /**
43
     * Longer string name of this protocol class
44
     *
45
     * @var string
46
     */
47
    protected $name_long = 'ARK: Survival Ascended';
48
49
    /**
50
     * String name of this protocol class
51
     *
52
     * @var string
53
     */
54
    protected $name = 'arksa';
55
56
    /**
57
     * Grant type used for authentication
58
     *
59
     * @var string
60
     */
61
    protected $grant_type = 'client_credentials';
62
63
    /**
64
     * Deployment ID for the game or application
65
     *
66
     * @var string
67
     */
68
    protected $deployment_id = 'ad9a8feffb3b4b2ca315546f038c3ae2';
69
70
    /**
71
     * User ID for authentication
72
     *
73
     * @var string
74
     */
75
    protected $user_id = 'xyza7891muomRmynIIHaJB9COBKkwj6n';
76
77
    /**
78
     * User secret key for authentication
79
     *
80
     * @var string
81
     */
82
    protected $user_secret = 'PP5UGxysEieNfSrEicaD1N2Bb3TdXuD7xHYcsdUHZ7s';
83
84
    /**
85
     * Process the response from the EOS API and filter ARK-specific server data
86
     *
87
     * @return array
88
     * @throws Exception
89
     */
90
    public function processResponse()
91
    {
92
        $serverData = parent::processResponse();
93
94
        // Filter by port to match server sessions
95
        $filtered = array_filter($serverData, function ($session) {
96
            return $session['attributes']['ADDRESSBOUND_s'] === "{$this->serverIp}:{$this->serverPortQuery}" ||
97
                   $session['attributes']['ADDRESSBOUND_s'] === "0.0.0.0:{$this->serverPortQuery}";
98
        });
99
100
        if (!$filtered) {
101
            throw new Exception('No matching sessions found for the specified port.');
102
        }
103
104
        $session = reset($filtered);
105
106
        $result = new Result();
107
108
        // Add server items to the result object
109
        $result->add('hostname', $this->getAttribute($session['attributes'], 'CUSTOMSERVERNAME_s', 'Unknown'));
110
        $result->add('mapname', $this->getAttribute($session['attributes'], 'MAPNAME_s', 'Unknown'));
111
        $result->add('password', $this->getAttribute($session['attributes'], 'SERVERPASSWORD_b', false));
0 ignored issues
show
Bug introduced by
It seems like $this->getAttribute($ses...RVERPASSWORD_b', false) can also be of type false; however, parameter $value of GameQ\Result::add() does only seem to accept array|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

111
        $result->add('password', /** @scrutinizer ignore-type */ $this->getAttribute($session['attributes'], 'SERVERPASSWORD_b', false));
Loading history...
112
        $result->add('numplayers', $this->getAttribute($session, 'totalPlayers', 0));
113
        $result->add('maxplayers', $this->getAttribute($session['settings'], 'maxPublicPlayers', 0));
114
        $result->add('anticheat', $this->getAttribute($session['attributes'], 'SERVERUSESBATTLEYE_b', false));
115
        $result->add('allowJoinInProgress', $this->getAttribute($session['settings'], 'allowJoinInProgress', false));
116
        $result->add('day', $this->getAttribute($session['attributes'], 'DAYTIME_s', ''));
117
        $result->add(
118
            'version',
119
            "v" . $this->getAttribute($session['attributes'], 'BUILDID_s', '0') . "." .
120
            $this->getAttribute($session['attributes'], 'MINORBUILDID_s', '0')
121
        );
122
        $result->add('pve', (bool) $this->getAttribute($session['attributes'], 'SESSIONISPVE_l', false));
123
        $result->add('officialserver', (bool) $this->getAttribute($session['attributes'], 'OFFICIALSERVER_s', false));
124
125
        // Return the final result
126
        return $result->fetch();
127
    }
128
}
129