Create ban feature by admin console
This commit is contained in:
parent
871ee6b192
commit
b1f8522c05
10 changed files with 68 additions and 26 deletions
|
@ -14,6 +14,11 @@ export interface AdminApiData {
|
|||
textures: CharacterTexture[]
|
||||
}
|
||||
|
||||
export interface AdminBannedData {
|
||||
is_banned: boolean,
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface CharacterTexture {
|
||||
id: number,
|
||||
level: number,
|
||||
|
@ -110,6 +115,18 @@ class AdminApi {
|
|||
headers: {"Authorization": `${ADMIN_API_TOKEN}`}
|
||||
});
|
||||
}
|
||||
|
||||
async verifyBanUser(organizationMemberToken: string, ipAddress: string, room: string): Promise<AdminBannedData> {
|
||||
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();
|
||||
|
|
|
@ -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, AdminApiData} from "../Services/AdminApi";
|
||||
import {adminApi, AdminBannedData} 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,6 +67,17 @@ class JWTTokenManager {
|
|||
});
|
||||
}
|
||||
|
||||
public async verifyBanUser(userUuid: string, ipAddress: string, room: string): Promise<unknown> {
|
||||
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');
|
||||
}
|
||||
|
|
|
@ -79,23 +79,20 @@ export class SocketManager implements ZoneEventListener {
|
|||
}
|
||||
|
||||
async handleAdminRoom(client: ExAdminSocketInterface, roomId: string): Promise<void> {
|
||||
console.log('Calling adminRoom')
|
||||
const apiClient = await apiClientRepository.getClient(roomId);
|
||||
const adminRoomStream = apiClient.adminRoom();
|
||||
client.adminConnection = adminRoomStream;
|
||||
|
||||
adminRoomStream.on('data', (message: ServerToAdminClientMessage) => {
|
||||
if (message.hasUseruuidjoinedroom()) {
|
||||
const userUuid = message.getUseruuidjoinedroom();
|
||||
|
||||
if (message.hasUseruuidnamejoinedroom()) {
|
||||
const userUuidName = message.getUseruuidnamejoinedroom();
|
||||
if (!client.disconnecting) {
|
||||
client.send('MemberJoin:'+userUuid+';'+roomId);
|
||||
client.send('MemberJoin:'+userUuidName+';'+roomId);
|
||||
}
|
||||
} else if (message.hasUseruuidleftroom()) {
|
||||
const userUuid = message.getUseruuidleftroom();
|
||||
|
||||
} else if (message.hasUseruuidnameleftroom()) {
|
||||
const userUuidName = message.getUseruuidnameleftroom();
|
||||
if (!client.disconnecting) {
|
||||
client.send('MemberLeave:'+userUuid+';'+roomId);
|
||||
client.send('MemberLeave:'+userUuidName+';'+roomId);
|
||||
}
|
||||
} else {
|
||||
throw new Error('Unexpected admin message');
|
||||
|
@ -151,6 +148,7 @@ 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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue