diff --git a/back/src/RoomManager.ts b/back/src/RoomManager.ts index 8a840c15..2705787e 100644 --- a/back/src/RoomManager.ts +++ b/back/src/RoomManager.ts @@ -29,7 +29,7 @@ import { WebRtcSignalToServerMessage, WorldFullWarningToRoomMessage, ZoneMessage, - LockGroupMessage, + LockGroupPromptMessage, } from "./Messages/generated/messages_pb"; import { sendUnaryData, ServerDuplexStream, ServerUnaryCall, ServerWritableStream } from "grpc"; import { socketManager } from "./Services/SocketManager"; @@ -136,11 +136,11 @@ const roomManager: IRoomManagerServer = { user, message.getFollowabortmessage() as FollowAbortMessage ); - } else if (message.hasLockgroupmessage()) { + } else if (message.hasLockgrouppromptmessage()) { socketManager.handleLockGroupMessage( room, user, - message.getLockgroupmessage() as LockGroupMessage + message.getLockgrouppromptmessage() as LockGroupPromptMessage ); } else if (message.hasSendusermessage()) { const sendUserMessage = message.getSendusermessage(); diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index 2bfe7cf2..0f78427f 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -40,6 +40,7 @@ import { PlayerDetailsUpdatedMessage, GroupUsersUpdateMessage, LockGroupMessage, + LockGroupPromptMessage, } from "../Messages/generated/messages_pb"; import { User, UserSocket } from "../Model/User"; import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils"; @@ -898,7 +899,7 @@ export class SocketManager { } } - handleLockGroupMessage(room: GameRoom, user: User, message: LockGroupMessage) { + handleLockGroupMessage(room: GameRoom, user: User, message: LockGroupPromptMessage) { const group = user.group; if (!group) { return; @@ -906,7 +907,7 @@ export class SocketManager { group.lock(message.getLock()); const lockGroupMessage = new LockGroupMessage(); lockGroupMessage.setLock(message.getLock()); - lockGroupMessage.setGroupid(message.getGroupid()); + lockGroupMessage.setGroupid(group.getId()); room.emitLockGroupMessage(user, lockGroupMessage); } } diff --git a/front/src/Components/CameraControls.svelte b/front/src/Components/CameraControls.svelte index 7b189aff..da207df1 100644 --- a/front/src/Components/CameraControls.svelte +++ b/front/src/Components/CameraControls.svelte @@ -17,7 +17,7 @@ import { embedScreenLayout } from "../Stores/EmbedScreensStore"; import { followRoleStore, followStateStore, followUsersStore } from "../Stores/FollowStore"; import { gameManager } from "../Phaser/Game/GameManager"; - import { currentPlayerGroupIdStore, currentPlayerGroupLockStateStore } from "../Stores/CurrentPlayerGroupStore"; + import { currentPlayerGroupLockStateStore } from "../Stores/CurrentPlayerGroupStore"; const gameScene = gameManager.getCurrentGameScene(); @@ -73,12 +73,7 @@ } function lockClick() { - console.log($currentPlayerGroupIdStore); - console.log($currentPlayerGroupLockStateStore); - if ($currentPlayerGroupIdStore === undefined) { - return; - } - gameScene.connection?.emitLockGroup($currentPlayerGroupIdStore, !$currentPlayerGroupLockStateStore); + gameScene.connection?.emitLockGroup(!$currentPlayerGroupLockStateStore); } let isSilent: boolean; diff --git a/front/src/Connexion/RoomConnection.ts b/front/src/Connexion/RoomConnection.ts index 3d69f38a..d0cc5c48 100644 --- a/front/src/Connexion/RoomConnection.ts +++ b/front/src/Connexion/RoomConnection.ts @@ -858,12 +858,11 @@ export class RoomConnection implements RoomConnection { this.socket.send(bytes); } - public emitLockGroup(groupId: number, lock: boolean = true): void { + public emitLockGroup(lock: boolean = true): void { const bytes = ClientToServerMessageTsProto.encode({ message: { - $case: "lockGroupMessage", - lockGroupMessage: { - groupId, + $case: "lockGroupPromptMessage", + lockGroupPromptMessage: { lock, }, }, diff --git a/messages/protos/messages.proto b/messages/protos/messages.proto index 3db0da95..b6e8d98f 100644 --- a/messages/protos/messages.proto +++ b/messages/protos/messages.proto @@ -98,6 +98,10 @@ message FollowAbortMessage { int32 follower = 2; } +message LockGroupPromptMessage { + bool lock = 1; +} + message LockGroupMessage { int32 groupId = 1; bool lock = 2; @@ -121,7 +125,7 @@ message ClientToServerMessage { FollowRequestMessage followRequestMessage = 15; FollowConfirmationMessage followConfirmationMessage = 16; FollowAbortMessage followAbortMessage = 17; - LockGroupMessage lockGroupMessage = 18; + LockGroupPromptMessage lockGroupPromptMessage = 18; } } @@ -412,7 +416,7 @@ message PusherToBackMessage { FollowRequestMessage followRequestMessage = 16; FollowConfirmationMessage followConfirmationMessage = 17; FollowAbortMessage followAbortMessage = 18; - LockGroupMessage lockGroupMessage = 19; + LockGroupPromptMessage lockGroupPromptMessage = 19; } } diff --git a/pusher/src/Controller/IoSocketController.ts b/pusher/src/Controller/IoSocketController.ts index 617da341..7c7928d6 100644 --- a/pusher/src/Controller/IoSocketController.ts +++ b/pusher/src/Controller/IoSocketController.ts @@ -22,6 +22,7 @@ import { FollowAbortMessage, VariableMessage, LockGroupMessage, + LockGroupPromptMessage, } from "../Messages/generated/messages_pb"; import { UserMovesMessage } from "../Messages/generated/messages_pb"; import { TemplatedApp } from "uWebSockets.js"; @@ -495,8 +496,11 @@ export class IoSocketController { ); } else if (message.hasFollowabortmessage()) { socketManager.handleFollowAbort(client, message.getFollowabortmessage() as FollowAbortMessage); - } else if (message.hasLockgroupmessage()) { - socketManager.handleLockGroup(client, message.getLockgroupmessage() as LockGroupMessage); + } else if (message.hasLockgrouppromptmessage()) { + socketManager.handleLockGroup( + client, + message.getLockgrouppromptmessage() as LockGroupPromptMessage + ); } /* Ok is false if backpressure was built up, wait for drain */ diff --git a/pusher/src/Model/PositionDispatcher.ts b/pusher/src/Model/PositionDispatcher.ts index f868cd2c..b0eea0ac 100644 --- a/pusher/src/Model/PositionDispatcher.ts +++ b/pusher/src/Model/PositionDispatcher.ts @@ -63,6 +63,7 @@ export class PositionDispatcher { const addedZones = [...newZones].filter((x) => !oldZones.has(x)); const removedZones = [...oldZones].filter((x) => !newZones.has(x)); + console.log("START LISTENING"); for (const zone of addedZones) { zone.startListening(socket); } diff --git a/pusher/src/Model/Zone.ts b/pusher/src/Model/Zone.ts index 451597b9..92f82222 100644 --- a/pusher/src/Model/Zone.ts +++ b/pusher/src/Model/Zone.ts @@ -140,6 +140,10 @@ export class GroupDescriptor { return new GroupDescriptor(message.getGroupid(), message.getGroupsize(), position, message.getLocked()); } + public updateFromLockGroupMessage(message: LockGroupMessage): void { + this.locked = message.getLock(); + } + public update(groupDescriptor: GroupDescriptor) { this.groupSize = groupDescriptor.groupSize; this.position = groupDescriptor.position; @@ -214,11 +218,17 @@ export class Zone { this.notifyGroupMove(groupDescriptor); } else { this.groups.set(groupId, groupDescriptor); - const fromZone = groupUpdateZoneMessage.getFromzone(); - this.notifyGroupEnter(groupDescriptor, fromZone?.toObject()); } + } else if (message.hasLockgroupmessage()) { + const lockGroupMessage = message.getLockgroupmessage() as LockGroupMessage; + const groupId = lockGroupMessage.getGroupid(); + const oldGroupDescriptor = this.groups.get(groupId); + if (oldGroupDescriptor !== undefined) { + oldGroupDescriptor.updateFromLockGroupMessage(lockGroupMessage); + this.notifyLockGroup(lockGroupMessage); + } } else if (message.hasUserleftzonemessage()) { const userLeftMessage = message.getUserleftzonemessage() as UserLeftZoneMessage; this.users.delete(userLeftMessage.getUserid()); diff --git a/pusher/src/Services/SocketManager.ts b/pusher/src/Services/SocketManager.ts index 96e599e0..30f41f2a 100644 --- a/pusher/src/Services/SocketManager.ts +++ b/pusher/src/Services/SocketManager.ts @@ -39,6 +39,7 @@ import { WorldFullMessage, PlayerDetailsUpdatedMessage, LockGroupMessage, + LockGroupPromptMessage, } from "../Messages/generated/messages_pb"; import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils"; import { ADMIN_API_URL, JITSI_ISS, JITSI_URL, SECRET_JITSI_KEY } from "../Enum/EnvironmentVariable"; @@ -293,9 +294,9 @@ export class SocketManager implements ZoneEventListener { client.backConnection.write(pusherToBackMessage); } - handleLockGroup(client: ExSocketInterface, message: LockGroupMessage): void { + handleLockGroup(client: ExSocketInterface, message: LockGroupPromptMessage): void { const pusherToBackMessage = new PusherToBackMessage(); - pusherToBackMessage.setLockgroupmessage(message); + pusherToBackMessage.setLockgrouppromptmessage(message); client.backConnection.write(pusherToBackMessage); } @@ -614,6 +615,7 @@ export class SocketManager implements ZoneEventListener { public onGroupEnters(group: GroupDescriptor, listener: ExSocketInterface): void { const subMessage = new SubMessage(); + console.log("ON GROUP ENTERS"); subMessage.setGroupupdatemessage(group.toGroupUpdateMessage()); emitInBatch(listener, subMessage);