create message to report

This commit is contained in:
Gregoire Parant 2020-10-12 11:22:41 +02:00
parent 07c17452e7
commit aeced0c648
6 changed files with 77 additions and 27 deletions

View File

@ -42,7 +42,7 @@ import {
SilentMessage,
WebRtcSignalToClientMessage,
WebRtcSignalToServerMessage,
WebRtcStartMessage, WebRtcDisconnectMessage, PlayGlobalMessage
WebRtcStartMessage, WebRtcDisconnectMessage, PlayGlobalMessage, ReportPlayerMessage
} from "../Messages/generated/messages_pb";
import {UserMovesMessage} from "../Messages/generated/messages_pb";
import Direction = PositionMessage.Direction;
@ -50,6 +50,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";
function emitInBatch(socket: ExSocketInterface, payload: SubMessage): void {
socket.batchedMessages.addPayload(payload);
@ -267,11 +268,13 @@ export class IoSocketController {
} else if (message.hasItemeventmessage()) {
this.handleItemEvent(client, message.getItemeventmessage() as ItemEventMessage);
} else if (message.hasWebrtcsignaltoservermessage()) {
this.emitVideo(client, message.getWebrtcsignaltoservermessage() as WebRtcSignalToServerMessage)
this.emitVideo(client, message.getWebrtcsignaltoservermessage() as WebRtcSignalToServerMessage);
} else if (message.hasWebrtcscreensharingsignaltoservermessage()) {
this.emitScreenSharing(client, message.getWebrtcscreensharingsignaltoservermessage() as WebRtcSignalToServerMessage)
this.emitScreenSharing(client, message.getWebrtcscreensharingsignaltoservermessage() as WebRtcSignalToServerMessage);
} else if (message.hasPlayglobalmessage()) {
this.emitPlayGlobalMessage(client, message.getPlayglobalmessage() as PlayGlobalMessage)
this.emitPlayGlobalMessage(client, message.getPlayglobalmessage() as PlayGlobalMessage);
} else if (message.hasReportplayermessage()){
this.handleReportMessage(client, message.getReportplayermessage() as ReportPlayerMessage);
}
/* Ok is false if backpressure was built up, wait for drain */
@ -547,6 +550,24 @@ export class IoSocketController {
}
}
private handleReportMessage(client: ExSocketInterface, reportPlayerMessage: ReportPlayerMessage) {
try {
let reportedSocket = this.sockets.get(reportPlayerMessage.getReporteduserid());
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,
});
} catch (e) {
console.error('An error occurred on "handleReportMessage"');
console.error(e);
}
}
emitVideo(socket: ExSocketInterface, data: WebRtcSignalToServerMessage): void {
//send only at user
const client = this.sockets.get(data.getReceiverid());

View File

@ -21,7 +21,8 @@ import {
WebRtcDisconnectMessage,
WebRtcSignalToClientMessage,
WebRtcSignalToServerMessage,
WebRtcStartMessage
WebRtcStartMessage,
ReportPlayerMessage
} from "../Messages/generated/messages_pb"
import {UserSimplePeerInterface} from "../WebRtc/SimplePeer";
@ -401,7 +402,6 @@ export class RoomConnection implements RoomConnection {
}
callback(event);
});
}
public getUserId(): number|null {
@ -478,4 +478,15 @@ export class RoomConnection implements RoomConnection {
this.socket.send(clientToServerMessage.serializeBinary().buffer);
}
public emitReportPlayerMessage(reportedUserId: number, reportComment: string ): void {
const reportPlayerMessage = new ReportPlayerMessage();
reportPlayerMessage.setReporteduserid(reportedUserId);
reportPlayerMessage.setReportcomment(reportComment);
const clientToServerMessage = new ClientToServerMessage();
clientToServerMessage.setReportplayermessage(reportPlayerMessage);
this.socket.send(clientToServerMessage.serializeBinary().buffer);
}
}

View File

