diff --git a/libsecondlife/EstateTools.cs b/libsecondlife/EstateTools.cs index ef024a56..882a358a 100644 --- a/libsecondlife/EstateTools.cs +++ b/libsecondlife/EstateTools.cs @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2008, Second Life Reverse Engineering Team + * Copyright (c) 2006-2007, Second Life Reverse Engineering Team * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -38,24 +38,60 @@ namespace libsecondlife public GroundTextureSettings GroundTextures; /// - /// Triggered on incoming LandStatReply when the report type is for "top colliders" + /// Triggered on LandStatReply when the report type is for "top colliders" /// /// /// public delegate void GetTopCollidersReply(int objectCount, List Tasks); + /// - /// Triggered on incoming LandStatReply when the report type is for "top scripts" + /// Triggered on LandStatReply when the report type is for "top scripts" /// /// /// public delegate void GetTopScriptsReply(int objectCount, List Tasks); - // Callback for incoming LandStatReply packets + /// + /// Triggered when the list of estate managers is received for the current estate + /// + /// + public delegate void EstateManagersReply(uint estateID, int count, List managers); + + /// + /// FIXME - Enumerate all params from EstateOwnerMessage packet + /// + /// + public delegate void EstateUpdateInfoReply(string estateName, LLUUID estateOwner, uint estateID, bool denyNoPaymentInfo); + + public delegate void EstateManagersListReply(uint estateID, List managers); + + public delegate void EstateBansReply(uint estateID, int count, List banned); + + public delegate void EstateUsersReply(uint estateID, int count, List allowedUsers); + + public delegate void EstateGroupsReply(uint estateID, int count, List allowedGroups); + + public delegate void EstateCovenantReply(LLUUID covenantID, long timestamp, string estateName, LLUUID estateOwnerID); + + + /// Callback for LandStatReply packets //public event LandStatReply OnLandStatReply; /// Triggered upon a successful .GetTopColliders() public event GetTopCollidersReply OnGetTopColliders; /// Triggered upon a successful .GetTopScripts() public event GetTopScriptsReply OnGetTopScripts; + /// Returned, along with other info, upon a successful .GetInfo() + public event EstateUpdateInfoReply OnGetEstateUpdateInfo; + /// Returned, along with other info, upon a successful .GetInfo() + public event EstateManagersReply OnGetEstateManagers; + /// Returned, along with other info, upon a successful .GetInfo() + public event EstateBansReply OnGetEstateBans; + /// Returned, along with other info, upon a successful .GetInfo() + public event EstateGroupsReply OnGetAllowedGroups; + /// Returned, along with other info, upon a successful .GetInfo() + public event EstateUsersReply OnGetAllowedUsers; + /// Triggered upon a successful .RequestCovenant() + public event EstateCovenantReply OnGetCovenant; /// /// Constructor for EstateTools class @@ -65,7 +101,8 @@ namespace libsecondlife { Client = client; Client.Network.RegisterCallback(PacketType.LandStatReply, new NetworkManager.PacketCallback(LandStatReplyHandler)); - //Client.Network.RegisterCallback(PacketType.EstateOwnerMessage, new NetworkManager.PacketCallback(EstateOwnerMessageHandler)); + Client.Network.RegisterCallback(PacketType.EstateOwnerMessage, new NetworkManager.PacketCallback(EstateOwnerMessageHandler)); + Client.Network.RegisterCallback(PacketType.EstateCovenantReply, new NetworkManager.PacketCallback(EstateCovenantReplyHandler)); } /// Describes tasks returned in LandStatReply @@ -93,6 +130,14 @@ namespace libsecondlife UnbanUser = 128 } + public enum EstateAccessReplyDelta : uint + { + AllowedUsers = 17, + AllowedGroups = 18, + EstateBans = 20, + EstateManagers = 24 + } + /// Used by GroundTextureSettings public class GroundTextureRegion { @@ -129,6 +174,12 @@ namespace libsecondlife Client.Network.SendPacket(p); } + /// Requests estate settings, including estate manager and access/ban lists + public void GetInfo() + { + EstateOwnerMessage("getinfo", new List()); + } + /// Requests the "Top Scripts" list for the current region public void GetTopScripts() { @@ -143,22 +194,183 @@ namespace libsecondlife LandStatRequest(0, LandStatReportType.TopColliders, 0, ""); } + private void EstateCovenantReplyHandler(Packet packet, Simulator simulator) + { + EstateCovenantReplyPacket reply = (EstateCovenantReplyPacket)packet; + if (OnGetCovenant != null) + { + try + { + OnGetCovenant( + reply.Data.CovenantID, + reply.Data.CovenantTimestamp, + Helpers.FieldToUTF8String(reply.Data.EstateName), + reply.Data.EstateOwnerID); + } + catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } + } + } + /// /// /// private void EstateOwnerMessageHandler(Packet packet, Simulator simulator) { EstateOwnerMessagePacket message = (EstateOwnerMessagePacket)packet; + uint estateID; string method = Helpers.FieldToUTF8String(message.MethodData.Method); - - //FIXME - remove debug output + List parameters = new List(); + + if (method == "estateupdateinfo") + { + string estateName = Helpers.FieldToUTF8String(message.ParamList[0].Parameter); + LLUUID estateOwner = new LLUUID(Helpers.FieldToUTF8String(message.ParamList[1].Parameter)); + estateID = Helpers.BytesToUInt(message.ParamList[2].Parameter); + /* + foreach (EstateOwnerMessagePacket.ParamListBlock param in message.ParamList) + { + parameters.Add(Helpers.FieldToUTF8String(param.Parameter)); + } + */ + bool denyNoPaymentInfo; + if (Helpers.BytesToUInt(message.ParamList[8].Parameter) == 0) denyNoPaymentInfo = true; + else denyNoPaymentInfo = false; + + if (OnGetEstateUpdateInfo != null) + { + try + { + OnGetEstateUpdateInfo(estateName, estateOwner, estateID, denyNoPaymentInfo); + } + catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } + } + } + + else if (method == "setaccess") + { + int count; + estateID = Helpers.BytesToUInt(message.ParamList[0].Parameter); + if (message.ParamList.Length > 1) + { + EstateAccessReplyDelta accessType = (EstateAccessReplyDelta)Helpers.BytesToUInt(message.ParamList[1].Parameter); + switch (accessType) + { + case EstateAccessReplyDelta.EstateManagers: + if (OnGetEstateManagers != null) + { + count = (int)Helpers.BytesToUInt(message.ParamList[3].Parameter); + List managers = new List(); + if (message.ParamList.Length > 5) + { + for (int i = 5; i < message.ParamList.Length; i++) + { + LLUUID managerID; + if (LLUUID.TryParse(Helpers.FieldToUTF8String(message.ParamList[i].Parameter), out managerID)) + { + managers.Add(managerID); + } + } + try { OnGetEstateManagers(estateID, count, managers); } + catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } + } + } + break; + + case EstateAccessReplyDelta.EstateBans: + if (OnGetEstateBans != null) + { + count = (int)Helpers.BytesToUInt(message.ParamList[4].Parameter); + List bannedUsers = new List(); + if (message.ParamList.Length > 5) + { + for (int i = 5; i < message.ParamList.Length; i++) + { + LLUUID bannedID; + if (LLUUID.TryParse(Helpers.FieldToUTF8String(message.ParamList[i].Parameter), out bannedID)) + { + bannedUsers.Add(bannedID); + } + } + try { OnGetEstateBans(estateID, count, bannedUsers); } + catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } + } + } + break; + + case EstateAccessReplyDelta.AllowedUsers: + if (OnGetAllowedUsers != null) + { + count = (int)Helpers.BytesToUInt(message.ParamList[2].Parameter); + List allowedUsers = new List(); + if (message.ParamList.Length > 5) + { + for (int i = 5; i < message.ParamList.Length; i++) + { + LLUUID userID; + if (LLUUID.TryParse(Helpers.FieldToUTF8String(message.ParamList[i].Parameter), out userID)) + { + allowedUsers.Add(userID); + } + } + try { OnGetAllowedUsers(estateID, count, allowedUsers); } + catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } + } + } + break; + + case EstateAccessReplyDelta.AllowedGroups: + if (OnGetAllowedGroups != null) + { + count = (int)Helpers.BytesToUInt(message.ParamList[3].Parameter); + List allowedGroups = new List(); + if (message.ParamList.Length > 5) + { + for (int i = 5; i < message.ParamList.Length; i++) + { + LLUUID groupID; + if (LLUUID.TryParse(Helpers.FieldToUTF8String(message.ParamList[i].Parameter), out groupID)) + { + allowedGroups.Add(groupID); + } + } + try { OnGetAllowedGroups(estateID, count, allowedGroups); } + catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } + } + } + break; + } + + if (accessType == EstateAccessReplyDelta.EstateManagers) + { + if (OnGetEstateManagers != null) + { + count = (int)Helpers.BytesToUInt(message.ParamList[5].Parameter); + List managers = new List(); + + for (int i = 5; i < message.ParamList.Length; i++) + { + LLUUID managerID; + if (LLUUID.TryParse(Helpers.FieldToUTF8String(message.ParamList[i].Parameter), out managerID)) + { + managers.Add(managerID); + } + } + try { OnGetEstateManagers(estateID, count, managers); } + catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } + } + } + + } + } + + /* Console.WriteLine("--- " + method + " ---"); foreach (EstateOwnerMessagePacket.ParamListBlock block in message.ParamList) { Console.WriteLine(Helpers.FieldToUTF8String(block.Parameter)); } Console.WriteLine("------"); - + */ } /// @@ -188,11 +400,13 @@ namespace libsecondlife if (OnGetTopScripts != null && type == LandStatReportType.TopScripts) { - OnGetTopScripts((int)p.RequestData.TotalObjectCount, Tasks); + try { OnGetTopScripts((int)p.RequestData.TotalObjectCount, Tasks); } + catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } else if (OnGetTopColliders != null && type == LandStatReportType.TopColliders) { - OnGetTopColliders((int)p.RequestData.TotalObjectCount, Tasks); + try { OnGetTopColliders((int)p.RequestData.TotalObjectCount, Tasks); } + catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } /* @@ -228,6 +442,7 @@ namespace libsecondlife EstateOwnerMessagePacket estate = new EstateOwnerMessagePacket(); estate.AgentData.AgentID = Client.Self.AgentID; estate.AgentData.SessionID = Client.Self.SessionID; + estate.AgentData.TransactionID = LLUUID.Zero; estate.MethodData.Invoice = LLUUID.Random(); estate.MethodData.Method = Helpers.StringToField(method); estate.ParamList = new EstateOwnerMessagePacket.ParamListBlock[listParams.Count]; @@ -265,7 +480,7 @@ namespace libsecondlife public void UnbanUser(LLUUID userID) { List listParams = new List(); - uint flag = (uint)EstateAccessDelta.BanUser; + uint flag = (uint)EstateAccessDelta.UnbanUser; listParams.Add(Client.Self.AgentID.ToString()); listParams.Add(flag.ToString()); listParams.Add(userID.ToString()); @@ -353,6 +568,14 @@ namespace libsecondlife EstateOwnerMessage("setregiondebug", listParams); } + public void RequestCovenant() + { + EstateCovenantRequestPacket req = new EstateCovenantRequestPacket(); + req.AgentData.AgentID = Client.Self.AgentID; + req.AgentData.SessionID = Client.Self.SessionID; + Client.Network.SendPacket(req); + } + } }