Catching errors in socket callbacks

Catching errors in socket callbacks to avoid having the server crashing when an error occurs.
This commit is contained in:
David Négrier 2020-05-12 11:49:55 +02:00
parent b50f28176e
commit 256fa51e24
3 changed files with 73 additions and 54 deletions

View file

@ -49,6 +49,8 @@ export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite {
this.setSize(16, 16); //edit the hitbox to better match the character model
this.setOffset(8, 16);
this.setDepth(-1);
this.scene.events.on('postupdate', this.postupdate.bind(this));
}
move(x: number, y: number) {
@ -69,14 +71,14 @@ export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite {
if (this.bubble) {
this.bubble.moveBubble(this.x, this.y);
}
this.updatePlayerNamePosition(this.x, this.y);
//update depth user
this.setDepth(this.y);
}
updatePlayerNamePosition(x: number, y: number){
this.playerName.setPosition(x, y - 25);
postupdate(time: number, delta: number) {
//super.update(delta);
this.playerName.setPosition(this.x, this.y - 25);
}
stop(){
@ -95,6 +97,9 @@ export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite {
}
destroy(fromScene?: boolean): void {
if (this.scene) {
this.scene.events.removeListener('postupdate', this.postupdate.bind(this));
}
super.destroy(fromScene);
this.playerName.destroy();
}

View file

@ -62,7 +62,7 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
let activeEvents = this.userInputManager.getEventListForGameTick();
let speedMultiplier = activeEvents.get(UserInputEvent.SpeedUp) ? 25 : 9;
let moveAmount = speedMultiplier * delta;
let moveAmount = speedMultiplier * 20;
let x = 0;
let y = 0;
@ -102,6 +102,5 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
this.setX(MessageUserPosition.position.x);
this.setY(MessageUserPosition.position.y);
this.setDepth(MessageUserPosition.position.y);
this.updatePlayerNamePosition(MessageUserPosition.position.x, MessageUserPosition.position.y);
}
}