-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsteam.php
125 lines (108 loc) · 2.95 KB
/
steam.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
class Steam
{
private static function resolveInputID($steamid)
{
switch (true) {
case preg_match("/STEAM_[0|1]:[0:1]:\d*/", $steamid):
return 'Steam2';
case preg_match("/\[U:1:\d*\]/", $steamid):
return 'Steam3';
case preg_match("/U:1:\d*/", $steamid):
return 'Steam3';
case preg_match("/\d{17}/", $steamid):
return 'Steam64';
default:
throw new Exception("Invalid SteamID input!");
}
}
public static function convertSteamID($steamid)
{
try {
$type = self::resolveInputID($steamid);
switch ($type) {
case 'Steam2':
return $steamid;
case 'Steam3':
$converted = self::SteamID3_To_SteamID($steamid);
return $converted;
case 'Steam64':
$converted = self::SteamID64_To_SteamID($steamid);
return $converted;
default:
throw new Exception("Invalid SteamID input!");
}
} catch (Exception $e) {
error_log("Error during conversion: " . $e->getMessage());
throw $e;
}
}
public static function SteamID_To_SteamID3($steamid32)
{
if (preg_match('/^STEAM_[01]\:[01]\:(.*)$/', $steamid32, $res)) {
$st = '[U:1:';
$st .= $res[1] * 2 + intval(substr($steamid32, 8, 1));
$st .= ']';
return $st;
}
return false;
}
public static function SteamID3_To_SteamID($steamid3)
{
if (preg_match("/U:1:(\d+)/", $steamid3, $matches)) {
$steam3 = intval($matches[1]);
$A = $steam3 % 2;
$B = intval($steam3 / 2);
return "STEAM_0:" . $A . ":" . $B;
}
return false;
}
public static function SteamID_To_SteamID64($steamid32)
{
if (preg_match('/^STEAM_0\:1|0\:(.*)$/', $steamid32, $res)) {
list(, $m1, $m2) = explode(':', $steamid32, 3);
list($steam_cid, ) = explode('.', bcadd((((int)$m2 * 2) + $m1), '76561197960265728'), 2);
return $steam_cid;
}
return false;
}
public static function SteamID64_To_SteamID($steamid64)
{
$pattern = "/^(7656119)([0-9]{10})$/";
if (preg_match($pattern, $steamid64, $match)) {
$const1 = 7960265728;
$const2 = "STEAM_0:";
$steam32 = '';
if ($const1 <= $match[2]) {
$a = ($match[2] - $const1) % 2;
$b = ($match[2] - $const1 - $a) / 2;
$steam32 = $const2 . $a . ':' . $b;
}
return $steam32;
}
return false;
}
public static function GetSteamProfile($steamid64, $attribute)
{
if (preg_match('/^\d+$/', $steamid64)) {
$xml = simplexml_load_file("https://steamcommunity.com/profiles/".$steamid64."?xml=1");
} else {
$xml = simplexml_load_file("https://steamcommunity.com/id/".$steamid64."?xml=1");
}
$SteamProfileAttribute = array();
$attributes = explode(', ', $attribute);
foreach ($attributes as $key => $attr_key) {
$SteamProfileAttribute += [$attr_key => $xml->$attr_key];
}
return $SteamProfileAttribute;
}
function verifyAndConvertSteamID($steamid) {
try {
$steamID2 = Steam::convertSteamID($steamid);
return ['success' => true, 'steamID2' => $steamID2];
} catch (Exception $e) {
return ['success' => false, 'error' => $e->getMessage()];
}
}
}
?>