From a0e89e9b6090ee12f36aa1adcffd89397fb39168 Mon Sep 17 00:00:00 2001 From: knotteye Date: Sat, 21 Dec 2019 16:16:50 -0600 Subject: [PATCH] Add proper kicking and banning for users with multiple accounts. --- src/http.ts | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/http.ts b/src/http.ts index 695f40a..a3f774e 100644 --- a/src/http.ts +++ b/src/http.ts @@ -95,7 +95,11 @@ async function chgNick(socket, nick, f?: boolean) { for(let i=1;i item !== socket.id)); + else store.rm(socket.nick); + } + if(f) store.set(nick, [].concat(store.get(nick), socket.id).filter(item => item !== undefined)); store.set(nick, socket.id); socket.nick = nick; } @@ -336,12 +340,6 @@ async function initSite(openReg) { async function initChat() { //set a cookie to request same nick - //apply same nick if the request comes from the same ip - //structure of entry in store should be: - // knotteye: { - // ip: "127.0.0.1", - // id: ["aklsjdnaksj", "asjdnaksjnd", "aksjdnkajs"] - //} //socket.io chat logic io.on('connection', async (socket) => { @@ -387,6 +385,11 @@ async function initChat() { for(let i=1;i item !== socket.id)) + if(store.get(socket.nick) !== []) + return; + } store.rm(socket.nick); }); socket.on('NICK', async (data) => { @@ -419,6 +422,11 @@ async function initChat() { //find client with data.nick let id: string = store.get(data.nick); if(id){ + if(Array.isArray(id)) { + for(let i=0;i