Merge branch 'localAdmin' into swaggerPusher
# Conflicts: # pusher/src/Services/AdminApi.ts
This commit is contained in:
commit
29f1e17767
@ -1,8 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { fly } from "svelte/transition";
|
||||
import { errorScreenStore } from "../../Stores/ErrorScreenStore";
|
||||
import { gameManager } from "../../Phaser/Game/GameManager";
|
||||
|
||||
import logo from "../images/logo-min-white.png";
|
||||
import logoImg from "../images/logo-min-white.png";
|
||||
let logo = gameManager?.currentStartedRoom?.loginSceneLogo ?? logoImg;
|
||||
import error from "../images/error.png";
|
||||
import cup from "../images/cup.png";
|
||||
import reload from "../images/reload.png";
|
||||
@ -39,10 +41,10 @@
|
||||
{detailsStylized}{#if $errorScreenStore.type === "retry"}<div class="loading" />{/if}
|
||||
</p>
|
||||
{#if ($errorScreenStore.type === "retry" && $errorScreenStore.canRetryManual) || ($errorScreenStore.type === "redirect" && (window.history.length > 2 || $errorScreenStore.urlToRedirect))}
|
||||
<div class="button" on:click={click}>
|
||||
<button type="button" class="nes-btn is-primary button" on:click={click}>
|
||||
<img src={$errorScreenStore.type === "retry" ? reload : external} alt="" class="reload" />
|
||||
{$errorScreenStore.buttonTitle}
|
||||
</div>
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</main>
|
||||
@ -130,12 +132,6 @@
|
||||
|
||||
.button {
|
||||
cursor: pointer;
|
||||
background-image: url("../images/button-large.png");
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: contain;
|
||||
padding: 16px 20px;
|
||||
margin-bottom: 2px;
|
||||
font-family: "Press Start 2P";
|
||||
font-size: 14px;
|
||||
.reload {
|
||||
@ -143,15 +139,5 @@
|
||||
width: 22px;
|
||||
}
|
||||
}
|
||||
.button:hover {
|
||||
margin-bottom: 0;
|
||||
margin-top: -5px;
|
||||
padding: 18px 22px;
|
||||
font-size: 16px;
|
||||
.reload {
|
||||
margin-top: -5px;
|
||||
width: 24px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
@ -25,7 +25,7 @@ import {
|
||||
TokenExpiredMessage,
|
||||
WorldConnexionMessage,
|
||||
ErrorMessage as ErrorMessageTsProto,
|
||||
ErrorV2Message as ErrorV2MessageTsProto,
|
||||
ErrorScreenMessage as ErrorScreenMessageTsProto,
|
||||
UserMovedMessage as UserMovedMessageTsProto,
|
||||
GroupUpdateMessage as GroupUpdateMessageTsProto,
|
||||
GroupDeleteMessage as GroupDeleteMessageTsProto,
|
||||
@ -48,7 +48,6 @@ import { selectCharacterSceneVisibleStore } from "../Stores/SelectCharacterStore
|
||||
import { gameManager } from "../Phaser/Game/GameManager";
|
||||
import { SelectCharacterScene, SelectCharacterSceneName } from "../Phaser/Login/SelectCharacterScene";
|
||||
import { errorScreenStore } from "../Stores/ErrorScreenStore";
|
||||
import { WAError } from "../Phaser/Reconnecting/WAError";
|
||||
|
||||
const manualPingDelay = 20000;
|
||||
|
||||
@ -64,8 +63,8 @@ export class RoomConnection implements RoomConnection {
|
||||
private readonly _errorMessageStream = new Subject<ErrorMessageTsProto>();
|
||||
public readonly errorMessageStream = this._errorMessageStream.asObservable();
|
||||
|
||||
private readonly _errorV2MessageStream = new Subject<ErrorV2MessageTsProto>();
|
||||
public readonly errorV2MessageStream = this._errorV2MessageStream.asObservable();
|
||||
private readonly _errorScreenMessageStream = new Subject<ErrorScreenMessageTsProto>();
|
||||
public readonly errorScreenMessageStream = this._errorScreenMessageStream.asObservable();
|
||||
|
||||
private readonly _roomJoinedMessageStream = new Subject<{
|
||||
connection: RoomConnection;
|
||||
@ -482,11 +481,11 @@ export class RoomConnection implements RoomConnection {
|
||||
console.error("An error occurred server side: " + message.errorMessage.message);
|
||||
break;
|
||||
}
|
||||
case "errorV2Message": {
|
||||
this._errorV2MessageStream.next(message.errorV2Message);
|
||||
if (message.errorV2Message.code !== "retry") this.closed = true;
|
||||
console.error("An error occurred server side: " + message.errorV2Message.code);
|
||||
errorScreenStore.setError(message.errorV2Message as unknown as WAError);
|
||||
case "errorScreenMessage": {
|
||||
this._errorScreenMessageStream.next(message.errorScreenMessage);
|
||||
if (message.errorScreenMessage.code !== "retry") this.closed = true;
|
||||
console.error("An error occurred server side: " + message.errorScreenMessage.code);
|
||||
errorScreenStore.setError(message.errorScreenMessage);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { gameManager } from "../Game/GameManager";
|
||||
import { Scene } from "phaser";
|
||||
import { ErrorScene } from "../Reconnecting/ErrorScene";
|
||||
import { WAError } from "../Reconnecting/WAError";
|
||||
import { waScaleManager } from "../Services/WaScaleManager";
|
||||
import { ReconnectingTextures } from "../Reconnecting/ReconnectingScene";
|
||||
import { localeDetector } from "../../i18n/locales";
|
||||
@ -47,19 +46,7 @@ export class EntryScene extends Scene {
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.response.data?.code) {
|
||||
errorScreenStore.setError(
|
||||
new WAError(
|
||||
err.response.data.type,
|
||||
err.response.data.code,
|
||||
err.response.data.title,
|
||||
err.response.data.subtitle,
|
||||
err.response.data.details,
|
||||
err.response.data.timeToRetry,
|
||||
err.response.data.canRetryManual,
|
||||
err.response.data.urlToRedirect,
|
||||
err.response.data.buttonTitle
|
||||
)
|
||||
);
|
||||
errorScreenStore.setError(err.response.data);
|
||||
} else {
|
||||
ErrorScene.showError(err, this.scene);
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
import { writable } from "svelte/store";
|
||||
import { WAError } from "../Phaser/Reconnecting/WAError";
|
||||
import { ErrorScreenMessage } from "../Messages/ts-proto-generated/protos/messages";
|
||||
|
||||
/**
|
||||
* A store that contains one error of type WAError to be displayed.
|
||||
*/
|
||||
function createErrorScreenStore() {
|
||||
const { subscribe, set } = writable<WAError>(undefined);
|
||||
const { subscribe, set } = writable<ErrorScreenMessage>(undefined);
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
setError: (e: WAError): void => set(e),
|
||||
setError: (e: ErrorScreenMessage): void => set(e),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -214,11 +214,17 @@ message UserLeftMessage {
|
||||
int32 userId = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* ErrorMessage is only used to console.error the message in the front
|
||||
*/
|
||||
message ErrorMessage {
|
||||
string message = 1;
|
||||
}
|
||||
|
||||
message ErrorV2Message {
|
||||
/*
|
||||
* ErrorScreenMessage is used to show the ErrorScreen in the front
|
||||
*/
|
||||
message ErrorScreenMessage {
|
||||
string type = 1;
|
||||
string code = 2;
|
||||
string title = 3;
|
||||
@ -341,7 +347,7 @@ message ServerToClientMessage {
|
||||
FollowAbortMessage followAbortMessage = 23;
|
||||
InvalidTextureMessage invalidTextureMessage = 24;
|
||||
GroupUsersUpdateMessage groupUsersUpdateMessage = 25;
|
||||
ErrorV2Message errorV2Message = 26;
|
||||
ErrorScreenMessage errorScreenMessage = 26;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { v4 } from "uuid";
|
||||
import { BaseHttpController } from "./BaseHttpController";
|
||||
import { adminApi, FetchMemberDataByUuidResponse } from "../Services/AdminApi";
|
||||
import { FetchMemberDataByUuidResponse } from "../Services/AdminApi";
|
||||
import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
|
||||
import { parse } from "query-string";
|
||||
import { openIDClient } from "../Services/OpenIDClient";
|
||||
@ -321,7 +321,7 @@ export class AuthenticateController extends BaseHttpController {
|
||||
(async () => {
|
||||
const param = await req.json();
|
||||
|
||||
adminApi.setLocale(req.header("accept-language"));
|
||||
adminService.locale = req.header("accept-language");
|
||||
|
||||
//todo: what to do if the organizationMemberToken is already used?
|
||||
const organizationMemberToken: string | null = param.organizationMemberToken;
|
||||
@ -329,13 +329,15 @@ export class AuthenticateController extends BaseHttpController {
|
||||
|
||||
try {
|
||||
if (typeof organizationMemberToken != "string") throw new Error("No organization token");
|
||||
const data = await adminApi.fetchMemberDataByToken(organizationMemberToken, playUri);
|
||||
const data = await adminService.fetchMemberDataByToken(organizationMemberToken, playUri);
|
||||
const userUuid = data.userUuid;
|
||||
const email = data.email;
|
||||
const roomUrl = data.roomUrl;
|
||||
const mapUrlStart = data.mapUrlStart;
|
||||
|
||||
const authToken = jwtTokenManager.createAuthToken(email || userUuid);
|
||||
|
||||
console.info(data);
|
||||
res.json({
|
||||
authToken,
|
||||
userUuid,
|
||||
@ -421,7 +423,7 @@ export class AuthenticateController extends BaseHttpController {
|
||||
|
||||
//get login profile
|
||||
res.status(302);
|
||||
res.setHeader("Location", adminApi.getProfileUrl(authTokenData.accessToken));
|
||||
res.setHeader("Location", adminService.getProfileUrl(authTokenData.accessToken));
|
||||
res.send("");
|
||||
return;
|
||||
} catch (error) {
|
||||
@ -487,7 +489,8 @@ export class AuthenticateController extends BaseHttpController {
|
||||
* @param email
|
||||
* @param playUri
|
||||
* @param IPAddress
|
||||
* @return FetchMemberDataByUuidResponse|object
|
||||
* @return
|
||||
|object
|
||||
* @private
|
||||
*/
|
||||
private async getUserByUserIdentifier(
|
||||
@ -505,7 +508,7 @@ export class AuthenticateController extends BaseHttpController {
|
||||
userRoomToken: undefined,
|
||||
};
|
||||
try {
|
||||
data = await adminApi.fetchMemberDataByUuid(email, playUri, IPAddress, []);
|
||||
data = await adminService.fetchMemberDataByUuid(email, playUri, IPAddress, []);
|
||||
} catch (err) {
|
||||
console.error("openIDCallback => fetchMemberDataByUuid", err);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import {
|
||||
import { UserMovesMessage } from "../Messages/generated/messages_pb";
|
||||
import { parse } from "query-string";
|
||||
import { AdminSocketTokenData, jwtTokenManager, tokenInvalidException } from "../Services/JWTTokenManager";
|
||||
import { adminApi, FetchMemberDataByUuidResponse } from "../Services/AdminApi";
|
||||
import { FetchMemberDataByUuidResponse } from "../Services/AdminApi";
|
||||
import { socketManager } from "../Services/SocketManager";
|
||||
import { emitInBatch } from "../Services/IoSocketHelpers";
|
||||
import { ADMIN_API_URL, ADMIN_SOCKETS_TOKEN, DISABLE_ANONYMOUS, SOCKET_IDLE_TIMER } from "../Enum/EnvironmentVariable";
|
||||
@ -40,6 +40,7 @@ import { localWokaService } from "../Services/LocalWokaService";
|
||||
import { WebSocket } from "uWebSockets.js";
|
||||
import { WokaDetail } from "../Messages/JsonMessages/PlayerTextures";
|
||||
import { z } from "zod";
|
||||
import { adminService } from "../Services/AdminService";
|
||||
|
||||
/**
|
||||
* The object passed between the "open" and the "upgrade" methods when opening a websocket
|
||||
@ -236,7 +237,7 @@ export class IoSocketController {
|
||||
const websocketExtensions = req.getHeader("sec-websocket-extensions");
|
||||
const IPAddress = req.getHeader("x-forwarded-for");
|
||||
|
||||
adminApi.setLocale(req.getHeader("accept-language"));
|
||||
adminService.locale = req.getHeader("accept-language");
|
||||
|
||||
const roomId = query.roomId;
|
||||
try {
|
||||
@ -305,7 +306,7 @@ export class IoSocketController {
|
||||
if (ADMIN_API_URL) {
|
||||
try {
|
||||
try {
|
||||
userData = await adminApi.fetchMemberDataByUuid(
|
||||
userData = await adminService.fetchMemberDataByUuid(
|
||||
userIdentifier,
|
||||
roomId,
|
||||
IPAddress,
|
||||
@ -328,9 +329,9 @@ export class IoSocketController {
|
||||
{
|
||||
rejected: true,
|
||||
reason: "error",
|
||||
message: err?.response?.data.code,
|
||||
status: err?.response?.status,
|
||||
error: err?.response?.data,
|
||||
message: err.response.data.code,
|
||||
status: err.response.status,
|
||||
error: err.response.data,
|
||||
roomId,
|
||||
} as UpgradeFailedData,
|
||||
websocketKey,
|
||||
@ -486,7 +487,7 @@ export class IoSocketController {
|
||||
} else if (ws.reason === "textureInvalid") {
|
||||
socketManager.emitInvalidTextureMessage(ws);
|
||||
} else if (ws.reason === "error") {
|
||||
socketManager.emitErrorV2Message(
|
||||
socketManager.emitErrorScreenMessage(
|
||||
ws,
|
||||
ws.error.type,
|
||||
ws.error.code,
|
||||
|
@ -1,11 +1,8 @@
|
||||
import { adminApi } from "../Services/AdminApi";
|
||||
import { ADMIN_API_URL, DISABLE_ANONYMOUS } from "../Enum/EnvironmentVariable";
|
||||
import { GameRoomPolicyTypes } from "../Model/PusherRoom";
|
||||
import { isMapDetailsData, MapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
|
||||
import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
|
||||
import { InvalidTokenError } from "./InvalidTokenError";
|
||||
import { DISABLE_ANONYMOUS } from "../Enum/EnvironmentVariable";
|
||||
import { isMapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
|
||||
import { parse } from "query-string";
|
||||
import { BaseHttpController } from "./BaseHttpController";
|
||||
import { adminService } from "../Services/AdminService";
|
||||
|
||||
export class MapController extends BaseHttpController {
|
||||
// Returns a map mapping map name to file name of the map
|
||||
@ -107,66 +104,15 @@ export class MapController extends BaseHttpController {
|
||||
return;
|
||||
}
|
||||
|
||||
// If no admin URL is set, let's react on '/_/[instance]/[map url]' URLs
|
||||
if (!ADMIN_API_URL) {
|
||||
const roomUrl = new URL(query.playUri);
|
||||
|
||||
const match = /\/_\/[^/]+\/(.+)/.exec(roomUrl.pathname);
|
||||
if (!match) {
|
||||
res.status(404);
|
||||
res.json({});
|
||||
return;
|
||||
}
|
||||
|
||||
const mapUrl = roomUrl.protocol + "//" + match[1];
|
||||
|
||||
res.json({
|
||||
mapUrl,
|
||||
policy_type: GameRoomPolicyTypes.ANONYMOUS_POLICY,
|
||||
roomSlug: null, // Deprecated
|
||||
group: null,
|
||||
tags: [],
|
||||
contactPage: null,
|
||||
authenticationMandatory: DISABLE_ANONYMOUS,
|
||||
} as MapDetailsData);
|
||||
|
||||
return;
|
||||
}
|
||||
adminService.locale = req.header("accept-language");
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
let userId: string | undefined = undefined;
|
||||
if (query.authToken != undefined) {
|
||||
let authTokenData: AuthTokenData;
|
||||
try {
|
||||
authTokenData = jwtTokenManager.verifyJWTToken(query.authToken as string);
|
||||
userId = authTokenData.identifier;
|
||||
} catch (e) {
|
||||
try {
|
||||
// Decode token, in this case we don't need to create new token.
|
||||
authTokenData = jwtTokenManager.verifyJWTToken(query.authToken as string, true);
|
||||
userId = authTokenData.identifier;
|
||||
console.info("JWT expire, but decoded", userId);
|
||||
} catch (e) {
|
||||
if (e instanceof InvalidTokenError) {
|
||||
// The token was not good, redirect user on login page
|
||||
res.status(401);
|
||||
res.send("Token decrypted error");
|
||||
return;
|
||||
} else {
|
||||
this.castErrorToResponse(e, res);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const mapDetails = isMapDetailsData.parse(
|
||||
await adminApi.fetchMapDetails(query.playUri as string, userId)
|
||||
await adminService.fetchMapDetails(query.playUri as string, query.authToken as string)
|
||||
);
|
||||
|
||||
if (DISABLE_ANONYMOUS) {
|
||||
mapDetails.authenticationMandatory = true;
|
||||
}
|
||||
if (DISABLE_ANONYMOUS) mapDetails.authenticationMandatory = true;
|
||||
|
||||
res.json(mapDetails);
|
||||
return;
|
||||
|
@ -7,6 +7,8 @@ import { z } from "zod";
|
||||
import { isWokaDetail } from "../Messages/JsonMessages/PlayerTextures";
|
||||
import qs from "qs";
|
||||
import { AdminInterface } from "./AdminInterface";
|
||||
import { AuthTokenData, jwtTokenManager } from "./JWTTokenManager";
|
||||
import { InvalidTokenError } from "../Controller/InvalidTokenError";
|
||||
|
||||
export interface AdminBannedData {
|
||||
is_banned: boolean;
|
||||
@ -27,18 +29,35 @@ export const isFetchMemberDataByUuidResponse = z.object({
|
||||
export type FetchMemberDataByUuidResponse = z.infer<typeof isFetchMemberDataByUuidResponse>;
|
||||
|
||||
class AdminApi implements AdminInterface {
|
||||
private locale: string = "en";
|
||||
setLocale(locale: string) {
|
||||
this.locale = locale;
|
||||
}
|
||||
/**
|
||||
* @var playUri: is url of the room
|
||||
* @var userId: can to be undefined or email or uuid
|
||||
* @return MapDetailsData|RoomRedirect
|
||||
*/
|
||||
async fetchMapDetails(playUri: string, userId?: string): Promise<MapDetailsData | RoomRedirect> {
|
||||
if (!ADMIN_API_URL) {
|
||||
return Promise.reject(new Error("No admin backoffice set!"));
|
||||
locale: string = "en";
|
||||
|
||||
async fetchMapDetails(playUri: string, authToken?: string): Promise<MapDetailsData | RoomRedirect> {
|
||||
let userId: string | undefined = undefined;
|
||||
if (authToken != undefined) {
|
||||
let authTokenData: AuthTokenData;
|
||||
try {
|
||||
authTokenData = jwtTokenManager.verifyJWTToken(authToken);
|
||||
userId = authTokenData.identifier;
|
||||
} catch (e) {
|
||||
try {
|
||||
// Decode token, in this case we don't need to create new token.
|
||||
authTokenData = jwtTokenManager.verifyJWTToken(authToken, true);
|
||||
userId = authTokenData.identifier;
|
||||
console.info("JWT expire, but decoded", userId);
|
||||
} catch (e) {
|
||||
if (e instanceof InvalidTokenError) {
|
||||
throw new Error("Token decrypted error");
|
||||
// The token was not good, redirect user on login page
|
||||
//res.status(401);
|
||||
//res.send("Token decrypted error");
|
||||
//return;
|
||||
} else {
|
||||
throw new Error("Error on decryption of token :" + e);
|
||||
//this.castErrorToResponse(e, res);
|
||||
//return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const params: { playUri: string; userId?: string } = {
|
||||
@ -75,9 +94,6 @@ class AdminApi implements AdminInterface {
|
||||
ipAddress: string,
|
||||
characterLayers: string[]
|
||||
): Promise<FetchMemberDataByUuidResponse> {
|
||||
if (!ADMIN_API_URL) {
|
||||
return Promise.reject(new Error("No admin backoffice set!"));
|
||||
}
|
||||
const res = await Axios.get<unknown, AxiosResponse<unknown>>(ADMIN_API_URL + "/api/room/access", {
|
||||
params: {
|
||||
userIdentifier,
|
||||
@ -105,9 +121,6 @@ class AdminApi implements AdminInterface {
|
||||
}
|
||||
|
||||
async fetchMemberDataByToken(organizationMemberToken: string, playUri: string | null): Promise<AdminApiData> {
|
||||
if (!ADMIN_API_URL) {
|
||||
return Promise.reject(new Error("No admin backoffice set!"));
|
||||
}
|
||||
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
|
||||
const res = await Axios.get(ADMIN_API_URL + "/api/login-url/" + organizationMemberToken, {
|
||||
params: { playUri },
|
||||
@ -131,9 +144,6 @@ class AdminApi implements AdminInterface {
|
||||
reporterUserUuid: string,
|
||||
reportWorldSlug: string
|
||||
) {
|
||||
if (!ADMIN_API_URL) {
|
||||
return Promise.reject(new Error("No admin backoffice set!"));
|
||||
}
|
||||
return Axios.post(
|
||||
`${ADMIN_API_URL}/api/report`,
|
||||
{
|
||||
@ -149,9 +159,6 @@ class AdminApi implements AdminInterface {
|
||||
}
|
||||
|
||||
async verifyBanUser(userUuid: string, ipAddress: string, roomUrl: string): Promise<AdminBannedData> {
|
||||
if (!ADMIN_API_URL) {
|
||||
return Promise.reject(new Error("No admin backoffice set!"));
|
||||
}
|
||||
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
|
||||
return Axios.get(
|
||||
ADMIN_API_URL +
|
||||
@ -169,10 +176,6 @@ class AdminApi implements AdminInterface {
|
||||
}
|
||||
|
||||
async getUrlRoomsFromSameWorld(roomUrl: string): Promise<string[]> {
|
||||
if (!ADMIN_API_URL) {
|
||||
return Promise.reject(new Error("No admin backoffice set!"));
|
||||
}
|
||||
|
||||
return Axios.get(ADMIN_API_URL + "/api/room/sameWorld" + "?roomUrl=" + encodeURIComponent(roomUrl), {
|
||||
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": this.locale },
|
||||
}).then((data) => {
|
||||
@ -180,10 +183,6 @@ class AdminApi implements AdminInterface {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param accessToken
|
||||
*/
|
||||
getProfileUrl(accessToken: string): string {
|
||||
if (!OPID_PROFILE_SCREEN_PROVIDER) {
|
||||
throw new Error("No admin backoffice set!");
|
||||
@ -191,7 +190,7 @@ class AdminApi implements AdminInterface {
|
||||
return `${OPID_PROFILE_SCREEN_PROVIDER}?accessToken=${accessToken}`;
|
||||
}
|
||||
|
||||
async logoutOauth(token: string) {
|
||||
async logoutOauth(token: string): Promise<void> {
|
||||
await Axios.get(ADMIN_API_URL + `/oauth/logout?token=${token}`);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,74 @@
|
||||
import { FetchMemberDataByUuidResponse } from "./AdminApi";
|
||||
import { AdminBannedData, FetchMemberDataByUuidResponse } from "./AdminApi";
|
||||
import { MapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
|
||||
import { RoomRedirect } from "../Messages/JsonMessages/RoomRedirect";
|
||||
import { AdminApiData } from "../Messages/JsonMessages/AdminApiData";
|
||||
|
||||
export interface AdminInterface {
|
||||
locale: string;
|
||||
|
||||
/**
|
||||
* @var playUri: is url of the room
|
||||
* @var userIdentifier: can to be undefined or email or uuid
|
||||
* @var ipAddress
|
||||
* @var characterLayers
|
||||
* @return MapDetailsData|RoomRedirect
|
||||
*/
|
||||
fetchMemberDataByUuid(
|
||||
userIdentifier: string,
|
||||
playUri: string,
|
||||
ipAddress: string,
|
||||
characterLayers: string[]
|
||||
): Promise<FetchMemberDataByUuidResponse>;
|
||||
|
||||
/**
|
||||
* @var playUri: is url of the room
|
||||
* @var userId: can to be undefined or email or uuid
|
||||
* @return MapDetailsData|RoomRedirect
|
||||
*/
|
||||
fetchMapDetails(playUri: string, authToken?: string): Promise<MapDetailsData | RoomRedirect>;
|
||||
|
||||
/**
|
||||
* @param organizationMemberToken
|
||||
* @param playUri
|
||||
* @return AdminApiData
|
||||
*/
|
||||
fetchMemberDataByToken(organizationMemberToken: string, playUri: string | null): Promise<AdminApiData>;
|
||||
|
||||
/**
|
||||
* @param reportedUserUuid
|
||||
* @param reportedUserComment
|
||||
* @param reporterUserUuid
|
||||
* @param reportWorldSlug
|
||||
*/
|
||||
reportPlayer(
|
||||
reportedUserUuid: string,
|
||||
reportedUserComment: string,
|
||||
reporterUserUuid: string,
|
||||
reportWorldSlug: string
|
||||
): Promise<unknown>;
|
||||
|
||||
/**
|
||||
* @param userUuid
|
||||
* @param ipAddress
|
||||
* @param roomUrl
|
||||
* @return AdminBannedData
|
||||
*/
|
||||
verifyBanUser(userUuid: string, ipAddress: string, roomUrl: string): Promise<AdminBannedData>;
|
||||
|
||||
/**
|
||||
* @param roomUrl
|
||||
* @return string[]
|
||||
*/
|
||||
getUrlRoomsFromSameWorld(roomUrl: string): Promise<string[]>;
|
||||
|
||||
/**
|
||||
* @param accessToken
|
||||
* @return string
|
||||
*/
|
||||
getProfileUrl(accessToken: string): string;
|
||||
|
||||
/**
|
||||
* @param token
|
||||
*/
|
||||
logoutOauth(token: string): Promise<void>;
|
||||
}
|
||||
|
@ -1,10 +1,17 @@
|
||||
import { FetchMemberDataByUuidResponse } from "./AdminApi";
|
||||
import { AdminBannedData, FetchMemberDataByUuidResponse } from "./AdminApi";
|
||||
import { AdminInterface } from "./AdminInterface";
|
||||
import { MapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
|
||||
import { RoomRedirect } from "../Messages/JsonMessages/RoomRedirect";
|
||||
import { GameRoomPolicyTypes } from "../Model/PusherRoom";
|
||||
import { DISABLE_ANONYMOUS } from "../Enum/EnvironmentVariable";
|
||||
import { AdminApiData } from "../Messages/JsonMessages/AdminApiData";
|
||||
|
||||
/**
|
||||
* A local class mocking a real admin if no admin is configured.
|
||||
*/
|
||||
class LocalAdmin implements AdminInterface {
|
||||
locale: string = "en";
|
||||
|
||||
fetchMemberDataByUuid(
|
||||
userIdentifier: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
@ -24,6 +31,89 @@ class LocalAdmin implements AdminInterface {
|
||||
userRoomToken: undefined,
|
||||
});
|
||||
}
|
||||
|
||||
fetchMapDetails(
|
||||
playUri: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
authToken?: string
|
||||
): Promise<MapDetailsData | RoomRedirect> {
|
||||
const roomUrl = new URL(playUri);
|
||||
|
||||
const match = /\/_\/[^/]+\/(.+)/.exec(roomUrl.pathname);
|
||||
if (!match) {
|
||||
throw new Error("URL format is not good");
|
||||
}
|
||||
|
||||
const mapUrl = roomUrl.protocol + "//" + match[1];
|
||||
|
||||
return Promise.resolve({
|
||||
mapUrl,
|
||||
policy_type: GameRoomPolicyTypes.ANONYMOUS_POLICY,
|
||||
tags: [],
|
||||
authenticationMandatory: DISABLE_ANONYMOUS,
|
||||
roomSlug: null,
|
||||
contactPage: null,
|
||||
group: null,
|
||||
iframeAuthentication: null,
|
||||
loadingLogo: null,
|
||||
loginSceneLogo: null,
|
||||
});
|
||||
}
|
||||
|
||||
async fetchMemberDataByToken(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
organizationMemberToken: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
playUri: string | null
|
||||
): Promise<AdminApiData> {
|
||||
return Promise.reject(new Error("No admin backoffice set!"));
|
||||
}
|
||||
|
||||
reportPlayer(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
reportedUserUuid: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
reportedUserComment: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
reporterUserUuid: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
reportWorldSlug: string
|
||||
) {
|
||||
return Promise.reject(new Error("No admin backoffice set!"));
|
||||
}
|
||||
|
||||
async verifyBanUser(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
userUuid: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
ipAddress: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
roomUrl: string
|
||||
): Promise<AdminBannedData> {
|
||||
return Promise.reject(new Error("No admin backoffice set!"));
|
||||
}
|
||||
|
||||
async getUrlRoomsFromSameWorld(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
roomUrl: string
|
||||
): Promise<string[]> {
|
||||
return Promise.reject(new Error("No admin backoffice set!"));
|
||||
}
|
||||
|
||||
getProfileUrl(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
accessToken: string
|
||||
): string {
|
||||
new Error("No admin backoffice set!");
|
||||
return "";
|
||||
}
|
||||
|
||||
async logoutOauth(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
token: string
|
||||
): Promise<void> {
|
||||
return Promise.reject(new Error("No admin backoffice set!"));
|
||||
}
|
||||
}
|
||||
|
||||
export const localAdmin = new LocalAdmin();
|
||||
|
@ -40,11 +40,10 @@ import {
|
||||
PlayerDetailsUpdatedMessage,
|
||||
LockGroupPromptMessage,
|
||||
InvalidTextureMessage,
|
||||
ErrorV2Message,
|
||||
ErrorScreenMessage,
|
||||
} 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";
|
||||
import { adminApi } from "./AdminApi";
|
||||
import { emitInBatch } from "./IoSocketHelpers";
|
||||
import Jwt from "jsonwebtoken";
|
||||
import { clientEventsEmitter } from "./ClientEventsEmitter";
|
||||
@ -55,6 +54,7 @@ import Debug from "debug";
|
||||
import { ExAdminSocketInterface } from "../Model/Websocket/ExAdminSocketInterface";
|
||||
import { compressors } from "hyper-express";
|
||||
import { isMapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
|
||||
import { adminService } from "./AdminService";
|
||||
|
||||
const debug = Debug("socket");
|
||||
|
||||
@ -122,13 +122,7 @@ export class SocketManager implements ZoneEventListener {
|
||||
}
|
||||
})
|
||||
.on("end", () => {
|
||||
console.warn(
|
||||
"Admin connection lost to back server '" +
|
||||
apiClient.getChannel().getTarget() +
|
||||
"' for room '" +
|
||||
roomId +
|
||||
"'"
|
||||
);
|
||||
console.warn("Admin connection lost to back server");
|
||||
// Let's close the front connection if the back connection is closed. This way, we can retry connecting from the start.
|
||||
if (!client.disconnecting) {
|
||||
this.closeWebsocketConnection(client, 1011, "Admin Connection lost to back server");
|
||||
@ -136,14 +130,7 @@ export class SocketManager implements ZoneEventListener {
|
||||
console.log("A user left");
|
||||
})
|
||||
.on("error", (err: Error) => {
|
||||
console.error(
|
||||
"Error in connection to back server '" +
|
||||
apiClient.getChannel().getTarget() +
|
||||
"' for room '" +
|
||||
roomId +
|
||||
"':",
|
||||
err
|
||||
);
|
||||
console.error("Error in connection to back server:", err);
|
||||
if (!client.disconnecting) {
|
||||
this.closeWebsocketConnection(client, 1011, "Error while connecting to back server");
|
||||
}
|
||||
@ -200,7 +187,7 @@ export class SocketManager implements ZoneEventListener {
|
||||
joinRoomMessage.addCharacterlayer(characterLayerMessage);
|
||||
}
|
||||
|
||||
console.log("Calling joinRoom '" + client.roomId + "'");
|
||||
console.log("Calling joinRoom");
|
||||
const apiClient = await apiClientRepository.getClient(client.roomId);
|
||||
const streamToPusher = apiClient.joinRoom();
|
||||
clientEventsEmitter.emitClientJoin(client.userUuid, client.roomId);
|
||||
@ -228,13 +215,7 @@ export class SocketManager implements ZoneEventListener {
|
||||
}
|
||||
})
|
||||
.on("end", () => {
|
||||
console.warn(
|
||||
"Connection lost to back server '" +
|
||||
apiClient.getChannel().getTarget() +
|
||||
"' for room '" +
|
||||
client.roomId +
|
||||
"'"
|
||||
);
|
||||
console.warn("Connection lost to back server");
|
||||
// Let's close the front connection if the back connection is closed. This way, we can retry connecting from the start.
|
||||
if (!client.disconnecting) {
|
||||
this.closeWebsocketConnection(client, 1011, "Connection lost to back server");
|
||||
@ -242,14 +223,7 @@ export class SocketManager implements ZoneEventListener {
|
||||
console.log("A user left");
|
||||
})
|
||||
.on("error", (err: Error) => {
|
||||
console.error(
|
||||
"Error in connection to back server '" +
|
||||
apiClient.getChannel().getTarget() +
|
||||
"' for room '" +
|
||||
client.roomId +
|
||||
"':",
|
||||
err
|
||||
);
|
||||
console.error("Error in connection to back server:", err);
|
||||
if (!client.disconnecting) {
|
||||
this.closeWebsocketConnection(client, 1011, "Error while connecting to back server");
|
||||
}
|
||||
@ -384,7 +358,7 @@ export class SocketManager implements ZoneEventListener {
|
||||
|
||||
async handleReportMessage(client: ExSocketInterface, reportPlayerMessage: ReportPlayerMessage) {
|
||||
try {
|
||||
await adminApi.reportPlayer(
|
||||
await adminService.reportPlayer(
|
||||
reportPlayerMessage.getReporteduseruuid(),
|
||||
reportPlayerMessage.getReportcomment(),
|
||||
client.userUuid,
|
||||
@ -470,7 +444,7 @@ export class SocketManager implements ZoneEventListener {
|
||||
}
|
||||
|
||||
public async updateRoomWithAdminData(room: PusherRoom): Promise<void> {
|
||||
const data = await adminApi.fetchMapDetails(room.roomUrl);
|
||||
const data = await adminService.fetchMapDetails(room.roomUrl);
|
||||
const mapDetailsData = isMapDetailsData.safeParse(data);
|
||||
|
||||
if (mapDetailsData.success) {
|
||||
@ -670,7 +644,7 @@ export class SocketManager implements ZoneEventListener {
|
||||
client.send(serverToClientMessage.serializeBinary().buffer, true);
|
||||
}
|
||||
|
||||
public emitErrorV2Message(
|
||||
public emitErrorScreenMessage(
|
||||
client: compressors.WebSocket,
|
||||
type: string,
|
||||
code: string,
|
||||
@ -682,7 +656,7 @@ export class SocketManager implements ZoneEventListener {
|
||||
urlToRedirect: string,
|
||||
buttonTitle: string
|
||||
) {
|
||||
const errorMessage = new ErrorV2Message();
|
||||
const errorMessage = new ErrorScreenMessage();
|
||||
errorMessage.setType(type);
|
||||
errorMessage.setCode(code);
|
||||
errorMessage.setTitle(title);
|
||||
@ -694,7 +668,7 @@ export class SocketManager implements ZoneEventListener {
|
||||
errorMessage.setButtontitle(buttonTitle);
|
||||
|
||||
const serverToClientMessage = new ServerToClientMessage();
|
||||
serverToClientMessage.setErrorv2message(errorMessage);
|
||||
serverToClientMessage.setErrorscreenmessage(errorMessage);
|
||||
|
||||
//if (!client.disconnecting) {
|
||||
client.send(serverToClientMessage.serializeBinary().buffer, true);
|
||||
@ -728,7 +702,7 @@ export class SocketManager implements ZoneEventListener {
|
||||
let tabUrlRooms: string[];
|
||||
|
||||
if (playGlobalMessageEvent.getBroadcasttoworld()) {
|
||||
tabUrlRooms = await adminApi.getUrlRoomsFromSameWorld(clientRoomUrl);
|
||||
tabUrlRooms = await adminService.getUrlRoomsFromSameWorld(clientRoomUrl);
|
||||
} else {
|
||||
tabUrlRooms = [clientRoomUrl];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user