-
Notifications
You must be signed in to change notification settings - Fork 7
/
raw.php
112 lines (103 loc) · 4.25 KB
/
raw.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
<?php
$db = new mysqli("localhost","steamidconvert",null,"steamidconvert");
include("apikey.php");
function toCommunityID($id) {
if (preg_match("/^STEAM_/",$id)) {
$parts = explode(":",$id);
return bcadd(bcadd(bcmul($parts[2],"2"),"76561197960265728"),$parts[1]);
} elseif (is_numeric($id) && strlen($id) < 16) {
return bcadd($id,"76561197960265728");
}
}
function toSteamID($id) {
if (is_numeric($id) && strlen($id) >= 16) {
$z = bcdiv(bcsub($id,"76561197960265728"),"2");
} elseif (is_numeric($id)) {
$z = bcdiv($id,"2");
}
$y = bcmod($id, '2');
return 'STEAM_0:' . $y . ':' . floor($z);
}
function toUserID($id) {
$split = explode(":",$id);
return $split[2] * 2 + $split[1];
}
function file_get_json($url) {
$data = file_get_contents($url);
return json_decode($data,true);
}
function file_get_xml($url) {
$xml = file_get_contents($url);
$p = xml_parser_create();
xml_parse_into_struct($p,$xml,$vals,$index);
xml_parser_free($p);
return $vals;
}
$output = [];
if (isset($_GET["input"])) {
$_GET["input"] = urldecode($_GET["input"]);
preg_match("/STEAM_\d:\d:\d+/i",$_GET["input"],$steamid);
preg_match("/7656119\d+/",$_GET["input"],$steamid64);
preg_match("/\[U:\d:\d+]/i",$_GET["input"],$uid);
if (count($steamid) > 0) {
$output["interpreted"] = "SteamID";
$data = file_get_json("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$apikey&steamids=" . toCommunityID($_GET["input"]));
if (isset($data["response"]["players"][0])) {
$ply = $data["response"]["players"][0];
$output["avatar"] = $ply["avatarfull"];
$output["name"] = $ply["personaname"];
$output["steamid"] = toSteamID($ply["steamid"]);
$output["steamid64"] = $ply["steamid"];
$output["uid"] = toUserID(toSteamID($ply["steamid"]));
}
} elseif (count($steamid64) > 0) {
$output["interpreted"] = "SteamID64";
$data = file_get_json("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$apikey&steamids=" . $_GET["input"]);
if (isset($data["response"]["players"][0])) {
$ply = $data["response"]["players"][0];
$output["avatar"] = $ply["avatarfull"];
$output["name"] = $ply["personaname"];
$output["steamid"] = toSteamID($ply["steamid"]);
$output["steamid64"] = $ply["steamid"];
$output["uid"] = toUserID(toSteamID($ply["steamid"]));
}
} elseif (count($uid) > 0) {
$output["interpreted"] = "UserID";
$_GET["input"] = preg_replace("/\[U:\d:(\d+)]/","$1",$_GET["input"]);
$data = file_get_json("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$apikey&steamids=" . toCommunityID($_GET["input"]));
if (isset($data["response"]["players"][0])) {
$ply = $data["response"]["players"][0];
$output["avatar"] = $ply["avatarfull"];
$output["name"] = $ply["personaname"];
$output["steamid"] = toSteamID($ply["steamid"]);
$output["steamid64"] = $ply["steamid"];
$output["uid"] = toUserID(toSteamID($ply["steamid"]));
}
} else {
$output["interpreted"] = "URL";
$_GET["input"] = preg_replace("/(https?:\/\/)?steamcommunity\.com\/id\//","",$_GET["input"]);
$vals = file_get_xml("http://steamcommunity.com/id/" . $_GET["input"] . "?xml=1");
if ($vals[1]["tag"] === "ERROR") {
$output["error"] = "Profile not found.";
} else {
$data = file_get_json("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$apikey&steamids=" . $vals[1]["value"]);
if (isset($data["response"]["players"][0])) {
$ply = $data["response"]["players"][0];
$output["avatar"] = $ply["avatarfull"];
$output["name"] = $ply["personaname"];
$output["steamid"] = toSteamID($ply["steamid"]);
$output["steamid64"] = $ply["steamid"];
$output["uid"] = toUserID(toSteamID($ply["steamid"]));
}
}
}
if (isset($output["steamid64"])) {
if ($output["steamid64"] != "76561198040894045") {
$db -> query("INSERT INTO `saves`(`ip`,`input`) VALUES ('".$db->real_escape_string($_SERVER["REMOTE_ADDR"])."','".$db->real_escape_string($output["steamid64"])."') ON DUPLICATE KEY UPDATE `input`='".$db->real_escape_string($output["steamid64"])."'");
} else {
$db -> query("DELETE IGNORE FROM `saves` WHERE `ip`='" . $_SERVER["REMOTE_ADDR"] . "'");
}
}
}
echo(json_encode($output));
?>