Skip to content

Commit

Permalink
Added chat log and chat support for client version 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterBoy344 committed Mar 2, 2023
1 parent be43ac7 commit 35ae824
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let warningTimer = warningTimerDefault
const wss = new WebSocket.Server({ port: 8080 })
let ws
let players = []
let chatlog = [];
let currentID = 1

fs.readdir('./tracks/', (err, files) => {
Expand Down Expand Up @@ -40,6 +41,7 @@ wss.on('connection', (socket, req) => {
return
}
ws.send(`{ "ID" : "${currentID}"}`)
ws.send(`{ "chat" : ${JSON.stringify(chatlog)} }`)
players.push({username : responseJSON.username, time : 999999, IP : req.socket.remoteAddress, ID : currentID})
currentID = currentID + 1
sendTrack(ws)
Expand Down Expand Up @@ -101,6 +103,10 @@ wss.on('connection', (socket, req) => {
})
updateLeaderboard()
}
if (Object.keys(responseJSON)[0] == 'message') {
chatlog.push(`${responseJSON.username}: ${responseJSON.message}`)
wss.broadcast(`{ "chat" : ${JSON.stringify(chatlog)} }`)
}
}
// Continue as before.
});
Expand Down

0 comments on commit 35ae824

Please sign in to comment.