import "./RequireHandler"; import * as handle from "tc-native/connection"; import {NativeServerConnection} from "tc-native/connection"; //remote_host: "51.68.181.92", //remote_host: "94.130.236.135", //remote_host: "54.36.232.11", /* the beast */ //remote_host: "79.133.54.207", /* gommehd.net */ const target_address = "127.0.0.1"; const { host, port } = { host: target_address.split(":")[0], port: target_address.split(":").length > 1 ? parseInt(target_address.split(":")[1]) : 9987 }; class Bot { connection: NativeServerConnection; knwonChannelIds: number[] = []; client_id: number; initialized: boolean; private switchInterval = []; private _timeouts = []; reset() { this.connection?.disconnect("reset", () => {}); this.connection = undefined; for(const interval of this.switchInterval) clearInterval(interval); for(const timeouts of this._timeouts) clearInterval(timeouts); } connect(callbackConnected?: () => void) { this.knwonChannelIds = []; this.client_id = 0; this.initialized = false; this.connection = handle.spawn_server_connection(); this.connection.connect({ timeout: 5000, remote_port: port, remote_host: host, callback: error => { if(callbackConnected) { callbackConnected(); } if(error == 0) { this.connection.send_command("clientinit", [ { "client_key_offset": 2030434, /* "client_version": "1.0.0", "client_platform": "nodejs/linux", */ "client_version": "3.1.8 [Build: 1516614607]", "client_platform": "Windows", "client_version_sign": "gDEgQf/BiOQZdAheKccM1XWcMUj2OUQqt75oFuvF2c0MQMXyv88cZQdUuckKbcBRp7RpmLInto4PIgd7mPO7BQ==", "client_nickname": "TeaClient Native Module Test", "client_input_hardware":true, "client_output_hardware":true, "client_default_channel":"", "client_default_channel_password":"", "client_server_password":"", "client_meta_data":"", "client_nickname_phonetic":"", "client_default_token":"", "hwid":"123,456123123123", return_code:91 } ], []); } else { console.log("Bot connect failed: %o (%s) ", error, this.connection.error_message(error)); this.reset(); } }, identity_key: "MG4DAgeAAgEgAiBC9JsqB1am6vowj2obomMyxm1GLk8qyRoxpBkAdiVYxwIgWksaSk7eyVQovZwPZBuiYHARz/xQD5zBUBK6e63V7hICIQCZ2glHe3kV62iIRKpkV2lzZGZtfBPRMbwIcU9aE1EVsg==", teamspeak: true }); this.connection.callback_command = (command, args, switches) => this.handle_command(command, args); this.connection.callback_disconnect = () => { this.connection = undefined; this.reset(); } } async disconnect() { await new Promise(resolve => this.connection.disconnect("bb", resolve)); this.connection = undefined; this.reset(); } private handle_command(command: string, args: any[]) { if(command == "initserver") { this.client_id = parseInt(args[0]["aclid"]); } else if(command == "channellistfinished"){ this.disconnect(); this.initialized = true; this.switchInterval.push(setInterval(() => this.switch_channel(), 10_000 + Math.random() * 5_000)); } else if(command == "channellist") { for(const element of args) { this.knwonChannelIds.push(parseInt(element["cid"])); } } else if(command == "notifychannelcreated") { this.knwonChannelIds.push(parseInt(args[0]["cid"])); } else if(command == "notifychanneldeleted") { for(const arg of args) { const channel_id = parseInt(arg["cid"]); const index = this.knwonChannelIds.indexOf(channel_id); if(index >= 0) this.knwonChannelIds.splice(index, 1); } } } private switch_channel() { const target_channel = this.knwonChannelIds[Math.floor((Math.random() * 100000) % this.knwonChannelIds.length)]; console.log("Switching to channel %d", target_channel); this.connection.send_command("clientmove", [{clid: this.client_id, cid: target_channel}], []); } } const botList: Bot[] = []; async function connectBots() { for(let index = 0; index < 1 || true; index++) { const bot = new Bot(); botList.push(bot); await new Promise(resolve => bot.connect(resolve)); await new Promise(resolve => setTimeout(resolve, 1000)); while(botList.length > 50) { const [ bot ] = botList.splice(0, 1); bot.reset(); } } } setInterval(() => { botList.forEach(connection => { if(connection.connection) { //connection.connection.send_voice_data(new Uint8Array([1, 2, 3]), 5, false); } else { connection.connect(); } }); }, 5); connectBots().then(undefined);