TeaSpeak-Client/native/serverconnection/test/js/flood.ts

156 lines
5.6 KiB
TypeScript
Raw Normal View History

2020-12-02 12:08:49 -05:00
import "./RequireHandler";
2019-10-25 19:51:40 -04:00
2020-12-02 12:08:49 -05:00
import * as handle from "tc-native/connection";
import {NativeServerConnection} from "tc-native/connection";
2019-10-25 19:51:40 -04:00
//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 */
2020-12-02 12:08:49 -05:00
const target_address = "127.0.0.1";
2019-10-25 19:51:40 -04:00
const { host, port } = {
host: target_address.split(":")[0],
port: target_address.split(":").length > 1 ? parseInt(target_address.split(":")[1]) : 9987
};
2020-12-02 12:08:49 -05:00
2019-10-25 19:51:40 -04:00
class Bot {
connection: NativeServerConnection;
2020-12-02 12:08:49 -05:00
knwonChannelIds: number[] = [];
2019-10-25 19:51:40 -04:00
client_id: number;
initialized: boolean;
2020-12-02 12:08:49 -05:00
private switchInterval = [];
2019-10-25 19:51:40 -04:00
private _timeouts = [];
2020-12-02 12:08:49 -05:00
reset() {
2020-12-05 10:40:34 -05:00
this.connection?.disconnect("reset", () => {});
2020-12-02 12:08:49 -05:00
this.connection = undefined;
for(const interval of this.switchInterval)
2019-10-25 19:51:40 -04:00
clearInterval(interval);
for(const timeouts of this._timeouts)
clearInterval(timeouts);
2020-12-02 12:08:49 -05:00
}
2019-10-25 19:51:40 -04:00
2020-12-05 10:40:34 -05:00
connect(callbackConnected?: () => void) {
2020-12-02 12:08:49 -05:00
this.knwonChannelIds = [];
2019-10-25 19:51:40 -04:00
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 => {
2020-12-05 10:40:34 -05:00
if(callbackConnected) {
callbackConnected();
}
2019-10-25 19:51:40 -04:00
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));
2020-12-02 12:08:49 -05:00
this.reset();
2019-10-25 19:51:40 -04:00
}
},
identity_key: "MG4DAgeAAgEgAiBC9JsqB1am6vowj2obomMyxm1GLk8qyRoxpBkAdiVYxwIgWksaSk7eyVQovZwPZBuiYHARz/xQD5zBUBK6e63V7hICIQCZ2glHe3kV62iIRKpkV2lzZGZtfBPRMbwIcU9aE1EVsg==",
teamspeak: true
});
this.connection.callback_command = (command, args, switches) => this.handle_command(command, args);
2020-12-02 12:08:49 -05:00
this.connection.callback_disconnect = () => {
this.connection = undefined;
this.reset();
}
2019-10-25 19:51:40 -04:00
}
async disconnect() {
await new Promise(resolve => this.connection.disconnect("bb", resolve));
this.connection = undefined;
2020-12-02 12:08:49 -05:00
this.reset();
2019-10-25 19:51:40 -04:00
}
private handle_command(command: string, args: any[]) {
if(command == "initserver") {
this.client_id = parseInt(args[0]["aclid"]);
} else if(command == "channellistfinished"){
2020-12-05 10:40:34 -05:00
this.disconnect();
2019-10-25 19:51:40 -04:00
this.initialized = true;
2020-12-05 10:40:34 -05:00
this.switchInterval.push(setInterval(() => this.switch_channel(), 10_000 + Math.random() * 5_000));
2019-10-25 19:51:40 -04:00
} else if(command == "channellist") {
for(const element of args) {
2020-12-02 12:08:49 -05:00
this.knwonChannelIds.push(parseInt(element["cid"]));
2019-10-25 19:51:40 -04:00
}
} else if(command == "notifychannelcreated") {
2020-12-02 12:08:49 -05:00
this.knwonChannelIds.push(parseInt(args[0]["cid"]));
2019-10-25 19:51:40 -04:00
} else if(command == "notifychanneldeleted") {
for(const arg of args) {
const channel_id = parseInt(arg["cid"]);
2020-12-02 12:08:49 -05:00
const index = this.knwonChannelIds.indexOf(channel_id);
2019-10-25 19:51:40 -04:00
if(index >= 0)
2020-12-02 12:08:49 -05:00
this.knwonChannelIds.splice(index, 1);
2019-10-25 19:51:40 -04:00
}
}
}
private switch_channel() {
2020-12-02 12:08:49 -05:00
const target_channel = this.knwonChannelIds[Math.floor((Math.random() * 100000) % this.knwonChannelIds.length)];
2019-10-25 19:51:40 -04:00
console.log("Switching to channel %d", target_channel);
this.connection.send_command("clientmove", [{clid: this.client_id, cid: target_channel}], []);
}
}
2020-12-05 10:40:34 -05:00
const botList: Bot[] = [];
2020-12-02 12:08:49 -05:00
async function connectBots() {
2020-12-05 10:40:34 -05:00
for(let index = 0; index < 1 || true; index++) {
2020-12-02 12:08:49 -05:00
const bot = new Bot();
2020-12-05 10:40:34 -05:00
botList.push(bot);
await new Promise(resolve => bot.connect(resolve));
2020-12-02 12:08:49 -05:00
2020-12-05 10:40:34 -05:00
await new Promise(resolve => setTimeout(resolve, 1000));
while(botList.length > 50) {
const [ bot ] = botList.splice(0, 1);
bot.reset();
}
2020-12-02 12:08:49 -05:00
}
}
setInterval(() => {
2020-12-05 10:40:34 -05:00
botList.forEach(connection => {
2020-12-02 12:08:49 -05:00
if(connection.connection) {
2020-12-05 10:40:34 -05:00
//connection.connection.send_voice_data(new Uint8Array([1, 2, 3]), 5, false);
2020-12-02 12:08:49 -05:00
} else {
connection.connect();
}
});
}, 5);
connectBots().then(undefined);