diff --git a/LibreMetaverse.StructuredData/LLSD/XmlLLSD.cs b/LibreMetaverse.StructuredData/LLSD/XmlLLSD.cs
index 179c90eb..b5b02056 100644
--- a/LibreMetaverse.StructuredData/LLSD/XmlLLSD.cs
+++ b/LibreMetaverse.StructuredData/LLSD/XmlLLSD.cs
@@ -28,6 +28,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Xml;
using System.Text;
@@ -48,15 +49,7 @@ namespace OpenMetaverse.StructuredData
public static OSD DeserializeLLSDXml(Stream xmlStream)
{
// XmlReader don't take no shit from nobody. Parse out Linden Lab's bad PI.
- bool match = true;
- for (int i = 0; i < linden_lab_loves_bad_pi.Length; ++i)
- {
- if (xmlStream.ReadByte() != linden_lab_loves_bad_pi[i])
- {
- match = false;
- break;
- }
- }
+ bool match = linden_lab_loves_bad_pi.All(t => xmlStream.ReadByte() == t);
if (match)
{
// read until the linebreak >
diff --git a/LibreMetaverse/DirectoryManager.cs b/LibreMetaverse/DirectoryManager.cs
index fdc964dc..b6eb2dd1 100644
--- a/LibreMetaverse/DirectoryManager.cs
+++ b/LibreMetaverse/DirectoryManager.cs
@@ -27,6 +27,7 @@
using System;
using System.Threading;
using System.Collections.Generic;
+using System.Linq;
using OpenMetaverse.Packets;
using OpenMetaverse.Interfaces;
using OpenMetaverse.Messages.Linden;
@@ -924,15 +925,23 @@ namespace OpenMetaverse
public void StartLandSearch(DirFindFlags findFlags, SearchTypeFlags typeFlags, int priceLimit,
int areaLimit, int queryStart)
{
- DirLandQueryPacket query = new DirLandQueryPacket();
- query.AgentData.AgentID = Client.Self.AgentID;
- query.AgentData.SessionID = Client.Self.SessionID;
- query.QueryData.Area = areaLimit;
- query.QueryData.Price = priceLimit;
- query.QueryData.QueryStart = queryStart;
- query.QueryData.SearchType = (uint)typeFlags;
- query.QueryData.QueryFlags = (uint)findFlags;
- query.QueryData.QueryID = UUID.Random();
+ DirLandQueryPacket query = new DirLandQueryPacket
+ {
+ AgentData =
+ {
+ AgentID = Client.Self.AgentID,
+ SessionID = Client.Self.SessionID
+ },
+ QueryData =
+ {
+ Area = areaLimit,
+ Price = priceLimit,
+ QueryStart = queryStart,
+ SearchType = (uint)typeFlags,
+ QueryFlags = (uint)findFlags,
+ QueryID = UUID.Random()
+ }
+ };
Client.Network.SendPacket(query);
}
@@ -958,13 +967,21 @@ namespace OpenMetaverse
///
public UUID StartGroupSearch(string searchText, int queryStart, DirFindFlags flags)
{
- DirFindQueryPacket find = new DirFindQueryPacket();
- find.AgentData.AgentID = Client.Self.AgentID;
- find.AgentData.SessionID = Client.Self.SessionID;
- find.QueryData.QueryFlags = (uint)flags;
- find.QueryData.QueryText = Utils.StringToBytes(searchText);
- find.QueryData.QueryID = UUID.Random();
- find.QueryData.QueryStart = queryStart;
+ DirFindQueryPacket find = new DirFindQueryPacket
+ {
+ AgentData =
+ {
+ AgentID = Client.Self.AgentID,
+ SessionID = Client.Self.SessionID
+ },
+ QueryData =
+ {
+ QueryFlags = (uint)flags,
+ QueryText = Utils.StringToBytes(searchText),
+ QueryID = UUID.Random(),
+ QueryStart = queryStart
+ }
+ };
Client.Network.SendPacket(find);
@@ -979,13 +996,21 @@ namespace OpenMetaverse
///
public UUID StartPeopleSearch(string searchText, int queryStart)
{
- DirFindQueryPacket find = new DirFindQueryPacket();
- find.AgentData.AgentID = Client.Self.AgentID;
- find.AgentData.SessionID = Client.Self.SessionID;
- find.QueryData.QueryFlags = (uint)DirFindFlags.People;
- find.QueryData.QueryText = Utils.StringToBytes(searchText);
- find.QueryData.QueryID = UUID.Random();
- find.QueryData.QueryStart = queryStart;
+ DirFindQueryPacket find = new DirFindQueryPacket
+ {
+ AgentData =
+ {
+ AgentID = Client.Self.AgentID,
+ SessionID = Client.Self.SessionID
+ },
+ QueryData =
+ {
+ QueryFlags = (uint)DirFindFlags.People,
+ QueryText = Utils.StringToBytes(searchText),
+ QueryID = UUID.Random(),
+ QueryStart = queryStart
+ }
+ };
Client.Network.SendPacket(find);
@@ -1036,17 +1061,26 @@ namespace OpenMetaverse
public UUID StartPlacesSearch(DirFindFlags findFlags, ParcelCategory searchCategory, string searchText, string simulatorName,
UUID groupID, UUID transactionID)
{
- PlacesQueryPacket find = new PlacesQueryPacket();
- find.AgentData.AgentID = Client.Self.AgentID;
- find.AgentData.SessionID = Client.Self.SessionID;
- find.AgentData.QueryID = groupID;
-
- find.TransactionData.TransactionID = transactionID;
-
- find.QueryData.QueryText = Utils.StringToBytes(searchText);
- find.QueryData.QueryFlags = (uint)findFlags;
- find.QueryData.Category = (sbyte)searchCategory;
- find.QueryData.SimName = Utils.StringToBytes(simulatorName);
+ PlacesQueryPacket find = new PlacesQueryPacket
+ {
+ AgentData =
+ {
+ AgentID = Client.Self.AgentID,
+ SessionID = Client.Self.SessionID,
+ QueryID = groupID
+ },
+ TransactionData =
+ {
+ TransactionID = transactionID
+ },
+ QueryData =
+ {
+ QueryText = Utils.StringToBytes(searchText),
+ QueryFlags = (uint)findFlags,
+ Category = (sbyte)searchCategory,
+ SimName = Utils.StringToBytes(simulatorName)
+ }
+ };
Client.Network.SendPacket(find);
return transactionID;
@@ -1083,9 +1117,14 @@ namespace OpenMetaverse
/// UUID of query to correlate results in callback.
public UUID StartEventsSearch(string searchText, DirFindFlags queryFlags, string eventDay, uint queryStart, EventCategories category)
{
- DirFindQueryPacket find = new DirFindQueryPacket();
- find.AgentData.AgentID = Client.Self.AgentID;
- find.AgentData.SessionID = Client.Self.SessionID;
+ DirFindQueryPacket find = new DirFindQueryPacket
+ {
+ AgentData =
+ {
+ AgentID = Client.Self.AgentID,
+ SessionID = Client.Self.SessionID
+ }
+ };
UUID queryID = UUID.Random();
@@ -1102,11 +1141,18 @@ namespace OpenMetaverse
/// ID of Event returned from the method
public void EventInfoRequest(uint eventID)
{
- EventInfoRequestPacket find = new EventInfoRequestPacket();
- find.AgentData.AgentID = Client.Self.AgentID;
- find.AgentData.SessionID = Client.Self.SessionID;
-
- find.EventData.EventID = eventID;
+ EventInfoRequestPacket find = new EventInfoRequestPacket
+ {
+ AgentData =
+ {
+ AgentID = Client.Self.AgentID,
+ SessionID = Client.Self.SessionID
+ },
+ EventData =
+ {
+ EventID = eventID
+ }
+ };
Client.Network.SendPacket(find);
}
@@ -1158,14 +1204,15 @@ namespace OpenMetaverse
foreach (DirClassifiedReplyPacket.QueryRepliesBlock block in reply.QueryReplies)
{
- Classified classified = new Classified();
-
- classified.CreationDate = Utils.UnixTimeToDateTime(block.CreationDate);
- classified.ExpirationDate = Utils.UnixTimeToDateTime(block.ExpirationDate);
- classified.Flags = (ClassifiedFlags)block.ClassifiedFlags;
- classified.ID = block.ClassifiedID;
- classified.Name = Utils.BytesToString(block.Name);
- classified.Price = block.PriceForListing;
+ Classified classified = new Classified
+ {
+ CreationDate = Utils.UnixTimeToDateTime(block.CreationDate),
+ ExpirationDate = Utils.UnixTimeToDateTime(block.ExpirationDate),
+ Flags = (ClassifiedFlags)block.ClassifiedFlags,
+ ID = block.ClassifiedID,
+ Name = Utils.BytesToString(block.Name),
+ Price = block.PriceForListing
+ };
classifieds.Add(classified);
}
@@ -1186,14 +1233,15 @@ namespace OpenMetaverse
foreach (DirLandReplyPacket.QueryRepliesBlock block in reply.QueryReplies)
{
- DirectoryParcel dirParcel = new DirectoryParcel();
-
- dirParcel.ActualArea = block.ActualArea;
- dirParcel.ID = block.ParcelID;
- dirParcel.Name = Utils.BytesToString(block.Name);
- dirParcel.SalePrice = block.SalePrice;
- dirParcel.Auction = block.Auction;
- dirParcel.ForSale = block.ForSale;
+ DirectoryParcel dirParcel = new DirectoryParcel
+ {
+ ActualArea = block.ActualArea,
+ ID = block.ParcelID,
+ Name = Utils.BytesToString(block.Name),
+ SalePrice = block.SalePrice,
+ Auction = block.Auction,
+ ForSale = block.ForSale
+ };
parcelsForSale.Add(dirParcel);
}
@@ -1215,14 +1263,15 @@ namespace OpenMetaverse
foreach (DirLandReplyMessage.QueryReply block in reply.QueryReplies)
{
- DirectoryParcel dirParcel = new DirectoryParcel();
-
- dirParcel.ActualArea = block.ActualArea;
- dirParcel.ID = block.ParcelID;
- dirParcel.Name = block.Name;
- dirParcel.SalePrice = block.SalePrice;
- dirParcel.Auction = block.Auction;
- dirParcel.ForSale = block.ForSale;
+ DirectoryParcel dirParcel = new DirectoryParcel
+ {
+ ActualArea = block.ActualArea,
+ ID = block.ParcelID,
+ Name = block.Name,
+ SalePrice = block.SalePrice,
+ Auction = block.Auction,
+ ForSale = block.ForSale
+ };
parcelsForSale.Add(dirParcel);
}
@@ -1242,11 +1291,13 @@ namespace OpenMetaverse
List matches = new List(peopleReply.QueryReplies.Length);
foreach (DirPeopleReplyPacket.QueryRepliesBlock reply in peopleReply.QueryReplies)
{
- AgentSearchData searchData = new AgentSearchData();
- searchData.Online = reply.Online;
- searchData.FirstName = Utils.BytesToString(reply.FirstName);
- searchData.LastName = Utils.BytesToString(reply.LastName);
- searchData.AgentID = reply.AgentID;
+ AgentSearchData searchData = new AgentSearchData
+ {
+ Online = reply.Online,
+ FirstName = Utils.BytesToString(reply.FirstName),
+ LastName = Utils.BytesToString(reply.LastName),
+ AgentID = reply.AgentID
+ };
matches.Add(searchData);
}
@@ -1266,10 +1317,12 @@ namespace OpenMetaverse
List matches = new List(groupsReply.QueryReplies.Length);
foreach (DirGroupsReplyPacket.QueryRepliesBlock reply in groupsReply.QueryReplies)
{
- GroupSearchData groupsData = new GroupSearchData();
- groupsData.GroupID = reply.GroupID;
- groupsData.GroupName = Utils.BytesToString(reply.GroupName);
- groupsData.Members = reply.Members;
+ GroupSearchData groupsData = new GroupSearchData
+ {
+ GroupID = reply.GroupID,
+ GroupName = Utils.BytesToString(reply.GroupName),
+ Members = reply.Members
+ };
matches.Add(groupsData);
}
@@ -1288,23 +1341,25 @@ namespace OpenMetaverse
PlacesReplyMessage replyMessage = (PlacesReplyMessage)message;
List places = new List();
- for (int i = 0; i < replyMessage.QueryDataBlocks.Length; i++)
+ foreach (var query in replyMessage.QueryDataBlocks)
{
- PlacesSearchData place = new PlacesSearchData();
- place.ActualArea = replyMessage.QueryDataBlocks[i].ActualArea;
- place.BillableArea = replyMessage.QueryDataBlocks[i].BillableArea;
- place.Desc = replyMessage.QueryDataBlocks[i].Description;
- place.Dwell = replyMessage.QueryDataBlocks[i].Dwell;
- place.Flags = (DirectoryManager.PlacesFlags)(byte)replyMessage.QueryDataBlocks[i].Flags;
- place.GlobalX = replyMessage.QueryDataBlocks[i].GlobalX;
- place.GlobalY = replyMessage.QueryDataBlocks[i].GlobalY;
- place.GlobalZ = replyMessage.QueryDataBlocks[i].GlobalZ;
- place.Name = replyMessage.QueryDataBlocks[i].Name;
- place.OwnerID = replyMessage.QueryDataBlocks[i].OwnerID;
- place.Price = replyMessage.QueryDataBlocks[i].Price;
- place.SimName = replyMessage.QueryDataBlocks[i].SimName;
- place.SnapshotID = replyMessage.QueryDataBlocks[i].SnapShotID;
- place.SKU = replyMessage.QueryDataBlocks[i].ProductSku;
+ PlacesSearchData place = new PlacesSearchData
+ {
+ ActualArea = query.ActualArea,
+ BillableArea = query.BillableArea,
+ Desc = query.Description,
+ Dwell = query.Dwell,
+ Flags = (DirectoryManager.PlacesFlags)(byte)query.Flags,
+ GlobalX = query.GlobalX,
+ GlobalY = query.GlobalY,
+ GlobalZ = query.GlobalZ,
+ Name = query.Name,
+ OwnerID = query.OwnerID,
+ Price = query.Price,
+ SimName = query.SimName,
+ SnapshotID = query.SnapShotID,
+ SKU = query.ProductSku
+ };
places.Add(place);
}
@@ -1325,20 +1380,22 @@ namespace OpenMetaverse
foreach (PlacesReplyPacket.QueryDataBlock block in placesReply.QueryData)
{
- PlacesSearchData place = new PlacesSearchData();
- place.OwnerID = block.OwnerID;
- place.Name = Utils.BytesToString(block.Name);
- place.Desc = Utils.BytesToString(block.Desc);
- place.ActualArea = block.ActualArea;
- place.BillableArea = block.BillableArea;
- place.Flags = (PlacesFlags)block.Flags;
- place.GlobalX = block.GlobalX;
- place.GlobalY = block.GlobalY;
- place.GlobalZ = block.GlobalZ;
- place.SimName = Utils.BytesToString(block.SimName);
- place.SnapshotID = block.SnapshotID;
- place.Dwell = block.Dwell;
- place.Price = block.Price;
+ PlacesSearchData place = new PlacesSearchData
+ {
+ OwnerID = block.OwnerID,
+ Name = Utils.BytesToString(block.Name),
+ Desc = Utils.BytesToString(block.Desc),
+ ActualArea = block.ActualArea,
+ BillableArea = block.BillableArea,
+ Flags = (PlacesFlags)block.Flags,
+ GlobalX = block.GlobalX,
+ GlobalY = block.GlobalY,
+ GlobalZ = block.GlobalZ,
+ SimName = Utils.BytesToString(block.SimName),
+ SnapshotID = block.SnapshotID,
+ Dwell = block.Dwell,
+ Price = block.Price
+ };
places.Add(place);
}
@@ -1360,13 +1417,15 @@ namespace OpenMetaverse
foreach (DirEventsReplyPacket.QueryRepliesBlock reply in eventsReply.QueryReplies)
{
- EventsSearchData eventsData = new EventsSearchData();
- eventsData.Owner = reply.OwnerID;
- eventsData.Name = Utils.BytesToString(reply.Name);
- eventsData.ID = reply.EventID;
- eventsData.Date = Utils.BytesToString(reply.Date);
- eventsData.Time = reply.UnixTime;
- eventsData.Flags = (EventFlags)reply.EventFlags;
+ EventsSearchData eventsData = new EventsSearchData
+ {
+ Owner = reply.OwnerID,
+ Name = Utils.BytesToString(reply.Name),
+ ID = reply.EventID,
+ Date = Utils.BytesToString(reply.Date),
+ Time = reply.UnixTime,
+ Flags = (EventFlags)reply.EventFlags
+ };
matches.Add(eventsData);
}
@@ -1383,20 +1442,22 @@ namespace OpenMetaverse
{
Packet packet = e.Packet;
EventInfoReplyPacket eventReply = (EventInfoReplyPacket)packet;
- EventInfo evinfo = new EventInfo();
- evinfo.ID = eventReply.EventData.EventID;
- evinfo.Name = Utils.BytesToString(eventReply.EventData.Name);
- evinfo.Desc = Utils.BytesToString(eventReply.EventData.Desc);
- evinfo.Amount = eventReply.EventData.Amount;
- evinfo.Category = (EventCategories)Utils.BytesToUInt(eventReply.EventData.Category);
- evinfo.Cover = eventReply.EventData.Cover;
- evinfo.Creator = (UUID)Utils.BytesToString(eventReply.EventData.Creator);
- evinfo.Date = Utils.BytesToString(eventReply.EventData.Date);
- evinfo.DateUTC = eventReply.EventData.DateUTC;
- evinfo.Duration = eventReply.EventData.Duration;
- evinfo.Flags = (EventFlags)eventReply.EventData.EventFlags;
- evinfo.SimName = Utils.BytesToString(eventReply.EventData.SimName);
- evinfo.GlobalPos = eventReply.EventData.GlobalPos;
+ EventInfo evinfo = new EventInfo
+ {
+ ID = eventReply.EventData.EventID,
+ Name = Utils.BytesToString(eventReply.EventData.Name),
+ Desc = Utils.BytesToString(eventReply.EventData.Desc),
+ Amount = eventReply.EventData.Amount,
+ Category = (EventCategories)Utils.BytesToUInt(eventReply.EventData.Category),
+ Cover = eventReply.EventData.Cover,
+ Creator = (UUID)Utils.BytesToString(eventReply.EventData.Creator),
+ Date = Utils.BytesToString(eventReply.EventData.Date),
+ DateUTC = eventReply.EventData.DateUTC,
+ Duration = eventReply.EventData.Duration,
+ Flags = (EventFlags)eventReply.EventData.EventFlags,
+ SimName = Utils.BytesToString(eventReply.EventData.SimName),
+ GlobalPos = eventReply.EventData.GlobalPos
+ };
OnEventInfo(new EventInfoReplyEventArgs(evinfo));
}
@@ -1411,20 +1472,15 @@ namespace OpenMetaverse
{
Packet packet = e.Packet;
DirPlacesReplyPacket reply = (DirPlacesReplyPacket)packet;
- List result = new List();
-
- for (int i = 0; i < reply.QueryReplies.Length; i++)
- {
- DirectoryParcel p = new DirectoryParcel();
-
- p.ID = reply.QueryReplies[i].ParcelID;
- p.Name = Utils.BytesToString(reply.QueryReplies[i].Name);
- p.Dwell = reply.QueryReplies[i].Dwell;
- p.Auction = reply.QueryReplies[i].Auction;
- p.ForSale = reply.QueryReplies[i].ForSale;
-
- result.Add(p);
- }
+ List result = reply.QueryReplies.Select(t => new DirectoryParcel
+ {
+ ID = t.ParcelID,
+ Name = Utils.BytesToString(t.Name),
+ Dwell = t.Dwell,
+ Auction = t.Auction,
+ ForSale = t.ForSale
+ })
+ .ToList();
OnDirPlaces(new DirPlacesReplyEventArgs(reply.QueryData[0].QueryID, result));
}
diff --git a/LibreMetaverse/InventoryManager.cs b/LibreMetaverse/InventoryManager.cs
index 5f104626..64f6d9cc 100644
--- a/LibreMetaverse/InventoryManager.cs
+++ b/LibreMetaverse/InventoryManager.cs
@@ -4017,10 +4017,10 @@ namespace OpenMetaverse
List folderContents = _Store.GetContents(search.Folder);
// Iterate over all of the inventory objects in the base search folder
- for (int j = 0; j < folderContents.Count; j++)
+ foreach (var content in folderContents)
{
// Check if this inventory object matches the current path node
- if (folderContents[j].Name == search.Path[search.Level])
+ if (content.Name == search.Path[search.Level])
{
if (search.Level == search.Path.Length - 1)
{
@@ -4030,7 +4030,7 @@ namespace OpenMetaverse
if (m_FindObjectByPathReply != null)
{
OnFindObjectByPathReply(new FindObjectByPathReplyEventArgs(String.Join("/", search.Path),
- folderContents[j].UUID));
+ content.UUID));
}
// Remove this entry and restart the loop since we are changing the collection size
@@ -4043,7 +4043,7 @@ namespace OpenMetaverse
Logger.DebugLog(
$"Matched level {search.Level}/{search.Path.Length - 1} in a path search of {String.Join("/", search.Path)}", Client);
- search.Folder = folderContents[j].UUID;
+ search.Folder = content.UUID;
search.Level++;
_Searches[i] = search;
diff --git a/LibreMetaverse/Messages/LindenMessages.cs b/LibreMetaverse/Messages/LindenMessages.cs
index 39d30138..c693ab67 100644
--- a/LibreMetaverse/Messages/LindenMessages.cs
+++ b/LibreMetaverse/Messages/LindenMessages.cs
@@ -2957,12 +2957,14 @@ namespace OpenMetaverse.Messages.Linden
/// An containing the objects data
public override OSDMap Serialize()
{
- OSDMap map = new OSDMap(3);
- map["method"] = OSD.FromString(Method);
- OSDArray agentsArray = new OSDArray();
- for (int i = 0; i < AgentsBlock.Length; i++)
+ OSDMap map = new OSDMap(3)
{
- agentsArray.Add(OSD.FromUUID(AgentsBlock[i]));
+ ["method"] = OSD.FromString(Method)
+ };
+ OSDArray agentsArray = new OSDArray();
+ foreach (var uuid in AgentsBlock)
+ {
+ agentsArray.Add(OSD.FromUUID(uuid));
}
map["params"] = agentsArray;
map["session-id"] = OSD.FromUUID(SessionID);
diff --git a/LibreMetaverse/ObjectManager.cs b/LibreMetaverse/ObjectManager.cs
index e1b30cf2..f3d8a6f2 100644
--- a/LibreMetaverse/ObjectManager.cs
+++ b/LibreMetaverse/ObjectManager.cs
@@ -26,6 +26,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Threading;
using OpenMetaverse.Packets;
using OpenMetaverse.Http;
@@ -1805,10 +1806,8 @@ namespace OpenMetaverse
ObjectUpdatePacket update = (ObjectUpdatePacket)packet;
UpdateDilation(e.Simulator, update.RegionData.TimeDilation);
- for (int b = 0; b < update.ObjectData.Length; b++)
+ foreach (var block in update.ObjectData)
{
- ObjectUpdatePacket.ObjectDataBlock block = update.ObjectData[b];
-
ObjectMovementUpdate objectupdate = new ObjectMovementUpdate();
//Vector4 collisionPlane = Vector4.Zero;
//Vector3 position;
@@ -2002,7 +2001,7 @@ namespace OpenMetaverse
break;
default:
Logger.Log("Got an ObjectUpdate block with ObjectUpdate field length of " +
- block.ObjectData.Length, Helpers.LogLevel.Warning, Client);
+ block.ObjectData.Length, Helpers.LogLevel.Warning, Client);
continue;
}
@@ -2112,7 +2111,7 @@ namespace OpenMetaverse
if (handler != null)
{
ThreadPool.QueueUserWorkItem(delegate(object o)
- { handler(this, new PrimEventArgs(simulator, prim, update.RegionData.TimeDilation, isNewObject, attachment)); });
+ { handler(this, new PrimEventArgs(simulator, prim, update.RegionData.TimeDilation, isNewObject, attachment)); });
}
//OnParticleUpdate handler replacing decode particles, PCode.Particle system appears to be deprecated this is a fix
if (prim.ParticleSys.PartMaxAge != 0) {
@@ -2255,10 +2254,8 @@ namespace OpenMetaverse
ImprovedTerseObjectUpdatePacket terse = (ImprovedTerseObjectUpdatePacket)packet;
UpdateDilation(simulator, terse.RegionData.TimeDilation);
- for (int i = 0; i < terse.ObjectData.Length; i++)
+ foreach (var block in terse.ObjectData)
{
- ImprovedTerseObjectUpdatePacket.ObjectDataBlock block = terse.ObjectData[i];
-
try
{
int pos = 4;
@@ -2333,7 +2330,7 @@ namespace OpenMetaverse
if (handler != null)
{
ThreadPool.QueueUserWorkItem(delegate(object o)
- { handler(this, new TerseObjectUpdateEventArgs(simulator, obj, update, terse.RegionData.TimeDilation)); });
+ { handler(this, new TerseObjectUpdateEventArgs(simulator, obj, update, terse.RegionData.TimeDilation)); });
}
#region Update Client.Self
@@ -2378,9 +2375,8 @@ namespace OpenMetaverse
ObjectUpdateCompressedPacket update = (ObjectUpdateCompressedPacket)packet;
- for (int b = 0; b < update.ObjectData.Length; b++)
+ foreach (var block in update.ObjectData)
{
- ObjectUpdateCompressedPacket.ObjectDataBlock block = update.ObjectData[b];
int i = 0;
try
@@ -2390,7 +2386,7 @@ namespace OpenMetaverse
i += 16;
// Local ID
uint LocalID = (uint)(block.Data[i++] + (block.Data[i++] << 8) +
- (block.Data[i++] << 16) + (block.Data[i++] << 24));
+ (block.Data[i++] << 16) + (block.Data[i++] << 24));
// PCode
PCode pcode = (PCode)block.Data[i++];
@@ -2459,7 +2455,7 @@ namespace OpenMetaverse
if ((flags & CompressedFlags.HasParent) != 0)
{
prim.ParentID = (uint)(block.Data[i++] + (block.Data[i++] << 8) +
- (block.Data[i++] << 16) + (block.Data[i++] << 24));
+ (block.Data[i++] << 16) + (block.Data[i++] << 24));
}
else
{
@@ -2644,9 +2640,9 @@ namespace OpenMetaverse
List ids = new List(update.ObjectData.Length);
// Object caching is implemented when Client.Settings.PRIMITIVES_FACTORY is True, otherwise request updates for all of these objects
- for (int i = 0; i < update.ObjectData.Length; i++)
+ foreach (var odb in update.ObjectData)
{
- uint localID = update.ObjectData[i].ID;
+ uint localID = odb.ID;
if (cachedPrimitives)
{
@@ -2690,9 +2686,9 @@ namespace OpenMetaverse
if (Client.Settings.OBJECT_TRACKING)
{
uint localID;
- for (int i = 0; i < kill.ObjectData.Length; i++)
+ foreach (var odb in kill.ObjectData)
{
- localID = kill.ObjectData[i].ID;
+ localID = odb.ID;
if (simulator.ObjectsPrimitives.Dictionary.ContainsKey(localID))
removePrims.Add(localID);
@@ -2713,32 +2709,26 @@ namespace OpenMetaverse
lock (simulator.ObjectsAvatars.Dictionary)
{
uint localID;
- for (int i = 0; i < kill.ObjectData.Length; i++)
+ foreach (var odb in kill.ObjectData)
{
- localID = kill.ObjectData[i].ID;
+ localID = odb.ID;
if (simulator.ObjectsAvatars.Dictionary.ContainsKey(localID))
removeAvatars.Add(localID);
List rootPrims = new List();
- foreach (KeyValuePair prim in simulator.ObjectsPrimitives.Dictionary)
+ foreach (var prim in simulator.ObjectsPrimitives.Dictionary.Where(prim => prim.Value.ParentID == localID))
{
- if (prim.Value.ParentID == localID)
- {
- OnKillObject(new KillObjectEventArgs(simulator, prim.Key));
- removePrims.Add(prim.Key);
- rootPrims.Add(prim.Key);
- }
+ OnKillObject(new KillObjectEventArgs(simulator, prim.Key));
+ removePrims.Add(prim.Key);
+ rootPrims.Add(prim.Key);
}
- foreach (KeyValuePair prim in simulator.ObjectsPrimitives.Dictionary)
+ foreach (var prim in simulator.ObjectsPrimitives.Dictionary.Where(prim => rootPrims.Contains(prim.Value.ParentID)))
{
- if (rootPrims.Contains(prim.Value.ParentID))
- {
- OnKillObject(new KillObjectEventArgs(simulator, prim.Key));
- removePrims.Add(prim.Key);
- }
+ OnKillObject(new KillObjectEventArgs(simulator, prim.Key));
+ removePrims.Add(prim.Key);
}
}
@@ -2769,34 +2759,34 @@ namespace OpenMetaverse
ObjectPropertiesPacket op = (ObjectPropertiesPacket)packet;
ObjectPropertiesPacket.ObjectDataBlock[] datablocks = op.ObjectData;
- for (int i = 0; i < datablocks.Length; ++i)
+ foreach (var objectData in datablocks)
{
- ObjectPropertiesPacket.ObjectDataBlock objectData = datablocks[i];
- Primitive.ObjectProperties props = new Primitive.ObjectProperties();
-
- props.ObjectID = objectData.ObjectID;
- props.AggregatePerms = objectData.AggregatePerms;
- props.AggregatePermTextures = objectData.AggregatePermTextures;
- props.AggregatePermTexturesOwner = objectData.AggregatePermTexturesOwner;
- props.Permissions = new Permissions(objectData.BaseMask, objectData.EveryoneMask, objectData.GroupMask,
- objectData.NextOwnerMask, objectData.OwnerMask);
- props.Category = (ObjectCategory)objectData.Category;
- props.CreationDate = Utils.UnixTimeToDateTime((uint)objectData.CreationDate);
- props.CreatorID = objectData.CreatorID;
- props.Description = Utils.BytesToString(objectData.Description);
- props.FolderID = objectData.FolderID;
- props.FromTaskID = objectData.FromTaskID;
- props.GroupID = objectData.GroupID;
- props.InventorySerial = objectData.InventorySerial;
- props.ItemID = objectData.ItemID;
- props.LastOwnerID = objectData.LastOwnerID;
- props.Name = Utils.BytesToString(objectData.Name);
- props.OwnerID = objectData.OwnerID;
- props.OwnershipCost = objectData.OwnershipCost;
- props.SalePrice = objectData.SalePrice;
- props.SaleType = (SaleType)objectData.SaleType;
- props.SitName = Utils.BytesToString(objectData.SitName);
- props.TouchName = Utils.BytesToString(objectData.TouchName);
+ Primitive.ObjectProperties props = new Primitive.ObjectProperties
+ {
+ ObjectID = objectData.ObjectID,
+ AggregatePerms = objectData.AggregatePerms,
+ AggregatePermTextures = objectData.AggregatePermTextures,
+ AggregatePermTexturesOwner = objectData.AggregatePermTexturesOwner,
+ Permissions = new Permissions(objectData.BaseMask, objectData.EveryoneMask, objectData.GroupMask,
+ objectData.NextOwnerMask, objectData.OwnerMask),
+ Category = (ObjectCategory)objectData.Category,
+ CreationDate = Utils.UnixTimeToDateTime((uint)objectData.CreationDate),
+ CreatorID = objectData.CreatorID,
+ Description = Utils.BytesToString(objectData.Description),
+ FolderID = objectData.FolderID,
+ FromTaskID = objectData.FromTaskID,
+ GroupID = objectData.GroupID,
+ InventorySerial = objectData.InventorySerial,
+ ItemID = objectData.ItemID,
+ LastOwnerID = objectData.LastOwnerID,
+ Name = Utils.BytesToString(objectData.Name),
+ OwnerID = objectData.OwnerID,
+ OwnershipCost = objectData.OwnershipCost,
+ SalePrice = objectData.SalePrice,
+ SaleType = (SaleType)objectData.SaleType,
+ SitName = Utils.BytesToString(objectData.SitName),
+ TouchName = Utils.BytesToString(objectData.TouchName)
+ };
int numTextures = objectData.TextureID.Length / 16;
props.TextureIDs = new UUID[numTextures];
@@ -2911,13 +2901,13 @@ namespace OpenMetaverse
if (Client.Settings.OBJECT_TRACKING)
{
- for (int i = 0; i < msg.ObjectPhysicsProperties.Length; i++)
+ foreach (var prop in msg.ObjectPhysicsProperties)
{
lock (simulator.ObjectsPrimitives.Dictionary)
{
- if (simulator.ObjectsPrimitives.Dictionary.ContainsKey(msg.ObjectPhysicsProperties[i].LocalID))
+ if (simulator.ObjectsPrimitives.Dictionary.ContainsKey(prop.LocalID))
{
- simulator.ObjectsPrimitives.Dictionary[msg.ObjectPhysicsProperties[i].LocalID].PhysicsProps = msg.ObjectPhysicsProperties[i];
+ simulator.ObjectsPrimitives.Dictionary[prop.LocalID].PhysicsProps = prop;
}
}
}
@@ -2925,9 +2915,9 @@ namespace OpenMetaverse
if (m_PhysicsProperties != null)
{
- for (int i = 0; i < msg.ObjectPhysicsProperties.Length; i++)
+ foreach (var prop in msg.ObjectPhysicsProperties)
{
- OnPhysicsProperties(new PhysicsPropertiesEventArgs(simulator, msg.ObjectPhysicsProperties[i]));
+ OnPhysicsProperties(new PhysicsPropertiesEventArgs(simulator, prop));
}
}
}
@@ -3244,10 +3234,8 @@ namespace OpenMetaverse
// Iterate through all of the simulators
Simulator[] sims = Client.Network.Simulators.ToArray();
- for (int i = 0; i < sims.Length; i++)
+ foreach (var sim in sims)
{
- Simulator sim = sims[i];
-
float adjSeconds = seconds * sim.Stats.Dilation;
// Iterate through all of this sims avatars
diff --git a/LibreMetaverse/PacketDecoder.cs b/LibreMetaverse/PacketDecoder.cs
index 77261201..1972ed03 100644
--- a/LibreMetaverse/PacketDecoder.cs
+++ b/LibreMetaverse/PacketDecoder.cs
@@ -1459,21 +1459,21 @@ namespace OpenMetaverse.Packets
FieldInfo[] fields = packet.GetType().GetFields();
- for (int i = 0; i < fields.Length; i++)
+ foreach (var t in fields)
{
// we're not interested in any of these here
- if (fields[i].Name == "Type" || fields[i].Name == "Header" || fields[i].Name == "HasVariableBlocks")
+ if (t.Name == "Type" || t.Name == "Header" || t.Name == "HasVariableBlocks")
continue;
- if (fields[i].FieldType.IsArray)
+ if (t.FieldType.IsArray)
{
- result.AppendFormat("{0,30} []" + Environment.NewLine, "-- " + fields[i].Name + " --");
- RecursePacketArray(fields[i], packet, ref result);
+ result.AppendFormat("{0,30} []" + Environment.NewLine, "-- " + t.Name + " --");
+ RecursePacketArray(t, packet, ref result);
}
else
{
- result.AppendFormat("{0,30}" + Environment.NewLine, "-- " + fields[i].Name + " --");
- RecursePacketField(fields[i], packet, ref result);
+ result.AppendFormat("{0,30}" + Environment.NewLine, "-- " + t.Name + " --");
+ RecursePacketField(t, packet, ref result);
}
}