Add teleport event

This commit is contained in:
Gregoire Parant 2020-10-15 11:51:24 +02:00
parent 7b435edd71
commit 8df56204e3
3 changed files with 18 additions and 5 deletions

View File

@ -891,12 +891,16 @@ export class IoSocketController {
}
public teleport(userUuid: string) {
const user = this.searchClientByUuid(userUuid);
if(!user){
const userSocket = this.searchClientByUuid(userUuid);
if (!userSocket) {
throw 'User not found';
}
const teleportMessageMessage = new TeleportMessageMessage();
teleportMessageMessage.setMap(`/teleport/${user.userUuid}`);
user.send(teleportMessageMessage.serializeBinary().buffer, true);
teleportMessageMessage.setMap(`wait/${userSocket.userUuid}`);
const serverToClientMessage = new ServerToClientMessage();
serverToClientMessage.setTeleportmessagemessage(teleportMessageMessage);
userSocket.send(serverToClientMessage.serializeBinary().buffer, true);
}
}

View File

@ -27,7 +27,10 @@ export class ReportController extends BaseController {
})
const param = await res.json();
this.ioSocketController.teleport(param.userUuid);
res.writeStatus("200 OK").end();
res.writeHeader('Content-Type', 'application/json');
res.writeStatus("200 OK").end(JSON.stringify({
mapUrl: `wait/${param.userUuid}`
}));
} catch (e) {
console.log("An error happened", e)
res.writeStatus(e.status || "500 Internal Server Error").end('An error happened');

View File

@ -20,6 +20,12 @@ export class GlobalMessageManager {
this.Connection.receiveStopGlobalMessage((messageId: string) => {
this.stopMessage(messageId);
});
//receive signal to close message
this.Connection.receiveTeleportMessage((map: string) => {
console.log('map to teleport user', map);
//TODO teleport user on map
});
}
private playMessage(message : PlayGlobalMessageInterface){