124 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
		
		
			
		
	
	
			124 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| 
								 | 
							
								/// <reference path="../../exports/exports.d.ts" />
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								module.paths.push("../../build/linux_x64");
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import * as fs from "fs";
							 | 
						||
| 
								 | 
							
								import * as handle from "teaclient_connection";
							 | 
						||
| 
								 | 
							
								import {NativeServerConnection} from "teaclient_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 = "51.68.181.92";
							 | 
						||
| 
								 | 
							
								const { host, port } = {
							 | 
						||
| 
								 | 
							
								    host: target_address.split(":")[0],
							 | 
						||
| 
								 | 
							
								    port: target_address.split(":").length > 1 ? parseInt(target_address.split(":")[1]) : 9987
							 | 
						||
| 
								 | 
							
								};
							 | 
						||
| 
								 | 
							
								class Bot {
							 | 
						||
| 
								 | 
							
								    connection: NativeServerConnection;
							 | 
						||
| 
								 | 
							
								    channel_ids: number[] = [];
							 | 
						||
| 
								 | 
							
								    client_id: number;
							 | 
						||
| 
								 | 
							
								    initialized: boolean;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    private _interval = [];
							 | 
						||
| 
								 | 
							
								    private _timeouts = [];
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    connect() {
							 | 
						||
| 
								 | 
							
								        for(const interval of this._interval)
							 | 
						||
| 
								 | 
							
								            clearInterval(interval);
							 | 
						||
| 
								 | 
							
								        for(const timeouts of this._timeouts)
							 | 
						||
| 
								 | 
							
								            clearInterval(timeouts);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        this.channel_ids = [];
							 | 
						||
| 
								 | 
							
								        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(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));
							 | 
						||
| 
								 | 
							
								                }
							 | 
						||
| 
								 | 
							
								            },
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            identity_key: "MG4DAgeAAgEgAiBC9JsqB1am6vowj2obomMyxm1GLk8qyRoxpBkAdiVYxwIgWksaSk7eyVQovZwPZBuiYHARz/xQD5zBUBK6e63V7hICIQCZ2glHe3kV62iIRKpkV2lzZGZtfBPRMbwIcU9aE1EVsg==",
							 | 
						||
| 
								 | 
							
								            teamspeak: true
							 | 
						||
| 
								 | 
							
								        });
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        this.connection.callback_command = (command, args, switches) => this.handle_command(command, args);
							 | 
						||
| 
								 | 
							
								        this.connection.callback_disconnect = () => this.disconnect();
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    async disconnect() {
							 | 
						||
| 
								 | 
							
								        await new Promise(resolve => this.connection.disconnect("bb", resolve));
							 | 
						||
| 
								 | 
							
								        this.connection = undefined;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    private handle_command(command: string, args: any[]) {
							 | 
						||
| 
								 | 
							
								        if(command == "initserver") {
							 | 
						||
| 
								 | 
							
								            this.client_id = parseInt(args[0]["aclid"]);
							 | 
						||
| 
								 | 
							
								        } else if(command == "channellistfinished"){
							 | 
						||
| 
								 | 
							
								             this.initialized = true;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								             this._interval.push(setInterval(() => this.switch_channel(), 1000));
							 | 
						||
| 
								 | 
							
								        } else if(command == "channellist") {
							 | 
						||
| 
								 | 
							
								            for(const element of args) {
							 | 
						||
| 
								 | 
							
								                this.channel_ids.push(parseInt(element["cid"]));
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        } else if(command == "notifychannelcreated") {
							 | 
						||
| 
								 | 
							
								            this.channel_ids.push(parseInt(args[0]["cid"]));
							 | 
						||
| 
								 | 
							
								        } else if(command == "notifychanneldeleted") {
							 | 
						||
| 
								 | 
							
								            for(const arg of args) {
							 | 
						||
| 
								 | 
							
								                const channel_id = parseInt(arg["cid"]);
							 | 
						||
| 
								 | 
							
								                const index = this.channel_ids.indexOf(channel_id);
							 | 
						||
| 
								 | 
							
								                if(index >= 0)
							 | 
						||
| 
								 | 
							
								                    this.channel_ids.splice(index, 1);
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    private switch_channel() {
							 | 
						||
| 
								 | 
							
								        const target_channel = this.channel_ids[Math.floor((Math.random() * 100000) % this.channel_ids.length)];
							 | 
						||
| 
								 | 
							
								        console.log("Switching to channel %d", target_channel);
							 | 
						||
| 
								 | 
							
								        this.connection.send_command("clientmove", [{clid: this.client_id, cid: target_channel}], []);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								const bot_list = [];
							 | 
						||
| 
								 | 
							
								for(let index = 0; index < 1; index++) {
							 | 
						||
| 
								 | 
							
								    const bot = new Bot();
							 | 
						||
| 
								 | 
							
								    bot_list.push(bot);
							 | 
						||
| 
								 | 
							
								    bot.connect();
							 | 
						||
| 
								 | 
							
								}
							 |