@ -46,8 +46,7 @@ export abstract class Character extends Container {
public PlayerValue: string;
public sprites: Map<string, Sprite>;
private lastDirection: string = PlayerAnimationNames.WalkDown;
private report: Sprite;
private teleportation: Sprite;
//private teleportation: Sprite;
constructor(scene: Phaser.Scene,
x: number,
@ -65,14 +64,6 @@ export abstract class Character extends Container {
for (const texture of textures) {
const sprite = new Sprite(scene, 0, 0, texture, frame);
sprite.setInteractive({useHandCursor: true});
sprite.on('pointerover', () => {
this.report.visible = true;
this.teleportation.visible = true;
});
sprite.on('pointerup', () => {
this.report.visible = true;
this.teleportation.visible = true;
});
this.add(sprite);
this.getPlayerAnimations(texture).forEach(d => {
this.scene.anims.create({
@ -87,23 +78,14 @@ export abstract class Character extends Container {
this.sprites.set(texture, sprite);
}
this.report = new Sprite(scene, 20, -10, 'report_flag', 3);
this.report.setInteractive();
this.report.visible = false;
this.report.on('pointerup', () => {
this.report.visible = false;
this.teleportation.visible = false;
});
this.add(this.report);
this.teleportation = new Sprite(scene, -20, -10, 'teleportation', 3);
/*this.teleportation = new Sprite(scene, -20, -10, 'teleportation', 3);
this.teleportation.setInteractive();
this.teleportation.visible = false;
this.teleportation.on('pointerup', () => {
this.report.visible = false;
this.teleportation.visible = false;
});
this.add(this.teleportation);
this.add(this.teleportation);*/
this.PlayerValue = name;
this.playerName = new BitmapText(scene, x, y - 25, 'main_font', name, 8);

View File

@ -1,12 +1,14 @@
import {GameScene} from "../Game/GameScene";
import {PointInterface} from "../../Connexion/ConnexionModels";
import {Character} from "../Entity/Character";
import {Sprite} from "./Sprite";
/**
* Class representing the sprite of a remote player (a player that plays on another computer)
*/
export class RemotePlayer extends Character {
userId: number;
private report: Sprite;
constructor(
userId: number,
@ -23,6 +25,25 @@ export class RemotePlayer extends Character {
//set data
this.userId = userId;
this.report = new Sprite(Scene, 20, -10, 'report_flag', 3);
this.report.setInteractive();
this.report.visible = false;
this.report.on('pointerup', () => {
//this.scene.events.emit('reportUser', {reportedUserId: userId, reportComment: comment});
this.scene.events.emit('reportUser', {reportedUserId: this.userId, reportComment: 'test'});
this.report.visible = false;
});
this.add(this.report);
this.sprites.forEach((sprite: Sprite) => {
sprite.on('pointerover', () => {
this.report.visible = true;
});
sprite.on('pointerup', () => {
this.report.visible = true;
});
})
//the current player model should be push away by other players to prevent conflict
//this.setImmovable(false);
}

View File

@ -601,6 +601,9 @@ export class GameScene extends ResizableScene implements CenterListener {
this.connection.setSilent(true);
}
});
//lisen event to report user
this.onReportUser();
}
private switchLayoutMode(): void {
@ -1181,4 +1184,10 @@ export class GameScene extends ResizableScene implements CenterListener {
public onCenterChange(): void {
this.updateCameraOffset();
}
public onReportUser(){
this.events.on('reportUser', (message: {reportedUserId: number, reportComment: string}) => {
this.connection.emitReportPlayerMessage(message.reportedUserId, message.reportComment);
});
}
}

View File

@ -54,6 +54,11 @@ message WebRtcSignalToServerMessage {
string signal = 2;
}
message ReportPlayerMessage {
int32 reportedUserId = 1;
string reportComment = 2;
}
message ClientToServerMessage {
oneof message {
JoinRoomMessage joinRoomMessage = 1;
@ -66,6 +71,7 @@ message ClientToServerMessage {
WebRtcSignalToServerMessage webRtcScreenSharingSignalToServerMessage = 8;
PlayGlobalMessage playGlobalMessage = 9;
StopGlobalMessage stopGlobalMessage = 10;
ReportPlayerMessage reportPlayerMessage = 11;
}
}