-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (52 loc) · 1.64 KB
/
index.js
File metadata and controls
61 lines (52 loc) · 1.64 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
const protocol = require('minecraft-protocol');
const express = require('express')
const app = express()
let tokens = []
app.get('/', (req, res) => {
let token = req.query.token;
if (token == undefined) {
res.status(400).send("Missing token.");
return
}
for (let t in tokens) {
res.status(200).send(tokens[t])
tokens.splice(tokens.indexOf(tokens[t]), 1)
return
}
res.status(400).send("Invalid token.")
})
app.listen(80, () => console.log(`✅ Listening.`))
// Create a minecraft server for recieving connections
const server = protocol.createServer({
'online-mode': true,
encryption: true,
host: '0.0.0.0',
port: 25565,
motd: "§7Join to generate an authentication token.\n§7Powered by §a§lhttps://git.io/fjM2L§7.",
maxPlayers: 0,
playerCount: 0
});
// Run on an incoming connection
server.on('login', function (client) {
// Generate a new token
while (true) {
let token = Math.floor(100000 + Math.random() * 900000)
for (let i in tokens) {
if (tokens[i]['token'] == token) continue
}
// Add token record and schedule deletion
let record = {
"token": token,
"uuid": client.uuid,
"username": client.username
}
tokens.push(record)
setTimeout(() => {
// Remove token from list
tokens.splice(tokens.indexOf(record), 1)
}, 300000)
// Kick player with message
client.write("kick_disconnect", {reason: `{"text": "§7Hey there, ${client.username}!\n§7Your code is §a§l${token}§7."}`})
return
}
});