* Reduced major-ass ugly code in LoadBalancer/TcpClient.cs

* Still more needs to be done.
0.6.0-stable
Adam Frisby 2008-05-08 05:18:38 +00:00
parent 8a48516bcf
commit 872af8e04d
1 changed files with 12 additions and 18 deletions

View File

@ -26,6 +26,7 @@
*/ */
using System; using System;
using System.IO;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading; using System.Threading;
@ -115,24 +116,17 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
public void FromBytes(byte[] bytes) public void FromBytes(byte[] bytes)
{ {
int i = 0; // offset MemoryStream memstr = new MemoryStream(bytes);
try memstr.Seek(0, SeekOrigin.Begin);
{ BinaryReader binread = new BinaryReader(memstr);
type = (int) (bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
throttlePacketType = (int) (bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); type = binread.ReadInt32();
numbytes = (int) (bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); throttlePacketType = binread.ReadInt32();
agent_id = new Guid( numbytes = binread.ReadInt32();
bytes[i++] | (bytes[i++] << 8) | (bytes[i++] << 16) | bytes[i++] << 24, agent_id = new Guid(binread.ReadBytes(16));
(short) (bytes[i++] | (bytes[i++] << 8)), region_port = binread.ReadInt32();
(short) (bytes[i++] | (bytes[i++] << 8)),
bytes[i++], bytes[i++], bytes[i++], bytes[i++], binread.Close();
bytes[i++], bytes[i++], bytes[i++], bytes[i++]);
region_port = (int) (bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
}
catch (Exception)
{
throw new Exception("bad format!!!");
}
} }
public byte[] ToBytes() public byte[] ToBytes()