class WTVClientSessionData { /***********************************\ |* Special Thanks to: *| |* No one *| |* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *| |* There is literally nothing *| |* special about this class *| \***********************************/ data_store = null; capabilities = null; constructor() { this.data_store = new Array(); } hasCap(cap) { if (this.capabilities) { return this.capabilities[cap] || false; } return false; } getMaxUsernameLength() { if (parseInt(this.data_store['wtv-system-version'] < 4000)) { // older builds may crash with nicknames longer than 16 chars. // actual build where support started is yet unknown return 16; } else { // newer builds supported up to 32 chars, I think return 32; } } setIRCNick(nick) { // strip out unsupported chars nick = nick.replace(/[^a-zA-Z0-9\-\_\`\^]/g, ""); // limit nick length based on build support nick = nick.substring(0, this.getMaxUsernameLength()); // returns headers to send to client, while storing the new data in our session data. this.data_store['wtv-user-name'] = nick; this.data_store['wtv-irc-nick'] = nick; return "wtv-irc-nick: " + nick + "\nwtv-user-nick: " + nick; } isMiniBrowser() { if (this.data_store['wtv-need-upgrade'] || this.data_store['wtv-used-8675309']) return true; return false; } currentConnections() { if (this.data_store) { if (this.data_store.sockets) { return this.data_store.sockets.size; } } return 0; } get(key = null) { if (typeof (this.data_store) === 'undefined') return null; else if (key === null) return this.data_store; else if (this.data_store[key]) return this.data_store[key]; else return null; } set(key, value) { if (key === null) throw ("ClientSessionData.set(): invalid key provided"); if (typeof (this.data_store) === 'undefined') this.data_store = new Array(); this.data_store[key] = value; } delete(key) { if (key === null) throw ("ClientSessionData.delete(): invalid key provided"); delete this.data_store[key]; } } module.exports = WTVClientSessionData;