forked from hippoz/brainlet
add forceful refresh of user clients to push updates and erase bad messages from the dom
This commit is contained in:
parent
670d7d49b4
commit
d0025b4221
3 changed files with 89 additions and 4 deletions
|
@ -18,9 +18,63 @@ class GatewayServer {
|
|||
minPoints: 0
|
||||
});
|
||||
this.eventSetup();
|
||||
|
||||
this._commandPrefix = '/';
|
||||
}
|
||||
}
|
||||
|
||||
GatewayServer.prototype._sendSystemMessage = function(socket, message, category) {
|
||||
const messageObject = {
|
||||
author: {
|
||||
username: '__SYSTEM',
|
||||
_id: '5fc69864f15a7c5e504c9a1f'
|
||||
},
|
||||
category: {
|
||||
title: category.title,
|
||||
_id: category._id
|
||||
},
|
||||
content: message,
|
||||
_id: uuid.v4()
|
||||
};
|
||||
|
||||
socket.emit('message', messageObject);
|
||||
};
|
||||
|
||||
GatewayServer.prototype.notifyClientsOfUpdate = function(reason) {
|
||||
this._gateway.emit('refreshClient', { reason: reason || 'REFRESH' });
|
||||
};
|
||||
|
||||
GatewayServer.prototype._processCommand = function(socket, message) {
|
||||
const content = message.content;
|
||||
const fullCommandString = content.slice(this._commandPrefix.length, content.length);
|
||||
const fullCommand = fullCommandString.split(' ');
|
||||
const command = fullCommand[0] || 'INVALID_COMMAND';
|
||||
const args = fullCommand.length - 1;
|
||||
|
||||
switch (command) {
|
||||
case 'INVALID_COMMAND': {
|
||||
this._sendSystemMessage(socket, 'Invalid command.', message.category);
|
||||
break;
|
||||
}
|
||||
case 'admin/fr': {
|
||||
if (args === 1) {
|
||||
if (socket.user.permissionLevel >= config.roleMap.ADMIN) {
|
||||
this._gateway.emit('refreshClient', { reason: fullCommand[1] || 'REFRESH' });
|
||||
} else {
|
||||
this._sendSystemMessage(socket, 'how about no', message.category);
|
||||
}
|
||||
} else {
|
||||
this._sendSystemMessage(socket, 'Invalid number of arguments.', message.category);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
this._sendSystemMessage(socket, 'That command does not exist.', message.category);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GatewayServer.prototype.authDisconnect = function(socket, callback) {
|
||||
console.log('[E] [gateway] [handshake] User disconnected due to failed authentication');
|
||||
socket.isConnected = false;
|
||||
|
@ -74,7 +128,8 @@ GatewayServer.prototype.eventSetup = function() {
|
|||
socket.user = {
|
||||
username: data.username,
|
||||
_id: user._id,
|
||||
token // Maybe not secure
|
||||
token, // Maybe not secure
|
||||
permissionLevel
|
||||
};
|
||||
console.log(`[*] [gateway] [handshake] User ${data.username} has successfully authenticated`);
|
||||
return callback();
|
||||
|
@ -123,6 +178,11 @@ GatewayServer.prototype.eventSetup = function() {
|
|||
_id: uuid.v4()
|
||||
};
|
||||
|
||||
if (messageObject.content.startsWith(this._commandPrefix)) {
|
||||
this._processCommand(socket, messageObject);
|
||||
return;
|
||||
}
|
||||
|
||||
this._gateway.in(category._id).emit('message', messageObject);
|
||||
});
|
||||
|
||||
|
|
|
@ -177,10 +177,10 @@ const app = new Vue({
|
|||
},
|
||||
gateway: new GatewayConnection(),
|
||||
messages: {
|
||||
'X': [ { username: 'NONEXISTENT_TEST_ACCOUNT', content: 'TEST MSG' } ]
|
||||
'X': [ { username: '__SYSTEM', content: 'TEST MSG' } ]
|
||||
},
|
||||
userLists: {
|
||||
'X': [ { username: 'NONEXISTENT_TEST_ACCOUNT', _id: 'INVALID_ID' } ]
|
||||
'X': [ { username: '__SYSTEM', _id: 'INVALID_ID' } ]
|
||||
},
|
||||
message: {
|
||||
typed: ''
|
||||
|
@ -238,6 +238,22 @@ const app = new Vue({
|
|||
console.log('[*] [gateway] Client list update', e);
|
||||
this.processUserListUpdate(e);
|
||||
});
|
||||
this.gateway.socket.on('refreshClient', (e) => {
|
||||
console.log('[*] [gateway] Gateway requested refresh', e);
|
||||
if (e.reason === 'exit') {
|
||||
this.showApp = false;
|
||||
this.okNotification('The server has exited. Sit tight!');
|
||||
} else if (e.reason === 'upd') {
|
||||
this.showApp = false;
|
||||
this.okNotification('An update has just rolled out! To ensure everything runs smoothly, you need to refresh the page!');
|
||||
} else {
|
||||
this.showApp = false;
|
||||
this.okNotification('Sorry, but something happened and a refresh is required to keep using the app!');
|
||||
}
|
||||
this.snackbarEditButton('Refresh', () => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
},
|
||||
processMessage: async function(messageObject) {
|
||||
if (!this.messages[messageObject.category._id]) this.$set(this.messages, messageObject.category._id, []);
|
||||
|
|
11
index.js
11
index.js
|
@ -27,12 +27,21 @@ app.use(express.static('app'));
|
|||
|
||||
app.get('/', authenticateEndpoint((req, res, user) => {
|
||||
res.redirect('/app.html');
|
||||
}, `/auth.html`));
|
||||
}, '/auth.html'));
|
||||
|
||||
app.get('/admin', (req, res) => {
|
||||
res.send('Keanu chungus wholesome 100 reddit moment 😀i beat up a kid that said minecraft bad 😂and my doggo bit him so i gave him snaccos😉 and we watched pewdiepie together while in elon musk’s cyber truck 😳talking about how superior reddit memers are : “haha emojis bad” 😲i said and keanu reeves came outta nowhere and said “this is wholesome 100, updoot this wholesome boy” 😗so i got alot of updoots and edit: thanks for the gold kind stranger😣. but the kind stranger revealed himself to be baby yoda eating chiccy nuggies😨 and drinking choccy milk😎 so we went to the cinema to see our (communism funny) favorite movies avengers endgame😆 but then thor played fortnite and fortnite bad😡, so then i said “reality is often dissappointing” and then baby yoda replied r/unexpectedthanos and i replied by r/expectedthanos😖 for balance and then danny devito came to pick us up from the cinema😩 and all the insta normies and gay mods stood watching😵 ,as we,superior redditors went home with danny devito to suck on his magnum dong😫 but i said no homo and started sucking,not like those gay mods😮,then the next morning we woke up to MrBeast telling us to plant 69420 million trees😌, me, baby yoda and danny said nice, and then on our way to plant 69420 million trees😊 (nice) we saw a kid doing a tiktok so keanu reeves appeared and said “we have a kid to burn” and i replied “you’re breathtaking”😄 so i said “i need a weapon” and baby yoda gave me an RPG so i blew the kid (DESTRUCTION 100)😎 and posted it on r/memes and r/dankmemes and r/pewdiepiesubmissions and got 1000000000 updoots😘,i’m sure pewds will give me a big pp, then we shat on emoji users😂😂 and started dreaming about girls that will never like me😢 and posted a lie on r/teenagers about how i got a GF after my doggo died by the hands of fortnite players😳 so i exploited his death for updoots😜, but i watched the sunset with the wholesome gang😁 (keanu,danny,Mrbeast, pewds, spongebob,stefan karl , bob ross, steve irwin, baby yoda and other artists that reddit exploits them) [Everyone liked that] WHOLESOME 100 REDDIT 100🤡');
|
||||
});
|
||||
|
||||
const onServerClosing = (evt) => {
|
||||
gateway.notifyClientsOfUpdate('exit');
|
||||
process.exit();
|
||||
};
|
||||
|
||||
['exit', 'SIGINT', 'SIGUSR1', 'SIGUSR2', 'uncaughtException', 'SIGTERM'].forEach((eventType) => {
|
||||
process.on(eventType, onServerClosing.bind(null, eventType));
|
||||
})
|
||||
|
||||
httpServer.listen(config.ports.mainServerPort, () => {
|
||||
console.log(`[*] [server] Main server is listening on port ${config.ports.mainServerPort}`);
|
||||
});
|
Loading…
Reference in a new issue