Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.eightlabs.IRCLib
  2. {
  3.     import com.eightlabs.utilities.*;
  4.     import flash.events.*;
  5.     import flash.net.*;
  6.     import flash.system.*;
  7.     import flash.utils.*;
  8.     import mx.core.*;
  9.  
  10.     public class ClientConnection extends EventDispatcher
  11.     {
  12.         public var port:int = 7000;
  13.         public var holdData:String = "";
  14.         public var hosts:Array;
  15.         private var ircLib:IRCLib = null;
  16.         public var originalUserName:String = null;
  17.         public var host:String = null;
  18.         public var userID:String = "ewcflash";
  19.         private var reconnectTimer:Timer;
  20.         public var hostnumber:int = 0;
  21.         private var socket:Socket;
  22.         public var userName:String = null;
  23.         public var passWord:String = null;
  24.  
  25.         public function ClientConnection(param1:IRCLib, param2:String, param3:int, param4:String, param5:String = "")
  26.         {
  27.             reconnectTimer = new Timer(5000, 1);
  28.             hosts = ["chat.everywherechat.com", "indigo.everywherechat.com"];
  29.             this.port = param3;
  30.             this.originalUserName = param4;
  31.             this.userName = param4;
  32.             this.passWord = passWord;
  33.             if (param5 != "")
  34.             {
  35.                 this.userID = param5;
  36.             }
  37.             this.ircLib = param1;
  38.             connect();
  39.             return;
  40.         }// end function
  41.  
  42.         private function socket_close(event:Event) : void
  43.         {
  44.             debug.write("socket_close from: " + this.host);
  45.             this.dispatchEvent(new Event("SocketClose"));
  46.             reconnectTimer.addEventListener("timer", reconnectHandler);
  47.             reconnectTimer.start();
  48.             return;
  49.         }// end function
  50.  
  51.         private function socket_data(event:Event) : void
  52.         {
  53.             var _loc_2:String = null;
  54.             var _loc_4:Array = null;
  55.             var _loc_5:String = null;
  56.             var _loc_3:* = new ByteArray();
  57.             socket.readBytes(_loc_3, 0, socket.bytesAvailable);
  58.             _loc_2 = _loc_3.toString();
  59.             if (holdData != "")
  60.             {
  61.                 _loc_2 = holdData + _loc_2;
  62.                 holdData = "";
  63.             }
  64.             _loc_4 = _loc_2.split("\r\n");
  65.             if (_loc_2.substr(_loc_2.length - 2) != "\r\n")
  66.             {
  67.                 holdData = _loc_4.pop();
  68.             }
  69.             for each (_loc_5 in _loc_4)
  70.             {
  71.                
  72.                 if (_loc_5.length > 0)
  73.                 {
  74.                     new IncomingData(ircLib, _loc_5);
  75.                 }
  76.             }
  77.             return;
  78.         }// end function
  79.  
  80.         private function nextHost() : void
  81.         {
  82.             if (this.hostnumber == (this.hosts.length - 1))
  83.             {
  84.                 this.hostnumber = 0;
  85.             }
  86.             else
  87.             {
  88.                 var _loc_1:String = this;
  89.                 var _loc_2:* = this.hostnumber + 1;
  90.                 _loc_1.hostnumber = _loc_2;
  91.             }
  92.             return;
  93.         }// end function
  94.  
  95.         public function socket_outData(param1:String) : void
  96.         {
  97.             socket.writeUTFBytes(param1 + String.fromCharCode(13) + String.fromCharCode(10));
  98.             socket.flush();
  99.             return;
  100.         }// end function
  101.  
  102.         public function reconnectHandler(event:TimerEvent) : void
  103.         {
  104.             connect();
  105.             return;
  106.         }// end function
  107.  
  108.         private function socket_connect(event:Event) : void
  109.         {
  110.             this.hostnumber = 0;
  111.             socket_outData("nick " + userName);
  112.             socket_outData("user " + userID + " rambler irc.everywherechat.com :EveryWhereChat Rambler " + Application.application.clientVersion);
  113.             return;
  114.         }// end function
  115.  
  116.         public function disconnect() : void
  117.         {
  118.             socket.close();
  119.             return;
  120.         }// end function
  121.  
  122.         private function socket_ioerror(event:IOErrorEvent) : void
  123.         {
  124.             debug.write("socket_ioerror from: " + this.host);
  125.             this.dispatchEvent(new Event("SocketClose"));
  126.             reconnectTimer.addEventListener("timer", reconnectHandler);
  127.             reconnectTimer.start();
  128.             return;
  129.         }// end function
  130.  
  131.         private function connect() : void
  132.         {
  133.             ircLib.sk = null;
  134.             socket = new Socket();
  135.             this.host = this.hosts[this.hostnumber];
  136.             debug.write("Connecting to " + this.host);
  137.             var CROSSDOMAINXML:* = "xmlsocket://" + this.host + ":843";
  138.             socket.addEventListener("connect", socket_connect);
  139.             socket.addEventListener("socketData", socket_data);
  140.             socket.addEventListener("ioError", socket_ioerror);
  141.             socket.addEventListener("close", socket_close);
  142.             if (CROSSDOMAINXML != null)
  143.             {
  144.                 Security.loadPolicyFile(CROSSDOMAINXML);
  145.             }
  146.             try
  147.             {
  148.                 socket.connect(host, port);
  149.             }
  150.             catch (e:SecurityError)
  151.             {
  152.             }
  153.             nextHost();
  154.             return;
  155.         }// end function
  156.  
  157.     }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement