From 8d8857011ea9fae0933af2802ef7f040db987843 Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Wed, 23 Feb 2022 14:40:19 +0100 Subject: [PATCH 01/16] removed unused imports --- front/src/Connexion/RoomConnection.ts | 17 +---------------- front/src/Phaser/Game/GameScene.ts | 1 + 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/front/src/Connexion/RoomConnection.ts b/front/src/Connexion/RoomConnection.ts index 4e2f8397..584a1a51 100644 --- a/front/src/Connexion/RoomConnection.ts +++ b/front/src/Connexion/RoomConnection.ts @@ -5,15 +5,11 @@ import type { UserSimplePeerInterface } from "../WebRtc/SimplePeer"; import { ProtobufClientUtils } from "../Network/ProtobufClientUtils"; import type { GroupCreatedUpdatedMessageInterface, - ItemEventMessageInterface, MessageUserJoined, - OnConnectInterface, - PlayerDetailsUpdatedMessageInterface, PlayGlobalMessageInterface, PositionInterface, RoomJoinedMessageInterface, ViewportInterface, - WebRtcDisconnectMessageInterface, WebRtcSignalReceivedMessageInterface, } from "./ConnexionModels"; import type { BodyResourceDescriptionInterface } from "../Phaser/Entity/PlayerTextures"; @@ -21,31 +17,22 @@ import { adminMessagesService } from "./AdminMessagesService"; import { connectionManager } from "./ConnectionManager"; import { get } from "svelte/store"; import { warningContainerStore } from "../Stores/MenuStore"; -import { followStateStore, followRoleStore, followUsersStore } from "../Stores/FollowStore"; +import { 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, @@ -54,8 +41,6 @@ import { PingMessage as PingMessageTsProto, } from "../Messages/ts-proto-generated/messages"; import { Subject } from "rxjs"; -import { OpenPopupEvent } from "../Api/Events/OpenPopupEvent"; -import { match } from "assert"; const manualPingDelay = 20000; diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 0a44cea3..274ae573 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -1976,6 +1976,7 @@ ${escapedMessage} } private doShareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface) { + console.log(groupPositionMessage); //delete previous group this.doDeleteGroup(groupPositionMessage.groupId); From 724dbc8efac7a8eea78260e7787c5d8f4be9ab81 Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Mon, 28 Feb 2022 13:47:08 +0100 Subject: [PATCH 02/16] send group userIds to players --- back/src/Model/Group.ts | 2 +- back/src/Services/SocketManager.ts | 24 ++++++++++++++++++++++-- front/src/Connexion/ConnexionModels.ts | 5 +++++ front/src/Connexion/RoomConnection.ts | 10 ++++++++++ front/src/Phaser/Game/GameScene.ts | 1 - messages/protos/messages.proto | 6 ++++++ 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/back/src/Model/Group.ts b/back/src/Model/Group.ts index c14d509f..65e15c40 100644 --- a/back/src/Model/Group.ts +++ b/back/src/Model/Group.ts @@ -147,9 +147,9 @@ export class Group implements Movable { 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 { diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index 9233811b..c396893d 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -38,6 +38,7 @@ import { SubToPusherRoomMessage, SetPlayerDetailsMessage, PlayerDetailsUpdatedMessage, + GroupUsersUpdateMessage, } from "../Messages/generated/messages_pb"; import { User, UserSocket } from "../Model/User"; import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils"; @@ -265,8 +266,14 @@ 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) => @@ -438,6 +445,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) { diff --git a/front/src/Connexion/ConnexionModels.ts b/front/src/Connexion/ConnexionModels.ts index bf834a02..3d8893a2 100644 --- a/front/src/Connexion/ConnexionModels.ts +++ b/front/src/Connexion/ConnexionModels.ts @@ -47,6 +47,11 @@ export interface GroupCreatedUpdatedMessageInterface { groupSize: number; } +export interface GroupUsersUpdateMessageInterface { + groupId: number; + userIds: number[]; +} + export interface WebRtcDisconnectMessageInterface { userId: number; } diff --git a/front/src/Connexion/RoomConnection.ts b/front/src/Connexion/RoomConnection.ts index 584a1a51..95c91cd5 100644 --- a/front/src/Connexion/RoomConnection.ts +++ b/front/src/Connexion/RoomConnection.ts @@ -5,6 +5,7 @@ import type { UserSimplePeerInterface } from "../WebRtc/SimplePeer"; import { ProtobufClientUtils } from "../Network/ProtobufClientUtils"; import type { GroupCreatedUpdatedMessageInterface, + GroupUsersUpdateMessageInterface, MessageUserJoined, PlayGlobalMessageInterface, PositionInterface, @@ -97,6 +98,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(); @@ -398,6 +402,12 @@ export class RoomConnection implements RoomConnection { this._sendJitsiJwtMessageStream.next(message.sendJitsiJwtMessage); break; } + case "groupUsersUpdateMessage": { + console.log("GOT GROUP USERS UPDATE MESSAGE"); + console.log(message.groupUsersUpdateMessage); + this._groupUsersUpdateMessageStream.next(message.groupUsersUpdateMessage); + break; + } case "sendUserMessage": { adminMessagesService.onSendusermessage(message.sendUserMessage); break; diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 274ae573..0a44cea3 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -1976,7 +1976,6 @@ ${escapedMessage} } private doShareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface) { - console.log(groupPositionMessage); //delete previous group this.doDeleteGroup(groupPositionMessage.groupId); diff --git a/messages/protos/messages.proto b/messages/protos/messages.proto index 8ac7bbf0..5c9c95b7 100644 --- a/messages/protos/messages.proto +++ b/messages/protos/messages.proto @@ -215,6 +215,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; @@ -310,6 +315,7 @@ message ServerToClientMessage { FollowRequestMessage followRequestMessage = 21; FollowConfirmationMessage followConfirmationMessage = 22; FollowAbortMessage followAbortMessage = 23; + GroupUsersUpdateMessage groupUsersUpdateMessage = 24; } } From d43c8d181af71542abe1c268de8a0bcaf4aaaca6 Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Tue, 1 Mar 2022 11:36:45 +0100 Subject: [PATCH 03/16] sending info about group lock state. wip --- back/src/Model/GameRoom.ts | 2 +- back/src/Model/Group.ts | 9 +++++++++ back/src/RoomManager.ts | 8 ++++++++ back/src/Services/SocketManager.ts | 7 +++++++ front/src/Connexion/ConnexionModels.ts | 1 + front/src/Connexion/RoomConnection.ts | 15 +++++++++++++++ front/src/Phaser/Game/GameScene.ts | 20 +++++++++++++++++++- messages/protos/messages.proto | 11 +++++++++++ pusher/src/Controller/IoSocketController.ts | 3 +++ pusher/src/Model/Zone.ts | 15 +++++++++++++-- pusher/src/Services/SocketManager.ts | 7 +++++++ 11 files changed, 94 insertions(+), 4 deletions(-) diff --git a/back/src/Model/GameRoom.ts b/back/src/Model/GameRoom.ts index 7d7b24a5..b55c6079 100644 --- a/back/src/Model/GameRoom.ts +++ b/back/src/Model/GameRoom.ts @@ -418,7 +418,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()); diff --git a/back/src/Model/Group.ts b/back/src/Model/Group.ts index 65e15c40..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,6 +142,10 @@ export class Group implements Movable { return this.users.size >= MAX_PER_GROUP; } + isLocked(): boolean { + return this.locked; + } + isEmpty(): boolean { return this.users.size <= 1; } @@ -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/RoomManager.ts b/back/src/RoomManager.ts index d375fbd8..b5e27982 100644 --- a/back/src/RoomManager.ts +++ b/back/src/RoomManager.ts @@ -29,6 +29,7 @@ import { WebRtcSignalToServerMessage, WorldFullWarningToRoomMessage, ZoneMessage, + LockGroupMessage, } from "./Messages/generated/messages_pb"; import { sendUnaryData, ServerDuplexStream, ServerUnaryCall, ServerWritableStream } from "grpc"; import { socketManager } from "./Services/SocketManager"; @@ -135,6 +136,11 @@ const roomManager: IRoomManagerServer = { user, message.getFollowabortmessage() as FollowAbortMessage ); + } else if (message.hasLockgroupmessage()) { + socketManager.handleLockGroupMessage( + user, + message.getLockgroupmessage() as LockGroupMessage + ); } else if (message.hasSendusermessage()) { const sendUserMessage = message.getSendusermessage(); socketManager.handleSendUserMessage(user, sendUserMessage as SendUserMessage); @@ -148,6 +154,8 @@ const roomManager: IRoomManagerServer = { user, setPlayerDetailsMessage as SetPlayerDetailsMessage ); + } else if (message.hasLockgroupmessage()) { + console.log("===== GOT LOCK GROUP MESSAGE FROM CLIENT ====="); } else { throw new Error("Unhandled message type"); } diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index c396893d..af0ec6cf 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -39,6 +39,7 @@ import { SetPlayerDetailsMessage, PlayerDetailsUpdatedMessage, GroupUsersUpdateMessage, + LockGroupMessage, } from "../Messages/generated/messages_pb"; import { User, UserSocket } from "../Model/User"; import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils"; @@ -404,6 +405,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); @@ -889,6 +891,11 @@ export class SocketManager { leader?.delFollower(user); } } + + handleLockGroupMessage(user: User, message: LockGroupMessage) { + console.log(`lock group: ${message.getLock()}`); + user.group?.lock(message.getLock()); + } } export const socketManager = new SocketManager(); diff --git a/front/src/Connexion/ConnexionModels.ts b/front/src/Connexion/ConnexionModels.ts index 3d8893a2..04282abc 100644 --- a/front/src/Connexion/ConnexionModels.ts +++ b/front/src/Connexion/ConnexionModels.ts @@ -45,6 +45,7 @@ export interface GroupCreatedUpdatedMessageInterface { position: PositionInterface; groupId: number; groupSize: number; + locked: boolean; } export interface GroupUsersUpdateMessageInterface { diff --git a/front/src/Connexion/RoomConnection.ts b/front/src/Connexion/RoomConnection.ts index 95c91cd5..0f932901 100644 --- a/front/src/Connexion/RoomConnection.ts +++ b/front/src/Connexion/RoomConnection.ts @@ -636,6 +636,7 @@ export class RoomConnection implements RoomConnection { groupId: message.groupId, position: position, groupSize: message.groupSize, + locked: message.locked, }; } @@ -851,6 +852,20 @@ export class RoomConnection implements RoomConnection { this.socket.send(bytes); } + public emitLockGroup(groupId: number, lock: boolean = true): void { + const bytes = ClientToServerMessageTsProto.encode({ + message: { + $case: "lockGroupMessage", + lockGroupMessage: { + groupId, + 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 0a44cea3..c0d82d24 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -718,6 +718,16 @@ export class GameScene extends DirtyScene { e ) ); + + this.input.keyboard.on("keydown-L", (event: Event) => { + console.log("group locked"); + this.connection?.emitLockGroup(1, true); + }); + + this.input.keyboard.on("keydown-U", (event: Event) => { + console.log("group unlocked"); + this.connection?.emitLockGroup(1, false); + }); } /** @@ -782,6 +792,7 @@ export class GameScene extends DirtyScene { this.connection.groupUpdateMessageStream.subscribe( (groupPositionMessage: GroupCreatedUpdatedMessageInterface) => { + console.log(groupPositionMessage); this.shareGroupPosition(groupPositionMessage); } ); @@ -1809,8 +1820,13 @@ ${escapedMessage} break; } case "GroupCreatedUpdatedEvent": + console.log("CREATE OR UPDATE GROUP"); this.doShareGroupPosition(event.event); break; + // TODO: CALL THIS ON GROUP LOCK CHANGE + // case "GroupCreatedUpdatedEvent": + // this.doShareGroupPosition(event.event); + // break; case "DeleteGroupEvent": this.doDeleteGroup(event.groupId); break; @@ -1985,7 +2001,9 @@ ${escapedMessage} 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); diff --git a/messages/protos/messages.proto b/messages/protos/messages.proto index 5c9c95b7..4ccaed4b 100644 --- a/messages/protos/messages.proto +++ b/messages/protos/messages.proto @@ -98,6 +98,11 @@ message FollowAbortMessage { int32 follower = 2; } +message LockGroupMessage { + int32 groupId = 1; + bool lock = 2; +} + message ClientToServerMessage { oneof message { UserMovesMessage userMovesMessage = 2; @@ -116,6 +121,7 @@ message ClientToServerMessage { FollowRequestMessage followRequestMessage = 15; FollowConfirmationMessage followConfirmationMessage = 16; FollowAbortMessage followAbortMessage = 17; + LockGroupMessage lockGroupMessage = 18; } } @@ -172,6 +178,7 @@ message SubMessage { VariableMessage variableMessage = 8; ErrorMessage errorMessage = 9; PlayerDetailsUpdatedMessage playerDetailsUpdatedMessage = 10; + LockGroupMessage lockGroupMessage = 11; } } @@ -184,6 +191,7 @@ message GroupUpdateMessage { int32 groupId = 1; PointMessage position = 2; int32 groupSize = 3; + bool locked = 4; } message GroupDeleteMessage { @@ -316,6 +324,7 @@ message ServerToClientMessage { FollowConfirmationMessage followConfirmationMessage = 22; FollowAbortMessage followAbortMessage = 23; GroupUsersUpdateMessage groupUsersUpdateMessage = 24; + LockGroupMessage lockGroupMessage = 25; } } @@ -358,6 +367,7 @@ message GroupUpdateZoneMessage { PointMessage position = 2; int32 groupSize = 3; Zone fromZone = 4; + bool locked = 5; } message GroupLeftZoneMessage { @@ -403,6 +413,7 @@ message PusherToBackMessage { FollowRequestMessage followRequestMessage = 16; FollowConfirmationMessage followConfirmationMessage = 17; FollowAbortMessage followAbortMessage = 18; + LockGroupMessage lockGroupMessage = 19; } } diff --git a/pusher/src/Controller/IoSocketController.ts b/pusher/src/Controller/IoSocketController.ts index 6db53403..617da341 100644 --- a/pusher/src/Controller/IoSocketController.ts +++ b/pusher/src/Controller/IoSocketController.ts @@ -21,6 +21,7 @@ import { FollowConfirmationMessage, FollowAbortMessage, VariableMessage, + LockGroupMessage, } from "../Messages/generated/messages_pb"; import { UserMovesMessage } from "../Messages/generated/messages_pb"; import { TemplatedApp } from "uWebSockets.js"; @@ -494,6 +495,8 @@ 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); } /* 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..1bf1090a 100644 --- a/pusher/src/Model/Zone.ts +++ b/pusher/src/Model/Zone.ts @@ -32,6 +32,7 @@ export interface ZoneEventListener { onGroupEnters(group: GroupDescriptor, listener: ExSocketInterface): void; onGroupMoves(group: GroupDescriptor, listener: ExSocketInterface): void; onGroupLeaves(groupId: number, listener: ExSocketInterface): void; + // onGroupLock(groupId: number, listener: ExSocketInterface): void; onEmote(emoteMessage: EmoteEventMessage, listener: ExSocketInterface): void; onError(errorMessage: ErrorMessage, listener: ExSocketInterface): void; onPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ExSocketInterface): void; @@ -123,19 +124,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,6 +153,7 @@ export class GroupDescriptor { groupUpdateMessage.setGroupid(this.groupId); groupUpdateMessage.setGroupsize(this.groupSize); groupUpdateMessage.setPosition(this.position); + groupUpdateMessage.setLocked(this.locked); return groupUpdateMessage; } @@ -238,6 +246,9 @@ export class Zone { } else if (message.hasEmoteeventmessage()) { const emoteEventMessage = message.getEmoteeventmessage() as EmoteEventMessage; this.notifyEmote(emoteEventMessage); + } else if (message.hasEmoteeventmessage()) { + const emoteEventMessage = message.getEmoteeventmessage() as EmoteEventMessage; + this.notifyEmote(emoteEventMessage); } else if (message.hasPlayerdetailsupdatedmessage()) { const playerDetailsUpdatedMessage = message.getPlayerdetailsupdatedmessage() as PlayerDetailsUpdatedMessage; diff --git a/pusher/src/Services/SocketManager.ts b/pusher/src/Services/SocketManager.ts index 30fe761f..b1006bf8 100644 --- a/pusher/src/Services/SocketManager.ts +++ b/pusher/src/Services/SocketManager.ts @@ -38,6 +38,7 @@ import { ErrorMessage, WorldFullMessage, PlayerDetailsUpdatedMessage, + LockGroupMessage, } 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"; @@ -292,6 +293,12 @@ export class SocketManager implements ZoneEventListener { client.backConnection.write(pusherToBackMessage); } + handleLockGroup(client: ExSocketInterface, message: LockGroupMessage): void { + const pusherToBackMessage = new PusherToBackMessage(); + pusherToBackMessage.setLockgroupmessage(message); + client.backConnection.write(pusherToBackMessage); + } + onEmote(emoteMessage: EmoteEventMessage, listener: ExSocketInterface): void { const subMessage = new SubMessage(); subMessage.setEmoteeventmessage(emoteMessage); From ef22d4ba209972b61f64810c9ffd0d1701323397 Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Wed, 2 Mar 2022 10:44:26 +0100 Subject: [PATCH 04/16] listening to lockGroupMessage on front --- back/src/Model/GameRoom.ts | 12 +++++ back/src/Model/PositionNotifier.ts | 13 ++++- back/src/Model/Zone.ts | 10 ++++ back/src/RoomManager.ts | 1 + back/src/Services/SocketManager.ts | 26 ++++++++-- back/tests/PositionNotifierTest.ts | 2 + front/src/Connexion/ConnexionModels.ts | 5 ++ front/src/Connexion/RoomConnection.ts | 10 +++- front/src/Phaser/Game/GameScene.ts | 66 +++++++++++++++++++++----- messages/protos/messages.proto | 1 + pusher/src/Model/Zone.ts | 15 ++++-- pusher/src/Services/SocketManager.ts | 7 +++ 12 files changed, 145 insertions(+), 23 deletions(-) diff --git a/back/src/Model/GameRoom.ts b/back/src/Model/GameRoom.ts index b55c6079..d6a6c7c2 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"; @@ -22,6 +23,7 @@ import { VariableMessage, VariableWithTagMessage, ServerToClientMessage, + LockGroupMessage, } from "../Messages/generated/messages_pb"; import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils"; import { RoomSocket, ZoneSocket } from "src/RoomManager"; @@ -66,6 +68,7 @@ export class GameRoom { onMoves: MovesCallback, onLeaves: LeavesCallback, onEmote: EmoteCallback, + onLockGroup: LockGroupCallback, onPlayerDetailsUpdated: PlayerDetailsUpdatedCallback ) { // A zone is 10 sprites wide. @@ -76,6 +79,7 @@ export class GameRoom { onMoves, onLeaves, onEmote, + onLockGroup, onPlayerDetailsUpdated ); } @@ -90,6 +94,7 @@ export class GameRoom { onMoves: MovesCallback, onLeaves: LeavesCallback, onEmote: EmoteCallback, + onLockGroup: LockGroupCallback, onPlayerDetailsUpdated: PlayerDetailsUpdatedCallback ): Promise { const mapDetails = await GameRoom.getMapDetails(roomUrl); @@ -105,6 +110,7 @@ export class GameRoom { onMoves, onLeaves, onEmote, + onLockGroup, onPlayerDetailsUpdated ); @@ -544,6 +550,12 @@ export class GameRoom { this.positionNotifier.emitEmoteEvent(user, emoteEventMessage); } + public emitLockGroupMessage(user: User, lockGroupMessage: LockGroupMessage) { + console.log("D2 GAME ROOM EMIT LOCK GROUP MESSAGE"); + console.log(lockGroupMessage.getGroupid()); + this.positionNotifier.emitLockGroupEvent(user, lockGroupMessage); + } + public addRoomListener(socket: RoomSocket) { this.roomListeners.add(socket); } diff --git a/back/src/Model/PositionNotifier.ts b/back/src/Model/PositionNotifier.ts index b059999a..ad7334f9 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, @@ -20,7 +21,7 @@ import { Movable } from "_Model/Movable"; import { PositionInterface } from "_Model/PositionInterface"; import { ZoneSocket } from "../RoomManager"; import { User } from "../Model/User"; -import { EmoteEventMessage, SetPlayerDetailsMessage } from "../Messages/generated/messages_pb"; +import { EmoteEventMessage, LockGroupMessage, SetPlayerDetailsMessage } from "../Messages/generated/messages_pb"; interface ZoneDescriptor { i: number; @@ -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,14 @@ export class PositionNotifier { zone.emitEmoteEvent(emoteEventMessage); } + public emitLockGroupEvent(user: User, lockGroupMessage: LockGroupMessage) { + const zoneDesc = this.getZoneDescriptorFromCoordinates(user.getPosition().x, user.getPosition().y); + const zone = this.getZone(zoneDesc.i, zoneDesc.j); + console.log("D3 emit from ZONE"); + console.log(lockGroupMessage.getGroupid()); + zone.emitLockGroupEvent(lockGroupMessage); + } + 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..35bb4660 100644 --- a/back/src/Model/Zone.ts +++ b/back/src/Model/Zone.ts @@ -7,12 +7,14 @@ import { EmoteEventMessage, SetPlayerDetailsMessage, PlayerDetailsUpdatedMessage, + LockGroupMessage, } from "../Messages/generated/messages_pb"; export type EntersCallback = (thing: Movable, fromZone: Zone | null, listener: ZoneSocket) => void; 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 = (lockGroupMessage: LockGroupMessage, listener: ZoneSocket) => void; export type PlayerDetailsUpdatedCallback = ( playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ZoneSocket @@ -27,6 +29,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 +111,13 @@ export class Zone { } } + public emitLockGroupEvent(lockGroupMessage: LockGroupMessage) { + console.log("D4 ZONE ON LOCK GROUP CALLBACK"); + for (const listener of this.listeners) { + this.onLockGroup(lockGroupMessage, 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 b5e27982..6a091054 100644 --- a/back/src/RoomManager.ts +++ b/back/src/RoomManager.ts @@ -138,6 +138,7 @@ const roomManager: IRoomManagerServer = { ); } else if (message.hasLockgroupmessage()) { socketManager.handleLockGroupMessage( + room, user, message.getLockgroupmessage() as LockGroupMessage ); diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index af0ec6cf..aaa373fb 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -285,6 +285,8 @@ export class SocketManager { this.onClientLeave(thing, newZone, listener), (emoteEventMessage: EmoteEventMessage, listener: ZoneSocket) => this.onEmote(emoteEventMessage, listener), + (lockGroupMessage: LockGroupMessage, listener: ZoneSocket) => + this.onLockGroup(lockGroupMessage, listener), (playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ZoneSocket) => this.onPlayerDetailsUpdated(playerDetailsUpdatedMessage, listener) ) @@ -388,6 +390,16 @@ export class SocketManager { emitZoneMessage(subMessage, client); } + private onLockGroup(lockGroupMessage: LockGroupMessage, client: ZoneSocket) { + const subMessage = new SubToPusherMessage(); + subMessage.setLockgroupmessage(lockGroupMessage); + console.log("D5 SOCKET MANAGER ON LOCK GROUP"); + console.log(lockGroupMessage.getGroupid()); + console.log(lockGroupMessage.getLock()); + + emitZoneMessage(subMessage, client); + } + private onPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, client: ZoneSocket) { const subMessage = new SubToPusherMessage(); subMessage.setPlayerdetailsupdatedmessage(playerDetailsUpdatedMessage); @@ -892,9 +904,17 @@ export class SocketManager { } } - handleLockGroupMessage(user: User, message: LockGroupMessage) { - console.log(`lock group: ${message.getLock()}`); - user.group?.lock(message.getLock()); + handleLockGroupMessage(room: GameRoom, user: User, message: LockGroupMessage) { + console.log("D1 HANDLE LOCK GROUP MESSAGE"); + const group = user.group; + if (!group) { + return; + } + group.lock(message.getLock()); + const lockGroupMessage = new LockGroupMessage(); + lockGroupMessage.setLock(message.getLock()); + lockGroupMessage.setGroupid(message.getGroupid()); + room.emitLockGroupMessage(user, lockGroupMessage); } } 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/Connexion/ConnexionModels.ts b/front/src/Connexion/ConnexionModels.ts index 04282abc..5b41e602 100644 --- a/front/src/Connexion/ConnexionModels.ts +++ b/front/src/Connexion/ConnexionModels.ts @@ -48,6 +48,11 @@ export interface GroupCreatedUpdatedMessageInterface { locked: boolean; } +export interface LockGroupMessageInterface { + groupId: number; + locked: boolean; +} + export interface GroupUsersUpdateMessageInterface { groupId: number; userIds: number[]; diff --git a/front/src/Connexion/RoomConnection.ts b/front/src/Connexion/RoomConnection.ts index 0f932901..3d69f38a 100644 --- a/front/src/Connexion/RoomConnection.ts +++ b/front/src/Connexion/RoomConnection.ts @@ -40,6 +40,7 @@ import { PositionMessage_Direction, SetPlayerDetailsMessage as SetPlayerDetailsMessageTsProto, PingMessage as PingMessageTsProto, + LockGroupMessage, } from "../Messages/ts-proto-generated/messages"; import { Subject } from "rxjs"; @@ -101,6 +102,9 @@ export class RoomConnection implements RoomConnection { private readonly _groupUsersUpdateMessageStream = new Subject(); public readonly groupUsersUpdateMessageStream = this._groupUsersUpdateMessageStream.asObservable(); + private readonly _lockGroupMessageStream = new Subject(); + public readonly lockGroupMessageStream = this._lockGroupMessageStream.asObservable(); + private readonly _groupDeleteMessageStream = new Subject(); public readonly groupDeleteMessageStream = this._groupDeleteMessageStream.asObservable(); @@ -264,6 +268,10 @@ export class RoomConnection implements RoomConnection { this._emoteEventMessageStream.next(subMessage.emoteEventMessage); break; } + case "lockGroupMessage": { + this._lockGroupMessageStream.next(subMessage.lockGroupMessage); + break; + } case "playerDetailsUpdatedMessage": { this._playerDetailsUpdatedMessageStream.next(subMessage.playerDetailsUpdatedMessage); break; @@ -403,8 +411,6 @@ export class RoomConnection implements RoomConnection { break; } case "groupUsersUpdateMessage": { - console.log("GOT GROUP USERS UPDATE MESSAGE"); - console.log(message.groupUsersUpdateMessage); this._groupUsersUpdateMessageStream.next(message.groupUsersUpdateMessage); break; } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index c0d82d24..7b92a5d1 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -51,6 +51,7 @@ import { PathfindingManager } from "../../Utils/PathfindingManager"; import { ActivatablesManager } from "./ActivatablesManager"; import type { GroupCreatedUpdatedMessageInterface, + LockGroupMessageInterface, MessageUserMovedInterface, MessageUserPositionInterface, OnConnectInterface, @@ -132,6 +133,11 @@ interface DeleteGroupEventInterface { groupId: number; } +interface LockGroupEventInterface { + type: "LockGroupEvent"; + event: LockGroupMessageInterface; +} + interface PlayerDetailsUpdatedInterface { type: "PlayerDetailsUpdated"; details: PlayerDetailsUpdatedMessageInterface; @@ -147,6 +153,7 @@ export class GameScene extends DirtyScene { mapFile!: ITiledMap; animatedTiles!: AnimatedTiles; groups: Map; + currentPlayerGroupId?: number; circleTexture!: CanvasTexture; circleRedTexture!: CanvasTexture; pendingEvents = new Queue< @@ -156,6 +163,7 @@ export class GameScene extends DirtyScene { | UserMovedEventInterface | GroupCreatedUpdatedEventInterface | DeleteGroupEventInterface + | LockGroupEventInterface | PlayerDetailsUpdatedInterface >(); private initPosition: PositionInterface | null = null; @@ -225,6 +233,7 @@ export class GameScene extends DirtyScene { }); this.Terrains = []; this.groups = new Map(); + this.currentPlayerGroupId = undefined; this.instance = room.getInstance(); this.MapUrlFile = MapUrlFile; @@ -720,13 +729,17 @@ export class GameScene extends DirtyScene { ); this.input.keyboard.on("keydown-L", (event: Event) => { - console.log("group locked"); - this.connection?.emitLockGroup(1, true); + if (this.currentPlayerGroupId !== undefined) { + console.log("group locked"); + this.connection?.emitLockGroup(this.currentPlayerGroupId, true); + } }); this.input.keyboard.on("keydown-U", (event: Event) => { - console.log("group unlocked"); - this.connection?.emitLockGroup(1, false); + if (this.currentPlayerGroupId !== undefined) { + console.log("group unlocked"); + this.connection?.emitLockGroup(this.currentPlayerGroupId, false); + } }); } @@ -792,7 +805,6 @@ export class GameScene extends DirtyScene { this.connection.groupUpdateMessageStream.subscribe( (groupPositionMessage: GroupCreatedUpdatedMessageInterface) => { - console.log(groupPositionMessage); this.shareGroupPosition(groupPositionMessage); } ); @@ -805,6 +817,10 @@ export class GameScene extends DirtyScene { } }); + this.connection.lockGroupMessageStream.subscribe((message) => { + this.lockGroup(message); + }); + this.connection.onServerDisconnected(() => { console.log("Player disconnected from server. Reloading scene."); this.cleanupClosingScene(); @@ -838,6 +854,12 @@ export class GameScene extends DirtyScene { }); }); + this.connection.groupUsersUpdateMessageStream.subscribe((message) => { + this.currentPlayerGroupId = message.groupId; + console.log("GOT GROUP USERS UPDATE MESSAGE"); + console.log(message); + }); + /** * Triggered when we receive the JWT token to connect to Jitsi */ @@ -1820,19 +1842,22 @@ ${escapedMessage} break; } case "GroupCreatedUpdatedEvent": - console.log("CREATE OR UPDATE GROUP"); this.doShareGroupPosition(event.event); break; - // TODO: CALL THIS ON GROUP LOCK CHANGE - // 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); + if (this.currentPlayerGroupId === event.groupId) { + this.currentPlayerGroupId = undefined; + } + break; + } + case "LockGroupEvent": { + this.doLockGroup(event.event); + break; + } default: { const tmp: never = event; } @@ -2027,6 +2052,21 @@ ${escapedMessage} this.groups.delete(groupId); } + lockGroup(event: LockGroupMessageInterface): void { + this.pendingEvents.enqueue({ + type: "LockGroupEvent", + event, + }); + } + + doLockGroup(event: LockGroupMessageInterface): void { + const group = this.groups.get(event.groupId); + if (!group) { + return; + } + group.setTexture(event.lock ? "circleSprite-red" : "circleSprite-white"); + } + doUpdatePlayerDetails(message: PlayerDetailsUpdatedMessageInterface): void { const character = this.MapPlayersByKey.get(message.userId); if (character === undefined) { diff --git a/messages/protos/messages.proto b/messages/protos/messages.proto index 4ccaed4b..4708f37d 100644 --- a/messages/protos/messages.proto +++ b/messages/protos/messages.proto @@ -434,6 +434,7 @@ message SubToPusherMessage { EmoteEventMessage emoteEventMessage = 9; ErrorMessage errorMessage = 10; PlayerDetailsUpdatedMessage playerDetailsUpdatedMessage = 11; + LockGroupMessage lockGroupMessage = 12; } } diff --git a/pusher/src/Model/Zone.ts b/pusher/src/Model/Zone.ts index 1bf1090a..50d684a1 100644 --- a/pusher/src/Model/Zone.ts +++ b/pusher/src/Model/Zone.ts @@ -18,6 +18,7 @@ import { ErrorMessage, PlayerDetailsUpdatedMessage, SetPlayerDetailsMessage, + LockGroupMessage, } from "../Messages/generated/messages_pb"; import { ClientReadableStream } from "grpc"; import { PositionDispatcher } from "_Model/PositionDispatcher"; @@ -32,7 +33,7 @@ export interface ZoneEventListener { onGroupEnters(group: GroupDescriptor, listener: ExSocketInterface): void; onGroupMoves(group: GroupDescriptor, listener: ExSocketInterface): void; onGroupLeaves(groupId: number, listener: ExSocketInterface): void; - // onGroupLock(groupId: number, listener: ExSocketInterface): void; + onLockGroup(lockGroupMessage: LockGroupMessage, listener: ExSocketInterface): void; onEmote(emoteMessage: EmoteEventMessage, listener: ExSocketInterface): void; onError(errorMessage: ErrorMessage, listener: ExSocketInterface): void; onPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ExSocketInterface): void; @@ -246,9 +247,9 @@ export class Zone { } else if (message.hasEmoteeventmessage()) { const emoteEventMessage = message.getEmoteeventmessage() as EmoteEventMessage; this.notifyEmote(emoteEventMessage); - } else if (message.hasEmoteeventmessage()) { - const emoteEventMessage = message.getEmoteeventmessage() as EmoteEventMessage; - this.notifyEmote(emoteEventMessage); + } else if (message.hasLockgroupmessage()) { + const lockGroupMessage = message.getLockgroupmessage() as LockGroupMessage; + this.notifyLockGroup(lockGroupMessage); } else if (message.hasPlayerdetailsupdatedmessage()) { const playerDetailsUpdatedMessage = message.getPlayerdetailsupdatedmessage() as PlayerDetailsUpdatedMessage; @@ -359,6 +360,12 @@ export class Zone { } } + private notifyLockGroup(lockGroupMessage: LockGroupMessage) { + for (const listener of this.listeners) { + this.socketListener.onLockGroup(lockGroupMessage, listener); + } + } + private notifyPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage) { for (const listener of this.listeners) { if (listener.userId === playerDetailsUpdatedMessage.getUserid()) { diff --git a/pusher/src/Services/SocketManager.ts b/pusher/src/Services/SocketManager.ts index b1006bf8..96e599e0 100644 --- a/pusher/src/Services/SocketManager.ts +++ b/pusher/src/Services/SocketManager.ts @@ -306,6 +306,13 @@ export class SocketManager implements ZoneEventListener { emitInBatch(listener, subMessage); } + onLockGroup(lockGroupMessage: LockGroupMessage, listener: ExSocketInterface): void { + const subMessage = new SubMessage(); + subMessage.setLockgroupmessage(lockGroupMessage); + + emitInBatch(listener, subMessage); + } + onPlayerDetailsUpdated( playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ExSocketInterface From a0205bf682ef301922c99c587aa493bd4b7c68ea Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Wed, 2 Mar 2022 17:00:43 +0100 Subject: [PATCH 05/16] cleanup --- back/src/Model/GameRoom.ts | 2 - back/src/Model/PositionNotifier.ts | 2 - back/src/Model/Zone.ts | 1 - back/src/RoomManager.ts | 2 - back/src/Services/SocketManager.ts | 15 ++------ front/src/Components/CameraControls.svelte | 30 ++++++++++++++- front/src/Components/images/lock.svg | 1 + .../images/lock.svg:Zone.Identifier | 3 ++ front/src/Connexion/ConnexionModels.ts | 2 +- front/src/Phaser/Game/GameScene.ts | 37 ++++++++----------- front/src/Stores/CurrentPlayerGroupStore.ts | 4 ++ messages/protos/messages.proto | 1 - pusher/src/Model/Zone.ts | 1 - 13 files changed, 57 insertions(+), 44 deletions(-) create mode 100644 front/src/Components/images/lock.svg create mode 100644 front/src/Components/images/lock.svg:Zone.Identifier create mode 100644 front/src/Stores/CurrentPlayerGroupStore.ts diff --git a/back/src/Model/GameRoom.ts b/back/src/Model/GameRoom.ts index d6a6c7c2..74284ab2 100644 --- a/back/src/Model/GameRoom.ts +++ b/back/src/Model/GameRoom.ts @@ -551,8 +551,6 @@ export class GameRoom { } public emitLockGroupMessage(user: User, lockGroupMessage: LockGroupMessage) { - console.log("D2 GAME ROOM EMIT LOCK GROUP MESSAGE"); - console.log(lockGroupMessage.getGroupid()); this.positionNotifier.emitLockGroupEvent(user, lockGroupMessage); } diff --git a/back/src/Model/PositionNotifier.ts b/back/src/Model/PositionNotifier.ts index ad7334f9..6e1fb195 100644 --- a/back/src/Model/PositionNotifier.ts +++ b/back/src/Model/PositionNotifier.ts @@ -143,8 +143,6 @@ export class PositionNotifier { public emitLockGroupEvent(user: User, lockGroupMessage: LockGroupMessage) { const zoneDesc = this.getZoneDescriptorFromCoordinates(user.getPosition().x, user.getPosition().y); const zone = this.getZone(zoneDesc.i, zoneDesc.j); - console.log("D3 emit from ZONE"); - console.log(lockGroupMessage.getGroupid()); zone.emitLockGroupEvent(lockGroupMessage); } diff --git a/back/src/Model/Zone.ts b/back/src/Model/Zone.ts index 35bb4660..4f49ff55 100644 --- a/back/src/Model/Zone.ts +++ b/back/src/Model/Zone.ts @@ -112,7 +112,6 @@ export class Zone { } public emitLockGroupEvent(lockGroupMessage: LockGroupMessage) { - console.log("D4 ZONE ON LOCK GROUP CALLBACK"); for (const listener of this.listeners) { this.onLockGroup(lockGroupMessage, listener); } diff --git a/back/src/RoomManager.ts b/back/src/RoomManager.ts index 6a091054..8a840c15 100644 --- a/back/src/RoomManager.ts +++ b/back/src/RoomManager.ts @@ -155,8 +155,6 @@ const roomManager: IRoomManagerServer = { user, setPlayerDetailsMessage as SetPlayerDetailsMessage ); - } else if (message.hasLockgroupmessage()) { - console.log("===== GOT LOCK GROUP MESSAGE FROM CLIENT ====="); } else { throw new Error("Unhandled message type"); } diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index aaa373fb..2bfe7cf2 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -70,7 +70,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); } @@ -277,8 +276,9 @@ export class SocketManager { }, 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) => @@ -393,17 +393,12 @@ export class SocketManager { private onLockGroup(lockGroupMessage: LockGroupMessage, client: ZoneSocket) { const subMessage = new SubToPusherMessage(); subMessage.setLockgroupmessage(lockGroupMessage); - console.log("D5 SOCKET MANAGER ON LOCK GROUP"); - console.log(lockGroupMessage.getGroupid()); - console.log(lockGroupMessage.getLock()); - emitZoneMessage(subMessage, client); } private onPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, client: ZoneSocket) { const subMessage = new SubToPusherMessage(); subMessage.setPlayerdetailsupdatedmessage(playerDetailsUpdatedMessage); - emitZoneMessage(subMessage, client); } @@ -433,7 +428,6 @@ export class SocketManager { const subMessage = new SubToPusherMessage(); subMessage.setGroupleftzonemessage(groupDeleteMessage); - emitZoneMessage(subMessage, client); //user.emitInBatch(subMessage); } @@ -445,7 +439,6 @@ export class SocketManager { const subMessage = new SubToPusherMessage(); subMessage.setUserleftzonemessage(userLeftMessage); - emitZoneMessage(subMessage, client); } @@ -667,6 +660,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); @@ -905,7 +899,6 @@ export class SocketManager { } handleLockGroupMessage(room: GameRoom, user: User, message: LockGroupMessage) { - console.log("D1 HANDLE LOCK GROUP MESSAGE"); const group = user.group; if (!group) { return; diff --git a/front/src/Components/CameraControls.svelte b/front/src/Components/CameraControls.svelte index bfe1d9d0..7b189aff 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 { currentPlayerGroupIdStore, currentPlayerGroupLockStateStore } from "../Stores/CurrentPlayerGroupStore"; const gameScene = gameManager.getCurrentGameScene(); @@ -70,6 +72,15 @@ } } + function lockClick() { + console.log($currentPlayerGroupIdStore); + console.log($currentPlayerGroupLockStateStore); + if ($currentPlayerGroupIdStore === undefined) { + return; + } + gameScene.connection?.emitLockGroup($currentPlayerGroupIdStore, !$currentPlayerGroupLockStateStore); + } + let isSilent: boolean; const unsubscribeIsSilent = isSilentStore.subscribe((value) => { isSilent = value; @@ -95,6 +106,15 @@ +
+ +
+
\ No newline at end of file diff --git a/front/src/Components/images/lock.svg:Zone.Identifier b/front/src/Components/images/lock.svg:Zone.Identifier new file mode 100644 index 00000000..053d1127 --- /dev/null +++ b/front/src/Components/images/lock.svg:Zone.Identifier @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +HostUrl=about:internet diff --git a/front/src/Connexion/ConnexionModels.ts b/front/src/Connexion/ConnexionModels.ts index 5b41e602..167624e6 100644 --- a/front/src/Connexion/ConnexionModels.ts +++ b/front/src/Connexion/ConnexionModels.ts @@ -50,7 +50,7 @@ export interface GroupCreatedUpdatedMessageInterface { export interface LockGroupMessageInterface { groupId: number; - locked: boolean; + lock: boolean; } export interface GroupUsersUpdateMessageInterface { diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 7b92a5d1..8b2112b9 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -77,6 +77,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; @@ -153,7 +154,6 @@ export class GameScene extends DirtyScene { mapFile!: ITiledMap; animatedTiles!: AnimatedTiles; groups: Map; - currentPlayerGroupId?: number; circleTexture!: CanvasTexture; circleRedTexture!: CanvasTexture; pendingEvents = new Queue< @@ -185,6 +185,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; @@ -226,6 +227,7 @@ export class GameScene extends DirtyScene { private loader: Loader; private lastCameraEvent: WasCameraUpdatedEvent | undefined; private firstCameraUpdateSent: boolean = false; + private currentPlayerGroupId?: number; constructor(private room: Room, MapUrlFile: string, customKey?: string | undefined) { super({ @@ -233,7 +235,6 @@ export class GameScene extends DirtyScene { }); this.Terrains = []; this.groups = new Map(); - this.currentPlayerGroupId = undefined; this.instance = room.getInstance(); this.MapUrlFile = MapUrlFile; @@ -717,6 +718,10 @@ export class GameScene extends DirtyScene { } }); + this.currentPlayerGroupIdStoreUnsubscribe = currentPlayerGroupIdStore.subscribe((groupId) => { + this.currentPlayerGroupId = groupId; + }); + Promise.all([this.connectionAnswerPromise as Promise, ...scriptPromises]) .then(() => { this.scene.wake(); @@ -727,20 +732,6 @@ export class GameScene extends DirtyScene { e ) ); - - this.input.keyboard.on("keydown-L", (event: Event) => { - if (this.currentPlayerGroupId !== undefined) { - console.log("group locked"); - this.connection?.emitLockGroup(this.currentPlayerGroupId, true); - } - }); - - this.input.keyboard.on("keydown-U", (event: Event) => { - if (this.currentPlayerGroupId !== undefined) { - console.log("group unlocked"); - this.connection?.emitLockGroup(this.currentPlayerGroupId, false); - } - }); } /** @@ -855,9 +846,8 @@ export class GameScene extends DirtyScene { }); this.connection.groupUsersUpdateMessageStream.subscribe((message) => { - this.currentPlayerGroupId = message.groupId; - console.log("GOT GROUP USERS UPDATE MESSAGE"); - console.log(message); + // TODO: how else can we deduce our current group? + currentPlayerGroupIdStore.set(message.groupId); }); /** @@ -1849,9 +1839,8 @@ ${escapedMessage} break; case "DeleteGroupEvent": { this.doDeleteGroup(event.groupId); - if (this.currentPlayerGroupId === event.groupId) { - this.currentPlayerGroupId = undefined; - } + currentPlayerGroupIdStore.set(undefined); + currentPlayerGroupLockStateStore.set(undefined); break; } case "LockGroupEvent": { @@ -2033,6 +2022,9 @@ ${escapedMessage} 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; } @@ -2064,6 +2056,7 @@ ${escapedMessage} if (!group) { return; } + currentPlayerGroupLockStateStore.set(event.lock); group.setTexture(event.lock ? "circleSprite-red" : "circleSprite-white"); } 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 4708f37d..3db0da95 100644 --- a/messages/protos/messages.proto +++ b/messages/protos/messages.proto @@ -324,7 +324,6 @@ message ServerToClientMessage { FollowConfirmationMessage followConfirmationMessage = 22; FollowAbortMessage followAbortMessage = 23; GroupUsersUpdateMessage groupUsersUpdateMessage = 24; - LockGroupMessage lockGroupMessage = 25; } } diff --git a/pusher/src/Model/Zone.ts b/pusher/src/Model/Zone.ts index 50d684a1..451597b9 100644 --- a/pusher/src/Model/Zone.ts +++ b/pusher/src/Model/Zone.ts @@ -155,7 +155,6 @@ export class GroupDescriptor { groupUpdateMessage.setGroupsize(this.groupSize); groupUpdateMessage.setPosition(this.position); groupUpdateMessage.setLocked(this.locked); - return groupUpdateMessage; } } From a0535ed4a84cff750f7e23f8ae27dcd306723085 Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Thu, 3 Mar 2022 12:22:16 +0100 Subject: [PATCH 06/16] Updating GroupDescriptors on LockGroupMessage --- back/src/RoomManager.ts | 6 +++--- back/src/Services/SocketManager.ts | 5 +++-- front/src/Components/CameraControls.svelte | 9 ++------- front/src/Connexion/RoomConnection.ts | 7 +++---- messages/protos/messages.proto | 8 ++++++-- pusher/src/Controller/IoSocketController.ts | 8 ++++++-- pusher/src/Model/PositionDispatcher.ts | 1 + pusher/src/Model/Zone.ts | 14 ++++++++++++-- pusher/src/Services/SocketManager.ts | 6 ++++-- 9 files changed, 40 insertions(+), 24 deletions(-) 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); From 5706e5c41631f6e038f36ae7d8941219b0e80ce7 Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Thu, 3 Mar 2022 12:31:17 +0100 Subject: [PATCH 07/16] remove console logs --- pusher/src/Model/PositionDispatcher.ts | 1 - pusher/src/Services/SocketManager.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/pusher/src/Model/PositionDispatcher.ts b/pusher/src/Model/PositionDispatcher.ts index b0eea0ac..f868cd2c 100644 --- a/pusher/src/Model/PositionDispatcher.ts +++ b/pusher/src/Model/PositionDispatcher.ts @@ -63,7 +63,6 @@ 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/Services/SocketManager.ts b/pusher/src/Services/SocketManager.ts index 30f41f2a..436ecd39 100644 --- a/pusher/src/Services/SocketManager.ts +++ b/pusher/src/Services/SocketManager.ts @@ -615,7 +615,6 @@ 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); From 363b906cb825d9019f36463ead8e445f9ec5e9c5 Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Thu, 3 Mar 2022 14:36:16 +0100 Subject: [PATCH 08/16] group circles with color fill --- front/src/Components/CameraControls.svelte | 2 +- front/src/Phaser/Game/GameScene.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/front/src/Components/CameraControls.svelte b/front/src/Components/CameraControls.svelte index da207df1..c22900ff 100644 --- a/front/src/Components/CameraControls.svelte +++ b/front/src/Components/CameraControls.svelte @@ -103,7 +103,7 @@
diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 8b2112b9..8b0793e0 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -980,7 +980,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 @@ -990,7 +992,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(); } From ba612c49ed482e2af89ed96e7058e4c62d31d0a0 Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Thu, 3 Mar 2022 14:47:42 +0100 Subject: [PATCH 09/16] fix GameRoom text --- back/tests/GameRoomTest.ts | 3 +++ 1 file changed, 3 insertions(+) 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, + () => {}, () => {} ); From 3c74b2b554fec3dc221ffde8b766917657371296 Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Thu, 3 Mar 2022 15:21:44 +0100 Subject: [PATCH 10/16] remove obsolete check --- front/src/Components/CameraControls.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/src/Components/CameraControls.svelte b/front/src/Components/CameraControls.svelte index c22900ff..b9cb7801 100644 --- a/front/src/Components/CameraControls.svelte +++ b/front/src/Components/CameraControls.svelte @@ -103,7 +103,7 @@
From 3a5aa3c3c55979208839659aaf57d00900910ab6 Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Wed, 9 Mar 2022 16:51:11 +0100 Subject: [PATCH 11/16] cr fixes #1 wip --- back/src/Model/GameRoom.ts | 14 ++++++++----- back/src/Services/SocketManager.ts | 20 ++++++++++++++----- .../images/lock.svg:Zone.Identifier | 3 --- front/src/Phaser/Game/GameScene.ts | 1 + 4 files changed, 25 insertions(+), 13 deletions(-) delete mode 100644 front/src/Components/images/lock.svg:Zone.Identifier diff --git a/back/src/Model/GameRoom.ts b/back/src/Model/GameRoom.ts index 74284ab2..a073f0e5 100644 --- a/back/src/Model/GameRoom.ts +++ b/back/src/Model/GameRoom.ts @@ -46,7 +46,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(); @@ -250,7 +250,7 @@ export class GameRoom { this.disconnectCallback, this.positionNotifier ); - this.groups.add(group); + this.groups.set(group.getId(), group); } } } else { @@ -334,7 +334,7 @@ export class GameRoom { this.disconnectCallback, this.positionNotifier ); - this.groups.add(newGroup); + this.groups.set(newGroup.getId(), newGroup); } else { this.leaveGroup(user); } @@ -381,10 +381,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(); @@ -664,4 +664,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/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index 0f78427f..f3f34f9b 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -41,6 +41,7 @@ import { GroupUsersUpdateMessage, LockGroupMessage, LockGroupPromptMessage, + RoomMessage, } from "../Messages/generated/messages_pb"; import { User, UserSocket } from "../Model/User"; import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils"; @@ -287,7 +288,7 @@ export class SocketManager { (emoteEventMessage: EmoteEventMessage, listener: ZoneSocket) => this.onEmote(emoteEventMessage, listener), (lockGroupMessage: LockGroupMessage, listener: ZoneSocket) => - this.onLockGroup(lockGroupMessage, listener), + this.onLockGroup(lockGroupMessage, listener, roomPromise), (playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ZoneSocket) => this.onPlayerDetailsUpdated(playerDetailsUpdatedMessage, listener) ) @@ -391,10 +392,19 @@ export class SocketManager { emitZoneMessage(subMessage, client); } - private onLockGroup(lockGroupMessage: LockGroupMessage, client: ZoneSocket) { - const subMessage = new SubToPusherMessage(); - subMessage.setLockgroupmessage(lockGroupMessage); - emitZoneMessage(subMessage, client); + private async onLockGroup( + lockGroupMessage: LockGroupMessage, + client: ZoneSocket, + roomPromise: PromiseLike | undefined + ) { + if (!roomPromise) { + return; + } + const group = (await roomPromise).getGroupById(lockGroupMessage.getGroupid()); + if (!group) { + return; + } + this.emitCreateUpdateGroupEvent(client, null, group); } private onPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, client: ZoneSocket) { diff --git a/front/src/Components/images/lock.svg:Zone.Identifier b/front/src/Components/images/lock.svg:Zone.Identifier deleted file mode 100644 index 053d1127..00000000 --- a/front/src/Components/images/lock.svg:Zone.Identifier +++ /dev/null @@ -1,3 +0,0 @@ -[ZoneTransfer] -ZoneId=3 -HostUrl=about:internet diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 8b0793e0..e795979f 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -2010,6 +2010,7 @@ ${escapedMessage} } private doShareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface) { + console.log(groupPositionMessage); //delete previous group this.doDeleteGroup(groupPositionMessage.groupId); From 5a8cba24fa423727ea3f98466d67007d84fb57b4 Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Thu, 10 Mar 2022 12:20:53 +0100 Subject: [PATCH 12/16] much cleaner approach to group lock update --- back/src/Model/GameRoom.ts | 5 ++-- back/src/Model/PositionNotifier.ts | 6 ++-- back/src/Model/Zone.ts | 7 ++--- back/src/RoomManager.ts | 2 +- back/src/Services/SocketManager.ts | 17 +++-------- front/src/Connexion/ConnexionModels.ts | 5 ---- front/src/Connexion/RoomConnection.ts | 8 ------ front/src/Phaser/Game/GameScene.ts | 31 --------------------- messages/protos/messages.proto | 7 ----- pusher/src/Controller/IoSocketController.ts | 1 - pusher/src/Model/Zone.ts | 23 --------------- pusher/src/Services/SocketManager.ts | 8 ------ 12 files changed, 13 insertions(+), 107 deletions(-) diff --git a/back/src/Model/GameRoom.ts b/back/src/Model/GameRoom.ts index a073f0e5..c1c1c346 100644 --- a/back/src/Model/GameRoom.ts +++ b/back/src/Model/GameRoom.ts @@ -23,7 +23,6 @@ import { VariableMessage, VariableWithTagMessage, ServerToClientMessage, - LockGroupMessage, } from "../Messages/generated/messages_pb"; import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils"; import { RoomSocket, ZoneSocket } from "src/RoomManager"; @@ -550,8 +549,8 @@ export class GameRoom { this.positionNotifier.emitEmoteEvent(user, emoteEventMessage); } - public emitLockGroupMessage(user: User, lockGroupMessage: LockGroupMessage) { - this.positionNotifier.emitLockGroupEvent(user, lockGroupMessage); + public emitLockGroupEvent(user: User, groupId: number) { + this.positionNotifier.emitLockGroupEvent(user, groupId); } public addRoomListener(socket: RoomSocket) { diff --git a/back/src/Model/PositionNotifier.ts b/back/src/Model/PositionNotifier.ts index 6e1fb195..38d538ec 100644 --- a/back/src/Model/PositionNotifier.ts +++ b/back/src/Model/PositionNotifier.ts @@ -21,7 +21,7 @@ import { Movable } from "_Model/Movable"; import { PositionInterface } from "_Model/PositionInterface"; import { ZoneSocket } from "../RoomManager"; import { User } from "../Model/User"; -import { EmoteEventMessage, LockGroupMessage, SetPlayerDetailsMessage } from "../Messages/generated/messages_pb"; +import { EmoteEventMessage, SetPlayerDetailsMessage } from "../Messages/generated/messages_pb"; interface ZoneDescriptor { i: number; @@ -140,10 +140,10 @@ export class PositionNotifier { zone.emitEmoteEvent(emoteEventMessage); } - public emitLockGroupEvent(user: User, lockGroupMessage: LockGroupMessage) { + 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(lockGroupMessage); + zone.emitLockGroupEvent(groupId); } public *getAllUsersInSquareAroundZone(zone: Zone): Generator { diff --git a/back/src/Model/Zone.ts b/back/src/Model/Zone.ts index 4f49ff55..2d0cefd5 100644 --- a/back/src/Model/Zone.ts +++ b/back/src/Model/Zone.ts @@ -7,14 +7,13 @@ import { EmoteEventMessage, SetPlayerDetailsMessage, PlayerDetailsUpdatedMessage, - LockGroupMessage, } from "../Messages/generated/messages_pb"; export type EntersCallback = (thing: Movable, fromZone: Zone | null, listener: ZoneSocket) => void; 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 = (lockGroupMessage: LockGroupMessage, listener: ZoneSocket) => void; +export type LockGroupCallback = (groupId: number, listener: ZoneSocket) => void; export type PlayerDetailsUpdatedCallback = ( playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ZoneSocket @@ -111,9 +110,9 @@ export class Zone { } } - public emitLockGroupEvent(lockGroupMessage: LockGroupMessage) { + public emitLockGroupEvent(groupId: number) { for (const listener of this.listeners) { - this.onLockGroup(lockGroupMessage, listener); + this.onLockGroup(groupId, listener); } } diff --git a/back/src/RoomManager.ts b/back/src/RoomManager.ts index 2705787e..ab886f50 100644 --- a/back/src/RoomManager.ts +++ b/back/src/RoomManager.ts @@ -137,7 +137,7 @@ const roomManager: IRoomManagerServer = { message.getFollowabortmessage() as FollowAbortMessage ); } else if (message.hasLockgrouppromptmessage()) { - socketManager.handleLockGroupMessage( + socketManager.handleLockGroupPromptMessage( room, user, message.getLockgrouppromptmessage() as LockGroupPromptMessage diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index f3f34f9b..d0151e30 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -39,7 +39,6 @@ import { SetPlayerDetailsMessage, PlayerDetailsUpdatedMessage, GroupUsersUpdateMessage, - LockGroupMessage, LockGroupPromptMessage, RoomMessage, } from "../Messages/generated/messages_pb"; @@ -287,8 +286,7 @@ export class SocketManager { this.onClientLeave(thing, newZone, listener), (emoteEventMessage: EmoteEventMessage, listener: ZoneSocket) => this.onEmote(emoteEventMessage, listener), - (lockGroupMessage: LockGroupMessage, listener: ZoneSocket) => - this.onLockGroup(lockGroupMessage, listener, roomPromise), + (groupId: number, listener: ZoneSocket) => this.onLockGroup(groupId, listener, roomPromise), (playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ZoneSocket) => this.onPlayerDetailsUpdated(playerDetailsUpdatedMessage, listener) ) @@ -392,15 +390,11 @@ export class SocketManager { emitZoneMessage(subMessage, client); } - private async onLockGroup( - lockGroupMessage: LockGroupMessage, - client: ZoneSocket, - roomPromise: PromiseLike | undefined - ) { + private async onLockGroup(groupId: number, client: ZoneSocket, roomPromise: PromiseLike | undefined) { if (!roomPromise) { return; } - const group = (await roomPromise).getGroupById(lockGroupMessage.getGroupid()); + const group = (await roomPromise).getGroupById(groupId); if (!group) { return; } @@ -915,10 +909,7 @@ export class SocketManager { return; } group.lock(message.getLock()); - const lockGroupMessage = new LockGroupMessage(); - lockGroupMessage.setLock(message.getLock()); - lockGroupMessage.setGroupid(group.getId()); - room.emitLockGroupMessage(user, lockGroupMessage); + room.emitLockGroupEvent(user, group.getId()); } } diff --git a/front/src/Connexion/ConnexionModels.ts b/front/src/Connexion/ConnexionModels.ts index 167624e6..04282abc 100644 --- a/front/src/Connexion/ConnexionModels.ts +++ b/front/src/Connexion/ConnexionModels.ts @@ -48,11 +48,6 @@ export interface GroupCreatedUpdatedMessageInterface { locked: boolean; } -export interface LockGroupMessageInterface { - groupId: number; - lock: boolean; -} - export interface GroupUsersUpdateMessageInterface { groupId: number; userIds: number[]; diff --git a/front/src/Connexion/RoomConnection.ts b/front/src/Connexion/RoomConnection.ts index d0cc5c48..48827bc5 100644 --- a/front/src/Connexion/RoomConnection.ts +++ b/front/src/Connexion/RoomConnection.ts @@ -40,7 +40,6 @@ import { PositionMessage_Direction, SetPlayerDetailsMessage as SetPlayerDetailsMessageTsProto, PingMessage as PingMessageTsProto, - LockGroupMessage, } from "../Messages/ts-proto-generated/messages"; import { Subject } from "rxjs"; @@ -102,9 +101,6 @@ export class RoomConnection implements RoomConnection { private readonly _groupUsersUpdateMessageStream = new Subject(); public readonly groupUsersUpdateMessageStream = this._groupUsersUpdateMessageStream.asObservable(); - private readonly _lockGroupMessageStream = new Subject(); - public readonly lockGroupMessageStream = this._lockGroupMessageStream.asObservable(); - private readonly _groupDeleteMessageStream = new Subject(); public readonly groupDeleteMessageStream = this._groupDeleteMessageStream.asObservable(); @@ -268,10 +264,6 @@ export class RoomConnection implements RoomConnection { this._emoteEventMessageStream.next(subMessage.emoteEventMessage); break; } - case "lockGroupMessage": { - this._lockGroupMessageStream.next(subMessage.lockGroupMessage); - break; - } case "playerDetailsUpdatedMessage": { this._playerDetailsUpdatedMessageStream.next(subMessage.playerDetailsUpdatedMessage); break; diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index e795979f..15570bb9 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -51,7 +51,6 @@ import { PathfindingManager } from "../../Utils/PathfindingManager"; import { ActivatablesManager } from "./ActivatablesManager"; import type { GroupCreatedUpdatedMessageInterface, - LockGroupMessageInterface, MessageUserMovedInterface, MessageUserPositionInterface, OnConnectInterface, @@ -134,11 +133,6 @@ interface DeleteGroupEventInterface { groupId: number; } -interface LockGroupEventInterface { - type: "LockGroupEvent"; - event: LockGroupMessageInterface; -} - interface PlayerDetailsUpdatedInterface { type: "PlayerDetailsUpdated"; details: PlayerDetailsUpdatedMessageInterface; @@ -163,7 +157,6 @@ export class GameScene extends DirtyScene { | UserMovedEventInterface | GroupCreatedUpdatedEventInterface | DeleteGroupEventInterface - | LockGroupEventInterface | PlayerDetailsUpdatedInterface >(); private initPosition: PositionInterface | null = null; @@ -808,10 +801,6 @@ export class GameScene extends DirtyScene { } }); - this.connection.lockGroupMessageStream.subscribe((message) => { - this.lockGroup(message); - }); - this.connection.onServerDisconnected(() => { console.log("Player disconnected from server. Reloading scene."); this.cleanupClosingScene(); @@ -1847,10 +1836,6 @@ ${escapedMessage} currentPlayerGroupLockStateStore.set(undefined); break; } - case "LockGroupEvent": { - this.doLockGroup(event.event); - break; - } default: { const tmp: never = event; } @@ -2049,22 +2034,6 @@ ${escapedMessage} this.groups.delete(groupId); } - lockGroup(event: LockGroupMessageInterface): void { - this.pendingEvents.enqueue({ - type: "LockGroupEvent", - event, - }); - } - - doLockGroup(event: LockGroupMessageInterface): void { - const group = this.groups.get(event.groupId); - if (!group) { - return; - } - currentPlayerGroupLockStateStore.set(event.lock); - group.setTexture(event.lock ? "circleSprite-red" : "circleSprite-white"); - } - doUpdatePlayerDetails(message: PlayerDetailsUpdatedMessageInterface): void { const character = this.MapPlayersByKey.get(message.userId); if (character === undefined) { diff --git a/messages/protos/messages.proto b/messages/protos/messages.proto index b6e8d98f..78858499 100644 --- a/messages/protos/messages.proto +++ b/messages/protos/messages.proto @@ -102,11 +102,6 @@ message LockGroupPromptMessage { bool lock = 1; } -message LockGroupMessage { - int32 groupId = 1; - bool lock = 2; -} - message ClientToServerMessage { oneof message { UserMovesMessage userMovesMessage = 2; @@ -182,7 +177,6 @@ message SubMessage { VariableMessage variableMessage = 8; ErrorMessage errorMessage = 9; PlayerDetailsUpdatedMessage playerDetailsUpdatedMessage = 10; - LockGroupMessage lockGroupMessage = 11; } } @@ -437,7 +431,6 @@ message SubToPusherMessage { EmoteEventMessage emoteEventMessage = 9; ErrorMessage errorMessage = 10; PlayerDetailsUpdatedMessage playerDetailsUpdatedMessage = 11; - LockGroupMessage lockGroupMessage = 12; } } diff --git a/pusher/src/Controller/IoSocketController.ts b/pusher/src/Controller/IoSocketController.ts index 7c7928d6..781b4fc0 100644 --- a/pusher/src/Controller/IoSocketController.ts +++ b/pusher/src/Controller/IoSocketController.ts @@ -21,7 +21,6 @@ import { FollowConfirmationMessage, FollowAbortMessage, VariableMessage, - LockGroupMessage, LockGroupPromptMessage, } from "../Messages/generated/messages_pb"; import { UserMovesMessage } from "../Messages/generated/messages_pb"; diff --git a/pusher/src/Model/Zone.ts b/pusher/src/Model/Zone.ts index 92f82222..02a01d8d 100644 --- a/pusher/src/Model/Zone.ts +++ b/pusher/src/Model/Zone.ts @@ -18,7 +18,6 @@ import { ErrorMessage, PlayerDetailsUpdatedMessage, SetPlayerDetailsMessage, - LockGroupMessage, } from "../Messages/generated/messages_pb"; import { ClientReadableStream } from "grpc"; import { PositionDispatcher } from "_Model/PositionDispatcher"; @@ -33,7 +32,6 @@ export interface ZoneEventListener { onGroupEnters(group: GroupDescriptor, listener: ExSocketInterface): void; onGroupMoves(group: GroupDescriptor, listener: ExSocketInterface): void; onGroupLeaves(groupId: number, listener: ExSocketInterface): void; - onLockGroup(lockGroupMessage: LockGroupMessage, listener: ExSocketInterface): void; onEmote(emoteMessage: EmoteEventMessage, listener: ExSocketInterface): void; onError(errorMessage: ErrorMessage, listener: ExSocketInterface): void; onPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ExSocketInterface): void; @@ -140,10 +138,6 @@ 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; @@ -221,14 +215,6 @@ export class Zone { 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()); @@ -256,9 +242,6 @@ export class Zone { } else if (message.hasEmoteeventmessage()) { const emoteEventMessage = message.getEmoteeventmessage() as EmoteEventMessage; this.notifyEmote(emoteEventMessage); - } else if (message.hasLockgroupmessage()) { - const lockGroupMessage = message.getLockgroupmessage() as LockGroupMessage; - this.notifyLockGroup(lockGroupMessage); } else if (message.hasPlayerdetailsupdatedmessage()) { const playerDetailsUpdatedMessage = message.getPlayerdetailsupdatedmessage() as PlayerDetailsUpdatedMessage; @@ -369,12 +352,6 @@ export class Zone { } } - private notifyLockGroup(lockGroupMessage: LockGroupMessage) { - for (const listener of this.listeners) { - this.socketListener.onLockGroup(lockGroupMessage, listener); - } - } - private notifyPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage) { for (const listener of this.listeners) { if (listener.userId === playerDetailsUpdatedMessage.getUserid()) { diff --git a/pusher/src/Services/SocketManager.ts b/pusher/src/Services/SocketManager.ts index 436ecd39..f6e2feb0 100644 --- a/pusher/src/Services/SocketManager.ts +++ b/pusher/src/Services/SocketManager.ts @@ -38,7 +38,6 @@ import { ErrorMessage, WorldFullMessage, PlayerDetailsUpdatedMessage, - LockGroupMessage, LockGroupPromptMessage, } from "../Messages/generated/messages_pb"; import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils"; @@ -307,13 +306,6 @@ export class SocketManager implements ZoneEventListener { emitInBatch(listener, subMessage); } - onLockGroup(lockGroupMessage: LockGroupMessage, listener: ExSocketInterface): void { - const subMessage = new SubMessage(); - subMessage.setLockgroupmessage(lockGroupMessage); - - emitInBatch(listener, subMessage); - } - onPlayerDetailsUpdated( playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ExSocketInterface From 767e3b94e3026088db18d4e1537c7e79b646eb62 Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Thu, 10 Mar 2022 13:19:23 +0100 Subject: [PATCH 13/16] fix compilation error --- back/src/Services/SocketManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index d0151e30..087843b1 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -903,7 +903,7 @@ export class SocketManager { } } - handleLockGroupMessage(room: GameRoom, user: User, message: LockGroupPromptMessage) { + handleLockGroupPromptMessage(room: GameRoom, user: User, message: LockGroupPromptMessage) { const group = user.group; if (!group) { return; From a8cd37bcf9a02936faec07945520fd9cb50d5388 Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Thu, 10 Mar 2022 15:34:19 +0100 Subject: [PATCH 14/16] well-known values wip --- messages/protos/messages.proto | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/messages/protos/messages.proto b/messages/protos/messages.proto index 78858499..9d211855 100644 --- a/messages/protos/messages.proto +++ b/messages/protos/messages.proto @@ -1,5 +1,7 @@ syntax = "proto3"; +import "google/protobuf/wrappers.proto"; + /*********** PARTIAL MESSAGES **************/ message PositionMessage { @@ -362,9 +364,9 @@ message UserLeftZoneMessage { message GroupUpdateZoneMessage { int32 groupId = 1; PointMessage position = 2; - int32 groupSize = 3; + google.protobuf.UInt32Value groupSize = 3; Zone fromZone = 4; - bool locked = 5; + google.protobuf.BoolValue locked = 5; } message GroupLeftZoneMessage { From 1b2c67a4d7fd2054dd51592bfd328184ce7359db Mon Sep 17 00:00:00 2001 From: Piotr 'pwh' Hanusiak Date: Mon, 28 Mar 2022 13:47:02 +0200 Subject: [PATCH 15/16] removed obsolete console.log --- front/src/Phaser/Game/GameScene.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index bc02cf87..1ef034dd 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -2038,7 +2038,6 @@ ${escapedMessage} } private doShareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface) { - console.log(groupPositionMessage); //delete previous group this.doDeleteGroup(groupPositionMessage.groupId); From 6230bb16574cf92d9558a25be485586ecb805c90 Mon Sep 17 00:00:00 2001 From: Piotr 'pwh' Hanusiak Date: Mon, 28 Mar 2022 14:35:21 +0200 Subject: [PATCH 16/16] fix linter issues --- back/src/Services/SocketManager.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index 2d3dd2e3..8aa7f6a4 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -287,7 +287,9 @@ export class SocketManager { this.onClientLeave(thing, newZone, listener), (emoteEventMessage: EmoteEventMessage, listener: ZoneSocket) => this.onEmote(emoteEventMessage, listener), - (groupId: number, listener: ZoneSocket) => this.onLockGroup(groupId, listener, roomPromise), + (groupId: number, listener: ZoneSocket) => { + void this.onLockGroup(groupId, listener, roomPromise); + }, (playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ZoneSocket) => this.onPlayerDetailsUpdated(playerDetailsUpdatedMessage, listener) ) @@ -391,7 +393,11 @@ export class SocketManager { emitZoneMessage(subMessage, client); } - private async onLockGroup(groupId: number, client: ZoneSocket, roomPromise: PromiseLike | undefined) { + private async onLockGroup( + groupId: number, + client: ZoneSocket, + roomPromise: PromiseLike | undefined + ): Promise { if (!roomPromise) { return; }