Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Community suggestions: password, restart
Browse files Browse the repository at this point in the history
also: config for minecraft version, and auto-opening of the webpage.
  • Loading branch information
Themoonisacheese committed Jun 2, 2019
1 parent e0f59a2 commit 925cb0e
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 37 deletions.
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
# 2bored2wait
A proxy to wait out 2b2t.org's way too long queue.


# 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.
3. Open a terminal and navigate to the folder you downloaded it
4. Run `npm install`
5. Copy secrets.json.example and name it secrets.json. Fill out your minecraft information in the file. Note that you must use your email adress and not your minecraft username.
6. If you so wish, edit the configuration in config.json.
7. For trust reasons, this tool does not update automatically. Check back here once in a while to see if there are any updates.


# How to use
1. read the code to ensure i'm not stealing your credentials. i'm not, but you shouldn't take my word for it.
2. run `npm install`
3. Copy secrets.json.example and name it secrets.json. Fill out your minecraft information in the file.
1. read the code to ensure i'm not stealing your credentials. i'm not, but you shouldn't take my word for it. If you don't know how to read it, downloading stuff off the internet and giving it your password is probably a bad idea anyway.
4. run `npm start`
5. open a browser window and go to http://localhost (or the adress of the server if you're hosting it elsewhere. yes, this works. just ensure you opened ports 80 (web) and 25565 (minecraft) on your router).
5. a browser window should open. You can close it if you want at any moment, and you can access it again at adress http://localhost
6. press the "Start queing" button. The queue position indicator auto-updates, but sometimes it takes a while to start counting (like 1 min).
7. once the queue reaches a low number, connect to the minecraft server at address `localhost`. Currently, you have to connect BEFORE reaching the end of the queue or you will not spawn in the world correctly (I'm told that sneaking around and right-clicking things eventually makes you spawn correctly but I was not able to verify that).
8. after you log off, click the "stop queuing" button. this is really important, as you will not actually disconnect until you do that.
8. after you log off, click the "stop queuing" button. This is really important, as you will not actually disconnect from 2b2t until you do that.

# Plans for the future
- make the proxy disconnect when you log off
- add some QOL features, such as anti-sign ban or anti-book ban

# Known issues
- starting the queue will revoke your minecraft token. this means that you will not be able to join normal minecraft servers until you restart the game
- starting the queue too many times in a row can sometimes boot you out of your minecraft account (starting the queue or connecting in the minecraft client will tell you "wrong email or password"). to fix this, log in to your account at minecraft.net, then restart minecraft. both of these issues are limitations put in place by mojang to prevent account stealing, and are not fixable.
- 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.

5 changes: 4 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"ports":{
"minecraft":25565,
"web":80
}
},
"openBrowserOnStart": true,
"password":"",
"MCversion":"1.12.2"
}
2 changes: 1 addition & 1 deletion index.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ body {
background-color: rgb(16, 16, 26);
}

h1 {
h1, .content {
margin: 0;
color: rgb(228, 228, 228);
font-family: sans-serif;
Expand Down
16 changes: 14 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
<div class="content">
<h1>Place in queue: <div class="place">None</div> </h1>
<h1>ETA: <div class="ETA">None</div> </h1>
<button id="queueButton" class="start" onclick="start()">Start queuing</button>
Password (leave blank if none) : <input type="password" class="password"><br>
<button id="queueButton" class="start" onclick="start()">Start queuing</button><br><br>
<input type="checkbox" class="restartQueue" onchange="toggleRestartQueue()"> Restart the queue if you're not connected at the end of it?
</div>
<script>
setInterval(() => { //each second, update the info.
const xhr = new XMLHttpRequest();
xhr.open("GET", "/update", true);

xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
const response = JSON.parse(this.responseText);
document.getElementsByClassName("place")[0].innerHTML = response.place;
document.getElementsByClassName("ETA")[0].innerHTML = response.ETA;
document.getElementsByClassName("restartQueue")[0].checked = response.restartQueue
const queueButton = document.getElementById('queueButton');
if(response.inQueue){
queueButton.innerHTML = "Stop queuing";
Expand All @@ -31,13 +33,15 @@ <h1>ETA: <div class="ETA">None</div> </h1>
}
}
}
xhr.setRequestHeader('XPassword', document.getElementsByClassName('password')[0].value)
xhr.send();

}, 1000);

