Fixing deployment of WA without admin
The open-source version must be installable without an admin backend. While working on AFUP's meeting, we introduced regression preventing WA from working without an admin. This commit fixes this behaviour and makes WA installable again!
This commit is contained in:
parent
3fc7886b42
commit
fcef89aa70
@ -22,7 +22,7 @@ import {adminApi, CharacterTexture, FetchMemberDataByUuidResponse} from "../Serv
|
|||||||
import {SocketManager, socketManager} from "../Services/SocketManager";
|
import {SocketManager, socketManager} from "../Services/SocketManager";
|
||||||
import {emitInBatch, resetPing} from "../Services/IoSocketHelpers";
|
import {emitInBatch, resetPing} from "../Services/IoSocketHelpers";
|
||||||
import {clientEventsEmitter} from "../Services/ClientEventsEmitter";
|
import {clientEventsEmitter} from "../Services/ClientEventsEmitter";
|
||||||
import {ADMIN_API_TOKEN} from "../Enum/EnvironmentVariable";
|
import {ADMIN_API_TOKEN, ADMIN_API_URL} from "../Enum/EnvironmentVariable";
|
||||||
|
|
||||||
export class IoSocketController {
|
export class IoSocketController {
|
||||||
private nextUserId: number = 1;
|
private nextUserId: number = 1;
|
||||||
@ -166,18 +166,21 @@ export class IoSocketController {
|
|||||||
if(room.isFull){
|
if(room.isFull){
|
||||||
throw new Error('Room is full');
|
throw new Error('Room is full');
|
||||||
}
|
}
|
||||||
try {
|
if (ADMIN_API_URL) {
|
||||||
const userData = await adminApi.fetchMemberDataByUuid(userUuid);
|
try {
|
||||||
//console.log('USERDATA', userData)
|
const userData = await adminApi.fetchMemberDataByUuid(userUuid);
|
||||||
memberTags = userData.tags;
|
//console.log('USERDATA', userData)
|
||||||
memberTextures = userData.textures;
|
memberTags = userData.tags;
|
||||||
if (!room.anonymous && room.policyType === GameRoomPolicyTypes.USE_TAGS_POLICY && !room.canAccess(memberTags)) {
|
memberTextures = userData.textures;
|
||||||
throw new Error('No correct tags')
|
if (!room.anonymous && room.policyType === GameRoomPolicyTypes.USE_TAGS_POLICY && !room.canAccess(memberTags)) {
|
||||||
|
throw new Error('No correct tags')
|
||||||
|
}
|
||||||
|
//console.log('access granted for user '+userUuid+' and room '+roomId);
|
||||||
|
} catch (e) {
|
||||||
|
console.log('access not granted for user '+userUuid+' and room '+roomId);
|
||||||
|
console.error(e);
|
||||||
|
throw new Error('Client cannot acces this ressource.')
|
||||||
}
|
}
|
||||||
//console.log('access granted for user '+userUuid+' and room '+roomId);
|
|
||||||
} catch (e) {
|
|
||||||
console.log('access not granted for user '+userUuid+' and room '+roomId);
|
|
||||||
throw new Error('Client cannot acces this ressource.')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate characterLayers objects from characterLayers string[]
|
// Generate characterLayers objects from characterLayers string[]
|
||||||
@ -238,22 +241,24 @@ export class IoSocketController {
|
|||||||
socketManager.handleJoinRoom(client);
|
socketManager.handleJoinRoom(client);
|
||||||
resetPing(client);
|
resetPing(client);
|
||||||
|
|
||||||
//get data information and shwo messages
|
//get data information and show messages
|
||||||
adminApi.fetchMemberDataByUuid(client.userUuid).then((res: FetchMemberDataByUuidResponse) => {
|
if (ADMIN_API_URL) {
|
||||||
if (!res.messages) {
|
adminApi.fetchMemberDataByUuid(client.userUuid).then((res: FetchMemberDataByUuidResponse) => {
|
||||||
return;
|
if (!res.messages) {
|
||||||
}
|
return;
|
||||||
res.messages.forEach((c: unknown) => {
|
}
|
||||||
const messageToSend = c as { type: string, message: string };
|
res.messages.forEach((c: unknown) => {
|
||||||
socketManager.emitSendUserMessage({
|
const messageToSend = c as { type: string, message: string };
|
||||||
userUuid: client.userUuid,
|
socketManager.emitSendUserMessage({
|
||||||
type: messageToSend.type,
|
userUuid: client.userUuid,
|
||||||
message: messageToSend.message
|
type: messageToSend.type,
|
||||||
})
|
message: messageToSend.message
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}).catch((err) => {
|
||||||
|
console.error('fetchMemberDataByUuid => err', err);
|
||||||
});
|
});
|
||||||
}).catch((err) => {
|
}
|
||||||
console.error('fetchMemberDataByUuid => err', err);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
message: (ws, arrayBuffer, isBinary): void => {
|
message: (ws, arrayBuffer, isBinary): void => {
|
||||||
const client = ws as ExSocketInterface;
|
const client = ws as ExSocketInterface;
|
||||||
|
@ -3,7 +3,7 @@ const URL_ROOM_STARTED = "/Floor0/floor0.json";
|
|||||||
const MINIMUM_DISTANCE = process.env.MINIMUM_DISTANCE ? Number(process.env.MINIMUM_DISTANCE) : 64;
|
const MINIMUM_DISTANCE = process.env.MINIMUM_DISTANCE ? Number(process.env.MINIMUM_DISTANCE) : 64;
|
||||||
const GROUP_RADIUS = process.env.GROUP_RADIUS ? Number(process.env.GROUP_RADIUS) : 48;
|
const GROUP_RADIUS = process.env.GROUP_RADIUS ? Number(process.env.GROUP_RADIUS) : 48;
|
||||||
const ALLOW_ARTILLERY = process.env.ALLOW_ARTILLERY ? process.env.ALLOW_ARTILLERY == 'true' : false;
|
const ALLOW_ARTILLERY = process.env.ALLOW_ARTILLERY ? process.env.ALLOW_ARTILLERY == 'true' : false;
|
||||||
const ADMIN_API_URL = process.env.ADMIN_API_URL || 'http://admin';
|
const ADMIN_API_URL = process.env.ADMIN_API_URL || '';
|
||||||
const ADMIN_API_TOKEN = process.env.ADMIN_API_TOKEN || 'myapitoken';
|
const ADMIN_API_TOKEN = process.env.ADMIN_API_TOKEN || 'myapitoken';
|
||||||
const MAX_USERS_PER_ROOM = parseInt(process.env.MAX_USERS_PER_ROOM || '') || 600;
|
const MAX_USERS_PER_ROOM = parseInt(process.env.MAX_USERS_PER_ROOM || '') || 600;
|
||||||
const CPU_OVERHEAT_THRESHOLD = Number(process.env.CPU_OVERHEAT_THRESHOLD) || 80;
|
const CPU_OVERHEAT_THRESHOLD = Number(process.env.CPU_OVERHEAT_THRESHOLD) || 80;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import {ALLOW_ARTILLERY, SECRET_KEY} from "../Enum/EnvironmentVariable";
|
import {ADMIN_API_URL, ALLOW_ARTILLERY, SECRET_KEY} from "../Enum/EnvironmentVariable";
|
||||||
import {uuid} from "uuidv4";
|
import {uuid} from "uuidv4";
|
||||||
import Jwt from "jsonwebtoken";
|
import Jwt from "jsonwebtoken";
|
||||||
import {TokenInterface} from "../Controller/AuthenticateController";
|
import {TokenInterface} from "../Controller/AuthenticateController";
|
||||||
import {adminApi, AdminApiData} from "../Services/AdminApi";
|
import {adminApi, AdminApiData} from "../Services/AdminApi";
|
||||||
|
|
||||||
class JWTTokenManager {
|
class JWTTokenManager {
|
||||||
|
|
||||||
public createJWTToken(userUuid: string) {
|
public createJWTToken(userUuid: string) {
|
||||||
return Jwt.sign({userUuid: userUuid}, SECRET_KEY, {expiresIn: '200d'}); //todo: add a mechanic to refresh or recreate token
|
return Jwt.sign({userUuid: userUuid}, SECRET_KEY, {expiresIn: '200d'}); //todo: add a mechanic to refresh or recreate token
|
||||||
}
|
}
|
||||||
@ -48,17 +48,21 @@ class JWTTokenManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//verify user in admin
|
if (ADMIN_API_URL) {
|
||||||
adminApi.fetchCheckUserByToken(tokenInterface.userUuid).then(() => {
|
//verify user in admin
|
||||||
resolve(tokenInterface.userUuid);
|
adminApi.fetchCheckUserByToken(tokenInterface.userUuid).then(() => {
|
||||||
}).catch((err) => {
|
|
||||||
//anonymous user
|
|
||||||
if(err.response && err.response.status && err.response.status === 404){
|
|
||||||
resolve(tokenInterface.userUuid);
|
resolve(tokenInterface.userUuid);
|
||||||
return;
|
}).catch((err) => {
|
||||||
}
|
//anonymous user
|
||||||
reject(new Error('Authentication error, invalid token structure. ' + err));
|
if(err.response && err.response.status && err.response.status === 404){
|
||||||
});
|
resolve(tokenInterface.userUuid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve(tokenInterface.userUuid);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -66,7 +70,7 @@ class JWTTokenManager {
|
|||||||
private isValidToken(token: object): token is TokenInterface {
|
private isValidToken(token: object): token is TokenInterface {
|
||||||
return !(typeof((token as TokenInterface).userUuid) !== 'string');
|
return !(typeof((token as TokenInterface).userUuid) !== 'string');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const jwtTokenManager = new JWTTokenManager();
|
export const jwtTokenManager = new JWTTokenManager();
|
||||||
|
Loading…
Reference in New Issue
Block a user