diff options
Diffstat (limited to 'webAO/client')
| -rw-r--r-- | webAO/client/handleCharacterInfo.ts | 38 | ||||
| -rw-r--r-- | webAO/client/sender/index.ts | 5 | ||||
| -rw-r--r-- | webAO/client/sender/sendMA.ts | 11 |
3 files changed, 35 insertions, 19 deletions
diff --git a/webAO/client/handleCharacterInfo.ts b/webAO/client/handleCharacterInfo.ts index 9d74a8b..cd024b5 100644 --- a/webAO/client/handleCharacterInfo.ts +++ b/webAO/client/handleCharacterInfo.ts @@ -6,6 +6,24 @@ import fileExists from "../utils/fileExists"; import { AO_HOST } from "./aoHost"; +export const getCharIcon = async (img: HTMLImageElement, charname: string) => { + const extensions = [".png", ".webp"]; + img.alt = charname; + const charIconBaseUrl = `${AO_HOST}characters/${encodeURI( + charname.toLowerCase() + )}/char_icon`; + for (let i = 0; i < extensions.length; i++) { + const fileUrl = charIconBaseUrl + extensions[i]; + const exists = await fileExists(fileUrl); + if (exists) { + img.alt = charname; + img.title = charname; + img.src = fileUrl; + return; + } + } +}; + /** * Handles the incoming character information, and downloads the sprite + ini for it * @param {Array} chargs packet arguments @@ -15,24 +33,8 @@ export const handleCharacterInfo = async (chargs: string[], charid: number) => { const img = <HTMLImageElement>document.getElementById(`demo_${charid}`); if (chargs[0]) { let cini: any = {}; - const getCharIcon = async () => { - const extensions = [".png", ".webp"]; - img.alt = chargs[0]; - const charIconBaseUrl = `${AO_HOST}characters/${encodeURI( - chargs[0].toLowerCase() - )}/char_icon`; - for (let i = 0; i < extensions.length; i++) { - const fileUrl = charIconBaseUrl + extensions[i]; - const exists = await fileExists(fileUrl); - if (exists) { - img.alt = chargs[0]; - img.title = chargs[0]; - img.src = fileUrl; - return; - } - } - }; - getCharIcon(); + + getCharIcon(img, chargs[0]); // If the ini doesn't exist on the server this will throw an error try { diff --git a/webAO/client/sender/index.ts b/webAO/client/sender/index.ts index 41a6bd5..4781ec1 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 0000000..5ba4e4b --- /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 |
