Linting
This commit is contained in:
parent
5c63573ef1
commit
b148ca3708
@ -32,7 +32,6 @@ import {
|
||||
import {UserMovesMessage} from "../../../messages/generated/messages_pb";
|
||||
import Direction = PositionMessage.Direction;
|
||||
import {ProtobufUtils} from "../Model/Websocket/ProtobufUtils";
|
||||
import toPositionMessage = ProtobufUtils.toPositionMessage;
|
||||
|
||||
enum SocketIoEvent {
|
||||
CONNECTION = "connection",
|
||||
@ -284,6 +283,12 @@ export class IoSocketController {
|
||||
socket.on(SocketIoEvent.USER_POSITION, (message: unknown): void => {
|
||||
//console.log(SockerIoEvent.USER_POSITION, userMovesMessage);
|
||||
try {
|
||||
if (!(message instanceof Buffer)) {
|
||||
socket.emit(SocketIoEvent.MESSAGE_ERROR, {message: 'Invalid USER_POSITION message. Expecting binary buffer.'});
|
||||
console.warn('Invalid USER_POSITION message received (expecting binary buffer): ', message);
|
||||
return;
|
||||
}
|
||||
|
||||
const userMovesMessage = UserMovesMessage.deserializeBinary(new Uint8Array(message as ArrayBuffer));
|
||||
const userMoves = userMovesMessage.toObject();
|
||||
|
||||
@ -375,14 +380,19 @@ export class IoSocketController {
|
||||
});
|
||||
|
||||
// Let's send the user id to the user
|
||||
socket.on(SocketIoEvent.SET_PLAYER_DETAILS, (message: any, answerFn) => {
|
||||
console.log(SocketIoEvent.SET_PLAYER_DETAILS, message);
|
||||
socket.on(SocketIoEvent.SET_PLAYER_DETAILS, (message: unknown, answerFn) => {
|
||||
//console.log(SocketIoEvent.SET_PLAYER_DETAILS, message);
|
||||
if (!(message instanceof Buffer)) {
|
||||
socket.emit(SocketIoEvent.MESSAGE_ERROR, {message: 'Invalid SET_PLAYER_DETAILS message. Expecting binary buffer.'});
|
||||
console.warn('Invalid SET_PLAYER_DETAILS message received (expecting binary buffer): ', message);
|
||||
return;
|
||||
}
|
||||
const playerDetailsMessage = SetPlayerDetailsMessage.deserializeBinary(new Uint8Array(message));
|
||||
const playerDetails = {
|
||||
name: playerDetailsMessage.getName(),
|
||||
characterLayers: playerDetailsMessage.getCharacterlayersList()
|
||||
};
|
||||
console.log(SocketIoEvent.SET_PLAYER_DETAILS, playerDetails);
|
||||
//console.log(SocketIoEvent.SET_PLAYER_DETAILS, playerDetails);
|
||||
if (!isSetPlayerDetailsMessage(playerDetails)) {
|
||||
socket.emit(SocketIoEvent.MESSAGE_ERROR, {message: 'Invalid SET_PLAYER_DETAILS message.'});
|
||||
console.warn('Invalid SET_PLAYER_DETAILS message received: ', playerDetails);
|
||||
@ -547,7 +557,7 @@ export class IoSocketController {
|
||||
|
||||
const userMovedMessage = new UserMovedMessage();
|
||||
userMovedMessage.setUserid(clientUser.userId);
|
||||
userMovedMessage.setPosition(toPositionMessage(clientUser.position));
|
||||
userMovedMessage.setPosition(ProtobufUtils.toPositionMessage(clientUser.position));
|
||||
|
||||
const subMessage = new SubMessage();
|
||||
subMessage.setUsermovedmessage(userMovedMessage);
|
||||
|
@ -1,11 +1,11 @@
|
||||
import {PointInterface} from "./PointInterface";
|
||||
import {PositionMessage} from "../../../../messages/generated/messages_pb";
|
||||
import {ExSocketInterface} from "_Model/Websocket/ExSocketInterface";
|
||||
import Direction = PositionMessage.Direction;
|
||||
|
||||
export namespace ProtobufUtils {
|
||||
import Direction = PositionMessage.Direction;
|
||||
export class ProtobufUtils {
|
||||
|
||||
export function toPositionMessage(point: PointInterface): PositionMessage {
|
||||
public static toPositionMessage(point: PointInterface): PositionMessage {
|
||||
let direction: PositionMessage.DirectionMap[keyof PositionMessage.DirectionMap];
|
||||
switch (point.direction) {
|
||||
case 'up':
|
||||
|
@ -152,7 +152,7 @@ export class Connection implements Connection {
|
||||
* Messages inside batched messages are extracted and sent to listeners directly.
|
||||
*/
|
||||
this.socket.on(EventMessage.BATCH, (batchedMessagesBinary: ArrayBuffer) => {
|
||||
const batchMessage = BatchMessage.deserializeBinary(new Uint8Array(batchedMessagesBinary as ArrayBuffer));
|
||||
const batchMessage = BatchMessage.deserializeBinary(new Uint8Array(batchedMessagesBinary));
|
||||
|
||||
for (const message of batchMessage.getPayloadList()) {
|
||||
let event: string;
|
||||
|
@ -1,10 +1,10 @@
|
||||
import {PositionMessage} from "../../../messages/generated/messages_pb";
|
||||
import {PointInterface} from "../Connection";
|
||||
import Direction = PositionMessage.Direction;
|
||||
|
||||
export namespace ProtobufClientUtils {
|
||||
import Direction = PositionMessage.Direction;
|
||||
export class ProtobufClientUtils {
|
||||
|
||||
export function toPointInterface(position: PositionMessage): PointInterface {
|
||||
public static toPointInterface(position: PositionMessage): PointInterface {
|
||||
let direction: string;
|
||||
switch (position.getDirection()) {
|
||||
case Direction.UP:
|
||||
|
@ -42,7 +42,6 @@ import {ActionableItem} from "../Items/ActionableItem";
|
||||
import {UserInputManager} from "../UserInput/UserInputManager";
|
||||
import {UserMovedMessage} from "../../../../messages/generated/messages_pb";
|
||||
import {ProtobufClientUtils} from "../../Network/ProtobufClientUtils";
|
||||
import toPointInterface = ProtobufClientUtils.toPointInterface;
|
||||
|
||||
|
||||
export enum Textures {
|
||||
@ -224,7 +223,7 @@ export class GameScene extends Phaser.Scene implements CenterListener {
|
||||
|
||||
const messageUserMoved: MessageUserMovedInterface = {
|
||||
userId: message.getUserid(),
|
||||
position: toPointInterface(position)
|
||||
position: ProtobufClientUtils.toPointInterface(position)
|
||||
}
|
||||
|
||||
this.updatePlayerPosition(messageUserMoved);
|
||||
|
Loading…
Reference in New Issue
Block a user