diff --git a/LibreMetaverse/ParcelManager.cs b/LibreMetaverse/ParcelManager.cs index 6e878fa..7fef2cf 100644 --- a/LibreMetaverse/ParcelManager.cs +++ b/LibreMetaverse/ParcelManager.cs @@ -617,18 +617,52 @@ namespace OpenMetaverse Update(client, client.Network.CurrentSim, wantReply); } + /// + /// UpdateParcelAccessList - Update the parcel access or ban list on the simulator + /// + /// The grid client we are using + /// what list to update sending AccessList.Both will result in a warning + /// list of avatar entry records public void UpdateParcelAccessList( GridClient Client, AccessList flags, List entries) { - if(Client == null) throw new InvalidOperationException("Client is null"); - if(Client.Network == null) throw new InvalidOperationException("Client.Network is null"); - if(Client.Network.CurrentSim == null) throw new InvalidOperationException("Client.Network.CurrentSim is null"); + // based on Alchemy Viewer's implementation + // might want to be cleaned up later + if (flags == AccessList.Both) + { + Logger.Log("Warning: UpdateParcelAccessList called with AccessList.Both, this is not supported. " + + "Use AccessList.Access or AccessList.Ban", Helpers.LogLevel.Warning); + return; + } + if (Client == null) + { + Logger.Log("Client is null", Helpers.LogLevel.Error); + return; + } + if (Client.Network == null) + { + Logger.Log("Client.Network is null", Helpers.LogLevel.Error); + return; + } + if (Client.Network.CurrentSim == null) + { + Logger.Log("Client.Network.CurrentSim is null", Helpers.LogLevel.Error); + return; + } Simulator simulator = Client.Network.CurrentSim; - if (simulator == null) throw new InvalidOperationException("No current simulator"); + if (Client.Network.CurrentSim == null) + { + Logger.Log("simulator is null", Helpers.LogLevel.Error); + return; + } int parcelLocalId = LocalID; - if (parcelLocalId == 0) throw new InvalidOperationException("Parcel LocalID is zero"); + if (parcelLocalId == 0) + { + Logger.Log("Parcel LocalID is zero", Helpers.LogLevel.Error); + return; + } if (entries.Count == 0) { // send an empty block to clear the list @@ -659,7 +693,7 @@ namespace OpenMetaverse return; } - const int PARCEL_MAX_ENTRIES_PER_PACKET = 48; // Set to your actual max + const int PARCEL_MAX_ENTRIES_PER_PACKET = 48; // ?? matching viewer's limit, but not documented anywhere int count = entries.Count; int numSections = (int)Math.Ceiling((double)count / PARCEL_MAX_ENTRIES_PER_PACKET); int sequenceId = 1; diff --git a/SecondBotEvents/Commands/ParcelCommands.cs b/SecondBotEvents/Commands/ParcelCommands.cs index 71eed35..6336035 100644 --- a/SecondBotEvents/Commands/ParcelCommands.cs +++ b/SecondBotEvents/Commands/ParcelCommands.cs @@ -591,15 +591,7 @@ namespace SecondBotEvents.Commands { return Failure("Invaild avatar", [avatar]); } - bool alreadyBanned = false; - foreach (ParcelAccessEntry E in targetparcel.AccessBlackList) - { - if (E.AgentID == avataruuid) - { - alreadyBanned = true; - break; - } - } + bool alreadyBanned = targetparcel.AccessBlackList.Any(e => e.AgentID == avataruuid); if (alreadyBanned == true) { return BasicReply("Avatar is in the blacklist", [avatar]); @@ -611,7 +603,7 @@ namespace SecondBotEvents.Commands Time = new System.DateTime(3030, 03, 03) }; targetparcel.AccessBlackList.Add(entry); - targetparcel.Update(GetClient()); + targetparcel.UpdateParcelAccessList(GetClient(), AccessList.Ban, targetparcel.AccessBlackList); return BasicReply("ok", [avatar]); } @@ -635,23 +627,18 @@ namespace SecondBotEvents.Commands { return Failure("Invaild avatar", [avatar]); } - bool alreadyBanned = false; - ParcelAccessEntry removeentry = new(); - foreach (ParcelAccessEntry E in targetparcel.AccessBlackList) - { - if (E.AgentID == avataruuid) - { - alreadyBanned = true; - removeentry = E; - break; - } - } + bool alreadyBanned = targetparcel.AccessBlackList.Any(e => e.AgentID == avataruuid); if (alreadyBanned == false) { return BasicReply("Avatar is already unbanned", [avatar]); } - targetparcel.AccessBlackList.Remove(removeentry); - targetparcel.Update(GetClient()); + // Find the entry to remove + var entryToRemove = targetparcel.AccessBlackList.FirstOrDefault(e => e.AgentID == avataruuid); + if (entryToRemove.AgentID != UUID.Zero) + { + targetparcel.AccessBlackList.Remove(entryToRemove); + } + targetparcel.UpdateParcelAccessList(GetClient(), AccessList.Ban, targetparcel.AccessBlackList); return BasicReply("ok", [avatar]); }