- minecraft token caching
- bug fixes
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -69,3 +69,4 @@ saveid
|
|||||||
.project
|
.project
|
||||||
#package-lock
|
#package-lock
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
minecraft_token.json
|
||||||
|
|||||||
14
README.md
14
README.md
@ -1,6 +1,12 @@
|
|||||||
# 2smart2wait
|
# 2smart2wait
|
||||||
A fork of the popular proxy to wait out 2b2t.org's way too long queue.(https://github.com/surprisejedi/2lazy2wait)
|
A fork of the popular proxy to wait out 2b2t.org's way too long queue.(https://github.com/surprisejedi/2lazy2wait)
|
||||||
|
|
||||||
|
# Features
|
||||||
|
- costum ETA calculator
|
||||||
|
- use the play command if you to play at a specified time
|
||||||
|
- chunk caching
|
||||||
|
- stores the minecraft login token to avoid account blocking
|
||||||
|
|
||||||
# How to install
|
# How to install
|
||||||
1. Download node.js and install it. On non-windows platforms, you also need npm.
|
1. Download node.js and install it. On non-windows platforms, you also need npm.
|
||||||
2. Download this repository with the green button (top right of this page). If you downloaded it as zip, unzip it.
|
2. Download this repository with the green button (top right of this page). If you downloaded it as zip, unzip it.
|
||||||
@ -25,6 +31,7 @@ A fork of the popular proxy to wait out 2b2t.org's way too long queue.(https://g
|
|||||||
All commands can be used through discord or the cli.
|
All commands can be used through discord or the cli.
|
||||||
- 'start' will start the queue. It takes between 15-30 seconds for the bot to update with the queue position.
|
- 'start' will start the queue. It takes between 15-30 seconds for the bot to update with the queue position.
|
||||||
- 'start 14:00' will start at 2pm.
|
- 'start 14:00' will start at 2pm.
|
||||||
|
- 'play 8:00' will try to calculate the right time to join so you can at 8:00
|
||||||
- 'update' will send an update to the current channel with your position and ETA.
|
- 'update' will send an update to the current channel with your position and ETA.
|
||||||
- 'stop' will stop the queue.
|
- 'stop' will stop the queue.
|
||||||
|
|
||||||
@ -39,10 +46,3 @@ Do not repeatedly stop and start the queue, eventually you will not be able to l
|
|||||||
- Some people report not being able to ride animals using this proxy.
|
- Some people report not being able to ride animals using this proxy.
|
||||||
- 2b2t sometimes bugs out and removes you from the queue without telling you. In this case, your queue position will no longer move. Reconnect to fix this.
|
- 2b2t sometimes bugs out and removes you from the queue without telling you. In this case, your queue position will no longer move. Reconnect to fix this.
|
||||||
- If you connect after the the queue is finnished or reconnect the proxy will send cached chunk data. Otherwise you would fly in a emtpy world. Other data however like entities are not chached and will not displayed correctly. You can move out of render distance and come back to fix this issue. Sometimes the client renders a cached chunk with a blank texture.
|
- If you connect after the the queue is finnished or reconnect the proxy will send cached chunk data. Otherwise you would fly in a emtpy world. Other data however like entities are not chached and will not displayed correctly. You can move out of render distance and come back to fix this issue. Sometimes the client renders a cached chunk with a blank texture.
|
||||||
|
|
||||||
# Todo
|
|
||||||
- [x] Mention you once you get below 30 queue
|
|
||||||
|
|
||||||
- [ ] Calculate the perfect time to join the queue based on queue size/eta. (E.g aim to join 2b2t between 8-9pm)
|
|
||||||
|
|
||||||
- [ ] Replace the 2b2t ETA calculator
|
|
||||||
|
|||||||
@ -14,9 +14,8 @@
|
|||||||
"minecraft-protocol": "^1.11.0",
|
"minecraft-protocol": "^1.11.0",
|
||||||
"minecraft-server-util": "^1.1.0",
|
"minecraft-server-util": "^1.1.0",
|
||||||
"moment": "^2.24.0",
|
"moment": "^2.24.0",
|
||||||
"node-schedule": "^1.3.2",
|
|
||||||
"opn": "^6.0.0",
|
"opn": "^6.0.0",
|
||||||
"prompt": "^1.0.0",
|
"prismarine-tokens": "^1.0.3",
|
||||||
"sleep-ms": "^2.0.1"
|
"prompt": "^1.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
145
src/main.js
145
src/main.js
@ -11,8 +11,9 @@ const {DateTime} = require("luxon");
|
|||||||
const https = require("https");
|
const https = require("https");
|
||||||
const prompt = require("prompt");
|
const prompt = require("prompt");
|
||||||
const ping = require('minecraft-server-util');
|
const ping = require('minecraft-server-util');
|
||||||
const sleep = require("sleep-ms")
|
const tokens = require('prismarine-tokens');
|
||||||
const save = "../saveid"
|
const save = "../saveid"
|
||||||
|
var auth;
|
||||||
var timedStart;
|
var timedStart;
|
||||||
var lastQueuePlace;
|
var lastQueuePlace;
|
||||||
var chunkData = [];
|
var chunkData = [];
|
||||||
@ -23,6 +24,11 @@ var id;
|
|||||||
var totalWaitTime;
|
var totalWaitTime;
|
||||||
var starttimestring;
|
var starttimestring;
|
||||||
var playTime;
|
var playTime;
|
||||||
|
var options;
|
||||||
|
var doing;
|
||||||
|
var calcInterval;
|
||||||
|
var authInterval;
|
||||||
|
var reconnectinterval;
|
||||||
webserver.restartQueue = config.reconnect.notConnectedQueueEnd;
|
webserver.restartQueue = config.reconnect.notConnectedQueueEnd;
|
||||||
if (config.webserver) {
|
if (config.webserver) {
|
||||||
webserver.createServer(config.ports.web); // create the webserver
|
webserver.createServer(config.ports.web); // create the webserver
|
||||||
@ -46,6 +52,12 @@ let server; // the minecraft server to pass packets
|
|||||||
prompt.start();
|
prompt.start();
|
||||||
cmdInput();
|
cmdInput();
|
||||||
|
|
||||||
|
options = {
|
||||||
|
host: config.minecraftserver.hostname,
|
||||||
|
port: config.minecraftserver.port,
|
||||||
|
version: config.minecraftserver.version
|
||||||
|
}
|
||||||
|
|
||||||
function cmdInput() {
|
function cmdInput() {
|
||||||
prompt.get("cmd", function (err, result) {
|
prompt.get("cmd", function (err, result) {
|
||||||
userInput(result.cmd, false);
|
userInput(result.cmd, false);
|
||||||
@ -68,18 +80,32 @@ function stop() {
|
|||||||
|
|
||||||
// function to start the whole thing
|
// function to start the whole thing
|
||||||
function startQueuing() {
|
function startQueuing() {
|
||||||
|
doing = "auth";
|
||||||
|
if (config.minecraftserver.onlinemode) {
|
||||||
|
options.username = secrets.username;
|
||||||
|
options.password = secrets.password;
|
||||||
|
options.tokensLocation = "../minecraft_token.json"
|
||||||
|
options.tokensDebug = true;
|
||||||
|
tokens.use(options, function (_err, _opts) {
|
||||||
|
|
||||||
|
if (_err) throw _err;
|
||||||
|
|
||||||
|
client = mc.createClient(_opts);
|
||||||
|
join();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
options.username = config.minecraftserver.username;
|
||||||
|
client = mc.createClient(options);// connect to 2b2t
|
||||||
|
join();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function join() {
|
||||||
|
let ETAhour;
|
||||||
|
let timepassed;
|
||||||
|
doing = "queue"
|
||||||
webserver.isInQueue = true;
|
webserver.isInQueue = true;
|
||||||
activity("Starting the queue...");
|
activity("Starting the queue...");
|
||||||
let options = {
|
|
||||||
host: config.minecraftserver.hostname,
|
|
||||||
port: config.minecraftserver.port,
|
|
||||||
version: config.minecraftserver.version
|
|
||||||
}
|
|
||||||
if (config.minecraftserver.onlinemode) {
|
|
||||||
options.password = secrets.password;
|
|
||||||
options.username = secrets.username;
|
|
||||||
} else options.username = config.minecraftserver.username;
|
|
||||||
client = mc.createClient(options);// connect to 2b2t
|
|
||||||
let finishedQueue = false;
|
let finishedQueue = false;
|
||||||
client.on("packet", (data, meta) => { // each time 2b2t sends a packet
|
client.on("packet", (data, meta) => { // each time 2b2t sends a packet
|
||||||
switch (meta.name) {
|
switch (meta.name) {
|
||||||
@ -91,10 +117,15 @@ function startQueuing() {
|
|||||||
let headermessage = JSON.parse(data.header);
|
let headermessage = JSON.parse(data.header);
|
||||||
let positioninqueue = headermessage.text.split("\n")[5].substring(25);
|
let positioninqueue = headermessage.text.split("\n")[5].substring(25);
|
||||||
webserver.queuePlace = positioninqueue; // update info on the web page
|
webserver.queuePlace = positioninqueue; // update info on the web page
|
||||||
|
console.log(positioninqueue);
|
||||||
if (webserver.queuePlace !== "None" && lastQueuePlace !== webserver.queuePlace) {
|
if (webserver.queuePlace !== "None" && lastQueuePlace !== webserver.queuePlace) {
|
||||||
let ETAhour = -Math.pow(positioninqueue/35.4, 2/3)+totalWaitTime;
|
if (!totalWaitTime) {
|
||||||
webserver.ETA = Math.floor(ETAhour) + "h " + ETAhour%1*60 + "m";
|
totalWaitTime = Math.pow(positioninqueue / 35.4, 2 / 3);
|
||||||
server.motd = `Place in queue: ${positioninqueue}`; // set the MOTD because why not
|
}
|
||||||
|
timepassed = -Math.pow(positioninqueue / 35.4, 2 / 3) + totalWaitTime;
|
||||||
|
ETAhour = totalWaitTime - timepassed;
|
||||||
|
webserver.ETA = Math.floor(ETAhour) + "h " + Math.round((ETAhour % 1) * 60) + "m";
|
||||||
|
server.motd = `Place in queue: ${positioninqueue} ETA: ${webserver.ETA}`; // set the MOTD because why not
|
||||||
activity("Pos: " + webserver.queuePlace + " ETA: " + webserver.ETA); //set the Discord Activity
|
activity("Pos: " + webserver.queuePlace + " ETA: " + webserver.ETA); //set the Discord Activity
|
||||||
log("Position in Queue: " + webserver.queuePlace)
|
log("Position in Queue: " + webserver.queuePlace)
|
||||||
if (config.notification.enabled && webserver.queuePlace <= config.notification.queuePlace && !notisend && config.discordBot && id != null) {
|
if (config.notification.enabled && webserver.queuePlace <= config.notification.queuePlace && !notisend && config.discordBot && id != null) {
|
||||||
@ -150,7 +181,7 @@ function startQueuing() {
|
|||||||
}
|
}
|
||||||
stop();
|
stop();
|
||||||
log("Connection reset by 2b2t server. Reconnecting...");
|
log("Connection reset by 2b2t server. Reconnecting...");
|
||||||
if (config.reconnect.onError) setTimeout(reconnect, 4000);
|
if (config.reconnect.onError) setTimeout(reconnect, 6000);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('error', (err) => {
|
client.on('error', (err) => {
|
||||||
@ -228,13 +259,16 @@ function log(logmsg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function reconnect() {
|
function reconnect() {
|
||||||
ping(config.minecraftserver.hostname, config.minecraftserver.port)
|
doing = "reconnect"
|
||||||
.then((response) => {
|
reconnectinterval = setInterval(function () {
|
||||||
startQueuing();
|
ping(config.minecraftserver.hostname, config.minecraftserver.port)
|
||||||
})
|
.then((response) => {
|
||||||
.catch((error) => {
|
if (doing === "reconnect") startQueuing();
|
||||||
reconnect();
|
clearInterval(reconnectinterval);
|
||||||
});
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
});
|
||||||
|
}, 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
//function to filter out some packets that would make us disconnect otherwise.
|
//function to filter out some packets that would make us disconnect otherwise.
|
||||||
@ -320,19 +354,33 @@ function userInput(cmd, DiscordOrigin, discordMsg) {
|
|||||||
else console.log("Position: " + webserver.queuePlace + " Estimated time until login: " + webserver.ETA);
|
else console.log("Position: " + webserver.queuePlace + " Estimated time until login: " + webserver.ETA);
|
||||||
break;
|
break;
|
||||||
case "stop":
|
case "stop":
|
||||||
if (webserver.isInQueue) {
|
switch (doing) {
|
||||||
stop();
|
case "queue":
|
||||||
if (DiscordOrigin) sendDiscordMsg(discordMsg.channel, "Queue", "Queue is **stopped**");
|
stop();
|
||||||
else console.log("Queue is stopped");
|
stopMsg(DiscordOrigin, discordMsg.channel, "Queue");
|
||||||
} else {
|
break;
|
||||||
clearTimeout(timedStart);
|
case "timedStart":
|
||||||
if (DiscordOrigin) sendDiscordMsg(discordMsg.channel, "Timer", "Timer is **stopped**");
|
clearTimeout(timedStart);
|
||||||
else console.log("Queue timer is stopped");
|
stopMsg(DiscordOrigin, discordMsg.channel, "Timer");
|
||||||
|
break;
|
||||||
|
case "reconnect":
|
||||||
|
clearInterval(reconnectinterval);
|
||||||
|
stopMsg(DiscordOrigin, discordMsg.channel, "Reconnecting");
|
||||||
|
break;
|
||||||
|
case "auth":
|
||||||
|
clearInterval(authInterval);
|
||||||
|
stopMsg(DiscordOrigin, discordMsg.channel, "Authentication");
|
||||||
|
break;
|
||||||
|
case "calcTime":
|
||||||
|
clearInterval(calcInterval);
|
||||||
|
stopMsg(DiscordOrigin, discordMsg.channel, "Time calculation");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (/start (\d|[0-1]\d|2[0-3]):[0-5]\d$/.test(cmd)) {
|
if (/start (\d|[0-1]\d|2[0-3]):[0-5]\d$/.test(cmd)) {
|
||||||
timedStart = setTimeout(startQueuing, timeStringtoDateTime(cmd).toMillis()-DateTime.local().toMillis());
|
doing = "timedStart"
|
||||||
|
timedStart = setTimeout(startQueuing, timeStringtoDateTime(cmd).toMillis() - DateTime.local().toMillis());
|
||||||
activity("Starting at " + starttimestring);
|
activity("Starting at " + starttimestring);
|
||||||
if (DiscordOrigin) {
|
if (DiscordOrigin) {
|
||||||
sendDiscordMsg(discordMsg.channel, "Timer", "Queue is starting at " + starttimestring);
|
sendDiscordMsg(discordMsg.channel, "Timer", "Queue is starting at " + starttimestring);
|
||||||
@ -347,6 +395,11 @@ function userInput(cmd, DiscordOrigin, discordMsg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stopMsg(discordOrigin, channel, stoppedThing) {
|
||||||
|
if (discordOrigin) sendDiscordMsg(channel, stoppedThing, stoppedThing + " is **stopped**");
|
||||||
|
else console.log(stoppedThing + " is stopped");
|
||||||
|
}
|
||||||
|
|
||||||
function sendDiscordMsg(channel, titel, content) {
|
function sendDiscordMsg(channel, titel, content) {
|
||||||
channel.send({
|
channel.send({
|
||||||
embed: {
|
embed: {
|
||||||
@ -379,19 +432,25 @@ function timeStringtoDateTime(time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function calcTime(msg) {
|
function calcTime(msg) {
|
||||||
https.get("https://2b2t.io/api/queue", (resp) => {
|
doing = "calcTime"
|
||||||
let data = '';
|
calcInterval = setInterval(function () {
|
||||||
resp.on('data', (chunk) => {
|
https.get("https://2b2t.io/api/queue", (resp) => {
|
||||||
data += chunk;
|
let data = '';
|
||||||
|
resp.on('data', (chunk) => {
|
||||||
|
data += chunk;
|
||||||
|
});
|
||||||
|
resp.on("end", () => {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
totalWaitTime = Math.pow(data[0][1] / 35.4, 2 / 3); // data[0][1] is the current queue length
|
||||||
|
playTime = timeStringtoDateTime(msg);
|
||||||
|
if (playTime.toSeconds() - DateTime.local().toSeconds() < totalWaitTime * 3600) {
|
||||||
|
startQueuing();
|
||||||
|
clearInterval(calcInterval);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
resp.on("end", () => {
|
}, 60000);
|
||||||
data = JSON.parse(data);
|
|
||||||
totalWaitTime = Math.pow(data[0][1] / 35.4, 2 / 3); // data[0][1] is the current queue length
|
|
||||||
playTime = timeStringtoDateTime(msg);
|
|
||||||
if (playTime.toSeconds() - DateTime.local().toSeconds() < totalWaitTime * 3600) startQueuing();
|
|
||||||
else setTimeout(calcTime, 60000);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
Reference in New Issue
Block a user