Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function connect(userName:String, host:String, port:uint = 9998, initialRoom:uint = 0):void {
- PalaceClient.loaderContext.checkPolicyFile = true;
- host = host.toLowerCase();
- var match:Array = host.match(/^palace:\/\/(.*)$/);
- if (match && match.length > 0) {
- host = match[1];
- }
- this.host = host;
- this.port = port;
- this.initialRoom = initialRoom;
- this.userName = userName;
- if (connected || (socket && socket.connected)) {
- disconnect();
- }
- else {
- resetState();
- }
- connecting = true;
- dispatchEvent(new PalaceEvent(PalaceEvent.CONNECT_START));
- socket = new Socket(this.host, this.port);
- socket.timeout = 5000;
- socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
- socket.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
- socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
- socket.addEventListener(Event.CONNECT, onConnect);
- socket.addEventListener(Event.CLOSE, onClose);
- }
- public function authenticate(username:String, password:String):void {
- if (socket && socket.connected) {
- // trace("Sending auth response");
- var userPass:ByteArray = PalaceEncryption.getInstance().encrypt(username + ":" + password);
- socket.writeInt(OutgoingMessageTypes.AUTHRESPONSE);
- socket.writeInt(userPass.length + 1);
- socket.writeInt(0);
- socket.writeByte(userPass.length);
- socket.writeBytes(userPass);
- socket.flush();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement