diff --git a/package.json b/package.json index f472470..f98013f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "satyr", - "version": "0.5.2", + "version": "0.5.3", "description": "A livestreaming server.", "license": "AGPL-3.0", "author": "knotteye", diff --git a/src/http.ts b/src/http.ts index 0944a02..f20cd44 100644 --- a/src/http.ts +++ b/src/http.ts @@ -13,6 +13,7 @@ import { readFileSync, writeFileSync } from "fs"; import { JWT, JWK } from "jose"; import { strict } from "assert"; import { parse } from "path"; +import { isBuffer } from "util"; const app = express(); const server = http.createServer(app); @@ -77,13 +78,13 @@ async function newNick(socket, skip?: boolean) { } } -async function chgNick(socket, nick) { +async function chgNick(socket, nick, f?: boolean) { let rooms = Object.keys(socket.rooms); for(let i=1;i { - res.cookie('Authorization', t); + res.cookie('Authorization', t, {maxAge: 604800000, httpOnly: true}); res.send('{"success":""}'); return; }); @@ -214,7 +215,7 @@ async function initAPI() { api.login(req.body.username, req.body.password).then((result) => { if(!result){ genToken(req.body.username).then((t) => { - res.cookie('Authorization', t); + res.cookie('Authorization', t, {maxAge: 604800000, httpOnly: true}); res.send('{"success":""}'); }) } @@ -348,6 +349,21 @@ async function initChat(ircconf: any) { } else socket.emit('ALERT', 'Room does not exist'); }); + socket.on('LIST', (data) => { + let str = ""; + let client; + io.in(data.room).clients((err, clients) => { + if(err) throw err; + if(clients === []) { + socket.emit('LIST', 'The room is empty.'); + return; + } + for(let i=0;i { socket.leave(data); if(ircconf.enable) irc.part(socket.nick, data); @@ -375,7 +391,7 @@ async function initChat(ircconf: any) { return false; } if(await db.validatePassword(data.nick, data.password)){ - chgNick(socket, data.nick); + chgNick(socket, data.nick, true); } else socket.emit('ALERT','Incorrect username or password'); } @@ -404,4 +420,4 @@ async function initChat(ircconf: any) { }); } -export { init }; \ No newline at end of file +export { init }; diff --git a/templates/chat.html b/templates/chat.html index 3395eb7..a8b30ef 100644 --- a/templates/chat.html +++ b/templates/chat.html @@ -33,6 +33,9 @@ else if(m.startsWith('/kick')){ socket.emit('KICK', {nick: m.split(' ')[1], room: room}); } + else if(m.startsWith('/list')){ + socket.emit('LIST', {room: room}); + } else socket.emit('MSG', {room: room, msg: m}); document.getElementById('m').value = ''; } @@ -52,6 +55,10 @@ document.getElementById('messages').innerHTML+='
  • '+data.nick+' has left the chat
  • '; window.scrollTo(0,document.body.scrollHeight); }); + socket.on('LIST', function(data){ + document.getElementById('messages').innerHTML+='
  • '+data+'
  • '; + window.scrollTo(0,document.body.scrollHeight); + }); function getUrlParameter(name) { name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');