Updating GroupDescriptors on LockGroupMessage

This commit is contained in:
Hanusiak Piotr 2022-03-03 12:22:16 +01:00
parent a0205bf682
commit a0535ed4a8
9 changed files with 40 additions and 24 deletions

View File

@ -29,7 +29,7 @@ import {
WebRtcSignalToServerMessage, WebRtcSignalToServerMessage,
WorldFullWarningToRoomMessage, WorldFullWarningToRoomMessage,
ZoneMessage, ZoneMessage,
LockGroupMessage, LockGroupPromptMessage,
} from "./Messages/generated/messages_pb"; } from "./Messages/generated/messages_pb";
import { sendUnaryData, ServerDuplexStream, ServerUnaryCall, ServerWritableStream } from "grpc"; import { sendUnaryData, ServerDuplexStream, ServerUnaryCall, ServerWritableStream } from "grpc";
import { socketManager } from "./Services/SocketManager"; import { socketManager } from "./Services/SocketManager";
@ -136,11 +136,11 @@ const roomManager: IRoomManagerServer = {
user, user,
message.getFollowabortmessage() as FollowAbortMessage message.getFollowabortmessage() as FollowAbortMessage
); );
} else if (message.hasLockgroupmessage()) { } else if (message.hasLockgrouppromptmessage()) {
socketManager.handleLockGroupMessage( socketManager.handleLockGroupMessage(
room, room,
user, user,
message.getLockgroupmessage() as LockGroupMessage message.getLockgrouppromptmessage() as LockGroupPromptMessage
); );
} else if (message.hasSendusermessage()) { } else if (message.hasSendusermessage()) {
const sendUserMessage = message.getSendusermessage(); const sendUserMessage = message.getSendusermessage();

View File

@ -40,6 +40,7 @@ import {
PlayerDetailsUpdatedMessage, PlayerDetailsUpdatedMessage,
GroupUsersUpdateMessage, GroupUsersUpdateMessage,
LockGroupMessage, LockGroupMessage,
LockGroupPromptMessage,
} from "../Messages/generated/messages_pb"; } from "../Messages/generated/messages_pb";
import { User, UserSocket } from "../Model/User"; import { User, UserSocket } from "../Model/User";
import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils"; 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; const group = user.group;
if (!group) { if (!group) {
return; return;
@ -906,7 +907,7 @@ export class SocketManager {
group.lock(message.getLock()); group.lock(message.getLock());
const lockGroupMessage = new LockGroupMessage(); const lockGroupMessage = new LockGroupMessage();
lockGroupMessage.setLock(message.getLock()); lockGroupMessage.setLock(message.getLock());
lockGroupMessage.setGroupid(message.getGroupid()); lockGroupMessage.setGroupid(group.getId());
room.emitLockGroupMessage(user, lockGroupMessage); room.emitLockGroupMessage(user, lockGroupMessage);
} }
} }

View File

@ -17,7 +17,7 @@
import { embedScreenLayout } from "../Stores/EmbedScreensStore"; import { embedScreenLayout } from "../Stores/EmbedScreensStore";
import { followRoleStore, followStateStore, followUsersStore } from "../Stores/FollowStore"; import { followRoleStore, followStateStore, followUsersStore } from "../Stores/FollowStore";
import { gameManager } from "../Phaser/Game/GameManager"; import { gameManager } from "../Phaser/Game/GameManager";
import { currentPlayerGroupIdStore, currentPlayerGroupLockStateStore } from "../Stores/CurrentPlayerGroupStore"; import { currentPlayerGroupLockStateStore } from "../Stores/CurrentPlayerGroupStore";
const gameScene = gameManager.getCurrentGameScene(); const gameScene = gameManager.getCurrentGameScene();
@ -73,12 +73,7 @@
} }
function lockClick() { function lockClick() {
console.log($currentPlayerGroupIdStore); gameScene.connection?.emitLockGroup(!$currentPlayerGroupLockStateStore);
console.log($currentPlayerGroupLockStateStore);
if ($currentPlayerGroupIdStore === undefined) {
return;
}
gameScene.connection?.emitLockGroup($currentPlayerGroupIdStore, !$currentPlayerGroupLockStateStore);
} }
let isSilent: boolean; let isSilent: boolean;

View File

