import { HelloPacket } from '../../net'; /** * @module core/models */ /** * An object representing the state of a client which is connecting to the game server. */ export interface GameState { /** * The build version of this state. */ buildVersion: string; /** * The character id of this state. */ characterId: number; /** * The game ID of this state. */ gameId: number; /** * The key of this state. */ key: number[]; /** * The key time of this state. */ keyTime: number; } /** * Checks whether the `gameState` object has the right * properties to implement the `GameState` interface. * @param gameState The object to check. */ export function isGameState(gameState: any): gameState is GameState { return gameState && typeof gameState.buildVersion === 'string' && typeof gameState.characterId === 'number' && typeof gameState.gameId === 'number'; } /** * Creates a `HelloPacket` with the `gameState` * properties copied to the hello packet. * @param gameState The game state to use. */ export function createHello(gameState: GameState): HelloPacket { const helloPacket: HelloPacket = new HelloPacket(); helloPacket.buildVersion = gameState.buildVersion; helloPacket.gameId = gameState.gameId; helloPacket.keyTime = gameState.keyTime; helloPacket.key = gameState.key; helloPacket.gameNet = 'rotmg'; helloPacket.playPlatform = 'rotmg'; return helloPacket; }