Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
change to use socket.id
Browse files Browse the repository at this point in the history
  • Loading branch information
glacialcascade committed Jun 9, 2024
1 parent 13c0be3 commit ea0a60f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
20 changes: 9 additions & 11 deletions cookie-clicker/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const port = 3000;
const socketIo = require('socket.io');
const io = socketIo(http);

const { v4 } = require('uuid');

let sessions = {}
let errors = {}
Expand All @@ -20,9 +19,8 @@ app.get('/', (req, res) => {
})

io.on('connection', (socket) => {
let id = v4();
sessions[id] = 0
errors[id] = 0
sessions[socket.id] = 0
errors[socket.id] = 0

socket.on('disconnect', () => {
console.log('user disconnected');
Expand All @@ -33,33 +31,33 @@ io.on('connection', (socket) => {
});

socket.on('receivedError', (msg) => {
sessions[id] = errors[id]
socket.emit('recievedScore', JSON.stringify({"value":sessions[id]}));
sessions[socket.id] = errors[socket.id]
socket.emit('recievedScore', JSON.stringify({"value":sessions[socket.id]}));
});

socket.on('click', (msg) => {
let json = JSON.parse(msg)

if (sessions[id] > 1e20) {
if (sessions[socket.id] > 1e20) {
socket.emit('recievedScore', JSON.stringify({"value":"bcactf{H0w_Did_Y0u_Cl1ck_S0_M4ny_T1mes_123}"}));
return;
}

if (json.value != sessions[id]) {
if (json.value != sessions[socket.id]) {
socket.emit("error", "previous value does not match")
}

let oldValue = sessions[id]
let oldValue = sessions[socket.id]
let newValue = Math.floor(Math.random() * json.power) + 1 + oldValue

sessions[id] = newValue
sessions[socket.id] = newValue
socket.emit('recievedScore', JSON.stringify({"value":newValue}));

if (json.power > 10) {
socket.emit('error', JSON.stringify({"value":oldValue}));
}

errors[id] = oldValue;
errors[socket.id] = oldValue;
});
});

Expand Down
23 changes: 10 additions & 13 deletions cookie-clicker/server/provided.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const port = 3000;
const socketIo = require('socket.io');
const io = socketIo(http);

const { v4 } = require('uuid');

let sessions = {}
let errors = {}
Expand All @@ -20,9 +19,8 @@ app.get('/', (req, res) => {
})

io.on('connection', (socket) => {
let id = v4();
sessions[id] = 0
errors[id] = 0
sessions[socket.id] = 0
errors[socket.id] = 0

socket.on('disconnect', () => {
console.log('user disconnected');
Expand All @@ -33,34 +31,33 @@ io.on('connection', (socket) => {
});

socket.on('receivedError', (msg) => {
sessions[id] = errors[id]
socket.emit('recievedScore', JSON.stringify({"value":sessions[id]}));
sessions[socket.id] = errors[socket.id]
socket.emit('recievedScore', JSON.stringify({"value":sessions[socket.id]}));
});

socket.on('click', (msg) => {
let json = JSON.parse(msg)

if (sessions[id] > 1e20) {
console.log("TEST")
socket.emit('recievedScore', JSON.stringify({"value":"flag"}));
if (sessions[socket.id] > 1e20) {
socket.emit('recievedScore', JSON.stringify({"value":"FLAG"}));
return;
}

if (json.value != sessions[id]) {
if (json.value != sessions[socket.id]) {
socket.emit("error", "previous value does not match")
}

let oldValue = sessions[id]
let oldValue = sessions[socket.id]
let newValue = Math.floor(Math.random() * json.power) + 1 + oldValue

sessions[id] = newValue
sessions[socket.id] = newValue
socket.emit('recievedScore', JSON.stringify({"value":newValue}));

if (json.power > 10) {
socket.emit('error', JSON.stringify({"value":oldValue}));
}

errors[id] = oldValue;
errors[socket.id] = oldValue;
});
});

Expand Down

0 comments on commit ea0a60f

Please sign in to comment.