This repository has been archived by the owner on Jun 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
244 lines (230 loc) · 8.02 KB
/
index.js
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
// $$\ $$\ $$$$$$\ $$$$$$$\ $$$$$$\
// $$ | $$ |$$ __$$\ $$ __$$\ $$ __$$\
// $$ | $$ |$$ / $$ |$$ | $$ |$$ / \__|
// \$$\ $$ |$$ | $$ |$$$$$$$ |\$$$$$$\
// \$$\$$ / $$ | $$ |$$ ____/ \____$$\
// \$$$ / $$ | $$ |$$ | $$\ $$ |
// \$ / $$$$$$ |$$ | \$$$$$$ |
// \_/ \______/ \__| \______/
//
// CheatBreaker Cosmetics API created by ItsVops
// https://github.com/ItsVops/CB-Cosmetics-API
//
var express = require("express");
var app = express();
var fs = require("fs");
var request = require("request");
var config = require("./config.json");
var { exit } = require("process");
function rawBody(req, res, next) {
req.setEncoding("utf8");
req.rawBody = "";
req.on("data", function (chunk) {
req.rawBody += chunk;
});
req.on("end", function () {
next();
});
}
app.use(rawBody);
// CHEATBREAKER REQUESTS (PLAYER, TOGGLE, SERVERS) START
app.get("/player/:uuid", async function (req, res) {
// Show Player Data
try {
const uuid = req.params.uuid;
const userPath = "users/" + uuid + ".json";
if (!fs.existsSync(userPath)) {
res.send({ uuid: uuid, cosmetics: {} });
return;
}
var playerData = fs.readFileSync(userPath);
var obj = JSON.parse(playerData);
res.send(obj);
}catch(err){console.log(err)}
});
app.post("/player/:uuid/cosmetics/:cosmetic/toggle", async function (req, res) {
// Toggle Player Cosmetic
try {
var uuid = req.params.uuid;
var cosmetic = req.params.cosmetic;
var userPath = "users/" + uuid + ".json";
var file = require("./users/" + uuid + ".json");
if (!file) return res.send({ success: false, errMsg: "user does not have cosmetic" });
var body = req.rawBody;
if (body !== "true" && body !== "false") {
res.send({ success: false, errMsg: "body is not a boolean" });
return;
}
if (!file.cosmetics[cosmetic]) return res.send({ success: false, errMsg: "user does not have cosmetic" });
file.cosmetics[cosmetic].active = body == "true";
fs.writeFileSync(userPath, JSON.stringify(file, null, 2));
res.send({ success: true });
}catch(err){console.log(err)}
});
app.get("/servers", async function (req, res) {
// Show Pinned Servers
try {
var obj = JSON.parse(fs.readFileSync("servers.json"));
res.send(obj);
}catch(err){console.log(err)}
});
// CHEATBREAKER REQUESTS (PLAYER, TOGGLE, SERVERS) END
// ADMIN PANEL DISPLAY & FUNCTIONS START
app.use(`/${config.secret}/panel`, express.static("panel")); // show panel HTML
app.get(`/${config.secret}/panel/addCape`, async function (req, res) {
try {
// addcape function (should have made this 1 function with wings but whatever)
var username = req.query.username;
var cape = req.query.cape;
var uuid;
request(
"https://api.ashcon.app/mojang/v2/user/" + username,
function (error, response, body) {
try {
var json = JSON.parse(body);
} catch (err) {}
if (!json) return res.send({ success: false });
if (!json.uuid) return res.send({ success: false });
uuid = json.uuid;
var userPath = "users/" + uuid + ".json";
if (!fs.existsSync(userPath)) {
var obj = { uuid: uuid, cosmetics: {} };
let data = JSON.stringify(obj, null, 2);
fs.writeFileSync(userPath, data);
}
fs.readFile(userPath, function (err, data) {
var json = JSON.parse(data);
json.cosmetics[cape] = {
active: false,
name: cape,
resourceLocation: cape,
scale: 0.16,
type: "cape",
};
let newCape = JSON.stringify(json, null, 2);
fs.writeFileSync(userPath, newCape);
});
res.send({ success: true });
}
);
}catch(err){console.log(err)}
});
app.get(`/${config.secret}/panel/addWings`, async function (req, res) {
// add wings
try {
var username = req.query.username;
var wings = req.query.wings;
var uuid;
request(
"https://api.ashcon.app/mojang/v2/user/" + username,
function (error, response, body) {
try {
var json = JSON.parse(body);
} catch (err) {}
if (!json) return res.send({ success: false });
if (!json.uuid) return res.send({ success: false });
uuid = json.uuid;
var userPath = "users/" + uuid + ".json";
if (!fs.existsSync(userPath)) {
var obj = { uuid: uuid, cosmetics: {} };
let data = JSON.stringify(obj, null, 2);
fs.writeFileSync(userPath, data);
}
fs.readFile(userPath, function (err, data) {
var json = JSON.parse(data);
json.cosmetics[wings] = {
active: false,
name: wings,
resourceLocation: wings,
scale: 0.14,
type: "dragon_wings",
};
let newWings = JSON.stringify(json, null, 2);
fs.writeFileSync(userPath, newWings);
});
res.send({ success: true });
}
);
}catch(err){console.log(err)}
});
app.get(`/${config.secret}/panel/delCape`, async function (req, res) {
// del cape
try {
var username = req.query.username;
var cape = req.query.cape;
var uuid;
request(
"https://api.ashcon.app/mojang/v2/user/" + username,
function (error, response, body) {
try {
var json = JSON.parse(body);
} catch (err) {}
if (!json) return res.send({ success: false });
if (!json.uuid) return res.send({ success: false });
uuid = json.uuid;
var userPath = "users/" + uuid + ".json";
if (!fs.existsSync(userPath)) return res.send({ success: false });
fs.readFile(userPath, function (err, data) {
var json = JSON.parse(data);
delete json.cosmetics[cape];
let newCape = JSON.stringify(json, null, 2);
fs.writeFileSync(userPath, newCape);
});
res.send({ success: true });
}
);
}catch(err){console.log(err)}
});
app.get(`/${config.secret}/panel/delWings`, async function (req, res) {
// add wings
try {
var username = req.query.username;
var wings = req.query.wings;
var uuid;
request(
"https://api.ashcon.app/mojang/v2/user/" + username,
function (error, response, body) {
try {
var json = JSON.parse(body);
} catch (err) {}
if (!json) return res.send({ success: false });
if (!json.uuid) return res.send({ success: false });
uuid = json.uuid;
var userPath = "users/" + uuid + ".json";
if (!fs.existsSync(userPath)) return res.send({ success: false });
fs.readFile(userPath, function (err, data) {
var json = JSON.parse(data);
delete json.cosmetics[wings];
let newwings = JSON.stringify(json, null, 2);
fs.writeFileSync(userPath, newwings);
});
res.send({ success: true });
}
);
}catch(err){console.log(err)}
});
// ADMIN PANEL DISPLAY & FUNCTIONS END
app.get("*", function (req, res) {
// simple 404
res
.status(404)
.send(
`<h1>404</h1>Please read the <a href="https://github.com/ItsVops/CB-Cosmetics-API/wiki"><b>CB Cosmetics API</b></a> wiki to see where you are suppose to go.`
);
});
if (!config.port) return console.log("Something is wrong with the config.json! Please fix it or redownload.");
app.listen(config.port, function () {
// OPEN THE GATES (turn on api)
request("https://httpbin.org/ip", function (error, response, body) {
//this shows the hosts ip for the console to display (makes it eaiser for the host)
if (error) return console.log(`CB Cosmetics API is online!`);
var json = JSON.parse(body);
var origin = json.origin;
if (!origin) return console.log(`CB Cosmetics API is online!`);
if (!config.secret) return console.log("Something is wrong with the config.json! Please fix it or redownload.");
if (config.secret == "ENTER_SECRET_HERE") return console.log("Please change the Panel Secret in config.json!");
console.log(
`CB Cosmetics API is online!\nPublic Link: http://${origin}:${config.port}\nPanel Link: http://${origin}:${config.port}/${config.secret}/panel\nNote: Port ${config.port} must be open for this API to be accessible by the public.`
);
});
});