Losing my mind over here

This commit is contained in:
bingus_violet 2024-04-20 13:18:01 -05:00
parent 32c6532a4f
commit de69048ebe
2 changed files with 3 additions and 58 deletions

View file

@ -56,28 +56,9 @@ server.on('request', app)
wsServer.on("connection", function connection(socket) { wsServer.on("connection", function connection(socket) {
console.log("BALLS") console.log("BALLS")
socket.on('message', function message(data) { socket.send("FUCK")
data = JSON.parse(data)
if (data.op == 3) {
for (let index = 0; index < sockets.length; index++) {
const socketData = sockets[index];
if (socketData.socket == socket) {
sockets[index].lastPing = Date.now()
}
}
socket.send(`{"op": 3}`)
}
})
socket.send(JSON.stringify(lanyardData))
socket.send(`{ "op": 1 }`)
sockets.push({ socket, lastPing: Date.now() })
}) })
process.on('uncaughtException', (err, origin) => { process.on('uncaughtException', (err, origin) => {
fs.writeSync( fs.writeSync(
process.stderr.fd, process.stderr.fd,

View file

@ -63,45 +63,9 @@ var lastPong = Date.now()
function socketeer() { function socketeer() {
var sock = new WebSocket('wss://beta.violets-purgatory.dev') var sock = new WebSocket('wss://beta.violets-purgatory.dev')
sock.onerror = (error) => { sock.onmessage = (event) => {
console.log(error) console.log(event.data)
} }
sock.onclose = () => {
console.log("Connection Closed. Attempting Reconnect in 30 seconds.")
setTimeout(() => {
socketeer()
}, 3000);
}
function ping(dur) {
sock.send(JSON.stringify({
op: 3
}))
setTimeout(() => {
ping(dur)
if (Date.now() - lastPong > 120000) {
sock.close()
console.log("Max duration since last pong exceeded- Closing socket.")
}
}, dur);
}
sock.addEventListener("message", async (res) => {
var data = JSON.parse(res.data)
if (data.op == 1) {
console.log("Connected to Discord Websocket!")
ping(30000)
lastPong = Date.now()
} else if (data.op == 3) {
lastPong = Date.now()
}
var discStatusHTML = await (await fetch("/discHTML")).text();
var activityDiv = document.querySelector("#activityHTML")
activityDiv.innerHTML = discStatusHTML
})
} }
socketeer() socketeer()