Skip to content

Commit f4f169d

Browse files
authored
Merge pull request #1 from HanashiDev/1.1.0
1.1.0
2 parents 23c2323 + 3385b82 commit f4f169d

3 files changed

Lines changed: 48 additions & 27 deletions

File tree

files/lib/system/exception/SteamException.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
* @license Freie Lizenz (https://hanashi.eu/freie-lizenz/)
1111
* @package WoltLabSuite\Core\System\Exception
1212
*/
13-
class SteamException extends SystemException
13+
class SteamException extends \Exception
1414
{
1515
}

files/lib/system/steam/SteamAPI.class.php

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace wcf\system\steam;
44

5+
use GuzzleHttp\Exception\BadResponseException;
6+
use GuzzleHttp\Exception\GuzzleException;
7+
use GuzzleHttp\Psr7\Request;
58
use wcf\system\exception\SteamException;
6-
use wcf\system\exception\SystemException;
7-
use wcf\util\exception\HTTPException;
8-
use wcf\util\HTTPRequest;
9+
use wcf\system\io\HttpFactory;
910
use wcf\util\JSON;
1011
use wcf\util\StringUtil;
1112

@@ -54,30 +55,38 @@ public static function execute(string $interface, string $method, int $version,
5455
$apiURL = 'http://api.steampowered.com/' . $interface . '/' . $method . '/v' . $version . '/';
5556

5657
$postParameters = [];
58+
$headers = [];
5759
if ($httpmethod == 'GET') {
58-
$apiURL .= '?' . http_build_query($parameters, null, '&');
60+
$apiURL .= '?' . http_build_query($parameters, '', '&');
5961
} else {
6062
$postParameters = $parameters;
63+
$headers['content-type'] = 'application/x-www-form-urlencoded';
6164
}
6265

63-
$request = new HTTPRequest($apiURL, ['method' => $httpmethod], $postParameters);
66+
$request = new Request($httpmethod, $apiURL, $headers, http_build_query($postParameters, '', '&'));
6467
try {
65-
$request->execute();
66-
$reply = $request->getReply();
68+
$response = HttpFactory::getDefaultClient()->send($request);
69+
$content = (string)$response->getBody();
6770
try {
68-
return JSON::decode($reply['body'], true);
69-
} catch (SystemException $e) {
70-
return $reply['body'];
71+
return JSON::decode($content, true);
72+
} catch (\Exception $e) {
73+
return $content;
7174
}
72-
} catch (HTTPException $e) {
73-
throw new SteamException('Wrong Steam API call or Steam API is not reachable. (Message: ' . $e->getMessage() . ')');
74-
} catch (SystemException $e) {
75-
$reply = $request->getReply();
75+
} catch (BadResponseException $e) {
76+
if (\ENABLE_DEBUG_MODE) {
77+
\wcf\functions\exception\logThrowable($e);
78+
}
79+
$content = (string)$e->getResponse()->getBody();
7680
try {
77-
return JSON::decode($reply['body'], true);
78-
} catch (SystemException $e) {
79-
return $reply['body'];
81+
return JSON::decode($content, true);
82+
} catch (\Exception $e) {
83+
return $content;
84+
}
85+
} catch (GuzzleException $e) {
86+
if (\ENABLE_DEBUG_MODE) {
87+
\wcf\functions\exception\logThrowable($e);
8088
}
89+
throw new SteamException('Wrong Steam API call or Steam API is not reachable. (Message: ' . $e->getMessage() . ')');
8190
}
8291
}
8392

@@ -100,7 +109,7 @@ public static function getOpenIDUrl(string $redirectUri, string $realm): string
100109
'openid.claimed_id' => 'http://specs.openid.net/auth/2.0/identifier_select',
101110
'openid.identity' => 'http://specs.openid.net/auth/2.0/identifier_select'
102111
];
103-
return 'https://steamcommunity.com/openid/login?' . http_build_query($data, null, '&');
112+
return 'https://steamcommunity.com/openid/login?' . http_build_query($data, '', '&');
104113
}
105114

106115
/**
@@ -119,11 +128,23 @@ public static function validateOpenID(): int
119128
}
120129
}
121130
$params['openid.mode'] = 'check_authentication';
131+
$parameters = \http_build_query($params, "", '&');
122132

123-
$request = new HTTPRequest('https://steamcommunity.com/openid/login', [], $params);
124-
$request->execute();
125-
$reply = $request->getReply();
126-
$content = $reply['body'];
133+
$headers = [
134+
'content-type' => 'application/x-www-form-urlencoded'
135+
];
136+
137+
$request = new Request('POST', 'https://steamcommunity.com/openid/login', $headers, $parameters);
138+
$content = '';
139+
try {
140+
$response = HttpFactory::getDefaultClient()->send($request);
141+
$content = (string)$response->getBody();
142+
} catch (\Exception $e) {
143+
if (\ENABLE_DEBUG_MODE) {
144+
\wcf\functions\exception\logThrowable($e);
145+
}
146+
throw new SteamException('API error - ' . $e->getMessage());
147+
}
127148

128149
if (strpos($content, 'is_valid:true') === false) {
129150
throw new SteamException('Invalid authentication');

package.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<packagename language="de"><![CDATA[Steam-API]]></packagename>
66
<packagedescription><![CDATA[Api package for Steam.]]></packagedescription>
77
<packagedescription language="de"><![CDATA[API-Paket für Steam.]]></packagedescription>
8-
<version>1.0.2</version>
9-
<date>2021-07-19</date>
8+
<version>1.1.0</version>
9+
<date>2021-07-20</date>
1010
</packageinformation>
1111

1212
<authorinformation>
@@ -15,7 +15,7 @@
1515
</authorinformation>
1616

1717
<requiredpackages>
18-
<requiredpackage minversion="3.0.0">com.woltlab.wcf</requiredpackage>
18+
<requiredpackage minversion="5.3.0">com.woltlab.wcf</requiredpackage>
1919
</requiredpackages>
2020

2121
<excludedpackages>
@@ -34,7 +34,7 @@
3434
<instruction type="option" />
3535
</instructions>
3636

37-
<instructions type="update" fromversion="1.0.1 pl 1">
37+
<instructions type="update" fromversion="1.0.2">
3838
<!-- files -->
3939
<instruction type="file" />
4040
</instructions>

0 commit comments

Comments
 (0)