Add ESLint & Run it against the system (#4470)

This commit is contained in:
Zach H 2021-11-13 14:49:06 -05:00 committed by ZeldaZach
parent 43eee6b32e
commit f789e02096
106 changed files with 1235 additions and 20242 deletions

View file

@ -1,156 +1,156 @@
const ProtoFiles = [
"admin_commands.proto",
"card_attributes.proto",
"color.proto",
"command_attach_card.proto",
"command_change_zone_properties.proto",
"command_concede.proto",
"command_create_arrow.proto",
"command_create_counter.proto",
"command_create_token.proto",
"command_deck_del.proto",
"command_deck_del_dir.proto",
"command_deck_download.proto",
"command_deck_list.proto",
"command_deck_new_dir.proto",
"command_deck_select.proto",
"command_deck_upload.proto",
"command_del_counter.proto",
"command_delete_arrow.proto",
"command_draw_cards.proto",
"command_dump_zone.proto",
"command_flip_card.proto",
"command_game_say.proto",
"command_inc_card_counter.proto",
"command_inc_counter.proto",
"command_kick_from_game.proto",
"command_leave_game.proto",
"command_move_card.proto",
"command_mulligan.proto",
"command_next_turn.proto",
"command_ready_start.proto",
"command_replay_delete_match.proto",
"command_replay_download.proto",
"command_replay_list.proto",
"command_replay_modify_match.proto",
"command_reveal_cards.proto",
"command_roll_die.proto",
"command_set_active_phase.proto",
"command_set_card_attr.proto",
"command_set_card_counter.proto",
"command_set_counter.proto",
"command_set_sideboard_lock.proto",
"command_set_sideboard_plan.proto",
"command_shuffle.proto",
"command_undo_draw.proto",
"commands.proto",
"context_concede.proto",
"context_connection_state_changed.proto",
"context_deck_select.proto",
"context_move_card.proto",
"context_mulligan.proto",
"context_ping_changed.proto",
"context_ready_start.proto",
"context_set_sideboard_lock.proto",
"context_undo_draw.proto",
"event_add_to_list.proto",
"event_attach_card.proto",
"event_change_zone_properties.proto",
"event_connection_closed.proto",
"event_create_arrow.proto",
"event_create_counter.proto",
"event_create_token.proto",
"event_del_counter.proto",
"event_delete_arrow.proto",
"event_destroy_card.proto",
"event_draw_cards.proto",
"event_dump_zone.proto",
"event_flip_card.proto",
"event_game_closed.proto",
"event_game_host_changed.proto",
"event_game_joined.proto",
"event_game_say.proto",
"event_game_state_changed.proto",
"event_join.proto",
"event_join_room.proto",
"event_kicked.proto",
"event_leave.proto",
"event_leave_room.proto",
"event_list_games.proto",
"event_list_rooms.proto",
"event_move_card.proto",
"event_notify_user.proto",
"event_player_properties_changed.proto",
"event_remove_from_list.proto",
"event_replay_added.proto",
"event_reveal_cards.proto",
"event_roll_die.proto",
"event_room_say.proto",
"event_server_complete_list.proto",
"event_server_identification.proto",
"event_server_message.proto",
"event_server_shutdown.proto",
"event_set_active_phase.proto",
"event_set_active_player.proto",
"event_set_card_attr.proto",
"event_set_card_counter.proto",
"event_set_counter.proto",
"event_shuffle.proto",
"event_user_joined.proto",
"event_user_left.proto",
"event_user_message.proto",
"game_commands.proto",
"game_event.proto",
"game_event_container.proto",
"game_event_context.proto",
"game_replay.proto",
"isl_message.proto",
"moderator_commands.proto",
"move_card_to_zone.proto",
"response.proto",
"response_activate.proto",
"response_adjust_mod.proto",
"response_ban_history.proto",
"response_deck_download.proto",
"response_deck_list.proto",
"response_deck_upload.proto",
"response_dump_zone.proto",
"response_forgotpasswordrequest.proto",
"response_get_games_of_user.proto",
"response_get_user_info.proto",
"response_join_room.proto",
"response_list_users.proto",
"response_login.proto",
"response_password_salt.proto",
"response_register.proto",
"response_replay_download.proto",
"response_replay_list.proto",
"response_viewlog_history.proto",
"response_warn_history.proto",
"response_warn_list.proto",
"room_commands.proto",
"room_event.proto",
"server_message.proto",
"serverinfo_arrow.proto",
"serverinfo_ban.proto",
"serverinfo_card.proto",
"serverinfo_cardcounter.proto",
"serverinfo_chat_message.proto",
"serverinfo_counter.proto",
"serverinfo_deckstorage.proto",
"serverinfo_game.proto",
"serverinfo_gametype.proto",
"serverinfo_player.proto",
"serverinfo_playerping.proto",
"serverinfo_playerproperties.proto",
"serverinfo_replay.proto",
"serverinfo_replay_match.proto",
"serverinfo_room.proto",
"serverinfo_user.proto",
"serverinfo_warning.proto",
"serverinfo_zone.proto",
"session_commands.proto",
"session_event.proto",
'admin_commands.proto',
'card_attributes.proto',
'color.proto',
'command_attach_card.proto',
'command_change_zone_properties.proto',
'command_concede.proto',
'command_create_arrow.proto',
'command_create_counter.proto',
'command_create_token.proto',
'command_deck_del.proto',
'command_deck_del_dir.proto',
'command_deck_download.proto',
'command_deck_list.proto',
'command_deck_new_dir.proto',
'command_deck_select.proto',
'command_deck_upload.proto',
'command_del_counter.proto',
'command_delete_arrow.proto',
'command_draw_cards.proto',
'command_dump_zone.proto',
'command_flip_card.proto',
'command_game_say.proto',
'command_inc_card_counter.proto',
'command_inc_counter.proto',
'command_kick_from_game.proto',
'command_leave_game.proto',
'command_move_card.proto',
'command_mulligan.proto',
'command_next_turn.proto',
'command_ready_start.proto',
'command_replay_delete_match.proto',
'command_replay_download.proto',
'command_replay_list.proto',
'command_replay_modify_match.proto',
'command_reveal_cards.proto',
'command_roll_die.proto',
'command_set_active_phase.proto',
'command_set_card_attr.proto',
'command_set_card_counter.proto',
'command_set_counter.proto',
'command_set_sideboard_lock.proto',
'command_set_sideboard_plan.proto',
'command_shuffle.proto',
'command_undo_draw.proto',
'commands.proto',
'context_concede.proto',
'context_connection_state_changed.proto',
'context_deck_select.proto',
'context_move_card.proto',
'context_mulligan.proto',
'context_ping_changed.proto',
'context_ready_start.proto',
'context_set_sideboard_lock.proto',
'context_undo_draw.proto',
'event_add_to_list.proto',
'event_attach_card.proto',
'event_change_zone_properties.proto',
'event_connection_closed.proto',
'event_create_arrow.proto',
'event_create_counter.proto',
'event_create_token.proto',
'event_del_counter.proto',
'event_delete_arrow.proto',
'event_destroy_card.proto',
'event_draw_cards.proto',
'event_dump_zone.proto',
'event_flip_card.proto',
'event_game_closed.proto',
'event_game_host_changed.proto',
'event_game_joined.proto',
'event_game_say.proto',
'event_game_state_changed.proto',
'event_join.proto',
'event_join_room.proto',
'event_kicked.proto',
'event_leave.proto',
'event_leave_room.proto',
'event_list_games.proto',
'event_list_rooms.proto',
'event_move_card.proto',
'event_notify_user.proto',
'event_player_properties_changed.proto',
'event_remove_from_list.proto',
'event_replay_added.proto',
'event_reveal_cards.proto',
'event_roll_die.proto',
'event_room_say.proto',
'event_server_complete_list.proto',
'event_server_identification.proto',
'event_server_message.proto',
'event_server_shutdown.proto',
'event_set_active_phase.proto',
'event_set_active_player.proto',
'event_set_card_attr.proto',
'event_set_card_counter.proto',
'event_set_counter.proto',
'event_shuffle.proto',
'event_user_joined.proto',
'event_user_left.proto',
'event_user_message.proto',
'game_commands.proto',
'game_event.proto',
'game_event_container.proto',
'game_event_context.proto',
'game_replay.proto',
'isl_message.proto',
'moderator_commands.proto',
'move_card_to_zone.proto',
'response.proto',
'response_activate.proto',
'response_adjust_mod.proto',
'response_ban_history.proto',
'response_deck_download.proto',
'response_deck_list.proto',
'response_deck_upload.proto',
'response_dump_zone.proto',
'response_forgotpasswordrequest.proto',
'response_get_games_of_user.proto',
'response_get_user_info.proto',
'response_join_room.proto',
'response_list_users.proto',
'response_login.proto',
'response_password_salt.proto',
'response_register.proto',
'response_replay_download.proto',
'response_replay_list.proto',
'response_viewlog_history.proto',
'response_warn_history.proto',
'response_warn_list.proto',
'room_commands.proto',
'room_event.proto',
'server_message.proto',
'serverinfo_arrow.proto',
'serverinfo_ban.proto',
'serverinfo_card.proto',
'serverinfo_cardcounter.proto',
'serverinfo_chat_message.proto',
'serverinfo_counter.proto',
'serverinfo_deckstorage.proto',
'serverinfo_game.proto',
'serverinfo_gametype.proto',
'serverinfo_player.proto',
'serverinfo_playerping.proto',
'serverinfo_playerproperties.proto',
'serverinfo_replay.proto',
'serverinfo_replay_match.proto',
'serverinfo_room.proto',
'serverinfo_user.proto',
'serverinfo_warning.proto',
'serverinfo_zone.proto',
'session_commands.proto',
'session_event.proto',
];
export default ProtoFiles;

View file

@ -1,9 +1,9 @@
import {ServerStatus, StatusEnum} from "types";
import { ServerStatus, StatusEnum } from 'types';
import {ProtobufService} from './services/ProtobufService';
import {WebSocketOptions, WebSocketService} from "./services/WebSocketService";
import { ProtobufService } from './services/ProtobufService';
import { WebSocketOptions, WebSocketService } from './services/WebSocketService';
import {RoomPersistence, SessionPersistence} from './persistence';
import { RoomPersistence, SessionPersistence } from './persistence';
export class WebClient {
public socket = new WebSocketService(this);
@ -11,30 +11,30 @@ export class WebClient {
public protocolVersion = 14;
public clientConfig = {
"clientver" : "webclient-1.0 (2019-10-31)",
"clientfeatures" : [
"client_id",
"client_ver",
"feature_set",
"room_chat_history",
"client_warnings",
'clientver': 'webclient-1.0 (2019-10-31)',
'clientfeatures': [
'client_id',
'client_ver',
'feature_set',
'room_chat_history',
'client_warnings',
/* unimplemented features */
"forgot_password",
"idle_client",
"mod_log_lookup",
"user_ban_history",
'forgot_password',
'idle_client',
'mod_log_lookup',
'user_ban_history',
// satisfy server reqs for POC
"websocket",
"2.7.0_min_version",
"2.8.0_min_version"
'websocket',
'2.7.0_min_version',
'2.8.0_min_version'
]
};
public options: WebSocketOptions = {
host: "",
port: "",
user: "",
pass: "",
host: '',
port: '',
user: '',
pass: '',
clientid: null,
reason: null,
autojoinrooms: true,
@ -54,7 +54,7 @@ export class WebClient {
}
public connect(options: WebSocketOptions) {
this.options = {...this.options, ...options};
this.options = { ...this.options, ...options };
this.socket.connect(this.options);
}

View file

@ -68,4 +68,4 @@ describe('RoomCommands', () => {
expect(RoomPersistence.leaveRoom).toHaveBeenCalledWith(roomId);
});
});
});
});

