mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Webatrice: fix login bugs (#4557)
* fix login after failed connection attempts, limit connection attempt time * fix register hashed password and salt * add feature detection and Unsupported Browser screen * nit Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
This commit is contained in:
parent
81d031ca0f
commit
bb16ae09ef
17 changed files with 104 additions and 18 deletions
|
|
@ -141,11 +141,6 @@ export class SessionCommands {
|
|||
const passwordSalt = raw['.Response_PasswordSalt.ext']?.passwordSalt;
|
||||
|
||||
switch (webClient.options.reason) {
|
||||
case WebSocketConnectReason.REGISTER: {
|
||||
SessionCommands.register(passwordSalt);
|
||||
break;
|
||||
}
|
||||
|
||||
case WebSocketConnectReason.ACTIVATE_ACCOUNT: {
|
||||
SessionCommands.activateAccount(passwordSalt);
|
||||
break;
|
||||
|
|
@ -174,11 +169,6 @@ export class SessionCommands {
|
|||
}
|
||||
|
||||
switch (webClient.options.reason) {
|
||||
case WebSocketConnectReason.REGISTER: {
|
||||
SessionPersistence.registrationFailed('Failed to retrieve password salt');
|
||||
break;
|
||||
}
|
||||
|
||||
case WebSocketConnectReason.ACTIVATE_ACCOUNT: {
|
||||
SessionPersistence.accountActivationFailed();
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { Room, StatusEnum, User, WebSocketConnectReason } from 'types';
|
|||
import { SessionCommands } from '../commands';
|
||||
import { RoomPersistence, SessionPersistence } from '../persistence';
|
||||
import { ProtobufEvents } from '../services/ProtobufService';
|
||||
import { passwordSaltSupported } from '../utils';
|
||||
import { generateSalt, passwordSaltSupported } from '../utils';
|
||||
import webClient from '../WebClient';
|
||||
|
||||
export const SessionEvents: ProtobufEvents = {
|
||||
|
|
@ -130,11 +130,8 @@ function serverIdentification(info: ServerIdentificationData) {
|
|||
}
|
||||
break;
|
||||
case WebSocketConnectReason.REGISTER:
|
||||
if (passwordSaltSupported(serverOptions, webClient)) {
|
||||
SessionCommands.requestPasswordSalt();
|
||||
} else {
|
||||
SessionCommands.register();
|
||||
}
|
||||
const passwordSalt = passwordSaltSupported(serverOptions, webClient) ? generateSalt() : null;
|
||||
SessionCommands.register(passwordSalt);
|
||||
break;
|
||||
case WebSocketConnectReason.ACTIVATE_ACCOUNT:
|
||||
if (passwordSaltSupported(serverOptions, webClient)) {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,10 @@ export class SessionPersistence {
|
|||
ServerDispatch.connectionClosed(reason);
|
||||
}
|
||||
|
||||
static connectionFailed() {
|
||||
ServerDispatch.connectionFailed();
|
||||
}
|
||||
|
||||
static updateBuddyList(buddyList) {
|
||||
ServerDispatch.updateBuddyList(buddyList);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { ServerStatus, StatusEnum, WebSocketConnectOptions } from 'types';
|
|||
|
||||
import { KeepAliveService } from './KeepAliveService';
|
||||
import { WebClient } from '../WebClient';
|
||||
import { SessionPersistence } from '../persistence';
|
||||
|
||||
export class WebSocketService {
|
||||
private socket: WebSocket;
|
||||
|
|
@ -60,7 +61,10 @@ export class WebSocketService {
|
|||
const socket = new WebSocket(url);
|
||||
socket.binaryType = 'arraybuffer';
|
||||
|
||||
const connectionTimer = setTimeout(() => socket.close(), this.keepalive);
|
||||
|
||||
socket.onopen = () => {
|
||||
clearTimeout(connectionTimer);
|
||||
this.updateStatus(StatusEnum.CONNECTED, 'Connected');
|
||||
|
||||
this.keepAliveService.startPingLoop(this.keepalive, (pingReceived: Function) => {
|
||||
|
|
@ -79,6 +83,7 @@ export class WebSocketService {
|
|||
|
||||
socket.onerror = () => {
|
||||
this.updateStatus(StatusEnum.DISCONNECTED, 'Connection Failed');
|
||||
SessionPersistence.connectionFailed();
|
||||
};
|
||||
|
||||
socket.onmessage = (event: MessageEvent) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue