Refactoring admin messages
This commit is contained in:
parent
b1d4af005e
commit
d1222e4440
@ -9,7 +9,7 @@ import {
|
||||
PusherToBackMessage,
|
||||
ServerToAdminClientMessage,
|
||||
ServerToClientMessage,
|
||||
SubMessage
|
||||
SubMessage, UserJoinedRoomMessage, UserLeftRoomMessage
|
||||
} from "../Messages/generated/messages_pb";
|
||||
import {CharacterLayer} from "_Model/Websocket/CharacterLayer";
|
||||
import {AdminSocket} from "../RoomManager";
|
||||
@ -23,13 +23,25 @@ export class Admin {
|
||||
|
||||
public sendUserJoin(uuid: string, name: string, ip: string): void {
|
||||
let serverToAdminClientMessage = new ServerToAdminClientMessage();
|
||||
serverToAdminClientMessage = serverToAdminClientMessage.setUseruuidnamejoinedroom(uuid+';'+name+';'+ip)
|
||||
|
||||
let userJoinedRoomMessage = new UserJoinedRoomMessage();
|
||||
userJoinedRoomMessage.setUuid(uuid);
|
||||
userJoinedRoomMessage.setName(name);
|
||||
userJoinedRoomMessage.setIpaddress(ip);
|
||||
|
||||
serverToAdminClientMessage.setUserjoinedroom(userJoinedRoomMessage);
|
||||
|
||||
this.socket.write(serverToAdminClientMessage);
|
||||
}
|
||||
|
||||
public sendUserLeft(uuid: string, name: string, ip: string): void {
|
||||
public sendUserLeft(uuid: string/*, name: string, ip: string*/): void {
|
||||
let serverToAdminClientMessage = new ServerToAdminClientMessage();
|
||||
serverToAdminClientMessage = serverToAdminClientMessage.setUseruuidnameleftroom(uuid+';'+name+';'+ip);
|
||||
|
||||
let userLeftRoomMessage = new UserLeftRoomMessage();
|
||||
userLeftRoomMessage.setUuid(uuid);
|
||||
|
||||
serverToAdminClientMessage.setUserleftroom(userLeftRoomMessage);
|
||||
|
||||
this.socket.write(serverToAdminClientMessage);
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ export class GameRoom {
|
||||
|
||||
// Notify admins
|
||||
for (const admin of this.admins) {
|
||||
admin.sendUserLeft(user.uuid, user.name, user.IPAddress);
|
||||
admin.sendUserLeft(user.uuid/*, user.name, user.IPAddress*/);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,8 +203,8 @@ const roomManager: IRoomManagerServer = {
|
||||
callback(null, new EmptyMessage());
|
||||
},
|
||||
ban(call: ServerUnaryCall<BanMessage>, callback: sendUnaryData<EmptyMessage>): void {
|
||||
|
||||
socketManager.banUser(call.request.getRoomid(), call.request.getRecipientuuid());
|
||||
// FIXME Work in progress
|
||||
socketManager.banUser(call.request.getRoomid(), call.request.getRecipientuuid(), 'foo bar TODO change this');
|
||||
|
||||
callback(null, new EmptyMessage());
|
||||
},
|
||||
|
@ -316,10 +316,20 @@ message ServerToAdminClientMessage {
|
||||
repeated SubToAdminPusherMessage payload = 2;
|
||||
}*/
|
||||
|
||||
message UserJoinedRoomMessage {
|
||||
string uuid = 1;
|
||||
string ipAddress = 2;
|
||||
string name = 3;
|
||||
}
|
||||
|
||||
message UserLeftRoomMessage {
|
||||
string uuid = 1;
|
||||
}
|
||||
|
||||
message ServerToAdminClientMessage {
|
||||
oneof message {
|
||||
string userUuidNameJoinedRoom = 1;
|
||||
string userUuidNameLeftRoom = 2;
|
||||
UserJoinedRoomMessage userJoinedRoom = 1;
|
||||
UserLeftRoomMessage userLeftRoom = 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ import {
|
||||
AdminPusherToBackMessage,
|
||||
ServerToAdminClientMessage,
|
||||
SendUserMessage,
|
||||
BanUserMessage
|
||||
BanUserMessage, UserJoinedRoomMessage, UserLeftRoomMessage
|
||||
} from "../Messages/generated/messages_pb";
|
||||
import {PointInterface} from "../Model/Websocket/PointInterface";
|
||||
import {ProtobufUtils} from "../Model/Websocket/ProtobufUtils";
|
||||
@ -77,15 +77,28 @@ export class SocketManager implements ZoneEventListener {
|
||||
client.adminConnection = adminRoomStream;
|
||||
|
||||
adminRoomStream.on('data', (message: ServerToAdminClientMessage) => {
|
||||
if (message.hasUseruuidnamejoinedroom()) {
|
||||
const userUuidName = message.getUseruuidnamejoinedroom();
|
||||
if (message.hasUserjoinedroom()) {
|
||||
const userJoinedRoomMessage = message.getUserjoinedroom() as UserJoinedRoomMessage;
|
||||
if (!client.disconnecting) {
|
||||
client.send('MemberJoin:'+userUuidName+';'+roomId);
|
||||
client.send(JSON.stringify({
|
||||
type: 'MemberJoin',
|
||||
data: {
|
||||
uuid: userJoinedRoomMessage.getUuid(),
|
||||
name: userJoinedRoomMessage.getName(),
|
||||
ipAddress: userJoinedRoomMessage.getIpaddress(),
|
||||
roomId: roomId,
|
||||
}
|
||||
}));
|
||||
}
|
||||
} else if (message.hasUseruuidnameleftroom()) {
|
||||
const userUuidName = message.getUseruuidnameleftroom();
|
||||
} else if (message.hasUserleftroom()) {
|
||||
const userLeftRoomMessage = message.getUserleftroom() as UserLeftRoomMessage;
|
||||
if (!client.disconnecting) {
|
||||
client.send('MemberLeave:'+userUuidName+';'+roomId);
|
||||
client.send(JSON.stringify({
|
||||
type: 'MemberLeave',
|
||||
data: {
|
||||
uuid: userLeftRoomMessage.getUuid()
|
||||
}
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
throw new Error('Unexpected admin message');
|
||||
|
Loading…
Reference in New Issue
Block a user