function start() {
const xhr = new XMLHttpRequest();
xhr.open("GET", "/start", true);
xhr.setRequestHeader('XPassword', document.getElementsByClassName('password')[0].value)
xhr.send();
const queueButton = document.getElementById('queueButton');
queueButton.innerHTML = "Stop queuing";
Expand All @@ -49,6 +53,7 @@ <h1>ETA: <div class="ETA">None</div> </h1>
function stop() {
const xhr = new XMLHttpRequest();
xhr.open("GET", "/stop", true);
xhr.setRequestHeader('XPassword', document.getElementsByClassName('password')[0].value)
xhr.send();
const queueButton = document.getElementById('queueButton');
queueButton.innerHTML = "Start queuing";
Expand All @@ -58,6 +63,13 @@ <h1>ETA: <div class="ETA">None</div> </h1>
document.getElementsByClassName("ETA")[0].innerHTML = 'None';
}

function toggleRestartQueue(){
const xhr = new XMLHttpRequest();
xhr.open("GET", "/togglerestart", true);
xhr.setRequestHeader('XPassword', document.getElementsByClassName('password')[0].value)
xhr.send();
}

</script>
</body>
</html>
29 changes: 22 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@
const mc = require('minecraft-protocol'); // to handle minecraft login session
const fs = require('fs'); // to read creds file
const webserver = require('./webserver.js'); // to serve the webserver
const opn = require('opn'); //to open a browser window


const secrets = JSON.parse(fs.readFileSync('secrets.json')); // read the creds
const config = JSON.parse(fs.readFileSync('config.json')); // read the config

webserver.createServer(config.ports.web); // create the webserver
webserver.password = config.password
webserver.onstart(() => { // set up actions for the webserver
startQueuing();
});
webserver.onstop(() => {
stop();
});

if (config.openBrowserOnStart) {
opn('http://localhost:' + config.ports.web); //open a browser window
}


// lets
let proxyClient; // a reference to the client that is the actual minecraft game
let client; // the client to connect to 2b2t
Expand All @@ -40,7 +48,7 @@ function startQueuing() {
port: 25565,
username: secrets.username,
password: secrets.password,
version: "1.12.2"
version: config.MCversion
});
let finishedQueue = false;
client.on("packet", (data, meta) => { // each time 2b2t sends a packet
Expand All @@ -56,9 +64,14 @@ function startQueuing() {
// we need to know if we finished the queue otherwise we crash when we're done, because the queue info is no longer in packets the server sends us.
let chatMessage = JSON.parse(data.message);
if (chatMessage.text && chatMessage.text === "Connecting to the server...") {
finishedQueue = true;
webserver.queuePlace = "FINISHED";
webserver.ETA = "NOW";
if (webserver.restartQueue && proxyClient == null) { //if we have no client connected and we should restart
stop();
setTimeout(startQueuing, 100); // reconnect after 100 ms
} else {
finishedQueue = true;
webserver.queuePlace = "FINISHED";
webserver.ETA = "NOW";
}
}
}

Expand All @@ -70,15 +83,17 @@ function startQueuing() {
// set up actions in case we get disconnected.
client.on('end', () => {
if (proxyClient) {
proxyClient.end("Connection reset by 2b2t server.\nReconnecting...");
proxyClient.end("Connection reset by 2b2t server.\nReconnecting...");
proxyClient = null
}
stop();
// setTimeout(startQueuing, 100); // reconnect after 100 ms
});

client.on('error', (err) => {
if (proxyClient) {
proxyClient.end(`Connection error by 2b2t server.\n Error message: ${err}\nReconnecting...`);
proxyClient.end(`Connection error by 2b2t server.\n Error message: ${err}\nReconnecting...`);
proxyClient = null
}
console.log('err', err);
stop();
Expand All @@ -90,7 +105,7 @@ function startQueuing() {
encryption: true,
host: '0.0.0.0',
port: config.ports.minecraft,
version: '1.12.2',
version: config.MCversion,
maxPlayers: 1
});

Expand Down
43 changes: 25 additions & 18 deletions webserver.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//this module exposes functions and variables to control the HTTP server.
const http = require('http'); //to serve the pages
const fs = require('fs'); //to read the webpages from disk
const opn = require('opn');

module.exports = {
createServer : (port) => {
Expand All @@ -14,26 +13,32 @@ module.exports = {
res.writeHead(200, {'Content-type': 'text/css'});
res.write(fs.readFileSync('index.css'));
res.end();
} else if(req.url === "/update") { //API endpoint to get position, ETA, and status in JSON format
res.writeHead(200, {'Content-type': 'text/json'});
res.write("{\"username\": \""+ module.exports.username +"\",\"place\": \""+ module.exports.queuePlace +"\",\"ETA\": \""+ module.exports.ETA +"\", \"inQueue\": " + module.exports.isInQueue+"}")
res.end();
} else if(req.url === "/start") { //API endpoint to start queuing
res.writeHead(200);
res.end();
module.exports.onstartcallback();
} else if(req.url === "/stop") { //API endpoint to stop queuing
res.writeHead(200);
res.end();
module.exports.onstopcallback();
} else {
res.writeHead(404);
res.end();
} else if (req.headers.xpassword == module.exports.password) { //before doing any action, test if the provided password is correct.
if(req.url === "/update") { //API endpoint to get position, ETA, and status in JSON format
res.writeHead(200, {'Content-type': 'text/json'});
res.write("{\"username\": \""+ module.exports.username +"\",\"place\": \""+ module.exports.queuePlace +"\",\"ETA\": \""+ module.exports.ETA +"\", \"inQueue\": " + module.exports.isInQueue+", \"restartQueue\":"+ module.exports.restartQueue+"}")
res.end();
} else if(req.url === "/start") { //API endpoint to start queuing
res.writeHead(200);
res.end();
module.exports.onstartcallback();
} else if(req.url === "/stop") { //API endpoint to stop queuing
res.writeHead(200);
res.end();
module.exports.onstopcallback();
} else if(req.url === "/togglerestart"){
module.exports.restartQueue = !module.exports.restartQueue
} else {
res.writeHead(404);
res.end();
}
}else{
res.writeHead(403);
res.end()
}
}).listen(port);
},
onstart: (callback) => { //function to set the action to do when starting
opn('http://localhost');
module.exports.onstartcallback = callback;
},
onstop: (callback) => { //same but to stop
Expand All @@ -43,6 +48,8 @@ module.exports = {
ETA: "None", //ETA
isInQueue: false, //are we in queue?
onstartcallback: null, //a save of the action to start
onstopcallback: null //same but to stop
onstopcallback: null, //same but to stop
restartQueue: false, //when at the end of the queue, restart if no client is connected?
password: "" //the password to use for the webapp
};

0 comments on commit 925cb0e

Please sign in to comment.