"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ML_UUID = exports.mluuid = void 0;
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const crypto_1 = __importDefault(require("crypto"));
const byteToHex = [];
for (var i = 0; i < 256; ++i) {
    byteToHex[i] = (i + 0x100).toString(16).substr(1);
}
class mluuid {
    nouns = [];
    adjectives = [];
    constructor() {
        this.nouns = fs_extra_1.default.readFileSync(path_1.default.join(__dirname, "english-nouns.txt")).toString().split("\n");
        this.adjectives = fs_extra_1.default.readFileSync(path_1.default.join(__dirname, "english-adjectives.txt")).toString().split("\n");
    }
    randomIntFromInterval(min, max) {
        return Math.floor(Math.random() * (max - min + 1) + min);
    }
    bytesToUuid(buf, offset = 0) {
        var i = offset || 0;
        var bth = byteToHex;
        return [
            bth[buf[i++]],
            bth[buf[i++]],
            bth[buf[i++]],
            bth[buf[i++]],
            '-',
            bth[buf[i++]],
            bth[buf[i++]],
            '-',
            bth[buf[i++]],
            bth[buf[i++]],
            '-',
            bth[buf[i++]],
            bth[buf[i++]],
            '-',
            bth[buf[i++]],
            bth[buf[i++]],
            bth[buf[i++]],
            bth[buf[i++]],
            bth[buf[i++]],
            bth[buf[i++]],
        ].join('');
    }
    v4() {
        var rnds = crypto_1.default.randomBytes(16);
        rnds[6] = (rnds[6] & 0x0f) | 0x40;
        rnds[8] = (rnds[8] & 0x3f) | 0x80;
        return this.bytesToUuid(rnds);
    }
    getLobbyName() {
        let n = this.nouns[this.randomIntFromInterval(0, this.nouns.length - 1)].replace("\r", "");
        let a = this.adjectives[this.randomIntFromInterval(0, this.adjectives.length - 1)].replace("\r", "");
        let z = (Math.floor(Math.random() * Math.floor(99))).toString().replace("\r", "");
        return n + "-" + a + "-" + z;
    }
    getUUID() {
        return this.v4();
    }
}
exports.mluuid = mluuid;
exports.ML_UUID = new mluuid();
//# sourceMappingURL=mluuid.js.map