mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-12 15:49:28 -08:00
Add some sessions (#5052)
* Add AccountEdit * Add PasswordChange * Cleanup * Add SessionService.accountImage * Add SessionService.message * Add SessionService.getUserInfo * Lint
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { SessionCommands } from 'websocket';
|
||||
import { common } from 'protobufjs';
|
||||
import IBytesValue = common.IBytesValue;
|
||||
|
||||
export default class SessionService {
|
||||
static addToBuddyList(userName: string) {
|
||||
@@ -16,4 +18,24 @@ export default class SessionService {
|
||||
static removeFromIgnoreList(userName: string) {
|
||||
SessionCommands.removeFromIgnoreList(userName);
|
||||
}
|
||||
|
||||
static changeAccountPassword(oldPassword: string, newPassword: string, hashedNewPassword?: string): void {
|
||||
SessionCommands.accountPassword(oldPassword, newPassword, hashedNewPassword);
|
||||
}
|
||||
|
||||
static changeAccountDetails(passwordCheck: string, realName?: string, email?: string, country?: string): void {
|
||||
SessionCommands.accountEdit(passwordCheck, realName, email, country);
|
||||
}
|
||||
|
||||
static changeAccountImage(image: IBytesValue): void {
|
||||
SessionCommands.accountImage(image);
|
||||
}
|
||||
|
||||
static sendDirectMessage(userName: string, message: string): void {
|
||||
SessionCommands.message(userName, message);
|
||||
}
|
||||
|
||||
static getUserInfo(userName: string): void {
|
||||
SessionCommands.getUserInfo(userName);
|
||||
}
|
||||
}
|
||||
|
||||
28
webclient/src/websocket/commands/session/accountEdit.ts
Normal file
28
webclient/src/websocket/commands/session/accountEdit.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import webClient from '../../WebClient';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function accountEdit(passwordCheck: string, realName?: string, email?: string, country?: string): void {
|
||||
const command = webClient.protobuf.controller.Command_AccountEdit.create({ passwordCheck, realName, email, country });
|
||||
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({
|
||||
'.Command_AccountEdit.ext': command
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.accountEditChanged(realName, email, country);
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespFunctionNotAllowed:
|
||||
console.log('Not allowed');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword:
|
||||
console.log('Wrong password');
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to update information');
|
||||
}
|
||||
});
|
||||
}
|
||||
30
webclient/src/websocket/commands/session/accountImage.ts
Normal file
30
webclient/src/websocket/commands/session/accountImage.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import webClient from '../../WebClient';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { common } from 'protobufjs';
|
||||
import IBytesValue = common.IBytesValue;
|
||||
|
||||
export function accountImage(image: IBytesValue): void {
|
||||
const command = webClient.protobuf.controller.Command_AccountImage.create({ image });
|
||||
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({
|
||||
'.Command_AccountImage.ext': command
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.accountImageChanged();
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespFunctionNotAllowed:
|
||||
console.log('Not allowed');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword:
|
||||
console.log('Wrong password');
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to update information');
|
||||
}
|
||||
});
|
||||
}
|
||||
22
webclient/src/websocket/commands/session/accountPassword.ts
Normal file
22
webclient/src/websocket/commands/session/accountPassword.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import webClient from '../../WebClient';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function accountPassword(oldPassword: string, newPassword: string, hashedNewPassword: string): void {
|
||||
const command = webClient.protobuf.controller.Command_AccountPassword.create({ oldPassword, newPassword, hashedNewPassword });
|
||||
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({
|
||||
'.Command_AccountPassword.ext': command
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.accountPasswordChange();
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to change password');
|
||||
}
|
||||
});
|
||||
}
|
||||
29
webclient/src/websocket/commands/session/getUserInfo.ts
Normal file
29
webclient/src/websocket/commands/session/getUserInfo.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import webClient from '../../WebClient';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function getUserInfo(userName: string): void {
|
||||
const command = webClient.protobuf.controller.Command_GetUserInfo.create({ userName });
|
||||
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({
|
||||
'.Command_GetUserInfo.ext': command
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
const { userInfo } = raw['.Response_GetUserInfo.ext'];
|
||||
SessionPersistence.getUserInfo(userInfo);
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespFunctionNotAllowed:
|
||||
console.log('Not allowed');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword:
|
||||
console.log('Wrong password');
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to update information');
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -13,3 +13,8 @@ export * from './resetPassword';
|
||||
export * from './resetPasswordChallenge'
|
||||
export * from './resetPasswordRequest';
|
||||
export * from './updateStatus';
|
||||
export * from './accountPassword';
|
||||
export * from './accountEdit';
|
||||
export * from './accountImage';
|
||||
export * from './message';
|
||||
export * from './getUserInfo';
|
||||
|
||||
34
webclient/src/websocket/commands/session/message.ts
Normal file
34
webclient/src/websocket/commands/session/message.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import webClient from '../../WebClient';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function message(userName: string, message: string): void {
|
||||
const command = webClient.protobuf.controller.Command_Message.create({ userName, message });
|
||||
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({
|
||||
'.Command_Message.ext': command
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.directMessageSent(userName, message);
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespNameNotFound:
|
||||
console.log('Name not found');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespInIgnoreList:
|
||||
console.log('On ignore list');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespChatFlood:
|
||||
console.log('Flooding chat');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword:
|
||||
console.log('Wrong password');
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to send direct message');
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -144,4 +144,24 @@ export class SessionPersistence {
|
||||
static resetPasswordFailed() {
|
||||
ServerDispatch.resetPasswordFailed();
|
||||
}
|
||||
|
||||
static accountPasswordChange(): void {
|
||||
console.log('accountPassword');
|
||||
}
|
||||
|
||||
static accountEditChanged(realName?: string, email?: string, country?: string): void {
|
||||
console.log('accountEditChange');
|
||||
}
|
||||
|
||||
static accountImageChanged(): void {
|
||||
console.log('accountImageChanged');
|
||||
}
|
||||
|
||||
static directMessageSent(userName: string, message: string): void {
|
||||
console.log('directMessageSent');
|
||||
}
|
||||
|
||||
static getUserInfo(userInfo: string) {
|
||||
console.log('getUserInfo');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user