Skip to content

Instantly share code, notes, and snippets.

@LoadLow
Created December 1, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save LoadLow/d468306406317571ae52 to your computer and use it in GitHub Desktop.
Save LoadLow/d468306406317571ae52 to your computer and use it in GitHub Desktop.
protected function lowReceive(_arg_1:IDataInput):INetworkMessage
{
var _local_2:INetworkMessage;
var _local_3:uint;
var _local_4:uint;
var _local_5:uint;
if (!this._splittedPacket){
if (_arg_1.bytesAvailable < 2){
if (DEBUG_LOW_LEVEL_VERBOSE){
_log.info((("Not enought data to read the header, byte available : " + _arg_1.bytesAvailable) + " (needed : 2)"));
};
return (null);
};
_local_3 = _arg_1.readUnsignedShort();
_local_4 = this.getMessageId(_local_3);
if (_arg_1.bytesAvailable >= (_local_3 & NetworkMessage.BIT_MASK)){
_local_5 = this.readMessageLength(_local_3, _arg_1);
if (_arg_1.bytesAvailable >= _local_5){
this.updateLatency();
_local_2 = this._rawParser.parse(new CustomDataWrapper(_arg_1), _local_4, _local_5);
MEMORY_LOG[_local_2] = 1;
if (DEBUG_LOW_LEVEL_VERBOSE){
_log.info("Full parsing done");
};
}
else {
if (DEBUG_LOW_LEVEL_VERBOSE){
_log.info((((("Not enought data to read msg content, byte available : " + _arg_1.bytesAvailable) + " (needed : ") + _local_5) + ")"));
};
this._staticHeader = -1;
this._splittedPacketLength = _local_5;
this._splittedPacketId = _local_4;
this._splittedPacket = true;
this._socket.readBytes(this._inputBuffer, 0, _arg_1.bytesAvailable);
return (null);
};
}
else {
if (DEBUG_LOW_LEVEL_VERBOSE){
_log.info((((("Not enought data to read message ID, byte available : " + _arg_1.bytesAvailable) + " (needed : ") + (_local_3 & NetworkMessage.BIT_MASK)) + ")"));
};
this._staticHeader = _local_3;
this._splittedPacketLength = _local_5;
this._splittedPacketId = _local_4;
this._splittedPacket = true;
return (null);
};
}
else {
if (this._staticHeader != -1){
this._splittedPacketLength = this.readMessageLength(this._staticHeader, _arg_1);
this._staticHeader = -1;
};
if ((_arg_1.bytesAvailable + this._inputBuffer.length) >= this._splittedPacketLength){
_arg_1.readBytes(this._inputBuffer, this._inputBuffer.length, (this._splittedPacketLength - this._inputBuffer.length));
this._inputBuffer.position = 0;
this.updateLatency();
_local_2 = this._rawParser.parse(new CustomDataWrapper(this._inputBuffer), this._splittedPacketId, this._splittedPacketLength);
MEMORY_LOG[_local_2] = 1;
this._splittedPacket = false;
this._inputBuffer = new ByteArray();
return (_local_2);
};
_arg_1.readBytes(this._inputBuffer, this._inputBuffer.length, _arg_1.bytesAvailable);
return (null);
};
return (_local_2);
}
private function updateLatency():void
{
if (((((this._pause) || ((this._pauseBuffer.length > 0)))) || ((this._latestSent == 0)))){
return;
};
var _local_1:uint = getTimer();
var _local_2:uint = (_local_1 - this._latestSent);
this._latestSent = 0;
this._latencyBuffer.push(_local_2);
if (this._latencyBuffer.length > LATENCY_AVG_BUFFER_SIZE){
this._latencyBuffer.shift();
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment