Initial implementation completion and refactor

This commit is contained in:
seavor 2026-04-11 21:18:10 -05:00
parent e977f123ce
commit f0bf865646
76 changed files with 897 additions and 890 deletions

View file

@ -4,8 +4,8 @@ import { leaveGame } from './leaveGame';
export const GameEvents: ProtobufEvents = {
'.Event_Join.ext': () => joinGame,
'.Event_Leave.ext': () => leaveGame,
'.Event_Join.ext': joinGame,
'.Event_Leave.ext': leaveGame,
'.Event_GameClosed.ext': () => console.log('Event_GameClosed.ext'),
'.Event_GameHostChanged.ext': () => console.log('Event_GameHostChanged.ext'),
'.Event_Kicked.ext': () => console.log('Event_Kicked.ext'),

View file

@ -1,5 +1,5 @@
import { StatusEnum } from 'types';
import webClient from '../../WebClient';
import { ProtoController } from '../../services/ProtoController';
import { updateStatus } from '../../commands/session';
import { ConnectionClosedData } from './interfaces';
@ -10,29 +10,30 @@ export function connectionClosed({ reason, reasonStr }: ConnectionClosedData): v
if (reasonStr) {
message = reasonStr;
} else {
const { CloseReason } = ProtoController.root.Event_ConnectionClosed;
switch (reason) {
case webClient.protobuf.controller.Event_ConnectionClosed.CloseReason.USER_LIMIT_REACHED:
case CloseReason.USER_LIMIT_REACHED:
message = 'The server has reached its maximum user capacity';
break;
case webClient.protobuf.controller.Event_ConnectionClosed.CloseReason.TOO_MANY_CONNECTIONS:
case CloseReason.TOO_MANY_CONNECTIONS:
message = 'There are too many concurrent connections from your address';
break;
case webClient.protobuf.controller.Event_ConnectionClosed.CloseReason.BANNED:
case CloseReason.BANNED:
message = 'You are banned';
break;
case webClient.protobuf.controller.Event_ConnectionClosed.CloseReason.DEMOTED:
case CloseReason.DEMOTED:
message = 'You were demoted';
break;
case webClient.protobuf.controller.Event_ConnectionClosed.CloseReason.SERVER_SHUTDOWN:
case CloseReason.SERVER_SHUTDOWN:
message = 'Scheduled server shutdown';
break;
case webClient.protobuf.controller.Event_ConnectionClosed.CloseReason.USERNAMEINVALID:
case CloseReason.USERNAMEINVALID:
message = 'Invalid username';
break;
case webClient.protobuf.controller.Event_ConnectionClosed.CloseReason.LOGGEDINELSEWERE:
case CloseReason.LOGGEDINELSEWERE:
message = 'You have been logged out due to logging in at another location';
break;
case webClient.protobuf.controller.Event_ConnectionClosed.CloseReason.OTHER:
case CloseReason.OTHER:
default:
message = 'Unknown reason';
break;

View file

@ -3,8 +3,9 @@ import { addToList } from './addToList';
import { connectionClosed } from './connectionClosed';
import { listRooms } from './listRooms';
import { notifyUser } from './notifyUser';
import { playerPropertiesChanged } from '../common/playerPropertiesChanged';
import { removeFromList } from './removeFromList';
import { replayAdded } from './replayAdded';
import { serverCompleteList } from './serverCompleteList';
import { serverIdentification } from './serverIdentification';
import { serverMessage } from './serverMessage';
import { serverShutdown } from './serverShutdown';
@ -20,8 +21,8 @@ export const SessionEvents: ProtobufEvents = {
'.Event_ListRooms.ext': listRooms,
'.Event_NotifyUser.ext': notifyUser,
'.Event_RemoveFromList.ext': removeFromList,
'.Event_ReplayAdded.ext': () => console.log('Event_ReplayAdded'),
'.Event_ServerCompleteList.ext': () => console.log('Event_ServerCompleteList'),
'.Event_ReplayAdded.ext': replayAdded,
'.Event_ServerCompleteList.ext': serverCompleteList,
'.Event_ServerIdentification.ext': serverIdentification,
'.Event_ServerMessage.ext': serverMessage,
'.Event_ServerShutdown.ext': serverShutdown,

View file

@ -1,4 +1,4 @@
import { Game, NotificationType, Room, User } from 'types';
import { Game, NotificationType, ReplayMatch, Room, User } from 'types';
export interface AddToListData {
listName: string;
@ -13,6 +13,8 @@ export interface ConnectionClosedData {
export interface GameJoinedData {
gameInfo: Game;
gameTypes: any[];
hostId: number;
playerId: number;
spectator: boolean;
resuming: boolean;
@ -76,3 +78,13 @@ export interface UserMessageData {
receiverName: string;
message: string;
}
export interface ReplayAddedData {
matchInfo: ReplayMatch;
}
export interface ServerCompleteListData {
serverId: number;
userList: User[];
roomList: Room[];
}

View file

@ -0,0 +1,6 @@
import { SessionPersistence } from '../../persistence';
import { ReplayAddedData } from './interfaces';
export function replayAdded({ matchInfo }: ReplayAddedData): void {
SessionPersistence.replayAdded(matchInfo);
}

View file

@ -0,0 +1,7 @@
import { RoomPersistence, SessionPersistence } from '../../persistence';
import { ServerCompleteListData } from './interfaces';
export function serverCompleteList({ userList, roomList }: ServerCompleteListData): void {
SessionPersistence.updateUsers(userList);
RoomPersistence.updateRooms(roomList);
}

View file

@ -1,4 +1,4 @@
import { StatusEnum, WebSocketConnectReason } from 'types';
import { StatusEnum, WebSocketConnectOptions, WebSocketConnectReason } from 'types';
import webClient from '../../WebClient';
import {
@ -24,48 +24,48 @@ export function serverIdentification(info: ServerIdentificationData): void {
return;
}
const getPasswordSalt = passwordSaltSupported(serverOptions, webClient);
const { options } = webClient;
const getPasswordSalt = passwordSaltSupported(serverOptions);
const connectOptions = { ...webClient.options };
switch (options.reason) {
switch (connectOptions.reason) {
case WebSocketConnectReason.LOGIN:
updateStatus(StatusEnum.LOGGING_IN, 'Logging In...');
if (getPasswordSalt) {
requestPasswordSalt(options);
requestPasswordSalt(connectOptions);
} else {
login(options);
login(connectOptions);
}
break;
case WebSocketConnectReason.REGISTER:
const passwordSalt = getPasswordSalt ? generateSalt() : null;
register(options, passwordSalt);
register(connectOptions, passwordSalt);
break;
case WebSocketConnectReason.ACTIVATE_ACCOUNT:
if (getPasswordSalt) {
requestPasswordSalt(options);
requestPasswordSalt(connectOptions);
} else {
activate(options);
activate(connectOptions);
}
break;
case WebSocketConnectReason.PASSWORD_RESET_REQUEST:
forgotPasswordRequest(options);
forgotPasswordRequest(connectOptions);
break;
case WebSocketConnectReason.PASSWORD_RESET_CHALLENGE:
forgotPasswordChallenge(options);
forgotPasswordChallenge(connectOptions);
break;
case WebSocketConnectReason.PASSWORD_RESET:
if (getPasswordSalt) {
requestPasswordSalt(options);
requestPasswordSalt(connectOptions);
} else {
forgotPasswordReset(options);
forgotPasswordReset(connectOptions);
}
break;
default:
updateStatus(StatusEnum.DISCONNECTED, 'Unknown Connection Reason: ' + options.reason);
updateStatus(StatusEnum.DISCONNECTED, 'Unknown Connection Reason: ' + connectOptions.reason);
disconnect();
break;
}
webClient.options = {};
webClient.options = {} as WebSocketConnectOptions;
SessionPersistence.updateInfo(serverName, serverVersion);
}