diff --git a/back/src/Model/GameRoom.ts b/back/src/Model/GameRoom.ts index 0e8203cf..157faa4e 100644 --- a/back/src/Model/GameRoom.ts +++ b/back/src/Model/GameRoom.ts @@ -6,6 +6,7 @@ import { EmoteCallback, EntersCallback, LeavesCallback, + LockGroupCallback, MovesCallback, PlayerDetailsUpdatedCallback, } from "_Model/Zone"; @@ -44,7 +45,7 @@ export class GameRoom { // Users, sorted by ID private readonly users = new Map(); private readonly usersByUuid = new Map(); - private readonly groups = new Set(); + private readonly groups: Map = new Map(); private readonly admins = new Set(); private itemsState = new Map(); @@ -66,6 +67,7 @@ export class GameRoom { onMoves: MovesCallback, onLeaves: LeavesCallback, onEmote: EmoteCallback, + onLockGroup: LockGroupCallback, onPlayerDetailsUpdated: PlayerDetailsUpdatedCallback ) { // A zone is 10 sprites wide. @@ -76,6 +78,7 @@ export class GameRoom { onMoves, onLeaves, onEmote, + onLockGroup, onPlayerDetailsUpdated ); } @@ -90,6 +93,7 @@ export class GameRoom { onMoves: MovesCallback, onLeaves: LeavesCallback, onEmote: EmoteCallback, + onLockGroup: LockGroupCallback, onPlayerDetailsUpdated: PlayerDetailsUpdatedCallback ): Promise { const mapDetails = await GameRoom.getMapDetails(roomUrl); @@ -105,6 +109,7 @@ export class GameRoom { onMoves, onLeaves, onEmote, + onLockGroup, onPlayerDetailsUpdated ); @@ -244,7 +249,7 @@ export class GameRoom { this.disconnectCallback, this.positionNotifier ); - this.groups.add(group); + this.groups.set(group.getId(), group); } } } else { @@ -328,7 +333,7 @@ export class GameRoom { this.disconnectCallback, this.positionNotifier ); - this.groups.add(newGroup); + this.groups.set(newGroup.getId(), newGroup); } else { this.leaveGroup(user); } @@ -375,10 +380,10 @@ export class GameRoom { group.leave(user); if (group.isEmpty()) { group.destroy(); - if (!this.groups.has(group)) { + if (!this.groups.has(group.getId())) { throw new Error(`Could not find group ${group.getId()} referenced by user ${user.id} in World.`); } - this.groups.delete(group); + this.groups.delete(group.getId()); //todo: is the group garbage collected? } else { group.updatePosition(); @@ -418,7 +423,7 @@ export class GameRoom { }); this.groups.forEach((group: Group) => { - if (group.isFull()) { + if (group.isFull() || group.isLocked()) { return; } const distance = GameRoom.computeDistanceBetweenPositions(user.getPosition(), group.getPosition()); @@ -544,6 +549,10 @@ export class GameRoom { this.positionNotifier.emitEmoteEvent(user, emoteEventMessage); } + public emitLockGroupEvent(user: User, groupId: number) { + this.positionNotifier.emitLockGroupEvent(user, groupId); + } + public addRoomListener(socket: RoomSocket) { this.roomListeners.add(socket); } @@ -657,4 +666,8 @@ export class GameRoom { const variablesManager = await this.getVariableManager(); return variablesManager.getVariablesForTags(tags); } + + public getGroupById(id: number): Group | undefined { + return this.groups.get(id); + } } diff --git a/back/src/Model/Group.ts b/back/src/Model/Group.ts index c14d509f..a960e7b3 100644 --- a/back/src/Model/Group.ts +++ b/back/src/Model/Group.ts @@ -14,6 +14,7 @@ export class Group implements Movable { private x!: number; private y!: number; private wasDestroyed: boolean = false; + private locked: boolean = false; private roomId: string; private currentZone: Zone | null = null; /** @@ -141,15 +142,19 @@ export class Group implements Movable { return this.users.size >= MAX_PER_GROUP; } + isLocked(): boolean { + return this.locked; + } + isEmpty(): boolean { return this.users.size <= 1; } join(user: User): void { // Broadcast on the right event - this.connectCallback(user, this); this.users.add(user); user.group = this; + this.connectCallback(user, this); } leave(user: User): void { @@ -167,6 +172,10 @@ export class Group implements Movable { this.disconnectCallback(user, this); } + lock(lock: boolean = true): void { + this.locked = lock; + } + /** * Let's kick everybody out. * Usually used when there is only one user left. diff --git a/back/src/Model/PositionNotifier.ts b/back/src/Model/PositionNotifier.ts index b059999a..38d538ec 100644 --- a/back/src/Model/PositionNotifier.ts +++ b/back/src/Model/PositionNotifier.ts @@ -12,6 +12,7 @@ import { EmoteCallback, EntersCallback, LeavesCallback, + LockGroupCallback, MovesCallback, PlayerDetailsUpdatedCallback, Zone, @@ -50,6 +51,7 @@ export class PositionNotifier { private onUserMoves: MovesCallback, private onUserLeaves: LeavesCallback, private onEmote: EmoteCallback, + private onLockGroup: LockGroupCallback, private onPlayerDetailsUpdated: PlayerDetailsUpdatedCallback ) {} @@ -111,6 +113,7 @@ export class PositionNotifier { this.onUserMoves, this.onUserLeaves, this.onEmote, + this.onLockGroup, this.onPlayerDetailsUpdated, i, j @@ -137,6 +140,12 @@ export class PositionNotifier { zone.emitEmoteEvent(emoteEventMessage); } + public emitLockGroupEvent(user: User, groupId: number) { + const zoneDesc = this.getZoneDescriptorFromCoordinates(user.getPosition().x, user.getPosition().y); + const zone = this.getZone(zoneDesc.i, zoneDesc.j); + zone.emitLockGroupEvent(groupId); + } + public *getAllUsersInSquareAroundZone(zone: Zone): Generator { const zoneDescriptor = this.getZoneDescriptorFromCoordinates(zone.x, zone.y); for (const d of getNearbyDescriptorsMatrix(zoneDescriptor)) { diff --git a/back/src/Model/Zone.ts b/back/src/Model/Zone.ts index 5c3e92ba..2d0cefd5 100644 --- a/back/src/Model/Zone.ts +++ b/back/src/Model/Zone.ts @@ -13,6 +13,7 @@ export type EntersCallback = (thing: Movable, fromZone: Zone | null, listener: Z export type MovesCallback = (thing: Movable, position: PositionInterface, listener: ZoneSocket) => void; export type LeavesCallback = (thing: Movable, newZone: Zone | null, listener: ZoneSocket) => void; export type EmoteCallback = (emoteEventMessage: EmoteEventMessage, listener: ZoneSocket) => void; +export type LockGroupCallback = (groupId: number, listener: ZoneSocket) => void; export type PlayerDetailsUpdatedCallback = ( playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ZoneSocket @@ -27,6 +28,7 @@ export class Zone { private onMoves: MovesCallback, private onLeaves: LeavesCallback, private onEmote: EmoteCallback, + private onLockGroup: LockGroupCallback, private onPlayerDetailsUpdated: PlayerDetailsUpdatedCallback, public readonly x: number, public readonly y: number @@ -108,6 +110,12 @@ export class Zone { } } + public emitLockGroupEvent(groupId: number) { + for (const listener of this.listeners) { + this.onLockGroup(groupId, listener); + } + } + public updatePlayerDetails(user: User, playerDetails: SetPlayerDetailsMessage) { const playerDetailsUpdatedMessage = new PlayerDetailsUpdatedMessage(); playerDetailsUpdatedMessage.setUserid(user.id); diff --git a/back/src/RoomManager.ts b/back/src/RoomManager.ts index d375fbd8..ab886f50 100644 --- a/back/src/RoomManager.ts +++ b/back/src/RoomManager.ts @@ -29,6 +29,7 @@ import { WebRtcSignalToServerMessage, WorldFullWarningToRoomMessage, ZoneMessage, + LockGroupPromptMessage, } from "./Messages/generated/messages_pb"; import { sendUnaryData, ServerDuplexStream, ServerUnaryCall, ServerWritableStream } from "grpc"; import { socketManager } from "./Services/SocketManager"; @@ -135,6 +136,12 @@ const roomManager: IRoomManagerServer = { user, message.getFollowabortmessage() as FollowAbortMessage ); + } else if (message.hasLockgrouppromptmessage()) { + socketManager.handleLockGroupPromptMessage( + room, + user, + message.getLockgrouppromptmessage() as LockGroupPromptMessage + ); } else if (message.hasSendusermessage()) { const sendUserMessage = message.getSendusermessage(); socketManager.handleSendUserMessage(user, sendUserMessage as SendUserMessage); diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index 1d26f001..8aa7f6a4 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -38,6 +38,9 @@ import { SubToPusherRoomMessage, SetPlayerDetailsMessage, PlayerDetailsUpdatedMessage, + GroupUsersUpdateMessage, + LockGroupPromptMessage, + RoomMessage, } from "../Messages/generated/messages_pb"; import { User, UserSocket } from "../Model/User"; import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils"; @@ -68,7 +71,6 @@ function emitZoneMessage(subMessage: SubToPusherMessage, socket: ZoneSocket): vo // TODO: should we batch those every 100ms? const batchMessage = new BatchToPusherMessage(); batchMessage.addPayload(subMessage); - socket.write(batchMessage); } @@ -266,18 +268,28 @@ export class SocketManager { if (roomPromise === undefined) { roomPromise = GameRoom.create( roomId, - (user: User, group: Group) => this.joinWebRtcRoom(user, group), - (user: User, group: Group) => this.disConnectedUser(user, group), + (user: User, group: Group) => { + this.joinWebRtcRoom(user, group); + this.sendGroupUsersUpdateToGroupMembers(group); + }, + (user: User, group: Group) => { + this.disConnectedUser(user, group); + this.sendGroupUsersUpdateToGroupMembers(group); + }, MINIMUM_DISTANCE, GROUP_RADIUS, - (thing: Movable, fromZone: Zone | null, listener: ZoneSocket) => - this.onZoneEnter(thing, fromZone, listener), + (thing: Movable, fromZone: Zone | null, listener: ZoneSocket) => { + this.onZoneEnter(thing, fromZone, listener); + }, (thing: Movable, position: PositionInterface, listener: ZoneSocket) => this.onClientMove(thing, position, listener), (thing: Movable, newZone: Zone | null, listener: ZoneSocket) => this.onClientLeave(thing, newZone, listener), (emoteEventMessage: EmoteEventMessage, listener: ZoneSocket) => this.onEmote(emoteEventMessage, listener), + (groupId: number, listener: ZoneSocket) => { + void this.onLockGroup(groupId, listener, roomPromise); + }, (playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ZoneSocket) => this.onPlayerDetailsUpdated(playerDetailsUpdatedMessage, listener) ) @@ -381,10 +393,24 @@ export class SocketManager { emitZoneMessage(subMessage, client); } + private async onLockGroup( + groupId: number, + client: ZoneSocket, + roomPromise: PromiseLike | undefined + ): Promise { + if (!roomPromise) { + return; + } + const group = (await roomPromise).getGroupById(groupId); + if (!group) { + return; + } + this.emitCreateUpdateGroupEvent(client, null, group); + } + private onPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, client: ZoneSocket) { const subMessage = new SubToPusherMessage(); subMessage.setPlayerdetailsupdatedmessage(playerDetailsUpdatedMessage); - emitZoneMessage(subMessage, client); } @@ -398,6 +424,7 @@ export class SocketManager { groupUpdateMessage.setPosition(pointMessage); groupUpdateMessage.setGroupsize(group.getSize); groupUpdateMessage.setFromzone(this.toProtoZone(fromZone)); + groupUpdateMessage.setLocked(group.isLocked()); const subMessage = new SubToPusherMessage(); subMessage.setGroupupdatezonemessage(groupUpdateMessage); @@ -413,7 +440,6 @@ export class SocketManager { const subMessage = new SubToPusherMessage(); subMessage.setGroupleftzonemessage(groupDeleteMessage); - emitZoneMessage(subMessage, client); //user.emitInBatch(subMessage); } @@ -425,7 +451,6 @@ export class SocketManager { const subMessage = new SubToPusherMessage(); subMessage.setUserleftzonemessage(userLeftMessage); - emitZoneMessage(subMessage, client); } @@ -439,6 +464,19 @@ export class SocketManager { return undefined; } + private sendGroupUsersUpdateToGroupMembers(group: Group) { + const groupUserUpdateMessage = new GroupUsersUpdateMessage(); + groupUserUpdateMessage.setGroupid(group.getId()); + groupUserUpdateMessage.setUseridsList(group.getUsers().map((user) => user.id)); + + const clientMessage = new ServerToClientMessage(); + clientMessage.setGroupusersupdatemessage(groupUserUpdateMessage); + + group.getUsers().forEach((currentUser: User) => { + currentUser.socket.write(clientMessage); + }); + } + private joinWebRtcRoom(user: User, group: Group) { for (const otherUser of group.getUsers()) { if (user === otherUser) { @@ -634,6 +672,7 @@ export class SocketManager { const groupUpdateMessage = new GroupUpdateZoneMessage(); groupUpdateMessage.setGroupid(thing.getId()); groupUpdateMessage.setPosition(ProtobufUtils.toPointMessage(thing.getPosition())); + groupUpdateMessage.setLocked(thing.isLocked()); const subMessage = new SubToPusherMessage(); subMessage.setGroupupdatezonemessage(groupUpdateMessage); @@ -870,6 +909,15 @@ export class SocketManager { leader?.delFollower(user); } } + + handleLockGroupPromptMessage(room: GameRoom, user: User, message: LockGroupPromptMessage) { + const group = user.group; + if (!group) { + return; + } + group.lock(message.getLock()); + room.emitLockGroupEvent(user, group.getId()); + } } export const socketManager = new SocketManager(); diff --git a/back/tests/GameRoomTest.ts b/back/tests/GameRoomTest.ts index d4e83daf..fb9f09fb 100644 --- a/back/tests/GameRoomTest.ts +++ b/back/tests/GameRoomTest.ts @@ -52,6 +52,7 @@ describe("GameRoom", () => { () => {}, () => {}, emote, + () => {}, () => {} ); @@ -88,6 +89,7 @@ describe("GameRoom", () => { () => {}, () => {}, emote, + () => {}, () => {} ); @@ -128,6 +130,7 @@ describe("GameRoom", () => { () => {}, () => {}, emote, + () => {}, () => {} ); diff --git a/back/tests/PositionNotifierTest.ts b/back/tests/PositionNotifierTest.ts index bf7ddd6e..f21bb4b2 100644 --- a/back/tests/PositionNotifierTest.ts +++ b/back/tests/PositionNotifierTest.ts @@ -25,6 +25,7 @@ describe("PositionNotifier", () => { leaveTriggered = true; }, () => {}, + () => {}, () => {} ); @@ -132,6 +133,7 @@ describe("PositionNotifier", () => { leaveTriggered = true; }, () => {}, + () => {}, () => {} ); diff --git a/front/src/Components/CameraControls.svelte b/front/src/Components/CameraControls.svelte index cad6603a..1a2caf93 100644 --- a/front/src/Components/CameraControls.svelte +++ b/front/src/Components/CameraControls.svelte @@ -10,12 +10,14 @@ import layoutPresentationImg from "./images/layout-presentation.svg"; import layoutChatImg from "./images/layout-chat.svg"; import followImg from "./images/follow.svg"; + import lockImg from "./images/lock.svg"; import { LayoutMode } from "../WebRtc/LayoutManager"; import { peerStore } from "../Stores/PeerStore"; import { onDestroy } from "svelte"; import { embedScreenLayout } from "../Stores/EmbedScreensStore"; import { followRoleStore, followStateStore, followUsersStore } from "../Stores/FollowStore"; import { gameManager } from "../Phaser/Game/GameManager"; + import { currentPlayerGroupLockStateStore } from "../Stores/CurrentPlayerGroupStore"; const gameScene = gameManager.getCurrentGameScene(); @@ -70,6 +72,10 @@ } } + function lockClick() { + gameScene.connection?.emitLockGroup(!$currentPlayerGroupLockStateStore); + } + let isSilent: boolean; const unsubscribeIsSilent = isSilentStore.subscribe((value) => { isSilent = value; @@ -95,6 +101,15 @@ +
+ +
+
\ No newline at end of file diff --git a/front/src/Connexion/ConnexionModels.ts b/front/src/Connexion/ConnexionModels.ts index c681fd37..d71d5c63 100644 --- a/front/src/Connexion/ConnexionModels.ts +++ b/front/src/Connexion/ConnexionModels.ts @@ -44,6 +44,12 @@ export interface GroupCreatedUpdatedMessageInterface { position: PositionInterface; groupId: number; groupSize: number; + locked: boolean; +} + +export interface GroupUsersUpdateMessageInterface { + groupId: number; + userIds: number[]; } export interface WebRtcDisconnectMessageInterface { diff --git a/front/src/Connexion/RoomConnection.ts b/front/src/Connexion/RoomConnection.ts index ed982536..f1dbde13 100644 --- a/front/src/Connexion/RoomConnection.ts +++ b/front/src/Connexion/RoomConnection.ts @@ -5,47 +5,35 @@ import type { UserSimplePeerInterface } from "../WebRtc/SimplePeer"; import { ProtobufClientUtils } from "../Network/ProtobufClientUtils"; import type { GroupCreatedUpdatedMessageInterface, - ItemEventMessageInterface, + GroupUsersUpdateMessageInterface, MessageUserJoined, - OnConnectInterface, - PlayerDetailsUpdatedMessageInterface, PlayGlobalMessageInterface, PositionInterface, RoomJoinedMessageInterface, ViewportInterface, - WebRtcDisconnectMessageInterface, WebRtcSignalReceivedMessageInterface, } from "./ConnexionModels"; import type { BodyResourceDescriptionInterface } from "../Phaser/Entity/PlayerTextures"; import { adminMessagesService } from "./AdminMessagesService"; import { connectionManager } from "./ConnectionManager"; import { get } from "svelte/store"; +import { followRoleStore, followUsersStore } from "../Stores/FollowStore"; import { menuIconVisiblilityStore, menuVisiblilityStore, warningContainerStore } from "../Stores/MenuStore"; -import { followStateStore, followRoleStore, followUsersStore } from "../Stores/FollowStore"; import { localUserStore } from "./LocalUserStore"; import { - RefreshRoomMessage, ServerToClientMessage as ServerToClientMessageTsProto, TokenExpiredMessage, WorldConnexionMessage, - WorldFullMessage, ErrorMessage as ErrorMessageTsProto, UserMovedMessage as UserMovedMessageTsProto, GroupUpdateMessage as GroupUpdateMessageTsProto, GroupDeleteMessage as GroupDeleteMessageTsProto, UserJoinedMessage as UserJoinedMessageTsProto, UserLeftMessage as UserLeftMessageTsProto, - ItemEventMessage as ItemEventMessageTsProto, EmoteEventMessage as EmoteEventMessageTsProto, - VariableMessage as VariableMessageTsProto, PlayerDetailsUpdatedMessage as PlayerDetailsUpdatedMessageTsProto, - WorldFullWarningMessage, WebRtcDisconnectMessage as WebRtcDisconnectMessageTsProto, - PlayGlobalMessage as PlayGlobalMessageTsProto, - StopGlobalMessage as StopGlobalMessageTsProto, SendJitsiJwtMessage as SendJitsiJwtMessageTsProto, - SendUserMessage as SendUserMessageTsProto, - BanUserMessage as BanUserMessageTsProto, ClientToServerMessage as ClientToServerMessageTsProto, PositionMessage as PositionMessageTsProto, ViewportMessage as ViewportMessageTsProto, @@ -55,8 +43,6 @@ import { CharacterLayerMessage, } from "../Messages/ts-proto-generated/messages"; import { Subject } from "rxjs"; -import { OpenPopupEvent } from "../Api/Events/OpenPopupEvent"; -import { match } from "assert"; import { selectCharacterSceneVisibleStore } from "../Stores/SelectCharacterStore"; import { gameManager } from "../Phaser/Game/GameManager"; import { SelectCharacterScene, SelectCharacterSceneName } from "../Phaser/Login/SelectCharacterScene"; @@ -116,6 +102,9 @@ export class RoomConnection implements RoomConnection { private readonly _groupUpdateMessageStream = new Subject(); public readonly groupUpdateMessageStream = this._groupUpdateMessageStream.asObservable(); + private readonly _groupUsersUpdateMessageStream = new Subject(); + public readonly groupUsersUpdateMessageStream = this._groupUsersUpdateMessageStream.asObservable(); + private readonly _groupDeleteMessageStream = new Subject(); public readonly groupDeleteMessageStream = this._groupDeleteMessageStream.asObservable(); @@ -443,6 +432,10 @@ export class RoomConnection implements RoomConnection { this._sendJitsiJwtMessageStream.next(message.sendJitsiJwtMessage); break; } + case "groupUsersUpdateMessage": { + this._groupUsersUpdateMessageStream.next(message.groupUsersUpdateMessage); + break; + } case "sendUserMessage": { adminMessagesService.onSendusermessage(message.sendUserMessage); break; @@ -675,6 +668,7 @@ export class RoomConnection implements RoomConnection { groupId: message.groupId, position: position, groupSize: message.groupSize, + locked: message.locked, }; } @@ -890,6 +884,19 @@ export class RoomConnection implements RoomConnection { this.socket.send(bytes); } + public emitLockGroup(lock: boolean = true): void { + const bytes = ClientToServerMessageTsProto.encode({ + message: { + $case: "lockGroupPromptMessage", + lockGroupPromptMessage: { + lock, + }, + }, + }).finish(); + + this.socket.send(bytes); + } + public getAllTags(): string[] { return this.tags; } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index b58b502f..9b39087f 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -76,6 +76,7 @@ import { userIsAdminStore } from "../../Stores/GameStore"; import { contactPageStore } from "../../Stores/MenuStore"; import type { WasCameraUpdatedEvent } from "../../Api/Events/WasCameraUpdatedEvent"; import { audioManagerFileStore } from "../../Stores/AudioManagerStore"; +import { currentPlayerGroupIdStore, currentPlayerGroupLockStateStore } from "../../Stores/CurrentPlayerGroupStore"; import EVENT_TYPE = Phaser.Scenes.Events; import Texture = Phaser.Textures.Texture; @@ -178,6 +179,7 @@ export class GameScene extends DirtyScene { private volumeStoreUnsubscribers: Map = new Map(); private localVolumeStoreUnsubscriber: Unsubscriber | undefined; private followUsersColorStoreUnsubscribe!: Unsubscriber; + private currentPlayerGroupIdStoreUnsubscribe!: Unsubscriber; private biggestAvailableAreaStoreUnsubscribe!: () => void; MapUrlFile: string; @@ -219,6 +221,7 @@ export class GameScene extends DirtyScene { private loader: Loader; private lastCameraEvent: WasCameraUpdatedEvent | undefined; private firstCameraUpdateSent: boolean = false; + private currentPlayerGroupId?: number; public readonly superLoad: SuperLoaderPlugin; constructor(private room: Room, MapUrlFile: string, customKey?: string | undefined) { @@ -724,6 +727,10 @@ export class GameScene extends DirtyScene { } }); + this.currentPlayerGroupIdStoreUnsubscribe = currentPlayerGroupIdStore.subscribe((groupId) => { + this.currentPlayerGroupId = groupId; + }); + Promise.all([ this.connectionAnswerPromiseDeferred.promise as Promise, ...scriptPromises, @@ -855,6 +862,11 @@ export class GameScene extends DirtyScene { }); }); + this.connection.groupUsersUpdateMessageStream.subscribe((message) => { + // TODO: how else can we deduce our current group? + currentPlayerGroupIdStore.set(message.groupId); + }); + /** * Triggered when we receive the JWT token to connect to Jitsi */ @@ -985,7 +997,9 @@ export class GameScene extends DirtyScene { context.arc(48, 48, 48, 0, 2 * Math.PI, false); // context.lineWidth = 5; context.strokeStyle = "#ffffff"; + context.fillStyle = "#ffffff44"; context.stroke(); + context.fill(); this.circleTexture.refresh(); //create red circle canvas use to create sprite @@ -995,7 +1009,9 @@ export class GameScene extends DirtyScene { contextRed.arc(48, 48, 48, 0, 2 * Math.PI, false); //context.lineWidth = 5; contextRed.strokeStyle = "#ff0000"; + contextRed.fillStyle = "#ff000044"; contextRed.stroke(); + contextRed.fill(); this.circleRedTexture.refresh(); } @@ -1884,12 +1900,15 @@ export class GameScene extends DirtyScene { case "GroupCreatedUpdatedEvent": this.doShareGroupPosition(event.event); break; - case "DeleteGroupEvent": - this.doDeleteGroup(event.groupId); - break; case "PlayerDetailsUpdated": this.doUpdatePlayerDetails(event.details); break; + case "DeleteGroupEvent": { + this.doDeleteGroup(event.groupId); + currentPlayerGroupIdStore.set(undefined); + currentPlayerGroupLockStateStore.set(undefined); + break; + } default: { const tmp: never = event; } @@ -2063,11 +2082,16 @@ export class GameScene extends DirtyScene { this, Math.round(groupPositionMessage.position.x), Math.round(groupPositionMessage.position.y), - groupPositionMessage.groupSize === MAX_PER_GROUP ? "circleSprite-red" : "circleSprite-white" + groupPositionMessage.groupSize === MAX_PER_GROUP || groupPositionMessage.locked + ? "circleSprite-red" + : "circleSprite-white" ); sprite.setDisplayOrigin(48, 48); this.add.existing(sprite); this.groups.set(groupPositionMessage.groupId, sprite); + if (this.currentPlayerGroupId === groupPositionMessage.groupId) { + currentPlayerGroupLockStateStore.set(groupPositionMessage.locked); + } return sprite; } diff --git a/front/src/Stores/CurrentPlayerGroupStore.ts b/front/src/Stores/CurrentPlayerGroupStore.ts new file mode 100644 index 00000000..cda46325 --- /dev/null +++ b/front/src/Stores/CurrentPlayerGroupStore.ts @@ -0,0 +1,4 @@ +import { writable } from "svelte/store"; + +export const currentPlayerGroupIdStore = writable(undefined); +export const currentPlayerGroupLockStateStore = writable(undefined); diff --git a/messages/protos/messages.proto b/messages/protos/messages.proto index d0768480..4ddb3941 100644 --- a/messages/protos/messages.proto +++ b/messages/protos/messages.proto @@ -99,6 +99,10 @@ message FollowAbortMessage { int32 follower = 2; } +message LockGroupPromptMessage { + bool lock = 1; +} + message ClientToServerMessage { oneof message { UserMovesMessage userMovesMessage = 2; @@ -117,6 +121,7 @@ message ClientToServerMessage { FollowRequestMessage followRequestMessage = 15; FollowConfirmationMessage followConfirmationMessage = 16; FollowAbortMessage followAbortMessage = 17; + LockGroupPromptMessage lockGroupPromptMessage = 18; } } @@ -185,6 +190,7 @@ message GroupUpdateMessage { int32 groupId = 1; PointMessage position = 2; int32 groupSize = 3; + bool locked = 4; } message GroupDeleteMessage { @@ -216,6 +222,11 @@ message ItemStateMessage { string stateJson = 2; } +message GroupUsersUpdateMessage { + int32 groupId = 1; + repeated int32 userIds = 2; +} + message RoomJoinedMessage { //repeated UserJoinedMessage user = 1; //repeated GroupUpdateMessage group = 2; @@ -316,6 +327,7 @@ message ServerToClientMessage { FollowConfirmationMessage followConfirmationMessage = 22; FollowAbortMessage followAbortMessage = 23; InvalidTextureMessage invalidTextureMessage = 24; + GroupUsersUpdateMessage groupUsersUpdateMessage = 25; } } @@ -356,8 +368,9 @@ message UserLeftZoneMessage { message GroupUpdateZoneMessage { int32 groupId = 1; PointMessage position = 2; - int32 groupSize = 3; + int32 groupSize = 3; Zone fromZone = 4; + bool locked = 5; } message GroupLeftZoneMessage { @@ -403,6 +416,7 @@ message PusherToBackMessage { FollowRequestMessage followRequestMessage = 16; FollowConfirmationMessage followConfirmationMessage = 17; FollowAbortMessage followAbortMessage = 18; + LockGroupPromptMessage lockGroupPromptMessage = 19; } } diff --git a/pusher/src/Controller/IoSocketController.ts b/pusher/src/Controller/IoSocketController.ts index a8243b49..6a2dccc1 100644 --- a/pusher/src/Controller/IoSocketController.ts +++ b/pusher/src/Controller/IoSocketController.ts @@ -21,6 +21,7 @@ import { FollowConfirmationMessage, FollowAbortMessage, VariableMessage, + LockGroupPromptMessage, } from "../Messages/generated/messages_pb"; import { UserMovesMessage } from "../Messages/generated/messages_pb"; import { parse } from "query-string"; @@ -561,6 +562,11 @@ export class IoSocketController { ); } else if (message.hasFollowabortmessage()) { socketManager.handleFollowAbort(client, message.getFollowabortmessage() as FollowAbortMessage); + } 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/Zone.ts b/pusher/src/Model/Zone.ts index 2132ff39..02a01d8d 100644 --- a/pusher/src/Model/Zone.ts +++ b/pusher/src/Model/Zone.ts @@ -123,19 +123,25 @@ export class UserDescriptor { } export class GroupDescriptor { - private constructor(public readonly groupId: number, private groupSize: number, private position: PointMessage) {} + private constructor( + public readonly groupId: number, + private groupSize: number, + private position: PointMessage, + private locked: boolean + ) {} public static createFromGroupUpdateZoneMessage(message: GroupUpdateZoneMessage): GroupDescriptor { const position = message.getPosition(); if (position === undefined) { throw new Error("Missing position"); } - return new GroupDescriptor(message.getGroupid(), message.getGroupsize(), position); + return new GroupDescriptor(message.getGroupid(), message.getGroupsize(), position, message.getLocked()); } public update(groupDescriptor: GroupDescriptor) { this.groupSize = groupDescriptor.groupSize; this.position = groupDescriptor.position; + this.locked = groupDescriptor.locked; } public toGroupUpdateMessage(): GroupUpdateMessage { @@ -146,7 +152,7 @@ export class GroupDescriptor { groupUpdateMessage.setGroupid(this.groupId); groupUpdateMessage.setGroupsize(this.groupSize); groupUpdateMessage.setPosition(this.position); - + groupUpdateMessage.setLocked(this.locked); return groupUpdateMessage; } } @@ -206,9 +212,7 @@ export class Zone { this.notifyGroupMove(groupDescriptor); } else { this.groups.set(groupId, groupDescriptor); - const fromZone = groupUpdateZoneMessage.getFromzone(); - this.notifyGroupEnter(groupDescriptor, fromZone?.toObject()); } } else if (message.hasUserleftzonemessage()) { diff --git a/pusher/src/Services/SocketManager.ts b/pusher/src/Services/SocketManager.ts index aac93c5d..d1257cf4 100644 --- a/pusher/src/Services/SocketManager.ts +++ b/pusher/src/Services/SocketManager.ts @@ -38,6 +38,7 @@ import { ErrorMessage, WorldFullMessage, PlayerDetailsUpdatedMessage, + LockGroupPromptMessage, InvalidTextureMessage, } from "../Messages/generated/messages_pb"; import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils"; @@ -304,6 +305,12 @@ export class SocketManager implements ZoneEventListener { client.backConnection.write(pusherToBackMessage); } + handleLockGroup(client: ExSocketInterface, message: LockGroupPromptMessage): void { + const pusherToBackMessage = new PusherToBackMessage(); + pusherToBackMessage.setLockgrouppromptmessage(message); + client.backConnection.write(pusherToBackMessage); + } + onEmote(emoteMessage: EmoteEventMessage, listener: ExSocketInterface): void { const subMessage = new SubMessage(); subMessage.setEmoteeventmessage(emoteMessage);