Advertisement
Guest User

Untitled

a guest
Jul 8th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public function connect(userName:String, host:String, port:uint = 9998, initialRoom:uint = 0):void {
  2.             PalaceClient.loaderContext.checkPolicyFile = true;
  3.            
  4.             host = host.toLowerCase();
  5.             var match:Array = host.match(/^palace:\/\/(.*)$/);
  6.             if (match && match.length > 0) {
  7.                 host = match[1];
  8.             }
  9.            
  10.             this.host = host;
  11.             this.port = port;
  12.             this.initialRoom = initialRoom;
  13.             this.userName = userName;
  14.            
  15.             if (connected || (socket && socket.connected)) {
  16.                 disconnect();
  17.             }
  18.             else {
  19.                 resetState();
  20.             }
  21.             connecting = true;
  22.             dispatchEvent(new PalaceEvent(PalaceEvent.CONNECT_START));
  23.            
  24.             socket = new Socket(this.host, this.port);
  25.             socket.timeout = 5000;
  26.             socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
  27.             socket.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
  28.             socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
  29.             socket.addEventListener(Event.CONNECT, onConnect);
  30.             socket.addEventListener(Event.CLOSE, onClose);
  31.         }
  32.  
  33.         public function authenticate(username:String, password:String):void {
  34.             if (socket && socket.connected) {
  35. //              trace("Sending auth response");
  36.                 var userPass:ByteArray = PalaceEncryption.getInstance().encrypt(username + ":" + password);
  37.                 socket.writeInt(OutgoingMessageTypes.AUTHRESPONSE);
  38.                 socket.writeInt(userPass.length + 1);
  39.                 socket.writeInt(0);
  40.                 socket.writeByte(userPass.length);
  41.                 socket.writeBytes(userPass);
  42.                 socket.flush();
  43.             }
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement