diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 3209c630c1..6c99761d72 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -26,14 +26,10 @@ */ using System; -using System.Collections; using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Threading; using log4net; using Nini.Config; -using Nwc.XmlRpc; using OpenMetaverse; using Mono.Addins; using OpenSim.Framework; @@ -75,9 +71,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } } - protected static readonly FriendInfo[] EMPTY_FRIENDS = new FriendInfo[0]; + protected static readonly FriendInfo[] EMPTY_FRIENDS = Array.Empty(); - protected List m_Scenes = new List(); + protected List m_Scenes = new(); protected IPresenceService m_PresenceService = null; protected IFriendsService m_FriendsService = null; @@ -90,25 +86,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends /// This is a complex and error-prone thing to do. At the moment, we assume that the efficiency gained in /// permissions checks outweighs the disadvantages of that complexity. /// - protected Dictionary m_Friends = new Dictionary(); + protected Dictionary m_Friends = new(); /// /// Maintain a record of clients that need to notify about their online status. This only /// needs to be done on login. Subsequent online/offline friend changes are sent by a different mechanism. /// - protected HashSet m_NeedsToNotifyStatus = new HashSet(); + protected HashSet m_NeedsToNotifyStatus = new(); /// /// Maintain a record of viewers that need to be sent notifications for friends that are online. This only /// needs to be done on login. Subsequent online/offline friend changes are sent by a different mechanism. /// - protected HashSet m_NeedsListOfOnlineFriends = new HashSet(); + protected HashSet m_NeedsListOfOnlineFriends = new(); protected IPresenceService PresenceService { get { - if (m_PresenceService == null) + if (m_PresenceService is null) { if (m_Scenes.Count > 0) m_PresenceService = m_Scenes[0].RequestModuleInterface(); @@ -122,7 +118,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends { get { - if (m_FriendsService == null) + if (m_FriendsService is null) { if (m_Scenes.Count > 0) m_FriendsService = m_Scenes[0].RequestModuleInterface(); @@ -186,11 +182,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends // Instantiate the request handler IHttpServer server = MainServer.GetHttpServer((uint)mPort); - if (server != null) - server.AddSimpleStreamHandler(new FriendsSimpleRequestHandler(this)); + server?.AddSimpleStreamHandler(new FriendsSimpleRequestHandler(this)); } - if (m_FriendsService == null) + if (m_FriendsService is null) { m_log.Error("[FRIENDS]: No Connector defined in section Friends, or failed to load, cannot continue"); throw new Exception("Connector load error"); @@ -247,7 +242,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends { FriendInfo[] friends = GetFriendsFromCache(principalID); FriendInfo finfo = GetFriend(friends, friendID); - if (finfo != null && finfo.TheirFlags != -1) + if (finfo is not null && finfo.TheirFlags != -1) { return finfo.TheirFlags; } @@ -307,18 +302,19 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends UUID agentID = client.AgentId; lock (m_Friends) { - UserFriendData friendsData; - if (m_Friends.TryGetValue(agentID, out friendsData)) + if (m_Friends.TryGetValue(agentID, out UserFriendData friendsData)) { friendsData.Refcount++; return false; } else { - friendsData = new UserFriendData(); - friendsData.PrincipalID = agentID; - friendsData.Friends = GetFriendsFromService(client); - friendsData.Refcount = 1; + friendsData = new UserFriendData + { + PrincipalID = agentID, + Friends = GetFriendsFromService(client), + Refcount = 1 + }; m_Friends[agentID] = friendsData; return true; @@ -337,8 +333,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends lock (m_Friends) { - UserFriendData friendsData; - if (m_Friends.TryGetValue(agentID, out friendsData)) + if (m_Friends.TryGetValue(agentID, out UserFriendData friendsData)) { friendsData.Refcount--; if (friendsData.Refcount <= 0) @@ -389,7 +384,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends client.SendAgentOnline(online.ToArray()); // Send outstanding friendship offers - List outstanding = new List(); + List outstanding = new(); FriendInfo[] friends = GetFriendsFromCache(client.AgentId); foreach (FriendInfo fi in friends) { @@ -397,7 +392,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends outstanding.Add(fi.Friend); } - GridInstantMessage im = new GridInstantMessage(client.Scene, UUID.Zero, String.Empty, client.AgentId, (byte)InstantMessageDialog.FriendshipOffered, + GridInstantMessage im = new(client.Scene, UUID.Zero, string.Empty, client.AgentId, (byte)InstantMessageDialog.FriendshipOffered, "Will you be my friend?", true, Vector3.Zero); foreach (string fid in outstanding) @@ -443,7 +438,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends List GetOnlineFriends(UUID userID) { - List friendList = new List(); + List friendList = new(); FriendInfo[] friends = GetFriendsFromCache(userID); foreach (FriendInfo fi in friends) @@ -452,27 +447,26 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends friendList.Add(fi.Friend); } - List online = new List(); + List online = new(); if (friendList.Count > 0) GetOnlineFriends(userID, friendList, online); -// m_log.DebugFormat( -// "[FRIENDS MODULE]: User {0} has {1} friends online", userID, online.Count); + //m_log.DebugFormat( + // "[FRIENDS MODULE]: User {0} has {1} friends online", userID, online.Count); return online; } protected virtual void GetOnlineFriends(UUID userID, List friendList, /*collector*/ List online) { -// m_log.DebugFormat( -// "[FRIENDS MODULE]: Looking for online presence of {0} users for {1}", friendList.Count, userID); + //m_log.DebugFormat( + // "[FRIENDS MODULE]: Looking for online presence of {0} users for {1}", friendList.Count, userID); PresenceInfo[] presence = PresenceService.GetAgents(friendList.ToArray()); foreach (PresenceInfo pi in presence) { - UUID presenceID; - if (UUID.TryParse(pi.UserID, out presenceID)) + if (UUID.TryParse(pi.UserID, out UUID presenceID)) online.Add(presenceID); } } @@ -487,7 +481,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends foreach (Scene scene in m_Scenes) { ScenePresence presence = scene.GetScenePresence(agentID); - if (presence != null && !presence.IsDeleted && !presence.IsChildAgent) + if (presence is not null && !presence.IsDeleted && !presence.IsChildAgent) return presence.ControllingClient; } } @@ -503,67 +497,67 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends private void StatusChange(UUID agentID, bool online) { FriendInfo[] friends = GetFriendsFromCache(agentID); - if (friends.Length > 0) - { - List friendList = new List(); - foreach (FriendInfo fi in friends) - { - if (((fi.MyFlags & (int)FriendRights.CanSeeOnline) != 0) && (fi.TheirFlags != -1)) - friendList.Add(fi); - } - if(friendList.Count > 0) - { - Util.FireAndForget( - delegate - { -// m_log.DebugFormat( -// "[FRIENDS MODULE]: Notifying {0} friends of {1} of online status {2}", -// friendList.Count, agentID, online); + if (friends.Length == 0) + return; - // Notify about this user status - StatusNotify(friendList, agentID, online); - }, null, "FriendsModule.StatusChange" - ); - } + List friendList = new(friends.Length); + foreach (FriendInfo fi in friends) + { + if (fi.TheirFlags != -1 && (fi.MyFlags & (int)FriendRights.CanSeeOnline) != 0) + friendList.Add(fi); + } + + if(friendList.Count > 0) + { + Util.FireAndForget( + delegate + { + //m_log.DebugFormat( + // "[FRIENDS MODULE]: Notifying {0} friends of {1} of online status {2}", + // friendList.Count, agentID, online); + + // Notify about this user status + StatusNotify(friendList, agentID, online); + }, null, "FriendsModule.StatusChange" + ); } } protected virtual void StatusNotify(List friendList, UUID userID, bool online) { //m_log.DebugFormat("[FRIENDS]: Entering StatusNotify for {0}", userID); - - List friendStringIds = friendList.ConvertAll(friend => friend.Friend); - List remoteFriendStringIds = new List(); - foreach (string friendStringId in friendStringIds) + List remoteFriendStringIds = new(friendList.Count); + foreach (FriendInfo friend in friendList) { - UUID friendUuid; - if (UUID.TryParse(friendStringId, out friendUuid)) + if (UUID.TryParse(friend.Friend, out UUID friendUuid)) { if (LocalStatusNotification(userID, friendUuid, online)) continue; - - remoteFriendStringIds.Add(friendStringId); + remoteFriendStringIds.Add(friend.Friend); } else { - m_log.WarnFormat("[FRIENDS]: Error parsing friend ID {0}", friendStringId); + m_log.WarnFormat("[FRIENDS]: Error parsing friend ID {0}", friend.Friend); } } + if (remoteFriendStringIds.Count == 0) + return; + // We do this regrouping so that we can efficiently send a single request rather than one for each // friend in what may be a very large friends list. PresenceInfo[] friendSessions = PresenceService.GetAgents(remoteFriendStringIds.ToArray()); - if(friendSessions == null) + if(friendSessions is null) return; foreach (PresenceInfo friendSession in friendSessions) { // let's guard against sessions-gone-bad - if (friendSession != null && !friendSession.RegionID.IsZero()) + if (friendSession is not null && friendSession.RegionID.IsNotZero()) { //m_log.DebugFormat("[FRIENDS]: Get region {0}", friendSession.RegionID); GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); - if (region != null) + if (region is not null) { m_FriendsSimConnector.StatusNotify(region, userID, friendSession.UserID, online); } @@ -578,17 +572,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends if ((InstantMessageDialog)im.dialog == InstantMessageDialog.FriendshipOffered) { // we got a friendship offer - UUID principalID = new UUID(im.fromAgentID); - UUID friendID = new UUID(im.toAgentID); + UUID principalID = new(im.fromAgentID); + UUID friendID = new(im.toAgentID); m_log.DebugFormat("[FRIENDS]: {0} ({1}) offered friendship to {2} ({3})", principalID, client.FirstName + client.LastName, friendID, im.fromAgentName); // Check that the friendship doesn't exist yet FriendInfo[] finfos = GetFriendsFromCache(principalID); - if (finfos != null) + if (finfos is not null) { FriendInfo f = GetFriend(finfos, friendID); - if (f != null) + if (f is not null) { client.SendAgentAlertMessage("This person is already your friend. Please delete it first if you want to reestablish the friendship.", false); return; @@ -617,13 +611,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends // The prospective friend is not here [as root]. Let's forward. PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); - if (friendSessions != null && friendSessions.Length > 0) + if (friendSessions is not null && friendSessions.Length > 0) { PresenceInfo friendSession = friendSessions[0]; - if (friendSession != null) + if (friendSession is not null) { GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); - if(region != null) + if(region is not null) { m_FriendsSimConnector.FriendshipOffered(region, agentID, friendID, im.message); return true; @@ -637,7 +631,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends protected virtual string GetFriendshipRequesterName(UUID agentID) { UserAccount account = UserAccountService.GetUserAccount(UUID.Zero, agentID); - return (account == null) ? "Unknown" : account.FirstName + " " + account.LastName; + return (account is null) ? "Unknown" : account.FirstName + " " + account.LastName; } protected virtual void OnApproveFriendRequest(IClientAPI client, UUID friendID, List callingCardFolders) @@ -651,10 +645,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends StoreFriendships(client.AgentId, friendID); ICallingCardModule ccm = client.Scene.RequestModuleInterface(); - if (ccm != null) - { - ccm.CreateCallingCard(client.AgentId, friendID, UUID.Zero); - } + ccm?.CreateCallingCard(client.AgentId, friendID, UUID.Zero); // Update the local cache. RecacheFriends(client); @@ -672,10 +663,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends // The friend is not here PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); - if (friendSessions != null && friendSessions.Length > 0) + if (friendSessions is not null && friendSessions.Length > 0) { PresenceInfo friendSession = friendSessions[0]; - if (friendSession != null) + if (friendSession is not null) { GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); m_FriendsSimConnector.FriendshipApproved(region, client.AgentId, client.Name, friendID); @@ -699,13 +690,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends return; PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); - if (friendSessions != null && friendSessions.Length > 0) + if (friendSessions is not null && friendSessions.Length > 0) { PresenceInfo friendSession = friendSessions[0]; - if (friendSession != null) + if (friendSession is not null) { GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); - if (region != null) + if (region is not null) m_FriendsSimConnector.FriendshipDenied(region, client.AgentId, client.Name, friendID); else m_log.WarnFormat("[FRIENDS]: Could not find region {0} in locating {1}", friendSession.RegionID, friendID); @@ -732,10 +723,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends return; PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { exfriendID.ToString() }); - if (friendSessions != null && friendSessions.Length > 0) + if (friendSessions is not null && friendSessions.Length > 0) { PresenceInfo friendSession = friendSessions[0]; - if (friendSession != null) + if (friendSession is not null) { GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); m_FriendsSimConnector.FriendshipTerminated(region, client.AgentId, exfriendID); @@ -754,7 +745,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends return; FriendInfo friend = GetFriend(friends, PreyID); - if (friend == null) + if (friend is null) return; if(friend.TheirFlags == -1 || (friend.TheirFlags & (int)FriendRights.CanSeeOnMap) == 0) @@ -762,14 +753,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends Scene hunterScene = (Scene)remoteClient.Scene; - if(hunterScene == null) + if(hunterScene is null) return; // check local - ScenePresence sp; double px; double py; - if(hunterScene.TryGetScenePresence(PreyID, out sp)) + if(hunterScene.TryGetScenePresence(PreyID, out ScenePresence sp)) { if(sp == null) return; @@ -782,16 +772,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { PreyID.ToString() }); - if (friendSessions == null || friendSessions.Length == 0) + if (friendSessions is null || friendSessions.Length == 0) return; PresenceInfo friendSession = friendSessions[0]; - if (friendSession == null) + if (friendSession is null) return; GridRegion region = GridService.GetRegionByUUID(hunterScene.RegionInfo.ScopeID, friendSession.RegionID); - if(region == null) + if(region is null) return; // we don't have presence location so point to a standard region center for now @@ -811,14 +801,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends FriendInfo[] friends = GetFriendsFromCache(requester); if (friends.Length == 0) - { return; - } // Let's find the friend in this user's friend list FriendInfo friend = GetFriend(friends, friendID); - - if (friend != null) // Found it + if (friend is not null) // Found it { // Store it on service if (!StoreRights(requester, friendID, rights)) @@ -843,10 +830,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends return; PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); - if (friendSessions != null && friendSessions.Length > 0) + if (friendSessions is not null && friendSessions.Length > 0) { PresenceInfo friendSession = friendSessions[0]; - if (friendSession != null) + if (friendSession is not null) { GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); // TODO: You might want to send the delta to save the lookup @@ -876,7 +863,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends public virtual bool LocalFriendshipOffered(UUID toID, GridInstantMessage im) { IClientAPI friendClient = LocateClientObject(toID); - if (friendClient != null) + if (friendClient is not null) { // the prospective friend in this sim as root agent friendClient.SendInstantMessage(im); @@ -889,18 +876,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends public bool LocalFriendshipApproved(UUID userID, string userName, UUID friendID) { IClientAPI friendClient = LocateClientObject(friendID); - if (friendClient != null) + if (friendClient is not null) { // the prospective friend in this sim as root agent - GridInstantMessage im = new GridInstantMessage(Scene, userID, userName, friendID, + GridInstantMessage im = new(Scene, userID, userName, friendID, (byte)OpenMetaverse.InstantMessageDialog.FriendshipAccepted, userID.ToString(), false, Vector3.Zero); friendClient.SendInstantMessage(im); ICallingCardModule ccm = friendClient.Scene.RequestModuleInterface(); - if (ccm != null) - { - ccm.CreateCallingCard(friendID, userID, UUID.Zero); - } + ccm?.CreateCallingCard(friendID, userID, UUID.Zero); // Update the local cache RecacheFriends(friendClient); @@ -915,10 +899,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends public bool LocalFriendshipDenied(UUID userID, string userName, UUID friendID) { IClientAPI friendClient = LocateClientObject(friendID); - if (friendClient != null) + if (friendClient is not null) { // the prospective friend in this sim as root agent - GridInstantMessage im = new GridInstantMessage(Scene, userID, userName, friendID, + GridInstantMessage im = new(Scene, userID, userName, friendID, (byte)OpenMetaverse.InstantMessageDialog.FriendshipDeclined, userID.ToString(), false, Vector3.Zero); friendClient.SendInstantMessage(im); // we're done @@ -931,7 +915,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends public bool LocalFriendshipTerminated(UUID userID, UUID exfriendID) { IClientAPI friendClient = LocateClientObject(exfriendID); - if (friendClient != null) + if (friendClient is not null) { // the friend in this sim as root agent friendClient.SendTerminateFriend(userID); @@ -947,7 +931,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends public bool LocalGrantRights(UUID userID, UUID friendID, int oldRights, int newRights) { IClientAPI friendClient = LocateClientObject(friendID); - if (friendClient != null) + if (friendClient is not null) { int changedRights = newRights ^ oldRights; bool onlineBitChanged = (changedRights & (int)FriendRights.CanSeeOnline) != 0; @@ -976,7 +960,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends { //m_log.DebugFormat("[FRIENDS]: Local Status Notify {0} that user {1} is {2}", friendID, userID, online); IClientAPI friendClient = LocateClientObject(friendID); - if (friendClient != null) + if (friendClient is not null) { // the friend in this sim as root agent if (online) @@ -996,11 +980,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends public FriendInfo[] GetFriendsFromCache(UUID userID) { - UserFriendData friendsData; - lock (m_Friends) { - if (m_Friends.TryGetValue(userID, out friendsData)) + if (m_Friends.TryGetValue(userID, out UserFriendData friendsData)) return friendsData.Friends; } @@ -1022,7 +1004,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends if(friends != EMPTY_FRIENDS) { FriendInfo finfo = GetFriend(friends, userID); - if(finfo!= null) + if(finfo is not null) finfo.TheirFlags = rights; } } diff --git a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs index dac6445cee..7790b51583 100644 --- a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs @@ -28,7 +28,6 @@ using System; using System.IO; using System.Text; -using System.Collections; using System.Collections.Generic; using System.Collections.Concurrent; using System.Globalization; @@ -36,7 +35,6 @@ using System.Linq; using System.Net; using System.Reflection; using System.Threading; -using System.Xml; using OpenMetaverse; using OpenMetaverse.StructuredData; using log4net; @@ -50,7 +48,6 @@ using OpenSim.Services.Connectors.Hypergrid; using OpenSim.Framework.Servers.HttpServer; using OpenSim.Services.UserProfilesService; using GridRegion = OpenSim.Services.Interfaces.GridRegion; -using Microsoft.CSharp; namespace OpenSim.Region.CoreModules.Avatar.UserProfiles { @@ -66,13 +63,12 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles // The pair of Dictionaries are used to handle the switching of classified ads // by maintaining a cache of classified id to creator id mappings and an interest // count. The entries are removed when the interest count reaches 0. - readonly Dictionary m_classifiedCache = new Dictionary(); - readonly Dictionary m_classifiedInterest = new Dictionary(); - readonly ExpiringCacheOS m_profilesCache = new ExpiringCacheOS(60000); - IAssetCache m_assetCache; + readonly Dictionary m_classifiedCache = new(); + readonly Dictionary m_classifiedInterest = new(); + readonly ExpiringCacheOS m_profilesCache = new(60000); IGroupsModule m_groupsModule = null; - private JsonRpcRequestManager rpc = new JsonRpcRequestManager(); + private readonly JsonRpcRequestManager rpc = new(); private bool m_allowUserProfileWebURLs = true; struct AsyncPropsRequest @@ -83,8 +79,8 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles public int reqtype; } - private ConcurrentStack m_asyncRequests = new ConcurrentStack(); - private object m_asyncRequestsLock = new object(); + private readonly ConcurrentStack m_asyncRequests = new(); + private readonly object m_asyncRequestsLock = new(); private bool m_asyncRequestsRunning = false; private void ProcessRequests() @@ -101,13 +97,10 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles if(req.reqtype == 0) { - UUID avatarID = req.agent; ScenePresence p = req.presence; - string serverURI = string.Empty; - bool ok = true; - bool foreign = GetUserProfileServerURI(avatarID, out serverURI); + bool foreign = GetUserProfileServerURI(req.agent, out string serverURI); if(serverURI.Length == 0) ok = false; @@ -115,34 +108,26 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles string born = string.Empty; uint flags = 0x00; - if (ok && GetUserAccountData(avatarID, out UserAccount acc)) + if (ok && GetUserAccountData(req.agent, out UserAccount acc)) { - int val_flags = acc.UserFlags; - flags = (uint)(val_flags & 0xff); + flags = (uint)(acc.UserFlags & 0xff); if (acc.UserTitle.Length == 0) - membershipType[0] = (byte)((val_flags & 0x0f00) >> 8); + membershipType[0] = (byte)((acc.UserFlags & 0x0f00) >> 8); else membershipType = Utils.StringToBytes(acc.UserTitle); int val_born = acc.Created; if (val_born != 0) born = Util.ToDateTime(val_born).ToString("M/d/yyyy", CultureInfo.InvariantCulture); - - // picky, picky } else ok = false; - UserProfileProperties props = new UserProfileProperties(); - props.UserId = avatarID; + UserProfileProperties props = new() { UserId = req.agent }; - if(ok) - { - string result = string.Empty; - if (!GetProfileData(ref props, foreign, serverURI, out result)) - ok = false; - } + if (ok) + ok = GetProfileData(ref props, foreign, serverURI, out string result); if (!ok) props.AboutText = "Profile not available at this time. User may still be unknown to this grid"; @@ -150,14 +135,18 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles if (!m_allowUserProfileWebURLs) props.WebUrl = ""; + // if on same region force online + if (p is not null && !p.IsDeleted) + flags |= (int)ProfileFlags.Online; + GroupMembershipData[] agentGroups = null; - if(ok && m_groupsModule != null) - agentGroups = m_groupsModule.GetMembershipData(avatarID); + if(ok && m_groupsModule is not null) + agentGroups = m_groupsModule.GetMembershipData(req.agent); HashSet clients; lock (m_profilesCache) { - if (!m_profilesCache.TryGetValue(props.UserId, out UserProfileCacheEntry uce) || uce == null) + if (!m_profilesCache.TryGetValue(props.UserId, out UserProfileCacheEntry uce) || uce is null) uce = new UserProfileCacheEntry(); uce.props = props; uce.born = born; @@ -169,11 +158,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles m_profilesCache.AddOrUpdate(props.UserId, uce, PROFILECACHEEXPIRE); } - // if on same region force online - if (p != null && !p.IsDeleted) - flags |= 0x10; - - if(clients == null) + if(clients is null) { client.SendAvatarProperties(props.UserId, props.AboutText, born, membershipType, props.FirstLifeText, flags, props.FirstLifeImageId, props.ImageId, props.WebUrl, props.PartnerId); @@ -193,7 +178,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles client.SendAvatarInterestsReply(props.UserId, (uint)props.WantToMask, props.WantToText, (uint)props.SkillsMask, props.SkillsText, props.Language); if (agentGroups != null) - client.SendAvatarGroupsReply(avatarID, agentGroups); + client.SendAvatarGroupsReply(req.agent, agentGroups); } foreach (IClientAPI cli in clients) { @@ -204,8 +189,8 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles cli.SendAvatarInterestsReply(props.UserId, (uint)props.WantToMask, props.WantToText, (uint)props.SkillsMask, props.SkillsText, props.Language); - if (agentGroups != null) - cli.SendAvatarGroupsReply(avatarID, agentGroups); + if (agentGroups is not null) + cli.SendAvatarGroupsReply(req.agent, agentGroups); } } } @@ -290,7 +275,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles IConfig profileConfig = Config.Configs["UserProfiles"]; - if (profileConfig == null) + if (profileConfig is null) { //m_log.Debug("[PROFILES]: UserProfiles disabled, no configuration"); Enabled = false; @@ -306,7 +291,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles return; } - OSHTTPURI tmp = new OSHTTPURI(ProfileServerUri, true); + OSHTTPURI tmp = new(ProfileServerUri, true); if (!tmp.IsResolvedHost) { m_log.ErrorFormat("[UserProfileModule: {0}", tmp.IsValidHost ? "Could not resolve ProfileServiceURL" : "ProfileServiceURL is a invalid host"); @@ -334,8 +319,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles return; Scene = scene; - if(m_thisGridInfo == null) - m_thisGridInfo = scene.SceneGridInfo; + m_thisGridInfo ??= scene.SceneGridInfo; Scene.RegisterModuleInterface(this); Scene.EventManager.OnNewClient += OnNewClient; Scene.EventManager.OnClientClosed += OnClientClosed; @@ -372,7 +356,6 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles { if(!Enabled) return; - m_assetCache = Scene.RequestModuleInterface(); m_groupsModule = Scene.RequestModuleInterface(); } @@ -451,7 +434,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles { ScenePresence sp = scene.GetScenePresence(AgentId); IClientAPI client = sp.ControllingClient; - if (client == null) + if (client is null) return; //Profile @@ -460,19 +443,15 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles client.OnAvatarInterestUpdate -= AvatarInterestsUpdate; // Classifieds -// client.r GenericPacketHandler("avatarclassifiedsrequest", ClassifiedsRequest); client.OnClassifiedInfoUpdate -= ClassifiedInfoUpdate; client.OnClassifiedInfoRequest -= ClassifiedInfoRequest; client.OnClassifiedDelete -= ClassifiedDelete; // Picks -// client.AddGenericPacketHandler("avatarpicksrequest", PicksRequest); -// client.AddGenericPacketHandler("pickinforequest", PickInfoRequest); client.OnPickInfoUpdate -= PickInfoUpdate; client.OnPickDelete -= PickDelete; // Notes -// client.AddGenericPacketHandler("avatarnotesrequest", NotesRequest); client.OnAvatarNotesUpdate -= NotesUpdate; // Preferences @@ -498,24 +477,22 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles /// public void ClassifiedsRequest(Object sender, string method, List args) { - if (!(sender is IClientAPI)) + if (sender is not IClientAPI remoteClient) return; - IClientAPI remoteClient = (IClientAPI)sender; - Dictionary classifieds = new Dictionary(); + Dictionary classifieds = new(); - UUID targetID; - if(!UUID.TryParse(args[0], out targetID) || targetID.IsZero()) + if (!UUID.TryParse(args[0], out UUID targetID) || targetID.IsZero()) return; - if (targetID == Constants.m_MrOpenSimID) + if (targetID.Equals(Constants.m_MrOpenSimID)) { remoteClient.SendAvatarClassifiedReply(targetID, classifieds); return; } ScenePresence p = FindPresence(targetID); - if (p != null && p.IsNPC) + if (p is not null && p.IsNPC) { remoteClient.SendAvatarClassifiedReply(targetID, classifieds); return; @@ -523,9 +500,9 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles lock(m_profilesCache) { - if(m_profilesCache.TryGetValue(targetID, out UserProfileCacheEntry uce) && uce != null) + if(m_profilesCache.TryGetValue(targetID, out UserProfileCacheEntry uce) && uce is not null) { - if(uce.classifiedsLists != null) + if(uce.classifiedsLists is not null) { foreach(KeyValuePair kvp in uce.classifiedsLists) { @@ -535,8 +512,8 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles { if (!m_classifiedCache.ContainsKey(kvpkey)) { - m_classifiedCache.Add(kvpkey,targetID); - m_classifiedInterest.Add(kvpkey, 0); + m_classifiedCache.Add(kvpkey,targetID); + m_classifiedInterest.Add(kvpkey, 0); } m_classifiedInterest[kvpkey]++; @@ -548,15 +525,18 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles } } - string serverURI = string.Empty; - GetUserProfileServerURI(targetID, out serverURI); + GetUserProfileServerURI(targetID, out string serverURI); if(string.IsNullOrWhiteSpace(serverURI)) { remoteClient.SendAvatarClassifiedReply(targetID, classifieds); return; } - OSDMap parameters= new OSDMap() {{"creatorId", OSD.FromUUID(targetID) }}; + OSDMap parameters= new() + { + {"creatorId", OSD.FromUUID(targetID)} + }; + OSD osdtmp = parameters; if(!rpc.JsonRpcRequest(ref osdtmp, "avatarclassifiedsrequest", serverURI, UUID.Random().ToString())) { @@ -565,7 +545,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles } parameters = (OSDMap)osdtmp; - if(!parameters.TryGetValue("result", out osdtmp) || !(osdtmp is OSDArray)) + if(!parameters.TryGetValue("result", out osdtmp) || osdtmp is not OSDArray) { remoteClient.SendAvatarClassifiedReply(targetID, classifieds); return; @@ -594,7 +574,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles lock(m_profilesCache) { - if(!m_profilesCache.TryGetValue(targetID, out UserProfileCacheEntry uce) || uce == null) + if(!m_profilesCache.TryGetValue(targetID, out UserProfileCacheEntry uce) || uce is null) uce = new UserProfileCacheEntry(); uce.classifiedsLists = classifieds; @@ -607,8 +587,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles public void ClassifiedInfoRequest(UUID queryClassifiedID, IClientAPI remoteClient) { UUID target = remoteClient.AgentId; - UserClassifiedAdd ad = new UserClassifiedAdd(); - ad.ClassifiedId = queryClassifiedID; + UserClassifiedAdd ad = new() { ClassifiedId = queryClassifiedID }; lock (m_classifiedCache) { @@ -616,7 +595,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles { target = m_classifiedCache[queryClassifiedID]; - m_classifiedInterest[queryClassifiedID] --; + m_classifiedInterest[queryClassifiedID]--; if (m_classifiedInterest[queryClassifiedID] == 0) { @@ -629,25 +608,24 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles UserProfileCacheEntry uce = null; lock(m_profilesCache) { - if(m_profilesCache.TryGetValue(target, out uce) && uce != null) + if(m_profilesCache.TryGetValue(target, out uce) && uce is not null) { - if(uce.classifieds != null && uce.classifieds.ContainsKey(queryClassifiedID)) + if(uce.classifieds is not null && uce.classifieds.ContainsKey(queryClassifiedID)) { ad = uce.classifieds[queryClassifiedID]; - Vector3 gPos = new Vector3(); - Vector3.TryParse(ad.GlobalPos, out gPos); - - remoteClient.SendClassifiedInfoReply(ad.ClassifiedId, ad.CreatorId, (uint)ad.CreationDate, + if(Vector3.TryParse(ad.GlobalPos, out Vector3 gPos)) + { + remoteClient.SendClassifiedInfoReply(ad.ClassifiedId, ad.CreatorId, (uint)ad.CreationDate, (uint)ad.ExpirationDate, (uint)ad.Category, ad.Name, ad.Description, ad.ParcelId, (uint)ad.ParentEstate, ad.SnapshotId, ad.SimName, gPos, ad.ParcelName, ad.Flags, ad.Price); + } return; } } } - string serverURI = string.Empty; - bool foreign = GetUserProfileServerURI(target, out serverURI); + bool foreign = GetUserProfileServerURI(target, out string serverURI); if(string.IsNullOrWhiteSpace(serverURI)) { return; @@ -670,19 +648,16 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles lock(m_profilesCache) { - if(!m_profilesCache.TryGetValue(target, out uce) || uce == null) + if(!m_profilesCache.TryGetValue(target, out uce) || uce is null) uce = new UserProfileCacheEntry(); - if(uce.classifieds == null) - uce.classifieds = new Dictionary(); + uce.classifieds ??= new Dictionary(); uce.classifieds[ad.ClassifiedId] = ad; m_profilesCache.AddOrUpdate(target, uce, PROFILECACHEEXPIRE); } - Vector3 globalPos = new Vector3(); - Vector3.TryParse(ad.GlobalPos, out globalPos); - - remoteClient.SendClassifiedInfoReply(ad.ClassifiedId, ad.CreatorId, (uint)ad.CreationDate, (uint)ad.ExpirationDate, + if(Vector3.TryParse(ad.GlobalPos, out Vector3 globalPos)) + remoteClient.SendClassifiedInfoReply(ad.ClassifiedId, ad.CreatorId, (uint)ad.CreationDate, (uint)ad.ExpirationDate, (uint)ad.Category, ad.Name, ad.Description, ad.ParcelId, (uint)ad.ParentEstate, ad.SnapshotId, ad.SimName, globalPos, ad.ParcelName, ad.Flags, ad.Price); @@ -734,26 +709,23 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles UUID creatorId = remoteClient.AgentId; ScenePresence p = FindPresence(creatorId); - UserProfileCacheEntry uce = null; - lock(m_profilesCache) + UserProfileCacheEntry uce; + lock (m_profilesCache) m_profilesCache.TryGetValue(remoteClient.AgentId, out uce); - string serverURI = string.Empty; - bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI); + bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out string serverURI); if(string.IsNullOrWhiteSpace(serverURI)) - { return; - } if(foreign) { remoteClient.SendAgentAlertMessage("Please change classifieds on your home grid", true); - if(uce != null && uce.classifiedsLists != null) + if(uce is not null && uce.classifiedsLists is not null) remoteClient.SendAvatarClassifiedReply(remoteClient.AgentId, uce.classifiedsLists); return; } - OSDMap parameters = new OSDMap {{"creatorId", OSD.FromUUID(creatorId)}}; + OSDMap parameters = new () { {"creatorId", OSD.FromUUID(creatorId)} }; OSD osdtmp = parameters; if (!rpc.JsonRpcRequest(ref osdtmp, "avatarclassifiedsrequest", serverURI, UUID.Random().ToString())) { @@ -769,51 +741,51 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles if (!exists) { money = s.RequestModuleInterface(); - if (money != null) + if (money is not null) { if (!money.AmountCovered(remoteClient.AgentId, queryclassifiedPrice)) { remoteClient.SendAgentAlertMessage("You do not have enough money to create this classified.", false); - if(uce != null && uce.classifiedsLists != null) + if(uce is not null && uce.classifiedsLists is not null) remoteClient.SendAvatarClassifiedReply(remoteClient.AgentId, uce.classifiedsLists); return; } } } - UserClassifiedAdd ad = new UserClassifiedAdd(); - - ad.ParcelName = land == null ? string.Empty : land.LandData.Name; - ad.CreatorId = remoteClient.AgentId; - ad.ClassifiedId = queryclassifiedID; - ad.Category = Convert.ToInt32(queryCategory); - ad.Name = queryName; - ad.Description = queryDescription; - ad.ParentEstate = Convert.ToInt32(queryParentEstate); - ad.SnapshotId = querySnapshotID; - ad.SimName = remoteClient.Scene.RegionInfo.RegionName; - ad.GlobalPos = queryGlobalPos.ToString (); - ad.Flags = queryclassifiedFlags; - ad.Price = queryclassifiedPrice; - ad.ParcelId = p.currentParcelUUID; + UserClassifiedAdd ad = new() + { + ParcelName = land == null ? string.Empty : land.LandData.Name, + CreatorId = remoteClient.AgentId, + ClassifiedId = queryclassifiedID, + Category = Convert.ToInt32(queryCategory), + Name = queryName, + Description = queryDescription, + ParentEstate = Convert.ToInt32(queryParentEstate), + SnapshotId = querySnapshotID, + SimName = remoteClient.Scene.RegionInfo.RegionName, + GlobalPos = queryGlobalPos.ToString(), + Flags = queryclassifiedFlags, + Price = queryclassifiedPrice, + ParcelId = p.currentParcelUUID + }; object Ad = ad; if(!rpc.JsonRpcRequest(ref Ad, "classified_update", serverURI, UUID.Random().ToString())) { remoteClient.SendAgentAlertMessage("Error updating classified", false); - if(uce != null && uce.classifiedsLists != null) + if(uce is not null && uce.classifiedsLists is not null) remoteClient.SendAvatarClassifiedReply(remoteClient.AgentId, uce.classifiedsLists); return; } // only charge if it worked - if (money != null) - money.ApplyCharge(remoteClient.AgentId, queryclassifiedPrice, MoneyTransactionType.ClassifiedCharge); + money?.ApplyCharge(remoteClient.AgentId, queryclassifiedPrice, MoneyTransactionType.ClassifiedCharge); // just flush cache for now lock(m_profilesCache) { - if(m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) && uce != null) + if(m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) && uce is not null) { uce.classifieds = null; uce.classifiedsLists = null; @@ -832,8 +804,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles /// public void ClassifiedDelete(UUID queryClassifiedID, IClientAPI remoteClient) { - string serverURI = string.Empty; - bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI); + bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out string serverURI); if(string.IsNullOrWhiteSpace(serverURI)) return; @@ -843,8 +814,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles return; } - UUID classifiedId; - if(!UUID.TryParse(queryClassifiedID.ToString(), out classifiedId)) + if (!UUID.TryParse(queryClassifiedID.ToString(), out UUID classifiedId)) return; OSD Params = new OSDMap() {{ "classifiedId", OSD.FromUUID(classifiedId) }}; @@ -856,10 +826,9 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles } // flush cache - UserProfileCacheEntry uce = null; lock(m_profilesCache) { - if(m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) && uce != null) + if(m_profilesCache.TryGetValue(remoteClient.AgentId, out UserProfileCacheEntry uce) && uce is not null) { uce.classifieds = null; uce.classifiedsLists = null; @@ -889,16 +858,16 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles if(!UUID.TryParse(args[0], out UUID targetId)) return; - Dictionary picks = new Dictionary(); + Dictionary picks = new(); - if (targetId == Constants.m_MrOpenSimID) + if (targetId.Equals(Constants.m_MrOpenSimID)) { remoteClient.SendAvatarPicksReply(targetId, picks); return; } ScenePresence p = FindPresence(targetId); - if (p != null && p.IsNPC) + if (p is not null && p.IsNPC) { remoteClient.SendAvatarPicksReply(targetId, picks); return; @@ -907,9 +876,9 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles UserProfileCacheEntry uce = null; lock(m_profilesCache) { - if(m_profilesCache.TryGetValue(targetId, out uce) && uce != null) + if(m_profilesCache.TryGetValue(targetId, out uce) && uce is not null) { - if(uce != null && uce.picksList != null) + if(uce.picksList is not null) { remoteClient.SendAvatarPicksReply(targetId, uce.picksList); return; @@ -917,15 +886,17 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles } } - string serverURI = string.Empty; - GetUserProfileServerURI(targetId, out serverURI); + GetUserProfileServerURI(targetId, out string serverURI); if(string.IsNullOrWhiteSpace(serverURI)) { remoteClient.SendAvatarPicksReply(targetId, picks); return; } - OSDMap parameters= new OSDMap() {{"creatorId", OSD.FromUUID(targetId)}}; + OSDMap parameters= new() + { + {"creatorId", OSD.FromUUID(targetId)} + }; OSD osdtmp = parameters; if(!rpc.JsonRpcRequest(ref osdtmp, "avatarpicksrequest", serverURI, UUID.Random().ToString())) { @@ -934,7 +905,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles } parameters = (OSDMap)osdtmp; - if(!parameters.TryGetValue("result", out osdtmp) || !(osdtmp is OSDArray)) + if(!parameters.TryGetValue("result", out osdtmp) || osdtmp is not OSDArray) { remoteClient.SendAvatarPicksReply(targetId, picks); return; @@ -951,7 +922,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles lock(m_profilesCache) { - if(!m_profilesCache.TryGetValue(targetId, out uce) || uce == null) + if(!m_profilesCache.TryGetValue(targetId, out uce) || uce is null) uce = new UserProfileCacheEntry(); uce.picksList = picks; @@ -975,12 +946,11 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles /// public void PickInfoRequest(Object sender, string method, List args) { - if (!(sender is IClientAPI)) + if (sender is not IClientAPI) return; - UserProfilePick pick = new UserProfilePick (); - UUID targetID; - if(!UUID.TryParse(args [0], out targetID)) + UserProfilePick pick = new(); + if(!UUID.TryParse(args [0], out UUID targetID)) return; pick.CreatorId = targetID; @@ -992,14 +962,13 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles UserProfileCacheEntry uce = null; lock(m_profilesCache) { - if(m_profilesCache.TryGetValue(targetID, out uce) && uce != null) + if(m_profilesCache.TryGetValue(targetID, out uce) && uce is not null) { - if(uce != null && uce.picks != null && uce.picks.ContainsKey(pick.PickId)) + if(uce.picks is not null && uce.picks.ContainsKey(pick.PickId)) { pick = uce.picks[pick.PickId]; - Vector3 gPos = new Vector3(Vector3.Zero); - Vector3.TryParse(pick.GlobalPos, out gPos); - remoteClient.SendPickInfoReply(pick.PickId,pick.CreatorId,pick.TopPick,pick.ParcelId,pick.Name, + if(Vector3.TryParse(pick.GlobalPos, out Vector3 gPos)) + remoteClient.SendPickInfoReply(pick.PickId,pick.CreatorId,pick.TopPick,pick.ParcelId,pick.Name, pick.Desc,pick.SnapshotId,pick.ParcelName,pick.OriginalName,pick.SimName, gPos,pick.SortOrder,pick.Enabled); return; @@ -1007,8 +976,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles } } - string serverURI = string.Empty; - bool foreign = GetUserProfileServerURI (targetID, out serverURI); + bool foreign = GetUserProfileServerURI (targetID, out string serverURI); if(string.IsNullOrWhiteSpace(serverURI)) { return; @@ -1023,8 +991,8 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles if(foreign) cacheForeignImage(targetID, pick.SnapshotId); - Vector3 globalPos = new Vector3(Vector3.Zero); - Vector3.TryParse(pick.GlobalPos, out globalPos); + if(!Vector3.TryParse(pick.GlobalPos, out Vector3 globalPos)) + return; if (m_thisGridInfo.IsLocalGrid(pick.Gatekeeper, true) == 0) { @@ -1032,17 +1000,14 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles string region = string.Format("{0} {1}",pick.Gatekeeper,pick.SimName); GridRegion target = Scene.GridService.GetRegionByName(Scene.RegionInfo.ScopeID, region); - if(target == null) + if(target is null) { // This is a unreachable region } else { // we have a proxy on map - ulong oriHandle; - uint oriX; - uint oriY; - if(Util.ParseFakeParcelID(pick.ParcelId, out oriHandle, out oriX, out oriY)) + if (Util.ParseFakeParcelID(pick.ParcelId, out ulong _, out uint oriX, out uint oriY)) { pick.ParcelId = Util.BuildFakeParcelID(target.RegionHandle, oriX, oriY); globalPos.X = target.RegionLocX + oriX; @@ -1071,10 +1036,9 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles lock(m_profilesCache) { - if(!m_profilesCache.TryGetValue(targetID, out uce) || uce == null) + if(!m_profilesCache.TryGetValue(targetID, out uce) || uce is null) uce = new UserProfileCacheEntry(); - if(uce.picks == null) - uce.picks = new Dictionary(); + uce.picks ??= new Dictionary(); uce.picks[pick.PickId] = pick; m_profilesCache.AddOrUpdate(targetID, uce, PROFILECACHEEXPIRE); @@ -1124,20 +1088,17 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles string serverURI = string.Empty; GetUserProfileServerURI(remoteClient.AgentId, out serverURI); if(string.IsNullOrWhiteSpace(serverURI)) - { return; - } ScenePresence p = FindPresence(remoteClient.AgentId); Vector3 avaPos = p.AbsolutePosition; // Getting the global position for the Avatar - Vector3 posGlobal = new Vector3(remoteClient.Scene.RegionInfo.WorldLocX + avaPos.X, - remoteClient.Scene.RegionInfo.WorldLocY + avaPos.Y, - avaPos.Z); + Vector3 posGlobal = new(remoteClient.Scene.RegionInfo.WorldLocX + avaPos.X, + remoteClient.Scene.RegionInfo.WorldLocY + avaPos.Y, + avaPos.Z); string landParcelName = "My Parcel"; -// UUID landParcelID = p.currentParcelUUID; // to locate parcels we use a fake id that encodes the region handle // since we do not have a global locator @@ -1145,11 +1106,10 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles UUID landParcelID = Util.BuildFakeParcelID(remoteClient.Scene.RegionInfo.RegionHandle, (uint)avaPos.X, (uint)avaPos.Y); ILandObject land = p.Scene.LandChannel.GetLandObject(avaPos.X, avaPos.Y); - if (land != null) + if (land is not null) { // If land found, use parcel uuid from here because the value from SP will be blank if the avatar hasnt moved landParcelName = land.LandData.Name; -// landParcelID = land.LandData.GlobalID; } else { @@ -1183,12 +1143,10 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles UserProfileCacheEntry uce = null; lock(m_profilesCache) { - if(!m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) || uce == null) + if(!m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) || uce is null) uce = new UserProfileCacheEntry(); - if(uce.picks == null) - uce.picks = new Dictionary(); - if(uce.picksList == null) - uce.picksList = new Dictionary(); + uce.picks ??= new Dictionary(); + uce.picksList ??= new Dictionary(); uce.picks[pick.PickId] = pick; uce.picksList[pick.PickId] = pick.Name; m_profilesCache.AddOrUpdate(remoteClient.AgentId, uce, PROFILECACHEEXPIRE); @@ -1212,15 +1170,13 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles /// public void PickDelete(IClientAPI remoteClient, UUID queryPickID) { - string serverURI = string.Empty; - GetUserProfileServerURI(remoteClient.AgentId, out serverURI); + GetUserProfileServerURI(remoteClient.AgentId, out string serverURI); if(string.IsNullOrWhiteSpace(serverURI)) { return; } - OSDMap parameters= new OSDMap(); - parameters.Add("pickId", OSD.FromUUID(queryPickID)); + OSDMap parameters = new() { { "pickId", OSD.FromUUID(queryPickID) } }; OSD Params = (OSD)parameters; if(!rpc.JsonRpcRequest(ref Params, "picks_delete", serverURI, UUID.Random().ToString())) { @@ -1232,16 +1188,16 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles UserProfileCacheEntry uce = null; lock(m_profilesCache) { - if(m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) && uce != null) + if(m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) && uce is not null) { if(uce.picks != null && uce.picks.ContainsKey(queryPickID)) uce.picks.Remove(queryPickID); - if(uce.picksList != null && uce.picksList.ContainsKey(queryPickID)) + if(uce.picksList is not null) uce.picksList.Remove(queryPickID); m_profilesCache.AddOrUpdate(remoteClient.AgentId, uce, PROFILECACHEEXPIRE); } } - if(uce != null && uce.picksList != null) + if(uce is not null && uce.picksList is not null) remoteClient.SendAvatarPicksReply(remoteClient.AgentId, uce.picksList); else remoteClient.SendAvatarPicksReply(remoteClient.AgentId, new Dictionary()); @@ -1263,19 +1219,17 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles /// public void NotesRequest(Object sender, string method, List args) { - UserProfileNotes note = new UserProfileNotes(); - - if (!(sender is IClientAPI)) + if (sender is not IClientAPI remoteClient) return; - if(!UUID.TryParse(args[0], out note.TargetId)) + UserProfileNotes note = new(); + + if (!UUID.TryParse(args[0], out note.TargetId)) return; - IClientAPI remoteClient = (IClientAPI)sender; note.UserId = remoteClient.AgentId; - string serverURI = string.Empty; - GetUserProfileServerURI(remoteClient.AgentId, out serverURI); + GetUserProfileServerURI(remoteClient.AgentId, out string serverURI); if(string.IsNullOrWhiteSpace(serverURI)) { remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes); @@ -1306,25 +1260,24 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles /// public void NotesUpdate(IClientAPI remoteClient, UUID queryTargetID, string queryNotes) { - if (queryTargetID == Constants.m_MrOpenSimID) + if (queryTargetID.Equals(Constants.m_MrOpenSimID)) return; ScenePresence p = FindPresence(queryTargetID); - if (p != null && p.IsNPC) + if (p is not null && p.IsNPC) { - remoteClient.SendAgentAlertMessage( - "Notes for NPCs not available", false); + remoteClient.SendAgentAlertMessage("Notes for NPCs not available", false); return; } - UserProfileNotes note = new UserProfileNotes(); + UserProfileNotes note = new() + { + UserId = remoteClient.AgentId, + TargetId = queryTargetID, + Notes = queryNotes + }; - note.UserId = remoteClient.AgentId; - note.TargetId = queryTargetID; - note.Notes = queryNotes; - - string serverURI = string.Empty; - GetUserProfileServerURI(remoteClient.AgentId, out serverURI); + GetUserProfileServerURI(remoteClient.AgentId, out string serverURI); if(string.IsNullOrWhiteSpace(serverURI)) return; @@ -1354,14 +1307,14 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles /// public void UpdateUserPreferences(bool imViaEmail, bool visible, IClientAPI remoteClient) { - UserPreferences pref = new UserPreferences(); + UserPreferences pref = new() + { + UserId = remoteClient.AgentId, + IMViaEmail = imViaEmail, + Visible = visible + }; - pref.UserId = remoteClient.AgentId; - pref.IMViaEmail = imViaEmail; - pref.Visible = visible; - - string serverURI = string.Empty; - bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI); + _ = GetUserProfileServerURI(remoteClient.AgentId, out string serverURI); if(string.IsNullOrWhiteSpace(serverURI)) return; @@ -1382,20 +1335,17 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles /// public void UserPreferencesRequest(IClientAPI remoteClient) { - UserPreferences pref = new UserPreferences(); - pref.UserId = remoteClient.AgentId; - - string serverURI = string.Empty; - bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI); + GetUserProfileServerURI(remoteClient.AgentId, out string serverURI); if(string.IsNullOrWhiteSpace(serverURI)) return; + UserPreferences pref = new() { UserId = remoteClient.AgentId }; object Pref = (object)pref; if(!rpc.JsonRpcRequest(ref Pref, "user_preferences_request", serverURI, UUID.Random().ToString())) { -// m_log.InfoFormat("[PROFILES]: UserPreferences request error"); -// remoteClient.SendAgentAlertMessage("Error requesting preferences", false); + //m_log.InfoFormat("[PROFILES]: UserPreferences request error"); + //remoteClient.SendAgentAlertMessage("Error requesting preferences", false); return; } pref = (UserPreferences) Pref; @@ -1445,15 +1395,14 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles if(!rpc.JsonRpcRequest(ref Param, "avatar_interests_update", serverURI, UUID.Random().ToString())) { - remoteClient.SendAgentAlertMessage( - "Error updating interests", false); + remoteClient.SendAgentAlertMessage("Error updating interests", false); return; } // flush cache lock(m_profilesCache) { - if(m_profilesCache.TryGetValue(remoteClient.AgentId, out UserProfileCacheEntry uce) && uce != null) + if(m_profilesCache.TryGetValue(remoteClient.AgentId, out UserProfileCacheEntry uce) && uce is not null) { uce.props = null; uce.ClientsWaitingProps = null; @@ -1481,7 +1430,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles return; } ScenePresence p = FindPresence(avatarID); - if (p != null && p.IsNPC) + if (p is not null && p.IsNPC) { remoteClient.SendAvatarProperties(avatarID, ((INPC)(p.ControllingClient)).profileAbout, ((INPC)(p.ControllingClient)).Born, Utils.StringToBytes("Non Player Character (NPC)"), "NPCs have no life", 0x10, @@ -1493,14 +1442,14 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles UserProfileProperties props; lock(m_profilesCache) { - if(m_profilesCache.TryGetValue(avatarID, out UserProfileCacheEntry uce) && uce != null) + if(m_profilesCache.TryGetValue(avatarID, out UserProfileCacheEntry uce) && uce is not null) { - if(uce.props != null) + if(uce.props is not null) { props = uce.props; uint cflags = uce.flags; // if on same region force online - if(p != null && !p.IsDeleted) + if(p is not null && !p.IsDeleted) cflags |= 0x10; remoteClient.SendAvatarProperties(props.UserId, props.AboutText, @@ -1510,7 +1459,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles remoteClient.SendAvatarInterestsReply(props.UserId, (uint)props.WantToMask, props.WantToText, (uint)props.SkillsMask, props.SkillsText, props.Language); - if(uce.avatarGroups != null) + if(uce.avatarGroups is not null) remoteClient.SendAvatarGroupsReply(avatarID, uce.avatarGroups); return; } @@ -1525,18 +1474,19 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles } else { - uce = new UserProfileCacheEntry(); - uce.ClientsWaitingProps = new HashSet(); + uce = new UserProfileCacheEntry { ClientsWaitingProps = new HashSet() }; uce.ClientsWaitingProps.Add(remoteClient); m_profilesCache.AddOrUpdate(avatarID, uce, PROFILECACHEEXPIRE); } } - AsyncPropsRequest req = new AsyncPropsRequest(); - req.client = remoteClient; - req.presence = p; - req.agent = avatarID; - req.reqtype = 0; + AsyncPropsRequest req = new() + { + client = remoteClient, + presence = p, + agent = avatarID, + reqtype = 0 + }; m_asyncRequests.Push(req); @@ -1686,7 +1636,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles // flush cache lock(m_profilesCache) { - if(m_profilesCache.TryGetValue(remoteClient.AgentId, out UserProfileCacheEntry uce) && uce != null) + if(m_profilesCache.TryGetValue(remoteClient.AgentId, out UserProfileCacheEntry uce) && uce is not null) { uce.props = null; uce.ClientsWaitingProps = null; @@ -1719,7 +1669,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles { try { - OpenProfileClient client = new OpenProfileClient(serverURI); + OpenProfileClient client = new(serverURI); if (client.RequestAvatarPropertiesUsingOpenProfile(ref properties)) secondChanceSuccess = true; } @@ -1779,7 +1729,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles // Is local IUserAccountService uas = Scene.UserAccountService; account = uas.GetUserAccount(Scene.RegionInfo.ScopeID, userID); - return account != null; + return account is not null; } else { @@ -1788,7 +1738,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles if (recentFailedWeb || String.IsNullOrEmpty(home_url)) return false; - UserAgentServiceConnector uConn = new UserAgentServiceConnector(home_url); + UserAgentServiceConnector uConn = new(home_url); Dictionary info; try @@ -1873,7 +1823,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles ScenePresence p; p = Scene.GetScenePresence(clientID); - if (p != null && !p.IsChildAgent) + if (p is not null && !p.IsChildAgent) return p; return null; @@ -1901,23 +1851,23 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles /// bool JsonRpcRequest(ref object parameters, string method, string uri, string jsonId) { - if (jsonId == null) - throw new ArgumentNullException ("jsonId"); - if (uri == null) - throw new ArgumentNullException ("uri"); - if (method == null) - throw new ArgumentNullException ("method"); - if (parameters == null) - throw new ArgumentNullException ("parameters"); + if (jsonId is null) + throw new ArgumentNullException(nameof(jsonId)); + if (uri is null) + throw new ArgumentNullException(nameof(uri)); + if (method is null) + throw new ArgumentNullException(nameof(method)); + if (parameters is null) + throw new ArgumentNullException(nameof(parameters)); // Prep our payload - OSDMap json = new OSDMap(); - - json.Add("jsonrpc", OSD.FromString("2.0")); - json.Add("id", OSD.FromString(jsonId)); - json.Add("method", OSD.FromString(method)); - - json.Add("params", OSD.SerializeMembers(parameters)); + OSDMap json = new() + { + { "jsonrpc", OSD.FromString("2.0") }, + { "id", OSD.FromString(jsonId) }, + { "method", OSD.FromString(method) }, + { "params", OSD.SerializeMembers(parameters) } + }; string jsonRequestData = OSDParser.SerializeJsonString(json); byte[] content = Encoding.UTF8.GetBytes(jsonRequestData); @@ -1927,7 +1877,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles webRequest.ContentType = "application/json-rpc"; webRequest.Method = "POST"; - WebResponse webResponse = null; + WebResponse webResponse; try { using(Stream dataStream = webRequest.GetRequestStream()) @@ -1942,7 +1892,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles return false; } - OSDMap mret = new OSDMap(); + OSDMap mret = new(); using (Stream rstream = webResponse.GetResponseStream()) { @@ -1953,14 +1903,12 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles catch (Exception e) { m_log.DebugFormat("[PROFILES]: JsonRpcRequest Error {0} - remote user with legacy profiles?", e.Message); - if (webResponse != null) - webResponse.Close(); + webResponse?.Close(); return false; } } - if (webResponse != null) - webResponse.Close(); + webResponse?.Close(); if (mret.ContainsKey("error")) return false; @@ -1990,17 +1938,17 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles /// bool JsonRpcRequest(ref OSD data, string method, string uri, string jsonId) { - OSDMap map = new OSDMap(); - - map["jsonrpc"] = "2.0"; - if(string.IsNullOrEmpty(jsonId)) + OSDMap map = new() + { + ["jsonrpc"] = "2.0", + ["method"] = method, + ["params"] = data + }; + if (string.IsNullOrEmpty(jsonId)) map["id"] = UUID.Random().ToString(); else map["id"] = jsonId; - map["method"] = method; - map["params"] = data; - string jsonRequestData = OSDParser.SerializeJsonString(map); byte[] content = Encoding.UTF8.GetBytes(jsonRequestData); @@ -2023,7 +1971,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles return false; } - OSDMap response = new OSDMap(); + OSDMap response = new(); using (Stream rstream = webResponse.GetResponseStream()) { @@ -2040,8 +1988,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles } } - if (webResponse != null) - webResponse.Close(); + webResponse?.Close(); if(response.ContainsKey("error")) { diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs index afb42311d5..4781ab0ced 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs @@ -844,9 +844,9 @@ namespace OpenSim.Region.CoreModules.World.Land else userflags = m_scene.GetUserFlags(avatar); - if(adults && ((userflags & 32) == 0)) + if(adults && ((userflags & (int)ProfileFlags.AgeVerified) == 0)) return true; - if(anonymous && ((userflags & 4) == 0)) + if(anonymous && ((userflags & (int)ProfileFlags.Identified) == 0)) return true; } return false; diff --git a/OpenSim/Services/Interfaces/IFriendsService.cs b/OpenSim/Services/Interfaces/IFriendsService.cs index d0d3b1002d..38cc7456c6 100644 --- a/OpenSim/Services/Interfaces/IFriendsService.cs +++ b/OpenSim/Services/Interfaces/IFriendsService.cs @@ -54,26 +54,29 @@ namespace OpenSim.Services.Interfaces public FriendInfo(Dictionary kvp) { PrincipalID = UUID.Zero; - if (kvp.ContainsKey("PrincipalID") && kvp["PrincipalID"] != null) - UUID.TryParse(kvp["PrincipalID"].ToString(), out PrincipalID); + object tmpo; + if (kvp.TryGetValue("PrincipalID", out tmpo) && tmpo is not null) + UUID.TryParse(tmpo.ToString(), out PrincipalID); Friend = string.Empty; - if (kvp.ContainsKey("Friend") && kvp["Friend"] != null) - Friend = kvp["Friend"].ToString(); + if (kvp.TryGetValue("Friend", out tmpo) && tmpo is not null) + Friend = tmpo.ToString(); MyFlags = (int)FriendRights.None; - if (kvp.ContainsKey("MyFlags") && kvp["MyFlags"] != null) - Int32.TryParse(kvp["MyFlags"].ToString(), out MyFlags); + if (kvp.TryGetValue("MyFlags", out tmpo) && tmpo is not null) + Int32.TryParse(tmpo.ToString(), out MyFlags); TheirFlags = 0; - if (kvp.ContainsKey("TheirFlags") && kvp["TheirFlags"] != null) - Int32.TryParse(kvp["TheirFlags"].ToString(), out TheirFlags); + if (kvp.TryGetValue("TheirFlags", out tmpo) && tmpo is not null) + Int32.TryParse(tmpo.ToString(), out TheirFlags); } public Dictionary ToKeyValuePairs() { - Dictionary result = new Dictionary(); - result["PrincipalID"] = PrincipalID.ToString(); - result["Friend"] = Friend; - result["MyFlags"] = MyFlags.ToString(); - result["TheirFlags"] = TheirFlags.ToString(); + Dictionary result = new() + { + ["PrincipalID"] = PrincipalID.ToString(), + ["Friend"] = Friend, + ["MyFlags"] = MyFlags.ToString(), + ["TheirFlags"] = TheirFlags.ToString() + }; return result; } diff --git a/OpenSim/Services/UserProfilesService/UserProfilesService.cs b/OpenSim/Services/UserProfilesService/UserProfilesService.cs index 76aa093c07..fa5ed18fdf 100644 --- a/OpenSim/Services/UserProfilesService/UserProfilesService.cs +++ b/OpenSim/Services/UserProfilesService/UserProfilesService.cs @@ -42,9 +42,7 @@ namespace OpenSim.Services.ProfilesService { public class UserProfilesService: UserProfilesServiceBase, IUserProfilesService { - static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); + static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); IUserAccountService userAccounts;