aboutsummaryrefslogtreecommitdiff
path: root/webAO/packets/handlers/handlePR.ts
blob: e39103d3bda9173371c6879f3dadc92fd3cf2bd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { client } from "../../client";
import { kickPlayer, banPlayer } from "../../dom/banPlayer";

function addPlayer(playerID: number) {
  const list = <HTMLTableElement>document.getElementById("client_playerlist");
  const playerRow = list.insertRow();
  playerRow.id = `client_playerlist_entry${playerID}`;
  playerRow.className = `area0`;

  const imgCell = playerRow.insertCell(0);
  imgCell.style.width = "64px";
  const img = document.createElement("img");
  imgCell.appendChild(img);

  const name = document.createTextNode("No Data");

  const charNameCell = playerRow.insertCell(1);
  charNameCell.appendChild(name);
  const showNameCell = playerRow.insertCell(2);
  showNameCell.appendChild(name);
  const oocNameCell = playerRow.insertCell(3);
  oocNameCell.appendChild(name);

  const kickCell = playerRow.insertCell(4);
  kickCell.style.width = "64px";
  const kick = <HTMLButtonElement>document.createElement("button");
  kick.innerText = "Kick";
  kick.onclick = () => {
    window.kickPlayer(playerID);
  };
  kickCell.appendChild(kick);

  const banCell = playerRow.insertCell(5);
  banCell.style.width = "64px";
  const ban = <HTMLButtonElement>document.createElement("button");
  ban.innerText = "Ban";
  ban.onclick = () => {
    window.banPlayer(playerID);
  };
  banCell.appendChild(ban);
}

function removePlayer(playerID: number) {
  const playerRow = <HTMLTableElement>(
    document.getElementById(`client_playerlist_entry${playerID}`)
  );
  playerRow.remove();
}

/**
 * Handles a player joining or leaving
 * @param {Array} args packet arguments
 */
export const handlePR = (args: string[]) => {
  const playerID = Number(args[1]);
  if (Number(args[2]) === 0) {
    addPlayer(playerID);
    client.players.set(playerID, { charId: -1, area: 0 });
  } else if (Number(args[2]) === 1) {
    removePlayer(playerID);
    client.players.delete(playerID);
  }
};