From 8c9e9522dbd6b0675d03d409ea42fc276cd1c836 Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Fri, 15 Jan 2021 03:15:14 +0100 Subject: [PATCH] Revert "Update ban feature" This reverts commit d2ee52ce43f80d6abb0e02ef56313e7041dacaae. --- back/src/Model/Admin.ts | 14 ++++++++------ back/src/Model/GameRoom.ts | 18 ++++-------------- back/src/Model/User.ts | 1 - back/tests/GameRoomTest.ts | 1 - messages/protos/messages.proto | 5 ++--- pusher/src/Controller/IoSocketController.ts | 6 +----- .../src/Model/Websocket/ExSocketInterface.ts | 1 - pusher/src/Services/AdminApi.ts | 17 ----------------- pusher/src/Services/JWTTokenManager.ts | 15 ++------------- pusher/src/Services/SocketManager.ts | 16 +++++++++------- 10 files changed, 26 insertions(+), 68 deletions(-) diff --git a/back/src/Model/Admin.ts b/back/src/Model/Admin.ts index 53757e96..aa4bd328 100644 --- a/back/src/Model/Admin.ts +++ b/back/src/Model/Admin.ts @@ -21,15 +21,17 @@ export class Admin { ) { } - public sendUserJoin(uuid: string, name: string, ip: string): void { - let serverToAdminClientMessage = new ServerToAdminClientMessage(); - serverToAdminClientMessage = serverToAdminClientMessage.setUseruuidnamejoinedroom(uuid+';'+name+';'+ip) + public sendUserJoin(uuid: string): void { + const serverToAdminClientMessage = new ServerToAdminClientMessage(); + serverToAdminClientMessage.setUseruuidjoinedroom(uuid); + this.socket.write(serverToAdminClientMessage); } - public sendUserLeft(uuid: string, name: string, ip: string): void { - let serverToAdminClientMessage = new ServerToAdminClientMessage(); - serverToAdminClientMessage = serverToAdminClientMessage.setUseruuidnameleftroom(uuid+';'+name+';'+ip); + public sendUserLeft(uuid: string): void { + const serverToAdminClientMessage = new ServerToAdminClientMessage(); + serverToAdminClientMessage.setUseruuidleftroom(uuid); + this.socket.write(serverToAdminClientMessage); } } diff --git a/back/src/Model/GameRoom.ts b/back/src/Model/GameRoom.ts index 8a57ee99..129b0ac8 100644 --- a/back/src/Model/GameRoom.ts +++ b/back/src/Model/GameRoom.ts @@ -102,17 +102,7 @@ export class GameRoom { } const position = ProtobufUtils.toPointInterface(positionMessage); - const user = new User(this.nextUserId, - joinRoomMessage.getUseruuid(), - joinRoomMessage.getIpaddress(), - position, - false, - this.positionNotifier, - socket, - joinRoomMessage.getTagList(), - joinRoomMessage.getName(), - ProtobufUtils.toCharacterLayerObjects(joinRoomMessage.getCharacterlayerList()) - ); + const user = new User(this.nextUserId, joinRoomMessage.getUseruuid(), position, false, this.positionNotifier, socket, joinRoomMessage.getTagList(), joinRoomMessage.getName(), ProtobufUtils.toCharacterLayerObjects(joinRoomMessage.getCharacterlayerList())); this.nextUserId++; this.users.set(user.id, user); this.usersByUuid.set(user.uuid, user); @@ -122,7 +112,7 @@ export class GameRoom { // Notify admins for (const admin of this.admins) { - admin.sendUserJoin(user.uuid, user.name, user.IPAddress); + admin.sendUserJoin(user.uuid); } return user; @@ -145,7 +135,7 @@ export class GameRoom { // Notify admins for (const admin of this.admins) { - admin.sendUserLeft(user.uuid, user.name, user.IPAddress); + admin.sendUserLeft(user.uuid); } } @@ -328,7 +318,7 @@ export class GameRoom { // Let's send all connected users for (const user of this.users.values()) { - admin.sendUserJoin(user.uuid, user.name, user.IPAddress); + admin.sendUserJoin(user.uuid); } } diff --git a/back/src/Model/User.ts b/back/src/Model/User.ts index 51a1a617..2bc3ee22 100644 --- a/back/src/Model/User.ts +++ b/back/src/Model/User.ts @@ -16,7 +16,6 @@ export class User implements Movable { public constructor( public id: number, public readonly uuid: string, - public readonly IPAddress: string, private position: PointInterface, public silent: boolean, private positionNotifier: PositionNotifier, diff --git a/back/tests/GameRoomTest.ts b/back/tests/GameRoomTest.ts index 45721334..3dc9aada 100644 --- a/back/tests/GameRoomTest.ts +++ b/back/tests/GameRoomTest.ts @@ -26,7 +26,6 @@ function createJoinRoomMessage(uuid: string, x: number, y: number): JoinRoomMess positionMessage.setMoving(false); const joinRoomMessage = new JoinRoomMessage(); joinRoomMessage.setUseruuid('1'); - joinRoomMessage.setIpaddress('10.0.0.2'); joinRoomMessage.setName('foo'); joinRoomMessage.setRoomid('_/global/test.json'); joinRoomMessage.setPositionmessage(positionMessage); diff --git a/messages/protos/messages.proto b/messages/protos/messages.proto index 0e92f381..24db45d5 100644 --- a/messages/protos/messages.proto +++ b/messages/protos/messages.proto @@ -220,7 +220,6 @@ message JoinRoomMessage { string userUuid = 4; string roomId = 5; repeated string tag = 6; - string IPAddress = 7; } message UserJoinedZoneMessage { @@ -309,8 +308,8 @@ message ServerToAdminClientMessage { message ServerToAdminClientMessage { oneof message { - string userUuidNameJoinedRoom = 1; - string userUuidNameLeftRoom = 2; + string userUuidJoinedRoom = 1; + string userUuidLeftRoom = 2; } } diff --git a/pusher/src/Controller/IoSocketController.ts b/pusher/src/Controller/IoSocketController.ts index a8bedabb..58cf05fb 100644 --- a/pusher/src/Controller/IoSocketController.ts +++ b/pusher/src/Controller/IoSocketController.ts @@ -148,7 +148,6 @@ export class IoSocketController { const websocketKey = req.getHeader('sec-websocket-key'); const websocketProtocol = req.getHeader('sec-websocket-protocol'); const websocketExtensions = req.getHeader('sec-websocket-extensions'); - const IPAddress = req.getHeader('x-forwarded-for'); const roomId = query.roomId; if (typeof roomId !== 'string') { @@ -178,8 +177,7 @@ export class IoSocketController { } const userUuid = await jwtTokenManager.getUserUuidFromToken(token); - //TODO send ban message - await jwtTokenManager.verifyBanUser(userUuid, IPAddress, roomId); + let memberTags: string[] = []; let memberTextures: CharacterTexture[] = []; const room = await socketManager.getOrCreateRoom(roomId); @@ -219,7 +217,6 @@ export class IoSocketController { url, token, userUuid, - IPAddress, roomId, name, characterLayers: characterLayerObjs, @@ -339,7 +336,6 @@ export class IoSocketController { client.userId = this.nextUserId; this.nextUserId++; client.userUuid = ws.userUuid; - client.IPAddress = ws.IPAddress; client.token = ws.token; client.batchedMessages = new BatchMessage(); client.batchTimeout = null; diff --git a/pusher/src/Model/Websocket/ExSocketInterface.ts b/pusher/src/Model/Websocket/ExSocketInterface.ts index 85cfad48..b8ee4bc8 100644 --- a/pusher/src/Model/Websocket/ExSocketInterface.ts +++ b/pusher/src/Model/Websocket/ExSocketInterface.ts @@ -24,7 +24,6 @@ export interface ExSocketInterface extends WebSocket, Identificable { roomId: string; //userId: number; // A temporary (autoincremented) identifier for this user userUuid: string; // A unique identifier for this user - IPAddress: string; // IP address name: string; characterLayers: CharacterLayer[]; position: PointInterface; diff --git a/pusher/src/Services/AdminApi.ts b/pusher/src/Services/AdminApi.ts index 75977482..9c46a41b 100644 --- a/pusher/src/Services/AdminApi.ts +++ b/pusher/src/Services/AdminApi.ts @@ -14,11 +14,6 @@ export interface AdminApiData { textures: CharacterTexture[] } -export interface AdminBannedData { - is_banned: boolean, - message: string -} - export interface CharacterTexture { id: number, level: number, @@ -115,18 +110,6 @@ class AdminApi { headers: {"Authorization": `${ADMIN_API_TOKEN}`} }); } - - async verifyBanUser(organizationMemberToken: string, ipAddress: string, room: string): Promise { - if (!ADMIN_API_URL) { - return Promise.reject('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 + '/api/check-moderate-user/' + ipAddress + '/' + organizationMemberToken + '/room/' + room, - {headers: {"Authorization": `${ADMIN_API_TOKEN}`}} - ).then((data) => { - return data.data; - }); - } } export const adminApi = new AdminApi(); diff --git a/pusher/src/Services/JWTTokenManager.ts b/pusher/src/Services/JWTTokenManager.ts index ca692b77..8abb0e45 100644 --- a/pusher/src/Services/JWTTokenManager.ts +++ b/pusher/src/Services/JWTTokenManager.ts @@ -2,7 +2,7 @@ import {ADMIN_API_URL, ALLOW_ARTILLERY, SECRET_KEY} from "../Enum/EnvironmentVar import {uuid} from "uuidv4"; import Jwt from "jsonwebtoken"; import {TokenInterface} from "../Controller/AuthenticateController"; -import {adminApi, AdminBannedData} from "../Services/AdminApi"; +import {adminApi, AdminApiData} from "../Services/AdminApi"; class JWTTokenManager { @@ -54,7 +54,7 @@ class JWTTokenManager { resolve(tokenInterface.userUuid); }).catch((err) => { //anonymous user - if (err.response && err.response.status && err.response.status === 404) { + if(err.response && err.response.status && err.response.status === 404){ resolve(tokenInterface.userUuid); return; } @@ -67,17 +67,6 @@ class JWTTokenManager { }); } - public async verifyBanUser(userUuid: string, ipAddress: string, room: string): Promise { - room = room.split('/').join('_'); - return adminApi.verifyBanUser(userUuid, ipAddress, room).then((data: AdminBannedData) => { - if (data && data.is_banned) { - throw new Error('User was banned'); - } - }).catch((err) => { - throw err; - }); - } - private isValidToken(token: object): token is TokenInterface { return !(typeof((token as TokenInterface).userUuid) !== 'string'); } diff --git a/pusher/src/Services/SocketManager.ts b/pusher/src/Services/SocketManager.ts index df944b9e..6255ca20 100644 --- a/pusher/src/Services/SocketManager.ts +++ b/pusher/src/Services/SocketManager.ts @@ -79,20 +79,23 @@ export class SocketManager implements ZoneEventListener { } async handleAdminRoom(client: ExAdminSocketInterface, roomId: string): Promise { + console.log('Calling adminRoom') const apiClient = await apiClientRepository.getClient(roomId); const adminRoomStream = apiClient.adminRoom(); client.adminConnection = adminRoomStream; adminRoomStream.on('data', (message: ServerToAdminClientMessage) => { - if (message.hasUseruuidnamejoinedroom()) { - const userUuidName = message.getUseruuidnamejoinedroom(); + if (message.hasUseruuidjoinedroom()) { + const userUuid = message.getUseruuidjoinedroom(); + if (!client.disconnecting) { - client.send('MemberJoin:'+userUuidName+';'+roomId); + client.send('MemberJoin:'+userUuid+';'+roomId); } - } else if (message.hasUseruuidnameleftroom()) { - const userUuidName = message.getUseruuidnameleftroom(); + } else if (message.hasUseruuidleftroom()) { + const userUuid = message.getUseruuidleftroom(); + if (!client.disconnecting) { - client.send('MemberLeave:'+userUuidName+';'+roomId); + client.send('MemberLeave:'+userUuid+';'+roomId); } } else { throw new Error('Unexpected admin message'); @@ -148,7 +151,6 @@ export class SocketManager implements ZoneEventListener { const joinRoomMessage = new JoinRoomMessage(); joinRoomMessage.setUseruuid(client.userUuid); - joinRoomMessage.setIpaddress(client.IPAddress); joinRoomMessage.setRoomid(client.roomId); joinRoomMessage.setName(client.name); joinRoomMessage.setPositionmessage(ProtobufUtils.toPositionMessage(client.position));