123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301 |
- /*
- * Copyright (c) Contributors, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the OpenSim Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- using System;
- using System.Collections.Generic;
- using System.Reflection;
- using System.Text;
- using System.Timers;
- using libsecondlife;
- using libsecondlife.Packets;
- using log4net;
- using OpenSim.Framework;
- using OpenSim.Framework.Communications.Cache;
- using OpenSim.Region.Environment.Interfaces;
- namespace OpenSim.Region.Environment.Scenes
- {
- class DeleteToInventoryHolder
- {
- public DeRezObjectPacket DeRezPacket;
- public EntityBase selectedEnt;
- public IClientAPI remoteClient;
- public SceneObjectGroup objectGroup;
- public LLUUID folderID;
- public bool permissionToDelete;
- }
- public partial class Scene
- {
- private Timer m_inventoryTicker;
- private readonly Queue<DeleteToInventoryHolder> m_inventoryDeletes = new Queue<DeleteToInventoryHolder>();
- private static readonly ILog m_log
- = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- /// <summary>
- /// Start all the scripts in the scene which should be started.
- /// </summary>
- public void CreateScriptInstances()
- {
- m_log.Info("[PRIM INVENTORY]: Starting scripts in scene");
- foreach (EntityBase group in Entities.Values)
- {
- if (group is SceneObjectGroup)
- {
- ((SceneObjectGroup) group).CreateScriptInstances(0, false);
- }
- }
- }
- public void AddUploadedInventoryItem(LLUUID agentID, InventoryItemBase item)
- {
- IMoneyModule money=RequestModuleInterface<IMoneyModule>();
- if (money != null)
- {
- money.ApplyUploadCharge(agentID);
- }
- AddInventoryItem(agentID, item);
- }
- public bool AddInventoryItemReturned(LLUUID AgentId, InventoryItemBase item)
- {
- CachedUserInfo userInfo
- = CommsManager.UserProfileCacheService.GetUserDetails(AgentId);
- if (userInfo != null)
- {
- userInfo.AddItem(item);
- return true;
- }
- else
- {
- m_log.ErrorFormat(
- "[AGENT INVENTORY]: Agent was not found for add of item {1} {2}", item.Name, item.ID);
- return false;
- }
- }
- public void AddInventoryItem(LLUUID AgentID, InventoryItemBase item)
- {
- CachedUserInfo userInfo
- = CommsManager.UserProfileCacheService.GetUserDetails(AgentID);
- if (userInfo != null)
- {
- userInfo.AddItem(item);
- int userlevel = 0;
- if (ExternalChecks.ExternalChecksCanBeGodLike(AgentID))
- {
- userlevel = 1;
- }
- if (m_regInfo.MasterAvatarAssignedUUID == AgentID)
- {
- userlevel = 2;
- }
- EventManager.TriggerOnNewInventoryItemUploadComplete(AgentID, item.AssetID, item.Name, userlevel);
- }
- else
- {
- m_log.ErrorFormat(
- "[AGENT INVENTORY]: Agent {1} was not found for add of item {2} {3}",
- AgentID, item.Name, item.ID);
- return;
- }
- }
- /// <summary>
- /// Add an inventory item to an avatar's inventory.
- /// </summary>
- /// <param name="remoteClient">The remote client controlling the avatar</param>
- /// <param name="item">The item. This structure contains all the item metadata, including the folder
- /// in which the item is to be placed.</param>
- public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item)
- {
- CachedUserInfo userInfo
- = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
- if (userInfo != null)
- {
- AddInventoryItem(remoteClient.AgentId, item);
- remoteClient.SendInventoryItemCreateUpdate(item);
- }
- }
- /// <summary>
- /// Capability originating call to update the asset of an item in an agent's inventory
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="itemID"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- public LLUUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID itemID, byte[] data)
- {
- CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
- if (userInfo != null)
- {
- if (userInfo.RootFolder != null)
- {
- InventoryItemBase item = userInfo.RootFolder.FindItem(itemID);
- if (item != null)
- {
- AssetBase asset =
- CreateAsset(item.Name, item.Description, (sbyte)item.AssetType, data);
- AssetCache.AddAsset(asset);
- item.AssetID = asset.FullID;
- userInfo.UpdateItem(item);
- // remoteClient.SendInventoryItemCreateUpdate(item);
- if ((InventoryType) item.InvType == InventoryType.Notecard)
- {
- //do we want to know about updated note cards?
- }
- else if ((InventoryType) item.InvType == InventoryType.LSL)
- {
- // do we want to know about updated scripts
- }
- return (asset.FullID);
- }
- }
- }
- return LLUUID.Zero;
- }
- /// <summary>
- /// <see>CapsUpdatedInventoryItemAsset(IClientAPI, LLUUID, byte[])</see>
- /// </summary>
- private LLUUID CapsUpdateInventoryItemAsset(LLUUID avatarId, LLUUID itemID, byte[] data)
- {
- ScenePresence avatar;
- if (TryGetAvatar(avatarId, out avatar))
- {
- return CapsUpdateInventoryItemAsset(avatar.ControllingClient, itemID, data);
- }
- else
- {
- m_log.ErrorFormat(
- "[AGENT INVENTORY]: " +
- "Avatar {0} cannot be found to update its inventory item asset",
- avatarId);
- }
- return LLUUID.Zero;
- }
- /// <summary>
- /// Capability originating call to update the asset of a script in a prim's (task's) inventory
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="itemID"></param>
- /// <param name="primID">The prim which contains the item to update</param>
- /// <param name="isScriptRunning">Indicates whether the script to update is currently running</param>
- /// <param name="data"></param>
- public void CapsUpdateTaskInventoryScriptAsset(IClientAPI remoteClient, LLUUID itemId,
- LLUUID primId, bool isScriptRunning, byte[] data)
- {
- // Retrieve group
- SceneObjectPart part = GetSceneObjectPart(primId);
- SceneObjectGroup group = part.ParentGroup;
- if (null == group)
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: " +
- "Prim inventory update requested for item ID {0} in prim ID {1} but this prim does not exist",
- itemId, primId);
- return;
- }
- // Retrieve item
- TaskInventoryItem item = group.GetInventoryItem(part.LocalId, itemId);
-
- if (null == item)
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for caps script update "
- + " but the item does not exist in this inventory",
- itemId, part.Name, part.UUID);
- return;
- }
- AssetBase asset = CreateAsset(item.Name, item.Description, (sbyte)AssetType.LSLText, data);
- AssetCache.AddAsset(asset);
- if (isScriptRunning)
- {
- part.RemoveScriptInstance(item.ItemID);
- }
- // Update item with new asset
- item.AssetID = asset.FullID;
- group.UpdateInventoryItem(item);
- part.GetProperties(remoteClient);
- // Trigger rerunning of script (use TriggerRezScript event, see RezScript)
- if (isScriptRunning)
- {
- part.CreateScriptInstance(item.ItemID, 0, false);
- }
- }
- /// <summary>
- /// <see>CapsUpdateTaskInventoryScriptAsset(IClientAPI, LLUUID, LLUUID, bool, byte[])</see>
- /// </summary>
- private void CapsUpdateTaskInventoryScriptAsset(LLUUID avatarId, LLUUID itemId,
- LLUUID primId, bool isScriptRunning, byte[] data)
- {
- ScenePresence avatar;
- if (TryGetAvatar(avatarId, out avatar))
- {
- CapsUpdateTaskInventoryScriptAsset(
- avatar.ControllingClient, itemId, primId, isScriptRunning, data);
- }
- else
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: " +
- "Avatar {0} cannot be found to update its prim item asset",
- avatarId);
- }
- }
- /// <summary>
- /// Update an item which is either already in the client's inventory or is within
- /// a transaction
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="transactionID">The transaction ID. If this is LLUUID.Zero we will
- /// assume that we are not in a transaction</param>
- /// <param name="itemID">The ID of the updated item</param>
- /// <param name="name">The name of the updated item</param>
- /// <param name="description">The description of the updated item</param>
- /// <param name="nextOwnerMask">The permissions of the updated item</param>
- /* public void UpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID transactionID,
- LLUUID itemID, string name, string description,
- uint nextOwnerMask)*/
- public void UpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID transactionID,
- LLUUID itemID, InventoryItemBase itemUpd)
- {
- CachedUserInfo userInfo
- = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
- if (userInfo != null && userInfo.RootFolder != null)
- {
- InventoryItemBase item = userInfo.RootFolder.FindItem(itemID);
- if (item != null)
- {
- if (LLUUID.Zero == transactionID)
- {
- item.Name = itemUpd.Name;
- item.Description = itemUpd.Description;
- item.NextPermissions = itemUpd.NextPermissions;
- item.CurrentPermissions |= 8; // Slam!
- item.EveryOnePermissions = itemUpd.EveryOnePermissions;
- // TODO: Requires sanity checks
- //item.GroupID = itemUpd.GroupID;
- //item.GroupOwned = itemUpd.GroupOwned;
- //item.CreationDate = itemUpd.CreationDate;
- // The client sends zero if its newly created?
- if (itemUpd.CreationDate == 0)
- item.CreationDate = Util.UnixTimeSinceEpoch();
- else
- item.CreationDate = itemUpd.CreationDate;
-
- // TODO: Check if folder changed and move item
- //item.NextPermissions = itemUpd.Folder;
- item.InvType = itemUpd.InvType;
- item.SalePrice = itemUpd.SalePrice;
- item.SaleType = itemUpd.SaleType;
- item.Flags = itemUpd.Flags;
- userInfo.UpdateItem(item);
- }
- else
- {
- IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
- if (agentTransactions != null)
- {
- agentTransactions.HandleItemUpdateFromTransaction(
- remoteClient, transactionID, item);
- }
- }
- }
- else
- {
- m_log.Error(
- "[AGENTINVENTORY]: Item ID " + itemID + " not found for an inventory item update.");
- }
- }
- else
- {
- m_log.Error(
- "[AGENT INVENTORY]: Agent ID " + remoteClient.AgentId + " not found for an inventory item update.");
- }
- }
- /// <summary>
- /// Give an inventory item from one avatar to another
- /// </summary>
- /// <param name="recipientClient"></param>
- /// <param name="senderId">ID of the sender of the item</param>
- /// <param name="itemId"></param>
- public void GiveInventoryItem(IClientAPI recipientClient, LLUUID senderId, LLUUID itemId)
- {
- // Retrieve the item from the sender
- CachedUserInfo senderUserInfo = CommsManager.UserProfileCacheService.GetUserDetails(senderId);
- if (senderUserInfo == null)
- {
- m_log.ErrorFormat(
- "[AGENT INVENTORY]: Failed to find sending user {0} for item {1}", senderId, itemId);
- return;
- }
- if (senderUserInfo.RootFolder != null)
- {
- InventoryItemBase item = senderUserInfo.RootFolder.FindItem(itemId);
- if (item != null)
- {
- if (!ExternalChecks.ExternalChecksBypassPermissions())
- {
- if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
- return;
- }
- // TODO get recipient's root folder
- CachedUserInfo recipientUserInfo
- = CommsManager.UserProfileCacheService.GetUserDetails(recipientClient.AgentId);
- if (recipientUserInfo != null)
- {
- // Insert a copy of the item into the recipient
- InventoryItemBase itemCopy = new InventoryItemBase();
- itemCopy.Owner = recipientClient.AgentId;
- itemCopy.Creator = senderId;
- itemCopy.ID = LLUUID.Random();
- itemCopy.AssetID = item.AssetID;
- itemCopy.Description = item.Description;
- itemCopy.Name = item.Name;
- itemCopy.AssetType = item.AssetType;
- itemCopy.InvType = item.InvType;
- itemCopy.Folder = LLUUID.Zero;
- if (ExternalChecks.ExternalChecksPropagatePermissions())
- {
- if (item.InvType == 6)
- {
- itemCopy.BasePermissions &= ~(uint)(PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer);
- itemCopy.BasePermissions |= (item.CurrentPermissions & 7) << 13;
- }
- else
- {
- Console.WriteLine("Non-Prim item ==>");
- itemCopy.BasePermissions = item.BasePermissions & item.NextPermissions;
- }
- itemCopy.CurrentPermissions = itemCopy.BasePermissions;
- if ((item.CurrentPermissions & 8) != 0) // Propagate slam bit
- {
- itemCopy.CurrentPermissions = item.NextPermissions;
- itemCopy.BasePermissions=itemCopy.CurrentPermissions;
- itemCopy.CurrentPermissions |= 8;
- }
- itemCopy.NextPermissions = item.NextPermissions;
- itemCopy.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions;
- }
- else
- {
- itemCopy.CurrentPermissions = item.CurrentPermissions;
- itemCopy.NextPermissions = item.NextPermissions;
- itemCopy.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions;
- itemCopy.BasePermissions = item.BasePermissions;
- }
- itemCopy.GroupID = item.GroupID;
- itemCopy.GroupOwned = item.GroupOwned;
- itemCopy.Flags = item.Flags;
- itemCopy.SalePrice = item.SalePrice;
- itemCopy.SaleType = item.SaleType;
- itemCopy.CreationDate = item.CreationDate;
- recipientUserInfo.AddItem(itemCopy);
- if (!ExternalChecks.ExternalChecksBypassPermissions())
- {
- if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
- senderUserInfo.DeleteItem(itemId);
- }
- // Let the recipient client know about this new item
- recipientClient.SendBulkUpdateInventory(itemCopy);
- }
- else
- {
- m_log.ErrorFormat(
- "[AGENT INVENTORY]: Could not find userinfo for recipient user {0}, {1} of item {2}, {3} from {4}",
- recipientClient.Name, recipientClient.AgentId, item.Name,
- item.ID, senderId);
- }
- }
- else
- {
- m_log.ErrorFormat(
- "[AGENT INVENTORY]: Failed to find item {0} to give to {1}", itemId, senderId);
- return;
- }
- }
- else
- {
- m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemId.ToString() + ", no root folder");
- return;
- }
- }
- public void CopyInventoryItem(IClientAPI remoteClient, uint callbackID, LLUUID oldAgentID, LLUUID oldItemID,
- LLUUID newFolderID, string newName)
- {
- m_log.DebugFormat(
- "[AGENT INVENTORY]: CopyInventoryItem received by {0} with oldAgentID {1}, oldItemID {2}, new FolderID {3}, newName {4}",
- remoteClient.AgentId, oldAgentID, oldItemID, newFolderID, newName);
- InventoryItemBase item = CommsManager.UserProfileCacheService.libraryRoot.FindItem(oldItemID);
- if (item == null)
- {
- CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(oldAgentID);
- if (userInfo == null)
- {
- m_log.Error("[AGENT INVENTORY]: Failed to find user " + oldAgentID.ToString());
- return;
- }
- if (userInfo.RootFolder != null)
- {
- item = userInfo.RootFolder.FindItem(oldItemID);
- if (item == null)
- {
- m_log.Error("[AGENT INVENTORY]: Failed to find item " + oldItemID.ToString());
- return;
- }
- }
- else
- {
- m_log.Error("[AGENT INVENTORY]: Failed to find item " + oldItemID.ToString());
- return;
- }
- }
- AssetBase asset
- = AssetCache.GetAsset(
- item.AssetID, (item.AssetType == (int)AssetType.Texture ? true : false));
- if (asset != null)
- {
- if (newName != String.Empty)
- {
- asset.Name = newName;
- }
- if (remoteClient.AgentId == oldAgentID)
- {
- CreateNewInventoryItem(
- remoteClient, newFolderID, item.Name, item.Flags, callbackID, asset, (sbyte)item.InvType,
- item.BasePermissions, item.CurrentPermissions, item.EveryOnePermissions, item.NextPermissions, Util.UnixTimeSinceEpoch());
- }
- else
- {
- CreateNewInventoryItem(
- remoteClient, newFolderID, item.Name, item.Flags, callbackID, asset, (sbyte)item.InvType,
- item.NextPermissions, item.NextPermissions, item.EveryOnePermissions & item.NextPermissions, item.NextPermissions, Util.UnixTimeSinceEpoch());
- }
- }
- else
- {
- m_log.ErrorFormat(
- "[AGENT INVENTORY]: Could not copy item {0} since asset {1} could not be found",
- item.Name, item.AssetID);
- }
- }
- /// <summary>
- /// Create a new asset data structure.
- /// </summary>
- /// <param name="name"></param>
- /// <param name="description"></param>
- /// <param name="invType"></param>
- /// <param name="assetType"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- private AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data)
- {
- AssetBase asset = new AssetBase();
- asset.Name = name;
- asset.Description = description;
- asset.Type = assetType;
- asset.FullID = LLUUID.Random();
- asset.Data = (data == null) ? new byte[1] : data;
-
- return asset;
- }
- /// <summary>
- /// Move an item within the agent's inventory.
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="folderID"></param>
- /// <param name="itemID"></param>
- /// <param name="length"></param>
- /// <param name="newName"></param>
- public void MoveInventoryItem(IClientAPI remoteClient, LLUUID folderID, LLUUID itemID, int length,
- string newName)
- {
- m_log.DebugFormat(
- "[AGENT INVENTORY]: Moving item {0} to {1} for {2}", itemID, folderID, remoteClient.AgentId);
- CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
- if (userInfo == null)
- {
- m_log.Error("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString());
- return;
- }
- if (userInfo.RootFolder != null)
- {
- InventoryItemBase item = userInfo.RootFolder.FindItem(itemID);
- if (item != null)
- {
- if (newName != String.Empty)
- {
- item.Name = newName;
- }
- item.Folder = folderID;
- userInfo.DeleteItem(item.ID);
- AddInventoryItem(remoteClient, item);
- }
- else
- {
- m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemID.ToString());
- return;
- }
- }
- else
- {
- m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemID.ToString() + ", no root folder");
- return;
- }
- }
- /// <summary>
- /// Create a new inventory item.
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="folderID"></param>
- /// <param name="callbackID"></param>
- /// <param name="asset"></param>
- /// <param name="invType"></param>
- /// <param name="nextOwnerMask"></param>
- private void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID folderID, string name, uint flags, uint callbackID,
- AssetBase asset, sbyte invType, uint nextOwnerMask, int creationDate)
- {
- CreateNewInventoryItem(
- remoteClient, folderID, name, flags, callbackID, asset, invType,
- (uint)PermissionMask.All, (uint)PermissionMask.All, 0, nextOwnerMask, creationDate);
- }
- /// <summary>
- /// Create a new Inventory Item
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="folderID"></param>
- /// <param name="callbackID"></param>
- /// <param name="asset"></param>
- /// <param name="invType"></param>
- /// <param name="nextOwnerMask"></param>
- /// <param name="creationDate"></param>
- private void CreateNewInventoryItem(
- IClientAPI remoteClient, LLUUID folderID, string name, uint flags, uint callbackID, AssetBase asset, sbyte invType,
- uint baseMask, uint currentMask, uint everyoneMask, uint nextOwnerMask, int creationDate)
- {
- CachedUserInfo userInfo
- = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
- if (userInfo != null)
- {
- InventoryItemBase item = new InventoryItemBase();
- item.Owner = remoteClient.AgentId;
- item.Creator = remoteClient.AgentId;
- item.ID = LLUUID.Random();
- item.AssetID = asset.FullID;
- item.Description = asset.Description;
- item.Name = name;
- item.Flags = flags;
- item.AssetType = asset.Type;
- item.InvType = invType;
- item.Folder = folderID;
- item.CurrentPermissions = currentMask;
- item.NextPermissions = nextOwnerMask;
- item.EveryOnePermissions = everyoneMask;
- item.BasePermissions = baseMask;
- item.CreationDate = creationDate;
- userInfo.AddItem(item);
- remoteClient.SendInventoryItemCreateUpdate(item);
- }
- else
- {
- m_log.WarnFormat(
- "No user details associated with client {0} uuid {1} in CreateNewInventoryItem!",
- remoteClient.Name, remoteClient.AgentId);
- }
- }
- /// <summary>
- /// Create a new inventory item. Called when the client creates a new item directly within their
- /// inventory (e.g. by selecting a context inventory menu option).
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="transactionID"></param>
- /// <param name="folderID"></param>
- /// <param name="callbackID"></param>
- /// <param name="description"></param>
- /// <param name="name"></param>
- /// <param name="invType"></param>
- /// <param name="type"></param>
- /// <param name="wearableType"></param>
- /// <param name="nextOwnerMask"></param>
- public void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
- uint callbackID, string description, string name, sbyte invType,
- sbyte assetType,
- byte wearableType, uint nextOwnerMask, int creationDate)
- {
- // m_log.DebugFormat("[AGENT INVENTORY]: Received request to create inventory item {0} in folder {1}", name, folderID);
- if (transactionID == LLUUID.Zero)
- {
- CachedUserInfo userInfo
- = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
- if (userInfo != null)
- {
- ScenePresence presence;
- TryGetAvatar(remoteClient.AgentId, out presence);
- byte[] data = null;
- if (invType == 3 && presence != null) // libsecondlife.asset.assettype.landmark = 3 - needs to be turned into an enum
- {
- LLVector3 pos=presence.AbsolutePosition;
- string strdata=String.Format("Landmark version 2\nregion_id {0}\nlocal_pos {1} {2} {3}\nregion_handle {4}\n",
- presence.Scene.RegionInfo.RegionID,
- pos.X, pos.Y, pos.Z,
- presence.RegionHandle);
- data=Encoding.ASCII.GetBytes(strdata);
- }
- AssetBase asset = CreateAsset(name, description, assetType, data);
- AssetCache.AddAsset(asset);
- CreateNewInventoryItem(remoteClient, folderID, asset.Name, 0, callbackID, asset, invType, nextOwnerMask, creationDate);
- }
- else
- {
- m_log.ErrorFormat(
- "userInfo for agent uuid {0} unexpectedly null in CreateNewInventoryItem",
- remoteClient.AgentId);
- }
- }
- else
- {
- IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
- if (agentTransactions != null)
- {
- agentTransactions.HandleItemCreationFromTransaction(
- remoteClient, transactionID, folderID, callbackID, description,
- name, invType, assetType, wearableType, nextOwnerMask);
- }
- }
- }
- /// <summary>
- /// Remove an inventory item for the client's inventory
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="itemID"></param>
- private void RemoveInventoryItem(IClientAPI remoteClient, LLUUID itemID)
- {
- CachedUserInfo userInfo
- = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
- if (userInfo == null)
- {
- m_log.WarnFormat(
- "[AGENT INVENTORY]: Failed to find user {0} {1} to delete inventory item {2}",
- remoteClient.Name, remoteClient.AgentId, itemID);
- return;
- }
- userInfo.DeleteItem(itemID);
- }
- /// <summary>
- /// Removes an inventory folder. Although there is a packet in the Linden protocol for this, it may be
- /// legacy and not currently used (purge folder is used to remove folders from trash instead).
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="folderID"></param>
- private void RemoveInventoryFolder(IClientAPI remoteClient, LLUUID folderID)
- {
- CachedUserInfo userInfo
- = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
- if (userInfo == null)
- {
- m_log.Warn("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString());
- return;
- }
- if (userInfo.RootFolder != null)
- {
- InventoryItemBase folder = userInfo.RootFolder.FindItem(folderID);
- if (folder != null)
- {
- m_log.WarnFormat(
- "[AGENT INVENTORY]: Remove folder not implemented in request by {0} {1} for {2}",
- remoteClient.Name, remoteClient.AgentId, folderID);
- // doesn't work just yet, commented out. will fix in next patch.
- // userInfo.DeleteItem(folder);
- }
- }
- }
- private SceneObjectGroup GetGroupByPrim(uint localID)
- {
- List<EntityBase> EntityList = GetEntities();
- foreach (EntityBase ent in EntityList)
- {
- if (ent is SceneObjectGroup)
- {
- if (((SceneObjectGroup) ent).HasChildPrim(localID))
- return (SceneObjectGroup) ent;
- }
- }
- return null;
- }
- /// <summary>
- /// Send the details of a prim's inventory to the client.
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="primLocalID"></param>
- public void RequestTaskInventory(IClientAPI remoteClient, uint primLocalID)
- {
- SceneObjectGroup group = GetGroupByPrim(primLocalID);
- if (group != null)
- {
- bool fileChange = group.GetPartInventoryFileName(remoteClient, primLocalID);
- if (fileChange)
- {
- if (XferManager != null)
- {
- group.RequestInventoryFile(remoteClient, primLocalID, XferManager);
- }
- }
- }
- else
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: Inventory requested of prim {0} which doesn't exist", primLocalID);
- }
- }
- /// <summary>
- /// Remove an item from a prim (task) inventory
- /// </summary>
- /// <param name="remoteClient">Unused at the moment but retained since the avatar ID might
- /// be necessary for a permissions check at some stage.</param>
- /// <param name="itemID"></param>
- /// <param name="localID"></param>
- public void RemoveTaskInventory(IClientAPI remoteClient, LLUUID itemID, uint localID)
- {
- SceneObjectPart part = GetSceneObjectPart(localID);
- SceneObjectGroup group = part.ParentGroup;
- if (group != null)
- {
- int type = group.RemoveInventoryItem(localID, itemID);
- part.GetProperties(remoteClient);
- if (type == 10)
- {
- EventManager.TriggerRemoveScript(localID, itemID);
- }
- }
- else
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: " +
- "Removal of item {0} requested of prim {1} but this prim does not exist",
- itemID,
- localID);
- }
- }
- private InventoryItemBase CreateAgentInventoryItemFromTask(LLUUID destAgent, SceneObjectPart part, LLUUID itemId)
- {
- TaskInventoryItem taskItem = part.GetInventoryItem(itemId);
- if (null == taskItem)
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for creating an avatar"
- + " inventory item from a prim's inventory item "
- + " but the required item does not exist in the prim's inventory",
- itemId, part.Name, part.UUID);
- return null;
- }
- InventoryItemBase agentItem = new InventoryItemBase();
- agentItem.ID = LLUUID.Random();
- agentItem.Creator = taskItem.CreatorID;
- agentItem.Owner = destAgent;
- agentItem.AssetID = taskItem.AssetID;
- agentItem.Description = taskItem.Description;
- agentItem.Name = taskItem.Name;
- agentItem.AssetType = taskItem.Type;
- agentItem.InvType = taskItem.InvType;
- agentItem.Flags = taskItem.Flags;
- if ((destAgent != taskItem.OwnerID) && ExternalChecks.ExternalChecksPropagatePermissions())
- {
- agentItem.BasePermissions = taskItem.NextOwnerMask;
- agentItem.CurrentPermissions = taskItem.NextOwnerMask;
- agentItem.NextPermissions = taskItem.NextOwnerMask;
- agentItem.EveryOnePermissions = taskItem.EveryoneMask & taskItem.NextOwnerMask;
- }
- else
- {
- agentItem.BasePermissions = taskItem.BaseMask;
- agentItem.CurrentPermissions = taskItem.OwnerMask;
- agentItem.NextPermissions = taskItem.NextOwnerMask;
- agentItem.EveryOnePermissions = taskItem.EveryoneMask;
- }
- if (!ExternalChecks.ExternalChecksBypassPermissions())
- {
- if ((taskItem.OwnerMask & (uint)PermissionMask.Copy) == 0)
- part.RemoveInventoryItem(itemId);
- }
- return agentItem;
- }
- /// <summary>
- /// Move the given item in the given prim to a folder in the client's inventory
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="folderID"></param>
- /// <param name="part"></param>
- /// <param name="itemID"></param>
- public void MoveTaskInventoryItem(IClientAPI remoteClient, LLUUID folderId, SceneObjectPart part, LLUUID itemId)
- {
- InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(remoteClient.AgentId, part, itemId);
- agentItem.Folder = folderId;
- AddInventoryItem(remoteClient, agentItem);
- }
-
- /// <summary>
- /// <see>ClientMoveTaskInventoryItem</see>
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="folderID"></param>
- /// <param name="primLocalID"></param>
- /// <param name="itemID"></param>
- public void ClientMoveTaskInventoryItem(IClientAPI remoteClient, LLUUID folderId, uint primLocalId, LLUUID itemId)
- {
- SceneObjectPart part = GetSceneObjectPart(primLocalId);
- if (null == part)
- {
- m_log.WarnFormat(
- "[PRIM INVENTORY]: " +
- "Move of inventory item {0} from prim with local id {1} failed because the prim could not be found",
- itemId, primLocalId);
- return;
- }
- TaskInventoryItem taskItem = part.GetInventoryItem(itemId);
-
- if (null == taskItem)
- {
- m_log.WarnFormat("[PRIM INVENTORY]: Move of inventory item {0} from prim with local id {1} failed"
- + " because the inventory item could not be found",
- itemId, primLocalId);
-
- return;
- }
- // Only owner can copy
- if (remoteClient.AgentId != taskItem.OwnerID)
- return;
- MoveTaskInventoryItem(remoteClient, folderId, part, itemId);
- }
-
- /// <summary>
- /// <see>MoveTaskInventoryItem</see>
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="folderID"></param>
- /// <param name="part"></param>
- /// <param name="itemID"></param>
- public void MoveTaskInventoryItem(LLUUID avatarId, LLUUID folderId, SceneObjectPart part, LLUUID itemId)
- {
- ScenePresence avatar;
- if (TryGetAvatar(avatarId, out avatar))
- {
- MoveTaskInventoryItem(avatar.ControllingClient, folderId, part, itemId);
- }
- else
- {
- CachedUserInfo profile = CommsManager.UserProfileCacheService.GetUserDetails(avatarId);
- if (profile == null || profile.RootFolder == null)
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: " +
- "Avatar {0} cannot be found to add item",
- avatarId);
- }
- InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(avatarId, part, itemId);
- agentItem.Folder = folderId;
- AddInventoryItem(avatarId, agentItem);
- }
- }
-
- /// <summary>
- /// Copy a task (prim) inventory item to another task (prim)
- /// </summary>
- /// <param name="destId"></param>
- /// <param name="part"></param>
- /// <param name="itemId"></param>
- public void MoveTaskInventoryItem(LLUUID destId, SceneObjectPart part, LLUUID itemId)
- {
- TaskInventoryItem srcTaskItem = part.GetInventoryItem(itemId);
- if (srcTaskItem == null)
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for moving"
- + " but the item does not exist in this inventory",
- itemId, part.Name, part.UUID);
- return;
- }
-
- SceneObjectPart destPart = GetSceneObjectPart(destId);
- if (destPart == null)
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: " +
- "Could not find prim for ID {0}",
- destId);
- return;
- }
-
- if (part.OwnerID != destPart.OwnerID && (part.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.AllowInventoryDrop) == 0)
- {
- // object cannot copy items to an object owned by a different owner
- // unless llAllowInventoryDrop has been called
- return;
- }
- // must have both move and modify permission to put an item in an object
- if ((part.OwnerMask & ((uint)PermissionMask.Move | (uint)PermissionMask.Modify)) == 0)
- {
- return;
- }
- TaskInventoryItem destTaskItem = new TaskInventoryItem();
-
- destTaskItem.ItemID = LLUUID.Random();
- destTaskItem.CreatorID = srcTaskItem.CreatorID;
- destTaskItem.AssetID = srcTaskItem.AssetID;
- destTaskItem.GroupID = destPart.GroupID;
- destTaskItem.OwnerID = destPart.OwnerID;
- destTaskItem.ParentID = destPart.UUID;
- destTaskItem.ParentPartID = destPart.UUID;
- destTaskItem.BaseMask = srcTaskItem.BaseMask;
- destTaskItem.EveryoneMask = srcTaskItem.EveryoneMask;
- destTaskItem.GroupMask = srcTaskItem.GroupMask;
- destTaskItem.OwnerMask = srcTaskItem.OwnerMask;
- destTaskItem.NextOwnerMask = srcTaskItem.NextOwnerMask;
- destTaskItem.Flags = srcTaskItem.Flags;
-
- if (destPart.OwnerID != part.OwnerID)
- {
- if (ExternalChecks.ExternalChecksPropagatePermissions())
- {
- destTaskItem.OwnerMask = srcTaskItem.OwnerMask &
- srcTaskItem.NextOwnerMask;
- destTaskItem.GroupMask = srcTaskItem.GroupMask &
- srcTaskItem.NextOwnerMask;
- destTaskItem.EveryoneMask = srcTaskItem.EveryoneMask &
- srcTaskItem.NextOwnerMask;
- destTaskItem.BaseMask = srcTaskItem.BaseMask &
- srcTaskItem.NextOwnerMask;
- destTaskItem.OwnerMask |= 8; // Slam!
- }
- }
- destTaskItem.Description = srcTaskItem.Description;
- destTaskItem.Name = srcTaskItem.Name;
- destTaskItem.InvType = srcTaskItem.InvType;
- destTaskItem.Type = srcTaskItem.Type;
-
- destPart.AddInventoryItem(destTaskItem);
- if ((srcTaskItem.OwnerMask & (uint)PermissionMask.Copy) == 0)
- part.RemoveInventoryItem(itemId);
- ScenePresence avatar;
-
- if (TryGetAvatar(srcTaskItem.OwnerID, out avatar))
- {
- destPart.GetProperties(avatar.ControllingClient);
- }
- }
-
- public void MoveTaskInventoryItems(LLUUID destID, string category, SceneObjectPart host, List<LLUUID> items)
- {
- CachedUserInfo profile = CommsManager.UserProfileCacheService.GetUserDetails(destID);
- if (profile == null || profile.RootFolder == null)
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: " +
- "Avatar {0} cannot be found to add items",
- destID);
- return;
- }
- LLUUID newFolderID = LLUUID.Random();
-
- profile.CreateFolder(category, newFolderID, 0xffff, profile.RootFolder.ID);
- foreach (LLUUID itemID in items)
- {
- InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(destID, host, itemID);
- agentItem.Folder = newFolderID;
- AddInventoryItem(destID, agentItem);
- }
- ScenePresence avatar;
- if (TryGetAvatar(destID, out avatar))
- {
- profile.SendInventoryDecendents(avatar.ControllingClient,
- profile.RootFolder.ID, true, false);
- profile.SendInventoryDecendents(avatar.ControllingClient,
- newFolderID, false, true);
- }
- }
- /// <summary>
- /// Update an item in a prim (task) inventory.
- /// This method does not handle scripts, <see>RezScript(IClientAPI, LLUUID, unit)</see>
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="transactionID"></param>
- /// <param name="itemInfo"></param>
- /// <param name="primLocalID"></param>
- public void UpdateTaskInventory(IClientAPI remoteClient, LLUUID transactionID, TaskInventoryItem itemInfo,
- uint primLocalID)
- {
- LLUUID itemID = itemInfo.ItemID;
- // Find the prim we're dealing with
- SceneObjectPart part = GetSceneObjectPart(primLocalID);
- if (part != null)
- {
- if (part.OwnerID != remoteClient.AgentId)
- return;
- if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
- return;
- TaskInventoryItem currentItem = part.GetInventoryItem(itemID);
- if (currentItem == null)
- {
- LLUUID copyID = LLUUID.Random();
- if (itemID != LLUUID.Zero)
- {
- CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
- if (userInfo != null && userInfo.RootFolder != null)
- {
- InventoryItemBase item = userInfo.RootFolder.FindItem(itemID);
- // Try library
- // XXX clumsy, possibly should be one call
- if (null == item)
- {
- item = CommsManager.UserProfileCacheService.libraryRoot.FindItem(itemID);
- }
- if (item != null)
- {
- part.ParentGroup.AddInventoryItem(remoteClient, primLocalID, item, copyID);
- m_log.InfoFormat(
- "[PRIM INVENTORY]: Update with item {0} requested of prim {1} for {2}",
- item.Name, primLocalID, remoteClient.Name);
- part.GetProperties(remoteClient);
- if (!ExternalChecks.ExternalChecksBypassPermissions())
- {
- if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
- RemoveInventoryItem(remoteClient, itemID);
- }
- }
- else
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: Could not find inventory item {0} to update for {1}!",
- itemID, remoteClient.Name);
- }
- }
- }
- }
- else // Updating existing item with new perms etc
- {
- TaskInventoryItem prevItem = part.GetInventoryItem(itemID);
- itemInfo.AssetID = prevItem.AssetID;
- if (part.UpdateInventoryItem(itemInfo))
- part.GetProperties(remoteClient);
- }
- }
- else
- {
- m_log.WarnFormat(
- "[PRIM INVENTORY]: " +
- "Update with item {0} requested of prim {1} for {2} but this prim does not exist",
- itemID, primLocalID, remoteClient.Name);
- }
- }
- /// <summary>
- /// Rez a script into a prim's inventory
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="itemID"> </param>
- /// <param name="localID"></param>
- public void RezScript(IClientAPI remoteClient, InventoryItemBase itemBase, LLUUID transactionID, uint localID)
- {
- LLUUID itemID=itemBase.ID;
- LLUUID copyID = LLUUID.Random();
- if (itemID != LLUUID.Zero)
- {
- CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
- if (userInfo != null && userInfo.RootFolder != null)
- {
- InventoryItemBase item = userInfo.RootFolder.FindItem(itemID);
- // Try library
- // XXX clumsy, possibly should be one call
- if (null == item)
- {
- item = CommsManager.UserProfileCacheService.libraryRoot.FindItem(itemID);
- }
- if (item != null)
- {
- SceneObjectPart part = GetSceneObjectPart(localID);
- if (part != null)
- {
- if (part.OwnerID != remoteClient.AgentId)
- return;
- if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
- return;
- part.ParentGroup.AddInventoryItem(remoteClient, localID, item, copyID);
- // TODO: set this to "true" when scripts in inventory have persistent state to fire on_rez
- part.CreateScriptInstance(copyID, 0, false);
- // m_log.InfoFormat("[PRIMINVENTORY]: " +
- // "Rezzed script {0} into prim local ID {1} for user {2}",
- // item.inventoryName, localID, remoteClient.Name);
- part.GetProperties(remoteClient);
- }
- else
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: " +
- "Could not rez script {0} into prim local ID {1} for user {2}"
- + " because the prim could not be found in the region!",
- item.Name, localID, remoteClient.Name);
- }
- }
- else
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: Could not find script inventory item {0} to rez for {1}!",
- itemID, remoteClient.Name);
- }
- }
- }
- else // If the itemID is zero then the script has been rezzed directly in an object's inventory
- {
- SceneObjectPart part=GetSceneObjectPart(itemBase.Folder);
- if (part == null)
- return;
- if (part.OwnerID != remoteClient.AgentId)
- return;
- if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
- return;
- AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType, Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"));
- AssetCache.AddAsset(asset);
- TaskInventoryItem taskItem=new TaskInventoryItem();
- taskItem.ResetIDs(itemBase.Folder);
- taskItem.ParentID = itemBase.Folder;
- taskItem.CreationDate = (uint)itemBase.CreationDate;
- taskItem.Name = itemBase.Name;
- taskItem.Description = itemBase.Description;
- taskItem.Type = itemBase.AssetType;
- taskItem.InvType = itemBase.InvType;
- taskItem.OwnerID = itemBase.Owner;
- taskItem.CreatorID = itemBase.Creator;
- taskItem.BaseMask = itemBase.BasePermissions;
- taskItem.OwnerMask = itemBase.CurrentPermissions;
- taskItem.EveryoneMask = itemBase.EveryOnePermissions;
- taskItem.NextOwnerMask = itemBase.NextPermissions;
- taskItem.GroupID = itemBase.GroupID;
- taskItem.GroupMask = 0;
- taskItem.Flags = itemBase.Flags;
- taskItem.PermsGranter = LLUUID.Zero;
- taskItem.PermsMask = 0;
- taskItem.AssetID = asset.ID;
- part.AddInventoryItem(taskItem);
- part.GetProperties(remoteClient);
-
- part.CreateScriptInstance(taskItem, 0, false);
- }
- }
- /// <summary>
- /// Rez a script into a prim's inventory from another prim
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="itemID"> </param>
- /// <param name="localID"></param>
- public void RezScript(LLUUID srcId, SceneObjectPart srcPart, LLUUID destId, int pin, int running, int start_param)
- {
- TaskInventoryItem srcTaskItem = srcPart.GetInventoryItem(srcId);
- if (srcTaskItem == null)
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for rezzing a script but the "
- + " item does not exist in this inventory",
- srcId, srcPart.Name, srcPart.UUID);
- return;
- }
-
- SceneObjectPart destPart = GetSceneObjectPart(destId);
- if (destPart == null)
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: " +
- "Could not find script for ID {0}",
- destId);
- return;
- }
-
- // Must own the object, and have modify rights
- if (srcPart.OwnerID != destPart.OwnerID)
- return;
- if ((destPart.OwnerMask & (uint)PermissionMask.Modify) == 0)
- return;
- if (destPart.ScriptAccessPin != pin)
- {
- m_log.WarnFormat(
- "[PRIM INVENTORY]: " +
- "Script in object {0} : {1}, attempted to load script {2} : {3} into object {4} : {5} with invalid pin {6}",
- srcPart.Name, srcId, srcTaskItem.Name, srcTaskItem.ItemID, destPart.Name, destId, pin);
- // the LSL Wiki says we are supposed to shout on the DEBUG_CHANNEL -
- // "Object: Task Object trying to illegally load script onto task Other_Object!"
- // How do we shout from in here?
- return;
- }
-
- TaskInventoryItem destTaskItem = new TaskInventoryItem();
-
- destTaskItem.ItemID = LLUUID.Random();
- destTaskItem.CreatorID = srcTaskItem.CreatorID;
- destTaskItem.AssetID = srcTaskItem.AssetID;
- destTaskItem.GroupID = destPart.GroupID;
- destTaskItem.OwnerID = destPart.OwnerID;
- destTaskItem.ParentID = destPart.UUID;
- destTaskItem.ParentPartID = destPart.UUID;
- destTaskItem.BaseMask = srcTaskItem.BaseMask;
- destTaskItem.EveryoneMask = srcTaskItem.EveryoneMask;
- destTaskItem.GroupMask = srcTaskItem.GroupMask;
- destTaskItem.OwnerMask = srcTaskItem.OwnerMask;
- destTaskItem.NextOwnerMask = srcTaskItem.NextOwnerMask;
- destTaskItem.Flags = srcTaskItem.Flags;
-
- if (destPart.OwnerID != srcPart.OwnerID)
- {
- if (ExternalChecks.ExternalChecksPropagatePermissions())
- {
- destTaskItem.OwnerMask = srcTaskItem.OwnerMask &
- srcTaskItem.NextOwnerMask;
- destTaskItem.GroupMask = srcTaskItem.GroupMask &
- srcTaskItem.NextOwnerMask;
- destTaskItem.EveryoneMask = srcTaskItem.EveryoneMask &
- srcTaskItem.NextOwnerMask;
- destTaskItem.BaseMask = srcTaskItem.BaseMask &
- srcTaskItem.NextOwnerMask;
- destTaskItem.OwnerMask |= 8; // Slam!
- }
- }
- destTaskItem.Description = srcTaskItem.Description;
- destTaskItem.Name = srcTaskItem.Name;
- destTaskItem.InvType = srcTaskItem.InvType;
- destTaskItem.Type = srcTaskItem.Type;
-
- destPart.AddInventoryItemExclusive(destTaskItem);
- if (running > 0)
- {
- destPart.CreateScriptInstance(destTaskItem, 0, false);
- }
-
- ScenePresence avatar;
-
- if (TryGetAvatar(srcTaskItem.OwnerID, out avatar))
- {
- destPart.GetProperties(avatar.ControllingClient);
- }
- }
-
- /// <summary>
- /// Called when an object is removed from the environment into inventory.
- /// </summary>
- /// <param name="packet"></param>
- /// <param name="remoteClient"></param>
- public virtual void DeRezObject(Packet packet, IClientAPI remoteClient)
- {
- DeRezObjectPacket DeRezPacket = (DeRezObjectPacket) packet;
- LLUUID folderID = LLUUID.Zero;
- foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData)
- {
- // m_log.DebugFormat(
- // "[AGENT INVENTORY]: Received request to derez {0} into folder {1}",
- // Data.ObjectLocalID, DeRezPacket.AgentBlock.DestinationID);
- EntityBase selectedEnt = null;
- //m_log.Info("[CLIENT]: LocalID:" + Data.ObjectLocalID.ToString());
- List<EntityBase> EntityList = GetEntities();
- foreach (EntityBase ent in EntityList)
- {
- if (ent.LocalId == Data.ObjectLocalID)
- {
- selectedEnt = ent;
- break;
- }
- }
- if (selectedEnt != null)
- {
- bool permissionToTake = false;
- bool permissionToDelete = false;
- if (DeRezPacket.AgentBlock.Destination == 1)// Take Copy
- {
- permissionToTake = ExternalChecks.ExternalChecksCanTakeCopyObject(((SceneObjectGroup)selectedEnt).UUID, remoteClient.AgentId);
- permissionToDelete = false; //Just taking copy!
- }
- else if (DeRezPacket.AgentBlock.Destination == 4) //Take
- {
- // Take
- permissionToTake = ExternalChecks.ExternalChecksCanTakeObject(((SceneObjectGroup)selectedEnt).UUID, remoteClient.AgentId);
- permissionToDelete = permissionToTake; //If they can take, they can delete!
- }
- else if (DeRezPacket.AgentBlock.Destination == 6) //Delete
- {
- permissionToTake = ExternalChecks.ExternalChecksCanDeleteObject(((SceneObjectGroup)selectedEnt).UUID, remoteClient.AgentId);
- permissionToDelete = ExternalChecks.ExternalChecksCanDeleteObject(((SceneObjectGroup)selectedEnt).UUID, remoteClient.AgentId);
- }
- else if (DeRezPacket.AgentBlock.Destination == 9) //Return
- {
- permissionToTake = ExternalChecks.ExternalChecksCanDeleteObject(((SceneObjectGroup)selectedEnt).UUID, remoteClient.AgentId);
- permissionToDelete = ExternalChecks.ExternalChecksCanDeleteObject(((SceneObjectGroup)selectedEnt).UUID, remoteClient.AgentId);
- }
- SceneObjectGroup objectGroup = (SceneObjectGroup)selectedEnt;
- if (permissionToTake)
- {
- if (m_inventoryTicker != null)
- {
- m_inventoryTicker.Stop();
- }
- else
- {
- m_inventoryTicker = new Timer(2000);
- m_inventoryTicker.AutoReset = false;
- m_inventoryTicker.Elapsed += InventoryRunDeleteTimer;
- }
- lock (m_inventoryDeletes)
- {
- DeleteToInventoryHolder dtis = new DeleteToInventoryHolder();
- dtis.DeRezPacket = DeRezPacket;
- dtis.folderID = folderID;
- dtis.objectGroup = objectGroup;
- dtis.remoteClient = remoteClient;
- dtis.selectedEnt = selectedEnt;
- dtis.permissionToDelete = permissionToDelete;
- m_inventoryDeletes.Enqueue(dtis);
- }
- m_inventoryTicker.Start();
- // Visually remove it, even if it isnt really gone yet.
- if (permissionToDelete)
- objectGroup.FakeDeleteGroup();
- }
- else if (permissionToDelete)
- {
- DeleteSceneObject(objectGroup);
- }
- }
- }
- }
- void InventoryRunDeleteTimer(object sender, ElapsedEventArgs e)
- {
- m_log.Info("Starting inventory send loop");
- while (InventoryDeQueueAndDelete() == true)
- {
- m_log.Info("Returned item successfully, continuing...");
- }
- }
- private bool InventoryDeQueueAndDelete()
- {
- DeleteToInventoryHolder x;
- try
- {
- lock (m_inventoryDeletes)
- {
- int left = m_inventoryDeletes.Count;
- if (left > 0)
- {
- m_log.InfoFormat("Sending deleted object to user's inventory, {0} item(s) remaining.", left);
- x = m_inventoryDeletes.Dequeue();
- DeleteToInventory(x.DeRezPacket, x.selectedEnt, x.remoteClient, x.objectGroup, x.folderID, x.permissionToDelete);
- return true;
- }
- }
- } catch(Exception e)
- {
- m_log.Error(e.ToString());
- }
- m_log.Info("No objects left in inventory delete queue.");
- return false;
- }
- private void DeleteToInventory(DeRezObjectPacket DeRezPacket, EntityBase selectedEnt, IClientAPI remoteClient, SceneObjectGroup objectGroup, LLUUID folderID, bool permissionToDelete)
- {
- string sceneObjectXml = objectGroup.ToXmlString();
- CachedUserInfo userInfo =
- CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
- if (userInfo != null)
- {
- // string searchFolder = "";
- // if (DeRezPacket.AgentBlock.Destination == 6)
- // searchFolder = "Trash";
- // else if (DeRezPacket.AgentBlock.Destination == 9)
- // searchFolder = "Lost And Found";
- // If we're deleting someone else's item, it goes back to their deleted items folder
- // If we're returning someone's item, it goes back to the owner's Lost And Found folder.
- if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero || (DeRezPacket.AgentBlock.Destination == 6 && objectGroup.OwnerID != remoteClient.AgentId))
- {
- List<InventoryFolderBase> subrootfolders = userInfo.RootFolder.RequestListOfFolders();
- foreach (InventoryFolderBase flder in subrootfolders)
- {
- if (flder.Name == "Lost And Found")
- {
- folderID = flder.ID;
- break;
- }
- }
- if (folderID == LLUUID.Zero)
- {
- folderID = userInfo.RootFolder.ID;
- }
- //currently following code not used (or don't know of any case of destination being zero
- }
- else
- {
- folderID = DeRezPacket.AgentBlock.DestinationID;
- }
- AssetBase asset = CreateAsset(
- ((SceneObjectGroup) selectedEnt).GetPartName(selectedEnt.LocalId),
- ((SceneObjectGroup) selectedEnt).GetPartDescription(selectedEnt.LocalId),
- (sbyte)AssetType.Object,
- Helpers.StringToField(sceneObjectXml));
- AssetCache.AddAsset(asset);
- InventoryItemBase item = new InventoryItemBase();
- item.Creator = objectGroup.RootPart.CreatorID;
- if (DeRezPacket.AgentBlock.Destination == 1 || DeRezPacket.AgentBlock.Destination == 4)// Take / Copy
- item.Owner = remoteClient.AgentId;
- else // Delete / Return
- item.Owner = objectGroup.OwnerID;
- item.ID = LLUUID.Random();
- item.AssetID = asset.FullID;
- item.Description = asset.Description;
- item.Name = asset.Name;
- item.AssetType = asset.Type;
- item.InvType = (int)InventoryType.Object;
- item.Folder = folderID;
- if ((remoteClient.AgentId != objectGroup.RootPart.OwnerID) && ExternalChecks.ExternalChecksPropagatePermissions())
- {
- uint perms=objectGroup.GetEffectivePermissions();
- uint nextPerms=(perms & 7) << 13;
- if ((nextPerms & (uint)PermissionMask.Copy) == 0)
- perms &= ~(uint)PermissionMask.Copy;
- if ((nextPerms & (uint)PermissionMask.Transfer) == 0)
- perms &= ~(uint)PermissionMask.Transfer;
- if ((nextPerms & (uint)PermissionMask.Modify) == 0)
- perms &= ~(uint)PermissionMask.Modify;
- item.BasePermissions = perms & objectGroup.RootPart.NextOwnerMask;
- item.CurrentPermissions = item.BasePermissions;
- item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
- item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask & objectGroup.RootPart.NextOwnerMask;
- item.CurrentPermissions |= 8; // Slam!
- }
- else
- {
- item.BasePermissions = objectGroup.GetEffectivePermissions();
- item.CurrentPermissions = objectGroup.GetEffectivePermissions();
- item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
- item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
- }
- // TODO: add the new fields (Flags, Sale info, etc)
- item.CreationDate = Util.UnixTimeSinceEpoch();
- userInfo.AddItem(item);
- if (item.Owner == remoteClient.AgentId)
- {
- remoteClient.SendInventoryItemCreateUpdate(item);
- }
- else
- {
- ScenePresence notifyUser = GetScenePresence(item.Owner);
- if (notifyUser != null)
- {
- notifyUser.ControllingClient.SendInventoryItemCreateUpdate(item);
- }
- }
- }
- // Finally remove the item, for reals this time.
- if(permissionToDelete)
- DeleteSceneObject(objectGroup);
- }
- public void updateKnownAsset(IClientAPI remoteClient, SceneObjectGroup grp, LLUUID assetID, LLUUID agentID)
- {
- SceneObjectGroup objectGroup = grp;
- if (objectGroup != null)
- {
- string sceneObjectXml = objectGroup.ToXmlString();
- CachedUserInfo userInfo =
- CommsManager.UserProfileCacheService.GetUserDetails(agentID);
- if (userInfo != null)
- {
- Queue<InventoryFolderImpl> searchfolders = new Queue<InventoryFolderImpl>();
- searchfolders.Enqueue(userInfo.RootFolder);
- LLUUID foundFolder = userInfo.RootFolder.ID;
- // search through folders to find the asset.
- while (searchfolders.Count > 0)
- {
- InventoryFolderImpl fld = searchfolders.Dequeue();
- lock (fld)
- {
- if (fld != null)
- {
- if (fld.Items.ContainsKey(assetID))
- {
- foundFolder = fld.ID;
- searchfolders.Clear();
- break;
- }
- else
- {
- foreach (InventoryFolderImpl subfld in fld.SubFolders.Values)
- {
- searchfolders.Enqueue(subfld);
- }
- }
- }
- }
- }
-
- AssetBase asset = CreateAsset(
- objectGroup.GetPartName(objectGroup.LocalId),
- objectGroup.GetPartDescription(objectGroup.LocalId),
- (sbyte)AssetType.Object,
- Helpers.StringToField(sceneObjectXml));
- AssetCache.AddAsset(asset);
- InventoryItemBase item = new InventoryItemBase();
- item.Creator = objectGroup.RootPart.CreatorID;
- item.Owner = agentID;
- item.ID = assetID;
- item.AssetID = asset.FullID;
- item.Description = asset.Description;
- item.Name = asset.Name;
- item.AssetType = asset.Type;
- item.InvType = (int)InventoryType.Object;
- // Sticking it in root folder for now.. objects folder later?
- item.Folder = foundFolder;// DeRezPacket.AgentBlock.DestinationID;
- if ((agentID != objectGroup.RootPart.OwnerID) && ExternalChecks.ExternalChecksPropagatePermissions())
- {
- item.BasePermissions = objectGroup.RootPart.NextOwnerMask;
- item.CurrentPermissions = objectGroup.RootPart.NextOwnerMask;
- item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
- item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask & objectGroup.RootPart.NextOwnerMask;
- }
- else
- {
- item.BasePermissions = objectGroup.GetEffectivePermissions();
- item.CurrentPermissions = objectGroup.GetEffectivePermissions();
- item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
- item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
- }
- userInfo.AddItem(item);
- // this gets called when the agent loggs off!
- if (remoteClient != null)
- {
- remoteClient.SendInventoryItemCreateUpdate(item);
- }
- }
- }
- }
- public LLUUID attachObjectAssetStore(IClientAPI remoteClient, SceneObjectGroup grp, LLUUID AgentId)
- {
- SceneObjectGroup objectGroup = grp;
- if (objectGroup != null)
- {
- string sceneObjectXml = objectGroup.ToXmlString();
- CachedUserInfo userInfo =
- CommsManager.UserProfileCacheService.GetUserDetails(AgentId);
- if (userInfo != null)
- {
- AssetBase asset = CreateAsset(
- objectGroup.GetPartName(objectGroup.LocalId),
- objectGroup.GetPartDescription(objectGroup.LocalId),
- (sbyte)AssetType.Object,
- Helpers.StringToField(sceneObjectXml));
- AssetCache.AddAsset(asset);
- InventoryItemBase item = new InventoryItemBase();
- item.Creator = objectGroup.RootPart.CreatorID;
- item.Owner = remoteClient.AgentId;
- item.ID = LLUUID.Random();
- item.AssetID = asset.FullID;
- item.Description = asset.Description;
- item.Name = asset.Name;
- item.AssetType = asset.Type;
- item.InvType = (int)InventoryType.Object;
- // Sticking it in root folder for now.. objects folder later?
- item.Folder = userInfo.RootFolder.ID;// DeRezPacket.AgentBlock.DestinationID;
- if ((remoteClient.AgentId != objectGroup.RootPart.OwnerID) && ExternalChecks.ExternalChecksPropagatePermissions())
- {
- item.BasePermissions = objectGroup.RootPart.NextOwnerMask;
- item.CurrentPermissions = objectGroup.RootPart.NextOwnerMask;
- item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
- item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask & objectGroup.RootPart.NextOwnerMask;
- }
- else
- {
- item.BasePermissions = objectGroup.RootPart.BaseMask;
- item.CurrentPermissions = objectGroup.RootPart.OwnerMask;
- item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
- item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
- }
- item.CreationDate = Util.UnixTimeSinceEpoch();
- userInfo.AddItem(item);
- remoteClient.SendInventoryItemCreateUpdate(item);
- return item.AssetID;
- }
- return LLUUID.Zero;
- }
- return LLUUID.Zero;
- }
- /// <summary>
- /// Event Handler Rez an object into a scene
- /// Calls the non-void event handler
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="itemID"></param>
- /// <param name="RayEnd"></param>
- /// <param name="RayStart"></param>
- /// <param name="RayTargetID"></param>
- /// <param name="BypassRayCast"></param>
- /// <param name="RayEndIsIntersection"></param>
- /// <param name="EveryoneMask"></param>
- /// <param name="GroupMask"></param>
- /// <param name="NextOwnerMask"></param>
- /// <param name="ItemFlags"></param>
- /// <param name="RezSelected"></param>
- /// <param name="RemoveItem"></param>
- /// <param name="fromTaskID"></param>
- public virtual void RezObject(IClientAPI remoteClient, LLUUID itemID, LLVector3 RayEnd, LLVector3 RayStart,
- LLUUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
- uint EveryoneMask, uint GroupMask, uint NextOwnerMask, uint ItemFlags,
- bool RezSelected, bool RemoveItem, LLUUID fromTaskID)
- {
- RezObject(
- remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
- EveryoneMask, GroupMask, NextOwnerMask, ItemFlags, RezSelected, RemoveItem, fromTaskID, false);
- }
- /// <summary>
- /// Returns SceneObjectGroup or null from asset request.
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="itemID"></param>
- /// <param name="RayEnd"></param>
- /// <param name="RayStart"></param>
- /// <param name="RayTargetID"></param>
- /// <param name="BypassRayCast"></param>
- /// <param name="RayEndIsIntersection"></param>
- /// <param name="EveryoneMask"></param>
- /// <param name="GroupMask"></param>
- /// <param name="NextOwnerMask"></param>
- /// <param name="ItemFlags"></param>
- /// <param name="RezSelected"></param>
- /// <param name="RemoveItem"></param>
- /// <param name="fromTaskID"></param>
- /// <param name="difference"></param>
- /// <returns></returns>
- public virtual SceneObjectGroup RezObject(IClientAPI remoteClient, LLUUID itemID, LLVector3 RayEnd, LLVector3 RayStart,
- LLUUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
- uint EveryoneMask, uint GroupMask, uint NextOwnerMask, uint ItemFlags,
- bool RezSelected, bool RemoveItem, LLUUID fromTaskID, bool attachment)
- {
- // Work out position details
- byte bRayEndIsIntersection = (byte)0;
- if (RayEndIsIntersection)
- {
- bRayEndIsIntersection = (byte)1;
- }
- else
- {
- bRayEndIsIntersection = (byte)0;
- }
- LLVector3 scale = new LLVector3(0.5f, 0.5f, 0.5f);
- LLVector3 pos = GetNewRezLocation(
- RayStart, RayEnd, RayTargetID, new LLQuaternion(0, 0, 0, 1),
- BypassRayCast, bRayEndIsIntersection,true,scale, false);
- // Rez object
- CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
- if (userInfo != null)
- {
- if (userInfo.RootFolder != null)
- {
- InventoryItemBase item = userInfo.RootFolder.FindItem(itemID);
- if (item != null)
- {
- AssetBase rezAsset = AssetCache.GetAsset(item.AssetID, false);
- if (rezAsset != null)
- {
- string xmlData = Helpers.FieldToUTF8String(rezAsset.Data);
- SceneObjectGroup group = new SceneObjectGroup(this, m_regionHandle, xmlData);
- if (!ExternalChecks.ExternalChecksCanRezObject(group.Children.Count, remoteClient.AgentId, pos) && !attachment)
- {
- return null;
- }
- group.ResetIDs();
- AddNewSceneObject(group, true);
- // if attachment we set it's asset id so object updates can reflect that
- // if not, we set it's position in world.
- if (!attachment)
- {
- pos = GetNewRezLocation(
- RayStart, RayEnd, RayTargetID, new LLQuaternion(0, 0, 0, 1),
- BypassRayCast, bRayEndIsIntersection, true, group.GroupScale(), false);
- group.AbsolutePosition = pos;
- }
- else
- {
- group.SetFromAssetID(itemID);
- }
- SceneObjectPart rootPart = null;
- try
- {
- rootPart = group.GetChildPart(group.UUID);
- }
- catch (NullReferenceException)
- {
- string isAttachment = "";
- if (attachment)
- isAttachment = " Object was an attachment";
- m_log.Error("[OJECTREZ]: Error rezzing ItemID: " + itemID + " object has no rootpart." + isAttachment);
- }
- // Since renaming the item in the inventory does not affect the name stored
- // in the serialization, transfer the correct name from the inventory to the
- // object itself before we rez.
- rootPart.Name = item.Name;
- rootPart.Description = item.Description;
- List<SceneObjectPart> partList = new List<SceneObjectPart>(group.Children.Values);
- if (rootPart.OwnerID != item.Owner)
- {
- if (ExternalChecks.ExternalChecksPropagatePermissions())
- {
- if ((item.CurrentPermissions & 8) != 0)
- {
- foreach (SceneObjectPart part in partList)
- {
- part.EveryoneMask = item.EveryOnePermissions;
- part.NextOwnerMask = item.NextPermissions;
- }
- }
- group.ApplyNextOwnerPermissions();
- }
- }
- foreach (SceneObjectPart part in partList)
- {
- if (part.OwnerID != item.Owner)
- {
- part.LastOwnerID = part.OwnerID;
- part.OwnerID = item.Owner;
- part.ChangeInventoryOwner(item.Owner);
- }
- else if (((item.CurrentPermissions & 8) != 0) && (!attachment)) // Slam!
- {
- part.EveryoneMask = item.EveryOnePermissions;
- part.NextOwnerMask = item.NextPermissions;
- }
- }
- rootPart.TrimPermissions();
- if (!attachment)
- {
- if (group.RootPart.Shape.PCode == (byte)PCode.Prim)
- {
- group.ClearPartAttachmentData();
- }
- // Ghost prim if this is enabled!
- //group.ApplyPhysics(m_physicalPrim);
- }
- // TODO: make this true to fire on_rez when scripts have state while in inventory
- group.CreateScriptInstances(0, false);
- if (!attachment)
- rootPart.ScheduleFullUpdate();
- if (!ExternalChecks.ExternalChecksBypassPermissions())
- {
- if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
- userInfo.DeleteItem(item.ID);
- }
- return rootPart.ParentGroup;
- }
- }
- }
- }
- return null;
- }
- /// <summary>
- /// Rez an object in the scene
- /// </summary>
- /// <param name="item"></param>
- /// <param name="pos"></param>
- /// <param name="rot"></param>
- /// <param name="vel"></param>
- /// <param name="param"></param>
- /// <returns></returns>
- public virtual SceneObjectGroup RezObject(SceneObjectPart sourcePart, TaskInventoryItem item, LLVector3 pos, LLQuaternion rot, LLVector3 vel, int param)
- {
- // Rez object
- if (item != null)
- {
- LLUUID ownerID = item.OwnerID;
- AssetBase rezAsset = AssetCache.GetAsset(item.AssetID, false);
- if (rezAsset != null)
- {
- string xmlData = Helpers.FieldToUTF8String(rezAsset.Data);
- SceneObjectGroup group = new SceneObjectGroup(this, m_regionHandle, xmlData);
- if (!ExternalChecks.ExternalChecksCanRezObject(group.Children.Count, ownerID, pos))
- {
- return null;
- }
- group.ResetIDs();
- AddNewSceneObject(group, true);
- // we set it's position in world.
- group.AbsolutePosition = pos;
- SceneObjectPart rootPart = group.GetChildPart(group.UUID);
- // Since renaming the item in the inventory does not affect the name stored
- // in the serialization, transfer the correct name from the inventory to the
- // object itself before we rez.
- rootPart.Name = item.Name;
- rootPart.Description = item.Description;
- List<SceneObjectPart> partList = new List<SceneObjectPart>(group.Children.Values);
- if (rootPart.OwnerID != item.OwnerID)
- {
- if (ExternalChecks.ExternalChecksPropagatePermissions())
- {
- if ((item.OwnerMask & 8) != 0)
- {
- foreach (SceneObjectPart part in partList)
- {
- part.EveryoneMask = item.EveryoneMask;
- part.NextOwnerMask = item.NextOwnerMask;
- }
- }
- group.ApplyNextOwnerPermissions();
- }
- }
- foreach (SceneObjectPart part in partList)
- {
- if (part.OwnerID != item.OwnerID)
- {
- part.LastOwnerID = part.OwnerID;
- part.OwnerID = item.OwnerID;
- part.ChangeInventoryOwner(item.OwnerID);
- }
- else if ((item.OwnerMask & 8) != 0) // Slam!
- {
- part.EveryoneMask = item.EveryoneMask;
- part.NextOwnerMask = item.NextOwnerMask;
- }
- }
- rootPart.TrimPermissions();
- if (group.RootPart.Shape.PCode == (byte)PCode.Prim)
- {
- group.ClearPartAttachmentData();
- }
- group.UpdateGroupRotation(rot);
- group.ApplyPhysics(m_physicalPrim);
- group.Velocity = vel;
- group.CreateScriptInstances(param, true);
- rootPart.ScheduleFullUpdate();
- if (!ExternalChecks.ExternalChecksBypassPermissions())
- {
- if ((item.OwnerMask & (uint)PermissionMask.Copy) == 0)
- sourcePart.RemoveInventoryItem(item.ItemID);
- }
- return rootPart.ParentGroup;
- }
- }
-
- return null;
- }
-
- public virtual bool returnObjects(SceneObjectGroup[] returnobjects, LLUUID AgentId)
- {
- string message = "";
- if (returnobjects.Length <= 0)
- return false;
- // for the moment we're going to store them individually.. however, in the future, the rezObject
- // will be able to have more items.
- //string returnstring = "";
- //returnstring += "<scene>\n";
- //for (int i = 0; i < returnobjects.Length; i++)
- //{
- // returnstring += grp.ToXmlString2();
- //}
- //returnstring += "</scene>\n";
- bool permissionToDelete = false;
- for (int i = 0; i < returnobjects.Length; i++)
- {
- CachedUserInfo userInfo =
- CommsManager.UserProfileCacheService.GetUserDetails(returnobjects[i].OwnerID);
- if (userInfo == null)
- {
- CommsManager.UserProfileCacheService.AddNewUser(returnobjects[i].OwnerID);
- }
- if (userInfo != null)
- {
- if (userInfo.HasInventory)
- {
- LLUUID folderID = LLUUID.Zero;
- List<InventoryFolderBase> subrootfolders = userInfo.RootFolder.RequestListOfFolders();
- foreach (InventoryFolderBase flder in subrootfolders)
- {
- if (flder.Name == "Lost And Found")
- {
- folderID = flder.ID;
- break;
- }
- }
- if (folderID == LLUUID.Zero)
- {
- folderID = userInfo.RootFolder.ID;
- }
- permissionToDelete = ExternalChecks.ExternalChecksCanDeleteObject(returnobjects[i].UUID, AgentId);
- // If the user doesn't have permission, go on to the next one.
- if (!permissionToDelete)
- continue;
- string sceneObjectXml = returnobjects[i].ToXmlString2();
- AssetBase asset = CreateAsset(
- returnobjects[i].GetPartName(returnobjects[i].LocalId),
- returnobjects[i].GetPartDescription(returnobjects[i].LocalId),
- (sbyte)AssetType.Object,
- Helpers.StringToField(sceneObjectXml));
- AssetCache.AddAsset(asset);
- InventoryItemBase item = new InventoryItemBase();
- item.Creator = returnobjects[i].RootPart.CreatorID;
- item.Owner = returnobjects[i].OwnerID;
- item.ID = LLUUID.Random();
- item.AssetID = asset.FullID;
- item.Description = asset.Description;
- item.Name = asset.Name;
- item.AssetType = asset.Type;
- item.InvType = (int)InventoryType.Object;
- item.Folder = folderID;
-
- if ((AgentId != returnobjects[i].RootPart.OwnerID) && ExternalChecks.ExternalChecksPropagatePermissions())
- {
- uint perms = returnobjects[i].GetEffectivePermissions();
- uint nextPerms = (perms & 7) << 13;
- if ((nextPerms & (uint)PermissionMask.Copy) == 0)
- perms &= ~(uint)PermissionMask.Copy;
- if ((nextPerms & (uint)PermissionMask.Transfer) == 0)
- perms &= ~(uint)PermissionMask.Transfer;
- if ((nextPerms & (uint)PermissionMask.Modify) == 0)
- perms &= ~(uint)PermissionMask.Modify;
- item.BasePermissions = perms & returnobjects[i].RootPart.NextOwnerMask;
- item.CurrentPermissions = item.BasePermissions;
- item.NextPermissions = returnobjects[i].RootPart.NextOwnerMask;
- item.EveryOnePermissions = returnobjects[i].RootPart.EveryoneMask & returnobjects[i].RootPart.NextOwnerMask;
- item.CurrentPermissions |= 8; // Slam!
- }
- else
- {
- item.BasePermissions = returnobjects[i].GetEffectivePermissions();
- item.CurrentPermissions = returnobjects[i].GetEffectivePermissions();
- item.NextPermissions = returnobjects[i].RootPart.NextOwnerMask;
- item.EveryOnePermissions = returnobjects[i].RootPart.EveryoneMask;
- }
- // TODO: add the new fields (Flags, Sale info, etc)
- userInfo.AddItem(item);
- ScenePresence notifyUser = GetScenePresence(item.Owner);
- if (notifyUser != null)
- {
- notifyUser.ControllingClient.SendInventoryItemCreateUpdate(item);
- }
- SceneObjectGroup ObjectDeleting = returnobjects[i];
- returnobjects[i] = null;
- DeleteSceneObject(ObjectDeleting);
- ObjectDeleting = null;
- }
- else
- {
- CommsManager.UserProfileCacheService.RequestInventoryForUser(returnobjects[i].OwnerID);
- message = "Still waiting on the inventory service, some of the items won't be returned until the inventory services completes it's task. Try again shortly.";
- }
- }
- else
- {
- message = "Still waiting on the inventory service, some of the items won't be returned until the inventory services completes it's task. Try again shortly.";
- }
- //return true;
- }
- if (message.Length != 0)
- {
- ScenePresence returningavatar = GetScenePresence(AgentId);
- if (returningavatar != null)
- {
- returningavatar.ControllingClient.SendAlertMessage(message);
- }
- return false;
- }
- return true;
- }
- public void GetScriptRunning(IClientAPI controllingClient, LLUUID objectID, LLUUID itemID)
- {
- IScriptModule scriptModule = RequestModuleInterface<IScriptModule>();
- if (scriptModule == null)
- return;
- controllingClient.SendScriptRunningReply(objectID, itemID,
- scriptModule.GetScriptRunning(objectID, itemID));
- }
- public void SetScriptRunning(IClientAPI controllingClient, LLUUID objectID, LLUUID itemID, bool running)
- {
- SceneObjectPart part = GetSceneObjectPart(objectID);
- if (part == null)
- return;
- if (running)
- EventManager.TriggerStartScript(part.LocalId, itemID);
- else
- EventManager.TriggerStopScript(part.LocalId, itemID);
- }
- }
- }
|