@ -858,12 +858,11 @@ export class RoomConnection implements RoomConnection {
this.socket.send(bytes); this.socket.send(bytes);
} }
public emitLockGroup(groupId: number, lock: boolean = true): void { public emitLockGroup(lock: boolean = true): void {
const bytes = ClientToServerMessageTsProto.encode({ const bytes = ClientToServerMessageTsProto.encode({
message: { message: {
$case: "lockGroupMessage", $case: "lockGroupPromptMessage",
lockGroupMessage: { lockGroupPromptMessage: {
groupId,
lock, lock,
}, },
}, },

View File

@ -98,6 +98,10 @@ message FollowAbortMessage {
int32 follower = 2; int32 follower = 2;
} }
message LockGroupPromptMessage {
bool lock = 1;
}
message LockGroupMessage { message LockGroupMessage {
int32 groupId = 1; int32 groupId = 1;
bool lock = 2; bool lock = 2;
@ -121,7 +125,7 @@ message ClientToServerMessage {
FollowRequestMessage followRequestMessage = 15; FollowRequestMessage followRequestMessage = 15;
FollowConfirmationMessage followConfirmationMessage = 16; FollowConfirmationMessage followConfirmationMessage = 16;
FollowAbortMessage followAbortMessage = 17; FollowAbortMessage followAbortMessage = 17;
LockGroupMessage lockGroupMessage = 18; LockGroupPromptMessage lockGroupPromptMessage = 18;
} }
} }
@ -412,7 +416,7 @@ message PusherToBackMessage {
FollowRequestMessage followRequestMessage = 16; FollowRequestMessage followRequestMessage = 16;
FollowConfirmationMessage followConfirmationMessage = 17; FollowConfirmationMessage followConfirmationMessage = 17;
FollowAbortMessage followAbortMessage = 18; FollowAbortMessage followAbortMessage = 18;
LockGroupMessage lockGroupMessage = 19; LockGroupPromptMessage lockGroupPromptMessage = 19;
} }
} }

View File

@ -22,6 +22,7 @@ import {
FollowAbortMessage, FollowAbortMessage,
VariableMessage, VariableMessage,
LockGroupMessage, LockGroupMessage,
LockGroupPromptMessage,
} from "../Messages/generated/messages_pb"; } from "../Messages/generated/messages_pb";
import { UserMovesMessage } from "../Messages/generated/messages_pb"; import { UserMovesMessage } from "../Messages/generated/messages_pb";
import { TemplatedApp } from "uWebSockets.js"; import { TemplatedApp } from "uWebSockets.js";
@ -495,8 +496,11 @@ export class IoSocketController {
); );
} else if (message.hasFollowabortmessage()) { } else if (message.hasFollowabortmessage()) {
socketManager.handleFollowAbort(client, message.getFollowabortmessage() as FollowAbortMessage); socketManager.handleFollowAbort(client, message.getFollowabortmessage() as FollowAbortMessage);
} else if (message.hasLockgroupmessage()) { } else if (message.hasLockgrouppromptmessage()) {
socketManager.handleLockGroup(client, message.getLockgroupmessage() as LockGroupMessage); socketManager.handleLockGroup(
client,
message.getLockgrouppromptmessage() as LockGroupPromptMessage
);
} }
/* Ok is false if backpressure was built up, wait for drain */ /* Ok is false if backpressure was built up, wait for drain */

View File

@ -63,6 +63,7 @@ export class PositionDispatcher {
const addedZones = [...newZones].filter((x) => !oldZones.has(x)); const addedZones = [...newZones].filter((x) => !oldZones.has(x));
const removedZones = [...oldZones].filter((x) => !newZones.has(x)); const removedZones = [...oldZones].filter((x) => !newZones.has(x));
console.log("START LISTENING");
for (const zone of addedZones) { for (const zone of addedZones) {
zone.startListening(socket); zone.startListening(socket);
} }

View File

@ -140,6 +140,10 @@ export class GroupDescriptor {
return new GroupDescriptor(message.getGroupid(), message.getGroupsize(), position, message.getLocked()); return new GroupDescriptor(message.getGroupid(), message.getGroupsize(), position, message.getLocked());
} }
public updateFromLockGroupMessage(message: LockGroupMessage): void {
this.locked = message.getLock();
}
public update(groupDescriptor: GroupDescriptor) { public update(groupDescriptor: GroupDescriptor) {
this.groupSize = groupDescriptor.groupSize; this.groupSize = groupDescriptor.groupSize;
this.position = groupDescriptor.position; this.position = groupDescriptor.position;
@ -214,11 +218,17 @@ export class Zone {
this.notifyGroupMove(groupDescriptor); this.notifyGroupMove(groupDescriptor);
} else { } else {
this.groups.set(groupId, groupDescriptor); this.groups.set(groupId, groupDescriptor);
const fromZone = groupUpdateZoneMessage.getFromzone(); const fromZone = groupUpdateZoneMessage.getFromzone();
this.notifyGroupEnter(groupDescriptor, fromZone?.toObject()); 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()) { } else if (message.hasUserleftzonemessage()) {
const userLeftMessage = message.getUserleftzonemessage() as UserLeftZoneMessage; const userLeftMessage = message.getUserleftzonemessage() as UserLeftZoneMessage;
this.users.delete(userLeftMessage.getUserid()); this.users.delete(userLeftMessage.getUserid());

View File

@ -39,6 +39,7 @@ import {
WorldFullMessage, WorldFullMessage,
PlayerDetailsUpdatedMessage, PlayerDetailsUpdatedMessage,
LockGroupMessage, LockGroupMessage,
LockGroupPromptMessage,
} from "../Messages/generated/messages_pb"; } from "../Messages/generated/messages_pb";
import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils"; import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils";
import { ADMIN_API_URL, JITSI_ISS, JITSI_URL, SECRET_JITSI_KEY } from "../Enum/EnvironmentVariable"; 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); client.backConnection.write(pusherToBackMessage);
} }
handleLockGroup(client: ExSocketInterface, message: LockGroupMessage): void { handleLockGroup(client: ExSocketInterface, message: LockGroupPromptMessage): void {
const pusherToBackMessage = new PusherToBackMessage(); const pusherToBackMessage = new PusherToBackMessage();
pusherToBackMessage.setLockgroupmessage(message); pusherToBackMessage.setLockgrouppromptmessage(message);
client.backConnection.write(pusherToBackMessage); client.backConnection.write(pusherToBackMessage);
} }
@ -614,6 +615,7 @@ export class SocketManager implements ZoneEventListener {
public onGroupEnters(group: GroupDescriptor, listener: ExSocketInterface): void { public onGroupEnters(group: GroupDescriptor, listener: ExSocketInterface): void {
const subMessage = new SubMessage(); const subMessage = new SubMessage();
console.log("ON GROUP ENTERS");
subMessage.setGroupupdatemessage(group.toGroupUpdateMessage()); subMessage.setGroupupdatemessage(group.toGroupUpdateMessage());
emitInBatch(listener, subMessage); emitInBatch(listener, subMessage);