2024-04-24 03:50:17 -04:00
|
|
|
import { Permissions } from './IConfig';
|
2023-01-31 22:00:30 -05:00
|
|
|
|
2024-04-24 03:50:17 -04:00
|
|
|
export function Randint(min: number, max: number) {
|
|
|
|
|
return Math.floor(Math.random() * (max - min) + min);
|
2023-01-31 22:00:30 -05:00
|
|
|
}
|
2024-04-24 03:50:17 -04:00
|
|
|
|
|
|
|
|
export function HTMLSanitize(input: string): string {
|
|
|
|
|
var output = '';
|
|
|
|
|
for (var i = 0; i < input.length; i++) {
|
|
|
|
|
switch (input[i]) {
|
|
|
|
|
case '<':
|
|
|
|
|
output += '<';
|
|
|
|
|
break;
|
|
|
|
|
case '>':
|
|
|
|
|
output += '>';
|
|
|
|
|
break;
|
|
|
|
|
case '&':
|
|
|
|
|
output += '&';
|
|
|
|
|
break;
|
|
|
|
|
case '"':
|
|
|
|
|
output += '"';
|
|
|
|
|
break;
|
|
|
|
|
case "'":
|
|
|
|
|
output += ''';
|
|
|
|
|
break;
|
|
|
|
|
case '/':
|
|
|
|
|
output += '/';
|
|
|
|
|
break;
|
|
|
|
|
case '\n':
|
|
|
|
|
output += ' ';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
var charcode: number = input.charCodeAt(i);
|
|
|
|
|
if (charcode >= 32 && charcode <= 126) output += input[i];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return output;
|
2023-01-31 22:00:30 -05:00
|
|
|
}
|
|
|
|
|
|
2024-04-24 03:50:17 -04:00
|
|
|
export function MakeModPerms(modperms: Permissions): number {
|
|
|
|
|
var perms = 0;
|
|
|
|
|
if (modperms.restore) perms |= 1;
|
|
|
|
|
if (modperms.reboot) perms |= 2;
|
|
|
|
|
if (modperms.ban) perms |= 4;
|
|
|
|
|
if (modperms.forcevote) perms |= 8;
|
|
|
|
|
if (modperms.mute) perms |= 16;
|
|
|
|
|
if (modperms.kick) perms |= 32;
|
|
|
|
|
if (modperms.bypassturn) perms |= 64;
|
|
|
|
|
if (modperms.rename) perms |= 128;
|
|
|
|
|
if (modperms.grabip) perms |= 256;
|
|
|
|
|
if (modperms.xss) perms |= 512;
|
|
|
|
|
return perms;
|
|
|
|
|
}
|