fix serverside gateway error when no channels are present and improve default config

This commit is contained in:
hippoz 2021-08-13 21:56:10 +03:00
parent ee04d03bdb
commit ab878b6718
Signed by untrusted user who does not match committer: hippoz
GPG key ID: 7C52899193467641
2 changed files with 24 additions and 22 deletions

View file

@ -123,24 +123,26 @@ class GatewayServer extends EventEmitter {
let presence = {}; let presence = {};
const channel = channels[0]; const channel = channels[0];
this.inChannel(channel._id, (client) => { if (channel) {
presence[client.session.user._id] = { this.inChannel(channel._id, (client) => {
_id: client.session.user._id, presence[client.session.user._id] = {
username: client.session.user.username, _id: client.session.user._id,
status: 1, username: client.session.user.username,
status_text: "Online"
};
if (client.session.sessionId !== ws.session.sessionId) client.send(packet("EVENT_CHANNEL_MEMBERS", {
[ws.session.user._id]: {
_id: ws.session.user._id,
username: ws.session.user.username,
status: 1, status: 1,
status_text: "Online" status_text: "Online"
} };
})); if (client.session.sessionId !== ws.session.sessionId) client.send(packet("EVENT_CHANNEL_MEMBERS", {
}); [ws.session.user._id]: {
_id: ws.session.user._id,
username: ws.session.user.username,
status: 1,
status_text: "Online"
}
}));
});
ws.send(packet("EVENT_CHANNEL_MEMBERS", presence)); ws.send(packet("EVENT_CHANNEL_MEMBERS", presence));
}
console.log(`gateway: user ${user.username}: handshake complete`); console.log(`gateway: user ${user.username}: handshake complete`);
} catch (e) { } catch (e) {

View file

@ -2,20 +2,20 @@ module.exports = {
ports: { ports: {
mainServerPort: 3005, mainServerPort: 3005,
}, },
address: 'localhost', address: "localhost",
//restrictions: { //restrictions: {
// signup: { // signup: {
// specialCode: '' // specialCode: ''
// } // }
//}, //},
mongoUrl: 'mongodb://192.168.0.105:27017/app', mongoUrl: "mongodb://127.0.0.1:27017/app",
bcryptRounds: 10, bcryptRounds: 10,
roleMap: { roleMap: {
'BANNED': 0, "BANNED": 0,
'RESTRICTED': 1, "RESTRICTED": 1,
'USER': 2, "USER": 2,
'BOT': 3, "BOT": 3,
'ADMIN': 4 "ADMIN": 4
}, },
gatewayStillNotConnectedTimeoutMS: 15*1000 gatewayStillNotConnectedTimeoutMS: 15*1000
}; };