Finish report in admin

This commit is contained in:
Gregoire Parant 2020-10-13 09:37:38 +02:00
parent aeced0c648
commit 3c2f134e4e
2 changed files with 24 additions and 9 deletions

View File

@ -2,7 +2,14 @@ import * as http from "http";
import {MessageUserPosition, Point} from "../Model/Websocket/MessageUserPosition"; //TODO fix import by "_Model/.."
import {ExSocketInterface} from "../Model/Websocket/ExSocketInterface"; //TODO fix import by "_Model/.."
import Jwt, {JsonWebTokenError} from "jsonwebtoken";
import {SECRET_KEY, MINIMUM_DISTANCE, GROUP_RADIUS, ALLOW_ARTILLERY} from "../Enum/EnvironmentVariable"; //TODO fix import by "_Enum/..."
import {
SECRET_KEY,
MINIMUM_DISTANCE,
GROUP_RADIUS,
ALLOW_ARTILLERY,
ADMIN_API_URL,
ADMIN_API_TOKEN
} from "../Enum/EnvironmentVariable"; //TODO fix import by "_Enum/..."
import {World} from "../Model/World";
import {Group} from "../Model/Group";
import {User} from "../Model/User";
@ -50,7 +57,7 @@ import {ProtobufUtils} from "../Model/Websocket/ProtobufUtils";
import {App, HttpRequest, TemplatedApp, WebSocket} from "uWebSockets.js"
import {parse} from "query-string";
import {cpuTracker} from "../Services/CpuTracker";
import axios from "axios";
import Axios from "axios";
function emitInBatch(socket: ExSocketInterface, payload: SubMessage): void {
socket.batchedMessages.addPayload(payload);
@ -553,14 +560,22 @@ export class IoSocketController {
private handleReportMessage(client: ExSocketInterface, reportPlayerMessage: ReportPlayerMessage) {
try {
let reportedSocket = this.sockets.get(reportPlayerMessage.getReporteduserid());
if(!reportedSocket){
if (!reportedSocket) {
throw 'reported socket user not found';
}
//TODO report user on admin application
axios.post('/report', {
reportedUserId: reportPlayerMessage.getReporteduserid(),
reportedUserComment: reportPlayerMessage.getReportcomment(),
reporterUserId: client.userUuid,
console.log('ADMIN_API_URL', ADMIN_API_URL);
console.log('ADMIN_API_TOKEN', ADMIN_API_TOKEN);
Axios.post(`${ADMIN_API_URL}/aoi/report`, {
reportedUserUuid: client.userUuid,
reportedUserComment: reportPlayerMessage.getReportcomment(),
reporterUserUuid: client.userUuid,
},
{
headers: {"Authorization": `${ADMIN_API_TOKEN}`}
}).catch((err) => {
console.error(err);
throw err;
});
} catch (e) {
console.error('An error occurred on "handleReportMessage"');

View File

@ -3,8 +3,8 @@ const URL_ROOM_STARTED = "/Floor0/floor0.json";
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 ALLOW_ARTILLERY = process.env.ALLOW_ARTILLERY ? process.env.ALLOW_ARTILLERY == 'true' : false;
const ADMIN_API_URL = process.env.ADMIN_API_URL || null;
const ADMIN_API_TOKEN = process.env.ADMIN_API_TOKEN || null;
const ADMIN_API_URL = process.env.ADMIN_API_URL || 'http://admin';
const ADMIN_API_TOKEN = process.env.ADMIN_API_TOKEN || 'myapitoken';
const CPU_OVERHEAT_THRESHOLD = Number(process.env.CPU_OVERHEAT_THRESHOLD) || 80;
export {