fix(policies/gateway): comply with policies.allowGatewayConnection

This commit is contained in:
hippoz 2021-09-15 15:54:08 +03:00
parent 3cd7fcb5f9
commit 0f3154745e
No known key found for this signature in database
GPG key ID: 7C52899193467641

View file

@ -90,6 +90,10 @@ class GatewayHandler {
}
handleConnection(ws) {
if (!policies.allowGatewayConnection) {
return ws.close(wsCloseCodes.SERVER_DENIED_CONNECTION[0], wsCloseCodes.SERVER_DENIED_CONNECTION[1]);
}
const session = new GatewaySession();
session.setWebsocketClient(ws);
session.send("HELLO", { pingInterval: clientFacingPingInterval });
@ -146,7 +150,7 @@ class GatewayHandler {
// Gateway message handlers
async handle_YOO({ data }, session) {
if (session.authenticated) return {error: wsCloseCodes.PAYLOAD_ERROR};
if (session.authenticated || !Array.isArray(data.roles) || data.roles.length > 10 || data.roles.) return {error: wsCloseCodes.PAYLOAD_ERROR};
try {
if (!(await session.authenticateWithToken(data.token))) return {error: wsCloseCodes.AUTHENTICATION_ERROR};
} catch(e) {