-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathroblox_handler.php
More file actions
220 lines (204 loc) · 6.78 KB
/
roblox_handler.php
File metadata and controls
220 lines (204 loc) · 6.78 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
//Stop Direct Access to the File
//Works only in PHP 5.0 and Up
if (get_included_files()[0] == __FILE__) {
exit("<h1>Access Denied</h1>");
}
//Stop Including This File Twice
if (defined(strtoupper(basename(__FILE__, ".php")) . "_PHP")) {
return True;
}
define(strtoupper(basename(__FILE__, ".php")) . "_PHP", True);
include_once "database.php";
//Get Roblox User Info From Name
function getRobloxUserInfo($name) {
$url = "https://users.roblox.com/v1/usernames/users";
$data = [
'usernames' => [$name],
'excludeBannedUsers' => true
];
$options = [
'http' => [
'method' => 'POST',
'header' => "Content-Type: application/json\r\n",
'content' => json_encode($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$result = json_decode($result, true);
if (isset($result["data"][0]["id"])) {
return $result["data"][0];
}
return false;
}
//Get Roblox User Id From Name
function getUserId($name) {
global $conn;
$result = $conn->queryPrepared("SELECT `user_id` FROM `user` WHERE `username` = ?", [$name]);
if ($result->num_rows > 0) {
$result = $result->fetch_assoc();
return $result["user_id"];
}
$result = getRobloxUserInfo($name);
if ($result) {
$conn->queryPrepared("INSERT INTO `user` (`username`, `user_id`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `username` = ?", [$result["name"], $result["id"], $result["name"]]);
return $result["id"];
}
return false;
}
//Get Name from User Id
function getName($user_id)
{
global $conn;
$result = $conn->queryPrepared("SELECT `username` FROM `user` WHERE `user_id` = ?", [$user_id]);
if ($result->num_rows > 0) {
$result = $result->fetch_assoc();
return $result["username"];
}
$url = "https://users.roblox.com/v1/users/" . $user_id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result, true);
if (isset($result["name"])) {
$conn->queryPrepared("INSERT INTO `user` (`username`, `user_id`) VALUES (?, ?)", [$result["name"], $result["id"]]);
return $result["name"];
}
return false;
}
//Get Roblox User Description from Id
function getUserDescription($id)
{
$url = "https://users.roblox.com/v1/users/" . $id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result, true);
if (isset($result["description"])) {
return $result["description"];
}
return false;
}
//Get User Description from Id from Database
function getUserDescriptionDatabase($id)
{
global $conn;
$result = $conn->queryPrepared("SELECT `description` FROM `user` WHERE `user_id` = ?", [$id]);
if ($result->num_rows > 0) {
$result = $result->fetch_assoc();
return $result["description"];
}
return false;
}
//Get Roblox User Description from name
function getUserDescriptionFromName($name)
{
$id = getUserId($name);
if ($id) {
return getUserDescription($id);
}
return false;
}
//Get User Description from name from Database
function getUserDescriptionFromNameDatabase($name)
{
global $conn;
$result = $conn->queryPrepared("SELECT `description` FROM `user` WHERE `username` = ?", [$name]);
if ($result->num_rows > 0) {
$result = $result->fetch_assoc();
return getUserDescriptionDatabase($result["description"]);
}
return false;
}
//Get Roblox User Thumbnail from Id
function getUserThumbnail($id, $size = "420x420", $fresh = false)
{
global $conn;
if (!$fresh) {
$result = $conn->queryPrepared("SELECT `thumbnail` FROM `user` WHERE `user_id` = ?", [$id]);
if ($result->num_rows > 0) {
$result = $result->fetch_assoc();
if ($result["thumbnail"]) {
return $result["thumbnail"];
}
}
}
$url = "https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds=" . $id . "&size=" . $size . "&format=Png&isCircular=false";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result, true);
if (isset($result["data"])) {
if ($result["data"][0]["state"] == "Completed") {
$conn->queryPrepared("UPDATE `user` SET `thumbnail` = ? WHERE `user_id` = ?", [$result["data"][0]["imageUrl"], $id]);
return $result["data"][0]["imageUrl"];
} else {
return getUserThumbnail($id, $size,$fresh);
}
}
return false;
}
//Get Roblox User Thumbnail from Name
function getUserThumbnailFromName($name, $size = "420x420", $fresh = false)
{
$id = getUserId($name);
if ($id) {
return getUserThumbnail($id, $size, $fresh);
}
return false;
}
//Check If String is in User Description
function checkUserDescription($id, $string)
{
$found = false;
$description = getUserDescriptionDatabase($id);
if ($description) {
$found = strpos($description, $string) !== false;
}
if (!$found) {
$description = getUserDescription($id);
if ($description) {
$found = strpos($description, $string) !== false;
}
}
return $found;
}
//Check if String is in User Description From Name
function checkUserDescriptionFromName($name, $string)
{
$id = getUserId($name);
if ($id) {
return checkUserDescription($id, $string);
}
return false;
}
//Get Asset Thumbnail from Id
function getAssetThumbnail($id, $size = "420x420")
{
$url = "https://thumbnails.roblox.com/v1/assets?assetIds=" . $id . "&size=" . $size . "&format=Png&isCircular=false";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result, true);
if (isset($result["data"]) and count($result["data"]) > 0) {
if ($result["data"][0]["state"] == "Completed") {
return $result["data"][0]["imageUrl"];
} else {
return getAssetThumbnail($id, $size);
}
}
return false;
}