reformat typescript code with prettier

Mostly just for nicity. I did manually clean up a few things, but other than that, this basically was just importing configs from cvm3/crusttest, adding prettier as a dev dependency, and just ctrl-shift-I on every typescript file part of the codebase
This commit is contained in:
modeco80 2024-03-12 01:28:23 -04:00
parent 6dc3ba20af
commit 125e6a769d
14 changed files with 1786 additions and 1751 deletions

5
.prettierignore Normal file
View File

@ -0,0 +1,5 @@
dist
*.md
*.json
*.html
*.css

20
.prettierrc.json Normal file
View File

@ -0,0 +1,20 @@
{
"arrowParens": "always",
"bracketSameLine": false,
"bracketSpacing": true,
"embeddedLanguageFormatting": "auto",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxSingleQuote": true,
"printWidth": 200,
"proseWrap": "preserve",
"quoteProps": "consistent",
"requirePragma": false,
"semi": true,
"singleAttributePerLine": false,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "none",
"useTabs": true,
"vueIndentScriptAndStyle": false
}

View File

@ -26,6 +26,7 @@
"@types/bootstrap": "^5.2.10", "@types/bootstrap": "^5.2.10",
"parcel": "^2.11.0", "parcel": "^2.11.0",
"parcel-reporter-static-files-copy": "^1.5.3", "parcel-reporter-static-files-copy": "^1.5.3",
"prettier": "^3.2.5",
"run-script-os": "^1.1.6", "run-script-os": "^1.1.6",
"typescript": "^5.3.3" "typescript": "^5.3.3"
} }

View File

