update cmd gives better output

This commit is contained in:
MrGeorgen
2020-06-28 17:24:14 +02:00
parent e3fef4f097
commit 833b7af2bf
2 changed files with 85 additions and 51 deletions

View File

@ -11,14 +11,14 @@
"logging": true, // log errors and queue place "logging": true, // log errors and queue place
"reconnect": { "reconnect": {
"onError": true, // reconnect on error or if 2b2t kicks you "onError": true, // reconnect on error or if 2b2t kicks you
"notConnectedQueueEnd": true // restart the queue if you are not connect at the end of it "notConnectedQueueEnd": false // restart the queue if you are not connect at the end of it
}, },
"minecraftserver": { // the server you want to connect. Make not much sense to change it, was just added for development purpose "minecraftserver": { // the server you want to connect. Make not much sense to change it, was just added for development purpose
"hostname": "localhost", "hostname": "2b2t.org",
"port": 25565, "port": 25565,
"renderDistance": 8, "renderDistance": 8,
"version": "1.12.2", "version": "1.12.2",
"onlinemode": false, // chunk caching does not work correctly if set to false "onlinemode": true, // chunk caching does not work correctly if set to false
"username": "lol" // the username to use if onlinemode is false "username": "lol" // the username to use if onlinemode is false
}, },
"notification": { // sends a message via discord if the place in the queue reaches the specified number "notification": { // sends a message via discord if the place in the queue reaches the specified number

View File

@ -208,7 +208,7 @@ function join() {
}); });
server.on('login', (newProxyClient) => { // handle login server.on('login', (newProxyClient) => { // handle login
setTimeout(sendChunks, 50) setTimeout(sendChunks, 1000)
if (config.antiAntiAFK) clearInterval(antiAntiAFk); if (config.antiAntiAFK) clearInterval(antiAntiAFk);
newProxyClient.write('login', loginpacket); newProxyClient.write('login', loginpacket);
newProxyClient.write('position', { newProxyClient.write('position', {
@ -237,7 +237,6 @@ function join() {
chunkPos.lz = chunkPos.z; chunkPos.lz = chunkPos.z;
} }
filterPacketAndSend(data, meta, client); filterPacketAndSend(data, meta, client);
//console.log("meta: " + JSON.stringify(meta) + "\ndata: " + JSON.stringify(data))
}); });
newProxyClient.on("end", () => { newProxyClient.on("end", () => {
antiAntiAfkmsg(); antiAntiAfkmsg();
@ -254,26 +253,31 @@ function sendChunks() {
} }
function log(logmsg) { function log(logmsg) {
if (config.logging) fs.appendFile('../2smart2wait.log', DateTime.local().toLocaleString({ if (config.logging) {
fs.appendFile('../2smart2wait.log', DateTime.local().toLocaleString({
hour: '2-digit', hour: '2-digit',
minute: '2-digit', minute: '2-digit',
hour12: false hour12: false
}) + " " + logmsg + "\n", err => { }) + " " + logmsg + "\n", err => {
if (err) console.error(err) if (err) console.error(err)
}) })
console.log(logmsg);
}
} }
function reconnect() { function reconnect() {
doing = "reconnect" doing = "reconnect"
reconnectinterval = setInterval(function () { reconnectLoop();
}
function reconnectLoop() {
ping(config.minecraftserver.hostname, config.minecraftserver.port) ping(config.minecraftserver.hostname, config.minecraftserver.port)
.then((response) => { .then((response) => {
if (doing === "reconnect") startQueuing(); startQueuing();
clearInterval(reconnectinterval);
}) })
.catch((error) => { .catch((error) => {
setTimeout(reconnectLoop, 3000);
}); });
}, 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.
@ -331,6 +335,8 @@ function userInput(cmd, DiscordOrigin, discordMsg) {
else console.log("Queue is starting up.") else console.log("Queue is starting up.")
break; break;
case "update": case "update":
switch (doing) {
case "queue":
if (DiscordOrigin) discordMsg.channel.send({ if (DiscordOrigin) discordMsg.channel.send({
embed: { embed: {
color: 3447003, color: 3447003,
@ -358,27 +364,54 @@ 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 "timedStart":
let timerMsg = "Timer is set to " + starttimestring;
if (DiscordOrigin) sendDiscordMsg(discordMsg.channel, "Timer", timerMsg);
else console.log(timerMsg);
break;
case "reconnect":
let reconnectMsg = "2bt is currently offline. Trying to reconnect";
if (DiscordOrigin) sendDiscordMsg("Reconnecting", reconnectMsg);
else console.log(reconnectMsg);
break;
case "auth":
let authMsg = "Authentication";
if (DiscordOrigin) sendDiscordMsg(authMsg, authMsg);
else console.log(authMsg);
break;
case "calcTime":
let calcMsg = "Calculating the time, so you can paly at " + starttimestring
if (DiscordOrigin) sendDiscordMsg("calculating time", calcMsg);
console.log(calcMsg);
break;
}
break;
case "stop": case "stop":
switch (doing) { switch (doing) {
case "queue": case "queue":
stop(); stop();
stopMsg(DiscordOrigin, discordMsg.channel, "Queue"); if (DiscordOrigin) stopMsg(DiscordOrigin, discordMsg.channel, "Queue");
else console.log("The queue is stopped");
break; break;
case "timedStart": case "timedStart":
clearTimeout(timedStart); clearTimeout(timedStart);
stopMsg(DiscordOrigin, discordMsg.channel, "Timer"); if (DiscordOrigin) stopMsg(DiscordOrigin, discordMsg.channel, "Timer");
else console.log("The timer is stopped");
break; break;
case "reconnect": case "reconnect":
clearInterval(reconnectinterval); clearInterval(reconnectinterval);
stopMsg(DiscordOrigin, discordMsg.channel, "Reconnecting"); if (DiscordOrigin) stopMsg(DiscordOrigin, discordMsg.channel, "Reconnecting");
else console.log("Reconnecting is stoppd");
break; break;
case "auth": case "auth":
clearInterval(authInterval); clearInterval(authInterval);
stopMsg(DiscordOrigin, discordMsg.channel, "Authentication"); if (DiscordOrigin) stopMsg(DiscordOrigin, discordMsg.channel, "Authentication");
else console.log("Authentication is stopped");
break; break;
case "calcTime": case "calcTime":
clearInterval(calcInterval); clearInterval(calcInterval);
stopMsg(DiscordOrigin, discordMsg.channel, "Time calculation"); if (DiscordOrigin) stopMsg(DiscordOrigin, discordMsg.channel, "Time calculation");
else console.log("Time calculation is stopped");
break; break;
} }
break; break;
@ -396,6 +429,7 @@ function userInput(cmd, DiscordOrigin, discordMsg) {
let output = "The perfect time to start the will be calculated, so you play at " + starttimestring; let output = "The perfect time to start the will be calculated, so you play at " + starttimestring;
if (DiscordOrigin) sendDiscordMsg(discordMsg.channel, "time calculator", output); if (DiscordOrigin) sendDiscordMsg(discordMsg.channel, "time calculator", output);
else console.log(output); else console.log(output);
activity("You can play at " + starttimestring);
} else if (DiscordOrigin) discordMsg.channel.send("Error: Unknown command"); } else if (DiscordOrigin) discordMsg.channel.send("Error: Unknown command");
else console.error("Unknown command") else console.error("Unknown command")
} }