diff --git a/libsecondlife-cs/AssetSystem/AssetManager.cs b/libsecondlife-cs/AssetSystem/AssetManager.cs
index eef092f8..e6f84e68 100644
--- a/libsecondlife-cs/AssetSystem/AssetManager.cs
+++ b/libsecondlife-cs/AssetSystem/AssetManager.cs
@@ -333,7 +333,8 @@ namespace libsecondlife.AssetSystem
// Lookup the request for this packet
if (!htDownloadRequests.ContainsKey(TransferID))
{
- slClient.Log("Received unexpected TransferInfo packet." + Environment.NewLine + packet.ToString(), Helpers.LogLevel.Warning);
+ //slClient.Log("Received unexpected TransferInfo packet." + Environment.NewLine + packet.ToString(),
+ // Helpers.LogLevel.Warning);
return;
}
AssetRequestDownload request = htDownloadRequests[TransferID];
diff --git a/libsecondlife-cs/Helpers.cs b/libsecondlife-cs/Helpers.cs
index d9cc0749..ad204361 100644
--- a/libsecondlife-cs/Helpers.cs
+++ b/libsecondlife-cs/Helpers.cs
@@ -153,6 +153,19 @@ namespace libsecondlife
return (uint)(bytes[3] + (bytes[2] << 8) + (bytes[1] << 16) + (bytes[0] << 24));
}
+ ///
+ /// Convert the first four bytes of the given array in big endian
+ /// ordering to an unsigned integer
+ ///
+ /// An array four bytes or longer
+ /// An unsigned integer, will be zero if the array contains
+ /// less than four bytes
+ public static uint BytesToUIntBig(byte[] bytes)
+ {
+ if (bytes.Length < 4) return 0;
+ return (uint)(bytes[0] + (bytes[1] << 8) + (bytes[2] << 16) + (bytes[3] << 24));
+ }
+
///
/// Convert the first eight bytes of the given array in little endian
/// ordering to an unsigned 64-bit integer
@@ -181,7 +194,10 @@ namespace libsecondlife
/// A UTF8 string
public static string FieldToUTF8String(byte[] bytes)
{
- return UTF8Encoding.UTF8.GetString(bytes);
+ if (bytes[bytes.Length - 1] == 0x00)
+ return UTF8Encoding.UTF8.GetString(bytes, 0, bytes.Length - 1);
+ else
+ return UTF8Encoding.UTF8.GetString(bytes);
}
///
diff --git a/libsecondlife-cs/MainAvatar.cs b/libsecondlife-cs/MainAvatar.cs
index fd9859d0..7560572b 100644
--- a/libsecondlife-cs/MainAvatar.cs
+++ b/libsecondlife-cs/MainAvatar.cs
@@ -1466,7 +1466,7 @@ namespace libsecondlife
// FIXME: quick and dirty hack
TeleportFinishPacket packet = new TeleportFinishPacket();
- packet.Info.SimIP = Helpers.BytesToUInt((byte[])info["SimIP"]);
+ packet.Info.SimIP = Helpers.BytesToUIntBig((byte[])info["SimIP"]);
packet.Info.LocationID = Helpers.BytesToUInt((byte[])info["LocationID"]);
packet.Info.TeleportFlags = Helpers.BytesToUInt((byte[])info["TeleportFlags"]);
packet.Info.AgentID = (LLUUID)info["AgentID"];
@@ -1475,7 +1475,10 @@ namespace libsecondlife
packet.Info.SimPort = (ushort)(long)info["SimPort"];
packet.Info.SimAccess = (byte)(long)info["SimAccess"];
- TeleportHandler(packet,Client.Network.CurrentSim);
+ Console.WriteLine("Received a TeleportFinish event, SimIP: " + new IPAddress(packet.Info.SimIP) +
+ ", LocationID: " + packet.Info.LocationID + ", RegionHandle: " + packet.Info.RegionHandle);
+
+ TeleportHandler(packet, Client.Network.CurrentSim);
}
}
@@ -1644,12 +1647,12 @@ namespace libsecondlife
Simulator previousSim = Client.Network.CurrentSim;
// Connect to the new sim
- String seedcaps = Encoding.UTF8.GetString(finish.Info.SeedCapability).Replace("\x00","");
- //look we are^H^H^Hshould work on little and big endian
- int after = IPAddress.NetworkToHostOrder((int)finish.Info.SimIP);
- IPAddress SimIP = new IPAddress(after);
+ string seedcaps = Helpers.FieldToUTF8String(finish.Info.SeedCapability);
+ IPAddress simIP = new IPAddress(finish.Info.SimIP);
+
+ Client.Network.CurrentCaps.Dead = true;
- Simulator sim = Client.Network.Connect(SimIP, finish.Info.SimPort,
+ Simulator sim = Client.Network.Connect(simIP, finish.Info.SimPort,
simulator.CircuitCode, true, seedcaps);
if (sim != null)
diff --git a/libsecondlife-cs/NetworkManager.cs b/libsecondlife-cs/NetworkManager.cs
index 40a2ea8c..06a3e126 100644
--- a/libsecondlife-cs/NetworkManager.cs
+++ b/libsecondlife-cs/NetworkManager.cs
@@ -65,10 +65,10 @@ namespace libsecondlife
/// Reference to the region this system is connected to
public Region Region;
+ internal bool Dead = false;
private string Seedcaps;
private StringDictionary Capabilities = new StringDictionary();
- private bool Dead = false;
private Thread EventThread;
private List Callbacks;
diff --git a/libsecondlife-cs/examples/TestClient/TestClient.cs b/libsecondlife-cs/examples/TestClient/TestClient.cs
index a6cabfbe..356cd923 100644
--- a/libsecondlife-cs/examples/TestClient/TestClient.cs
+++ b/libsecondlife-cs/examples/TestClient/TestClient.cs
@@ -21,20 +21,21 @@ namespace libsecondlife.TestClient
public Dictionary Appearances = new Dictionary();
public Dictionary Commands = new Dictionary();
public AppearanceManager Appearance;
-
public bool Running = true;
public string Master = String.Empty;
public ClientManager ClientManager;
+ public int regionX;
+ public int regionY;
+
+ //internal libsecondlife.InventorySystem.InventoryFolder currentDirectory;
private LLQuaternion bodyRotation = LLQuaternion.Identity;
private LLVector3 forward = new LLVector3(0, 0.9999f, 0);
private LLVector3 left = new LLVector3(0.9999f, 0, 0);
private LLVector3 up = new LLVector3(0, 0, 0.9999f);
private int DrawDistance = 64;
- internal libsecondlife.InventorySystem.InventoryFolder currentDirectory;
private System.Timers.Timer updateTimer;
- public int regionX;
- public int regionY;
+
///
///
diff --git a/libsecondlife-cs/examples/TestClient/TestClient.csproj b/libsecondlife-cs/examples/TestClient/TestClient.csproj
index 983e436b..e7edfdda 100644
--- a/libsecondlife-cs/examples/TestClient/TestClient.csproj
+++ b/libsecondlife-cs/examples/TestClient/TestClient.csproj
@@ -66,6 +66,9 @@
Code
+
+ Code
+
Code
diff --git a/libsecondlife-cs/libsecondlife.Utilities/Assets.cs b/libsecondlife-cs/libsecondlife.Utilities/Assets.cs
index 4b71006d..377ccd2c 100644
--- a/libsecondlife-cs/libsecondlife.Utilities/Assets.cs
+++ b/libsecondlife-cs/libsecondlife.Utilities/Assets.cs
@@ -91,7 +91,7 @@ namespace libsecondlife.Utilities.Assets
///
///
///
- public enum ChannelType
+ public enum ChannelType : int
{
///
Unknown = 0,
@@ -104,7 +104,7 @@ namespace libsecondlife.Utilities.Assets
///
///
///
- public enum SourceType
+ public enum SourceType : int
{
///
Unknown = 0,
@@ -122,7 +122,7 @@ namespace libsecondlife.Utilities.Assets
///
///
///
- public enum TargetType
+ public enum TargetType : int
{
///
Unknown = 0,
@@ -298,80 +298,74 @@ namespace libsecondlife.Utilities.Assets
private void TransferPacketHandler(Packet packet, Simulator simulator)
{
- TransferPacketPacket asset = (TransferPacketPacket)packet;
-
- Console.WriteLine(asset.ToString());
-
- if (Transfers.ContainsKey(asset.TransferData.TransferID))
+ if (OnAssetReceived != null)
{
- AssetTransfer transfer = Transfers[asset.TransferData.TransferID];
+ TransferPacketPacket asset = (TransferPacketPacket)packet;
+ Console.WriteLine(asset.ToString());
- if (transfer.Size == 0)
+ if (Transfers.ContainsKey(asset.TransferData.TransferID))
{
- // We haven't received the header yet, block until it's received or times out
- transfer.HeaderReceivedEvent.WaitOne(1000 * 20, false);
+ AssetTransfer transfer = Transfers[asset.TransferData.TransferID];
if (transfer.Size == 0)
{
- Client.Log("Timed out while waiting for the asset header to download for " +
- transfer.ID.ToStringHyphenated(), Helpers.LogLevel.Warning);
+ // We haven't received the header yet, block until it's received or times out
+ transfer.HeaderReceivedEvent.WaitOne(1000 * 20, false);
- lock (Transfers) Transfers.Remove(transfer.ID);
-
- // Fire the event with our transfer that contains Success = false;
- if (OnAssetReceived != null)
+ if (transfer.Size == 0)
{
+ Client.Log("Timed out while waiting for the asset header to download for " +
+ transfer.ID.ToStringHyphenated(), Helpers.LogLevel.Warning);
+
+ lock (Transfers) Transfers.Remove(transfer.ID);
+
+ // Fire the event with our transfer that contains Success = false;
try { OnAssetReceived(transfer); }
catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
+
+ return;
}
+ }
+
+ // This assumes that every transfer packet except the last one is exactly 1000 bytes,
+ // hopefully that is a safe assumption to make
+ if (asset.TransferData.Data.Length == 1000 ||
+ transfer.Transferred + asset.TransferData.Data.Length >= transfer.Size)
+ {
+ Array.Copy(asset.TransferData.Data, 0, transfer.AssetData, 1000 * (asset.TransferData.Packet - 1),
+ asset.TransferData.Data.Length);
+ transfer.Transferred += asset.TransferData.Data.Length;
+ }
+ else
+ {
+ Client.Log("Received a TransferPacket with a data length of " + asset.TransferData.Data.Length +
+ " bytes!", Helpers.LogLevel.Error);
+
+ // fire the even with out transfer that contains Success = false;
+ try { OnAssetReceived(transfer); }
+ catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
return;
}
- }
- // This assumes that every transfer packet except the last one is exactly 1000 bytes,
- // hopefully that is a safe assumption to make
- if (asset.TransferData.Data.Length == 1000)
- {
- Array.Copy(asset.TransferData.Data, 0, transfer.AssetData, 1000 * (asset.TransferData.Packet - 1),
- asset.TransferData.Data.Length);
- transfer.Transferred += 1000;
+ Client.DebugLog("Received " + asset.TransferData.Data.Length + "/" + transfer.Transferred +
+ "/" + transfer.Size + " bytes for asset " + transfer.ID.ToStringHyphenated());
+
+ // Check if we downloaded the full asset
+ if (transfer.Transferred >= transfer.Size)
+ {
+ transfer.Success = true;
+ lock (Transfers) Transfers.Remove(transfer.ID);
+
+ try { OnAssetReceived(transfer); }
+ catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
+ }
}
else
{
- Client.Log("Received a TransferPacket with a data length of " + asset.TransferData.Data.Length +
- " bytes!", Helpers.LogLevel.Error);
-
- // fire the even with out transfer that contains Success = false;
- if (OnAssetReceived != null)
- {
- try { OnAssetReceived(transfer); }
- catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
- }
-
- return;
+ Client.Log("Received a TransferPacket packet for an asset we didn't request, TransferID: " +
+ asset.TransferData.TransferID, Helpers.LogLevel.Warning);
}
-
- Client.DebugLog("Received " + asset.TransferData.Data.Length + "/" + transfer.Transferred +
- "/" + transfer.Size + " bytes for asset " + transfer.ID.ToStringHyphenated());
-
- // Check if we downloaded the full asset
- if (transfer.Transferred >= transfer.Size)
- {
- transfer.Success = true;
- lock (Transfers) Transfers.Remove(transfer.ID);
-
- if (OnAssetReceived != null)
- {
- try { OnAssetReceived(transfer); }
- catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
- }
- }
- }
- else
- {
- Client.Log("Received a TransferPacket packet for an asset we didn't request, TransferID: " +
- asset.TransferData.TransferID, Helpers.LogLevel.Warning);
}
}
}
diff --git a/libsecondlife-cs/libsecondlife.Utilities/libsecondlife.Utilities.csproj b/libsecondlife-cs/libsecondlife.Utilities/libsecondlife.Utilities.csproj
index 97ba5703..a71ad400 100644
--- a/libsecondlife-cs/libsecondlife.Utilities/libsecondlife.Utilities.csproj
+++ b/libsecondlife-cs/libsecondlife.Utilities/libsecondlife.Utilities.csproj
@@ -33,6 +33,7 @@
+