@ -3,14 +3,8 @@
// shitty but it works so /shrug // shitty but it works so /shrug
// THIS SUCKS SO BAD AND I HATE IT PLEASE REWRITE ALL OF THIS // THIS SUCKS SO BAD AND I HATE IT PLEASE REWRITE ALL OF THIS
export default function GetKeysym( export default function GetKeysym(keyCode: number, key: string, location: number): number | null {
keyCode: number, let keysym = keysym_from_key_identifier(key, location) || keysym_from_keycode(keyCode, location);
key: string,
location: number
): number | null {
let keysym =
keysym_from_key_identifier(key, location) ||
keysym_from_keycode(keyCode, location);
return keysym; return keysym;
} }
@ -20,7 +14,7 @@ export default function GetKeysym(
let typedCharacter: string | undefined; let typedCharacter: string | undefined;
// If identifier is U+xxxx, decode Unicode character // If identifier is U+xxxx, decode Unicode character
const unicodePrefixLocation = identifier.indexOf("U+"); const unicodePrefixLocation = identifier.indexOf('U+');
if (unicodePrefixLocation >= 0) { if (unicodePrefixLocation >= 0) {
const hex = identifier.substring(unicodePrefixLocation + 2); const hex = identifier.substring(unicodePrefixLocation + 2);
typedCharacter = String.fromCharCode(parseInt(hex, 16)); typedCharacter = String.fromCharCode(parseInt(hex, 16));
@ -55,7 +49,7 @@ export default function GetKeysym(
function key_identifier_sane(keyCode: number, keyIdentifier: string): boolean { function key_identifier_sane(keyCode: number, keyIdentifier: string): boolean {
if (!keyIdentifier) return false; if (!keyIdentifier) return false;
const unicodePrefixLocation = keyIdentifier.indexOf("U+"); const unicodePrefixLocation = keyIdentifier.indexOf('U+');
if (unicodePrefixLocation === -1) return true; if (unicodePrefixLocation === -1) return true;
const codepoint = parseInt(keyIdentifier.substring(unicodePrefixLocation + 2), 16); const codepoint = parseInt(keyIdentifier.substring(unicodePrefixLocation + 2), 16);
@ -78,337 +72,337 @@ interface KeyIdentifierKeysym {
} }
interface KeyCodeKeysyms { interface KeyCodeKeysyms {
[key: number]: (number[] | null); [key: number]: number[] | null;
} }
var keycodeKeysyms: KeyCodeKeysyms = { var keycodeKeysyms: KeyCodeKeysyms = {
8: [0xFF08], // backspace 8: [0xff08], // backspace
9: [0xFF09], // tab 9: [0xff09], // tab
12: [0xFF0B, 0xFF0B, 0xFF0B, 0xFFB5], // clear / KP 5 12: [0xff0b, 0xff0b, 0xff0b, 0xffb5], // clear / KP 5
13: [0xFF0D], // enter 13: [0xff0d], // enter
16: [0xFFE1, 0xFFE1, 0xFFE2], // shift 16: [0xffe1, 0xffe1, 0xffe2], // shift
17: [0xFFE3, 0xFFE3, 0xFFE4], // ctrl 17: [0xffe3, 0xffe3, 0xffe4], // ctrl
18: [0xFFE9, 0xFFE9, 0xFE03], // alt 18: [0xffe9, 0xffe9, 0xfe03], // alt
19: [0xFF13], // pause/break 19: [0xff13], // pause/break
20: [0xFFE5], // caps lock 20: [0xffe5], // caps lock
27: [0xFF1B], // escape 27: [0xff1b], // escape
32: [0x0020], // space 32: [0x0020], // space
33: [0xFF55, 0xFF55, 0xFF55, 0xFFB9], // page up / KP 9 33: [0xff55, 0xff55, 0xff55, 0xffb9], // page up / KP 9
34: [0xFF56, 0xFF56, 0xFF56, 0xFFB3], // page down / KP 3 34: [0xff56, 0xff56, 0xff56, 0xffb3], // page down / KP 3
35: [0xFF57, 0xFF57, 0xFF57, 0xFFB1], // end / KP 1 35: [0xff57, 0xff57, 0xff57, 0xffb1], // end / KP 1
36: [0xFF50, 0xFF50, 0xFF50, 0xFFB7], // home / KP 7 36: [0xff50, 0xff50, 0xff50, 0xffb7], // home / KP 7
37: [0xFF51, 0xFF51, 0xFF51, 0xFFB4], // left arrow / KP 4 37: [0xff51, 0xff51, 0xff51, 0xffb4], // left arrow / KP 4
38: [0xFF52, 0xFF52, 0xFF52, 0xFFB8], // up arrow / KP 8 38: [0xff52, 0xff52, 0xff52, 0xffb8], // up arrow / KP 8
39: [0xFF53, 0xFF53, 0xFF53, 0xFFB6], // right arrow / KP 6 39: [0xff53, 0xff53, 0xff53, 0xffb6], // right arrow / KP 6
40: [0xFF54, 0xFF54, 0xFF54, 0xFFB2], // down arrow / KP 2 40: [0xff54, 0xff54, 0xff54, 0xffb2], // down arrow / KP 2
45: [0xFF63, 0xFF63, 0xFF63, 0xFFB0], // insert / KP 0 45: [0xff63, 0xff63, 0xff63, 0xffb0], // insert / KP 0
46: [0xFFFF, 0xFFFF, 0xFFFF, 0xFFAE], // delete / KP decimal 46: [0xffff, 0xffff, 0xffff, 0xffae], // delete / KP decimal
91: [0xFFEB], // left window key (hyper_l) 91: [0xffeb], // left window key (hyper_l)
92: [0xFF67], // right window key (menu key?) 92: [0xff67], // right window key (menu key?)
93: null, // select key 93: null, // select key
96: [0xFFB0], // KP 0 96: [0xffb0], // KP 0
97: [0xFFB1], // KP 1 97: [0xffb1], // KP 1
98: [0xFFB2], // KP 2 98: [0xffb2], // KP 2
99: [0xFFB3], // KP 3 99: [0xffb3], // KP 3
100: [0xFFB4], // KP 4 100: [0xffb4], // KP 4
101: [0xFFB5], // KP 5 101: [0xffb5], // KP 5
102: [0xFFB6], // KP 6 102: [0xffb6], // KP 6
103: [0xFFB7], // KP 7 103: [0xffb7], // KP 7
104: [0xFFB8], // KP 8 104: [0xffb8], // KP 8
105: [0xFFB9], // KP 9 105: [0xffb9], // KP 9
106: [0xFFAA], // KP multiply 106: [0xffaa], // KP multiply
107: [0xFFAB], // KP add 107: [0xffab], // KP add
109: [0xFFAD], // KP subtract 109: [0xffad], // KP subtract
110: [0xFFAE], // KP decimal 110: [0xffae], // KP decimal
111: [0xFFAF], // KP divide 111: [0xffaf], // KP divide
112: [0xFFBE], // f1 112: [0xffbe], // f1
113: [0xFFBF], // f2 113: [0xffbf], // f2
114: [0xFFC0], // f3 114: [0xffc0], // f3
115: [0xFFC1], // f4 115: [0xffc1], // f4
116: [0xFFC2], // f5 116: [0xffc2], // f5
117: [0xFFC3], // f6 117: [0xffc3], // f6
118: [0xFFC4], // f7 118: [0xffc4], // f7
119: [0xFFC5], // f8 119: [0xffc5], // f8
120: [0xFFC6], // f9 120: [0xffc6], // f9
121: [0xFFC7], // f10 121: [0xffc7], // f10
122: [0xFFC8], // f11 122: [0xffc8], // f11
123: [0xFFC9], // f12 123: [0xffc9], // f12
144: [0xFF7F], // num lock 144: [0xff7f], // num lock
145: [0xFF14], // scroll lock 145: [0xff14], // scroll lock
225: [0xFE03] // altgraph (iso_level3_shift) 225: [0xfe03] // altgraph (iso_level3_shift)
}; };
var keyidentifier_keysym: KeyIdentifierKeysym = { var keyidentifier_keysym: KeyIdentifierKeysym = {
"Again": [0xFF66], Again: [0xff66],
"AllCandidates": [0xFF3D], AllCandidates: [0xff3d],
"Alphanumeric": [0xFF30], Alphanumeric: [0xff30],
"Alt": [0xFFE9, 0xFFE9, 0xFE03], Alt: [0xffe9, 0xffe9, 0xfe03],
"Attn": [0xFD0E], Attn: [0xfd0e],
"AltGraph": [0xFE03], AltGraph: [0xfe03],
"ArrowDown": [0xFF54], ArrowDown: [0xff54],
"ArrowLeft": [0xFF51], ArrowLeft: [0xff51],
"ArrowRight": [0xFF53], ArrowRight: [0xff53],
"ArrowUp": [0xFF52], ArrowUp: [0xff52],
"Backspace": [0xFF08], Backspace: [0xff08],
"CapsLock": [0xFFE5], CapsLock: [0xffe5],
"Cancel": [0xFF69], Cancel: [0xff69],
"Clear": [0xFF0B], Clear: [0xff0b],
"Convert": [0xFF21], Convert: [0xff21],
"Copy": [0xFD15], Copy: [0xfd15],
"Crsel": [0xFD1C], Crsel: [0xfd1c],
"CrSel": [0xFD1C], CrSel: [0xfd1c],
"CodeInput": [0xFF37], CodeInput: [0xff37],
"Compose": [0xFF20], Compose: [0xff20],
"Control": [0xFFE3, 0xFFE3, 0xFFE4], Control: [0xffe3, 0xffe3, 0xffe4],
"ContextMenu": [0xFF67], ContextMenu: [0xff67],
"DeadGrave": [0xFE50], DeadGrave: [0xfe50],
"DeadAcute": [0xFE51], DeadAcute: [0xfe51],
"DeadCircumflex": [0xFE52], DeadCircumflex: [0xfe52],
"DeadTilde": [0xFE53], DeadTilde: [0xfe53],
"DeadMacron": [0xFE54], DeadMacron: [0xfe54],
"DeadBreve": [0xFE55], DeadBreve: [0xfe55],
"DeadAboveDot": [0xFE56], DeadAboveDot: [0xfe56],
"DeadUmlaut": [0xFE57], DeadUmlaut: [0xfe57],
"DeadAboveRing": [0xFE58], DeadAboveRing: [0xfe58],
"DeadDoubleacute": [0xFE59], DeadDoubleacute: [0xfe59],
"DeadCaron": [0xFE5A], DeadCaron: [0xfe5a],
"DeadCedilla": [0xFE5B], DeadCedilla: [0xfe5b],
"DeadOgonek": [0xFE5C], DeadOgonek: [0xfe5c],
"DeadIota": [0xFE5D], DeadIota: [0xfe5d],
"DeadVoicedSound": [0xFE5E], DeadVoicedSound: [0xfe5e],
"DeadSemivoicedSound": [0xFE5F], DeadSemivoicedSound: [0xfe5f],
"Delete": [0xFFFF], Delete: [0xffff],
"Down": [0xFF54], Down: [0xff54],
"End": [0xFF57], End: [0xff57],
"Enter": [0xFF0D], Enter: [0xff0d],
"EraseEof": [0xFD06], EraseEof: [0xfd06],
"Escape": [0xFF1B], Escape: [0xff1b],
"Execute": [0xFF62], Execute: [0xff62],
"Exsel": [0xFD1D], Exsel: [0xfd1d],
"ExSel": [0xFD1D], ExSel: [0xfd1d],
"F1": [0xFFBE], F1: [0xffbe],
"F2": [0xFFBF], F2: [0xffbf],
"F3": [0xFFC0], F3: [0xffc0],
"F4": [0xFFC1], F4: [0xffc1],
"F5": [0xFFC2], F5: [0xffc2],
"F6": [0xFFC3], F6: [0xffc3],
"F7": [0xFFC4], F7: [0xffc4],
"F8": [0xFFC5], F8: [0xffc5],
"F9": [0xFFC6], F9: [0xffc6],
"F10": [0xFFC7], F10: [0xffc7],
"F11": [0xFFC8], F11: [0xffc8],
"F12": [0xFFC9], F12: [0xffc9],
"F13": [0xFFCA], F13: [0xffca],
"F14": [0xFFCB], F14: [0xffcb],
"F15": [0xFFCC], F15: [0xffcc],
"F16": [0xFFCD], F16: [0xffcd],
"F17": [0xFFCE], F17: [0xffce],
"F18": [0xFFCF], F18: [0xffcf],
"F19": [0xFFD0], F19: [0xffd0],
"F20": [0xFFD1], F20: [0xffd1],
"F21": [0xFFD2], F21: [0xffd2],
"F22": [0xFFD3], F22: [0xffd3],
"F23": [0xFFD4], F23: [0xffd4],
"F24": [0xFFD5], F24: [0xffd5],
"Find": [0xFF68], Find: [0xff68],
"GroupFirst": [0xFE0C], GroupFirst: [0xfe0c],
"GroupLast": [0xFE0E], GroupLast: [0xfe0e],
"GroupNext": [0xFE08], GroupNext: [0xfe08],
"GroupPrevious": [0xFE0A], GroupPrevious: [0xfe0a],
"FullWidth": null, FullWidth: null,
"HalfWidth": null, HalfWidth: null,
"HangulMode": [0xFF31], HangulMode: [0xff31],
"Hankaku": [0xFF29], Hankaku: [0xff29],
"HanjaMode": [0xFF34], HanjaMode: [0xff34],
"Help": [0xFF6A], Help: [0xff6a],
"Hiragana": [0xFF25], Hiragana: [0xff25],
"HiraganaKatakana": [0xFF27], HiraganaKatakana: [0xff27],
"Home": [0xFF50], Home: [0xff50],
"Hyper": [0xFFED, 0xFFED, 0xFFEE], Hyper: [0xffed, 0xffed, 0xffee],
"Insert": [0xFF63], Insert: [0xff63],
"JapaneseHiragana": [0xFF25], JapaneseHiragana: [0xff25],
"JapaneseKatakana": [0xFF26], JapaneseKatakana: [0xff26],
"JapaneseRomaji": [0xFF24], JapaneseRomaji: [0xff24],
"JunjaMode": [0xFF38], JunjaMode: [0xff38],
"KanaMode": [0xFF2D], KanaMode: [0xff2d],
"KanjiMode": [0xFF21], KanjiMode: [0xff21],
"Katakana": [0xFF26], Katakana: [0xff26],
"Left": [0xFF51], Left: [0xff51],
"Meta": [0xFFE7, 0xFFE7, 0xFFE8], Meta: [0xffe7, 0xffe7, 0xffe8],
"ModeChange": [0xFF7E], ModeChange: [0xff7e],
"NumLock": [0xFF7F], NumLock: [0xff7f],
"PageDown": [0xFF56], PageDown: [0xff56],
"PageUp": [0xFF55], PageUp: [0xff55],
"Pause": [0xFF13], Pause: [0xff13],
"Play": [0xFD16], Play: [0xfd16],
"PreviousCandidate": [0xFF3E], PreviousCandidate: [0xff3e],
"PrintScreen": [0xFD1D], PrintScreen: [0xfd1d],
"Redo": [0xFF66], Redo: [0xff66],
"Right": [0xFF53], Right: [0xff53],
"RomanCharacters": null, RomanCharacters: null,
"Scroll": [0xFF14], Scroll: [0xff14],
"Select": [0xFF60], Select: [0xff60],
"Separator": [0xFFAC], Separator: [0xffac],
"Shift": [0xFFE1, 0xFFE1, 0xFFE2], Shift: [0xffe1, 0xffe1, 0xffe2],
"SingleCandidate": [0xFF3C], SingleCandidate: [0xff3c],
"Super": [0xFFEB, 0xFFEB, 0xFFEC], Super: [0xffeb, 0xffeb, 0xffec],
"Tab": [0xFF09], Tab: [0xff09],
"Up": [0xFF52], Up: [0xff52],
"Undo": [0xFF65], Undo: [0xff65],
"Win": [0xFFEB], Win: [0xffeb],
"Zenkaku": [0xFF28], Zenkaku: [0xff28],
"ZenkakuHankaku": [0xFF2A] ZenkakuHankaku: [0xff2a]
}; };
const OSK_keyMappings: [string, number, string, string, number][] = [ const OSK_keyMappings: [string, number, string, string, number][] = [
["!", 49, "Digit1", "!", 0], ['!', 49, 'Digit1', '!', 0],
["#", 51, "Digit3", "#", 0], ['#', 51, 'Digit3', '#', 0],
["$", 52, "Digit4", "$", 0], ['$', 52, 'Digit4', '$', 0],
["%", 53, "Digit5", "%", 0], ['%', 53, 'Digit5', '%', 0],
["&", 55, "Digit7", "&", 0], ['&', 55, 'Digit7', '&', 0],
["'", 222, "Quote", "'", 0], ["'", 222, 'Quote', "'", 0],
["(", 57, "Digit9", "(", 0], ['(', 57, 'Digit9', '(', 0],
[")", 48, "Digit0", ")", 0], [')', 48, 'Digit0', ')', 0],
["*", 56, "Digit8", "*", 0], ['*', 56, 'Digit8', '*', 0],
["+", 187, "Equal", "+", 0], ['+', 187, 'Equal', '+', 0],
[",", 188, "Comma", ",", 0], [',', 188, 'Comma', ',', 0],
["-", 189, "Minus", "-", 0], ['-', 189, 'Minus', '-', 0],
[".", 190, "Period", ".", 0], ['.', 190, 'Period', '.', 0],
["/", 191, "Slash", "/", 0], ['/', 191, 'Slash', '/', 0],
["0", 48, "Digit0", "0", 0], ['0', 48, 'Digit0', '0', 0],
["1", 49, "Digit1", "1", 0], ['1', 49, 'Digit1', '1', 0],
["2", 50, "Digit2", "2", 0], ['2', 50, 'Digit2', '2', 0],
["3", 51, "Digit3", "3", 0], ['3', 51, 'Digit3', '3', 0],
["4", 52, "Digit4", "4", 0], ['4', 52, 'Digit4', '4', 0],
["5", 53, "Digit5", "5", 0], ['5', 53, 'Digit5', '5', 0],
["6", 54, "Digit6", "6", 0], ['6', 54, 'Digit6', '6', 0],
["7", 55, "Digit7", "7", 0], ['7', 55, 'Digit7', '7', 0],
["8", 56, "Digit8", "8", 0], ['8', 56, 'Digit8', '8', 0],
["9", 57, "Digit9", "9", 0], ['9', 57, 'Digit9', '9', 0],
[":", 186, "Semicolon", ":", 0], [':', 186, 'Semicolon', ':', 0],
[";", 186, "Semicolon", ";", 0], [';', 186, 'Semicolon', ';', 0],
["<", 188, "Comma", "<", 0], ['<', 188, 'Comma', '<', 0],
["=", 187, "Equal", "=", 0], ['=', 187, 'Equal', '=', 0],
[">", 190, "Period", ">", 0], ['>', 190, 'Period', '>', 0],
["?", 191, "Slash", "?", 0], ['?', 191, 'Slash', '?', 0],
["@", 50, "Digit2", "@", 0], ['@', 50, 'Digit2', '@', 0],
["A", 65, "KeyA", "A", 0], ['A', 65, 'KeyA', 'A', 0],
["B", 66, "KeyB", "B", 0], ['B', 66, 'KeyB', 'B', 0],
["C", 67, "KeyC", "C", 0], ['C', 67, 'KeyC', 'C', 0],
["D", 68, "KeyD", "D", 0], ['D', 68, 'KeyD', 'D', 0],
["E", 69, "KeyE", "E", 0], ['E', 69, 'KeyE', 'E', 0],
["F", 70, "KeyF", "F", 0], ['F', 70, 'KeyF', 'F', 0],
["G", 71, "KeyG", "G", 0], ['G', 71, 'KeyG', 'G', 0],
["H", 72, "KeyH", "H", 0], ['H', 72, 'KeyH', 'H', 0],
["I", 73, "KeyI", "I", 0], ['I', 73, 'KeyI', 'I', 0],
["J", 74, "KeyJ", "J", 0], ['J', 74, 'KeyJ', 'J', 0],
["K", 75, "KeyK", "K", 0], ['K', 75, 'KeyK', 'K', 0],
["L", 76, "KeyL", "L", 0], ['L', 76, 'KeyL', 'L', 0],
["M", 77, "KeyM", "M", 0], ['M', 77, 'KeyM', 'M', 0],
["N", 78, "KeyN", "N", 0], ['N', 78, 'KeyN', 'N', 0],
["O", 79, "KeyO", "O", 0], ['O', 79, 'KeyO', 'O', 0],
["P", 80, "KeyP", "P", 0], ['P', 80, 'KeyP', 'P', 0],
["Q", 81, "KeyQ", "Q", 0], ['Q', 81, 'KeyQ', 'Q', 0],
["R", 82, "KeyR", "R", 0], ['R', 82, 'KeyR', 'R', 0],
["S", 83, "KeyS", "S", 0], ['S', 83, 'KeyS', 'S', 0],
["T", 84, "KeyT", "T", 0], ['T', 84, 'KeyT', 'T', 0],
["U", 85, "KeyU", "U", 0], ['U', 85, 'KeyU', 'U', 0],
["V", 86, "KeyV", "V", 0], ['V', 86, 'KeyV', 'V', 0],
["W", 87, "KeyW", "W", 0], ['W', 87, 'KeyW', 'W', 0],
["X", 88, "KeyX", "X", 0], ['X', 88, 'KeyX', 'X', 0],
["Y", 89, "KeyY", "Y", 0], ['Y', 89, 'KeyY', 'Y', 0],
["Z", 90, "KeyZ", "Z", 0], ['Z', 90, 'KeyZ', 'Z', 0],
["[", 219, "BracketLeft", "[", 0], ['[', 219, 'BracketLeft', '[', 0],
["\\", 220, "Backslash", "\\", 0], ['\\', 220, 'Backslash', '\\', 0],
["]", 221, "BracketRight", "]", 0], [']', 221, 'BracketRight', ']', 0],
["^", 54, "Digit6", "^", 0], ['^', 54, 'Digit6', '^', 0],
["_", 189, "Minus", "_", 0], ['_', 189, 'Minus', '_', 0],
["`", 192, "Backquote", "`", 0], ['`', 192, 'Backquote', '`', 0],
["a", 65, "KeyA", "a", 0], ['a', 65, 'KeyA', 'a', 0],
["b", 66, "KeyB", "b", 0], ['b', 66, 'KeyB', 'b', 0],
["c", 67, "KeyC", "c", 0], ['c', 67, 'KeyC', 'c', 0],
["d", 68, "KeyD", "d", 0], ['d', 68, 'KeyD', 'd', 0],
["e", 69, "KeyE", "e", 0], ['e', 69, 'KeyE', 'e', 0],
["f", 70, "KeyF", "f", 0], ['f', 70, 'KeyF', 'f', 0],
["g", 71, "KeyG", "g", 0], ['g', 71, 'KeyG', 'g', 0],
["h", 72, "KeyH", "h", 0], ['h', 72, 'KeyH', 'h', 0],
["i", 73, "KeyI", "i", 0], ['i', 73, 'KeyI', 'i', 0],
["j", 74, "KeyJ", "j", 0], ['j', 74, 'KeyJ', 'j', 0],
["k", 75, "KeyK", "k", 0], ['k', 75, 'KeyK', 'k', 0],
["l", 76, "KeyL", "l", 0], ['l', 76, 'KeyL', 'l', 0],
["m", 77, "KeyM", "m", 0], ['m', 77, 'KeyM', 'm', 0],
["n", 78, "KeyN", "n", 0], ['n', 78, 'KeyN', 'n', 0],
["o", 79, "KeyO", "o", 0], ['o', 79, 'KeyO', 'o', 0],
["p", 80, "KeyP", "p", 0], ['p', 80, 'KeyP', 'p', 0],
["q", 81, "KeyQ", "q", 0], ['q', 81, 'KeyQ', 'q', 0],
["r", 82, "KeyR", "r", 0], ['r', 82, 'KeyR', 'r', 0],
["s", 83, "KeyS", "s", 0], ['s', 83, 'KeyS', 's', 0],
["t", 84, "KeyT", "t", 0], ['t', 84, 'KeyT', 't', 0],
["u", 85, "KeyU", "u", 0], ['u', 85, 'KeyU', 'u', 0],
["v", 86, "KeyV", "v", 0], ['v', 86, 'KeyV', 'v', 0],
["w", 87, "KeyW", "w", 0], ['w', 87, 'KeyW', 'w', 0],
["x", 88, "KeyX", "x", 0], ['x', 88, 'KeyX', 'x', 0],
["y", 89, "KeyY", "y", 0], ['y', 89, 'KeyY', 'y', 0],
["z", 90, "KeyZ", "z", 0], ['z', 90, 'KeyZ', 'z', 0],
["{", 219, "BracketLeft", "{", 0], ['{', 219, 'BracketLeft', '{', 0],
["{altleft}", 18, "AltLeft", "AltLeft", 1], ['{altleft}', 18, 'AltLeft', 'AltLeft', 1],
["{altright}", 18, "AltRight", "AltRight", 2], ['{altright}', 18, 'AltRight', 'AltRight', 2],
["{arrowdown}", 40, "ArrowDown", "ArrowDown", 0], ['{arrowdown}', 40, 'ArrowDown', 'ArrowDown', 0],
["{arrowleft}", 37, "ArrowLeft", "ArrowLeft", 0], ['{arrowleft}', 37, 'ArrowLeft', 'ArrowLeft', 0],
["{arrowright}", 39, "ArrowRight", "ArrowRight", 0], ['{arrowright}', 39, 'ArrowRight', 'ArrowRight', 0],
["{arrowup}", 38, "ArrowUp", "ArrowUp", 0], ['{arrowup}', 38, 'ArrowUp', 'ArrowUp', 0],
["{backspace}", 8, "Backspace", "Backspace", 0], ['{backspace}', 8, 'Backspace', 'Backspace', 0],
["{capslock}", 20, "CapsLock", "CapsLock", 0], ['{capslock}', 20, 'CapsLock', 'CapsLock', 0],
["{controlleft}", 17, "ControlLeft", "ControlLeft", 1], ['{controlleft}', 17, 'ControlLeft', 'ControlLeft', 1],
["{controlright}", 17, "ControlRight", "ControlRight", 2], ['{controlright}', 17, 'ControlRight', 'ControlRight', 2],
["{delete}", 46, "Delete", "Delete", 0], ['{delete}', 46, 'Delete', 'Delete', 0],
["{end}", 35, "End", "End", 0], ['{end}', 35, 'End', 'End', 0],
["{enter}", 13, "Enter", "Enter", 0], ['{enter}', 13, 'Enter', 'Enter', 0],
["{escape}", 27, "Escape", "Escape", 0], ['{escape}', 27, 'Escape', 'Escape', 0],
["{f10}", 121, "F10", "F10", 0], ['{f10}', 121, 'F10', 'F10', 0],
["{f11}", 122, "F11", "F11", 0], ['{f11}', 122, 'F11', 'F11', 0],
["{f12}", 123, "F12", "F12", 0], ['{f12}', 123, 'F12', 'F12', 0],
["{f1}", 112, "F1", "F1", 0], ['{f1}', 112, 'F1', 'F1', 0],
["{f2}", 113, "F2", "F2", 0], ['{f2}', 113, 'F2', 'F2', 0],
["{f3}", 114, "F3", "F3", 0], ['{f3}', 114, 'F3', 'F3', 0],
["{f4}", 115, "F4", "F4", 0], ['{f4}', 115, 'F4', 'F4', 0],
["{f5}", 116, "F5", "F5", 0], ['{f5}', 116, 'F5', 'F5', 0],
["{f6}", 117, "F6", "F6", 0], ['{f6}', 117, 'F6', 'F6', 0],
["{f7}", 118, "F7", "F7", 0], ['{f7}', 118, 'F7', 'F7', 0],
["{f8}", 119, "F8", "F8", 0], ['{f8}', 119, 'F8', 'F8', 0],
["{f9}", 120, "F9", "F9", 0], ['{f9}', 120, 'F9', 'F9', 0],
["{home}", 36, "Home", "Home", 0], ['{home}', 36, 'Home', 'Home', 0],
["{insert}", 45, "Insert", "Insert", 0], ['{insert}', 45, 'Insert', 'Insert', 0],
["{metaleft}", 91, "OSLeft", "OSLeft", 1], ['{metaleft}', 91, 'OSLeft', 'OSLeft', 1],
["{metaright}", 92, "OSRight", "OSRight", 2], ['{metaright}', 92, 'OSRight', 'OSRight', 2],
["{numlock}", 144, "NumLock", "NumLock", 0], ['{numlock}', 144, 'NumLock', 'NumLock', 0],
["{numpad0}", 96, "Numpad0", "Numpad0", 3], ['{numpad0}', 96, 'Numpad0', 'Numpad0', 3],
["{numpad1}", 97, "Numpad1", "Numpad1", 3], ['{numpad1}', 97, 'Numpad1', 'Numpad1', 3],
["{numpad2}", 98, "Numpad2", "Numpad2", 3], ['{numpad2}', 98, 'Numpad2', 'Numpad2', 3],
["{numpad3}", 99, "Numpad3", "Numpad3", 3], ['{numpad3}', 99, 'Numpad3', 'Numpad3', 3],
["{numpad4}", 100, "Numpad4", "Numpad4", 3], ['{numpad4}', 100, 'Numpad4', 'Numpad4', 3],
["{numpad5}", 101, "Numpad5", "Numpad5", 3], ['{numpad5}', 101, 'Numpad5', 'Numpad5', 3],
["{numpad6}", 102, "Numpad6", "Numpad6", 3], ['{numpad6}', 102, 'Numpad6', 'Numpad6', 3],
["{numpad7}", 103, "Numpad7", "Numpad7", 3], ['{numpad7}', 103, 'Numpad7', 'Numpad7', 3],
["{numpad8}", 104, "Numpad8", "Numpad8", 3], ['{numpad8}', 104, 'Numpad8', 'Numpad8', 3],
["{numpad9}", 105, "Numpad9", "Numpad9", 3], ['{numpad9}', 105, 'Numpad9', 'Numpad9', 3],
["{numpadadd}", 107, "NumpadAdd", "NumpadAdd", 3], ['{numpadadd}', 107, 'NumpadAdd', 'NumpadAdd', 3],
["{numpaddecimal}", 110, "NumpadDecimal", "NumpadDecimal", 3], ['{numpaddecimal}', 110, 'NumpadDecimal', 'NumpadDecimal', 3],
["{numpaddivide}", 111, "NumpadDivide", "NumpadDivide", 3], ['{numpaddivide}', 111, 'NumpadDivide', 'NumpadDivide', 3],
["{numpadenter}", 13, "NumpadEnter", "NumpadEnter", 3], ['{numpadenter}', 13, 'NumpadEnter', 'NumpadEnter', 3],
["{numpadmultiply}", 106, "NumpadMultiply", "NumpadMultiply", 3], ['{numpadmultiply}', 106, 'NumpadMultiply', 'NumpadMultiply', 3],
["{numpadsubtract}", 109, "NumpadSubtract", "NumpadSubtract", 3], ['{numpadsubtract}', 109, 'NumpadSubtract', 'NumpadSubtract', 3],
["{pagedown}", 34, "PageDown", "PageDown", 0], ['{pagedown}', 34, 'PageDown', 'PageDown', 0],
["{pageup}", 33, "PageUp", "PageUp", 0], ['{pageup}', 33, 'PageUp', 'PageUp', 0],
["{pause}", 19, "Pause", "Pause", 0], ['{pause}', 19, 'Pause', 'Pause', 0],
["{prtscr}", 44, "PrintScreen", "PrintScreen", 0], ['{prtscr}', 44, 'PrintScreen', 'PrintScreen', 0],
["{scrolllock}", 145, "ScrollLock", "ScrollLock", 0], ['{scrolllock}', 145, 'ScrollLock', 'ScrollLock', 0],
["{shiftleft}", 16, "ShiftLeft", "ShiftLeft", 1], ['{shiftleft}', 16, 'ShiftLeft', 'ShiftLeft', 1],
["{shiftright}", 16, "ShiftRight", "ShiftRight", 2], ['{shiftright}', 16, 'ShiftRight', 'ShiftRight', 2],
["{space}", 32, "Space", "Space", 0], ['{space}', 32, 'Space', 'Space', 0],
["{tab}", 9, "Tab", "Tab", 0], ['{tab}', 9, 'Tab', 'Tab', 0],
["|", 220, "Backslash", "|", 0], ['|', 220, 'Backslash', '|', 0],
["}", 221, "BracketRight", "}", 0], ['}', 221, 'BracketRight', '}', 0],
["~", 192, "Backquote", "~", 0], ['~', 192, 'Backquote', '~', 0],
['"', 222, "Quote", '"', 0] ['"', 222, 'Quote', '"', 0]
]; ];

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +1,18 @@
import {createNanoEvents, Emitter, DefaultEvents } from "nanoevents"; import { createNanoEvents, Emitter, DefaultEvents } from 'nanoevents';
import * as Guacutils from './Guacutils.js'; import * as Guacutils from './Guacutils.js';
import VM from "./VM.js"; import VM from './VM.js';
import { User } from "./User.js"; import { User } from './User.js';
import { AdminOpcode, Permissions, Rank } from "./Permissions.js"; import { AdminOpcode, Permissions, Rank } from './Permissions.js';
import TurnStatus from "./TurnStatus.js"; import TurnStatus from './TurnStatus.js';
import Mouse from "./mouse.js"; import Mouse from './mouse.js';
import GetKeysym from '../keyboard.js'; import GetKeysym from '../keyboard.js';
import VoteStatus from "./VoteStatus.js"; import VoteStatus from './VoteStatus.js';
import MuteState from "./MuteState.js"; import MuteState from './MuteState.js';
// TODO: `Object` has a toString(), but we should probably gate that off // TODO: `Object` has a toString(), but we should probably gate that off
/// Interface for things that can be turned into strings /// Interface for things that can be turned into strings
interface ToStringable { interface ToStringable {
toString() : string toString(): string;
} }
/// A type for strings, or things that can (in a valid manner) be turned into strings /// A type for strings, or things that can (in a valid manner) be turned into strings
@ -39,7 +39,6 @@ export interface CollabVMClientEvents {
voteend: () => void; voteend: () => void;
votecd: (coolDownTime: number) => void; votecd: (coolDownTime: number) => void;
badpw: () => void; badpw: () => void;
login: (rank: Rank, perms: Permissions) => void; login: (rank: Rank, perms: Permissions) => void;
} }
@ -84,75 +83,98 @@ export default class CollabVMClient {
// Get the 2D context // Get the 2D context
this.ctx = this.canvas.getContext('2d')!; this.ctx = this.canvas.getContext('2d')!;
// Bind canvas click // Bind canvas click
this.canvas.addEventListener('click', e => { this.canvas.addEventListener('click', (e) => {
if (this.users.find(u => u.username === this.username)?.turn === -1) if (this.users.find((u) => u.username === this.username)?.turn === -1) this.turn(true);
this.turn(true);
}); });
// Bind keyboard and mouse // Bind keyboard and mouse
this.canvas.addEventListener('mousedown', (e : MouseEvent) => { this.canvas.addEventListener(
if (this.users.find(u => u.username === this.username)?.turn === -1 && this.rank !== Rank.Admin) return; 'mousedown',
(e: MouseEvent) => {
if (this.users.find((u) => u.username === this.username)?.turn === -1 && this.rank !== Rank.Admin) return;
this.mouse.initFromMouseEvent(e); this.mouse.initFromMouseEvent(e);
this.sendmouse(this.mouse.x, this.mouse.y, this.mouse.makeMask()); this.sendmouse(this.mouse.x, this.mouse.y, this.mouse.makeMask());
}, { },
{
capture: true capture: true
}); }
);
this.canvas.addEventListener('mouseup', (e : MouseEvent) => { this.canvas.addEventListener(
if (this.users.find(u => u.username === this.username)?.turn === -1 && this.rank !== Rank.Admin) return; 'mouseup',
(e: MouseEvent) => {
if (this.users.find((u) => u.username === this.username)?.turn === -1 && this.rank !== Rank.Admin) return;
this.mouse.initFromMouseEvent(e); this.mouse.initFromMouseEvent(e);
this.sendmouse(this.mouse.x, this.mouse.y, this.mouse.makeMask()); this.sendmouse(this.mouse.x, this.mouse.y, this.mouse.makeMask());
}, { },
{
capture: true capture: true
}); }
);
this.canvas.addEventListener('mousemove', (e : MouseEvent) => { this.canvas.addEventListener(
if (this.users.find(u => u.username === this.username)?.turn === -1 && this.rank !== Rank.Admin) return; 'mousemove',
(e: MouseEvent) => {
if (this.users.find((u) => u.username === this.username)?.turn === -1 && this.rank !== Rank.Admin) return;
this.mouse.initFromMouseEvent(e); this.mouse.initFromMouseEvent(e);
this.sendmouse(this.mouse.x, this.mouse.y, this.mouse.makeMask()); this.sendmouse(this.mouse.x, this.mouse.y, this.mouse.makeMask());
}, { },
{
capture: true capture: true
}); }
);
this.canvas.addEventListener('keydown', (e : KeyboardEvent) => { this.canvas.addEventListener(
'keydown',
(e: KeyboardEvent) => {
e.preventDefault(); e.preventDefault();
if (this.users.find(u => u.username === this.username)?.turn === -1 && this.rank !== Rank.Admin) return; if (this.users.find((u) => u.username === this.username)?.turn === -1 && this.rank !== Rank.Admin) return;
var keysym = GetKeysym(e.keyCode, e.key, e.location); var keysym = GetKeysym(e.keyCode, e.key, e.location);
if (keysym === null) return; if (keysym === null) return;
this.key(keysym, true); this.key(keysym, true);
}, { },
{
capture: true capture: true
}); }
);
this.canvas.addEventListener('keyup', (e : KeyboardEvent) => { this.canvas.addEventListener(
'keyup',
(e: KeyboardEvent) => {
e.preventDefault(); e.preventDefault();
if (this.users.find(u => u.username === this.username)?.turn === -1 && this.rank !== Rank.Admin) return; if (this.users.find((u) => u.username === this.username)?.turn === -1 && this.rank !== Rank.Admin) return;
var keysym = GetKeysym(e.keyCode, e.key, e.location); var keysym = GetKeysym(e.keyCode, e.key, e.location);
if (keysym === null) return; if (keysym === null) return;
this.key(keysym, false); this.key(keysym, false);
}, { },
{
capture: true capture: true
}); }
);
this.canvas.addEventListener('wheel', (ev: WheelEvent) => { this.canvas.addEventListener(
'wheel',
(ev: WheelEvent) => {
ev.preventDefault(); ev.preventDefault();
if (this.users.find(u => u.username === this.username)?.turn === -1 && this.rank !== Rank.Admin) return; if (this.users.find((u) => u.username === this.username)?.turn === -1 && this.rank !== Rank.Admin) return;
this.mouse.initFromWheelEvent(ev); this.mouse.initFromWheelEvent(ev);
this.sendmouse(this.mouse.x, this.mouse.y, this.mouse.makeMask()); this.sendmouse(this.mouse.x, this.mouse.y, this.mouse.makeMask());
// this is a very, very ugly hack but it seems to work so /shrug // this is a very, very ugly hack but it seems to work so /shrug
if(this.mouse.scrollUp) if (this.mouse.scrollUp) this.mouse.scrollUp = false;
this.mouse.scrollUp = false; else if (this.mouse.scrollDown) this.mouse.scrollDown = false;
else if(this.mouse.scrollDown)
this.mouse.scrollDown = false;
this.sendmouse(this.mouse.x, this.mouse.y, this.mouse.makeMask()); this.sendmouse(this.mouse.x, this.mouse.y, this.mouse.makeMask());
}, { capture: true }); },
{
capture: true
}
);
this.canvas.addEventListener('contextmenu', e => e.preventDefault()); this.canvas.addEventListener('contextmenu', (e) => e.preventDefault());
// Create the WebSocket // Create the WebSocket
this.socket = new WebSocket(url, "guacamole"); this.socket = new WebSocket(url, 'guacamole');
// Add the event listeners // Add the event listeners
this.socket.addEventListener('open', () => this.onOpen()); this.socket.addEventListener('open', () => this.onOpen());
this.socket.addEventListener('message', (event) => this.onMessage(event)); this.socket.addEventListener('message', (event) => this.onMessage(event));
@ -175,45 +197,45 @@ export default class CollabVMClient {
} }
this.publicEmitter.emit('message', ...msgArr); this.publicEmitter.emit('message', ...msgArr);
switch (msgArr[0]) { switch (msgArr[0]) {
case "nop": { case 'nop': {
// Send a NOP back // Send a NOP back
this.send("nop"); this.send('nop');
break; break;
} }
case "list": { case 'list': {
// pass msgarr to the emitter for processing by list() // pass msgarr to the emitter for processing by list()
this.internalEmitter.emit('list', msgArr.slice(1)); this.internalEmitter.emit('list', msgArr.slice(1));
break; break;
} }
case "connect": { case 'connect': {
this.connectedToVM = msgArr[1] === "1"; this.connectedToVM = msgArr[1] === '1';
this.internalEmitter.emit('connect', this.connectedToVM); this.internalEmitter.emit('connect', this.connectedToVM);
break; break;
} }
case "size": { case 'size': {
if (msgArr[1] !== "0") return; if (msgArr[1] !== '0') return;
this.canvas.width = parseInt(msgArr[2]); this.canvas.width = parseInt(msgArr[2]);
this.canvas.height = parseInt(msgArr[3]); this.canvas.height = parseInt(msgArr[3]);
break; break;
} }
case "png": { case 'png': {
// Despite the opcode name, this is actually JPEG, because old versions of the server used PNG and yknow backwards compatibility // Despite the opcode name, this is actually JPEG, because old versions of the server used PNG and yknow backwards compatibility
var img = new Image(); var img = new Image();
img.addEventListener('load', () => { img.addEventListener('load', () => {
this.ctx.drawImage(img, parseInt(msgArr[3]), parseInt(msgArr[4])); this.ctx.drawImage(img, parseInt(msgArr[3]), parseInt(msgArr[4]));
}); });
img.src = "data:image/jpeg;base64," + msgArr[5]; img.src = 'data:image/jpeg;base64,' + msgArr[5];
break; break;
} }
case "chat": { case 'chat': {
for (var i = 1; i < msgArr.length; i += 2) { for (var i = 1; i < msgArr.length; i += 2) {
this.publicEmitter.emit('chat', msgArr[i], msgArr[i + 1]); this.publicEmitter.emit('chat', msgArr[i], msgArr[i + 1]);
} }
break; break;
} }
case "adduser": { case 'adduser': {
for (var i = 2; i < msgArr.length; i += 2) { for (var i = 2; i < msgArr.length; i += 2) {
var _user = this.users.find(u => u.username === msgArr[i]); var _user = this.users.find((u) => u.username === msgArr[i]);
if (_user !== undefined) { if (_user !== undefined) {
_user.rank = parseInt(msgArr[i + 1]); _user.rank = parseInt(msgArr[i + 1]);
} else { } else {
@ -224,48 +246,47 @@ export default class CollabVMClient {
} }
break; break;
} }
case "remuser": { case 'remuser': {
for (var i = 2; i < msgArr.length; i++) { for (var i = 2; i < msgArr.length; i++) {
var _user = this.users.find(u => u.username === msgArr[i]); var _user = this.users.find((u) => u.username === msgArr[i]);
if (_user === undefined) continue; if (_user === undefined) continue;
this.users.splice(this.users.indexOf(_user), 1); this.users.splice(this.users.indexOf(_user), 1);
this.publicEmitter.emit('remuser', _user); this.publicEmitter.emit('remuser', _user);
} }
} }
case "rename": { case 'rename': {
var selfrename = false; var selfrename = false;
var oldusername: string | null = null; var oldusername: string | null = null;
// We've been renamed // We've been renamed
if (msgArr[1] === "0") { if (msgArr[1] === '0') {
selfrename = true; selfrename = true;
oldusername = this.username; oldusername = this.username;
// msgArr[2] is the status of the rename // msgArr[2] is the status of the rename
// Anything other than 0 is an error, however the server will still rename us to a guest name // Anything other than 0 is an error, however the server will still rename us to a guest name
switch (msgArr[2]) { switch (msgArr[2]) {
case "1": case '1':
// The username we wanted was taken // The username we wanted was taken
this.publicEmitter.emit('renamestatus', 'taken'); this.publicEmitter.emit('renamestatus', 'taken');
break; break;
case "2": case '2':
// The username we wanted was invalid // The username we wanted was invalid
this.publicEmitter.emit('renamestatus', 'invalid'); this.publicEmitter.emit('renamestatus', 'invalid');
break; break;
case "3": case '3':
// The username we wanted is blacklisted // The username we wanted is blacklisted
this.publicEmitter.emit('renamestatus', 'blacklisted'); this.publicEmitter.emit('renamestatus', 'blacklisted');
break; break;
} }
this.username = msgArr[3]; this.username = msgArr[3];
} } else oldusername = msgArr[2];
else oldusername = msgArr[2]; var _user = this.users.find((u) => u.username === oldusername);
var _user = this.users.find(u => u.username === oldusername);
if (_user) { if (_user) {
_user.username = msgArr[3]; _user.username = msgArr[3];
} }
this.publicEmitter.emit('rename', oldusername!, msgArr[3], selfrename); this.publicEmitter.emit('rename', oldusername!, msgArr[3], selfrename);
break; break;
} }
case "turn": { case 'turn': {
// Reset all turn data // Reset all turn data
for (var user of this.users) user.turn = -1; for (var user of this.users) user.turn = -1;
var queuedUsers = parseInt(msgArr[2]); var queuedUsers = parseInt(msgArr[2]);
@ -274,16 +295,16 @@ export default class CollabVMClient {
user: null, user: null,
queue: [], queue: [],
turnTime: null, turnTime: null,
queueTime: null, queueTime: null
}); });
return; return;
} }
var currentTurn = this.users.find(u => u.username === msgArr[3])!; var currentTurn = this.users.find((u) => u.username === msgArr[3])!;
currentTurn.turn = 0; currentTurn.turn = 0;
var queue: User[] = []; var queue: User[] = [];
if (queuedUsers > 1) { if (queuedUsers > 1) {
for (var i = 1; i < queuedUsers; i++) { for (var i = 1; i < queuedUsers; i++) {
var user = this.users.find(u => u.username === msgArr[i+3])!; var user = this.users.find((u) => u.username === msgArr[i + 3])!;
queue.push(user); queue.push(user);
user.turn = i; user.turn = i;
} }
@ -292,15 +313,15 @@ export default class CollabVMClient {
user: currentTurn, user: currentTurn,
queue: queue, queue: queue,
turnTime: currentTurn.username === this.username ? parseInt(msgArr[1]) : null, turnTime: currentTurn.username === this.username ? parseInt(msgArr[1]) : null,
queueTime: queue.some(u => u.username === this.username) ? parseInt(msgArr[msgArr.length - 1]) : null, queueTime: queue.some((u) => u.username === this.username) ? parseInt(msgArr[msgArr.length - 1]) : null
}) });
break; break;
} }
case "vote": { case 'vote': {
switch (msgArr[1]) { switch (msgArr[1]) {
case "0": case '0':
// Vote started // Vote started
case "1": case '1':
// Vote updated // Vote updated
var timeToEnd = parseInt(msgArr[2]); var timeToEnd = parseInt(msgArr[2]);
var yesVotes = parseInt(msgArr[3]); var yesVotes = parseInt(msgArr[3]);
@ -310,34 +331,34 @@ export default class CollabVMClient {
this.voteStatus = { this.voteStatus = {
timeToEnd: timeToEnd, timeToEnd: timeToEnd,
yesVotes: yesVotes, yesVotes: yesVotes,
noVotes: noVotes, noVotes: noVotes
}; };
this.publicEmitter.emit('vote', this.voteStatus); this.publicEmitter.emit('vote', this.voteStatus);
break; break;
case "2": case '2':
// Vote ended // Vote ended
this.voteStatus = null; this.voteStatus = null;
this.publicEmitter.emit('voteend'); this.publicEmitter.emit('voteend');
break; break;
case "3": case '3':
// Cooldown // Cooldown
this.publicEmitter.emit('votecd', parseInt(msgArr[2])); this.publicEmitter.emit('votecd', parseInt(msgArr[2]));
break; break;
} }
} }
case "admin": { case 'admin': {
switch (msgArr[1]) { switch (msgArr[1]) {
case "0": { case '0': {
// Login // Login
switch (msgArr[2]) { switch (msgArr[2]) {
case "0": case '0':
this.publicEmitter.emit('badpw'); this.publicEmitter.emit('badpw');
return; return;
case "1": case '1':
this.perms = new Permissions(65535); this.perms = new Permissions(65535);
this.rank = Rank.Admin; this.rank = Rank.Admin;
break; break;
case "3": case '3':
this.perms = new Permissions(parseInt(msgArr[3])); this.perms = new Permissions(parseInt(msgArr[3]));
this.rank = Rank.Moderator; this.rank = Rank.Moderator;
break; break;
@ -345,12 +366,12 @@ export default class CollabVMClient {
this.publicEmitter.emit('login', this.rank, this.perms); this.publicEmitter.emit('login', this.rank, this.perms);
break; break;
} }
case "19": { case '19': {
// IP // IP
this.internalEmitter.emit('ip', msgArr[2], msgArr[3]); this.internalEmitter.emit('ip', msgArr[2], msgArr[3]);
break; break;
} }
case "2": { case '2': {
// QEMU // QEMU
this.internalEmitter.emit('qemu', msgArr[2]); this.internalEmitter.emit('qemu', msgArr[2]);
break; break;
@ -364,8 +385,7 @@ export default class CollabVMClient {
send(...args: StringLike[]) { send(...args: StringLike[]) {
let guacElements = [...args].map((el) => { let guacElements = [...args].map((el) => {
// This catches cases where the thing already is a string // This catches cases where the thing already is a string
if(typeof el == "string") if (typeof el == 'string') return el as string;
return (el as string);
return el.toString(); return el.toString();
}); });
@ -380,32 +400,32 @@ export default class CollabVMClient {
var vms: VM[] = []; var vms: VM[] = [];
for (var i = 0; i < list.length; i += 3) { for (var i = 0; i < list.length; i += 3) {
var th = new Image(); var th = new Image();
th.src = "data:image/jpeg;base64," + list[i + 2]; th.src = 'data:image/jpeg;base64,' + list[i + 2];
vms.push({ vms.push({
url: this.url, url: this.url,
id: list[i], id: list[i],
displayName: list[i + 1], displayName: list[i + 1],
thumbnail: th, thumbnail: th
}); });
} }
res(vms); res(vms);
}); });
this.send("list"); this.send('list');
}); });
} }
// Connect to a node // Connect to a node
connect(id: string, username: string | null = null): Promise<boolean> { connect(id: string, username: string | null = null): Promise<boolean> {
return new Promise(res => { return new Promise((res) => {
var u = this.onInternal('connect', (success: boolean) => { var u = this.onInternal('connect', (success: boolean) => {
u(); u();
res(success); res(success);
}); });
if (username === null) this.send("rename"); if (username === null) this.send('rename');
else this.send("rename", username); else this.send('rename', username);
this.send("connect", id); this.send('connect', id);
this.node = id; this.node = id;
}) });
} }
// Close the connection // Close the connection
@ -422,28 +442,28 @@ export default class CollabVMClient {
// Send a chat message // Send a chat message
chat(message: string) { chat(message: string) {
this.send("chat", message); this.send('chat', message);
} }
// Rename // Rename
rename(username: string | null = null) { rename(username: string | null = null) {
if (username) this.send("rename", username); if (username) this.send('rename', username);
else this.send("rename"); else this.send('rename');
} }
// Take or drop turn // Take or drop turn
turn(taketurn: boolean) { turn(taketurn: boolean) {
this.send("turn", taketurn ? "1" : "0"); this.send('turn', taketurn ? '1' : '0');
} }
// Send mouse instruction // Send mouse instruction
sendmouse(x: number, y: number, mask: number) { sendmouse(x: number, y: number, mask: number) {
this.send("mouse", x, y, mask); this.send('mouse', x, y, mask);
} }
// Send key // Send key
key(keysym: number, down: boolean) { key(keysym: number, down: boolean) {
this.send("key", keysym, down ? "1" : "0"); this.send('key', keysym, down ? '1' : '0');
} }
// Get vote status // Get vote status
@ -453,12 +473,12 @@ export default class CollabVMClient {
// Start a vote, or vote // Start a vote, or vote
vote(vote: boolean) { vote(vote: boolean) {
this.send("vote", vote ? "1" : "0"); this.send('vote', vote ? '1' : '0');
} }
// Try to login using the specified password // Try to login using the specified password
login(password: string) { login(password: string) {
this.send("admin", AdminOpcode.Login, password); this.send('admin', AdminOpcode.Login, password);
} }
/* Admin commands */ /* Admin commands */
@ -466,105 +486,105 @@ export default class CollabVMClient {
// Restore // Restore
restore() { restore() {
if (!this.node) return; if (!this.node) return;
this.send("admin", AdminOpcode.Restore, this.node!); this.send('admin', AdminOpcode.Restore, this.node!);
} }
// Reboot // Reboot
reboot() { reboot() {
if (!this.node) return; if (!this.node) return;
this.send("admin", AdminOpcode.Reboot, this.node!); this.send('admin', AdminOpcode.Reboot, this.node!);
} }
// Clear turn queue // Clear turn queue
clearQueue() { clearQueue() {
if (!this.node) return; if (!this.node) return;
this.send("admin", AdminOpcode.ClearTurns, this.node!); this.send('admin', AdminOpcode.ClearTurns, this.node!);
} }
// Bypass turn // Bypass turn
bypassTurn() { bypassTurn() {
this.send("admin", AdminOpcode.BypassTurn); this.send('admin', AdminOpcode.BypassTurn);
} }
// End turn // End turn
endTurn(user: string) { endTurn(user: string) {
this.send("admin", AdminOpcode.EndTurn, user); this.send('admin', AdminOpcode.EndTurn, user);
} }
// Ban // Ban
ban(user: string) { ban(user: string) {
this.send("admin", AdminOpcode.BanUser, user); this.send('admin', AdminOpcode.BanUser, user);
} }
// Kick // Kick
kick(user: string) { kick(user: string) {
this.send("admin", AdminOpcode.KickUser, user); this.send('admin', AdminOpcode.KickUser, user);
} }
// Rename user // Rename user
renameUser(oldname: string, newname: string) { renameUser(oldname: string, newname: string) {
this.send("admin", AdminOpcode.RenameUser, oldname, newname); this.send('admin', AdminOpcode.RenameUser, oldname, newname);
} }
// Mute user // Mute user
mute(user: string, state: MuteState) { mute(user: string, state: MuteState) {
this.send("admin", AdminOpcode.MuteUser, user, state); this.send('admin', AdminOpcode.MuteUser, user, state);
} }
// Grab IP // Grab IP
getip(user: string) { getip(user: string) {
if (this.users.find(u => u.username === user) === undefined) return false; if (this.users.find((u) => u.username === user) === undefined) return false;
return new Promise<string>(res => { return new Promise<string>((res) => {
var u = this.onInternal('ip', (username: string, ip: string) => { var u = this.onInternal('ip', (username: string, ip: string) => {
if (username !== user) return; if (username !== user) return;
u(); u();
res(ip); res(ip);
}) });
this.send("admin", AdminOpcode.GetIP, user); this.send('admin', AdminOpcode.GetIP, user);
}); });
} }
// QEMU Monitor // QEMU Monitor
qemuMonitor(cmd: string) { qemuMonitor(cmd: string) {
return new Promise<string>(res => { return new Promise<string>((res) => {
var u = this.onInternal('qemu', output => { var u = this.onInternal('qemu', (output) => {
u(); u();
res(output); res(output);
}) });
this.send("admin", AdminOpcode.MonitorCommand, this.node!, cmd); this.send('admin', AdminOpcode.MonitorCommand, this.node!, cmd);
}); });
} }
// XSS // XSS
xss(msg: string) { xss(msg: string) {
this.send("admin", AdminOpcode.ChatXSS, msg); this.send('admin', AdminOpcode.ChatXSS, msg);
} }
// Force vote // Force vote
forceVote(result: boolean) { forceVote(result: boolean) {
this.send("admin", AdminOpcode.ForceVote, result ? "1" : "0"); this.send('admin', AdminOpcode.ForceVote, result ? '1' : '0');
} }
// Toggle turns // Toggle turns
turns(enabled: boolean) { turns(enabled: boolean) {
this.send("admin", AdminOpcode.ToggleTurns, enabled ? "1" : "0"); this.send('admin', AdminOpcode.ToggleTurns, enabled ? '1' : '0');
} }
// Indefinite turn // Indefinite turn
indefiniteTurn() { indefiniteTurn() {
this.send("admin", AdminOpcode.IndefiniteTurn); this.send('admin', AdminOpcode.IndefiniteTurn);
} }
// Hide screen // Hide screen
hideScreen(hidden: boolean) { hideScreen(hidden: boolean) {
this.send("admin", AdminOpcode.HideScreen, hidden ? "1" : "0"); this.send('admin', AdminOpcode.HideScreen, hidden ? '1' : '0');
} }
private onInternal<E extends keyof CollabVMClientPrivateEvents>(event: E, callback: CollabVMClientPrivateEvents[E]) { private onInternal<E extends keyof CollabVMClientPrivateEvents>(event: E, callback: CollabVMClientPrivateEvents[E]) {
return this.internalEmitter.on(event, callback) return this.internalEmitter.on(event, callback);
} }
on<E extends keyof CollabVMClientEvents>(event: E, callback: CollabVMClientEvents[E]) { on<E extends keyof CollabVMClientEvents>(event: E, callback: CollabVMClientEvents[E]) {
return this.publicEmitter.on(event, callback) return this.publicEmitter.on(event, callback);
} }
} }

View File

@ -5,27 +5,21 @@ export function decode(string : string) : string[] {
for (;;) { for (;;) {
let len = string.indexOf('.', pos + 1); let len = string.indexOf('.', pos + 1);
if(len === -1) if (len === -1) break;
break;
pos = parseInt(string.slice(pos + 1, len)) + len + 1; pos = parseInt(string.slice(pos + 1, len)) + len + 1;
// don't allow funky protocol length // don't allow funky protocol length
if(pos > string.length) if (pos > string.length) return [];
return [];
sections.push(string.slice(len + 1, pos)); sections.push(string.slice(len + 1, pos));
const sep = string.slice(pos, pos + 1); const sep = string.slice(pos, pos + 1);
if(sep === ',') if (sep === ',') continue;
continue; else if (sep === ';') break;
else if(sep === ';')
break;
else
// Invalid data. // Invalid data.
return []; else return [];
} }
return sections; return sections;
@ -37,7 +31,7 @@ export function encode(...string : string[]) : string {
for (var i = 0; i < string.length; i++) { for (var i = 0; i < string.length; i++) {
let current = string[i]; let current = string[i];
command += current.toString().length + '.' + current; command += current.toString().length + '.' + current;
command += ( i < string.length - 1 ? ',' : ';'); command += i < string.length - 1 ? ',' : ';';
} }
return command; return command;
} }

View File

@ -27,7 +27,7 @@ export class Permissions {
export enum Rank { export enum Rank {
Unregistered = 0, Unregistered = 0,
Admin = 2, Admin = 2,
Moderator = 3, Moderator = 3
} }
// All used admin opcodes as a enum // All used admin opcodes as a enum

View File

@ -1,4 +1,4 @@
import { User } from "./User.js"; import { User } from './User.js';
export default interface TurnStatus { export default interface TurnStatus {
// The user currently taking their turn // The user currently taking their turn

View File

@ -1,4 +1,4 @@
import { Rank } from "./Permissions.js"; import { Rank } from './Permissions.js';
export class User { export class User {
username: string; username: string;

View File

@ -6,5 +6,4 @@ export default interface VM {
displayName: string; displayName: string;
thumbnail: HTMLImageElement; thumbnail: HTMLImageElement;
} }

View File

@ -39,9 +39,7 @@ export default class Mouse {
this.initFromMouseEvent(ev as MouseEvent); this.initFromMouseEvent(ev as MouseEvent);
// Now do the actual wheel handling // Now do the actual wheel handling
if (ev.deltaY < 0) if (ev.deltaY < 0) this.scrollUp = true;
this.scrollUp = true; else if (ev.deltaY > 0) this.scrollDown = true;
else if (ev.deltaY > 0)
this.scrollDown = true;
} }
} }