mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-20 09:37:50 -05:00
Brought up to date with the private repository (feea4c7)
This commit is contained in:
1 parent
1aa738d692
commit
1b1df1ae48
7925 files changed
+2617237
-20
No files matched your search
@@ -0,0 +1,172 @@
|
||||
package it.gotoandplay.smartfoxserver.http
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.events.HTTPStatusEvent;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLRequest;
|
||||
import flash.net.URLVariables;
|
||||
import it.gotoandplay.smartfoxserver.SmartFoxClient;
|
||||
|
||||
public class HttpConnection extends EventDispatcher
|
||||
{
|
||||
|
||||
private static const HANDSHAKE:String = "connect";
|
||||
|
||||
private static const DISCONNECT:String = "disconnect";
|
||||
|
||||
private static const CONN_LOST:String = "ERR#01";
|
||||
|
||||
public static const POLL:String = "poll";
|
||||
|
||||
public static const HANDSHAKE_TOKEN:String = "#";
|
||||
|
||||
private static const servletUrl:String = "BlueBox/HttpBox.do";
|
||||
|
||||
private static const paramName:String = "sfsHttp";
|
||||
|
||||
private var smartFoxClient:SmartFoxClient;
|
||||
|
||||
private var sessionId:String;
|
||||
|
||||
private var connected:Boolean = false;
|
||||
|
||||
private var ipAddr:String;
|
||||
|
||||
private var port:int;
|
||||
|
||||
private var baseUrl:String;
|
||||
|
||||
private var webUrl:String;
|
||||
|
||||
private var urlRequest:URLRequest;
|
||||
|
||||
private var codec:IHttpProtocolCodec;
|
||||
|
||||
public function HttpConnection(param1:SmartFoxClient)
|
||||
{
|
||||
super();
|
||||
codec = new RawProtocolCodec();
|
||||
HttpRequest.init(handleResponse,handleStatus,handleIOError);
|
||||
this.smartFoxClient = param1;
|
||||
param1.debugMessage("HttpConnection ctor");
|
||||
}
|
||||
|
||||
public function getSessionId() : String
|
||||
{
|
||||
return this.sessionId;
|
||||
}
|
||||
|
||||
public function getBaseUrl() : String
|
||||
{
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
public function isConnected() : Boolean
|
||||
{
|
||||
return this.connected;
|
||||
}
|
||||
|
||||
public function connect(param1:String, param2:int = 8080, param3:Boolean = false) : void
|
||||
{
|
||||
this.ipAddr = param1;
|
||||
this.port = param2;
|
||||
this.baseUrl = (param3 ? "https://bb-" : "http://") + this.ipAddr;
|
||||
if(!param3 && param2 != 80 || param3 && param2 != 443)
|
||||
{
|
||||
this.baseUrl += ":" + this.port;
|
||||
}
|
||||
this.webUrl = baseUrl + "/" + "BlueBox/HttpBox.do";
|
||||
this.sessionId = null;
|
||||
urlRequest = new URLRequest(webUrl);
|
||||
urlRequest.method = "POST";
|
||||
smartFoxClient.debugMessage("connect: " + baseUrl);
|
||||
send("connect");
|
||||
}
|
||||
|
||||
public function close() : void
|
||||
{
|
||||
send("disconnect");
|
||||
}
|
||||
|
||||
public function send(param1:String) : void
|
||||
{
|
||||
var _loc2_:URLVariables = null;
|
||||
if(connected || param1 == "connect" || param1 == "poll")
|
||||
{
|
||||
_loc2_ = new URLVariables();
|
||||
_loc2_["sfsHttp"] = codec.encode(this.sessionId,param1);
|
||||
urlRequest.data = _loc2_;
|
||||
smartFoxClient.debugMessage("[Sending - BlueBox]: " + urlRequest.data);
|
||||
new HttpRequest(urlRequest,param1);
|
||||
}
|
||||
else
|
||||
{
|
||||
smartFoxClient.debugMessage("send: can\'t send message before being connected: " + param1);
|
||||
}
|
||||
}
|
||||
|
||||
private function handleResponse(param1:Event, param2:HttpRequest) : void
|
||||
{
|
||||
var _loc5_:HttpEvent = null;
|
||||
var _loc4_:URLLoader = param1.target as URLLoader;
|
||||
var _loc3_:String = _loc4_.data as String;
|
||||
var _loc6_:Object = {};
|
||||
if(_loc3_.charAt(0) == "#")
|
||||
{
|
||||
if(sessionId == null)
|
||||
{
|
||||
sessionId = codec.decode(_loc3_);
|
||||
connected = true;
|
||||
smartFoxClient.debugMessage("handleResponse: init sessionId: " + sessionId);
|
||||
_loc6_.sessionId = this.sessionId;
|
||||
_loc6_.success = true;
|
||||
_loc5_ = new HttpEvent("onHttpConnect",_loc6_);
|
||||
dispatchEvent(_loc5_);
|
||||
}
|
||||
else
|
||||
{
|
||||
smartFoxClient.debugMessage("**ERROR** SessionId is being rewritten");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_loc3_.indexOf("ERR#01") == 0)
|
||||
{
|
||||
_loc6_.data = {};
|
||||
_loc5_ = new HttpEvent("onHttpClose",_loc6_);
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc6_.data = _loc3_;
|
||||
_loc5_ = new HttpEvent("onHttpData",_loc6_);
|
||||
}
|
||||
dispatchEvent(_loc5_);
|
||||
}
|
||||
}
|
||||
|
||||
private function handleStatus(param1:HTTPStatusEvent, param2:HttpRequest) : void
|
||||
{
|
||||
var _loc3_:HttpEvent = null;
|
||||
if(param1.status < 200 || param1.status >= 400)
|
||||
{
|
||||
if(param2.message == "poll")
|
||||
{
|
||||
param2.complete();
|
||||
_loc3_ = new HttpEvent("onHttpPollError",null);
|
||||
dispatchEvent(_loc3_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function handleIOError(param1:IOErrorEvent, param2:HttpRequest) : void
|
||||
{
|
||||
var _loc3_:Object = {};
|
||||
_loc3_.message = param1.text;
|
||||
var _loc4_:HttpEvent = new HttpEvent("onHttpError",_loc3_);
|
||||
dispatchEvent(_loc4_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package it.gotoandplay.smartfoxserver.http
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class HttpEvent extends Event
|
||||
{
|
||||
|
||||
public static const onHttpData:String = "onHttpData";
|
||||
|
||||
public static const onHttpError:String = "onHttpError";
|
||||
|
||||
public static const onHttpPollError:String = "onHttpPollError";
|
||||
|
||||
public static const onHttpConnect:String = "onHttpConnect";
|
||||
|
||||
public static const onHttpClose:String = "onHttpClose";
|
||||
|
||||
public var params:Object;
|
||||
|
||||
private var evtType:String;
|
||||
|
||||
public function HttpEvent(param1:String, param2:Object)
|
||||
{
|
||||
super(param1);
|
||||
this.params = param2;
|
||||
this.evtType = param1;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new HttpEvent(this.evtType,this.params);
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return formatToString("HttpEvent","type","bubbles","cancelable","eventPhase","params");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package it.gotoandplay.smartfoxserver.http
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.HTTPStatusEvent;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLRequest;
|
||||
|
||||
public class HttpRequest
|
||||
{
|
||||
|
||||
private static var _responseHandler:Function;
|
||||
|
||||
private static var _statusHandler:Function;
|
||||
|
||||
private static var _errorHandler:Function;
|
||||
|
||||
private var _message:String;
|
||||
|
||||
private var _status:int;
|
||||
|
||||
private var _isCompleted:Boolean;
|
||||
|
||||
public function HttpRequest(param1:URLRequest, param2:String)
|
||||
{
|
||||
super();
|
||||
_message = param2;
|
||||
var _loc3_:URLLoader = new URLLoader();
|
||||
_loc3_.dataFormat = "text";
|
||||
_loc3_.addEventListener("complete",handleResponse);
|
||||
_loc3_.addEventListener("httpStatus",handleStatus);
|
||||
_loc3_.addEventListener("ioError",handleIOError);
|
||||
_loc3_.load(param1);
|
||||
}
|
||||
|
||||
public static function init(param1:Function, param2:Function, param3:Function) : void
|
||||
{
|
||||
_responseHandler = param1;
|
||||
_statusHandler = param2;
|
||||
_errorHandler = param3;
|
||||
}
|
||||
|
||||
private function handleResponse(param1:Event) : void
|
||||
{
|
||||
_responseHandler(param1,this);
|
||||
}
|
||||
|
||||
private function handleStatus(param1:HTTPStatusEvent) : void
|
||||
{
|
||||
_status = param1.status;
|
||||
_statusHandler(param1,this);
|
||||
}
|
||||
|
||||
private function handleIOError(param1:IOErrorEvent) : void
|
||||
{
|
||||
if(!_isCompleted)
|
||||
{
|
||||
_errorHandler(param1,this);
|
||||
}
|
||||
}
|
||||
|
||||
public function get message() : String
|
||||
{
|
||||
return _message;
|
||||
}
|
||||
|
||||
public function get status() : int
|
||||
{
|
||||
return _status;
|
||||
}
|
||||
|
||||
public function complete() : void
|
||||
{
|
||||
_isCompleted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package it.gotoandplay.smartfoxserver.http
|
||||
{
|
||||
public interface IHttpProtocolCodec
|
||||
{
|
||||
|
||||
function encode(param1:String, param2:String) : String;
|
||||
|
||||
function decode(param1:String) : String;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package it.gotoandplay.smartfoxserver.http
|
||||
{
|
||||
public class RawProtocolCodec implements IHttpProtocolCodec
|
||||
{
|
||||
|
||||
private static const SESSION_ID_LEN:int = 32;
|
||||
|
||||
public function RawProtocolCodec()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function encode(param1:String, param2:String) : String
|
||||
{
|
||||
return (param1 == null ? "" : param1) + param2;
|
||||
}
|
||||
|
||||
public function decode(param1:String) : String
|
||||
{
|
||||
var _loc2_:String = null;
|
||||
if(param1.charAt(0) == "#")
|
||||
{
|
||||
_loc2_ = param1.substr(1,32);
|
||||
}
|
||||
return _loc2_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user