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,
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();

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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,
},
},

View File

@ -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;
}
}

View File

@ -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 */

View File

@ -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);
}

View File

@ -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());

View File

@ -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);