llagentwearables.cpp 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187
  1. /**
  2. * @file llagentwearables.cpp
  3. * @brief LLAgentWearables class implementation
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewergpl$
  6. *
  7. * Copyright (c) 2010, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llagentwearables.h"
  34. #include "llcallbacklist.h"
  35. #include "llmd5.h"
  36. #include "llnotifications.h"
  37. #include "llagent.h"
  38. #include "llappearancemgr.h"
  39. #include "llfloatercustomize.h"
  40. #include "llfloaterinventory.h"
  41. #include "hbfloatermakenewoutfit.h"
  42. #include "llgesturemgr.h"
  43. #include "llgridmanager.h" // For gIsInSecondLife
  44. #include "llinventorybridge.h"
  45. //MK
  46. #include "mkrlinterface.h"
  47. //mk
  48. #include "llstartup.h"
  49. #include "llviewercontrol.h"
  50. #include "llviewerregion.h"
  51. #include "llvoavatarself.h"
  52. #include "llviewerwearable.h"
  53. #include "llwearablelist.h"
  54. // Globals
  55. LLAgentWearables gAgentWearables;
  56. bool gWearablesListDirty = false;
  57. using namespace LLAvatarAppearanceDefines;
  58. //-----------------------------------------------------------------------------
  59. // Support classes
  60. //-----------------------------------------------------------------------------
  61. class LLCreateStandardWearablesDoneCallback : public LLRefCount
  62. {
  63. protected:
  64. LOG_CLASS(LLCreateStandardWearablesDoneCallback);
  65. ~LLCreateStandardWearablesDoneCallback()
  66. {
  67. LL_DEBUGS("Wearables") << "Destructor - all done ?" << LL_ENDL;
  68. gAgentWearables.createStandardWearablesAllDone();
  69. }
  70. };
  71. class LLSendAgentWearablesUpdateCallback : public LLRefCount
  72. {
  73. protected:
  74. ~LLSendAgentWearablesUpdateCallback()
  75. {
  76. gAgentWearables.sendAgentWearablesUpdate();
  77. }
  78. };
  79. /**
  80. * @brief Construct a callback for dealing with the wearables.
  81. *
  82. * Would like to pass the agent in here, but we can't safely
  83. * count on it being around later. Just use gAgent directly.
  84. * @param cb callback to execute on completion (??? unused ???)
  85. * @param type Type for the wearable in the agent
  86. * @param wearable The wearable data.
  87. * @param todo Bitmask of actions to take on completion.
  88. */
  89. class LLAddWearableToInventoryCallback final : public LLInventoryCallback
  90. {
  91. protected:
  92. LOG_CLASS(LLAddWearableToInventoryCallback);
  93. public:
  94. enum ETodo
  95. {
  96. CALL_NONE = 0,
  97. CALL_UPDATE = 1,
  98. CALL_RECOVERDONE = 2,
  99. CALL_CREATESTANDARDDONE = 4,
  100. CALL_MAKENEWOUTFITDONE = 8
  101. };
  102. LLAddWearableToInventoryCallback(LLPointer<LLRefCount> cb,
  103. LLWearableType::EType type, U32 index,
  104. LLViewerWearable* wearable,
  105. U32 todo = CALL_NONE)
  106. : mType(type),
  107. mIndex(index),
  108. mWearable(wearable),
  109. mTodo(todo),
  110. mCB(cb)
  111. {
  112. LL_DEBUGS("Wearables") << "Constructor" << LL_ENDL;
  113. }
  114. void fire(const LLUUID& inv_item) override
  115. {
  116. if (mTodo & CALL_CREATESTANDARDDONE)
  117. {
  118. llinfos << "Callback fired, inv_item " << inv_item.asString()
  119. << llendl;
  120. }
  121. if (inv_item.isNull())
  122. {
  123. return;
  124. }
  125. gAgentWearables.addWearabletoAgentInventoryDone(mType, mIndex,
  126. inv_item, mWearable);
  127. if (mTodo & CALL_UPDATE)
  128. {
  129. // This calls sendAgentWearablesUpdate() (which was the call that
  130. // was made in v1 viewers), but also takes care of fully syncing
  131. // the outfit data (especially the outfit.xml file and/or COF).
  132. gAgentWearables.updateServer();
  133. }
  134. if (mTodo & CALL_RECOVERDONE)
  135. {
  136. gAgentWearables.recoverMissingWearableDone();
  137. }
  138. // Do this for every one in the loop
  139. if (mTodo & CALL_CREATESTANDARDDONE)
  140. {
  141. gAgentWearables.createStandardWearablesDone(mType, mIndex);
  142. }
  143. if (mTodo & CALL_MAKENEWOUTFITDONE)
  144. {
  145. gAgentWearables.makeNewOutfitDone(mType, mIndex);
  146. }
  147. }
  148. private:
  149. LLWearableType::EType mType;
  150. U32 mIndex;
  151. LLViewerWearable* mWearable;
  152. U32 mTodo;
  153. LLPointer<LLRefCount> mCB;
  154. };
  155. class LLMoveAfterCopyDoneCallback final : public LLInventoryCallback
  156. {
  157. protected:
  158. LOG_CLASS(LLMoveAfterCopyDoneCallback);
  159. public:
  160. LLMoveAfterCopyDoneCallback(const LLUUID& item_id,
  161. const LLUUID& folder_id,
  162. const std::string& item_name)
  163. : mItemID(item_id),
  164. mFolderID(folder_id),
  165. mItemName(item_name)
  166. {
  167. }
  168. void fire(const LLUUID& inv_item) override
  169. {
  170. move_inventory_item(mItemID, mFolderID, mItemName);
  171. }
  172. private:
  173. LLUUID mItemID;
  174. LLUUID mFolderID;
  175. std::string mItemName;
  176. };
  177. ///////////////////////////////////////////////////////////////////////////////
  178. LLAgentWearables::LLAgentWearables()
  179. : LLWearableData(),
  180. mWearablesLoaded(false),
  181. mIsSettingOutfit(false)
  182. {
  183. }
  184. void LLAgentWearables::setAvatarObject(LLVOAvatarSelf* avatar)
  185. {
  186. if (avatar)
  187. {
  188. //MK
  189. // Set wear/unwear checking functions for class LLWearableData
  190. setCanWearFunc(LLAgent::canWear);
  191. setCanUnwearFunc(LLAgent::canUnwear);
  192. //mk
  193. sendAgentWearablesRequest();
  194. setAvatarAppearance(avatar);
  195. }
  196. }
  197. void LLAgentWearables::sendAgentWearablesUpdate()
  198. {
  199. LLViewerWearable* wearable;
  200. // First make sure that we have inventory items for each wearable
  201. for (S32 type = 0; type < LLWearableType::WT_COUNT; ++type)
  202. {
  203. for (U32 index = 0,
  204. count = getWearableCount((LLWearableType::EType)type);
  205. index < count; ++index)
  206. {
  207. wearable = getViewerWearable((LLWearableType::EType)type, index);
  208. if (wearable)
  209. {
  210. if (wearable->getItemID().isNull())
  211. {
  212. LLPointer<LLInventoryCallback> cb =
  213. new LLAddWearableToInventoryCallback(LLPointer<LLRefCount>(NULL),
  214. (LLWearableType::EType)type,
  215. index, wearable,
  216. LLAddWearableToInventoryCallback::CALL_NONE);
  217. addWearableToAgentInventory(cb, wearable);
  218. }
  219. else
  220. {
  221. gInventory.addChangedMask(LLInventoryObserver::LABEL,
  222. wearable->getItemID());
  223. }
  224. }
  225. }
  226. }
  227. // Then make sure the inventory is in sync with the avatar.
  228. gInventory.notifyObservers();
  229. // Send the AgentIsNowWearing
  230. LLMessageSystem* msg = gMessageSystemp;
  231. msg->newMessageFast(_PREHASH_AgentIsNowWearing);
  232. msg->nextBlockFast(_PREHASH_AgentData);
  233. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  234. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  235. LL_DEBUGS("Wearables") << "sendAgentWearablesUpdate()" << LL_ENDL;
  236. // MULTI-WEARABLE: DEPRECATED: HACK: index to 0 - server database tables
  237. // don't support concept of multiwearables.
  238. for (S32 type = 0; type < LLWearableType::WT_COUNT; ++type)
  239. {
  240. msg->nextBlockFast(_PREHASH_WearableData);
  241. U8 type_u8 = (U8)type;
  242. msg->addU8Fast(_PREHASH_WearableType, type_u8);
  243. wearable = getViewerWearable((LLWearableType::EType)type, 0);
  244. if (wearable)
  245. {
  246. LLUUID item_id = wearable->getItemID();
  247. LL_DEBUGS("Wearables") << "Sending wearable " << wearable->getName()
  248. << " mItemID = " << item_id << LL_ENDL;
  249. const LLViewerInventoryItem* item = gInventory.getItem(item_id);
  250. if (item && item->getIsLinkType())
  251. {
  252. // Get the itemID that this item points to. i.e. make sure
  253. // we are storing baseitems, not their links, in the database.
  254. item_id = item->getLinkedUUID();
  255. }
  256. msg->addUUIDFast(_PREHASH_ItemID, item_id);
  257. }
  258. else
  259. {
  260. LL_DEBUGS("Wearables") << "Not wearing wearable type: "
  261. << LLWearableType::getTypeName((LLWearableType::EType)type)
  262. << LL_ENDL;
  263. msg->addUUIDFast(_PREHASH_ItemID, LLUUID::null);
  264. }
  265. LL_DEBUGS("Wearables") << " "
  266. << LLWearableType::getTypeLabel((LLWearableType::EType)type)
  267. << ": "
  268. << (wearable ? wearable->getAssetID() : LLUUID::null)
  269. << LL_ENDL;
  270. }
  271. gAgent.sendReliableMessage();
  272. }
  273. void LLAgentWearables::saveWearable(LLWearableType::EType type, U32 index,
  274. bool send_update,
  275. const std::string& new_name)
  276. {
  277. LLViewerWearable* old_wearable = getViewerWearable(type, index);
  278. if (!old_wearable || !isAgentAvatarValid()) return;
  279. bool name_changed = !new_name.empty() &&
  280. new_name != old_wearable->getName();
  281. if (name_changed || old_wearable->isDirty() ||
  282. old_wearable->isOldVersion())
  283. {
  284. LLUUID old_item_id = old_wearable->getItemID();
  285. LLViewerWearable* new_wearable =
  286. LLWearableList::getInstance()->createCopy(old_wearable, "");
  287. // should the following line be in LLViewerWearable::copyDataFrom() ?
  288. new_wearable->setItemID(old_item_id);
  289. setWearable(type, index, new_wearable);
  290. #if 1
  291. // old_wearable may still be referred to by other inventory items.
  292. // Revert unsaved changes so other inventory items aren't affected by
  293. // the changes that were just saved.
  294. old_wearable->revertValuesWithoutUpdate();
  295. #endif
  296. LLViewerInventoryItem* item = gInventory.getItem(old_item_id);
  297. if (item)
  298. {
  299. std::string item_name = item->getName();
  300. if (name_changed)
  301. {
  302. llinfos << "Changing name from " << item->getName() << " to "
  303. << new_name << llendl;
  304. item_name = new_name;
  305. }
  306. // Update existing inventory item
  307. LLPointer<LLViewerInventoryItem> template_item =
  308. new LLViewerInventoryItem(item->getUUID(),
  309. item->getParentUUID(),
  310. item->getPermissions(),
  311. new_wearable->getAssetID(),
  312. new_wearable->getAssetType(),
  313. item->getInventoryType(),
  314. item_name, item->getDescription(),
  315. item->getSaleInfo(),
  316. item->getFlags(),
  317. item->getCreationDate());
  318. template_item->setTransactionID(new_wearable->getTransactionID());
  319. update_inventory_item(template_item);
  320. }
  321. else
  322. {
  323. // Add a new inventory item (shouldn't ever happen here)
  324. U32 todo = LLAddWearableToInventoryCallback::CALL_NONE;
  325. if (send_update)
  326. {
  327. todo |= LLAddWearableToInventoryCallback::CALL_UPDATE;
  328. }
  329. LLPointer<LLInventoryCallback> cb =
  330. new LLAddWearableToInventoryCallback(LLPointer<LLRefCount>(NULL),
  331. type, index, new_wearable,
  332. todo);
  333. addWearableToAgentInventory(cb, new_wearable);
  334. return;
  335. }
  336. gAgentAvatarp->wearableUpdated(type, true);
  337. if (send_update)
  338. {
  339. sendAgentWearablesUpdate();
  340. }
  341. }
  342. }
  343. void LLAgentWearables::saveWearableAs(LLWearableType::EType type, U32 index,
  344. const std::string& new_name,
  345. bool save_in_laf)
  346. {
  347. if (!isWearableCopyable(type, index))
  348. {
  349. llwarns << "Wearable not copyable." << llendl;
  350. return;
  351. }
  352. LLViewerWearable* old_wearable = getViewerWearable(type, index);
  353. if (!old_wearable)
  354. {
  355. llwarns << "No old wearable." << llendl;
  356. return;
  357. }
  358. LLInventoryItem* item = gInventory.getItem(getWearableItemID(type, index));
  359. if (!item)
  360. {
  361. llwarns << "No inventory item." << llendl;
  362. return;
  363. }
  364. std::string trunc_name(new_name);
  365. LLStringUtil::truncate(trunc_name, DB_INV_ITEM_NAME_STR_LEN);
  366. LLViewerWearable* new_wearable =
  367. LLWearableList::getInstance()->createCopy(old_wearable, trunc_name);
  368. LLPointer<LLInventoryCallback> cb =
  369. new LLAddWearableToInventoryCallback(LLPointer<LLRefCount>(NULL),
  370. type, index, new_wearable,
  371. LLAddWearableToInventoryCallback::CALL_UPDATE);
  372. const LLUUID& cat_id = save_in_laf ? gInventory.getLostAndFoundID()
  373. : item->getParentUUID();
  374. if (cat_id.isNull())
  375. {
  376. llwarns << "Could not find the destination folder." << llendl;
  377. return;
  378. }
  379. copy_inventory_item(item->getPermissions().getOwner(), item->getUUID(),
  380. cat_id, new_name, cb);
  381. #if 1
  382. // old_wearable may still be referred to by other inventory items. Revert
  383. // unsaved changes so other inventory items aren't affected by the changes
  384. // that were just saved.
  385. old_wearable->revertValuesWithoutUpdate();
  386. #endif
  387. }
  388. void LLAgentWearables::revertWearable(LLWearableType::EType type, U32 index)
  389. {
  390. LLViewerWearable* wearable = getViewerWearable(type, index);
  391. if (wearable)
  392. {
  393. wearable->revertValues();
  394. }
  395. gAgent.sendAgentSetAppearance();
  396. }
  397. void LLAgentWearables::saveAllWearables()
  398. {
  399. #if 0
  400. if (!gInventory.isLoaded())
  401. {
  402. return;
  403. }
  404. #endif
  405. // This prevents too fast an update of the COF while each wearable saving
  406. // gets (slowly) acknowledged one after the other by the asset server:
  407. LLWearableSaveData::sResetCOFTimer = true;
  408. for (S32 i = 0; i < LLWearableType::WT_COUNT; ++i)
  409. {
  410. for (U32 j = 0, count = getWearableCount((LLWearableType::EType)i);
  411. j < count; ++j)
  412. {
  413. saveWearable((LLWearableType::EType)i, j, false);
  414. }
  415. }
  416. LLWearableSaveData::sResetCOFTimer = false;
  417. sendAgentWearablesUpdate();
  418. }
  419. // Called when the user changes the name of a wearable inventory item that is
  420. // currently being worn.
  421. void LLAgentWearables::setWearableName(const LLUUID& item_id,
  422. const std::string& new_name)
  423. {
  424. LLWearableList* wl = LLWearableList::getInstance();
  425. for (S32 i = 0; i < LLWearableType::WT_COUNT; ++i)
  426. {
  427. for (U32 j = 0, count = getWearableCount((LLWearableType::EType)i);
  428. j < count; ++j)
  429. {
  430. const LLUUID& curr_item_id =
  431. getWearableItemID((LLWearableType::EType)i, j);
  432. if (curr_item_id == item_id)
  433. {
  434. LLViewerWearable* old_wearable =
  435. getViewerWearable((LLWearableType::EType)i, j);
  436. llassert(old_wearable); //if (!old_wearable) continue;
  437. std::string old_name = old_wearable->getName();
  438. old_wearable->setName(new_name);
  439. LLViewerWearable* new_wearable = wl->createCopy(old_wearable);
  440. new_wearable->setItemID(item_id);
  441. LLInventoryItem* item = gInventory.getItem(item_id);
  442. if (item)
  443. {
  444. new_wearable->setPermissions(item->getPermissions());
  445. }
  446. old_wearable->setName(old_name);
  447. setWearable((LLWearableType::EType)i, j, new_wearable);
  448. sendAgentWearablesUpdate();
  449. break;
  450. }
  451. }
  452. }
  453. }
  454. bool LLAgentWearables::isWearableModifiable(LLWearableType::EType type,
  455. U32 index) const
  456. {
  457. const LLUUID& item_id = getWearableItemID(type, index);
  458. return item_id.notNull() && isWearableModifiable(item_id);
  459. }
  460. bool LLAgentWearables::isWearableModifiable(const LLUUID& item_id) const
  461. {
  462. const LLUUID& linked_id = gInventory.getLinkedItemID(item_id);
  463. if (linked_id.notNull())
  464. {
  465. LLInventoryItem* item = gInventory.getItem(linked_id);
  466. if (item && item->getPermissions().allowModifyBy(gAgentID,
  467. gAgent.getGroupID()))
  468. {
  469. return true;
  470. }
  471. }
  472. return false;
  473. }
  474. bool LLAgentWearables::isWearableCopyable(LLWearableType::EType type,
  475. U32 index) const
  476. {
  477. const LLUUID& item_id = getWearableItemID(type, index);
  478. if (item_id.notNull())
  479. {
  480. LLInventoryItem* item = gInventory.getItem(item_id);
  481. if (item && item->getPermissions().allowCopyBy(gAgentID,
  482. gAgent.getGroupID()))
  483. {
  484. return true;
  485. }
  486. }
  487. return false;
  488. }
  489. LLViewerInventoryItem* LLAgentWearables::getWearableInventoryItem(LLWearableType::EType type,
  490. U32 index)
  491. {
  492. const LLUUID& item_id = getWearableItemID(type, index);
  493. return item_id.notNull() ? gInventory.getItem(item_id) : NULL;
  494. }
  495. const LLViewerWearable* LLAgentWearables::getWearableFromItemID(const LLUUID& item_id) const
  496. {
  497. const LLUUID& base_item_id = gInventory.getLinkedItemID(item_id);
  498. for (S32 i = 0; i < LLWearableType::WT_COUNT; ++i)
  499. {
  500. for (U32 j = 0, count = getWearableCount((LLWearableType::EType)i);
  501. j < count; ++j)
  502. {
  503. const LLViewerWearable* curr_wearable =
  504. getViewerWearable((LLWearableType::EType)i, j);
  505. if (curr_wearable && curr_wearable->getItemID() == base_item_id)
  506. {
  507. return curr_wearable;
  508. }
  509. }
  510. }
  511. return NULL;
  512. }
  513. LLViewerWearable* LLAgentWearables::getWearableFromItemID(const LLUUID& item_id)
  514. {
  515. const LLUUID& base_item_id = gInventory.getLinkedItemID(item_id);
  516. for (S32 i = 0; i < LLWearableType::WT_COUNT; ++i)
  517. {
  518. for (U32 j = 0, count = getWearableCount((LLWearableType::EType)i);
  519. j < count; ++j)
  520. {
  521. LLViewerWearable* curr_wearable =
  522. getViewerWearable((LLWearableType::EType)i, j);
  523. if (curr_wearable && curr_wearable->getItemID() == base_item_id)
  524. {
  525. return curr_wearable;
  526. }
  527. }
  528. }
  529. return NULL;
  530. }
  531. LLViewerWearable* LLAgentWearables::getWearableFromAssetID(const LLUUID& asset_id)
  532. {
  533. for (S32 i = 0; i < LLWearableType::WT_COUNT; ++i)
  534. {
  535. for (U32 j = 0, count = getWearableCount((LLWearableType::EType)i);
  536. j < count; ++j)
  537. {
  538. LLViewerWearable* curr_wearable =
  539. getViewerWearable((LLWearableType::EType)i, j);
  540. if (curr_wearable && curr_wearable->getAssetID() == asset_id)
  541. {
  542. return curr_wearable;
  543. }
  544. }
  545. }
  546. return NULL;
  547. }
  548. void LLAgentWearables::sendAgentWearablesRequest()
  549. {
  550. LLMessageSystem* msg = gMessageSystemp;
  551. msg->newMessageFast(_PREHASH_AgentWearablesRequest);
  552. msg->nextBlockFast(_PREHASH_AgentData);
  553. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  554. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  555. gAgent.sendReliableMessage();
  556. }
  557. LLViewerWearable* LLAgentWearables::getViewerWearable(LLWearableType::EType type,
  558. U32 index)
  559. {
  560. LLWearable* wearable = getWearable(type, index);
  561. return wearable ? wearable->asViewerWearable() : NULL;
  562. }
  563. const LLViewerWearable* LLAgentWearables::getViewerWearable(LLWearableType::EType type,
  564. U32 index) const
  565. {
  566. const LLWearable* wearable = getWearable(type, index);
  567. return wearable ? wearable->asViewerWearable() : NULL;
  568. }
  569. //static
  570. bool LLAgentWearables::selfHasWearable(LLWearableType::EType type)
  571. {
  572. return gAgentWearables.getWearableCount(type) > 0;
  573. }
  574. //virtual
  575. void LLAgentWearables::wearableUpdated(LLWearable* wearable, bool removed)
  576. {
  577. if (!wearable || !isAgentAvatarValid()) return;
  578. gAgentAvatarp->wearableUpdated(wearable->getType(), removed);
  579. LLWearableData::wearableUpdated(wearable, removed);
  580. LLViewerWearable* viewer_wearable = wearable->asViewerWearable();
  581. if (!removed && viewer_wearable)
  582. {
  583. viewer_wearable->refreshName();
  584. // Hack pt 2. If the wearable we just loaded has definition version 24,
  585. // then force a re-save of this wearable after slamming the version
  586. // number to 22. This number was incorrectly incremented for internal
  587. // builds before release, and this fix will ensure that the affected
  588. // wearables are re-saved with the right version number. The versions
  589. // themselves are compatible. This code can be removed before release.
  590. if (wearable->getDefinitionVersion() == 24)
  591. {
  592. U32 index;
  593. if (getWearableIndex(wearable, index))
  594. {
  595. llinfos << "forcing werable type " << wearable->getType()
  596. << " to version 22 from 24" << llendl;
  597. wearable->setDefinitionVersion(22);
  598. saveWearable(wearable->getType(), index, true);
  599. }
  600. }
  601. }
  602. if (gFloaterCustomizep && viewer_wearable)
  603. {
  604. gFloaterCustomizep->updateWearableType(viewer_wearable->getType(),
  605. viewer_wearable);
  606. }
  607. }
  608. const LLUUID& LLAgentWearables::getWearableItemID(LLWearableType::EType type,
  609. U32 index) const
  610. {
  611. const LLViewerWearable* wearable = getViewerWearable(type, index);
  612. return wearable ? wearable->getItemID() : LLUUID::null;
  613. }
  614. const LLUUID& LLAgentWearables::getWearableAssetID(LLWearableType::EType type,
  615. U32 index) const
  616. {
  617. const LLViewerWearable* wearable = getViewerWearable(type, index);
  618. return wearable ? wearable->getAssetID() : LLUUID::null;
  619. }
  620. bool LLAgentWearables::isWearingItem(const LLUUID& item_id) const
  621. {
  622. return getWearableFromItemID(gInventory.getLinkedItemID(item_id)) != NULL;
  623. }
  624. void LLAgentWearables::setInitialWearablesUpdateReceived()
  625. {
  626. mInitialWearablesUpdateReceived = mWearablesLoaded = true;
  627. }
  628. // OPENSIM COMPATIBILITY
  629. //static
  630. void LLAgentWearables::processAgentInitialWearablesUpdate(LLMessageSystem* mesgsys,
  631. void** user_data)
  632. {
  633. if (gIsInSecondLife)
  634. {
  635. gAgentWearables.setInitialWearablesUpdateReceived();
  636. llinfos << "Received initial agent wearables message in state: "
  637. << LLStartUp::getStartupStateString() << llendl;
  638. // Simply ignore this message: it's no more conveying valid data in SL
  639. return;
  640. }
  641. // We should only receive this message a single time. Ignore subsequent
  642. // AgentWearablesUpdates that may result from AgentWearablesRequest having
  643. // been sent more than once.
  644. if (gAgentWearables.mInitialWearablesUpdateReceived)
  645. {
  646. LL_DEBUGS("InitialOutfit") << "Spurious AgentWearablesUpdates message received, ignoring..."
  647. << LL_ENDL;
  648. return;
  649. }
  650. LLUUID agent_id;
  651. LLMessageSystem* msg = gMessageSystemp;
  652. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  653. if (isAgentAvatarValid() && agent_id == gAgentAvatarp->getID())
  654. {
  655. LL_DEBUGS("InitialOutfit") << "Initial AgentWearablesUpdates message received."
  656. << LL_ENDL;
  657. gAgentWearables.mInitialWearablesUpdateReceived = true;
  658. msg->getU32Fast(_PREHASH_AgentData, _PREHASH_SerialNum,
  659. gAgentQueryManager.mUpdateSerialNum);
  660. constexpr S32 NUM_BODY_PARTS = 4;
  661. S32 num_wearables = msg->getNumberOfBlocksFast(_PREHASH_WearableData);
  662. if (num_wearables < NUM_BODY_PARTS)
  663. {
  664. // Transitional state. Avatars should always have at least their
  665. // body parts (hair, eyes, shape and skin).
  666. // The fact that they don't have any here (only a dummy is sent)
  667. // implies that either:
  668. // 1. This account existed before we had wearables
  669. // 2. The database has gotten messed up
  670. // 3. This is the account's first login (i.e. the wearables haven't
  671. // been generated yet).
  672. llwarns << "Insufficient number of wearables, aborting." << llendl;
  673. return;
  674. }
  675. bool restore_from_cof = gSavedSettings.getBool("RestoreOutfitFromCOF");
  676. if (!gIsInSecondLife && !gSavedSettings.getBool("OSUseCOF"))
  677. {
  678. restore_from_cof = false;
  679. }
  680. // Add wearables
  681. // MULTI-WEARABLE: DEPRECATED: Message only supports one wearable per
  682. // type, will be ignored in future.
  683. std::pair<LLUUID, LLUUID> asset_id_array[LLWearableType::WT_COUNT];
  684. for (S32 i = 0; i < num_wearables; ++i)
  685. {
  686. // Parse initial wearables data from message system
  687. U8 type_u8 = 0;
  688. msg->getU8Fast(_PREHASH_WearableData, _PREHASH_WearableType, type_u8, i);
  689. if (type_u8 >= LLWearableType::WT_COUNT)
  690. {
  691. continue;
  692. }
  693. LLWearableType::EType type = (LLWearableType::EType)type_u8;
  694. LLAssetType::EType asset_type = LLWearableType::getAssetType(type);
  695. if (asset_type == LLAssetType::AT_NONE)
  696. {
  697. continue;
  698. }
  699. LLUUID item_id;
  700. msg->getUUIDFast(_PREHASH_WearableData, _PREHASH_ItemID,
  701. item_id, i);
  702. if (item_id.isNull())
  703. {
  704. continue;
  705. }
  706. LLUUID asset_id;
  707. msg->getUUIDFast(_PREHASH_WearableData, _PREHASH_AssetID,
  708. asset_id, i);
  709. if (asset_id.isNull())
  710. {
  711. //MK
  712. gRLInterface.mRestoringOutfit = true;
  713. //mk
  714. LLViewerWearable::removeFromAvatar(type, false);
  715. //MK
  716. gRLInterface.mRestoringOutfit = false;
  717. //mk
  718. }
  719. else
  720. {
  721. // NOTE: when restoring from COF, only wear the body parts (so
  722. // to de-cloud the avatar): the rest will be restored from the
  723. // COF. This prevents issues with wearables that use the
  724. // maximum number of layers (the last layer would fail to be
  725. // worn if the first layer is already worn, which is not
  726. // detected by the setWearableOutfit() method which is used to
  727. // restore from the COF).
  728. if (!restore_from_cof ||
  729. asset_type == LLAssetType::AT_BODYPART)
  730. {
  731. asset_id_array[type] = std::make_pair(asset_id, item_id);
  732. LL_DEBUGS("InitialOutfit") << "Wearable type: "
  733. << LLWearableType::getTypeLabel(type)
  734. << ", Asset Id: " << asset_id
  735. << ", Item Id: "
  736. << gAgentWearables.getWearableItemID(type, 0)
  737. << LL_ENDL;
  738. }
  739. }
  740. }
  741. // Now that we have the asset IDs, request the wearable assets
  742. LLWearableList* wl = LLWearableList::getInstance();
  743. for (S32 i = 0; i < LLWearableType::WT_COUNT; ++i)
  744. {
  745. LL_DEBUGS("InitialOutfit") << "Fetching asset. Id: "
  746. << asset_id_array[i].first << LL_ENDL;
  747. const LLUUID item_id = asset_id_array[i].second;
  748. if (asset_id_array[i].second.notNull())
  749. {
  750. wl->getAsset(asset_id_array[i].first, LLStringUtil::null,
  751. gAgentAvatarp,
  752. LLWearableType::getAssetType((LLWearableType::EType)i),
  753. LLAgentWearables::onInitialWearableAssetArrived,
  754. (void*)new std::pair<const LLWearableType::EType,
  755. const LLUUID>((LLWearableType::EType)i,
  756. item_id));
  757. }
  758. }
  759. }
  760. else
  761. {
  762. LL_DEBUGS("InitialOutfit") << "AgentWearablesUpdates message received but not for us, ignoring..."
  763. << LL_ENDL;
  764. }
  765. }
  766. // A single wearable that the avatar was wearing on start-up has arrived from
  767. // the database.
  768. //static
  769. void LLAgentWearables::onInitialWearableAssetArrived(LLViewerWearable* wearable,
  770. void* userdata)
  771. {
  772. if (!userdata) return;
  773. std::pair<const LLWearableType::EType, const LLUUID>* wearable_data;
  774. wearable_data = (std::pair<const LLWearableType::EType,
  775. const LLUUID>*)userdata;
  776. LLWearableType::EType type = wearable_data->first;
  777. LLUUID item_id = wearable_data->second;
  778. if (!isAgentAvatarValid())
  779. {
  780. LL_DEBUGS("InitialOutfit") << "Agent is not valid !" << LL_ENDL;
  781. return;
  782. }
  783. //MK
  784. gRLInterface.mRestoringOutfit = true;
  785. //mk
  786. if (wearable)
  787. {
  788. LL_DEBUGS("InitialOutfit") << "Adding wearable: " << item_id << LL_ENDL;
  789. llassert(type == wearable->getType());
  790. wearable->setItemID(item_id);
  791. gAgentWearables.setWearable(type, 0, wearable);
  792. // disable composites if initial textures are baked
  793. gAgentAvatarp->setupComposites();
  794. gAgentWearables.queryWearableCache();
  795. gAgentAvatarp->setCompositeUpdatesEnabled(true);
  796. gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id);
  797. }
  798. else
  799. {
  800. // Somehow the asset doesn't exist in the database.
  801. LL_DEBUGS("InitialOutfit") << "Missing wearable for type " << type
  802. << ", starting recovery." << LL_ENDL;
  803. gAgentWearables.recoverMissingWearable(type, 0);
  804. }
  805. //MK
  806. gRLInterface.mRestoringOutfit = false;
  807. //mk
  808. gInventory.notifyObservers();
  809. // Have all the wearables that the avatar was wearing at log-in arrived ?
  810. if (!gAgentWearables.mWearablesLoaded)
  811. {
  812. gAgentWearables.mWearablesLoaded = true;
  813. for (S32 i = 0; i < LLWearableType::WT_COUNT; ++i)
  814. {
  815. if (gAgentWearables.getWearableItemID((LLWearableType::EType)i, 0).notNull() &&
  816. !gAgentWearables.getViewerWearable((LLWearableType::EType)i, 0))
  817. {
  818. LL_DEBUGS("InitialOutfit") << "Not all wearables have loaded yet."
  819. << LL_ENDL;
  820. gAgentWearables.mWearablesLoaded = false;
  821. break;
  822. }
  823. }
  824. }
  825. if (gAgentWearables.mWearablesLoaded)
  826. {
  827. LL_DEBUGS("InitialOutfit") << "All wearables have loaded." << LL_ENDL;
  828. // Make sure that the server's idea of the avatar's wearables actually
  829. // match the wearables.
  830. gAgent.sendAgentSetAppearance();
  831. // Check to see if there are any baked textures that we hadn't uploaded
  832. // before we logged off last time.
  833. // If there are any, schedule them to be uploaded as soon as the layer
  834. // textures they depend on arrive.
  835. if (!gAgent.cameraCustomizeAvatar())
  836. {
  837. gAgentAvatarp->requestLayerSetUploads();
  838. }
  839. }
  840. }
  841. // Normally, all wearables referred to "AgentWearablesUpdate" will correspond
  842. // to actual assets in the database. If for some reason, we can't load one of
  843. // those assets, we can try to reconstruct it so that the user isn't left
  844. // without a shape, for example. We can do that only after the inventory has
  845. // loaded.
  846. void LLAgentWearables::recoverMissingWearable(LLWearableType::EType type,
  847. U32 index)
  848. {
  849. if (!isAgentAvatarValid())
  850. {
  851. return;
  852. }
  853. // Try to recover by replacing missing wearable with a new one.
  854. gNotifications.add("ReplacedMissingWearable");
  855. LL_DEBUGS("Wearables") << "Wearable " << LLWearableType::getTypeLabel(type)
  856. << " could not be downloaded. Replaced inventory item with default wearable."
  857. << LL_ENDL;
  858. LLViewerWearable* new_wearable =
  859. LLWearableList::getInstance()->createNewWearable(type, gAgentAvatarp);
  860. setWearable(type, index, new_wearable);
  861. // Add a new one in the lost and found folder (we used to overwrite the
  862. // "not found" one, but that could potentially destroy content). JC
  863. LLPointer<LLInventoryCallback> cb =
  864. new LLAddWearableToInventoryCallback(LLPointer<LLRefCount>(NULL),
  865. type, index, new_wearable,
  866. LLAddWearableToInventoryCallback::CALL_RECOVERDONE);
  867. addWearableToAgentInventory(cb, new_wearable,
  868. gInventory.getLostAndFoundID(), true);
  869. }
  870. void LLAgentWearables::recoverMissingWearableDone()
  871. {
  872. // Have all the wearables that the avatar was wearing at log-in arrived or
  873. // been fabricated?
  874. updateWearablesLoaded();
  875. if (areWearablesLoaded())
  876. {
  877. // Make sure that the server's idea of the avatar's wearables actually
  878. // match the wearables.
  879. gAgent.sendAgentSetAppearance();
  880. }
  881. else
  882. {
  883. gInventory.addChangedMask(LLInventoryObserver::LABEL, LLUUID::null);
  884. gInventory.notifyObservers();
  885. }
  886. }
  887. LLLocalTextureObject* LLAgentWearables::addLocalTextureObject(LLWearableType::EType type,
  888. LLAvatarAppearanceDefines::ETextureIndex texture_type,
  889. U32 index)
  890. {
  891. LLViewerWearable* wearable =
  892. getViewerWearable((LLWearableType::EType)type, index);
  893. if (wearable)
  894. {
  895. LLLocalTextureObject lto;
  896. return wearable->setLocalTextureObject(texture_type, lto);
  897. }
  898. return NULL;
  899. }
  900. void LLAgentWearables::createStandardWearables(bool female)
  901. {
  902. llwarns << "Creating standard " << (female ? "female" : "male")
  903. << " wearables" << llendl;
  904. if (!isAgentAvatarValid())
  905. {
  906. return;
  907. }
  908. gAgentAvatarp->setSex(female ? SEX_FEMALE : SEX_MALE);
  909. bool create[LLWearableType::WT_COUNT] =
  910. {
  911. true, //WT_SHAPE
  912. true, //WT_SKIN
  913. true, //WT_HAIR
  914. true, //WT_EYES
  915. true, //WT_SHIRT
  916. true, //WT_PANTS
  917. true, //WT_SHOES
  918. true, //WT_SOCKS
  919. false, //WT_JACKET
  920. false, //WT_GLOVES
  921. true, //WT_UNDERSHIRT
  922. true, //WT_UNDERPANTS
  923. false, //WT_SKIRT
  924. false, //WT_ALPHA
  925. false, //WT_TATTOO
  926. false, //WT_PHYSICS
  927. false //WT_UNIVERSAL
  928. };
  929. LLWearableList* wl = LLWearableList::getInstance();
  930. for (S32 i = 0; i < LLWearableType::WT_COUNT; ++i)
  931. {
  932. bool once = false;
  933. LLPointer<LLRefCount> donecb = NULL;
  934. if (create[i])
  935. {
  936. if (!once)
  937. {
  938. once = true;
  939. donecb = new LLCreateStandardWearablesDoneCallback;
  940. }
  941. llassert(getWearableCount((LLWearableType::EType)i) == 0);
  942. LLViewerWearable* wearable =
  943. wl->createNewWearable((LLWearableType::EType)i, gAgentAvatarp);
  944. // no need to update here...
  945. LLPointer<LLInventoryCallback> cb =
  946. new LLAddWearableToInventoryCallback(donecb,
  947. (LLWearableType::EType)i,
  948. 0, wearable,
  949. LLAddWearableToInventoryCallback::CALL_CREATESTANDARDDONE);
  950. addWearableToAgentInventory(cb, wearable, LLUUID::null, false);
  951. }
  952. }
  953. }
  954. void LLAgentWearables::createStandardWearablesDone(S32 type, U32 index)
  955. {
  956. if (isAgentAvatarValid())
  957. {
  958. // Copy wearable params to avatar.
  959. gAgentAvatarp->writeWearablesToAvatar();
  960. // Then update the avatar based on the copied params.
  961. gAgentAvatarp->updateVisualParams();
  962. }
  963. }
  964. void LLAgentWearables::createStandardWearablesAllDone()
  965. {
  966. // ...because sendAgentWearablesUpdate will notify inventory observers.
  967. mWearablesLoaded = true;
  968. updateServer();
  969. // Treat this as the first texture entry message, if none received yet
  970. gAgentAvatarp->onFirstTEMessageReceived();
  971. }
  972. S32 LLAgentWearables::getWearableTypeAndIndex(LLViewerWearable* wearable,
  973. LLWearableType::EType& type)
  974. {
  975. S32 layer = -1;
  976. if (wearable)
  977. {
  978. type = wearable->getType();
  979. for (U32 index = 0, count = getWearableCount(type); index < count;
  980. ++index)
  981. {
  982. LLViewerWearable* worn = getViewerWearable(type, index);
  983. if (worn == wearable)
  984. {
  985. layer = index;
  986. break;
  987. }
  988. }
  989. }
  990. return layer;
  991. }
  992. struct HBNewOutfitData
  993. {
  994. HBNewOutfitData(const uuid_vec_t& wearables_to_include,
  995. const uuid_vec_t& attachments_to_include,
  996. bool rename_clothing)
  997. : mWearables(wearables_to_include),
  998. mAttachments(attachments_to_include),
  999. mRenameClothing(rename_clothing)
  1000. {
  1001. }
  1002. uuid_vec_t mWearables;
  1003. uuid_vec_t mAttachments;
  1004. bool mRenameClothing;
  1005. };
  1006. void LLAgentWearables::makeNewOutfit(const std::string& new_folder_name,
  1007. const uuid_vec_t& wearables_to_include,
  1008. const uuid_vec_t& attachments_to_include,
  1009. bool rename_clothing)
  1010. {
  1011. if (!isAgentAvatarValid())
  1012. {
  1013. return;
  1014. }
  1015. // Store the required data for the callback in a temporary structure (this
  1016. // is slow, but this is the cost for using asynchronous callbacks). HB
  1017. HBNewOutfitData* datap = new HBNewOutfitData(wearables_to_include,
  1018. attachments_to_include,
  1019. rename_clothing);
  1020. // We will create a sub-folder in the user-preferred folder or the Clothing
  1021. // folder by default (FT_MY_OUTFITS becomes FT_CLOTHING on purpose in
  1022. // findChoosenCategoryUUIDForType() when no user preferred folder is set).
  1023. const LLUUID clothing_folder_id =
  1024. gInventory.findChoosenCategoryUUIDForType(LLFolderType::FT_MY_OUTFITS);
  1025. // Create the category and, on completion, call back our method to link,
  1026. // copy or move the items into it. HB
  1027. inventory_func_t func = boost::bind(&LLAgentWearables::makeNewOutfitCopy,
  1028. this, _1, datap);
  1029. gInventory.createNewCategory(clothing_folder_id, LLFolderType::FT_NONE,
  1030. new_folder_name, func);
  1031. }
  1032. void LLAgentWearables::makeNewOutfitCopy(const LLUUID& cat_id,
  1033. HBNewOutfitData* datap)
  1034. {
  1035. if (!datap) return; // Paranoia
  1036. if (cat_id.isNull())
  1037. {
  1038. gNotifications.add("CantCreateRequestedInvFolder");
  1039. delete datap;
  1040. return;
  1041. }
  1042. bool found_first_item = false;
  1043. bool no_link = !gSavedSettings.getBool("UseInventoryLinks");
  1044. bool do_link = gSavedSettings.getBool("UseInventoryLinksAlways");
  1045. bool cloth_link = gSavedSettings.getBool("UseInventoryLinksForClothes");
  1046. ///////////////////
  1047. // Wearables
  1048. if (datap->mWearables.size())
  1049. {
  1050. LLWearableList* wl = LLWearableList::getInstance();
  1051. // Then, iterate though each of the wearables and save copies of them
  1052. // in the folder.
  1053. LLPointer<LLRefCount> cbdone = NULL;
  1054. LLWearableType::EType type;
  1055. std::string new_name, name_base;
  1056. if (datap->mRenameClothing)
  1057. {
  1058. LLViewerInventoryCategory* catp = gInventory.getCategory(cat_id);
  1059. if (catp) // Paranoia
  1060. {
  1061. name_base = catp->getName() + " ";
  1062. }
  1063. }
  1064. for (S32 i = 0, count = datap->mWearables.size(); i < count; ++i)
  1065. {
  1066. const LLUUID& item_id = datap->mWearables[i];
  1067. LLViewerWearable* old_wearablep = getWearableFromItemID(item_id);
  1068. S32 index = getWearableTypeAndIndex(old_wearablep, type);
  1069. if (index < 0) continue; // Not found/not worn
  1070. bool use_link = do_link ||
  1071. (cloth_link && type >= LLWearableType::WT_SHIRT);
  1072. LLViewerInventoryItem* itemp = gInventory.getItem(item_id);
  1073. if (!itemp)
  1074. {
  1075. llwarns << "Could not find inventory item for wearable type: "
  1076. << LLWearableType::getTypeLabel(type)
  1077. << " - layer index: " << index << llendl;
  1078. continue;
  1079. }
  1080. if (name_base.empty())
  1081. {
  1082. new_name = itemp->getName();
  1083. }
  1084. else
  1085. {
  1086. new_name = name_base + old_wearablep->getTypeLabel();
  1087. if (index > 0)
  1088. {
  1089. if ((S32)new_name.length() + 10 <= DB_INV_ITEM_NAME_STR_LEN)
  1090. {
  1091. new_name += llformat(" (layer %d)", index);
  1092. }
  1093. else
  1094. {
  1095. new_name += llformat("#%d", index);
  1096. }
  1097. }
  1098. LLStringUtil::truncate(new_name, DB_INV_ITEM_NAME_STR_LEN);
  1099. }
  1100. bool can_copy = isWearableCopyable(type, index);
  1101. if (!use_link && (no_link || can_copy))
  1102. {
  1103. if (can_copy)
  1104. {
  1105. LLViewerWearable* new_wearablep = wl->createCopy(old_wearablep);
  1106. if (datap->mRenameClothing)
  1107. {
  1108. new_wearablep->setName(new_name);
  1109. }
  1110. S32 todo = LLAddWearableToInventoryCallback::CALL_NONE;
  1111. if (!found_first_item)
  1112. {
  1113. found_first_item = true;
  1114. // set the focus to the first item
  1115. todo |= LLAddWearableToInventoryCallback::CALL_MAKENEWOUTFITDONE;
  1116. // Send the agent wearables update when done
  1117. cbdone = new LLSendAgentWearablesUpdateCallback;
  1118. }
  1119. LLPointer<LLInventoryCallback> cb =
  1120. new LLAddWearableToInventoryCallback(cbdone, type,
  1121. index,
  1122. new_wearablep,
  1123. todo);
  1124. copy_inventory_item(itemp->getPermissions().getOwner(),
  1125. itemp->getLinkedUUID(), cat_id,
  1126. new_name, cb);
  1127. }
  1128. else
  1129. {
  1130. move_inventory_item(itemp->getLinkedUUID(), cat_id,
  1131. new_name);
  1132. }
  1133. }
  1134. else
  1135. {
  1136. link_inventory_item(itemp->getLinkedUUID(), cat_id,
  1137. // For auto-ordering on outfit wearing:
  1138. build_order_string(type, index),
  1139. LLAssetType::AT_LINK);
  1140. }
  1141. }
  1142. gInventory.notifyObservers();
  1143. }
  1144. ///////////////////
  1145. // Attachments
  1146. if (datap->mAttachments.size())
  1147. {
  1148. for (S32 i = 0, count = datap->mAttachments.size(); i < count; ++i)
  1149. {
  1150. const LLUUID& item_id = datap->mAttachments[i];
  1151. LLViewerInventoryItem* itemp = gInventory.getItem(item_id);
  1152. if (!itemp) continue;
  1153. const LLUUID& inv_item_id = itemp->getLinkedUUID();
  1154. if (!do_link &&
  1155. (no_link || itemp->getPermissions().allowCopyBy(gAgentID)))
  1156. {
  1157. const std::string item_name = itemp->getName();
  1158. const LLUUID& old_cat_id = itemp->getParentUUID();
  1159. if (itemp->getPermissions().allowCopyBy(gAgentID))
  1160. {
  1161. LLPointer<LLInventoryCallback> cb =
  1162. new LLMoveAfterCopyDoneCallback(inv_item_id, cat_id,
  1163. item_name);
  1164. copy_inventory_item(itemp->getPermissions().getOwner(),
  1165. inv_item_id, old_cat_id, item_name,
  1166. cb);
  1167. }
  1168. else
  1169. {
  1170. move_inventory_item(inv_item_id, cat_id, item_name);
  1171. }
  1172. }
  1173. else
  1174. {
  1175. link_inventory_item(inv_item_id, cat_id,
  1176. itemp->getDescription(),
  1177. LLAssetType::AT_LINK);
  1178. }
  1179. }
  1180. gInventory.notifyObservers();
  1181. }
  1182. delete datap;
  1183. }
  1184. void LLAgentWearables::makeNewOutfitDone(LLWearableType::EType type, U32 index)
  1185. {
  1186. const LLUUID& first_item_id = getWearableItemID(type, index);
  1187. if (first_item_id.isNull()) return;
  1188. // Open the inventory and select the first item we added.
  1189. LLFloaterInventory* floaterp = LLFloaterInventory::getActiveFloater();
  1190. if (floaterp)
  1191. {
  1192. floaterp->getPanel()->setSelection(first_item_id, TAKE_FOCUS_NO);
  1193. }
  1194. }
  1195. void LLAgentWearables::addWearableToAgentInventory(LLPointer<LLInventoryCallback> cb,
  1196. LLViewerWearable* wearable,
  1197. const LLUUID& category_id,
  1198. bool) // unused: remove ?
  1199. {
  1200. create_inventory_item(category_id, wearable->getTransactionID(),
  1201. wearable->getName(), wearable->getDescription(),
  1202. wearable->getAssetType(),
  1203. LLInventoryType::IT_WEARABLE,
  1204. (U8)wearable->getType(),
  1205. wearable->getPermissions().getMaskNextOwner(), cb);
  1206. }
  1207. void LLAgentWearables::addWearabletoAgentInventoryDone(LLWearableType::EType type,
  1208. U32 index,
  1209. const LLUUID& item_id,
  1210. LLViewerWearable* wearable)
  1211. {
  1212. llinfos << "type " << type << " index " << index << " item "
  1213. << item_id.asString() << llendl;
  1214. if (item_id.isNull())
  1215. {
  1216. return;
  1217. }
  1218. const LLUUID& old_item_id = getWearableItemID(type, index);
  1219. if (wearable)
  1220. {
  1221. wearable->setItemID(item_id);
  1222. if (old_item_id.notNull())
  1223. {
  1224. gInventory.addChangedMask(LLInventoryObserver::LABEL, old_item_id);
  1225. setWearable(type, index, wearable);
  1226. }
  1227. else
  1228. {
  1229. pushWearable(type, wearable);
  1230. }
  1231. }
  1232. gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id);
  1233. LLViewerInventoryItem* item = gInventory.getItem(item_id);
  1234. if (item && wearable)
  1235. {
  1236. // We're changing the asset id, so we both need to set it
  1237. // locally via setAssetUUID() and via setTransactionID() which
  1238. // will be decoded on the server. JC
  1239. item->setAssetUUID(wearable->getAssetID());
  1240. item->setTransactionID(wearable->getTransactionID());
  1241. gInventory.addChangedMask(LLInventoryObserver::INTERNAL, item_id);
  1242. item->updateServer(false);
  1243. }
  1244. gInventory.notifyObservers();
  1245. }
  1246. void LLAgentWearables::removeWearable(LLWearableType::EType type,
  1247. bool do_remove_all, U32 index)
  1248. {
  1249. //MK
  1250. if (gRLenabled && !gRLInterface.canUnwear(type))
  1251. {
  1252. return;
  1253. }
  1254. //mk
  1255. U32 count = getWearableCount(type);
  1256. #if LL_TEEN_WERABLE_RESTRICTIONS
  1257. bool is_teen_and_underwear = gAgent.isTeen() &&
  1258. (type == LLWearableType::WT_UNDERSHIRT ||
  1259. type == LLWearableType::WT_UNDERPANTS);
  1260. if (count == 0 || (is_teen_and_underwear && count == 1))
  1261. #else
  1262. if (count == 0)
  1263. #endif
  1264. {
  1265. // No wearable to remove or teen trying to remove their last underwear
  1266. return;
  1267. }
  1268. if (do_remove_all)
  1269. {
  1270. #if LL_TEEN_WERABLE_RESTRICTIONS
  1271. if (is_teen_and_underwear)
  1272. {
  1273. // Remove all but one layer
  1274. for (U32 index = count - 1; index > 0; --index)
  1275. {
  1276. removeWearableFinal(type, false, index);
  1277. }
  1278. }
  1279. else
  1280. #endif
  1281. {
  1282. removeWearableFinal(type, true, 0);
  1283. }
  1284. }
  1285. else
  1286. {
  1287. LLViewerWearable* old_wearable = getViewerWearable(type, index);
  1288. if (old_wearable)
  1289. {
  1290. if (old_wearable->isDirty())
  1291. {
  1292. LLSD payload;
  1293. payload["wearable_type"] = (S32)type;
  1294. payload["wearable_index"] = (S32)index;
  1295. // Bring up view-modal dialog: Save changes? Yes, No, Cancel
  1296. gNotifications.add("WearableSave", LLSD(), payload,
  1297. onRemoveWearableDialog);
  1298. return;
  1299. }
  1300. else
  1301. {
  1302. removeWearableFinal(type, do_remove_all, index);
  1303. }
  1304. }
  1305. }
  1306. }
  1307. //static
  1308. bool LLAgentWearables::onRemoveWearableDialog(const LLSD& notification,
  1309. const LLSD& response)
  1310. {
  1311. S32 option = LLNotification::getSelectedOption(notification, response);
  1312. LLWearableType::EType type =
  1313. (LLWearableType::EType)notification["payload"]["wearable_type"].asInteger();
  1314. S32 index = (S32)notification["payload"]["wearable_index"].asInteger();
  1315. switch (option)
  1316. {
  1317. case 0: // "Save"
  1318. gAgentWearables.saveWearable(type, index);
  1319. gAgentWearables.removeWearableFinal(type, false, index);
  1320. break;
  1321. case 1: // "Don't Save"
  1322. gAgentWearables.removeWearableFinal(type, false, index);
  1323. break;
  1324. case 2: // "Cancel"
  1325. break;
  1326. default:
  1327. llassert(0);
  1328. break;
  1329. }
  1330. return false;
  1331. }
  1332. // Called by removeWearable() and onRemoveWearableDialog() to actually do the
  1333. // removal.
  1334. void LLAgentWearables::removeWearableFinal(LLWearableType::EType type,
  1335. bool do_remove_all,
  1336. U32 index)
  1337. {
  1338. LLViewerWearable* old_wearable;
  1339. if (do_remove_all)
  1340. {
  1341. //MK
  1342. bool all_removed = true;
  1343. //mk
  1344. S32 max_entry = getWearableCount(type) - 1;
  1345. for (S32 i = max_entry; i >= 0; --i)
  1346. {
  1347. old_wearable = getViewerWearable(type, i);
  1348. if (old_wearable)
  1349. {
  1350. //MK
  1351. if (gRLenabled)
  1352. {
  1353. LLViewerInventoryItem* old_item;
  1354. old_item = gInventory.getItem(old_wearable->getItemID());
  1355. if (old_item && !gRLInterface.canUnwear(old_item))
  1356. {
  1357. all_removed = false;
  1358. continue;
  1359. }
  1360. }
  1361. //mk
  1362. eraseWearable(old_wearable);
  1363. old_wearable->removeFromAvatar(true);
  1364. }
  1365. }
  1366. //MK
  1367. if (all_removed)
  1368. //mk
  1369. {
  1370. clearWearableType(type);
  1371. }
  1372. }
  1373. else
  1374. {
  1375. old_wearable = getViewerWearable(type, index);
  1376. if (old_wearable)
  1377. {
  1378. //MK
  1379. if (gRLenabled)
  1380. {
  1381. LLViewerInventoryItem* old_item;
  1382. old_item = gInventory.getItem(old_wearable->getItemID());
  1383. if (old_item && !gRLInterface.canUnwear(old_item))
  1384. {
  1385. return;
  1386. }
  1387. }
  1388. //mk
  1389. eraseWearable(old_wearable);
  1390. old_wearable->removeFromAvatar(true);
  1391. }
  1392. }
  1393. //MK
  1394. if (gRLenabled)
  1395. {
  1396. std::string layer = gRLInterface.getOutfitLayerAsString(type);
  1397. if (!layer.empty())
  1398. {
  1399. gRLInterface.notify("unworn legally " + layer);
  1400. }
  1401. }
  1402. //mk
  1403. queryWearableCache();
  1404. // Update the server
  1405. updateServer();
  1406. if (gFloaterCustomizep)
  1407. {
  1408. gFloaterCustomizep->updateWearableType(type, NULL);
  1409. }
  1410. }
  1411. // Assumes existing wearables are not dirty.
  1412. void LLAgentWearables::setWearableOutfit(const LLInventoryItem::item_array_t& items,
  1413. const std::vector<LLViewerWearable*>& wearables,
  1414. bool remove)
  1415. {
  1416. LL_DEBUGS("Wearables") << "setWearableOutfit() start" << LL_ENDL;
  1417. S32 i;
  1418. S32 count = wearables.size();
  1419. if (count == 0) return;
  1420. llassert((S32)items.size() == count);
  1421. mIsSettingOutfit = true;
  1422. // Keep track of all worn AT_BODYPART wearables that are to be replaced
  1423. // with a new bodypart of the same type, so that we can remove them prior
  1424. // to wearing the new ones (removing the replaced body parts must be done
  1425. // to avoid seeing removed items still flagged as "worn" (label in bold)
  1426. // in the inventory when they are copies of the newly worn body part (e.g.
  1427. // when you have a copy of the same eyes in the newly worn outfit folder
  1428. // as the eyes you were wearing before).
  1429. // Also check for duplicate body parts (so to wear only one of each type),
  1430. // scanning backwards to stay compatible with older viewers behaviour as
  1431. // to which duplicate part will actually be worn in the end.
  1432. std::set<LLWearableType::EType> new_bodyparts;
  1433. std::set<S32> skip_wearable;
  1434. bool changing_shape = false;
  1435. for (i = count - 1; i >= 0; --i)
  1436. {
  1437. LLWearableType::EType type = wearables[i]->getType();
  1438. if (LLWearableType::getAssetType(type) == LLAssetType::AT_BODYPART)
  1439. {
  1440. if (new_bodyparts.count(type) ||
  1441. //MK
  1442. (gRLenabled && !gRLInterface.canUnwear(type)))
  1443. //mk
  1444. {
  1445. // Do not try and wear two body parts of the same type
  1446. // or to replace a body part that RestrainedLove locked
  1447. skip_wearable.insert(i);
  1448. }
  1449. else
  1450. {
  1451. // Keep track of what body part type is present in the new
  1452. // outift we are going to wear
  1453. new_bodyparts.insert(type);
  1454. if (type == LLWearableType::WT_SHAPE)
  1455. {
  1456. changing_shape = true;
  1457. }
  1458. }
  1459. }
  1460. }
  1461. // Before changing the shape, do reset all rigged meshes joint offsets
  1462. if (changing_shape && isAgentAvatarValid())
  1463. {
  1464. gAgentAvatarp->clearAttachmentOverrides();
  1465. }
  1466. // When remove == true, this loop removes all clothing.
  1467. // Note that removeWearable() will also take care of checking whether
  1468. // the items can actually be removed (for teens and underwear, and for
  1469. // RestrainedLove locked items).
  1470. // It also always removes the body parts that will be replaced with the new
  1471. // wearables.
  1472. for (i = 0; i < (S32)LLWearableType::WT_COUNT; ++i)
  1473. {
  1474. LLWearableType::EType type = (LLWearableType::EType)i;
  1475. if (new_bodyparts.count(type) ||
  1476. (remove &&
  1477. LLWearableType::getAssetType(type) == LLAssetType::AT_CLOTHING))
  1478. {
  1479. removeWearable(type, true, 0);
  1480. }
  1481. }
  1482. bool no_multiple_physics = gSavedSettings.getBool("NoMultiplePhysics");
  1483. bool no_multiple_shoes = gSavedSettings.getBool("NoMultipleShoes");
  1484. bool no_multiple_skirts = gSavedSettings.getBool("NoMultipleSkirts");
  1485. for (i = 0; i < count; ++i)
  1486. {
  1487. if (skip_wearable.count(i)) continue;
  1488. LLViewerWearable* new_wearable = wearables[i];
  1489. LLPointer<LLInventoryItem> new_item = items[i];
  1490. llassert(new_wearable);
  1491. if (new_wearable)
  1492. {
  1493. bool success = false;
  1494. LLWearableType::EType type = new_wearable->getType();
  1495. new_wearable->setName(new_item->getName());
  1496. new_wearable->setItemID(new_item->getUUID());
  1497. if (((no_multiple_physics && type == LLWearableType::WT_PHYSICS) ||
  1498. (no_multiple_shoes && type == LLWearableType::WT_SHOES) ||
  1499. (no_multiple_skirts && type == LLWearableType::WT_SKIRT) ||
  1500. LLWearableType::getAssetType(type) == LLAssetType::AT_BODYPART))
  1501. {
  1502. // exactly one wearable per body part, or per Physics, or per
  1503. // cloth types which combination is confusing to the user
  1504. success = setWearable(type, 0, new_wearable);
  1505. }
  1506. else if (!canAddWearable(type))
  1507. {
  1508. llwarns_once << "Attempted to wear more than "
  1509. << MAX_CLOTHING_LAYERS << " wearables" << llendl;
  1510. continue;
  1511. }
  1512. else
  1513. {
  1514. success = pushWearable(type, new_wearable);
  1515. }
  1516. wearableUpdated(new_wearable, false);
  1517. //MK
  1518. if (success && gRLenabled)
  1519. {
  1520. // Notify that this layer has been worn
  1521. std::string layer = gRLInterface.getOutfitLayerAsString(type);
  1522. gRLInterface.notify("worn legally " + layer);
  1523. }
  1524. //mk
  1525. }
  1526. }
  1527. mIsSettingOutfit = false;
  1528. if (isAgentAvatarValid())
  1529. {
  1530. gAgentAvatarp->setCompositeUpdatesEnabled(true);
  1531. if (!gAgentAvatarp->getIsCloud())
  1532. {
  1533. // If we have not yet declouded, we may want to use baked texture
  1534. // UUIDs sent from the first objectUpdate message don't overwrite
  1535. // these. If we have already declouded, we've saved these ids as
  1536. // the last known good textures and can invalidate without
  1537. // re-clouding.
  1538. gAgentAvatarp->invalidateAll();
  1539. }
  1540. // Copy wearable params to avatar.
  1541. gAgentAvatarp->writeWearablesToAvatar();
  1542. // Then update the avatar based on the copied params.
  1543. gAgentAvatarp->updateVisualParams();
  1544. // After changing the shape, restore all rigged meshes joint offsets
  1545. if (changing_shape)
  1546. {
  1547. gAgentAvatarp->rebuildAttachmentOverrides();
  1548. }
  1549. }
  1550. // Start rendering & update the server
  1551. mWearablesLoaded = true;
  1552. queryWearableCache();
  1553. updateServer();
  1554. bool dump_outfit = false;
  1555. LL_DEBUGS("Wearables") << "New outfit dump:";
  1556. dump_outfit = isAgentAvatarValid();
  1557. LL_CONT << LL_ENDL;
  1558. if (dump_outfit)
  1559. {
  1560. gAgentAvatarp->dumpAvatarTEs("setWearableOutfit");
  1561. }
  1562. }
  1563. // User has picked "wear" from a menu and this function gets called from the
  1564. // LLWearableBridge::onWearOnAvatarArrived() callback.
  1565. // NOTE: we used to check for a dirty old wearable here, when replacing the
  1566. // latter with a new one (do_append == false), but this implied setting up
  1567. // a notification callback within this function which is itself a callback,
  1568. // and very bad things were happening (among which crashes)... That check
  1569. // and also all checks related with RestrainedLove restrictions were therefore
  1570. // moved to LLAppearanceMgr::wearItemOnAvatar(). HB.
  1571. void LLAgentWearables::setWearableItem(LLInventoryItem* new_item,
  1572. LLViewerWearable* new_wearable,
  1573. bool do_append)
  1574. {
  1575. if (isWearingItem(new_item->getUUID()))
  1576. {
  1577. llwarns << "Wearable " << new_item->getUUID() << " is already worn"
  1578. << llendl;
  1579. return;
  1580. }
  1581. const LLWearableType::EType type = new_wearable->getType();
  1582. if (!do_append)
  1583. {
  1584. // Check old wearable, if any. MULTI_WEARABLE: hardwired to 0
  1585. LLViewerWearable* old_wearable = getViewerWearable(type, 0);
  1586. if (old_wearable)
  1587. {
  1588. const LLUUID& old_item_id = old_wearable->getItemID();
  1589. if (old_wearable->getAssetID() == new_wearable->getAssetID() &&
  1590. old_item_id == new_item->getUUID())
  1591. {
  1592. LL_DEBUGS("Wearables") << "No change to wearable asset and item: "
  1593. << LLWearableType::getTypeName(type)
  1594. << LL_ENDL;
  1595. return;
  1596. }
  1597. }
  1598. }
  1599. setWearableFinal(new_item, new_wearable, do_append);
  1600. }
  1601. // Called from setWearableItem() and onSetWearableDialog() to actually set the
  1602. // wearable.
  1603. // MULTI_WEARABLE: unify code after null objects are gone.
  1604. void LLAgentWearables::setWearableFinal(LLInventoryItem* new_item,
  1605. LLViewerWearable* new_wearable,
  1606. bool do_append)
  1607. {
  1608. const LLWearableType::EType type = new_wearable->getType();
  1609. // Before changing the shape, do reset all rigged meshes joint offsets
  1610. bool reset_joints = type == LLWearableType::WT_SHAPE;
  1611. if (reset_joints && isAgentAvatarValid())
  1612. {
  1613. gAgentAvatarp->clearAttachmentOverrides();
  1614. }
  1615. mIsSettingOutfit = true;
  1616. if (type == LLWearableType::WT_SHAPE || type == LLWearableType::WT_SKIN ||
  1617. type == LLWearableType::WT_HAIR || type == LLWearableType::WT_EYES)
  1618. {
  1619. // Can't wear more than one body part of each type
  1620. do_append = false;
  1621. }
  1622. bool success = false;
  1623. if (do_append && getWearableItemID(type, 0).notNull())
  1624. {
  1625. new_wearable->setItemID(new_item->getUUID());
  1626. success = pushWearable(type, new_wearable, false);
  1627. llinfos << "Added additional wearable for type " << type
  1628. << " size is now " << getWearableCount(type) << llendl;
  1629. if (gFloaterCustomizep)
  1630. {
  1631. gFloaterCustomizep->updateWearableType(type, new_wearable);
  1632. }
  1633. }
  1634. else
  1635. {
  1636. // Replace the old wearable with a new one.
  1637. llassert(new_item->getAssetUUID() == new_wearable->getAssetID());
  1638. LLViewerWearable* old_wearable = getViewerWearable(type, 0);
  1639. LLUUID old_item_id;
  1640. if (old_wearable)
  1641. {
  1642. old_item_id = old_wearable->getItemID();
  1643. }
  1644. new_wearable->setItemID(new_item->getUUID());
  1645. success = setWearable(type, 0, new_wearable);
  1646. if (old_item_id.notNull())
  1647. {
  1648. gInventory.addChangedMask(LLInventoryObserver::LABEL, old_item_id);
  1649. gInventory.notifyObservers();
  1650. }
  1651. LL_DEBUGS("Wearables") << "Replaced current element 0 for type "
  1652. << type << " size is now "
  1653. << getWearableCount(type) << LL_ENDL;
  1654. }
  1655. //MK
  1656. if (success && gRLenabled)
  1657. {
  1658. // Notify that this layer has been worn
  1659. std::string layer = gRLInterface.getOutfitLayerAsString(type);
  1660. gRLInterface.notify("worn legally " + layer);
  1661. }
  1662. //mk
  1663. mIsSettingOutfit = false;
  1664. if (isAgentAvatarValid())
  1665. {
  1666. gAgentAvatarp->setCompositeUpdatesEnabled(true);
  1667. // Copy wearable params to avatar.
  1668. gAgentAvatarp->writeWearablesToAvatar();
  1669. // Then update the avatar based on the copied params.
  1670. gAgentAvatarp->updateVisualParams();
  1671. if (!gAgentAvatarp->getIsCloud())
  1672. {
  1673. // If we have not yet declouded, we may want to use baked texture
  1674. // UUIDs sent from the first objectUpdate message don't overwrite
  1675. // these. If we have already declouded, we've saved these ids as
  1676. // the last known good textures and can invalidate without
  1677. // re-clouding.
  1678. gAgentAvatarp->invalidateAll();
  1679. }
  1680. // After changing the shape, restore all rigged meshes joint offsets
  1681. if (reset_joints)
  1682. {
  1683. gAgentAvatarp->rebuildAttachmentOverrides();
  1684. }
  1685. }
  1686. queryWearableCache();
  1687. updateServer();
  1688. }
  1689. void LLAgentWearables::queryWearableCache()
  1690. {
  1691. if (!areWearablesLoaded() || LLVOAvatarSelf::canUseServerBaking())
  1692. {
  1693. return;
  1694. }
  1695. if (isAgentAvatarValid())
  1696. {
  1697. gAgentAvatarp->setIsUsingServerBakes(false);
  1698. }
  1699. // Look up affected baked textures.
  1700. // If they exist:
  1701. // - Disallow updates for affected layersets (until dataserver responds
  1702. // with cache request).
  1703. // - If cache miss, turn updates back on and invalidate composite.
  1704. // - If cache hit, modify baked texture entries.
  1705. //
  1706. // Cache requests contain list of hashes for each baked texture entry.
  1707. // Response is list of valid baked texture assets. (same message)
  1708. LLMessageSystem* msg = gMessageSystemp;
  1709. msg->newMessageFast(_PREHASH_AgentCachedTexture);
  1710. msg->nextBlockFast(_PREHASH_AgentData);
  1711. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  1712. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  1713. msg->addS32Fast(_PREHASH_SerialNum,
  1714. gAgentQueryManager.mWearablesCacheQueryID);
  1715. S32 num_queries = 0;
  1716. for (U8 bake_idx = 0; bake_idx < gAgent.mUploadedBakes; ++bake_idx)
  1717. {
  1718. LLUUID hash_id =
  1719. computeBakedTextureHash((EBakedTextureIndex)bake_idx);
  1720. if (hash_id.notNull())
  1721. {
  1722. ++num_queries;
  1723. // *NOTE: make sure at least one request gets packed
  1724. ETextureIndex te_index =
  1725. LLAvatarAppearanceDictionary::bakedToLocalTextureIndex((EBakedTextureIndex)bake_idx);
  1726. msg->nextBlockFast(_PREHASH_WearableData);
  1727. msg->addUUIDFast(_PREHASH_ID, hash_id);
  1728. msg->addU8Fast(_PREHASH_TextureIndex, (U8)te_index);
  1729. }
  1730. gAgentQueryManager.mActiveCacheQueries[bake_idx] =
  1731. gAgentQueryManager.mWearablesCacheQueryID;
  1732. }
  1733. // VWR-22113: gAgent.getRegion() can return null if invalid, seen here on
  1734. // logout
  1735. if (gAgent.getRegion())
  1736. {
  1737. llinfos << "Requesting texture cache entry for " << num_queries
  1738. << " baked textures" << llendl;
  1739. msg->sendReliable(gAgent.getRegionHost());
  1740. ++gAgentQueryManager.mNumPendingQueries;
  1741. ++gAgentQueryManager.mWearablesCacheQueryID;
  1742. }
  1743. }
  1744. // virtual
  1745. void LLAgentWearables::invalidateBakedTextureHash(LLMD5& hash) const
  1746. {
  1747. // Add some garbage into the hash so that it becomes invalid.
  1748. if (isAgentAvatarValid())
  1749. {
  1750. hash.update((const unsigned char*)gAgentAvatarp->getID().mData,
  1751. UUID_BYTES);
  1752. }
  1753. }
  1754. // User has picked "remove from avatar" from a menu.
  1755. //static
  1756. void LLAgentWearables::userRemoveWearable(LLWearableType::EType type, U32 idx)
  1757. {
  1758. if (type != LLWearableType::WT_SHAPE && type != LLWearableType::WT_SKIN &&
  1759. type != LLWearableType::WT_HAIR && type != LLWearableType::WT_EYES)
  1760. {
  1761. gAgentWearables.removeWearable(type, false, idx);
  1762. }
  1763. }
  1764. //static
  1765. void LLAgentWearables::userRemoveWearablesOfType(LLWearableType::EType type)
  1766. {
  1767. if (type != LLWearableType::WT_SHAPE && type != LLWearableType::WT_SKIN &&
  1768. type != LLWearableType::WT_HAIR && type != LLWearableType::WT_EYES)
  1769. {
  1770. gAgentWearables.removeWearable(type, true, 0);
  1771. }
  1772. }
  1773. void LLAgentWearables::userRemoveAllClothes()
  1774. {
  1775. // We have to do this up front to avoid having to deal with the case of
  1776. // multiple wearables being dirty.
  1777. if (gFloaterCustomizep)
  1778. {
  1779. gFloaterCustomizep->askToSaveIfDirty(userRemoveAllClothesStep2, NULL);
  1780. }
  1781. else
  1782. {
  1783. userRemoveAllClothesStep2(true, NULL);
  1784. }
  1785. }
  1786. void LLAgentWearables::userRemoveAllClothesStep2(bool proceed, void*)
  1787. {
  1788. if (proceed)
  1789. {
  1790. gAgentWearables.userRemoveWearablesOfType(LLWearableType::WT_SHIRT);
  1791. gAgentWearables.userRemoveWearablesOfType(LLWearableType::WT_PANTS);
  1792. gAgentWearables.userRemoveWearablesOfType(LLWearableType::WT_SHOES);
  1793. gAgentWearables.userRemoveWearablesOfType(LLWearableType::WT_SOCKS);
  1794. gAgentWearables.userRemoveWearablesOfType(LLWearableType::WT_JACKET);
  1795. gAgentWearables.userRemoveWearablesOfType(LLWearableType::WT_GLOVES);
  1796. gAgentWearables.userRemoveWearablesOfType(LLWearableType::WT_UNDERSHIRT);
  1797. gAgentWearables.userRemoveWearablesOfType(LLWearableType::WT_UNDERPANTS);
  1798. gAgentWearables.userRemoveWearablesOfType(LLWearableType::WT_SKIRT);
  1799. gAgentWearables.userRemoveWearablesOfType(LLWearableType::WT_ALPHA);
  1800. gAgentWearables.userRemoveWearablesOfType(LLWearableType::WT_TATTOO);
  1801. }
  1802. }
  1803. void LLAgentWearables::userRemoveMultipleAttachments(llvo_vec_t& objects_to_remove)
  1804. {
  1805. if (!isAgentAvatarValid()) return;
  1806. if (objects_to_remove.empty())
  1807. {
  1808. return;
  1809. }
  1810. LLMessageSystem* msg = gMessageSystemp;
  1811. msg->newMessage("ObjectDetach");
  1812. msg->nextBlockFast(_PREHASH_AgentData);
  1813. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  1814. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  1815. for (llvo_vec_t::iterator it = objects_to_remove.begin(),
  1816. end = objects_to_remove.end();
  1817. it != end; ++it)
  1818. {
  1819. LLViewerObject* objectp = *it;
  1820. //MK
  1821. if (gRLenabled && !gRLInterface.canDetach(objectp))
  1822. {
  1823. continue;
  1824. }
  1825. //mk
  1826. msg->nextBlockFast(_PREHASH_ObjectData);
  1827. msg->addU32Fast(_PREHASH_ObjectLocalID, objectp->getLocalID());
  1828. }
  1829. msg->sendReliable(gAgent.getRegionHost());
  1830. }
  1831. void LLAgentWearables::userRemoveAllAttachments(bool only_temp_attach)
  1832. {
  1833. if (!isAgentAvatarValid()) return;
  1834. llvo_vec_t objects_to_remove;
  1835. for (S32 i = 0, count = gAgentAvatarp->mAttachedObjectsVector.size();
  1836. i < count; ++i)
  1837. {
  1838. LLViewerObject* object =
  1839. gAgentAvatarp->mAttachedObjectsVector[i].first;
  1840. if (!object) continue; // Paranoia
  1841. if (!only_temp_attach ||
  1842. (only_temp_attach && object->isTempAttachment()))
  1843. {
  1844. objects_to_remove.push_back(object);
  1845. }
  1846. }
  1847. userRemoveMultipleAttachments(objects_to_remove);
  1848. }
  1849. void LLAgentWearables::userAttachMultipleAttachments(LLInventoryModel::item_array_t& objects)
  1850. {
  1851. if (!gAgent.getRegion()) return;
  1852. // Build a compound message to send all the objects that need to be rezzed.
  1853. S32 obj_count = objects.size();
  1854. // Limit number of packets to send
  1855. constexpr S32 MAX_PACKETS_TO_SEND = 10;
  1856. constexpr S32 OBJECTS_PER_PACKET = 4;
  1857. constexpr S32 MAX_OBJECTS_TO_SEND = MAX_PACKETS_TO_SEND *
  1858. OBJECTS_PER_PACKET;
  1859. if (obj_count > MAX_OBJECTS_TO_SEND)
  1860. {
  1861. obj_count = MAX_OBJECTS_TO_SEND;
  1862. }
  1863. // Create an id to keep the parts of the compound message together
  1864. LLUUID compound_msg_id;
  1865. compound_msg_id.generate();
  1866. LLMessageSystem* msg = gMessageSystemp;
  1867. for (S32 i = 0; i < obj_count; ++i)
  1868. {
  1869. if (i % OBJECTS_PER_PACKET == 0)
  1870. {
  1871. // Start a new message chunk
  1872. msg->newMessageFast(_PREHASH_RezMultipleAttachmentsFromInv);
  1873. msg->nextBlockFast(_PREHASH_AgentData);
  1874. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  1875. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  1876. msg->nextBlockFast(_PREHASH_HeaderData);
  1877. msg->addUUIDFast(_PREHASH_CompoundMsgID, compound_msg_id);
  1878. msg->addU8Fast(_PREHASH_TotalObjects, obj_count);
  1879. msg->addBoolFast(_PREHASH_FirstDetachAll, false);
  1880. }
  1881. const LLInventoryItem* item = objects[i].get();
  1882. msg->nextBlockFast(_PREHASH_ObjectData);
  1883. msg->addUUIDFast(_PREHASH_ItemID, item->getLinkedUUID());
  1884. msg->addUUIDFast(_PREHASH_OwnerID, item->getPermissions().getOwner());
  1885. // Wear at the previous or default attachment point:
  1886. msg->addU8Fast(_PREHASH_AttachmentPt, 0 | ATTACHMENT_ADD);
  1887. pack_permissions_slam(msg, item->getFlags(), item->getPermissions());
  1888. msg->addStringFast(_PREHASH_Name, item->getName());
  1889. msg->addStringFast(_PREHASH_Description, item->getDescription());
  1890. if (obj_count == i + 1 ||
  1891. i % OBJECTS_PER_PACKET == OBJECTS_PER_PACKET - 1)
  1892. {
  1893. // End of message chunk
  1894. msg->sendReliable(gAgent.getRegionHost());
  1895. }
  1896. }
  1897. }
  1898. // Returns false if the given wearable is already topmost/bottommost
  1899. // (depending on closer_to_body parameter).
  1900. bool LLAgentWearables::canMoveWearable(const LLUUID& item_id,
  1901. bool closer_to_body) const
  1902. {
  1903. const LLWearable* wearable = getWearableFromItemID(item_id);
  1904. if (!wearable) return false;
  1905. LLWearableType::EType wtype = wearable->getType();
  1906. const LLWearable* marginal_wearable = closer_to_body ? getBottomWearable(wtype)
  1907. : getTopWearable(wtype);
  1908. return marginal_wearable && wearable != marginal_wearable;
  1909. }
  1910. bool LLAgentWearables::areWearablesLoaded() const
  1911. {
  1912. return mWearablesLoaded;
  1913. }
  1914. // MULTI-WEARABLE: DEPRECATED: item pending count relies on old messages that
  1915. // don't support multi-wearables. do not trust to be accurate
  1916. void LLAgentWearables::updateWearablesLoaded()
  1917. {
  1918. mWearablesLoaded = true;
  1919. for (S32 i = 0; i < LLWearableType::WT_COUNT; ++i)
  1920. {
  1921. if (getWearableItemID((LLWearableType::EType)i, 0).notNull() &&
  1922. !getViewerWearable((LLWearableType::EType)i, 0))
  1923. {
  1924. mWearablesLoaded = false;
  1925. break;
  1926. }
  1927. }
  1928. LL_DEBUGS("Wearables") << "mWearablesLoaded = " << mWearablesLoaded
  1929. << LL_ENDL;
  1930. }
  1931. bool LLAgentWearables::canWearableBeRemoved(const LLViewerWearable* wearable) const
  1932. {
  1933. if (!wearable) return false;
  1934. LLWearableType::EType type = wearable->getType();
  1935. //MK
  1936. if (gRLenabled && !gRLInterface.canUnwear(type))
  1937. {
  1938. return false;
  1939. }
  1940. //mk
  1941. // Make sure the user always has at least one shape, skin, eyes, and hair
  1942. // type currently worn.
  1943. return getWearableCount(type) > 1 ||
  1944. (type != LLWearableType::WT_SHAPE &&
  1945. type != LLWearableType::WT_SKIN &&
  1946. type != LLWearableType::WT_HAIR &&
  1947. type != LLWearableType::WT_EYES);
  1948. }
  1949. void LLAgentWearables::animateAllWearableParams(F32 delta, bool upload_bake)
  1950. {
  1951. for (S32 type = 0; type < LLWearableType::WT_COUNT; ++type)
  1952. {
  1953. for (S32 count = 0,
  1954. total = getWearableCount((LLWearableType::EType)type);
  1955. count < total; ++count)
  1956. {
  1957. LLViewerWearable* wearable =
  1958. getViewerWearable((LLWearableType::EType)type, count);
  1959. if (wearable)
  1960. {
  1961. wearable->animateParams(delta, upload_bake);
  1962. }
  1963. }
  1964. }
  1965. }
  1966. void LLAgentWearables::updateServer()
  1967. {
  1968. sendAgentWearablesUpdate();
  1969. gAgent.sendAgentSetAppearance();
  1970. gInventory.notifyObservers();
  1971. // Ensure the new outfit will be saved
  1972. gWearablesListDirty = true;
  1973. // Notify the Make new outfit floater, if opened
  1974. HBFloaterMakeNewOutfit::setDirty();
  1975. }