This repository has been archived by the owner on Jul 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
77 lines (62 loc) · 2.46 KB
/
server.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
const https = require('https')
/* Configuration! */
const txAdminUrl = "123.123.123.123"; /* Set to you txAdmin hostname or IP */
const txAdminPort = 40120; /* Default is 40120. */
const txAdminUsername = "username" /* Set to a txAdmin user with ban permissions */
const txAdminPassword = "password" /* Set to a txAdmin user with ban permissions */
/* No need to touch anything below here. You can, but it isn't needed really */
exports("txApi_banPlayer", (source, reason) => {
const data = JSON.stringify({
username: txAdminUsername,
password: txAdminPassword
})
const options = {
hostname: txAdminUrl,
port: txAdminPort,
path: '/auth/password',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
}
const req = https.request(options, res => {
var Cookies = res.headers["set-cookie"];
if (reason == null) {reason = "No reason given"}
const dataBan = JSON.stringify({
duration: 'permanent',
reference: source,
reason: `${reason}`
})
const optionsBan = {
hostname: txAdminUrl,
port: txAdminPort,
path: '/player/ban',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': dataBan.length,
'Cookie': Cookies
}
}
const reqBan = https.request(optionsBan, reqBan => {
reqBan.on('data', d => {
console.log("[^2\x1b[1mINFO\x1b[0m^7] \x1b[41m\x1b[30m|txApi|\x1b[0m\x1b[1m ^7Banned player ID:" + source + " for " + reason + "\x1b[0m^0")
})
})
reqBan.write(dataBan)
reqBan.end()
reqBan.on('error', error => {
console.log("[^1\x1b[1mERROR\x1b[0m^7] \x1b[41m\x1b[30m|txApi|\x1b[0m\x1b[1m " + error + "\x1b[0m^0")
})
res.on('data', d => {
console.log("[^2\x1b[1mINFO\x1b[0m^7] \x1b[41m\x1b[30m|txApi|\x1b[0m\x1b[1m ^7Logged in to txAdmin\x1b[0m^0")
})
}
)
req.write(data)
req.end()
req.on('error', error => {
console.log("[^1\x1b[1mERROR\x1b[0m^7] \x1b[41m\x1b[30m|txApi|\x1b[0m\x1b[1m " + error + "\x1b[0m^0")
})
});