View file

@ -1,28 +1,30 @@
import { RoomPersistence } from '../persistence';
import webClient from "../WebClient";
import webClient from '../WebClient';
export class RoomCommands {
static roomSay(roomId: number, message: string): void {
const trimmed = message.trim();
if (!trimmed) return;
var CmdRoomSay = webClient.protobuf.controller.Command_RoomSay.create({
"message" : trimmed
if (!trimmed) {
return;
}
const CmdRoomSay = webClient.protobuf.controller.Command_RoomSay.create({
'message': trimmed
});
var rc = webClient.protobuf.controller.RoomCommand.create({
".Command_RoomSay.ext" : CmdRoomSay
const rc = webClient.protobuf.controller.RoomCommand.create({
'.Command_RoomSay.ext': CmdRoomSay
});
webClient.protobuf.sendRoomCommand(roomId, rc);
}
static leaveRoom(roomId: number): void {
var CmdLeaveRoom = webClient.protobuf.controller.Command_LeaveRoom.create();
const CmdLeaveRoom = webClient.protobuf.controller.Command_LeaveRoom.create();
var rc = webClient.protobuf.controller.RoomCommand.create({
".Command_LeaveRoom.ext" : CmdLeaveRoom
const rc = webClient.protobuf.controller.RoomCommand.create({
'.Command_LeaveRoom.ext': CmdLeaveRoom
});
webClient.protobuf.sendRoomCommand(roomId, rc, (raw) => {

View file

@ -1,11 +1,11 @@
import {StatusEnum} from 'types';
import { StatusEnum } from 'types';
import {SessionCommands} from './SessionCommands';
import { SessionCommands } from './SessionCommands';
import {RoomPersistence, SessionPersistence} from '../persistence';
import { RoomPersistence, SessionPersistence } from '../persistence';
import webClient from '../WebClient';
import {WebSocketConnectReason} from "../services/WebSocketService";
import {AccountActivationParams, ServerRegisterParams} from "../../store";
import { WebSocketConnectReason } from '../services/WebSocketService';
import { AccountActivationParams, ServerRegisterParams } from '../../store';
describe('SessionCommands', () => {
const roomId = 1;
@ -42,7 +42,7 @@ describe('SessionCommands', () => {
expect(SessionCommands.updateStatus).toHaveBeenCalled();
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.CONNECTING, expect.any(String));
expect(webClient.connect).toHaveBeenCalled();
expect(webClient.connect).toHaveBeenCalledWith({ ...options, reason: WebSocketConnectReason.LOGIN });
});
@ -75,7 +75,7 @@ describe('SessionCommands', () => {
expect(SessionCommands.updateStatus).toHaveBeenCalled();
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTING, 'Disconnecting...');
expect(webClient.disconnect).toHaveBeenCalled();
});
});
@ -226,7 +226,10 @@ describe('SessionCommands', () => {
SessionCommands.login();
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, 'Login failed: account not activated');
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(
StatusEnum.DISCONNECTED,
'Login failed: account not activated'
);
});
it('all other responseCodes should update status', () => {
@ -236,7 +239,10 @@ describe('SessionCommands', () => {
SessionCommands.login();
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, `Login failed: unknown error: ${response.responseCode}`);
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(
StatusEnum.DISCONNECTED,
`Login failed: unknown error: ${response.responseCode}`
);
});
});
});
@ -283,17 +289,17 @@ describe('SessionCommands', () => {
response = {
responseCode: RespRegistrationAccepted,
[respKey]: {
reasonStr: "",
reasonStr: '',
endTime: 10000000
}
};
webClient.protobuf.controller.Response = { ResponseCode: { RespRegistrationAccepted }};
webClient.protobuf.controller.Response = { ResponseCode: { RespRegistrationAccepted } };
sendSessionCommandSpy.and.callFake((_, callback) => callback(response));
})
it("should login user if registration accepted without email verification", () => {
it('should login user if registration accepted without email verification', () => {
spyOn(SessionCommands, 'login');
spyOn(SessionPersistence, 'accountAwaitingActivation');
@ -303,10 +309,11 @@ describe('SessionCommands', () => {
expect(SessionPersistence.accountAwaitingActivation).not.toHaveBeenCalled();
});
it("should prompt user if registration accepted with email verification", () => {
it('should prompt user if registration accepted with email verification', () => {
const RespRegistrationAcceptedNeedsActivation = 'RespRegistrationAcceptedNeedsActivation';
response.responseCode = RespRegistrationAcceptedNeedsActivation;
webClient.protobuf.controller.Response.ResponseCode.RespRegistrationAcceptedNeedsActivation = RespRegistrationAcceptedNeedsActivation;
webClient.protobuf.controller.Response.ResponseCode.RespRegistrationAcceptedNeedsActivation =
RespRegistrationAcceptedNeedsActivation;
spyOn(SessionCommands, 'login');
spyOn(SessionPersistence, 'accountAwaitingActivation');
@ -317,7 +324,7 @@ describe('SessionCommands', () => {
expect(SessionPersistence.accountAwaitingActivation).toHaveBeenCalled();
});
it("should disconnect user if registration fails due to registration being disabled", () => {
it('should disconnect user if registration fails due to registration being disabled', () => {
const RespRegistrationDisabled = 'RespRegistrationDisabled';
response.responseCode = RespRegistrationDisabled;
webClient.protobuf.controller.Response.ResponseCode.RespRegistrationDisabled = RespRegistrationDisabled;
@ -368,7 +375,7 @@ describe('SessionCommands', () => {
}
};
webClient.protobuf.controller.Response = { ResponseCode: { RespActivationAccepted }};
webClient.protobuf.controller.Response = { ResponseCode: { RespActivationAccepted } };
sendSessionCommandSpy.and.callFake((_, callback) => callback(response));
spyOn(SessionCommands, 'login');
@ -497,7 +504,10 @@ describe('SessionCommands', () => {
SessionCommands.joinRoom(roomId);
expect(console.error).toHaveBeenCalledWith(RespContextError, 'The server thinks you are in the room but Cockatrice is unable to display it. Try restarting Cockatrice.');
expect(console.error).toHaveBeenCalledWith(
RespContextError,
'The server thinks you are in the room but Cockatrice is unable to display it. Try restarting Cockatrice.'
);
});
it('RespUserLevelTooLow should console error', () => {
@ -572,7 +582,7 @@ describe('SessionCommands', () => {
});
it('should call protobuf controller methods and sendCommand', () => {
const addToList = { list: 'list', userName: 'userName'};
const addToList = { list: 'list', userName: 'userName' };
SessionCommands.addToList(addToList.list, addToList.userName);
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalled();
@ -588,7 +598,7 @@ describe('SessionCommands', () => {
});
it('should call protobuf controller methods and sendCommand', () => {
const removeFromList = { list: 'list', userName: 'userName'};
const removeFromList = { list: 'list', userName: 'userName' };
SessionCommands.removeFromList(removeFromList.list, removeFromList.userName);
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalled();

View file

@ -1,9 +1,9 @@
import {StatusEnum} from 'types';
import { StatusEnum } from 'types';
import {RoomPersistence, SessionPersistence} from '../persistence';
import { RoomPersistence, SessionPersistence } from '../persistence';
import webClient from '../WebClient';
import {guid, hashPassword} from '../utils';
import {WebSocketConnectReason, WebSocketOptions} from "../services/WebSocketService";
import { guid, hashPassword } from '../utils';
import { WebSocketConnectReason, WebSocketOptions } from '../services/WebSocketService';
import {
AccountActivationParams,
ForgotPasswordChallengeParams,
@ -11,8 +11,8 @@ import {
ForgotPasswordResetParams,
RequestPasswordSaltParams,
ServerRegisterParams
} from "../../store";
import NormalizeService from "../utils/NormalizeService";
} from '../../store';
import NormalizeService from '../utils/NormalizeService';
export class SessionCommands {
static connect(options: WebSocketOptions, reason: WebSocketConnectReason): void {
@ -53,7 +53,7 @@ export class SessionCommands {
const CmdLogin = webClient.protobuf.controller.Command_Login.create(loginConfig);
const command = webClient.protobuf.controller.SessionCommand.create({
'.Command_Login.ext' : CmdLogin
'.Command_Login.ext': CmdLogin
});
webClient.protobuf.sendSessionCommand(command, raw => {
@ -73,7 +73,7 @@ export class SessionCommands {
return;
}
switch(raw.responseCode) {
switch (raw.responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespClientUpdateRequired:
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Login failed: missing features');
break;
@ -127,23 +127,23 @@ export class SessionCommands {
const CmdRequestPasswordSalt = webClient.protobuf.controller.Command_RequestPasswordSalt.create(registerConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({
".Command_RequestPasswordSalt.ext" : CmdRequestPasswordSalt
'.Command_RequestPasswordSalt.ext': CmdRequestPasswordSalt
});
webClient.protobuf.sendSessionCommand(sc, raw => {
switch (raw.responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
const passwordSalt = raw[".Response_PasswordSalt.ext"].passwordSalt;
const passwordSalt = raw['.Response_PasswordSalt.ext'].passwordSalt;
SessionCommands.login(passwordSalt);
break;
case webClient.protobuf.controller.Response.ResponseCode.RespRegistrationRequired:
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, "Login failed: incorrect username or password");
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Login failed: incorrect username or password');
SessionCommands.disconnect();
break;
default:
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, "Login failed: Unknown Reason");
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Login failed: Unknown Reason');
SessionCommands.disconnect();
break;
}
@ -166,7 +166,7 @@ export class SessionCommands {
const CmdRegister = webClient.protobuf.controller.Command_Register.create(registerConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_Register.ext' : CmdRegister
'.Command_Register.ext': CmdRegister
});
webClient.protobuf.sendSessionCommand(sc, raw => {
@ -203,12 +203,12 @@ export class SessionCommands {
error = NormalizeService.normalizeBannedUserError(raw.reasonStr, raw.endTime);
break;
case webClient.protobuf.controller.Response.ResponseCode.RespUsernameInvalid:
console.error("ResponseCode.RespUsernameInvalid", raw.reasonStr);
console.error('ResponseCode.RespUsernameInvalid', raw.reasonStr);
error = 'Invalid username';
break;
case webClient.protobuf.controller.Response.ResponseCode.RespRegistrationFailed:
default:
console.error("ResponseCode Type", raw.responseCode);
console.error('ResponseCode Type', raw.responseCode);
error = 'Registration failed due to a server issue';
break;
}
@ -238,13 +238,13 @@ export class SessionCommands {
});
webClient.protobuf.sendSessionCommand(sc, raw => {
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespActivationAccepted) {
SessionCommands.login();
} else {
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Account Activation Failed');
SessionCommands.disconnect();
SessionPersistence.accountActivationFailed();
}
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespActivationAccepted) {
SessionCommands.login();
} else {
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Account Activation Failed');
SessionCommands.disconnect();
SessionPersistence.accountActivationFailed();
}
});
}
@ -260,12 +260,12 @@ export class SessionCommands {
const CmdForgotPasswordRequest = webClient.protobuf.controller.Command_ForgotPasswordRequest.create(forgotPasswordConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_ForgotPasswordRequest.ext' : CmdForgotPasswordRequest
'.Command_ForgotPasswordRequest.ext': CmdForgotPasswordRequest
});
webClient.protobuf.sendSessionCommand(sc, raw => {
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) {
const resp = raw[".Response_ForgotPasswordRequest.ext"];
const resp = raw['.Response_ForgotPasswordRequest.ext'];
if (resp.challengeEmail) {
SessionPersistence.resetPasswordChallenge();
@ -293,7 +293,7 @@ export class SessionCommands {
const CmdForgotPasswordChallenge = webClient.protobuf.controller.Command_ForgotPasswordChallenge.create(forgotPasswordChallengeConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_ForgotPasswordChallenge.ext' : CmdForgotPasswordChallenge
'.Command_ForgotPasswordChallenge.ext': CmdForgotPasswordChallenge
});
webClient.protobuf.sendSessionCommand(sc, raw => {
@ -321,7 +321,7 @@ export class SessionCommands {
const CmdForgotPasswordReset = webClient.protobuf.controller.Command_ForgotPasswordReset.create(forgotPasswordResetConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_ForgotPasswordReset.ext' : CmdForgotPasswordReset
'.Command_ForgotPasswordReset.ext': CmdForgotPasswordReset
});
webClient.protobuf.sendSessionCommand(sc, raw => {
@ -339,7 +339,7 @@ export class SessionCommands {
const CmdListUsers = webClient.protobuf.controller.Command_ListUsers.create();
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_ListUsers.ext' : CmdListUsers
'.Command_ListUsers.ext': CmdListUsers
});
webClient.protobuf.sendSessionCommand(sc, raw => {
@ -363,7 +363,7 @@ export class SessionCommands {
const CmdListRooms = webClient.protobuf.controller.Command_ListRooms.create();
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_ListRooms.ext' : CmdListRooms
'.Command_ListRooms.ext': CmdListRooms
});
webClient.protobuf.sendSessionCommand(sc);
@ -373,7 +373,7 @@ export class SessionCommands {
const CmdJoinRoom = webClient.protobuf.controller.Command_JoinRoom.create({ roomId });
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_JoinRoom.ext' : CmdJoinRoom
'.Command_JoinRoom.ext': CmdJoinRoom
});
webClient.protobuf.sendSessionCommand(sc, (raw) => {
@ -381,7 +381,7 @@ export class SessionCommands {
let error;
switch(responseCode) {
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
const { roomInfo } = raw['.Response_JoinRoom.ext'];
@ -400,7 +400,7 @@ export class SessionCommands {
error = 'Failed to join the room due to an unknown error.';
break;
}
if (error) {
console.error(responseCode, error);
}
@ -427,7 +427,7 @@ export class SessionCommands {
const CmdAddToList = webClient.protobuf.controller.Command_AddToList.create({ list, userName });
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_AddToList.ext' : CmdAddToList
'.Command_AddToList.ext': CmdAddToList
});
webClient.protobuf.sendSessionCommand(sc, ({ responseCode }) => {
@ -439,7 +439,7 @@ export class SessionCommands {
const CmdRemoveFromList = webClient.protobuf.controller.Command_RemoveFromList.create({ list, userName });
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_RemoveFromList.ext' : CmdRemoveFromList
'.Command_RemoveFromList.ext': CmdRemoveFromList
});
webClient.protobuf.sendSessionCommand(sc, ({ responseCode }) => {
@ -451,7 +451,7 @@ export class SessionCommands {
const CmdViewLogHistory = webClient.protobuf.controller.Command_ViewLogHistory.create(filters);
const sc = webClient.protobuf.controller.ModeratorCommand.create({
'.Command_ViewLogHistory.ext' : CmdViewLogHistory
'.Command_ViewLogHistory.ext': CmdViewLogHistory
});
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
@ -459,7 +459,7 @@ export class SessionCommands {
let error;
switch(responseCode) {
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
const { logMessage } = raw['.Response_ViewLogHistory.ext'];
SessionPersistence.viewLogs(logMessage)
@ -468,7 +468,7 @@ export class SessionCommands {
error = 'Failed to retrieve log history.';
break;
}
if (error) {
console.error(responseCode, error);
}

View file

@ -1,2 +1,2 @@
export { RoomCommands } from "./RoomCommands";
export { SessionCommands } from "./SessionCommands";
export { RoomCommands } from './RoomCommands';
export { SessionCommands } from './SessionCommands';

View file

@ -61,4 +61,4 @@ describe('RoomEvents', () => {
data
);
});
});
});

View file

@ -3,10 +3,10 @@ import { RoomPersistence } from '../persistence/RoomPersistence';
import { ProtobufEvents } from '../services/ProtobufService';
export const RoomEvents: ProtobufEvents = {
".Event_JoinRoom.ext": joinRoom,
".Event_LeaveRoom.ext": leaveRoom,
".Event_ListGames.ext": listGames,
".Event_RoomSay.ext": roomSay,
'.Event_JoinRoom.ext': joinRoom,
'.Event_LeaveRoom.ext': leaveRoom,
'.Event_ListGames.ext': listGames,
'.Event_RoomSay.ext': roomSay,
};
function joinRoom({ userInfo }: JoinRoomData, { roomEvent }: RoomEvent) {

View file

@ -1,4 +1,4 @@
import {StatusEnum} from "types";
import { StatusEnum } from 'types';
import {
AddToListData,
@ -12,10 +12,10 @@ import {
UserLeftData,
} from './SessionEvents';
import {SessionCommands} from "../commands";
import {RoomPersistence, SessionPersistence} from '../persistence';
import { SessionCommands } from '../commands';
import { RoomPersistence, SessionPersistence } from '../persistence';
import webClient from '../WebClient';
import {WebSocketConnectReason} from "../services/WebSocketService";
import { WebSocketConnectReason } from '../services/WebSocketService';
describe('SessionEvents', () => {
const roomId = 1;
@ -340,7 +340,10 @@ describe('SessionEvents', () => {
event(data);
expect(SessionCommands.disconnect).toHaveBeenCalled();
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, `Protocol version mismatch: ${data.protocolVersion}`);
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(
StatusEnum.DISCONNECTED,
`Protocol version mismatch: ${data.protocolVersion}`
);
expect(SessionCommands.login).not.toHaveBeenCalled();
});
});
@ -361,7 +364,7 @@ describe('SessionEvents', () => {
describe('.Event_UserJoined.ext', () => {
it('should call SessionPersistence.userJoined', () => {
spyOn(SessionPersistence, 'userJoined');
const data: UserJoinedData = { userInfo: {} as any };
const data: UserJoinedData = { userInfo: {} as any };
SessionEvents['.Event_UserJoined.ext'](data);
@ -374,7 +377,7 @@ describe('SessionEvents', () => {
describe('.Event_UserLeft.ext', () => {
it('should call SessionPersistence.userLeft', () => {
spyOn(SessionPersistence, 'userLeft');
const data: UserLeftData = { name: '' };
const data: UserLeftData = { name: '' };
SessionEvents['.Event_UserLeft.ext'](data);

View file

@ -1,10 +1,10 @@
import {Room, StatusEnum, User} from 'types';
import { Room, StatusEnum, User } from 'types';
import {SessionCommands} from '../commands';
import {RoomPersistence, SessionPersistence} from '../persistence';
import {ProtobufEvents} from '../services/ProtobufService';
import { SessionCommands } from '../commands';
import { RoomPersistence, SessionPersistence } from '../persistence';
import { ProtobufEvents } from '../services/ProtobufService';
import webClient from '../WebClient';
import {WebSocketConnectReason} from "../services/WebSocketService";
import { WebSocketConnectReason } from '../services/WebSocketService';
export const SessionEvents: ProtobufEvents = {
'.Event_AddToList.ext': addToList,
@ -21,7 +21,7 @@ export const SessionEvents: ProtobufEvents = {
'.Event_UserMessage.ext': userMessage,
}
function addToList({ listName, userInfo}: AddToListData) {
function addToList({ listName, userInfo }: AddToListData) {
switch (listName) {
case 'buddy': {
SessionPersistence.addToBuddyList(userInfo);
@ -44,7 +44,7 @@ function connectionClosed({ reason, reasonStr }: ConnectionClosedData) {
if (reasonStr) {
message = reasonStr;
} else {
switch(reason) {
switch (reason) {
case webClient.protobuf.controller.Event_ConnectionClosed.CloseReason.USER_LIMIT_REACHED:
message = 'The server has reached its maximum user capacity';
break;
@ -147,7 +147,7 @@ function serverIdentification(info: ServerIdentificationData) {
SessionCommands.resetPassword();
break;
default:
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, "Unknown Connection Reason: " + webClient.options.reason);
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Unknown Connection Reason: ' + webClient.options.reason);
SessionCommands.disconnect();
break;
}

View file

@ -1,6 +1,6 @@
import { store, RoomsDispatch, RoomsSelectors } from "store";
import { store, RoomsDispatch, RoomsSelectors } from 'store';
import { Game, Message, Room, User } from 'types';
import NormalizeService from "../utils/NormalizeService";
import NormalizeService from '../utils/NormalizeService';
export class RoomPersistence {
static clearStore() {

View file

@ -1,8 +1,8 @@
import { ServerDispatch } from "store";
import { Log, StatusEnum, User } from "types";
import { ServerDispatch } from 'store';
import { Log, StatusEnum, User } from 'types';
import { sanitizeHtml } from "websocket/utils";
import NormalizeService from "../utils/NormalizeService";
import { sanitizeHtml } from 'websocket/utils';
import NormalizeService from '../utils/NormalizeService';
export class SessionPersistence {
static clearStore() {
@ -74,27 +74,27 @@ export class SessionPersistence {
}
static accountAwaitingActivation() {
console.log("Open Modal for Activation Code input");
console.log('Open Modal for Activation Code input');
}
static accountActivationFailed() {
console.log("Account activation failed, show an action here");
console.log('Account activation failed, show an action here');
}
static resetPasswordChallenge() {
console.log("Open Modal asking for Email address associated with account");
console.log('Open Modal asking for Email address associated with account');
}
static resetPassword() {
console.log("Open Modal asking for reset token & new password");
console.log('Open Modal asking for reset token & new password');
}
static resetPasswordSuccess() {
console.log("User password successfully changed Alert!");
console.log('User password successfully changed Alert!');
}
static resetPasswordFailed() {
console.log("Open Alert telling user their password request failed for some reason");
console.log('Open Alert telling user their password request failed for some reason');
}
}

View file

@ -1,2 +1,2 @@
export { RoomPersistence } from "./RoomPersistence";
export { SessionPersistence } from "./SessionPersistence";
export { RoomPersistence } from './RoomPersistence';
export { SessionPersistence } from './SessionPersistence';

View file

@ -1,5 +1,5 @@
import { KeepAliveService } from './KeepAliveService';
import { WebSocketService } from "./WebSocketService";
import { WebSocketService } from './WebSocketService';
import webClient from '../WebClient';

View file

@ -1,6 +1,6 @@
import { Subject } from "rxjs";
import { Subject } from 'rxjs';
import { WebSocketService } from "./WebSocketService";
import { WebSocketService } from './WebSocketService';
export class KeepAliveService {
private socket: WebSocketService;

View file

@ -1,7 +1,7 @@
import protobuf from "protobufjs";
import protobuf from 'protobufjs';
import ProtoFiles from "../ProtoFiles";
import { WebClient } from "../WebClient";
import ProtoFiles from '../ProtoFiles';
import { WebClient } from '../WebClient';
import { RoomEvents, SessionEvents } from '../events';
@ -31,8 +31,8 @@ export class ProtobufService {
public sendRoomCommand(roomId: number, roomCmd: number, callback?: Function) {
const cmd = this.controller.CommandContainer.create({
"roomId" : roomId,
"roomCommand" : [ roomCmd ]
'roomId': roomId,
'roomCommand': [roomCmd]
});
this.sendCommand(cmd, raw => callback && callback(raw));
@ -40,7 +40,7 @@ export class ProtobufService {
public sendSessionCommand(sesCmd: number, callback?: Function) {
const cmd = this.controller.CommandContainer.create({
"sessionCommand" : [ sesCmd ]
'sessionCommand': [sesCmd]
});
this.sendCommand(cmd, (raw) => callback && callback(raw));
@ -48,7 +48,7 @@ export class ProtobufService {
public sendModeratorCommand(modCmd: number, callback?: Function) {
const cmd = this.controller.CommandContainer.create({
"moderatorCommand" : [ modCmd ]
'moderatorCommand': [modCmd]
});
this.sendCommand(cmd, (raw) => callback && callback(raw));
@ -57,7 +57,7 @@ export class ProtobufService {
public sendCommand(cmd: number, callback: Function) {
this.cmdId++;
cmd["cmdId"] = this.cmdId;
cmd['cmdId'] = this.cmdId;
this.pendingCommands[this.cmdId] = callback;
if (this.webClient.socket.checkReadyState(WebSocket.OPEN)) {
@ -67,7 +67,7 @@ export class ProtobufService {
public sendKeepAliveCommand(pingReceived: Function) {
const command = this.controller.SessionCommand.create({
".Command_Ping.ext" : this.controller.Command_Ping.create()
'.Command_Ping.ext': this.controller.Command_Ping.create()
});
this.sendSessionCommand(command, pingReceived);
@ -90,12 +90,12 @@ export class ProtobufService {
this.processSessionEvent(msg.sessionEvent, msg);
break;
case this.controller.ServerMessage.MessageType.GAME_EVENT_CONTAINER:
// @TODO
// @TODO
break;
}
}
} catch (err) {
console.error("Processing failed:", err);
console.error('Processing failed:', err);
}
}

View file

@ -1,8 +1,8 @@
import { Subject } from 'rxjs';
import { ServerStatus, StatusEnum } from "types";
import { ServerStatus, StatusEnum } from 'types';
import { KeepAliveService } from "./KeepAliveService";
import { KeepAliveService } from './KeepAliveService';
import { WebClient } from '../WebClient';
export interface WebSocketOptions {
@ -42,7 +42,7 @@ export class WebSocketService {
this.keepAliveService = new KeepAliveService(this);
this.keepAliveService.disconnected$.subscribe(() => {
this.disconnect();
this.updateStatus(StatusEnum.DISCONNECTED, "Connection timeout");
this.updateStatus(StatusEnum.DISCONNECTED, 'Connection timeout');
});
}
@ -73,15 +73,15 @@ export class WebSocketService {
public updateStatus(status: StatusEnum, description: string): void {
this.status = status;
this.statusChange$.next({status, description});
this.statusChange$.next({ status, description });
}
private createWebSocket(url: string): WebSocket {
const socket = new WebSocket(url);
socket.binaryType = "arraybuffer"; // We are talking binary
socket.binaryType = 'arraybuffer';
socket.onopen = () => {
this.updateStatus(StatusEnum.CONNECTED, "Connected");
this.updateStatus(StatusEnum.CONNECTED, 'Connected');
this.keepAliveService.startPingLoop(this.keepalive, (pingReceived: Function) => {
this.webClient.keepAlive(pingReceived);
@ -91,14 +91,14 @@ export class WebSocketService {
socket.onclose = () => {
// dont overwrite failure messages
if (this.status !== StatusEnum.DISCONNECTED) {
this.updateStatus(StatusEnum.DISCONNECTED, "Connection Closed");
this.updateStatus(StatusEnum.DISCONNECTED, 'Connection Closed');
}
this.keepAliveService.endPingLoop();
};
socket.onerror = () => {
this.updateStatus(StatusEnum.DISCONNECTED, "Connection Failed");
this.updateStatus(StatusEnum.DISCONNECTED, 'Connection Failed');
};
socket.onmessage = (event: MessageEvent) => {

View file

@ -20,11 +20,11 @@ export default class NormalizeService {
static normalizeGameObject(game: Game, gametypeMap: GametypeMap): void {
const { gameTypes, description } = game;
const hasType = gameTypes && gameTypes.length;
game.gameType = hasType ? gametypeMap[gameTypes[0]] : "";
game.gameType = hasType ? gametypeMap[gameTypes[0]] : '';
game.description = description || "";
game.description = description || '';
}
// Flatten logs[] into object mapped by targetType (room, game, chat)
static normalizeLogs(logs: Log[]): LogGroups {
return logs.reduce((obj, log) => {

View file

@ -4,5 +4,5 @@ function s4(): string {
}
export function guid(): string {
return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}

View file

@ -1,3 +1,3 @@
export * from "./guid.util";
export * from "./sanitizeHtml.util";
export * from "./passwordHasher";
export * from './guid.util';
export * from './sanitizeHtml.util';
export * from './passwordHasher';

View file

@ -5,22 +5,22 @@ const HASH_ROUNDS = 1_000;
const SALT_LENGTH = 16;
export const hashPassword = (salt: string, password: string): string => {
let hashedPassword = salt + password;
for (let i = 0; i < HASH_ROUNDS; i++) {
// WHY DO WE DO IT THIS WAY?
hashedPassword = sha512(hashedPassword);
}
let hashedPassword = salt + password;
for (let i = 0; i < HASH_ROUNDS; i++) {
// WHY DO WE DO IT THIS WAY?
hashedPassword = sha512(hashedPassword);
}
return salt + Base64.stringify(hashedPassword);
return salt + Base64.stringify(hashedPassword);
};
export const generateSalt = (): string => {
const characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
const characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
let salt = "";
for (let i = 0; i < SALT_LENGTH; i++) {
salt += characters.charAt(Math.floor(Math.random() * characters.length));
}
let salt = '';
for (let i = 0; i < SALT_LENGTH; i++) {
salt += characters.charAt(Math.floor(Math.random() * characters.length));
}
return salt;
}
return salt;
}

View file

@ -1,11 +1,11 @@
import $ from "jquery";
import $ from 'jquery';
export function sanitizeHtml(msg: string): string {
const $div = $("<div>").html(msg);
const $div = $('<div>').html(msg);
const whitelist = {
tags: "br,a,img,center,b,font",
attrs: ["href","color"],
href: ["http://","https://","ftp://","//"]
tags: 'br,a,img,center,b,font',
attrs: ['href', 'color'],
href: ['http://', 'https://', 'ftp://', '//']
};
// remove all tags, attributes, and href protocols except some
@ -17,35 +17,36 @@ export function sanitizeHtml(msg: string): string {
}
function enforceTagWhitelist($el: JQuery<HTMLElement>, tags: string): void {
$el.find("*").not(tags).each(function() {
$el.find('*').not(tags).each(() => {
$(this).replaceWith(this.innerHTML);
});
}
function enforceAttrWhitelist($el: JQuery<HTMLElement>, attrs: string[]): void {
$el.find("*").each(function() {
var attributes = this.attributes;
var i = attributes.length;
while( i-- ) {
var attr = attributes[i];
if( $.inArray(attr.name,attrs) === -1 )
$el.find('*').each(() => {
const attributes = this.attributes;
let i = attributes.length;
while (i--) {
const attr = attributes[i];
if ($.inArray(attr.name, attrs) === -1) {
this.removeAttributeNode(attr);
}
}
});
}
function enforceHrefWhitelist($el: JQuery<HTMLElement>, hrefs: string[]): void {
$el.find("[href]").each(function() {
$el.find('[href]').each(() => {
const $_el = $(this);
const attributeValue = $_el.attr("href");
const attributeValue = $_el.attr('href');
for (let protocol in hrefs) {
if (attributeValue.indexOf(hrefs[protocol]) === 0) {
$_el.attr("target", "_blank");
return;
}
if (attributeValue.indexOf(hrefs[protocol]) === 0) {
$_el.attr('target', '_blank');
return;
}
}
$_el.removeAttr("href");
$_el.removeAttr('href');
});
}
}