Initial implementation completion and refactor (#6806)
Some checks failed
Build Desktop / Configure (push) Has been cancelled
Build Docker Image / amd64 & arm64 (push) Has been cancelled
Build Web / React (Node 16) (push) Has been cancelled
Build Web / React (Node lts/*) (push) Has been cancelled
Build Desktop / Debian 11 (push) Has been cancelled
Build Desktop / Debian 13 (push) Has been cancelled
Build Desktop / Debian 12 (push) Has been cancelled
Build Desktop / Fedora 43 (push) Has been cancelled
Build Desktop / Fedora 42 (push) Has been cancelled
Build Desktop / Servatrice_Debian 11 (push) Has been cancelled
Build Desktop / Ubuntu 24.04 (push) Has been cancelled
Build Desktop / Ubuntu 26.04 (push) Has been cancelled
Build Desktop / Ubuntu 22.04 (push) Has been cancelled
Build Desktop / Arch (push) Has been cancelled
Build Desktop / macOS 14 (push) Has been cancelled
Build Desktop / macOS 15 (push) Has been cancelled
Build Desktop / macOS 13 Intel (push) Has been cancelled
Build Desktop / macOS 15 Debug (push) Has been cancelled
Build Desktop / Windows 10 (push) Has been cancelled

This commit is contained in:
Jeremy Letto 2026-04-11 22:51:10 -05:00 committed by GitHub
parent 2e10b2f5d5
commit 8cc65b8967
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
76 changed files with 897 additions and 890 deletions

View file

@ -1,5 +1,7 @@
import { StatusEnum, WebSocketConnectOptions } from 'types';
import webClient from '../../WebClient';
import { BackendService } from '../../services/BackendService';
import { ProtoController } from '../../services/ProtoController';
import { hashPassword } from '../../utils';
import { SessionPersistence } from '../../persistence';
@ -25,13 +27,18 @@ export function login(options: WebSocketConnectOptions, passwordSalt?: string):
loginConfig.password = password;
}
const command = webClient.protobuf.controller.Command_Login.create(loginConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_Login.ext': command });
const { ResponseCode } = ProtoController.root.Response;
webClient.protobuf.sendSessionCommand(sc, raw => {
const resp = raw['.Response_Login.ext'];
const onLoginError = (message: string, extra?: () => void) => {
updateStatus(StatusEnum.DISCONNECTED, message);
extra?.();
SessionPersistence.loginFailed();
disconnect();
};
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) {
BackendService.sendSessionCommand('Command_Login', loginConfig, {
responseName: 'Response_Login',
onSuccess: (resp) => {
const { buddyList, ignoreList, userInfo } = resp;
SessionPersistence.updateBuddyList(buddyList);
@ -43,50 +50,30 @@ export function login(options: WebSocketConnectOptions, passwordSalt?: string):
listRooms();
updateStatus(StatusEnum.LOGGED_IN, 'Logged in.');
return;
}
switch (raw.responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespClientUpdateRequired:
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: missing features');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword:
case webClient.protobuf.controller.Response.ResponseCode.RespUsernameInvalid:
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: incorrect username or password');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespWouldOverwriteOldSession:
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: duplicated user session');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespUserIsBanned:
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: banned user');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespRegistrationRequired:
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: registration required');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespClientIdRequired:
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: missing client ID');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespContextError:
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: server error');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespAccountNotActivated:
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: account not activated');
SessionPersistence.accountAwaitingActivation(options);
break;
default:
updateStatus(StatusEnum.DISCONNECTED, `Login failed: unknown error: ${raw.responseCode}`);
}
SessionPersistence.loginFailed();
disconnect();
},
onResponseCode: {
[ResponseCode.RespClientUpdateRequired]: () =>
onLoginError('Login failed: missing features'),
[ResponseCode.RespWrongPassword]: () =>
onLoginError('Login failed: incorrect username or password'),
[ResponseCode.RespUsernameInvalid]: () =>
onLoginError('Login failed: incorrect username or password'),
[ResponseCode.RespWouldOverwriteOldSession]: () =>
onLoginError('Login failed: duplicated user session'),
[ResponseCode.RespUserIsBanned]: () =>
onLoginError('Login failed: banned user'),
[ResponseCode.RespRegistrationRequired]: () =>
onLoginError('Login failed: registration required'),
[ResponseCode.RespClientIdRequired]: () =>
onLoginError('Login failed: missing client ID'),
[ResponseCode.RespContextError]: () =>
onLoginError('Login failed: server error'),
[ResponseCode.RespAccountNotActivated]: () =>
onLoginError('Login failed: account not activated',
() => SessionPersistence.accountAwaitingActivation(options)
),
},
onError: (responseCode) =>
onLoginError(`Login failed: unknown error: ${responseCode}`),
});
}