This commit is contained in:
UbitUmarov
2022-10-16 19:21:54 +01:00
parent 0df9802aa3
commit bce31bda7d
4 changed files with 61 additions and 60 deletions

View File

@@ -97,7 +97,7 @@ namespace OpenSim.Framework
/// <summary>
/// Agent's full name.
/// </summary>
public string Name { get { return string.Format("{0} {1}", firstname, lastname); } }
public string Name { get { return $"{firstname} {lastname}"; } }
/// <summary>
/// Random Unique GUID for this session. Client gets this at login and it's
@@ -139,13 +139,13 @@ namespace OpenSim.Framework
get
{
// Old style version string contains viewer name followed by a space followed by a version number
if (m_viewerInternal == null || m_viewerInternal.Contains(" "))
if (m_viewerInternal is null || m_viewerInternal.Contains(' '))
{
return m_viewerInternal;
}
else // New style version contains no spaces, just version number
{
return Channel + " " + m_viewerInternal;
return $"{Channel} {m_viewerInternal}";
}
}
}
@@ -183,14 +183,16 @@ namespace OpenSim.Framework
/// <returns>map of the agent circuit data</returns>
public OSDMap PackAgentCircuitData(EntityTransferContext ctx)
{
OSDMap args = new OSDMap();
args["agent_id"] = OSD.FromUUID(AgentID);
args["base_folder"] = OSD.FromUUID(BaseFolder);
args["caps_path"] = OSD.FromString(CapsPath);
if (ChildrenCapSeeds != null)
OSDMap args = new()
{
OSDArray childrenSeeds = new OSDArray(ChildrenCapSeeds.Count);
["agent_id"] = OSD.FromUUID(AgentID),
["base_folder"] = OSD.FromUUID(BaseFolder),
["caps_path"] = OSD.FromString(CapsPath)
};
if (ChildrenCapSeeds is not null)
{
OSDArray childrenSeeds = new(ChildrenCapSeeds.Count);
foreach (KeyValuePair<ulong, string> kvp in ChildrenCapSeeds)
{
OSDMap pair = new OSDMap();

View File

@@ -42,36 +42,38 @@ namespace OpenSim.Framework
/// <remarks>
/// We lock this for operations both on this dictionary and on m_agentCircuitsByUUID
/// </remarks>
private ConcurrentDictionary<uint, AgentCircuitData> m_agentCircuits = new ConcurrentDictionary<uint, AgentCircuitData>();
private readonly ConcurrentDictionary<uint, AgentCircuitData> m_agentCircuits = new();
/// <summary>
/// Agent circuits indexed by agent UUID.
/// </summary>
private ConcurrentDictionary<UUID, AgentCircuitData> m_agentCircuitsByUUID = new ConcurrentDictionary<UUID, AgentCircuitData>();
private readonly ConcurrentDictionary<UUID, AgentCircuitData> m_agentCircuitsByUUID = new();
public virtual AuthenticateResponse AuthenticateSession(UUID sessionID, UUID agentID, uint circuitcode)
{
AuthenticateResponse user = new AuthenticateResponse();
if (!m_agentCircuits.TryGetValue(circuitcode, out AgentCircuitData validcircuit) || validcircuit == null)
AuthenticateResponse user = new();
if (!m_agentCircuits.TryGetValue(circuitcode, out AgentCircuitData validcircuit) || validcircuit is null)
{
//don't have this circuit code in our list
user.Authorised = false;
return user;
}
if ((sessionID == validcircuit.SessionID) && (agentID == validcircuit.AgentID))
if (sessionID.Equals(validcircuit.SessionID) && agentID.Equals(validcircuit.AgentID))
{
user.Authorised = true;
user.LoginInfo = new Login();
user.LoginInfo.Agent = agentID;
user.LoginInfo.Session = sessionID;
user.LoginInfo.SecureSession = validcircuit.SecureSessionID;
user.LoginInfo.First = validcircuit.firstname;
user.LoginInfo.Last = validcircuit.lastname;
user.LoginInfo.InventoryFolder = validcircuit.InventoryFolder;
user.LoginInfo.BaseFolder = validcircuit.BaseFolder;
user.LoginInfo.StartPos = validcircuit.startpos;
user.LoginInfo.StartFar = (float)validcircuit.startfar;
user.LoginInfo = new Login
{
Agent = agentID,
Session = sessionID,
SecureSession = validcircuit.SecureSessionID,
First = validcircuit.firstname,
Last = validcircuit.lastname,
InventoryFolder = validcircuit.InventoryFolder,
BaseFolder = validcircuit.BaseFolder,
StartPos = validcircuit.startpos,
StartFar = validcircuit.startfar
};
}
else
{
@@ -106,7 +108,7 @@ namespace OpenSim.Framework
{
if (m_agentCircuits.TryRemove(circuitCode, out AgentCircuitData ac))
{
m_agentCircuitsByUUID.TryRemove(ac.AgentID, out AgentCircuitData dummy);
m_agentCircuitsByUUID.TryRemove(ac.AgentID, out AgentCircuitData _);
}
}
@@ -114,16 +116,16 @@ namespace OpenSim.Framework
{
if (m_agentCircuitsByUUID.TryRemove(agentID, out AgentCircuitData ac))
{
m_agentCircuits.TryRemove(ac.circuitcode, out AgentCircuitData dummy);
m_agentCircuits.TryRemove(ac.circuitcode, out AgentCircuitData _);
}
}
public virtual void RemoveCircuit(AgentCircuitData ac)
{
m_agentCircuitsByUUID.TryRemove(ac.AgentID, out AgentCircuitData dummy);
m_agentCircuits.TryRemove(ac.circuitcode, out AgentCircuitData dummyb);
if (dummy!= null && dummy.circuitcode != ac.circuitcode) //??
m_agentCircuits.TryRemove(dummy.circuitcode, out AgentCircuitData dummyc);
m_agentCircuitsByUUID.TryRemove(ac.AgentID, out AgentCircuitData byuuid);
m_agentCircuits.TryRemove(ac.circuitcode, out AgentCircuitData _);
if (byuuid is not null && byuuid.circuitcode != ac.circuitcode) //??
m_agentCircuits.TryRemove(byuuid.circuitcode, out AgentCircuitData _);
}
public AgentCircuitData GetAgentCircuitData(uint circuitCode)

View File

@@ -40,15 +40,15 @@ namespace OpenSim.Framework
{
/// <summary>A dictionary mapping from <seealso cref="UUID"/>
/// to <seealso cref="IClientAPI"/> references</summary>
private readonly Dictionary<UUID, IClientAPI> m_dictbyUUID = new Dictionary<UUID, IClientAPI>();
private readonly Dictionary<UUID, IClientAPI> m_dictbyUUID = new();
/// <summary>A dictionary mapping from <seealso cref="IPEndPoint"/>
/// to <seealso cref="IClientAPI"/> references</summary>
private readonly Dictionary<IPEndPoint, IClientAPI> m_dictbyIPe= new Dictionary<IPEndPoint, IClientAPI>();
private readonly Dictionary<IPEndPoint, IClientAPI> m_dictbyIPe= new();
/// <summary>snapshot collection of current <seealso cref="IClientAPI"/>
/// references</summary>
private IClientAPI[] m_array = null;
/// <summary>Synchronization object for writing to the collections</summary>
private readonly object m_syncRoot = new object();
private readonly object m_syncRoot = new();
/// <summary>Number of clients in the collection</summary>
public int Count
@@ -96,10 +96,8 @@ namespace OpenSim.Framework
{
lock (m_syncRoot)
{
IClientAPI value;
if (m_dictbyUUID.TryGetValue(key, out value))
if (m_dictbyUUID.Remove(key, out IClientAPI value))
{
m_dictbyUUID.Remove(key);
m_dictbyIPe.Remove(value.RemoteEndPoint);
m_array = null;
return true;

View File

@@ -37,6 +37,7 @@ using OpenSim.Framework;
using OpenSim.Region.Framework.Scenes.Types;
using OpenSim.Region.PhysicsModules.SharedBase;
using OpenSim.Region.Framework.Interfaces;
using System.Runtime.InteropServices;
namespace OpenSim.Region.Framework.Scenes
{
@@ -251,7 +252,7 @@ namespace OpenSim.Region.Framework.Scenes
scaleY = 1.0f / scaleY;
List<ScenePresence> presences = GetScenePresences();
foreach (ScenePresence sp in presences)
foreach (ScenePresence sp in CollectionsMarshal.AsSpan(presences))
{
// If this presence is a child agent, we don't want its coarse locations
if (sp.IsChildAgent)
@@ -804,7 +805,7 @@ namespace OpenSim.Region.Framework.Scenes
int rootnpccount = 0;
List<ScenePresence> presences = GetScenePresences();
foreach(ScenePresence sp in presences)
foreach(ScenePresence sp in CollectionsMarshal.AsSpan(presences))
{
if (sp.IsChildAgent)
++childcount;
@@ -986,7 +987,7 @@ namespace OpenSim.Region.Framework.Scenes
protected internal ScenePresence GetScenePresence(in string firstName, in string lastName)
{
List<ScenePresence> presences = GetScenePresences();
foreach (ScenePresence presence in presences)
foreach (ScenePresence presence in CollectionsMarshal.AsSpan(presences))
{
if (string.Equals(presence.Firstname, firstName, StringComparison.CurrentCultureIgnoreCase)
&& string.Equals(presence.Lastname, lastName, StringComparison.CurrentCultureIgnoreCase))
@@ -1050,7 +1051,7 @@ namespace OpenSim.Region.Framework.Scenes
protected internal bool TryGetAvatarByName(in string name, out ScenePresence avatar)
{
List<ScenePresence> presences = GetScenePresences();
foreach (ScenePresence presence in presences)
foreach (ScenePresence presence in CollectionsMarshal.AsSpan(presences))
{
if (string.Equals(name, presence.ControllingClient.Name, StringComparison.CurrentCultureIgnoreCase))
{
@@ -1122,11 +1123,10 @@ namespace OpenSim.Region.Framework.Scenes
float closestDistance = 280f;
EntityIntersection result = new();
EntityBase[] EntityList = GetEntities();
foreach (EntityBase ent in EntityList)
foreach (EntityBase ent in EntityList.AsSpan())
{
if (ent is SceneObjectGroup)
if (ent is SceneObjectGroup reportingG)
{
SceneObjectGroup reportingG = ent as SceneObjectGroup;
EntityIntersection inter = reportingG.TestIntersection(hray, frontFacesOnly, faceCenters);
if (inter.HitTF && inter.distance < closestDistance)
{
@@ -1149,7 +1149,7 @@ namespace OpenSim.Region.Framework.Scenes
EntityBase[] entities = Entities.GetEntities();
List<SceneObjectGroup> ret = new(entities.Length);
foreach(EntityBase et in entities)
foreach(EntityBase et in entities.AsSpan())
{
if(et is SceneObjectGroup sog)
ret.Add(sog);
@@ -1188,7 +1188,7 @@ namespace OpenSim.Region.Framework.Scenes
/// <returns>null if the part was not found</returns>
protected internal SceneObjectGroup GetSceneObjectGroup(in string name)
{
foreach(EntityBase entity in Entities.GetEntities())
foreach(EntityBase entity in Entities.GetEntities().AsSpan())
{
if (entity is SceneObjectGroup sog && sog.Name.Equals(name))
return sog;
@@ -1355,7 +1355,7 @@ namespace OpenSim.Region.Framework.Scenes
protected internal void ForEachSOG(Action<SceneObjectGroup> action)
{
EntityBase[] entities = Entities.GetEntities();
foreach (EntityBase entity in entities)
foreach (EntityBase entity in entities.AsSpan())
{
if (entity is SceneObjectGroup sog)
{
@@ -1379,7 +1379,7 @@ namespace OpenSim.Region.Framework.Scenes
public void ForEachRootScenePresence(Action<ScenePresence> action)
{
List<ScenePresence> presences = GetScenePresences();
foreach (ScenePresence sp in presences)
foreach (ScenePresence sp in CollectionsMarshal.AsSpan(presences))
{
if(sp.IsChildAgent || sp.IsDeleted)
continue;
@@ -1402,7 +1402,7 @@ namespace OpenSim.Region.Framework.Scenes
public void ForEachScenePresence(Action<ScenePresence> action)
{
List<ScenePresence> presences = GetScenePresences();
foreach (ScenePresence sp in presences)
foreach (ScenePresence sp in CollectionsMarshal.AsSpan(presences))
{
if (sp.IsDeleted)
continue;
@@ -1890,10 +1890,9 @@ namespace OpenSim.Region.Framework.Scenes
List<SceneObjectGroup> childGroups = new();
// We do this in reverse to get the link order of the prims correct
for (int i = 0; i < children.Count; i++)
foreach (SceneObjectPart childpart in CollectionsMarshal.AsSpan(children))
{
SceneObjectGroup child = children[i].ParentGroup;
SceneObjectGroup child = childpart.ParentGroup;
// Don't try and add a group to itself - this will only cause severe problems later on.
if (child == parentGroup)
continue;
@@ -1910,7 +1909,7 @@ namespace OpenSim.Region.Framework.Scenes
}
}
foreach (SceneObjectGroup child in childGroups)
foreach (SceneObjectGroup child in CollectionsMarshal.AsSpan(childGroups))
{
if (parentGroup.OwnerID == child.OwnerID)
{
@@ -1962,7 +1961,7 @@ namespace OpenSim.Region.Framework.Scenes
Monitor.Enter(m_linkLock);
try
{
foreach (SceneObjectPart part in prims)
foreach (SceneObjectPart part in CollectionsMarshal.AsSpan(prims))
{
if(part is null)
continue;
@@ -1997,7 +1996,7 @@ namespace OpenSim.Region.Framework.Scenes
if (childParts.Count > 0)
{
foreach (SceneObjectPart child in childParts)
foreach (SceneObjectPart child in CollectionsMarshal.AsSpan(childParts))
{
// Unlink all child parts from their groups
child.ParentGroup.DelinkFromGroup(child, true);
@@ -2007,7 +2006,7 @@ namespace OpenSim.Region.Framework.Scenes
}
}
foreach (SceneObjectPart root in rootParts)
foreach (SceneObjectPart root in CollectionsMarshal.AsSpan(rootParts))
{
// In most cases, this will run only one time, and the prim
// will be a solo prim
@@ -2035,7 +2034,7 @@ namespace OpenSim.Region.Framework.Scenes
// Determine new root
//
newSet.RemoveAt(0);
foreach (SceneObjectPart newChild in newSet)
foreach (SceneObjectPart newChild in CollectionsMarshal.AsSpan(newSet))
newChild.ClearUpdateSchedule();
LinkObjects(newRoot, newSet);
@@ -2051,7 +2050,7 @@ namespace OpenSim.Region.Framework.Scenes
// trigger events in the roots
//
foreach (SceneObjectGroup g in affectedGroups)
foreach (SceneObjectGroup g in CollectionsMarshal.AsSpan(affectedGroups))
{
if(g.RootPart.PhysActor is not null)
g.RootPart.PhysActor.Building = false;
@@ -2143,7 +2142,7 @@ namespace OpenSim.Region.Framework.Scenes
if (m_parentScene.Permissions.PropagatePermissions())
{
foreach (SceneObjectPart child in parts)
foreach (SceneObjectPart child in parts.AsSpan())
{
child.Inventory.ChangeInventoryOwner(AgentID);
child.TriggerScriptChangedEvent(Changed.OWNER);
@@ -2165,7 +2164,7 @@ namespace OpenSim.Region.Framework.Scenes
Entities.Add(copy);
m_scenePartsArray = null;
foreach (SceneObjectPart part in parts)
foreach (SceneObjectPart part in parts.AsSpan())
{
if (part.GetPrimType() == PrimType.SCULPT)
m_numMesh++;