From 73373ce08b060c97fcb6311e862b8261c3222d9f Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 7 Aug 2024 20:49:33 +0200 Subject: [PATCH] add ban button --- webAO/client/sender/index.ts | 5 ++++- webAO/client/sender/sendMA.ts | 11 +++++++++++ webAO/dom/banPlayer.ts | 14 ++++++++++++++ webAO/dom/window.ts | 3 ++- webAO/packets/handlers/handlePR.ts | 11 +++++++++-- webAO/packets/handlers/handlePV.ts | 2 +- 6 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 webAO/client/sender/sendMA.ts create mode 100644 webAO/dom/banPlayer.ts diff --git a/webAO/client/sender/index.ts b/webAO/client/sender/index.ts index 41a6bd57..4781ec1b 100644 --- a/webAO/client/sender/index.ts +++ b/webAO/client/sender/index.ts @@ -11,6 +11,7 @@ import {sendZZ} from './sendZZ' import {sendEE} from './sendEE' import {sendDE} from './sendDE' import {sendPE} from './sendPE' +import {sendMA} from './sendMA' export interface ISender { sendIC: (deskmod: number, preanim: string, @@ -50,6 +51,7 @@ export interface ISender { sendEE: (id: number, name: string, desc: string, img: string) => void sendDE: (id: number) => void sendPE: (name: string, desc: string, img: string) => void + sendMA: (id: number, length: number, reason: string) => void } export const sender = { sendIC, @@ -64,5 +66,6 @@ export const sender = { sendZZ, sendEE, sendDE, - sendPE + sendPE, + sendMA } \ No newline at end of file diff --git a/webAO/client/sender/sendMA.ts b/webAO/client/sender/sendMA.ts new file mode 100644 index 00000000..5ba4e4b2 --- /dev/null +++ b/webAO/client/sender/sendMA.ts @@ -0,0 +1,11 @@ +import { client } from "../../client"; + +/** + * Sends mod command. + * @param {number} id player id + * @param {number} length in hours + * @param {string} reason player message + */ +export const sendMA = (id: number, length: number, reason: string) => { + client.sender.sendServer(`MA#${id}#${length}#${reason}#%`); +} \ No newline at end of file diff --git a/webAO/dom/banPlayer.ts b/webAO/dom/banPlayer.ts new file mode 100644 index 00000000..a8f6d5a1 --- /dev/null +++ b/webAO/dom/banPlayer.ts @@ -0,0 +1,14 @@ +import { client } from '../client' +/** + * Tries to ban a player from the playerlist + * @param {Number} id the players id + */ +export function banPlayer(id: number) { + let reason; + let length; + reason = prompt("Please enter the ban reason", ""); + length = Number(prompt("Please enter the ban length in hours", "")); + + client.sender.sendMA(id, length, reason); +} +window.banPlayer = banPlayer; \ No newline at end of file diff --git a/webAO/dom/window.ts b/webAO/dom/window.ts index 3215b89c..f2cd86cb 100644 --- a/webAO/dom/window.ts +++ b/webAO/dom/window.ts @@ -26,7 +26,7 @@ declare global { editEvidence: () => void; addEvidence: () => void; pickEvidence: (evidence: any) => void; - pickEmotion: (emo: any) => void; + pickEmotion: (emo: number) => void; pickChar: (ccharacter: any) => void; chartable_filter: (_event: any) => void; ReconnectButton: (_event: any) => void; @@ -52,6 +52,7 @@ declare global { onEnter: (event: any) => void; onReplayGo: (_event: any) => void; onOOCEnter: (_event: any) => void; + banPlayer: (id: number) => void; hcallback: (_event: any) => void; } } diff --git a/webAO/packets/handlers/handlePR.ts b/webAO/packets/handlers/handlePR.ts index d3f43648..a52ad1f3 100644 --- a/webAO/packets/handlers/handlePR.ts +++ b/webAO/packets/handlers/handlePR.ts @@ -1,6 +1,7 @@ import { client } from "../../client"; +import { banPlayer } from '../../dom/banPlayer' -function addPlayer(playerID: Number) { +function addPlayer(playerID: number) { const list = document.getElementById("client_playerlist"); const playerRow = list.insertRow(); playerRow.id = `client_playerlist_entry${playerID}`; @@ -17,9 +18,15 @@ function addPlayer(playerID: Number) { showNameCell.appendChild(name); const oocNameCell = playerRow.insertCell(3); oocNameCell.appendChild(name); + + const banCell = playerRow.insertCell(4); + const ban = document.createElement("button"); + ban.innerText = "Ban"; + ban.onclick = () => { window.banPlayer(playerID) } + banCell.appendChild(ban); } -function removePlayer(playerID: Number) { +function removePlayer(playerID: number) { const playerRow = document.getElementById(`client_playerlist_entry${playerID}`); playerRow.remove(); } diff --git a/webAO/packets/handlers/handlePV.ts b/webAO/packets/handlers/handlePV.ts index 38657bea..5a04b899 100644 --- a/webAO/packets/handlers/handlePV.ts +++ b/webAO/packets/handlers/handlePV.ts @@ -4,7 +4,7 @@ import { updateActionCommands } from '../../dom/updateActionCommands' import { pickEmotion } from '../../dom/pickEmotion' import { AO_HOST } from "../../client/aoHost"; -function addEmoteButton(i: Number, imgurl: string, desc: string) { +function addEmoteButton(i: number, imgurl: string, desc: string) { const emotesList = document.getElementById("client_emo"); const emote_item = new Image(); emote_item.id = "emo_" + i;