forked from MrGeorgen/2smart2wait
- minecraft token caching
- bug fixes
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -69,3 +69,4 @@ saveid
|
||||
.project
|
||||
#package-lock
|
||||
package-lock.json
|
||||
minecraft_token.json
|
||||
|
||||
14
README.md
14
README.md
@ -1,6 +1,12 @@
|
||||
# 2smart2wait
|
||||
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
|
||||
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.
|
||||
@ -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.
|
||||
- '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.
|
||||
- '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.
|
||||
- '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.
|
||||
- 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.
|
||||
|
||||
# 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-server-util": "^1.1.0",
|
||||
"moment": "^2.24.0",
|
||||
"node-schedule": "^1.3.2",
|
||||
"opn": "^6.0.0",
|
||||
"prompt": "^1.0.0",
|
||||
"sleep-ms": "^2.0.1"
|
||||
"prismarine-tokens": "^1.0.3",
|
||||
"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 prompt = require("prompt");
|
||||
const ping = require('minecraft-server-util');
|
||||
const sleep = require("sleep-ms")
|
||||
const tokens = require('prismarine-tokens');
|
||||
const save = "../saveid"
|
||||
var auth;
|
||||
var timedStart;
|
||||
var lastQueuePlace;
|
||||
var chunkData = [];
|
||||
@ -23,6 +24,11 @@ var id;
|
||||
var totalWaitTime;
|
||||
var starttimestring;
|
||||
var playTime;
|
||||
var options;
|
||||
var doing;
|
||||
var calcInterval;
|
||||
var authInterval;
|
||||
var reconnectinterval;
|
||||
webserver.restartQueue = config.reconnect.notConnectedQueueEnd;
|
||||
if (config.webserver) {
|
||||
webserver.createServer(config.ports.web); // create the webserver
|
||||
@ -46,6 +52,12 @@ let server; // the minecraft server to pass packets
|
||||
prompt.start();
|
||||
cmdInput();
|
||||
|
||||
options = {
|
||||
host: config.minecraftserver.hostname,
|
||||
port: config.minecraftserver.port,
|
||||
version: config.minecraftserver.version
|
||||
}
|
||||
|
||||
function cmdInput() {
|
||||
prompt.get("cmd", function (err, result) {
|
||||
userInput(result.cmd, false);
|
||||
@ -68,18 +80,32 @@ function stop() {
|
||||
|
||||
// function to start the whole thing
|
||||
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;
|
||||
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;
|
||||
client.on("packet", (data, meta) => { // each time 2b2t sends a packet
|
||||
switch (meta.name) {
|
||||
@ -91,10 +117,15 @@ function startQueuing() {
|
||||
let headermessage = JSON.parse(data.header);
|
||||
let positioninqueue = headermessage.text.split("\n")[5].substring(25);
|
||||
webserver.queuePlace = positioninqueue; // update info on the web page
|
||||
console.log(positioninqueue);
|
||||
if (webserver.queuePlace !== "None" && lastQueuePlace !== webserver.queuePlace) {
|
||||
let ETAhour = -Math.pow(positioninqueue/35.4, 2/3)+totalWaitTime;
|
||||
webserver.ETA = Math.floor(ETAhour) + "h " + ETAhour%1*60 + "m";
|
||||
server.motd = `Place in queue: ${positioninqueue}`; // set the MOTD because why not
|
||||
if (!totalWaitTime) {
|
||||
totalWaitTime = Math.pow(positioninqueue / 35.4, 2 / 3);
|
||||
}
|
||||
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
|
||||
log("Position in Queue: " + webserver.queuePlace)
|
||||
if (config.notification.enabled && webserver.queuePlace <= config.notification.queuePlace && !notisend && config.discordBot && id != null) {
|
||||
@ -150,7 +181,7 @@ function startQueuing() {
|
||||
}
|
||||
stop();
|
||||
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) => {
|
||||
@ -228,13 +259,16 @@ function log(logmsg) {
|
||||
}
|
||||
|
||||
function reconnect() {
|
||||
ping(config.minecraftserver.hostname, config.minecraftserver.port)
|
||||
.then((response) => {
|
||||
startQueuing();
|
||||
})
|
||||
.catch((error) => {
|
||||
reconnect();
|
||||
});
|
||||
doing = "reconnect"
|
||||
reconnectinterval = setInterval(function () {
|
||||
ping(config.minecraftserver.hostname, config.minecraftserver.port)
|
||||
.then((response) => {
|
||||
if (doing === "reconnect") startQueuing();
|
||||
clearInterval(reconnectinterval);
|
||||
})
|
||||
.catch((error) => {
|
||||
});
|
||||
}, 500)
|
||||
}
|
||||
|
||||
//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);
|
||||
break;
|
||||
case "stop":
|
||||
if (webserver.isInQueue) {
|
||||
stop();
|
||||
if (DiscordOrigin) sendDiscordMsg(discordMsg.channel, "Queue", "Queue is **stopped**");
|
||||
else console.log("Queue is stopped");
|
||||
} else {
|
||||
clearTimeout(timedStart);
|
||||
if (DiscordOrigin) sendDiscordMsg(discordMsg.channel, "Timer", "Timer is **stopped**");
|
||||
else console.log("Queue timer is stopped");
|
||||
switch (doing) {
|
||||
case "queue":
|
||||
stop();
|
||||
stopMsg(DiscordOrigin, discordMsg.channel, "Queue");
|
||||
break;
|
||||
case "timedStart":
|
||||
clearTimeout(timedStart);
|
||||
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;
|
||||
default:
|
||||
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);
|
||||
if (DiscordOrigin) {
|
||||
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) {
|
||||
channel.send({
|
||||
embed: {
|
||||
@ -379,19 +432,25 @@ function timeStringtoDateTime(time) {
|
||||
}
|
||||
|
||||
function calcTime(msg) {
|
||||
https.get("https://2b2t.io/api/queue", (resp) => {
|
||||
let data = '';
|
||||
resp.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
doing = "calcTime"
|
||||
calcInterval = setInterval(function () {
|
||||
https.get("https://2b2t.io/api/queue", (resp) => {
|
||||
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", () => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
}, 60000);
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user