-
Notifications
You must be signed in to change notification settings - Fork 0
/
ban.js
296 lines (268 loc) · 7.38 KB
/
ban.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
const log = require('./log.js').log;
const fs = require('fs-extra');
const settings = require(`${__dirname}/json/settings.json`);
const io = require('./server.js').io;
const sanitize = require('sanitize-html');
const { EmbedBuilder, WebhookClient } = require('discord.js');
const reports_hook = new WebhookClient({url: "https://discord.com/api/webhooks/1085690050383187980/P4Pc1EqZzYUK1-t3AI7eU9bZRm8Q9ownQeZAPIVf9yPDDFj5veSu3yXqtnJiofT8OiNl"});
const admx_hook = new WebhookClient({url: "https://discord.com/api/webhooks/1085690409004572763/VVVjdn9DdXd7QT6twBDckARL3KwPnF8-8ZTTkoZ7M6Y8BlRyK9mnbV0t3-HJ84SSwky6"});
let bans;
let mutes;
let logins;
let accounts;
let rooms;
var rooms_table = [];
process.on("uncaughtException", (err) => {
console.log(err.stack);
throw err;
});
function replace_crap(string) {
return string
.replaceAll("@", "%")
.replaceAll("`", "\u200B ")
.replaceAll(" ", "\u200B ")
.replaceAll("http://", "hgrunt/ass.wav ")
.replaceAll("https://", "hgrunt/ass.wav ")
.replaceAll("discord.gg/", "hgrunt/ass.wav ")
.replaceAll("discord.com/", "hgrunt/ass.wav ")
.replaceAll("bonzi.lol", "bwe ")
.replaceAll("bonzi.ga", "bwe ")
.replaceAll("*", " ")
.replaceAll("|", " ")
.replaceAll("~", " ");
}
exports.rooms = rooms;
exports.rooms_table = rooms_table;
exports.init = () => {
fs.writeFile(`${__dirname}/json/bans.json`, "{}", { flag: 'wx' }, (err) => {
if (!err)
console.log("Created empty bans list.");
try {
bans = require(`${__dirname}/json/bans.json`);
} catch (e) {
throw "Could not load bans.json. Check syntax and permissions.";
}
});
fs.writeFile(`${__dirname}/json/mutes.json`, "{}", { flag: 'wx' }, (err) => {
if (!err)
console.log("Created empty mutes list.");
try {
mutes = require(`${__dirname}/json/mutes.json`);
} catch (e) {
throw "Could not load mutes.json. Check syntax and permissions.";
}
});
};
exports.saveBans = () => {
fs.writeFile(
`${__dirname}/json/bans.json`,
JSON.stringify(bans),
{ flag: 'w' },
function (error) {
log.info.log('info', 'banSave', {
error: error
});
}
);
};
exports.saveReport = () => {
fs.writeFile(
`${__dirname}/json/reports.json`,
JSON.stringify(reports)
);
};
exports.saveMutes = () => {
fs.writeFile(
`${__dirname}/json/mutes.json`,
JSON.stringify(mutes),
{ flag: 'w' },
function (error) {
log.info.log('info', 'banSave', {
error: error
});
}
);
};
// Ban length is in minutes
exports.addBan = (ip, length, reason) => {
length = parseFloat(length) || settings.banLength;
reason = reason || "N/A";
bans[ip] = {
name: reason,
end: new Date().getTime() + (length * 60000)
};
var sockets = io.sockets.sockets;
var socketList = Object.keys(sockets);
for (var i = 0; i < socketList.length; i++) {
var socket = sockets[socketList[i]];
if (socket.handshake.headers['cf-connecting-ip'] == ip)
exports.handleBan(socket);
}
exports.saveBans();
};
exports.removeBan = (ip) => {
delete bans[ip];
exports.saveBans();
};
exports.removeSocket = (ip) => {
delete ips[ip];
exports.saveIps();
};
exports.removeMute = (ip) => {
delete mutes[ip];
exports.saveMutes();
};
exports.removeLogin = (ip) => {
delete logins[ip];
exports.saveLogins();
};
exports.handleReport = (name) => {
var ip = name;
return true;
};
exports.handleBan = (socket) => {
var ip = socket.handshake.headers['cf-connecting-ip'] || socket.request.connection.remoteAddress;
var agent = socket.handshake.headers['user-agent'];
if (bans[ip].end <= new Date().getTime()) {
exports.removeBan(ip);
return false;
}
log.access.log('info', 'ban', {
ip: ip
});
socket.emit('ban', {
reason: bans[ip].reason,
end: bans[ip].end
});
socket.disconnect();
return true;
};
exports.handleReport = (name) => {
var ip = name;
var username = replace_crap(reports[ip].username);
var reason = replace_crap(reports[ip].reason);
var reporter = replace_crap(reports[ip].reporter);
var rid = replace_crap(reports[ip].rid);
const IMAGE_URL = "https://raw.githubusercontent.com/CosmicStar98/BonziWORLD-Enhanced/main/BWE%20Icon.png";
const reportEmbed = {
color: 0xCF14B0,
author: {
name: `BonziWORLD: Enhanced | Ver ${settings.version}`,
icon_url: IMAGE_URL,
url: 'https://github.com/CosmicStar98/BonziWORLD-Enhanced',
},
fields: [
{
name: 'Who:',
value: username,
inline: true,
},
{
name: 'Room ID:',
value: rid,
inline: true,
},
{
name: 'Reason:',
value: reason,
inline: true,
},
{
name: 'Reporter:',
value: reporter,
inline: true,
},
],
timestamp: new Date().toISOString(),
footer: {
text: 'Sent from the BWE website',
icon_url: IMAGE_URL,
},
};
if(settings.webhook.enabled == true) {
if (settings.webhoook.show_embeds == true) {
reports_hook.send({username: `${reporter} - New Report!`, avatarURL: IMAGE_URL, embeds: [reportEmbed]});
} else {
reports_hook.send({username: `${reporter} - New Report!`, avatarURL: IMAGE_URL, content: `> \u0060\n**Who: **${username}\n**Room ID: **${rid}\n**Reason: **${reason}.\n**Reporter: **${reporter}\u0060`});
}
}
console.log(`!!REPORT!!\nWho: ${username}\nRoom ID: ${rid}\nReason: ${reason}.\nReporter: ${reporter}`);
return true;
};
exports.handleMute = (socket) => {
var ip = socket.request.connection.remoteAddress;
if (mutes[ip].end <= new Date().getTime()) {
exports.removeMute(ip);
return false;
}
log.access.log('info', 'mute', {
ip: ip
});
socket.emit('mute', {
reason: `${mutes[ip].reason} <button onclick='hidemute()'>Close</button>`,
end: mutes[ip].end
});
return true;
};
exports.kick = (ip, reason) => {
var sockets = io.sockets.sockets;
var socketList = Object.keys(sockets);
for (var i = 0; i < socketList.length; i++) {
var socket = sockets[socketList[i]];
if (socket.request.connection.remoteAddress == ip) {
socket.emit('kick', {
reason: reason || "N/A"
});
socket.disconnect();
}
}
};
exports.warning = function(ip, reason) {
var sockets = io.sockets.sockets;
var socketList = Object.keys(sockets);
reason = reason || "N/A";
for (var i = 0; i < socketList.length; i++) {
var socket = sockets[socketList[i]];
if (socket.request.connection.remoteAddress == ip) {
socket.emit('warning', {
reason: `${reason} <button onclick='hidewarning()'>Close</button>`
});
}
}
};
exports.mute = (ip, length, reason) => {
var sockets = io.sockets.sockets;
var socketList = Object.keys(sockets);
length = parseFloat(length) || settings.banLength;
mutes[ip] = {
reason: reason,
end: new Date().getTime() + (length * 600)
};
reason = reason || "N/A";
for (var i = 0; i < socketList.length; i++) {
var socket = sockets[socketList[i]];
if (socket.request.connection.remoteAddress == ip) {
exports.handleMute(socket);
}
}
exports.saveMutes();
};
exports.addReport = (name, username, reason, reporter, rid) => {
var sockets = io.sockets.sockets;
var socketList = Object.keys(sockets);
reports[name] = {
username: username,
reporter: reporter,
rid: rid,
reason: reason
};
reason = reason || "N/A";
username = username || "missingno";
reporter = reporter || "FAK SAN WAT ARE YOU DOING, NO!";
rid = rid || "ERROR! Can't get room id";
exports.handleReport(name);
exports.saveReport();
};
exports.isBanned = (ip) => Object.keys(bans).indexOf(ip) != -1;
exports.isSocketIn = (ip) => Object.keys(ips).indexOf(ip) != -1;
exports.isMuted = (ip) => Object.keys(mutes).indexOf(ip) != -1;