Get tags from the admin

And uses tag "admin" to choose whether to display the console or not
This commit is contained in:
David Négrier 2020-10-14 11:07:34 +02:00
parent 3710c3cb7d
commit 98bda49d7e
6 changed files with 33 additions and 11 deletions

View file

@ -145,12 +145,14 @@ export class IoSocketController {
const userUuid = await jwtTokenManager.getUserUuidFromToken(token); const userUuid = await jwtTokenManager.getUserUuidFromToken(token);
console.log('uuid', userUuid); console.log('uuid', userUuid);
let memberTags: string[] = [];
if (roomIdentifier.anonymous === false) { if (roomIdentifier.anonymous === false) {
const isGranted = await adminApi.memberIsGrantedAccessToRoom(userUuid, roomIdentifier); const grants = await adminApi.memberIsGrantedAccessToRoom(userUuid, roomIdentifier);
if (!isGranted) { if (!grants.granted) {
console.log('access not granted for user '+userUuid+' and room '+roomId); console.log('access not granted for user '+userUuid+' and room '+roomId);
throw new Error('Client cannot acces this ressource.') throw new Error('Client cannot acces this ressource.')
} else { } else {
memberTags = grants.memberTags;
console.log('access granted for user '+userUuid+' and room '+roomId); console.log('access granted for user '+userUuid+' and room '+roomId);
} }
} }
@ -181,7 +183,8 @@ export class IoSocketController {
right, right,
bottom, bottom,
left left
} },
tags: memberTags
}, },
/* Spell these correctly */ /* Spell these correctly */
websocketKey, websocketKey,
@ -218,6 +221,7 @@ export class IoSocketController {
client.name = ws.name; client.name = ws.name;
client.characterLayers = ws.characterLayers; client.characterLayers = ws.characterLayers;
client.roomId = ws.roomId; client.roomId = ws.roomId;
client.tags = ws.tags;
this.sockets.set(client.userId, client); this.sockets.set(client.userId, client);
@ -353,6 +357,7 @@ export class IoSocketController {
} }
roomJoinedMessage.setCurrentuserid(client.userId); roomJoinedMessage.setCurrentuserid(client.userId);
roomJoinedMessage.setTagList(client.tags);
const serverToClientMessage = new ServerToClientMessage(); const serverToClientMessage = new ServerToClientMessage();
serverToClientMessage.setRoomjoinedmessage(roomJoinedMessage); serverToClientMessage.setRoomjoinedmessage(roomJoinedMessage);

View file

@ -7,7 +7,7 @@ import {WebSocket} from "uWebSockets.js"
export interface ExSocketInterface extends WebSocket, Identificable { export interface ExSocketInterface extends WebSocket, Identificable {
token: string; token: string;
roomId: string; roomId: string;
userId: number; // A temporary (autoincremented) identifier for this user //userId: number; // A temporary (autoincremented) identifier for this user
userUuid: string; // A unique identifier for this user userUuid: string; // A unique identifier for this user
name: string; name: string;
characterLayers: string[]; characterLayers: string[];
@ -19,5 +19,6 @@ export interface ExSocketInterface extends WebSocket, Identificable {
emitInBatch: (payload: SubMessage) => void; emitInBatch: (payload: SubMessage) => void;
batchedMessages: BatchMessage; batchedMessages: BatchMessage;
batchTimeout: NodeJS.Timeout|null; batchTimeout: NodeJS.Timeout|null;
disconnecting: boolean disconnecting: boolean,
tags: string[]
} }

View file

@ -10,6 +10,11 @@ export interface AdminApiData {
userUuid: string userUuid: string
} }
export interface GrantedApiData {
granted: boolean,
memberTags: string[]
}
class AdminApi { class AdminApi {
async fetchMapDetails(organizationSlug: string, worldSlug: string, roomSlug: string|undefined): Promise<AdminApiData> { async fetchMapDetails(organizationSlug: string, worldSlug: string, roomSlug: string|undefined): Promise<AdminApiData> {
@ -46,7 +51,7 @@ class AdminApi {
return res.data; return res.data;
} }
async memberIsGrantedAccessToRoom(memberId: string, roomIdentifier: RoomIdentifier): Promise<boolean> { async memberIsGrantedAccessToRoom(memberId: string, roomIdentifier: RoomIdentifier): Promise<GrantedApiData> {
if (!ADMIN_API_URL) { if (!ADMIN_API_URL) {
return Promise.reject('No admin backoffice set!'); return Promise.reject('No admin backoffice set!');
} }
@ -54,10 +59,13 @@ class AdminApi {
const res = await Axios.get(ADMIN_API_URL+'/api/member/is-granted-access', const res = await Axios.get(ADMIN_API_URL+'/api/member/is-granted-access',
{ headers: {"Authorization" : `${ADMIN_API_TOKEN}`}, params: {memberId, organizationSlug: roomIdentifier.organizationSlug, worldSlug: roomIdentifier.worldSlug, roomSlug: roomIdentifier.roomSlug} } { headers: {"Authorization" : `${ADMIN_API_TOKEN}`}, params: {memberId, organizationSlug: roomIdentifier.organizationSlug, worldSlug: roomIdentifier.worldSlug, roomSlug: roomIdentifier.roomSlug} }
) )
return !!res.data; return res.data;
} catch (e) { } catch (e) {
console.log(e.message) console.log(e.message)
return false; return {
granted: false,
memberTags: []
};
} }
} }
} }

