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