Send follow me request to all players

This commit is contained in:
PizZaKatZe 2021-12-12 00:24:39 +01:00
parent b30d0989c8
commit 1fca99c0d1
6 changed files with 59 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import {
BatchToPusherMessage,
BatchToPusherRoomMessage,
EmotePromptMessage,
FollowMeRequestMessage,
EmptyMessage,
ItemEventMessage,
JoinRoomMessage,
@ -116,6 +117,12 @@ const roomManager: IRoomManagerServer = {
user,
message.getEmotepromptmessage() as EmotePromptMessage
);
} else if (message.hasFollowmerequestmessage()) {
socketManager.handleFollowMeRequestMessage(
room,
user,
message.getFollowmerequestmessage() as FollowMeRequestMessage
);
} else if (message.hasSendusermessage()) {
const sendUserMessage = message.getSendusermessage();
if (sendUserMessage !== undefined) {

View File

@ -30,6 +30,7 @@ import {
BanUserMessage,
RefreshRoomMessage,
EmotePromptMessage,
FollowMeRequestMessage,
VariableMessage,
BatchToPusherRoomMessage,
SubToPusherRoomMessage,
@ -833,6 +834,17 @@ export class SocketManager {
emoteEventMessage.setActoruserid(user.id);
room.emitEmoteEvent(user, emoteEventMessage);
}
handleFollowMeRequestMessage(room: GameRoom, user: User, requestMessage: FollowMeRequestMessage) {
console.log("Handling follow me request message");
console.log(user.name);
requestMessage.setPlayername(user.name);
room.getUsers().forEach((recipient) => {
const clientMessage = new ServerToClientMessage();
clientMessage.setFollowmerequestmessage(requestMessage);
recipient.socket.write(clientMessage);
});
}
}
export const socketManager = new SocketManager();

View File

@ -30,6 +30,7 @@ import {
PingMessage,
EmoteEventMessage,
EmotePromptMessage,
FollowMeRequestMessage,
SendUserMessage,
BanUserMessage,
VariableMessage,
@ -257,6 +258,9 @@ export class RoomConnection implements RoomConnection {
warningContainerStore.activateWarningContainer();
} else if (message.hasRefreshroommessage()) {
//todo: implement a way to notify the user the room was refreshed.
} else if (message.hasFollowmerequestmessage()) {
const requestMessage = message.getFollowmerequestmessage() as FollowMeRequestMessage;
console.log("Follow me request from " + requestMessage.getPlayername());
} else if (message.hasErrormessage()) {
const errorMessage = message.getErrormessage() as ErrorMessage;
console.error("An error occurred server side: " + errorMessage.getMessage());
@ -712,6 +716,14 @@ export class RoomConnection implements RoomConnection {
this.socket.send(clientToServerMessage.serializeBinary().buffer);
}
public emitFollowMeRequest(): void {
console.log("Emitting follow me request");
const message = new FollowMeRequestMessage();
const clientToServerMessage = new ClientToServerMessage();
clientToServerMessage.setFollowmerequestmessage(message);
this.socket.send(clientToServerMessage.serializeBinary().buffer);
}
public getAllTags(): string[] {
return this.tags;
}

View File

@ -80,6 +80,15 @@ message QueryJitsiJwtMessage {
string tag = 2; // FIXME: rather than reading the tag from the query, we should read it from the current map!
}
message FollowMeRequestMessage {
string playerName = 1;
}
message FollowMeResponseMessage {
string playerName = 1;
bool accepted = 2;
}
message ClientToServerMessage {
oneof message {
UserMovesMessage userMovesMessage = 2;
@ -95,6 +104,8 @@ message ClientToServerMessage {
QueryJitsiJwtMessage queryJitsiJwtMessage = 12;
EmotePromptMessage emotePromptMessage = 13;
VariableMessage variableMessage = 14;
FollowMeRequestMessage followMeRequestMessage = 15;
FollowMeResponseMessage followMeResponseMessage = 16;
}
}
@ -285,6 +296,8 @@ message ServerToClientMessage {
WorldConnexionMessage worldConnexionMessage = 18;
//EmoteEventMessage emoteEventMessage = 19;
TokenExpiredMessage tokenExpiredMessage = 20;
FollowMeRequestMessage followMeRequestMessage = 21;
FollowMeResponseMessage followMeResponseMessage = 22;
}
}
@ -365,6 +378,8 @@ message PusherToBackMessage {
BanUserMessage banUserMessage = 13;
EmotePromptMessage emotePromptMessage = 14;
VariableMessage variableMessage = 15;
FollowMeRequestMessage followMeRequestMessage = 16;
FollowMeResponseMessage followMeResponseMessage = 17;
}
}

View File

@ -17,6 +17,7 @@ import {
ServerToClientMessage,
CompanionMessage,
EmotePromptMessage,
FollowMeRequestMessage,
VariableMessage,
} from "../Messages/generated/messages_pb";
import { UserMovesMessage } from "../Messages/generated/messages_pb";
@ -469,6 +470,11 @@ export class IoSocketController {
client,
message.getEmotepromptmessage() as EmotePromptMessage
);
} else if (message.hasFollowmerequestmessage()) {
socketManager.handleFollowMeRequest(
client,
message.getFollowmerequestmessage() as FollowMeRequestMessage
);
}
/* Ok is false if backpressure was built up, wait for drain */

View File

@ -8,6 +8,7 @@ import {
CharacterLayerMessage,
EmoteEventMessage,
EmotePromptMessage,
FollowMeRequestMessage,
GroupDeleteMessage,
ItemEventMessage,
JoinRoomMessage,
@ -269,6 +270,12 @@ export class SocketManager implements ZoneEventListener {
this.handleViewport(client, viewport.toObject());
}
handleFollowMeRequest(client: ExSocketInterface, requestMessage: FollowMeRequestMessage): void {
const pusherToBackMessage = new PusherToBackMessage();
pusherToBackMessage.setFollowmerequestmessage(requestMessage);
client.backConnection.write(pusherToBackMessage);
}
onEmote(emoteMessage: EmoteEventMessage, listener: ExSocketInterface): void {
const subMessage = new SubMessage();
subMessage.setEmoteeventmessage(emoteMessage);