View file

@ -43,6 +43,7 @@ export class RoomConnection implements RoomConnection {
private listeners: Map<string, Function[]> = new Map<string, Function[]>(); private listeners: Map<string, Function[]> = new Map<string, Function[]>();
private static websocketFactory: null|((url: string)=>any) = null; // eslint-disable-line @typescript-eslint/no-explicit-any private static websocketFactory: null|((url: string)=>any) = null; // eslint-disable-line @typescript-eslint/no-explicit-any
private closed: boolean = false; private closed: boolean = false;
private tags: string[] = [];
public static setWebsocketFactory(websocketFactory: (url: string)=>any): void { // eslint-disable-line @typescript-eslint/no-explicit-any public static setWebsocketFactory(websocketFactory: (url: string)=>any): void { // eslint-disable-line @typescript-eslint/no-explicit-any
RoomConnection.websocketFactory = websocketFactory; RoomConnection.websocketFactory = websocketFactory;
@ -124,6 +125,7 @@ export class RoomConnection implements RoomConnection {
} }
this.userId = roomJoinedMessage.getCurrentuserid(); this.userId = roomJoinedMessage.getCurrentuserid();
this.tags = roomJoinedMessage.getTagList();
this.dispatch(EventMessage.START_ROOM, { this.dispatch(EventMessage.START_ROOM, {
users, users,
@ -478,4 +480,8 @@ export class RoomConnection implements RoomConnection {
this.socket.send(clientToServerMessage.serializeBinary().buffer); this.socket.send(clientToServerMessage.serializeBinary().buffer);
} }
public hasTag(tag: string): boolean {
return this.tags.indexOf(tag) !== -1;
}
} }

View file

@ -397,9 +397,6 @@ export class GameScene extends ResizableScene implements CenterListener {
//create input to move //create input to move
this.userInputManager = new UserInputManager(this); this.userInputManager = new UserInputManager(this);
//TODO check right of user
this.ConsoleGlobalMessageManager = new ConsoleGlobalMessageManager(this.connection, this.userInputManager);
//notify game manager can to create currentUser in map //notify game manager can to create currentUser in map
this.createCurrentPlayer(); this.createCurrentPlayer();
@ -530,6 +527,10 @@ export class GameScene extends ResizableScene implements CenterListener {
connection.onStartRoom((roomJoinedMessage: RoomJoinedMessageInterface) => { connection.onStartRoom((roomJoinedMessage: RoomJoinedMessageInterface) => {
this.initUsersPosition(roomJoinedMessage.users); this.initUsersPosition(roomJoinedMessage.users);
this.connectionAnswerPromiseResolve(roomJoinedMessage); this.connectionAnswerPromiseResolve(roomJoinedMessage);
// Analyze tags to find if we are admin. If yes, show console.
if (this.connection.hasTag('admin')) {
this.ConsoleGlobalMessageManager = new ConsoleGlobalMessageManager(this.connection, this.userInputManager);
}
}); });
connection.onUserJoins((message: MessageUserJoined) => { connection.onUserJoins((message: MessageUserJoined) => {

View file

@ -139,6 +139,7 @@ message RoomJoinedMessage {
repeated GroupUpdateMessage group = 2; repeated GroupUpdateMessage group = 2;
repeated ItemStateMessage item = 3; repeated ItemStateMessage item = 3;
int32 currentUserId = 4; int32 currentUserId = 4;
repeated string tag = 5;
} }
message WebRtcStartMessage { message WebRtcStartMessage {