package 
{

	import flash.display.MovieClip;
	import flash.events.*;
	import flash.net.URLRequest;
	import flash.net.URLLoader;
	import flash.net.NetConnection;
	import flash.net.NetGroup;
	import flash.net.GroupSpecifier;
	import flash.utils.setInterval;
	import flash.utils.setTimeout;
	import flash.utils.clearInterval;
	import flash.utils.clearTimeout;
	import flash.text.TextFieldType;
	import flash.desktop.NativeApplication;
	import flash.geom.Rectangle;
	import flash.media.Sound;
	import flash.display.Loader;
	import flash.utils.ByteArray;
	import com.adobe.images.JPGEncoder;
	import flash.system.LoaderContext;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import com.adobe.crypto.MD5;
	import flash.net.URLVariables;
	import flash.net.URLRequestMethod;
	import fl.transitions.easing.Strong;
	import flash.desktop.NotificationType;
	import flash.display.NativeWindow;
	import flash.text.TextField;
	import swing.*;
	import swing.net.*;
	import flash.filesystem.File;
	import flash.desktop.NativeProcess;
	import flash.desktop.NativeProcessStartupInfo;

	public class Main extends MovieClip
	{
		//основа
		private var win:NativeWindow;

		//соеденение
		private var nc:NetConnection;
		private var group:NetGroup;
		private var groupName:String = '';
		private var sKey:String = '';

		//классы
		private var loader:MyURLLoader = new MyURLLoader();
		private var request:URLRequest = new URLRequest  ;
		private var sound:sou = new sou  ;
		private var mcLoader:MultipartURLLoader;
		public var ids:MyArray = new MyArray  ;
		private var randomizer:random = new random  ;
		private var h:help = new help();
		private var hw:HWID;

		//константы сервера
		private var checker:String = 'check.php';
		private var ban:String = 'ban.php';
		private var vips:String = 'ids.php?key=';
		private var already:String = 'ok.php';
		private var host:String = 'http://swing-apps.pp.ua/abuser/';

		//id таймеров
		private var i1:uint;
		private var i2:uint;
		private var i3:uint;
		private var i4:uint;
		private var i5:uint;
		private var i6:uint;
		private var i7:uint;
		private var i8:uint;
		private var i9:uint;
		private var i10:uint;

		//всякая херь
		private var captcha:String = '';
		private var captcha1:String = '';
		private var curl:String = '';
		private var currCapt:String = '';
		private var captOn:Boolean = false;
		private var currMobHash:String = '';
		private var currCallback:Function;
		private var sec:String = 'hackfuck';

		//переменные слежения 
		private var numErrors:Number = 0;
		private var isWork:Boolean = true;
		private var isCopy:Boolean = false;
		private var isBot:Boolean = false;
		private var auto:Boolean = false;
		private var checkedCaptcha:Boolean = false;
		private var connected:Boolean = false;

		//переменные юзера
		private var hash:String;
		private var bal:Number = 0;
		private var vip:Number = 0;
		private var warID:String;
		private var targetID:String;
		private var targetIndex:uint;
		private var Hkey:String;

		public function Main()
		{
			if (stage)
			{
				win = stage.nativeWindow;
				v_txt.text = h.getAppVersion();
				checkUpdate();
				var save:Object = h.loadSave();
				if (save.email != null)
				{
					email_txt.text = save.email;
				}
				if (save.pass != null)
				{
					pass_txt.text = save.pass;
				}
				if (save.agate != null)
				{
					agate_txt.text = save.agate;
					agate_cb.selected = true;
				}
				request.useCache = false;
				request.cacheResponse = false;
				request.followRedirects = false;
				request.manageCookies = false;
				start_btn.visible = false;
				NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, fakeMode);
				fakes_btn.addEventListener(MouseEvent.CLICK, startFakes);
			}
		}
		/*
		
		P2P
		
		*/

		private function connect():void
		{
			nc = new NetConnection  ;
			nc.addEventListener(NetStatusEvent.NET_STATUS,netStatus);
			nc.connect("rtmfp://p2p.rtmfp.net",sKey);
		}

		private function netStatus(event:NetStatusEvent):void
		{
			trace(event.info.code);
			switch (event.info.code)
			{
				case "NetConnection.Connect.Success" :
					setupGroup();
					break;
				case "NetGroup.Connect.Failed" :
					connect();
					break;
				case "NetGroup.Connect.Rejected" :
					connect();
					break;
				case "NetStream.Connect.Closed" :
					connect();
					break;
				case "NetStream.Connect.Rejected" :
					connect();
					break;
				case "NetStream.Failed" :
					connect();
					break;
				case "NetGroup.Connect.Success" :
					startWork();
					break;
				case "NetGroup.Neighbor.Connect" :
					createAcc(event.info.peerID);
					break;
				case "NetGroup.Neighbor.Disconnect" :
					removeAcc(event.info.peerID);
					break;
				case "NetGroup.Posting.Notify" :
					updateAcc(event.info.message);
					break;
			}
		}

		private function startWork():void
		{
			if (! connected)
			{
				status_txt.text = 'Подключились! :)';
				advice_txt.text = 'Получаем id и кол-во онлайн(15 сек)...';
				loadVip();
				warID = h.restrict(id_txt.text);
				connected = true;
			}
			clearInterval(i1);
			i1 = setInterval(sendAcc,9500,warID);
			clearInterval(i4);
			i4 = setTimeout(work,9500);
			clearInterval(i5);
			i5 = setInterval(checkBalance,65000);
			clearInterval(i6);
			i6 = setInterval(checkKey,40000);
			clearInterval(i7);
			i7 = setInterval(checkUpdate,100000);
			clearInterval(i8);
			i8 = setInterval(countUsers,10000);
			checkBalance();
			sendAcc(warID);
		}

		private function setupGroup():void
		{
			if (! connected)
			{
				status_txt.text = 'Подключение...';
				advice_txt.text = 'Подключение к P2P серверу...';
				if (pass_txt.text != '******')
				{
					h.writeSave(email_txt.text,pass_txt.text,agate_txt.text);
				}
				pass_txt.text = '******';
			}
			var groupspec:GroupSpecifier = new GroupSpecifier(groupName);
			groupspec.postingEnabled = true;
			groupspec.ipMulticastMemberUpdatesEnabled = true;
			groupspec.multicastEnabled = true;
			groupspec.serverChannelEnabled = true;
			group = new NetGroup(nc,groupspec.groupspecWithAuthorizations());
			group.addEventListener(NetStatusEvent.NET_STATUS,netStatus);
		}
		private function sendAcc(txt:String):void
		{
			var message:Object = new Object  ;
			if (h.checkAdm(txt))
			{
				haltErr('Банить этот ID запрещено');
				return;
			}
			message.id = txt;
			message.myid = nc.nearID;
			message.hash = hash;
			message.isBot = isBot;
			message.capt = captOn;
			group.post(message);
		}

		private function createAcc(str:String):void
		{
			trace('addAcc',str);
			ids.push({nid:str,id:'',hash:'temp'+String(randomizer.randNum(0,9999999)),ok:'0'});
			countUsers();
		}

		private function removeAcc(str:String):void
		{
			trace('removeAcc',str);
			ids.setID('-1',str,'');
			countUsers();
		}

		private function updateAcc(message:Object):void
		{
			if (! h.checkAdm(message.id))
			{
				message.id = h.restrict(message.id);
				ids.setID(message.id,message.myid,message.hash,message.isBot,message.capt);
			}
		}

		/*
		
		P2P
		
		*/

		private function work(e:MouseEvent=null):void
		{
			if (! isWork)
			{
				advice_txt.text = "Работа остановлена!";
				clearInterval(i1);
				return;
			}
			clearTimeout(i9);
			loader.removeEventListener(Event.COMPLETE,markSpam);
			stage.removeEventListener(KeyboardEvent.KEY_UP,work1);
			stage.removeEventListener(KeyboardEvent.KEY_UP,loadWall1);
			frontWindow();
			capt.x = 500;
			targetID = ids.getID();
			targetIndex = ids.getIDIndex();
			if (targetID != 'wait')
			{
				if (targetID.length > 0)
				{
					advice_txt.text = 'Оставляем жалобу на ' + targetID;
					request.url = 'http://vk.com/abuse.php?act=a_page_abuse_box&al=1&oid=' + targetID;
					loader.removeEventListener(Event.COMPLETE,authorized);
					loader.removeEventListener(Event.COMPLETE,markSpam);
					loader.loadRequest(request, abuseIt);
				}
				else
				{
					ids.okID(targetID,targetIndex);
				}
			}
			else
			{
				advice_txt.text = 'Ждём новых id...';
				timeout(work,5000);
			}
		}

		private function abuseIt(e:Event):void
		{
			var reason:String = h.getReason();
			var pattern:RegExp = /hash: '(.*?)'},/;
			var obj:Object = pattern.exec(e.target.data);
			if (obj != null)
			{
				trace('жалуемся на ',targetID,':',obj[1]);
				request.url = 'http://vk.com/abuse.php?act=a_abuse&al=1&bl=&comment=' + reason.split('/')[0] + '&hash=' + obj[1] + '&oid=' + targetID + '&reason=' + reason.split('/')[1] + '&captcha_key=' + capt.capt_txt.text + '&captcha_sid=' + captcha;
				if (captcha != 'ok')
				{
					capt.capt_txt.text = '';
					capt.capt_btn.enabled = true;
					capt.x = 500;
				}
				else
				{
					captOn = false;
				}
				loader.removeEventListener(Event.COMPLETE,markSpam);
				loader.removeEventListener(Event.COMPLETE,abuseIt);
				loader.loadRequest(request, abused);
			}
			else
			{
				timeout(work,12000);
				ids.okID(targetID, targetIndex);
				if (e.target.data.search('already') == -1)
				{
					numErrors++;
					if ((numErrors > 5))
					{
						stopWork();
					}
					else
					{
						numErrors = 0;
					}
					advice_txt.text = 'Ошибка...';
				}
				else
				{
					advice_txt.text = targetID + ' уже заблокирован...';
					var temploader:URLLoader = new URLLoader();
					temploader.load(new URLRequest(host+already+'?uid='+targetID));
				}
			}
		}

		private function abused(e:Event):void
		{
			loader.removeEventListener(Event.COMPLETE,abused);
			var pattern:RegExp = /class="mem_link"/;
			captcha = parseCaptcha(e.target.data,work,work1);
			trace('каптча',captcha);
			var obj:Object = pattern.exec(e.target.data);
			if ((captcha == 'ok'))
			{
				ids.okID(targetID, targetIndex);
				if ((obj != null))
				{
					advice_txt.text = 'Отправили жалобу на ID ' + targetID + ' ...Ждём...';
					numErrors = 0;
				}
				else
				{
					if (e.target.data.search('<!>3<!>') != -1)
					{
						numErrors++;
					}
					advice_txt.text = 'На ID ' + targetID + ' уже была отправлена жалоба ...Ждём...';
				}
				if ((numErrors < 5))
				{
					loadWall();
					timeout(work,18500);
				}
				else
				{
					advice_txt.text = 'Слишком много неуспешных жалоб, отключились.';
					stopWork();
				}
			}
		}
		private function loadWall(offset:String = '0'):void
		{
			stage.removeEventListener(KeyboardEvent.KEY_UP,work1);
			stage.removeEventListener(KeyboardEvent.KEY_UP,loadWall1);
			request.url = 'http://vk.com/wall' + targetID + '?al=-1&local=1&offset=' + offset + '&own=1&_rndVer=' + String(randomizer.randNum(99999,40000));
			loader.loadRequest(request, markSpam);
			if (offset == '0')
			{
				setTimeout(loadWall,1000,'20');
			}
		}

		private function markSpam(e:Event):void
		{
			loader.removeEventListener(Event.COMPLETE, markSpam);
			var arr:Array = h.parseWall(e.target.data);
			var targetsPhoto:Array;
			var targetsLink:Array;
			var targetsAny:Array;
			var targetsAll:Array;
			var tP:Array;
			var tL:Array;
			var tA:Array;
			if (arr.length < 1)
			{
				return;
			}
			else
			{
				targetsPhoto = new Array();
				targetsLink = new Array();
				targetsAny = new Array();
				targetsAll = new Array();
				for (var i:uint = 0; i<arr.length; i++)
				{
					if (arr[i]['photo'] != -1)
					{
						targetsPhoto.push(arr[i]['spam']);
					}
					if (arr[i]['link'] != -1)
					{
						targetsLink.push(arr[i]['spam']);
					}
					if (arr[i]['photo'] == -1 && arr[i]['link'] == -1)
					{
						targetsAny.push(arr[i]['spam']);
					}
					targetsAll.push(arr[i]['spam']);
				}
				if (targetsAny.length > 0)
				{
					tA = targetsAny[randomizer.randNum(targetsAny.length-1,0,'floor')].split('|');
				}
				if (targetsPhoto.length > 0)
				{
					tP = targetsPhoto[randomizer.randNum(targetsPhoto.length-1,0,'floor')].split('|');
				}
				if (targetsLink.length > 0)
				{
					tL = targetsLink[randomizer.randNum(targetsLink.length-1,0,'floor')].split('|');
				}
				if (targetsAll.length > 0)
				{
					if (tA == null)
					{
						tA = targetsAll[randomizer.randNum(targetsAll.length-1,0,'floor')].split('|');
					}
					if (tP == null)
					{
						tP = targetsAll[randomizer.randNum(targetsAll.length-1,0,'floor')].split('|');
					}
					if (tL == null)
					{
						tL = targetsAll[randomizer.randNum(targetsAll.length-1,0,'floor')].split('|');
					}
				}
				else
				{
					return;
				}
				var temploader:MyURLLoader = new MyURLLoader();
				var temploader1:MyURLLoader = new MyURLLoader();
				var temploader2:MyURLLoader = new MyURLLoader();
				var temprequest:URLRequest = new URLRequest('http://vk.com/al_wall.php?act=spam&al=1&hash=' + tA[1] + '&post=' + tA[0] + '&captcha_key=' + capt.capt_txt.text + '&captcha_sid=' + captcha1 + '');
				var temprequest1:URLRequest = new URLRequest('http://vk.com/al_wall.php?act=spam&al=1&hash=' + tP[1] + '&post=' + tP[0] + '&captcha_key=' + capt.capt_txt.text + '&captcha_sid=' + captcha1+'');
				var temprequest2:URLRequest = new URLRequest('http://vk.com/al_wall.php?act=spam&al=1&hash=' + tL[1] + '&post=' + tL[0] + '&captcha_key=' + capt.capt_txt.text + '&captcha_sid=' + captcha1+'');
				temploader.resetCookies(loader.cookies);
				temploader1.resetCookies(loader.cookies);
				temploader2.resetCookies(loader.cookies);
				temploader.loadRequest(temprequest, spamed);
				temploader1.loadRequest(temprequest1, spamed);
				temploader2.loadRequest(temprequest2, spamed);
			}
		}

		private function spamed(e:Event):void
		{
			loader.removeEventListener(Event.COMPLETE, spamed);
			captcha1 = parseCaptcha(e.target.data,loadWall,loadWall1);
			if (captcha == 'ok')
			{
				ids.okID(targetID,targetIndex);
			}
		}

		/*
		АВТОРИЗАЦИЯ ВКОНТАКТЕ
		*/

		private function tryAuth(e:MouseEvent = null):void
		{
			request.url = 'http://vk.com/login.php?op=a_login_attempt&login=sdasdasd' + '&captcha_key=' + capt.capt_txt.text + '&captcha_sid=' + captcha1;
			loader.loadRequest(request, triedAuth);
		}

		private function triedAuth(e:Event):void
		{
			if (checkedCaptcha)
			{
				return;
			}
			captcha1 = parseCaptcha(e.target.data,tryAuth,tryAuth1);
			if (captcha1 == 'ok')
			{
				checkedCaptcha = true;
				auth();
			}

		}

		private function auth(e:MouseEvent = null):void
		{
			if (! checkedCaptcha)
			{
				tryAuth();
				return;
			}
			start_btn.removeEventListener(MouseEvent.CLICK, auth);
			ids_list.enabled = false;
			request.url = 'http://login.vk.com/?act=login&email=' + email_txt.text + '&pass=' + pass_txt.text;
			loader.loadRequest(request, authorized);
			loader.dispatch(haltConnect);
			if (agate_txt.text.length > 31)
			{
				agate_cb.selected = true;
			}
		}

		private function authorized(e:Event):void
		{
			var str:String = e.target.data;
			if (str.search("/edit") != -1 && str.search("validate_btn") == -1)
			{
				setTimeout(saveSaved,400);
				function saveSaved():void
				{
					status_txt.text = 'Подключение...';
					advice_txt.text = 'Логинимся на сервер вконтакте...';
					id_txt.enabled = false;
					email_txt.enabled = false;
					pass_txt.enabled = false;
					agate_txt.enabled = false;
					agate_cb.enabled = false;
					hash = MD5.hash(email_txt.text + pass_txt.text).substr(0,14);
					trace('hash(email+pass)',hash);
					mob.x = 318;
					numErrors = 0;
					connect();
					start_btn.removeEventListener(MouseEvent.CLICK, auth);
				}
			}
			else if (str.search("validate_btn") > 1)
			{
				advice_txt.text = 'Требует мобилу! :(';
				mob.x = 18;
				var pattern:RegExp = /hash: '(.*?)'/;
				var obj:Object = pattern.exec(e.target.data);
				if (obj != null)
				{
					currMobHash = obj[1];
					mob.ok_btn.addEventListener(MouseEvent.CLICK, checkMobile);
					if (auto)
					{
						setTimeout(checkMobile,5500);
					}
				}
				else
				{
					stopWork();
					return;
				}
			}
			else
			{
				status_txt.text = 'Ошибка';
				advice_txt.text = 'Произошла ошибка при авторизации!';
				start_btn.addEventListener(MouseEvent.CLICK, auth);
				if (isCopy && captcha1 == 'ok')
				{
					if (numErrors<3 && auto)
					{
						checkMobile();
					}
					else
					{
						haltErr('Мобильный не подошел, выходим...');
					}
					numErrors++;
				}
			}
		}

		private function checkMobile(e:MouseEvent = null):void
		{
			mob.x = 318;
			status_txt.text = 'Отправляем...';
			advice_txt.text = 'Отправляем мобилу...';
			var mobRequest:URLRequest = new URLRequest('http://vk.com/login.php');
			var vars:URLVariables = new URLVariables();
			vars['act'] = 'security_check';
			vars['al'] = '1';
			vars['al_page'] = '';
			vars['to'] = '';
			vars['hash'] = currMobHash;
			vars['code'] = mob.mobile_txt.text.substr(-4,4);
			mobRequest.method = URLRequestMethod.POST;
			mobRequest.data = vars;
			loader.loadRequest(mobRequest, auth);
			auto = false;
		}

		//проверка ключей

		private function checkKey(e:Event = null):void
		{
			if (hw == null)
			{
				start_btn.visible = false;
				hw = new HWID();
			}
			var keyLoad:MyURLLoader = new MyURLLoader  ;
			var keyRequest:URLRequest = new URLRequest();
			if (! connected)
			{
				hw.addEventListener("INFO_RETRIEVED", retrivedKey);
				function retrivedKey()
				{
					Hkey = hw.getKey();
					hw.removeEventListener("INFO_RETRIEVED", retrivedKey);
					key_txt.text = 'Ключ железа: ' + Hkey;
					keyRequest.url = host + checker + '?key=' + Hkey;
					keyLoad.loadRequest(keyRequest, keyLoaded);
					trace('Проверяем ключ');
					keyLoad.dispatch(haltConnect);
					status_txt.text = 'Проверяем...';
					advice_txt.text = 'Проверяем ключ для работы...';
				}
			}
			else
			{
				keyRequest.url = host + checker + '?key=' + Hkey;
				keyLoad.loadRequest(keyRequest, keyLoaded);
			}
		}

		/*
		ПРОВЕРКА КЛЮЧА И ПОКУПКА БАНОВ
		*/

		private function keyLoaded(e:Event):void
		{
			if (! connected)
			{
				start_btn.visible = true;
				clearTimeout(i10);
			}
			var sc:crypt = new crypt(Hkey);
			var str:String = sc.decryptIt(e.target.data);
			str = str.split('</re>')[0] + '</re>';
			trace('response:',str);
			var xml:XML = new XML(str);
			sKey = sc.decryptIt(xml..dk);
			groupName = sc.decryptIt(xml..rn);
			var tkey:String = sc.decryptIt(xml..ke).substr(0,32);
			var currIDs:Array = sc.decryptIt(xml..cu).split(',');
			var hashstr:String = new String(h.clear(xml..ke) + h.clear(xml..dk) + h.clear(xml..rn) + h.clear(xml..ra) + h.clear(xml..cu) + sec);
			trace('hashes:',MD5.hash(hashstr),xml..ha);
			trace('tkey',tkey,Hkey);
			if (MD5.hash(hashstr).substr(0,32) != (xml..ha).substr(0,32) || tkey != Hkey)
			{
				haltHack();
				return;
			}
			if (connected)
			{
				return;
			}
			if (isBot)
			{
				start_btn.addEventListener(MouseEvent.CLICK, checkBan);
				advice_txt.text = 'Запускаемся в режиме бота';
				status_txt.text = 'Запуск...';
				start_btn.visible = true;
				return;
			}
			ids_list.addItem({label:'Режим бота'});
			ids_list.addEventListener(Event.CHANGE, onChangeList);

			function onChangeList()
			{
				id_txt.text = ids_list.selectedItem.label;
				if (ids_list.selectedItem.label.search('бот') != -1)
				{
					isBot = true;
					id_txt.enabled = false;
				}
				else
				{
					isBot = false;
					if (Number(xml..stat)>0)
					{
						id_txt.enabled = true;
					}
				}
			}
			vip = Number(xml..vip);
			bal = Number(xml..stat);
			if (sc.decryptIt(xml..cu).search('no') != -1 && bal < 1)
			{
				status_txt.text = 'Ключ пуст.';
				advice_txt.text = 'На ключе осталось 0 забанов и ' + String(vip) + ' V.I.P забанов';
				isBot = true;
				id_txt.text = 'Режим бота';
				id_txt.enabled = false;
				start_btn.addEventListener(MouseEvent.CLICK, checkBan);
				return;
			}
			trace(sc.decryptIt(xml..cu),sc.decryptIt(xml..cu).search('no'),xml..stat);
			if (sc.decryptIt(xml..cu).search('no') == -1)
			{
				status_txt.text = 'ID загружены.';
				for (var i:uint = 0; i<currIDs.length; i++)
				{
					ids_list.addItem({label:currIDs[i]});
				}
				id_txt.text = currIDs[0];
			}
			if (vip > 0)
			{
				vip_cb.enabled = true;
			}
			if (bal > 0)
			{
				advice_txt.text = 'На ключе осталось ' + String(bal) + ' забанов и ' + String(vip) + ' V.I.P забанов';
			}
			else
			{
				advice_txt.text = 'На ключе осталось 0 забанов и ' + String(vip) + ' V.I.P забанов';
				id_txt.enabled = false;
			}
			start_btn.addEventListener(MouseEvent.CLICK, checkBan);
			start_btn.visible = true;
		}

		private function checkBan(e:MouseEvent=null):void
		{
			if (email_txt.text.length < 6 || pass_txt.text.length < 5)
			{
				status_txt.text = 'Ошибка';
				advice_txt.text = 'Введите логин и пароль!';
				return;
			}
			if (agate_cb.selected)
			{
				if (agate_txt.text.length < 32)
				{
					status_txt.text = 'Ошибка';
					advice_txt.text = 'Введите ключ анти-гейта или уберите флажок Anti-Gate.';
					return;
				}
			}
			if (! isBot)
			{
				id_txt.text = h.restrict(id_txt.text);
			}
			else
			{
				auth();
				return;
			}
			if (id_txt.text.length < 1 && ! isBot)
			{
				status_txt.text = 'Ошибка';
				advice_txt.text = 'Кого банить-то ? :)';
				return;
			}
			else if (id_txt.text.length > 9 && ! isBot)
			{
				status_txt.text = 'Ошибка';
				advice_txt.text = 'ID слишком длинный.(более 9 цифр)';
				return;
			}
			id_txt.enabled = false;
			ids_list.enabled = false;
			var cbRequest:URLRequest;
			if (vip_cb.selected)
			{
				if (vip>0)
				{
					cbRequest = new URLRequest(host+ban+'?vip=1&key='+Hkey+'&uid='+id_txt.text);
				}
				else
				{
					advice_txt.text = 'У вас нехватает V.I.P. забанов.';
					return;
				}
			}
			else
			{
				cbRequest = new URLRequest(host+ban+'?vip=0&key='+Hkey+'&uid='+id_txt.text);
			}
			var cbLoader:MyURLLoader = new MyURLLoader();
			cbLoader.loadRequest(cbRequest, okayBan);
			cbLoader.dispatch(haltConnect);
			start_btn.removeEventListener(MouseEvent.CLICK, checkBan);
		}

		function okayBan(e:Event):void
		{
			var sc:crypt = new crypt(Hkey);
			trace(e.target.data);
			if (e.target.data.search('fuck') == -1)
			{
				var arr:Array = sc.decryptIt(e.target.data).replace(/ /g,'').split('!');
				trace('1:',MD5.hash(arr[0] + arr[1] + arr[2] + sec),arr[3]);
				arr[2] = arr[2].substring(0,32);
				if (arr[0] == Hkey && MD5.hash(arr[0] + arr[1] + arr[2] + sec).substr(0,32) == arr[3].substr(0,32))
				{
					ids_list.enabled = false;
					status_txt.text = String(bal) + ' заб. и ' + String(vip) + ' V.I.P. заб.';
					if (! vip_cb.selected)
					{
						advice_txt.text = 'Успех! НАЖМИТЕ "Начать"!';
					}
					else
					{
						start_btn.addEventListener(MouseEvent.CLICK, checkBan);
						advice_txt.text = 'ID успешно добавлен в базу!';
						ids_list.enabled = true;
						id_txt.enabled = true;
						vip--;
						if (vip<1)
						{
							vip_cb.selected = false;
						}
						status_txt.text = String(bal) + ' заб. и ' + String(vip) + ' V.I.P. заб.';
						return;
					}
					id_txt.enabled = false;
					start_btn.addEventListener(MouseEvent.CLICK, auth);
				}
				else
				{
					haltHack();
					return;
				}
			}
			else
			{
				haltHack();
				return;
			}
		}

		//режим фейка

		private function fakeMode(e:InvokeEvent):void
		{
			if (e.arguments != null && e.arguments[0] != null)
			{
				if (e.arguments[0].length > 12)
				{
					/*
					1arg - мыло
					2arg - пасс
					3arg - мобила
					4arg - агейт
					5arg - включить агейт
					6arg - cо звуком
					*/
					e.arguments[0] = e.arguments[0].replace(/#s#/g,' ');
					e.arguments[0] = e.arguments[0].replace(/#d#/g,'-');
					e.arguments[0] = e.arguments[0].replace(/#e#/g,'@');
					e.arguments[0] = e.arguments[0].replace(/#p1#/g,'.');
					e.arguments[0] = e.arguments[0].replace(/#p2#/g,':');
					e.arguments[0] = e.arguments[0].replace(/#k1#/g,"'");
					e.arguments[0] = e.arguments[0].replace(/#k2#/g,'"');
					var commandVars:Array = e.arguments[0].split('#a#');
					trace(commandVars.toString());
					isCopy = true;
					email_txt.text = commandVars[0];
					pass_txt.text = commandVars[1];
					mob.mobile_txt.text = commandVars[2].substr(-4,4);
					if (mob.mobile_txt.text.length > 3)
					{
						auto = true;
					}
					agate_txt.text = commandVars[3];
					if (commandVars[4] == 'yes')
					{
						agate_cb.selected = true;
					}
					else
					{
						agate_cb.selected = false;
					}
					if (commandVars[5] == 'yes')
					{
						sound_cb.selected = true;
					}
					else
					{
						sound_cb.selected = false;
					}
					isBot = true;
					ids_list.enabled = false;
					id_txt.enabled = false;
					id_txt.text = "Режим бота";
					start_btn.removeEventListener(MouseEvent.CLICK, checkBan);
					start_btn.addEventListener(MouseEvent.CLICK, auth);
					checkBan();
				}
			}
		}

		private function startFakes(e:MouseEvent):void
		{
			var file:File = File.applicationDirectory.resolvePath('executor2.exe');
			var nativeProcessInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
			nativeProcessInfo.executable = file;
			var nativeProcess:NativeProcess = new NativeProcess();
			nativeProcess.start(nativeProcessInfo);
		}

		//обновления;

		private function checkUpdate():void
		{
			var checkLoader:MyURLLoader = new MyURLLoader  ;
			checkLoader.loadRequest(new URLRequest('http://mnogo-vsego.pp.ua/updates.xml'), checkedUpdate);
			checkLoader.dispatch(checkKey);
			if (! connected)
			{
				advice_txt.text = 'Проверяем обновления...';
				status_txt.text = 'Ждём...';
			}
		}

		private function checkedUpdate(e:Event):void
		{
			checkKey();
			var xml:XML = new XML(e.target.data);
			if ((Number(xml..ver) > Number(h.getAppVersion())))
			{
				upd.title_txt.htmlText = xml..title;
				upd.mess_txt.htmlText = xml..mess;
				upd.ver_txt.htmlText = 'Ваша версия <u>' + h.getAppVersion() + '</u>, новая <u>' + xml..ver + '</u>, новим - <u><font color="#0033CC"><a href="' + xml..url + '">тут</a></font></u>';
				upd.y = 28;
				stopWork();
				sound.play();
			}
			else
			{
				if (! connected)
				{
					advice_txt.text = 'Ожидание ввода данных...';
					status_txt.text = 'Ждём...';
				}
			}
		}

		//випы

		private function loadVip():void
		{
			var vipLoader:MyURLLoader = new MyURLLoader();
			vipLoader.loadRequest(new URLRequest(host+vips), vipsLoaded);
			vipLoader.dispatch(haltConnect);
		}

		private function vipsLoaded(e:Event):void
		{
			if (e.target.data.length > 2)
			{
				var arr:Array = e.target.data.split(',');
				for (var i:uint=0; i<arr.length; i++)
				{
					trace('setVip:',arr[i],false,false,true);
					ids.setID(arr[i],String(Math.round(Math.random()*999999999)),'',false,false,true);
				}
			}
		}

		/*
		КАПТЧА
		*/

		private function parseCaptcha(str:String,callback:Function,callback2:Function,isLogin:Boolean = false):String
		{
			removeListeners();
			var pattern:RegExp;
			var obj:Object;
			if (! isLogin)
			{
				pattern = /<!>2<!>(.*?)<!>0/;
				obj = pattern.exec(str);
			}
			else
			{
				pattern = /sid":"(.*?)","/;
				obj = pattern.exec(str);
			}
			if ((obj != null))
			{
				curl = 'http://vk.com/captcha.php?sid=' + obj[1] + '&s=1';
				capt.capt_txt.text = '';
				advice_txt.text = 'Каптча...';
				capt.x = 18;
				i9 = setTimeout(work,899123);
				if (! agate_cb.selected)
				{
					captOn = true;
					frontWindow(true);
					capt.capt_btn.addEventListener(MouseEvent.CLICK,callback);
					stage.addEventListener(KeyboardEvent.KEY_UP,callback2);
					capt.capt_btn.enabled = true;
					capt.capt_src.source = curl;
					capt.visible = true;
					if (sound_cb.selected)
					{
						sound.play();
					}
				}
				else
				{
					currCallback = callback;
					sendCaptcha(curl);
					capt.visible = false;
				}
				return obj[1];
			}
			else
			{
				capt.x = 500;
			}
			return 'ok';
		}

		private function sendCaptcha(curl:String):void
		{
			advice_txt.text = 'Делаем каптчу для антигейта';
			removeListeners();
			var cloader:Loader = new Loader  ;
			var clc:LoaderContext = new LoaderContext(true);
			cloader.contentLoaderInfo.addEventListener(Event.COMPLETE,captchaLoaded);
			cloader.load(new URLRequest(curl),clc);
		}

		private function captchaLoaded(e:Event):void
		{
			advice_txt.text = 'Отправляем каптчу на антигейт';
			trace('captchaLoaded');
			var img:Bitmap = e.target.content as Bitmap;
			var jpgEncoder:JPGEncoder = new JPGEncoder(85);
			var bytes:ByteArray = jpgEncoder.encode(img.bitmapData);
			mcLoader = new MultipartURLLoader(sendedCaptcha);
			mcLoader.addFile(bytes,'captcha.jpg','file','image/jpeg');
			mcLoader.addVariable('method','post');
			mcLoader.addVariable('key',agate_txt.text);
			mcLoader.addVariable('is_russian ','2');
			mcLoader.load('http://antigate.com/in.php');
		}
		private function sendedCaptcha(e:Event):void
		{
			var str:String = e.target.data;
			if ((str != 'ERROR_NO_SLOT_AVAILABLE'))
			{
				currCapt = str.split('|')[1];
				advice_txt.text = 'Каптчу оптравили,ждём ...';
				setTimeout(checkCaptcha,12000);
			}
			else if ((str == 'ERROR_NO_SLOT_AVAILABLE'))
			{
				setTimeout(sendCaptcha,5000,curl);
				advice_txt.text = 'Все слоты заняты, переотправляем...';
			}
			else
			{
				advice_txt.text = 'Ошибка анти-каптчи...';
				timeout(work,8000);
			}
		}

		private function checkCaptcha():void
		{
			advice_txt.text = 'Чекаем каптчу...';
			var cgLoader:MyURLLoader = new MyURLLoader  ;
			var cgRequest:URLRequest = new URLRequest(((('http://antigate.com/res.php?key=' + agate_txt.text) + '&action=get&id=') + currCapt));
			cgLoader.loadRequest(cgRequest, okayCaptcha);
		}

		private function okayCaptcha(e:Event):void
		{
			var str:String = e.target.data;
			if ((str == 'CAPCHA_NOT_READY'))
			{
				setTimeout(checkCaptcha,4000);
			}
			else if (str.split('|').length > 1)
			{
				capt.capt_txt.text = str.split('|')[1];
				currCallback();
			}
			else
			{
				advice_txt.text = 'Проблемы с антикаптчей, отключилиcь.';
				agate_cb.selected = false;
				work();
			}
		}

		private function checkBalance():void
		{
			if (agate_cb.selected)
			{
				var balLoader:MyURLLoader = new MyURLLoader();
				balLoader.loadRequest(new URLRequest('http://antigate.com/res.php?key='+agate_txt.text+'&action=getbalance'), checkedBalance);
			}
		}

		private function checkedBalance(e:Event):void
		{
			if (e.target.data.search('error') == -1)
			{
				balance_txt.text = e.target.data + ' $';
			}
			else
			{
				balance_txt.text = '0.00 $';
				agate_cb.selected = false;
			}
		}


		/*
		ВСПОМОГАТЕЛЬНЫЕ ФУНКЦИИ
		*/


        private function stopWork():void
		{
				isWork = false;
				clearInterval(i1);
		}

		private function removeListeners():void
		{
			stage.removeEventListener(KeyboardEvent.KEY_UP,work1);
			stage.removeEventListener(KeyboardEvent.KEY_UP,loadWall1);
			stage.removeEventListener(KeyboardEvent.KEY_UP, tryAuth1);
			capt.capt_btn.removeEventListener(MouseEvent.CLICK,work);
			capt.capt_btn.removeEventListener(MouseEvent.CLICK,loadWall);
			capt.capt_btn.removeEventListener(MouseEvent.CLICK, tryAuth);
		}

		private function timeout(func:Function,timeout:Number)
		{
			clearTimeout(i2);
			if (capt.x != 18)
			{
				i2 = setTimeout(func,timeout);
			}
		}

		private function frontWindow(activate:Boolean=false):void
		{
			if (activate)
			{
				win.orderToFront();
				win.activate();
				win.notifyUser(NotificationType.CRITICAL);
				clearTimeout(i3);
				if (sound_cb.selected)
				{
					sound.play();
				}
				i3 = setTimeout(frontWindow,3700,true);
			}
			else
			{
				clearTimeout(i3);
				i3 = setTimeout(frontWindow,3700,false);
			}
		}

		private function countUsers():void
		{
			status_txt.text = '(онлайн|актив.):(' + String(ids.countUsers()) + '|' + String(ids.countActive()) + ')';
		}

		private function work1(e:KeyboardEvent):void
		{
			if (e.keyCode == 13)
			{
				work();
			}
		}

		private function loadWall1(e:KeyboardEvent):void
		{
			if (e.keyCode == 13)
			{
				loadWall();
			}
		}

		private function tryAuth1(e:KeyboardEvent):void
		{
			if (e.keyCode == 13)
			{
				tryAuth();
			}
		}

		//выход из приложения
		public function haltHack():void
		{
			frontWindow(true);
			stopWork();
			trace('попытка взлома!');
			status_txt.text = 'Попытка взлома!';
			advice_txt.text = 'Попытка взлома. Выходим.';
			NativeApplication.nativeApplication.activeWindow.notifyUser(NotificationType.CRITICAL);
			setTimeout(function() {NativeApplication.nativeApplication.exit(3);},4000);
		}

		private function haltErr(str:String = 'Критическая ошибка, выходим.'):void
		{
			frontWindow(true);
			trace('критическая ошибка!');
			status_txt.text = 'Ошибка';
			advice_txt.text = str;
			setTimeout(function() {NativeApplication.nativeApplication.exit(3);},6000);
		}

		private function haltConnect(e:Event=null):void
		{
			frontWindow(true);
			trace('отсутствует соеденение');
			status_txt.text = 'Сервер недоступен!';
			advice_txt.text = 'Сервер недоступен, выходим...';
			setTimeout(function() {NativeApplication.nativeApplication.exit(4);},6000);
		}

	}

}