llviewerparcelmgr.cpp 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308
  1. /**
  2. * @file llviewerparcelmgr.cpp
  3. * @brief Viewer-side representation of owned land
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, 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 "llviewerparcelmgr.h"
  34. #include "llaudioengine.h"
  35. #include "llcachename.h"
  36. #include "llcorehttputil.h"
  37. #include "llgl.h"
  38. #include "llnotifications.h"
  39. #include "llregionhandle.h"
  40. #include "llsdutil.h"
  41. #include "llsdutil_math.h"
  42. #include "llmessage.h"
  43. #include "roles_constants.h"
  44. #include "llagent.h"
  45. #include "llappviewer.h" // For gDisconnected
  46. #include "llenvironment.h"
  47. #include "llfloaterbuyland.h"
  48. #include "llfloatersellland.h"
  49. //MK
  50. #include "mkrlinterface.h"
  51. //mk
  52. #include "llstatusbar.h"
  53. #include "llsurface.h"
  54. #include "llviewercontrol.h"
  55. #include "llviewerparcelmedia.h"
  56. #include "llviewerparceloverlay.h"
  57. #include "llviewerregion.h"
  58. #include "llviewertexturelist.h"
  59. #include "llworld.h"
  60. constexpr F32 PARCEL_COLLISION_DRAW_SECS = 1.f;
  61. constexpr U8 EAST_MASK = 0x1 << EAST;
  62. constexpr U8 NORTH_MASK = 0x1 << NORTH;
  63. constexpr U8 WEST_MASK = 0x1 << WEST;
  64. constexpr U8 SOUTH_MASK = 0x1 << SOUTH;
  65. // Global variables
  66. LLViewerParcelMgr gViewerParcelMgr;
  67. LLUUID gCurrentMovieID;
  68. // Static variables
  69. U8* LLViewerParcelMgr::sPackedOverlay = NULL;
  70. LLPointer<LLViewerTexture> sBlockedImage;
  71. LLPointer<LLViewerTexture> sPassImage;
  72. LLViewerParcelMgr::LLViewerParcelMgr()
  73. : mSelected(false),
  74. mRequestResult(0),
  75. mSelectedDwell(DWELL_NAN),
  76. mAgentParcelSequenceID(-1),
  77. mHoverRequestResult(0),
  78. mRenderCollision(false),
  79. mRenderSelection(true),
  80. mCollisionBanned(0),
  81. mParcelsPerEdge((S32)(REGION_WIDTH_METERS / PARCEL_GRID_STEP_METERS)),
  82. mCurrentParcel(NULL),
  83. mCurrentParcelSelection(NULL),
  84. mFloatingParcelSelection(NULL),
  85. mAgentParcel(NULL),
  86. mHoverParcel(NULL),
  87. mCollisionParcel(NULL),
  88. mHighlightSegments(NULL),
  89. mCollisionSegments(NULL),
  90. mBlockedImage(NULL),
  91. mPassImage(NULL),
  92. mAgentParcelOverlay(NULL),
  93. // The initial parcel update is treated like teleport:
  94. mTeleportInProgress(true)
  95. {
  96. }
  97. void LLViewerParcelMgr::initClass()
  98. {
  99. mCurrentParcel = new LLParcel();
  100. mCurrentParcelSelection = new LLParcelSelection(mCurrentParcel);
  101. mFloatingParcelSelection = new LLParcelSelection(mCurrentParcel);
  102. mAgentParcel = new LLParcel();
  103. mHoverParcel = new LLParcel();
  104. mCollisionParcel = new LLParcel();
  105. mBlockedImage =
  106. LLViewerTextureManager::getFetchedTextureFromFile("noentrylines.j2c");
  107. mPassImage =
  108. LLViewerTextureManager::getFetchedTextureFromFile("noentrypasslines.j2c");
  109. // Variable region size support: 8192 is the maximum width for a region, so
  110. // let's allocate enough room for that...
  111. mParcelsPerEdge = (S32)(8192.f / PARCEL_GRID_STEP_METERS);
  112. S32 segments = (mParcelsPerEdge + 1) * (mParcelsPerEdge + 1);
  113. mHighlightSegments = new U8[segments];
  114. resetSegments(mHighlightSegments);
  115. mCollisionSegments = new U8[segments];
  116. resetSegments(mCollisionSegments);
  117. segments = mParcelsPerEdge * mParcelsPerEdge;
  118. sPackedOverlay = new U8[segments / PARCEL_OVERLAY_CHUNKS];
  119. mAgentParcelOverlay = new U8[segments];
  120. for (S32 i = 0; i < segments; ++i)
  121. {
  122. mAgentParcelOverlay[i] = 0;
  123. }
  124. mParcelsPerEdge = S32(REGION_WIDTH_METERS / PARCEL_GRID_STEP_METERS);
  125. llinfos << "Viewer parcel manager initialized." << llendl;
  126. }
  127. void LLViewerParcelMgr::cleanupClass()
  128. {
  129. mCurrentParcelSelection->setParcel(NULL);
  130. mCurrentParcelSelection = NULL;
  131. mFloatingParcelSelection->setParcel(NULL);
  132. mFloatingParcelSelection = NULL;
  133. delete mCurrentParcel;
  134. mCurrentParcel = NULL;
  135. delete mAgentParcel;
  136. mAgentParcel = NULL;
  137. delete mCollisionParcel;
  138. mCollisionParcel = NULL;
  139. delete mHoverParcel;
  140. mHoverParcel = NULL;
  141. delete[] mHighlightSegments;
  142. mHighlightSegments = NULL;
  143. delete[] mCollisionSegments;
  144. mCollisionSegments = NULL;
  145. delete[] sPackedOverlay;
  146. sPackedOverlay = NULL;
  147. delete[] mAgentParcelOverlay;
  148. mAgentParcelOverlay = NULL;
  149. sBlockedImage = NULL;
  150. sPassImage = NULL;
  151. llinfos << "Viewer parcel manager cleaned up." << llendl;
  152. }
  153. // Variable region size support
  154. void LLViewerParcelMgr::setRegionWidth(F32 region_size)
  155. {
  156. mParcelsPerEdge = (S32)(region_size / PARCEL_GRID_STEP_METERS);
  157. }
  158. void LLViewerParcelMgr::dump()
  159. {
  160. llinfos << "Parcel manager dump" << llendl;
  161. llinfos << "Selected: " << (mSelected ? "true" : "false") << llendl;
  162. llinfos << "Selected parcel: " << llendl;
  163. llinfos << mWestSouth << " to " << mEastNorth << llendl;
  164. mCurrentParcel->dump();
  165. llinfos << "Ban list size: " << mCurrentParcel->mBanList.size() << llendl;
  166. for (access_map_t::const_iterator it = mCurrentParcel->mBanList.begin(),
  167. end = mCurrentParcel->mBanList.end();
  168. it != end; ++it)
  169. {
  170. llinfos << "Ban Id: " << it->first << llendl;
  171. }
  172. llinfos << "Hover parcel:" << llendl;
  173. mHoverParcel->dump();
  174. llinfos << "Agent parcel:" << llendl;
  175. mAgentParcel->dump();
  176. }
  177. LLViewerRegion* LLViewerParcelMgr::getSelectionRegion()
  178. {
  179. return gWorld.getRegionFromPosGlobal(mWestSouth);
  180. }
  181. void LLViewerParcelMgr::getDisplayInfo(S32* area_out, S32* claim_out,
  182. S32* rent_out, bool* for_sale_out,
  183. F32* dwell_out)
  184. {
  185. S32 area = 0;
  186. S32 price = 0;
  187. S32 rent = 0;
  188. bool for_sale = false;
  189. F32 dwell = DWELL_NAN;
  190. if (mSelected)
  191. {
  192. if (mCurrentParcelSelection->mSelectedMultipleOwners)
  193. {
  194. area = mCurrentParcelSelection->getClaimableArea();
  195. }
  196. else
  197. {
  198. area = getSelectedArea();
  199. }
  200. if (mCurrentParcel->getForSale())
  201. {
  202. price = mCurrentParcel->getSalePrice();
  203. for_sale = true;
  204. }
  205. else
  206. {
  207. price = area * mCurrentParcel->getClaimPricePerMeter();
  208. for_sale = false;
  209. }
  210. rent = mCurrentParcel->getTotalRent();
  211. dwell = mSelectedDwell;
  212. }
  213. *area_out = area;
  214. *claim_out = price;
  215. *rent_out = rent;
  216. *for_sale_out = for_sale;
  217. *dwell_out = dwell;
  218. }
  219. S32 LLViewerParcelMgr::getSelectedArea() const
  220. {
  221. if (mSelected && mCurrentParcel &&
  222. mCurrentParcelSelection->mWholeParcelSelected)
  223. {
  224. return mCurrentParcel->getArea();
  225. }
  226. if (mSelected)
  227. {
  228. F64 width = mEastNorth.mdV[VX] - mWestSouth.mdV[VX];
  229. F64 height = mEastNorth.mdV[VY] - mWestSouth.mdV[VY];
  230. F32 area = (F32)(width * height);
  231. return ll_round(area);
  232. }
  233. return 0;
  234. }
  235. void LLViewerParcelMgr::resetSegments(U8* segments)
  236. {
  237. for (S32 i = 0, count = (mParcelsPerEdge + 1) * (mParcelsPerEdge + 1);
  238. i < count; ++i)
  239. {
  240. segments[i] = 0x0;
  241. }
  242. }
  243. void LLViewerParcelMgr::writeHighlightSegments(F32 west, F32 south, F32 east,
  244. F32 north)
  245. {
  246. S32 min_x = ll_round(west / PARCEL_GRID_STEP_METERS);
  247. S32 max_x = ll_round(east / PARCEL_GRID_STEP_METERS);
  248. S32 min_y = ll_round(south / PARCEL_GRID_STEP_METERS);
  249. S32 max_y = ll_round(north / PARCEL_GRID_STEP_METERS);
  250. const S32 stride = mParcelsPerEdge + 1;
  251. // South edge
  252. for (S32 x = min_x; x < max_x; ++x)
  253. {
  254. // Exclusive OR means that writing to this segment twice will turn it
  255. // off
  256. mHighlightSegments[x + min_y * stride] ^= SOUTH_MASK;
  257. }
  258. // West edge
  259. for (S32 y = min_y; y < max_y; ++y)
  260. {
  261. mHighlightSegments[min_x + y * stride] ^= WEST_MASK;
  262. }
  263. // North edge; draw the south border on the y+1'th cell, which given
  264. // C-style arrays, is item foo[max_y]
  265. for (S32 x = min_x; x < max_x; ++x)
  266. {
  267. mHighlightSegments[x + max_y * stride] ^= SOUTH_MASK;
  268. }
  269. // East edge; draw west border on x+1'th cell
  270. for (S32 y = min_y; y < max_y; ++y)
  271. {
  272. mHighlightSegments[max_x + y * stride] ^= WEST_MASK;
  273. }
  274. }
  275. void LLViewerParcelMgr::writeSegmentsFromBitmap(U8* bitmap, U8* segments)
  276. {
  277. const S32 in_stride = mParcelsPerEdge;
  278. const S32 out_stride = in_stride + 1;
  279. for (S32 y = 0; y < in_stride; ++y)
  280. {
  281. S32 x = 0;
  282. while (x < in_stride)
  283. {
  284. U8 byte = bitmap[(x + y * in_stride) / 8];
  285. for (S32 bit = 0; bit < 8; ++bit)
  286. {
  287. if (byte & (1 << bit))
  288. {
  289. S32 out = x + y * out_stride;
  290. // This and one above it
  291. segments[out] ^= SOUTH_MASK;
  292. segments[out + out_stride] ^= SOUTH_MASK;
  293. // This and one to the right
  294. segments[out] ^= WEST_MASK;
  295. segments[out + 1] ^= WEST_MASK;
  296. }
  297. ++x;
  298. }
  299. }
  300. }
  301. }
  302. void LLViewerParcelMgr::writeAgentParcelFromBitmap(U8* bitmap)
  303. {
  304. const S32 in_stride = mParcelsPerEdge;
  305. for (S32 y = 0; y < in_stride; ++y)
  306. {
  307. S32 x = 0;
  308. while (x < in_stride)
  309. {
  310. U8 byte = bitmap[(x + y * in_stride) / 8];
  311. for (S32 bit = 0; bit < 8; ++bit)
  312. {
  313. if (byte & (1 << bit))
  314. {
  315. mAgentParcelOverlay[x + y * in_stride] = 1;
  316. }
  317. else
  318. {
  319. mAgentParcelOverlay[x + y * in_stride] = 0;
  320. }
  321. ++x;
  322. }
  323. }
  324. }
  325. }
  326. // Given a point, find the PARCEL_GRID_STEP x PARCEL_GRID_STEP block
  327. // containing it and select that.
  328. LLParcelSelectionHandle LLViewerParcelMgr::selectParcelAt(const LLVector3d& pos)
  329. {
  330. constexpr F64 witdh = (F64)PARCEL_GRID_STEP_METERS;
  331. constexpr F64 half_witdh = witdh * 0.5;
  332. LLVector3d southwest = pos - LLVector3d(half_witdh, half_witdh, 0.0);
  333. southwest.mdV[VX] = ll_round(southwest.mdV[VX], witdh);
  334. southwest.mdV[VY] = ll_round(southwest.mdV[VY], witdh);
  335. LLVector3d northeast = pos + LLVector3d(half_witdh, half_witdh, 0.0);
  336. northeast.mdV[VX] = ll_round(northeast.mdV[VX], witdh);
  337. northeast.mdV[VY] = ll_round(northeast.mdV[VY], witdh);
  338. // Snap to parcel
  339. return selectLand(southwest, northeast, true);
  340. }
  341. // Tries to select the parcel inside the rectangle
  342. LLParcelSelectionHandle LLViewerParcelMgr::selectParcelInRectangle()
  343. {
  344. return selectLand(mWestSouth, mEastNorth, true);
  345. }
  346. void LLViewerParcelMgr::resetCollisionSegments()
  347. {
  348. resetSegments(mCollisionSegments);
  349. }
  350. void LLViewerParcelMgr::selectCollisionParcel()
  351. {
  352. // *HACK: claim to be in the agent's region
  353. LLViewerRegion* regionp = gAgent.getRegion();
  354. if (!regionp) return;
  355. mWestSouth = regionp->getOriginGlobal();
  356. #if 1 // Variable region size support
  357. constexpr F64 factor = (F64)PARCEL_GRID_STEP_METERS /
  358. (F64)REGION_WIDTH_METERS;
  359. F64 width = (F64)regionp->getWidth() * factor;
  360. mEastNorth = mWestSouth + LLVector3d(width, width, 0.0);
  361. #else
  362. mEastNorth = mWestSouth + LLVector3d(PARCEL_GRID_STEP_METERS,
  363. PARCEL_GRID_STEP_METERS, 0.0);
  364. #endif
  365. // *HACK: must be in the sim you are in
  366. LLMessageSystem* msg = gMessageSystemp;
  367. msg->newMessageFast(_PREHASH_ParcelPropertiesRequestByID);
  368. msg->nextBlockFast(_PREHASH_AgentID);
  369. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  370. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  371. msg->nextBlockFast(_PREHASH_ParcelData);
  372. msg->addS32Fast(_PREHASH_SequenceID, SELECTED_PARCEL_SEQ_ID);
  373. msg->addS32Fast(_PREHASH_LocalID, mCollisionParcel->getLocalID());
  374. gAgent.sendReliableMessage();
  375. mRequestResult = PARCEL_RESULT_NO_DATA;
  376. // *HACK: copy some data over temporarily
  377. mCurrentParcel->setName(mCollisionParcel->getName());
  378. mCurrentParcel->setDesc(mCollisionParcel->getDesc());
  379. mCurrentParcel->setPassPrice(mCollisionParcel->getPassPrice());
  380. mCurrentParcel->setPassHours(mCollisionParcel->getPassHours());
  381. #if 0
  382. // Clear the list of segments to prevent flashing
  383. resetSegments(mHighlightSegments);
  384. #endif
  385. mFloatingParcelSelection->setParcel(mCurrentParcel);
  386. mCurrentParcelSelection->setParcel(NULL);
  387. mCurrentParcelSelection = new LLParcelSelection(mCurrentParcel);
  388. mSelected = true;
  389. mCurrentParcelSelection->mWholeParcelSelected = true;
  390. notifySelectionObservers();
  391. }
  392. // Snap_selection = auto-select the hit parcel, if there is exactly one
  393. LLParcelSelectionHandle LLViewerParcelMgr::selectLand(const LLVector3d& corner1,
  394. const LLVector3d& corner2,
  395. bool snap_selection)
  396. {
  397. sanitize_corners(corner1, corner2, mWestSouth, mEastNorth);
  398. // ...x is not more than one meter away
  399. F32 delta_x = getSelectionWidth();
  400. if (delta_x * delta_x <= 1.f)
  401. {
  402. mSelected = false;
  403. notifySelectionObservers();
  404. return NULL;
  405. }
  406. // ...y is not more than one meter away
  407. F32 delta_y = getSelectionHeight();
  408. if (delta_y * delta_y <= 1.f)
  409. {
  410. mSelected = false;
  411. notifySelectionObservers();
  412. return NULL;
  413. }
  414. // Cannot select across region boundary. We need to pull in the upper right
  415. // corner by a little bit to allow selection up to the x = 256 or y = 256
  416. // edge.
  417. LLVector3d east_north_region_check(mEastNorth);
  418. east_north_region_check.mdV[VX] -= 0.5;
  419. east_north_region_check.mdV[VY] -= 0.5;
  420. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(mWestSouth);
  421. if (!region)
  422. {
  423. // Just in case they somehow selected no land.
  424. mSelected = false;
  425. notifySelectionObservers();
  426. return NULL;
  427. }
  428. LLViewerRegion* region_other =
  429. gWorld.getRegionFromPosGlobal(east_north_region_check);
  430. if (region != region_other)
  431. {
  432. gNotifications.add("CantSelectLandFromMultipleRegions");
  433. mSelected = false;
  434. notifySelectionObservers();
  435. return NULL;
  436. }
  437. // Build region global copies of corners
  438. LLVector3 wsb_region = region->getPosRegionFromGlobal(mWestSouth);
  439. LLVector3 ent_region = region->getPosRegionFromGlobal(mEastNorth);
  440. // Send request message
  441. LLMessageSystem* msg = gMessageSystemp;
  442. msg->newMessageFast(_PREHASH_ParcelPropertiesRequest);
  443. msg->nextBlockFast(_PREHASH_AgentData);
  444. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  445. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  446. msg->nextBlockFast(_PREHASH_ParcelData);
  447. msg->addS32Fast(_PREHASH_SequenceID, SELECTED_PARCEL_SEQ_ID);
  448. msg->addF32Fast(_PREHASH_West, wsb_region.mV[VX]);
  449. msg->addF32Fast(_PREHASH_South, wsb_region.mV[VY]);
  450. msg->addF32Fast(_PREHASH_East, ent_region.mV[VX]);
  451. msg->addF32Fast(_PREHASH_North, ent_region.mV[VY]);
  452. msg->addBool(_PREHASH_SnapSelection, snap_selection);
  453. msg->sendReliable(region->getHost());
  454. mRequestResult = PARCEL_RESULT_NO_DATA;
  455. // Clear the list of segments to prevent flashing
  456. resetSegments(mHighlightSegments);
  457. mFloatingParcelSelection->setParcel(mCurrentParcel);
  458. mCurrentParcelSelection->setParcel(NULL);
  459. mCurrentParcelSelection = new LLParcelSelection(mCurrentParcel);
  460. mSelected = true;
  461. mCurrentParcelSelection->mWholeParcelSelected = snap_selection;
  462. notifySelectionObservers();
  463. return mCurrentParcelSelection;
  464. }
  465. void LLViewerParcelMgr::deselectUnused()
  466. {
  467. // No more outstanding references to this selection, other than our own
  468. if (mCurrentParcelSelection->getNumRefs() == 1 &&
  469. mFloatingParcelSelection->getNumRefs() == 1)
  470. {
  471. deselectLand();
  472. }
  473. }
  474. void LLViewerParcelMgr::deselectLand()
  475. {
  476. if (mSelected)
  477. {
  478. mSelected = false;
  479. // Invalidate the selected parcel
  480. mCurrentParcel->setLocalID(-1);
  481. mCurrentParcel->mAccessList.clear();
  482. mCurrentParcel->mBanList.clear();
  483. //mCurrentParcel->mRenterList.reset();
  484. mSelectedDwell = DWELL_NAN;
  485. // Invalidate parcel selection so that existing users of this selection
  486. // can clean up
  487. mCurrentParcelSelection->setParcel(NULL);
  488. mFloatingParcelSelection->setParcel(NULL);
  489. // Create new parcel selection
  490. mCurrentParcelSelection = new LLParcelSelection(mCurrentParcel);
  491. // Notify observers *after* changing the parcel selection
  492. notifySelectionObservers();
  493. }
  494. }
  495. void LLViewerParcelMgr::addSelectionObserver(LLParcelSelectionObserver* obs)
  496. {
  497. mSelectionObservers.insert(obs);
  498. }
  499. void LLViewerParcelMgr::removeSelectionObserver(LLParcelSelectionObserver* obs)
  500. {
  501. mSelectionObservers.erase(obs);
  502. }
  503. // Call this method when it is time to update everyone on a new state.
  504. void LLViewerParcelMgr::notifySelectionObservers()
  505. {
  506. LL_DEBUGS("ParcelMgr") << "Notifying observers..." << LL_ENDL;
  507. for (observers_list_t::iterator it = mSelectionObservers.begin(),
  508. end = mSelectionObservers.end();
  509. it != end; )
  510. {
  511. // Note: an observer could respond by removing itself from the list.
  512. LLParcelSelectionObserver* obs = *it++;
  513. if (obs) // Paranoia
  514. {
  515. obs->changed();
  516. }
  517. }
  518. }
  519. LLParcel* LLViewerParcelMgr::getSelectedOrAgentParcel() const
  520. {
  521. LLParcel* parcel = mAgentParcel;
  522. LLParcelSelectionHandle handle = mFloatingParcelSelection;
  523. if (handle)
  524. {
  525. LLParcelSelection* selection = handle.get();
  526. if (selection)
  527. {
  528. parcel = selection->getParcel();
  529. if (!parcel || parcel->getLocalID() == INVALID_PARCEL_ID)
  530. {
  531. parcel = mAgentParcel;
  532. }
  533. }
  534. }
  535. return parcel;
  536. }
  537. // Return whether the agent can build on the land they are on
  538. bool LLViewerParcelMgr::allowAgentBuild(bool prelude_check) const
  539. {
  540. if (!mAgentParcel)
  541. {
  542. return false;
  543. }
  544. if (gAgent.isGodlike())
  545. {
  546. return true;
  547. }
  548. // *HACK: The "prelude" Help Islands have a build sandbox area, so users
  549. // need the Edit and Create pie menu options when they are there, thus the
  550. // prelude_check flag (see LLEnableEdit in llviewermenu.cpp).
  551. if (prelude_check && gAgent.inPrelude())
  552. {
  553. return false;
  554. }
  555. //MK
  556. if (gRLenabled &&
  557. (gRLInterface.mContainsRez || gRLInterface.mContainsEdit))
  558. {
  559. return false;
  560. }
  561. //mk
  562. return mAgentParcel->getOwnerID() == gAgentID ||
  563. mAgentParcel->allowModifyBy(gAgentID, gAgent.getGroupID()) ||
  564. gAgent.hasPowerInGroup(mAgentParcel->getGroupID(),
  565. GP_LAND_ALLOW_CREATE);
  566. }
  567. // Return whether anyone can build on the given parcel
  568. bool LLViewerParcelMgr::allowAgentBuild(const LLParcel* parcel) const
  569. {
  570. return parcel->getAllowModify();
  571. }
  572. bool LLViewerParcelMgr::allowAgentVoice() const
  573. {
  574. return allowAgentVoice(gAgent.getRegion(), mAgentParcel);
  575. }
  576. bool LLViewerParcelMgr::allowAgentVoice(const LLViewerRegion* region,
  577. const LLParcel* parcel) const
  578. {
  579. return region && region->isVoiceEnabled() &&
  580. parcel && parcel->getParcelFlagAllowVoice();
  581. }
  582. bool LLViewerParcelMgr::allowAgentFly(const LLViewerRegion* region,
  583. const LLParcel* parcel) const
  584. {
  585. return region && !region->getBlockFly() && parcel && parcel->getAllowFly();
  586. }
  587. // Can the agent be pushed around by LLPushObject?
  588. bool LLViewerParcelMgr::allowAgentPush(const LLViewerRegion* region,
  589. const LLParcel* parcel) const
  590. {
  591. return region && !region->getRestrictPushObject() &&
  592. parcel && !parcel->getRestrictPushObject();
  593. }
  594. bool LLViewerParcelMgr::allowAgentScripts(const LLViewerRegion* region,
  595. const LLParcel* parcel) const
  596. {
  597. // *NOTE: This code does not take into account group-owned parcels
  598. // and the flag to allow group-owned scripted objects to run.
  599. // This mirrors the traditional menu bar parcel icon code, but is not
  600. // technically correct.
  601. return region && parcel && parcel->getAllowOtherScripts() &&
  602. !region->getRegionFlag(REGION_FLAGS_SKIP_SCRIPTS) &&
  603. !region->getRegionFlag(REGION_FLAGS_ESTATE_SKIP_SCRIPTS);
  604. }
  605. bool LLViewerParcelMgr::allowAgentDamage(const LLViewerRegion* region,
  606. const LLParcel* parcel) const
  607. {
  608. return (region && region->getAllowDamage()) ||
  609. (parcel && parcel->getAllowDamage());
  610. }
  611. bool LLViewerParcelMgr::isOwnedAt(const LLVector3d& pos_global) const
  612. {
  613. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(pos_global);
  614. if (!region) return false;
  615. LLViewerParcelOverlay* overlay = region->getParcelOverlay();
  616. if (!overlay) return false;
  617. LLVector3 pos_region = region->getPosRegionFromGlobal(pos_global);
  618. return overlay->isOwned(pos_region);
  619. }
  620. bool LLViewerParcelMgr::isOwnedSelfAt(const LLVector3d& pos_global) const
  621. {
  622. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(pos_global);
  623. if (!region) return false;
  624. LLViewerParcelOverlay* overlay = region->getParcelOverlay();
  625. if (!overlay) return false;
  626. LLVector3 pos_region = region->getPosRegionFromGlobal(pos_global);
  627. return overlay->isOwnedSelf(pos_region);
  628. }
  629. bool LLViewerParcelMgr::isOwnedOtherAt(const LLVector3d& pos_global) const
  630. {
  631. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(pos_global);
  632. if (!region) return false;
  633. LLViewerParcelOverlay* overlay = region->getParcelOverlay();
  634. if (!overlay) return false;
  635. LLVector3 pos_region = region->getPosRegionFromGlobal(pos_global);
  636. return overlay->isOwnedOther(pos_region);
  637. }
  638. bool LLViewerParcelMgr::isSoundLocal(const LLVector3d& pos_global) const
  639. {
  640. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(pos_global);
  641. if (!region) return false;
  642. LLViewerParcelOverlay* overlay = region->getParcelOverlay();
  643. if (!overlay) return false;
  644. LLVector3 pos_region = region->getPosRegionFromGlobal(pos_global);
  645. return overlay->isSoundLocal(pos_region);
  646. }
  647. bool LLViewerParcelMgr::canHearSound(const LLVector3d& pos_global) const
  648. {
  649. if (!inAgentParcel(pos_global))
  650. {
  651. static LLCachedControl<bool> neighbor_sims_sounds(gSavedSettings,
  652. "NeighborSimsSounds");
  653. if (!neighbor_sims_sounds &&
  654. gWorld.getRegionFromPosGlobal(pos_global) != gAgent.getRegion())
  655. {
  656. return false;
  657. }
  658. if (gViewerParcelMgr.getAgentParcel()->getSoundLocal())
  659. {
  660. // Not in same parcel, and agent parcel only has local sound
  661. return false;
  662. }
  663. if (gViewerParcelMgr.isSoundLocal(pos_global))
  664. {
  665. // Not in same parcel, and target parcel only has local sound
  666. return false;
  667. }
  668. }
  669. return true;
  670. }
  671. bool LLViewerParcelMgr::inAgentParcel(const LLVector3d& pos_global) const
  672. {
  673. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(pos_global);
  674. if (!gAgent.getRegion() || region != gAgent.getRegion())
  675. {
  676. // Cannot be in the agent parcel if you are not in the same region.
  677. return false;
  678. }
  679. LLVector3 pos_region = gAgent.getRegion()->getPosRegionFromGlobal(pos_global);
  680. S32 row = S32(pos_region.mV[VY] / PARCEL_GRID_STEP_METERS);
  681. S32 column = S32(pos_region.mV[VX] / PARCEL_GRID_STEP_METERS);
  682. return mAgentParcelOverlay[row * mParcelsPerEdge + column];
  683. }
  684. //
  685. // UTILITIES
  686. //
  687. void LLViewerParcelMgr::render()
  688. {
  689. if (mSelected && mRenderSelection && !gDisconnected)
  690. {
  691. // Rendering is done in agent-coordinates, so need to supply
  692. // an appropriate offset to the render code.
  693. LLViewerRegion* regionp = gWorld.getRegionFromPosGlobal(mWestSouth);
  694. if (regionp)
  695. {
  696. renderHighlightSegments(mHighlightSegments, regionp);
  697. }
  698. }
  699. }
  700. void LLViewerParcelMgr::renderParcelCollision()
  701. {
  702. // Check for expiration
  703. if (mCollisionTimer.getElapsedTimeF32() > PARCEL_COLLISION_DRAW_SECS)
  704. {
  705. mRenderCollision = false;
  706. }
  707. static LLCachedControl<bool> show_lines(gSavedSettings, "ShowBanLines");
  708. // The default behaviour is rather annoying when riding a vehicle, since as
  709. // soon as your *instantaneous* heading is not any more driving you to the
  710. // banned parcel, the ban walls disappear (and often reappear when you are
  711. // too close when you change your heading and are driving fast), making it
  712. // hard to avoid the said wall when driving at high speed and/or with a
  713. // high inertia. I therefore added this life saviour setting... HB
  714. static LLCachedControl<bool> render_always(gSavedSettings,
  715. "RenderBanWallAlways");
  716. if (show_lines && (mRenderCollision || render_always))
  717. {
  718. LLViewerRegion* regionp = gAgent.getRegion();
  719. if (regionp)
  720. {
  721. bool use_pass = mCollisionParcel->getParcelFlag(PF_USE_PASS_LIST);
  722. renderCollisionSegments(mCollisionSegments, use_pass, regionp);
  723. }
  724. }
  725. }
  726. void LLViewerParcelMgr::sendParcelAccessListRequest(U32 flags)
  727. {
  728. if (!mSelected)
  729. {
  730. return;
  731. }
  732. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(mWestSouth);
  733. if (!region)
  734. {
  735. return;
  736. }
  737. LLMessageSystem* msg = gMessageSystemp;
  738. if (flags & AL_BAN)
  739. {
  740. mCurrentParcel->mBanList.clear();
  741. }
  742. if (flags & AL_ACCESS)
  743. {
  744. mCurrentParcel->mAccessList.clear();
  745. }
  746. if (flags & AL_ALLOW_EXPERIENCE)
  747. {
  748. mCurrentParcel->clearExperienceKeysByType(EXPERIENCE_KEY_TYPE_ALLOWED);
  749. }
  750. if (flags & AL_BLOCK_EXPERIENCE)
  751. {
  752. mCurrentParcel->clearExperienceKeysByType(EXPERIENCE_KEY_TYPE_BLOCKED);
  753. }
  754. // Only the headers differ
  755. msg->newMessageFast(_PREHASH_ParcelAccessListRequest);
  756. msg->nextBlockFast(_PREHASH_AgentData);
  757. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  758. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  759. msg->nextBlockFast(_PREHASH_Data);
  760. msg->addS32Fast(_PREHASH_SequenceID, 0);
  761. msg->addU32Fast(_PREHASH_Flags, flags);
  762. msg->addS32(_PREHASH_LocalID, mCurrentParcel->getLocalID());
  763. msg->sendReliable(region->getHost());
  764. }
  765. void LLViewerParcelMgr::sendParcelDwellRequest()
  766. {
  767. if (!mSelected)
  768. {
  769. return;
  770. }
  771. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(mWestSouth);
  772. if (!region)
  773. {
  774. return;
  775. }
  776. LLMessageSystem* msg = gMessageSystemp;
  777. // Only the headers differ
  778. msg->newMessage(_PREHASH_ParcelDwellRequest);
  779. msg->nextBlock(_PREHASH_AgentData);
  780. msg->addUUID(_PREHASH_AgentID, gAgentID);
  781. msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
  782. msg->nextBlock(_PREHASH_Data);
  783. msg->addS32(_PREHASH_LocalID, mCurrentParcel->getLocalID());
  784. msg->addUUID(_PREHASH_ParcelID, LLUUID::null); // Filled in on simulator
  785. msg->sendReliable(region->getHost());
  786. }
  787. bool callback_god_force_owner(const LLSD& notification, const LLSD& response)
  788. {
  789. if (LLNotification::getSelectedOption(notification, response) == 0)
  790. {
  791. LLMessageSystem* msg = gMessageSystemp;
  792. msg->newMessage(_PREHASH_ParcelGodForceOwner);
  793. msg->nextBlock(_PREHASH_AgentData);
  794. msg->addUUID(_PREHASH_AgentID, gAgentID);
  795. msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
  796. msg->nextBlock(_PREHASH_Data);
  797. msg->addUUID(_PREHASH_OwnerID,
  798. notification["payload"]["owner_id"].asUUID());
  799. msg->addS32(_PREHASH_LocalID,
  800. notification["payload"]["parcel_local_id"].asInteger());
  801. msg->sendReliable(LLHost(notification["payload"]["region_host"].asString()));
  802. }
  803. return false;
  804. }
  805. void LLViewerParcelMgr::sendParcelGodForceOwner(const LLUUID& owner_id)
  806. {
  807. if (!mSelected)
  808. {
  809. gNotifications.add("CannotSetLandOwnerNothingSelected");
  810. return;
  811. }
  812. llinfos << "Claiming " << mWestSouth << " to " << mEastNorth << llendl;
  813. // BUG: Only works for the region containing mWestSouthBottom
  814. LLVector3d east_north_region_check(mEastNorth);
  815. east_north_region_check.mdV[VX] -= 0.5;
  816. east_north_region_check.mdV[VY] -= 0.5;
  817. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(mWestSouth);
  818. if (!region)
  819. {
  820. // *TODO: Add a force owner version of this alert.
  821. gNotifications.add("CannotContentifyNoRegion");
  822. return;
  823. }
  824. // *FIXME: make it work for cross-region selections
  825. LLViewerRegion* region2 =
  826. gWorld.getRegionFromPosGlobal(east_north_region_check);
  827. if (region != region2)
  828. {
  829. gNotifications.add("CannotSetLandOwnerMultipleRegions");
  830. return;
  831. }
  832. llinfos << "Region " << region->getOriginGlobal() << llendl;
  833. LLSD payload;
  834. payload["owner_id"] = owner_id;
  835. payload["parcel_local_id"] = mCurrentParcel->getLocalID();
  836. payload["region_host"] = region->getHost().getIPandPort();
  837. LLNotification::Params params("ForceOwnerAuctionWarning");
  838. params.payload(payload).functor(callback_god_force_owner);
  839. if (mCurrentParcel->getAuctionID())
  840. {
  841. gNotifications.add(params);
  842. }
  843. else
  844. {
  845. gNotifications.forceResponse(params, 0);
  846. }
  847. }
  848. void LLViewerParcelMgr::sendParcelGodForceToContent()
  849. {
  850. if (!mSelected)
  851. {
  852. gNotifications.add("CannotContentifyNothingSelected");
  853. return;
  854. }
  855. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(mWestSouth);
  856. if (!region)
  857. {
  858. gNotifications.add("CannotContentifyNoRegion");
  859. return;
  860. }
  861. LLMessageSystem* msg = gMessageSystemp;
  862. msg->newMessage(_PREHASH_ParcelGodMarkAsContent);
  863. msg->nextBlock(_PREHASH_AgentData);
  864. msg->addUUID(_PREHASH_AgentID, gAgentID);
  865. msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
  866. msg->nextBlock(_PREHASH_ParcelData);
  867. msg->addS32(_PREHASH_LocalID, mCurrentParcel->getLocalID());
  868. msg->sendReliable(region->getHost());
  869. }
  870. void LLViewerParcelMgr::sendParcelRelease()
  871. {
  872. if (!mSelected)
  873. {
  874. gNotifications.add("CannotReleaseLandNothingSelected");
  875. return;
  876. }
  877. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(mWestSouth);
  878. if (!region)
  879. {
  880. gNotifications.add("CannotReleaseLandNoRegion");
  881. return;
  882. }
  883. LLMessageSystem* msg = gMessageSystemp;
  884. msg->newMessage(_PREHASH_ParcelRelease);
  885. msg->nextBlock(_PREHASH_AgentData);
  886. msg->addUUID(_PREHASH_AgentID, gAgentID);
  887. msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
  888. msg->nextBlock(_PREHASH_Data);
  889. msg->addS32(_PREHASH_LocalID, mCurrentParcel->getLocalID());
  890. #if 0
  891. msg->addU32(_PREHASH_Flags,
  892. gAgent.isGodlikeWithoutAdminMenuFakery ? PR_GOD_FORCE
  893. : PR_NONE);
  894. #endif
  895. msg->sendReliable(region->getHost());
  896. // Blitz selection, since the parcel might be non-rectangular, and we would
  897. // not have appropriate parcel information.
  898. deselectLand();
  899. }
  900. struct LLViewerParcelMgr::ParcelBuyInfo
  901. {
  902. LLUUID mAgent;
  903. LLUUID mSession;
  904. LLUUID mGroup;
  905. LLHost mHost;
  906. // For parcel buys
  907. S32 mParcelID;
  908. S32 mPrice;
  909. S32 mArea;
  910. // For land claims
  911. F32 mWest;
  912. F32 mSouth;
  913. F32 mEast;
  914. F32 mNorth;
  915. bool mIsGroupOwned;
  916. bool mRemoveContribution;
  917. bool mIsClaim;
  918. };
  919. LLViewerParcelMgr::ParcelBuyInfo* LLViewerParcelMgr::setupParcelBuy(const LLUUID& agent_id,
  920. const LLUUID& session_id,
  921. const LLUUID& group_id,
  922. bool is_group_owned,
  923. bool is_claim,
  924. bool remove_contribution)
  925. {
  926. if (!mSelected || !mCurrentParcel)
  927. {
  928. gNotifications.add("CannotBuyLandNothingSelected");
  929. return NULL;
  930. }
  931. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(mWestSouth);
  932. if (!region)
  933. {
  934. gNotifications.add("CannotBuyLandNoRegion");
  935. return NULL;
  936. }
  937. if (is_claim)
  938. {
  939. llinfos << "Claiming " << mWestSouth << " to " << mEastNorth << llendl;
  940. llinfos << "Region " << region->getOriginGlobal() << llendl;
  941. // BUG: Only works for the region containing mWestSouthBottom
  942. LLVector3d east_north_region_check(mEastNorth);
  943. east_north_region_check.mdV[VX] -= 0.5;
  944. east_north_region_check.mdV[VY] -= 0.5;
  945. if (region != gWorld.getRegionFromPosGlobal(east_north_region_check))
  946. {
  947. gNotifications.add("CantBuyLandAcrossMultipleRegions");
  948. return NULL;
  949. }
  950. }
  951. ParcelBuyInfo* info = new ParcelBuyInfo;
  952. info->mAgent = agent_id;
  953. info->mSession = session_id;
  954. info->mGroup = group_id;
  955. info->mIsGroupOwned = is_group_owned;
  956. info->mIsClaim = is_claim;
  957. info->mRemoveContribution = remove_contribution;
  958. info->mHost = region->getHost();
  959. info->mPrice = mCurrentParcel->getSalePrice();
  960. info->mArea = mCurrentParcel->getArea();
  961. if (!is_claim)
  962. {
  963. info->mParcelID = mCurrentParcel->getLocalID();
  964. }
  965. else
  966. {
  967. // *FIXME: make it work for cross-region selections
  968. LLVector3 west_south_bottom_region = region->getPosRegionFromGlobal(mWestSouth);
  969. LLVector3 east_north_top_region = region->getPosRegionFromGlobal(mEastNorth);
  970. info->mWest = west_south_bottom_region.mV[VX];
  971. info->mSouth = west_south_bottom_region.mV[VY];
  972. info->mEast = east_north_top_region.mV[VX];
  973. info->mNorth = east_north_top_region.mV[VY];
  974. }
  975. return info;
  976. }
  977. void LLViewerParcelMgr::sendParcelBuy(ParcelBuyInfo* info)
  978. {
  979. LLMessageSystem* msg = gMessageSystemp;
  980. msg->newMessage(info->mIsClaim ? _PREHASH_ParcelClaim
  981. : _PREHASH_ParcelBuy);
  982. msg->nextBlock(_PREHASH_AgentData);
  983. msg->addUUID(_PREHASH_AgentID, info->mAgent);
  984. msg->addUUID(_PREHASH_SessionID, info->mSession);
  985. msg->nextBlock(_PREHASH_Data);
  986. msg->addUUID(_PREHASH_GroupID, info->mGroup);
  987. msg->addBool(_PREHASH_IsGroupOwned, info->mIsGroupOwned);
  988. if (!info->mIsClaim)
  989. {
  990. msg->addBool(_PREHASH_RemoveContribution, info->mRemoveContribution);
  991. msg->addS32(_PREHASH_LocalID, info->mParcelID);
  992. }
  993. msg->addBool(_PREHASH_Final, true); // Do not allow escrow buys
  994. if (info->mIsClaim)
  995. {
  996. msg->nextBlock(_PREHASH_ParcelData);
  997. msg->addF32(_PREHASH_West, info->mWest);
  998. msg->addF32(_PREHASH_South, info->mSouth);
  999. msg->addF32(_PREHASH_East, info->mEast);
  1000. msg->addF32(_PREHASH_North, info->mNorth);
  1001. }
  1002. else // ParcelBuy
  1003. {
  1004. msg->nextBlock(_PREHASH_ParcelData);
  1005. msg->addS32(_PREHASH_Price, info->mPrice);
  1006. msg->addS32(_PREHASH_Area, info->mArea);
  1007. }
  1008. msg->sendReliable(info->mHost);
  1009. }
  1010. void LLViewerParcelMgr::deleteParcelBuy(ParcelBuyInfo*& info)
  1011. {
  1012. delete info;
  1013. info = NULL;
  1014. }
  1015. void LLViewerParcelMgr::sendParcelDeed(const LLUUID& group_id)
  1016. {
  1017. if (!mSelected || !mCurrentParcel)
  1018. {
  1019. gNotifications.add("CannotDeedLandNothingSelected");
  1020. return;
  1021. }
  1022. if (group_id.isNull())
  1023. {
  1024. gNotifications.add("CannotDeedLandNoGroup");
  1025. return;
  1026. }
  1027. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(mWestSouth);
  1028. if (!region)
  1029. {
  1030. gNotifications.add("CannotDeedLandNoRegion");
  1031. return;
  1032. }
  1033. LLMessageSystem* msg = gMessageSystemp;
  1034. msg->newMessage(_PREHASH_ParcelDeedToGroup);
  1035. msg->nextBlock(_PREHASH_AgentData);
  1036. msg->addUUID(_PREHASH_AgentID, gAgentID);
  1037. msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
  1038. msg->nextBlock(_PREHASH_Data);
  1039. msg->addUUID(_PREHASH_GroupID, group_id);
  1040. msg->addS32(_PREHASH_LocalID, mCurrentParcel->getLocalID());
  1041. //msg->addU32("JoinNeighbors", join);
  1042. msg->sendReliable(region->getHost());
  1043. }
  1044. #if 0 // *NOTE: We cannot easily make landmarks at global positions because
  1045. // global positions probably refer to a sim/local combination which can
  1046. // move over time. We could implement this by looking up the region
  1047. // global x,y, but it is easier to take it out for now.
  1048. void LLViewerParcelMgr::makeLandmarkAtSelection()
  1049. {
  1050. // Do not create for parcels you do not own
  1051. if (gAgentID != mCurrentParcel->getOwnerID())
  1052. {
  1053. return;
  1054. }
  1055. LLVector3d global_center(mWestSouth);
  1056. global_center += mEastNorth;
  1057. global_center *= 0.5f;
  1058. LLViewerRegion* region;
  1059. region = gWorld.getRegionFromPosGlobal(global_center);
  1060. LLVector3 west_south_bottom_region =
  1061. region->getPosRegionFromGlobal(mWestSouth);
  1062. LLVector3 east_north_top_region =
  1063. region->getPosRegionFromGlobal(mEastNorth);
  1064. std::string buffer;
  1065. S32 pos_x = (S32)floor((west_south_bottom_region.mV[VX] +
  1066. east_north_top_region.mV[VX]) * 0.5f);
  1067. S32 pos_y = (S32)floor((west_south_bottom_region.mV[VY] +
  1068. east_north_top_region.mV[VY]) * 0.5f);
  1069. buffer = llformat("%s in %s (%d, %d)", "My land",
  1070. region->getName().c_str(), pos_x, pos_y);
  1071. name.assign(buffer);
  1072. create_landmark("My land", "Claimed land", global_center);
  1073. }
  1074. #endif
  1075. S32 LLViewerParcelMgr::getAgentParcelId() const
  1076. {
  1077. return mAgentParcel ? mAgentParcel->getLocalID() : INVALID_PARCEL_ID;
  1078. }
  1079. void LLViewerParcelMgr::sendParcelPropertiesUpdate(LLParcel* parcel,
  1080. bool use_agent_region)
  1081. {
  1082. if (!parcel) return;
  1083. LLViewerRegion* region;
  1084. region = use_agent_region ? gAgent.getRegion()
  1085. : gWorld.getRegionFromPosGlobal(mWestSouth);
  1086. if (!region) return;
  1087. LLSD body;
  1088. const std::string& url = region->getCapability("ParcelPropertiesUpdate");
  1089. if (url.empty())
  1090. {
  1091. LLMessageSystem* msg = gMessageSystemp;
  1092. msg->newMessageFast(_PREHASH_ParcelPropertiesUpdate);
  1093. msg->nextBlockFast(_PREHASH_AgentData);
  1094. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  1095. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  1096. msg->nextBlockFast(_PREHASH_ParcelData);
  1097. msg->addS32Fast(_PREHASH_LocalID, parcel->getLocalID());
  1098. U32 message_flags = 0x01;
  1099. msg->addU32(_PREHASH_Flags, message_flags);
  1100. parcel->packMessage(msg);
  1101. msg->sendReliable(region->getHost());
  1102. }
  1103. else
  1104. {
  1105. // Request new properties update from simulator
  1106. U32 message_flags = 0x01;
  1107. body["flags"] = ll_sd_from_U32(message_flags);
  1108. parcel->packMessage(body);
  1109. llinfos << "Sending parcel properties update via capability to: "
  1110. << url << llendl;
  1111. LLCoreHttpUtil::HttpCoroutineAdapter::messageHttpPost(url, body,
  1112. "Parcel Properties sent to sim.",
  1113. "Parcel Properties failed to send to sim.");
  1114. }
  1115. // If this is the agent parcel, tell to the status bar that its icons need
  1116. // a refresh (this will cause a call to requestParcelProperties() by the
  1117. // status bar 2 seconds or so later, to let some time for the above
  1118. // properties update call to complete first).
  1119. if (gStatusBarp && parcel->getLocalID() == mAgentParcel->getLocalID())
  1120. {
  1121. gStatusBarp->setDirtyAgentParcelProperties();
  1122. }
  1123. }
  1124. void LLViewerParcelMgr::setHoverParcel(const LLVector3d& pos)
  1125. {
  1126. LLViewerRegion* regionp = gWorld.getRegionFromPosGlobal(pos);
  1127. if (!regionp)
  1128. {
  1129. return;
  1130. }
  1131. // Only request parcel info if position has changed outside of the last
  1132. // parcel grid step.
  1133. static S32 last_west, last_south;
  1134. constexpr F64 meters_per_step = 1.0 / PARCEL_GRID_STEP_METERS;
  1135. S32 west_parcel_step = pos.mdV[VX] * meters_per_step;
  1136. S32 south_parcel_step = pos.mdV[VY] * meters_per_step;
  1137. if (west_parcel_step == last_west && south_parcel_step == last_south)
  1138. {
  1139. return;
  1140. }
  1141. static LLUUID last_region;
  1142. const LLUUID& region_id = regionp->getRegionID();
  1143. LLVector3 local_pos = regionp->getPosRegionFromGlobal(pos);
  1144. LLViewerParcelOverlay* overlayp = regionp->getParcelOverlay();
  1145. // Check to see if the new position is in same parcel. This check is not
  1146. // ideal, since it checks by way of straight lines. So sometimes (small
  1147. // parcel in the middle of large one) it can decide that parcel actually
  1148. // changed, but it still allows to reduce amount of requests significantly.
  1149. bool do_request = !overlayp || region_id != last_region;
  1150. if (!do_request)
  1151. {
  1152. S32 west_parcel = local_pos.mV[VX] / PARCEL_GRID_STEP_METERS;
  1153. S32 south_parcel = local_pos.mV[VY] / PARCEL_GRID_STEP_METERS;
  1154. while (!do_request && west_parcel_step < last_west)
  1155. {
  1156. S32 shift = last_west-- - west_parcel_step;
  1157. do_request = PARCEL_WEST_LINE &
  1158. overlayp->parcelLineFlags(south_parcel,
  1159. west_parcel + shift);
  1160. }
  1161. while (!do_request && south_parcel_step < last_south)
  1162. {
  1163. S32 shift = last_south-- - south_parcel_step;
  1164. do_request = PARCEL_SOUTH_LINE &
  1165. overlayp->parcelLineFlags(south_parcel + shift,
  1166. west_parcel);
  1167. }
  1168. while (!do_request && west_parcel_step > last_west)
  1169. {
  1170. S32 shift = west_parcel_step - last_west++;
  1171. do_request = PARCEL_WEST_LINE &
  1172. overlayp->parcelLineFlags(south_parcel,
  1173. west_parcel - shift + 1);
  1174. }
  1175. while (!do_request && south_parcel_step > last_south)
  1176. {
  1177. S32 shift = south_parcel_step - last_south++;
  1178. do_request = PARCEL_SOUTH_LINE &
  1179. overlayp->parcelLineFlags(south_parcel - shift + 1,
  1180. west_parcel);
  1181. }
  1182. }
  1183. if (!do_request)
  1184. {
  1185. return;
  1186. }
  1187. // Remember the last requested parcel position
  1188. last_region = region_id;
  1189. last_west = west_parcel_step;
  1190. last_south = south_parcel_step;
  1191. mHoverRequestResult = PARCEL_RESULT_NO_DATA;
  1192. // Send a rectangle around the point. This means the parcel sent back is at
  1193. // least a rectangle around the point, which is more efficient for public
  1194. // land. Fewer requests are sent. JC
  1195. F32 west = PARCEL_GRID_STEP_METERS *
  1196. floor(local_pos.mV[VX] / PARCEL_GRID_STEP_METERS);
  1197. F32 south = PARCEL_GRID_STEP_METERS *
  1198. floor(local_pos.mV[VY] / PARCEL_GRID_STEP_METERS);
  1199. // Send request message
  1200. LLMessageSystem* msg = gMessageSystemp;
  1201. msg->newMessageFast(_PREHASH_ParcelPropertiesRequest);
  1202. msg->nextBlockFast(_PREHASH_AgentData);
  1203. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  1204. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  1205. msg->nextBlockFast(_PREHASH_ParcelData);
  1206. msg->addS32Fast(_PREHASH_SequenceID, HOVERED_PARCEL_SEQ_ID);
  1207. msg->addF32Fast(_PREHASH_West, west);
  1208. msg->addF32Fast(_PREHASH_South, south);
  1209. msg->addF32Fast(_PREHASH_East, west + PARCEL_GRID_STEP_METERS);
  1210. msg->addF32Fast(_PREHASH_North, south + PARCEL_GRID_STEP_METERS);
  1211. msg->addBool(_PREHASH_SnapSelection, false);
  1212. msg->sendReliable(regionp->getHost());
  1213. }
  1214. bool LLViewerParcelMgr::requestParcelProperties(const LLVector3d& pos, S32 id)
  1215. {
  1216. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(pos);
  1217. if (!region)
  1218. {
  1219. return false;
  1220. }
  1221. // Send a rectangle around the point.
  1222. // This means the parcel sent back is at least a rectangle around the point,
  1223. // which is more efficient for public land. Fewer requests are sent. JC
  1224. LLVector3 wsb_region = region->getPosRegionFromGlobal(pos);
  1225. F32 west = PARCEL_GRID_STEP_METERS * floor(wsb_region.mV[VX] /
  1226. PARCEL_GRID_STEP_METERS);
  1227. F32 south = PARCEL_GRID_STEP_METERS * floor(wsb_region.mV[VY] /
  1228. PARCEL_GRID_STEP_METERS);
  1229. F32 east = west + PARCEL_GRID_STEP_METERS;
  1230. F32 north = south + PARCEL_GRID_STEP_METERS;
  1231. // Send request message
  1232. LLMessageSystem* msg = gMessageSystemp;
  1233. msg->newMessageFast(_PREHASH_ParcelPropertiesRequest);
  1234. msg->nextBlockFast(_PREHASH_AgentData);
  1235. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  1236. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  1237. msg->nextBlockFast(_PREHASH_ParcelData);
  1238. msg->addS32Fast(_PREHASH_SequenceID, id);
  1239. msg->addF32Fast(_PREHASH_West, west);
  1240. msg->addF32Fast(_PREHASH_South, south);
  1241. msg->addF32Fast(_PREHASH_East, east);
  1242. msg->addF32Fast(_PREHASH_North, north);
  1243. msg->addBool(_PREHASH_SnapSelection, false);
  1244. msg->sendReliable(region->getHost());
  1245. return true;
  1246. }
  1247. //static
  1248. void LLViewerParcelMgr::processParcelOverlay(LLMessageSystem* msg, void**)
  1249. {
  1250. // Extract the packed overlay information
  1251. S32 packed_overlay_size = msg->getSizeFast(_PREHASH_ParcelData,
  1252. _PREHASH_Data);
  1253. if (packed_overlay_size <= 0)
  1254. {
  1255. llwarns << "Overlay size " << packed_overlay_size << llendl;
  1256. return;
  1257. }
  1258. // Variable region size support
  1259. #if 0
  1260. S32 parcels_per_edge = gViewerParcelMgr.mParcelsPerEdge;
  1261. S32 expected_size = parcels_per_edge * parcels_per_edge / PARCEL_OVERLAY_CHUNKS;
  1262. #else
  1263. S32 expected_size = 1024;
  1264. #endif
  1265. if (packed_overlay_size != expected_size)
  1266. {
  1267. llwarns << "Got parcel overlay size " << packed_overlay_size
  1268. << " expecting " << expected_size << llendl;
  1269. return;
  1270. }
  1271. S32 sequence_id;
  1272. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_SequenceID, sequence_id);
  1273. msg->getBinaryDataFast(_PREHASH_ParcelData, _PREHASH_Data, sPackedOverlay,
  1274. expected_size);
  1275. LLHost host = msg->getSender();
  1276. LLViewerRegion* region = gWorld.getRegion(host);
  1277. if (region)
  1278. {
  1279. region->mParcelOverlay->uncompressLandOverlay(sequence_id,
  1280. sPackedOverlay);
  1281. }
  1282. }
  1283. //static
  1284. void LLViewerParcelMgr::processParcelProperties(LLMessageSystem* msg, void**)
  1285. {
  1286. S32 self_count = 0;
  1287. S32 other_count = 0;
  1288. S32 public_count = 0;
  1289. S32 local_id;
  1290. LLUUID owner_id;
  1291. U32 auction_id = 0;
  1292. S32 claim_price_per_meter = 0;
  1293. S32 rent_price_per_meter = 0;
  1294. S32 claim_date = 0;
  1295. LLVector3 aabb_min;
  1296. LLVector3 aabb_max;
  1297. S32 area = 0;
  1298. S32 sw_max_prims = 0;
  1299. S32 sw_total_prims = 0;
  1300. U8 status = 0;
  1301. S32 max_prims = 0;
  1302. S32 total_prims = 0;
  1303. S32 owner_prims = 0;
  1304. S32 group_prims = 0;
  1305. S32 other_prims = 0;
  1306. S32 selected_prims = 0;
  1307. S32 other_clean_time = 0;
  1308. F32 parcel_prim_bonus = 1.f;
  1309. bool is_group_owned = false;
  1310. bool region_push_override = false;
  1311. bool region_deny_anonymous_override = false;
  1312. bool region_deny_identified_override = false; // Deprecated
  1313. bool region_deny_transacted_override = false; // Deprecated
  1314. bool region_deny_age_unverified_override = false;
  1315. bool region_allow_access_override = true;
  1316. bool agent_parcel_update = false;
  1317. bool region_allow_env_override = true;
  1318. S32 parcel_env_version = 0;
  1319. // Variable region size support
  1320. LLViewerRegion* msg_region = gWorld.getRegion(msg->getSender());
  1321. if (msg_region)
  1322. {
  1323. gViewerParcelMgr.mParcelsPerEdge = (S32)(msg_region->getWidth() /
  1324. PARCEL_GRID_STEP_METERS);
  1325. }
  1326. else
  1327. {
  1328. gViewerParcelMgr.mParcelsPerEdge = (S32)(gAgent.getRegion()->getWidth() /
  1329. PARCEL_GRID_STEP_METERS);
  1330. }
  1331. S32 request_result;
  1332. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_RequestResult,
  1333. request_result);
  1334. if (request_result == PARCEL_RESULT_NO_DATA)
  1335. {
  1336. // No valid parcel data
  1337. llinfos << "No valid parcel data" << llendl;
  1338. return;
  1339. }
  1340. // Decide where the data will go.
  1341. LLParcel* parcel = NULL;
  1342. S32 sequence_id;
  1343. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_SequenceID, sequence_id);
  1344. if (sequence_id == SELECTED_PARCEL_SEQ_ID)
  1345. {
  1346. // ...selected parcels report this sequence id
  1347. gViewerParcelMgr.mRequestResult = PARCEL_RESULT_SUCCESS;
  1348. parcel = gViewerParcelMgr.mCurrentParcel;
  1349. }
  1350. else if (sequence_id == HOVERED_PARCEL_SEQ_ID)
  1351. {
  1352. gViewerParcelMgr.mHoverRequestResult = PARCEL_RESULT_SUCCESS;
  1353. parcel = gViewerParcelMgr.mHoverParcel;
  1354. }
  1355. else if (sequence_id == COLLISION_NOT_IN_GROUP_PARCEL_SEQ_ID ||
  1356. sequence_id == COLLISION_NOT_ON_LIST_PARCEL_SEQ_ID ||
  1357. sequence_id == COLLISION_BANNED_PARCEL_SEQ_ID)
  1358. {
  1359. gViewerParcelMgr.mHoverRequestResult = PARCEL_RESULT_SUCCESS;
  1360. parcel = gViewerParcelMgr.mCollisionParcel;
  1361. }
  1362. else if (sequence_id == UPDATE_AGENT_PARCEL_SEQ_ID || sequence_id == 0 ||
  1363. sequence_id > gViewerParcelMgr.mAgentParcelSequenceID)
  1364. {
  1365. if (sequence_id != UPDATE_AGENT_PARCEL_SEQ_ID)
  1366. {
  1367. gViewerParcelMgr.mAgentParcelSequenceID = sequence_id;
  1368. }
  1369. parcel = gViewerParcelMgr.mAgentParcel;
  1370. }
  1371. else
  1372. {
  1373. llinfos << "Out of order agent parcel sequence id " << sequence_id
  1374. << " last good " << gViewerParcelMgr.mAgentParcelSequenceID
  1375. << llendl;
  1376. return;
  1377. }
  1378. LL_DEBUGS("ParcelMgr") << "Sequence id = ";
  1379. switch (sequence_id)
  1380. {
  1381. case UPDATE_AGENT_PARCEL_SEQ_ID:
  1382. LL_CONT << "UPDATE_AGENT_PARCEL_SEQ_ID";
  1383. break;
  1384. case SELECTED_PARCEL_SEQ_ID:
  1385. LL_CONT << "SELECTED_PARCEL_SEQ_ID";
  1386. break;
  1387. case COLLISION_NOT_IN_GROUP_PARCEL_SEQ_ID:
  1388. LL_CONT << "COLLISION_NOT_IN_GROUP_PARCEL_SEQ_ID";
  1389. break;
  1390. case COLLISION_BANNED_PARCEL_SEQ_ID:
  1391. LL_CONT << "COLLISION_BANNED_PARCEL_SEQ_ID";
  1392. break;
  1393. case COLLISION_NOT_ON_LIST_PARCEL_SEQ_ID:
  1394. LL_CONT << "COLLISION_NOT_ON_LIST_PARCEL_SEQ_ID";
  1395. break;
  1396. case HOVERED_PARCEL_SEQ_ID:
  1397. LL_CONT << "HOVERED_PARCEL_SEQ_ID";
  1398. break;
  1399. default:
  1400. LL_CONT << sequence_id;
  1401. }
  1402. LL_CONT << LL_ENDL;
  1403. bool snap_selection = false;
  1404. msg->getBool(_PREHASH_ParcelData, _PREHASH_SnapSelection, snap_selection);
  1405. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_SelfCount, self_count);
  1406. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_OtherCount, other_count);
  1407. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_PublicCount, public_count);
  1408. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_LocalID, local_id);
  1409. msg->getUUIDFast(_PREHASH_ParcelData, _PREHASH_OwnerID, owner_id);
  1410. msg->getBoolFast(_PREHASH_ParcelData, _PREHASH_IsGroupOwned,
  1411. is_group_owned);
  1412. msg->getU32Fast(_PREHASH_ParcelData, _PREHASH_AuctionID, auction_id);
  1413. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_ClaimDate, claim_date);
  1414. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_ClaimPrice,
  1415. claim_price_per_meter);
  1416. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_RentPrice,
  1417. rent_price_per_meter);
  1418. msg->getVector3Fast(_PREHASH_ParcelData, _PREHASH_AABBMin, aabb_min);
  1419. msg->getVector3Fast(_PREHASH_ParcelData, _PREHASH_AABBMax, aabb_max);
  1420. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_Area, area);
  1421. #if 0
  1422. LLUUID buyer_id;
  1423. msg->getUUIDFast(_PREHASH_ParcelData, _PREHASH_BuyerID, buyer_id);
  1424. #endif
  1425. msg->getU8(_PREHASH_ParcelData, _PREHASH_Status, status);
  1426. msg->getS32(_PREHASH_ParcelData, _PREHASH_SimWideMaxPrims, sw_max_prims);
  1427. msg->getS32(_PREHASH_ParcelData, _PREHASH_SimWideTotalPrims,
  1428. sw_total_prims);
  1429. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_MaxPrims, max_prims);
  1430. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_TotalPrims, total_prims);
  1431. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_OwnerPrims, owner_prims);
  1432. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_GroupPrims, group_prims);
  1433. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_OtherPrims, other_prims);
  1434. msg->getS32Fast(_PREHASH_ParcelData, _PREHASH_SelectedPrims,
  1435. selected_prims);
  1436. msg->getF32Fast(_PREHASH_ParcelData, _PREHASH_ParcelPrimBonus,
  1437. parcel_prim_bonus);
  1438. msg->getBoolFast(_PREHASH_ParcelData, _PREHASH_RegionPushOverride,
  1439. region_push_override);
  1440. msg->getBoolFast(_PREHASH_ParcelData, _PREHASH_RegionDenyAnonymous,
  1441. region_deny_anonymous_override);
  1442. msg->getBoolFast(_PREHASH_ParcelData, _PREHASH_RegionDenyIdentified,
  1443. region_deny_identified_override); // Deprecated
  1444. msg->getBoolFast(_PREHASH_ParcelData, _PREHASH_RegionDenyTransacted,
  1445. region_deny_transacted_override); // Deprecated
  1446. if (msg->getNumberOfBlocksFast(_PREHASH_AgeVerificationBlock))
  1447. {
  1448. // This block was added later and may not be on older sims, so we have
  1449. // to test its existence first
  1450. msg->getBoolFast(_PREHASH_AgeVerificationBlock,
  1451. _PREHASH_RegionDenyAgeUnverified,
  1452. region_deny_age_unverified_override);
  1453. }
  1454. if (msg->getNumberOfBlocks(_PREHASH_RegionAllowAccessBlock))
  1455. {
  1456. msg->getBoolFast(_PREHASH_RegionAllowAccessBlock,
  1457. _PREHASH_RegionAllowAccessOverride,
  1458. region_allow_access_override);
  1459. }
  1460. // Obscure MOAP
  1461. U32 extended_flags = 0;
  1462. if (msg->getNumberOfBlocks(_PREHASH_ParcelExtendedFlags))
  1463. {
  1464. msg->getU32Fast(_PREHASH_ParcelExtendedFlags, _PREHASH_Flags,
  1465. extended_flags);
  1466. }
  1467. if (msg->getNumberOfBlocks(_PREHASH_ParcelEnvironmentBlock))
  1468. {
  1469. msg->getS32Fast(_PREHASH_ParcelEnvironmentBlock,
  1470. _PREHASH_ParcelEnvironmentVersion,
  1471. parcel_env_version);
  1472. msg->getBoolFast(_PREHASH_ParcelEnvironmentBlock,
  1473. _PREHASH_RegionAllowEnvironmentOverride,
  1474. region_allow_env_override);
  1475. }
  1476. msg->getS32(_PREHASH_ParcelData, _PREHASH_OtherCleanTime,
  1477. other_clean_time);
  1478. // Actually extract the data.
  1479. if (parcel)
  1480. {
  1481. if (local_id == gViewerParcelMgr.mAgentParcel->getLocalID())
  1482. {
  1483. // Parcels in different regions can have same Ids.
  1484. LLViewerRegion* parcel_region = gWorld.getRegion(msg->getSender());
  1485. LLViewerRegion* agent_region = gAgent.getRegion();
  1486. agent_parcel_update = parcel_region && agent_region &&
  1487. parcel_region->getRegionID() ==
  1488. agent_region->getRegionID();
  1489. }
  1490. S32 cur_env_version = parcel->getParcelEnvironmentVersion();
  1491. parcel->init(owner_id, false, false, false, claim_date,
  1492. claim_price_per_meter, rent_price_per_meter, area,
  1493. other_prims, parcel_prim_bonus, is_group_owned);
  1494. parcel->setLocalID(local_id);
  1495. parcel->setAABBMin(aabb_min);
  1496. parcel->setAABBMax(aabb_max);
  1497. parcel->setAuctionID(auction_id);
  1498. parcel->setOwnershipStatus((LLParcel::EOwnershipStatus)status);
  1499. parcel->setSimWideMaxPrimCapacity(sw_max_prims);
  1500. parcel->setSimWidePrimCount(sw_total_prims);
  1501. parcel->setMaxPrimCapacity(max_prims);
  1502. parcel->setOwnerPrimCount(owner_prims);
  1503. parcel->setGroupPrimCount(group_prims);
  1504. parcel->setOtherPrimCount(other_prims);
  1505. parcel->setSelectedPrimCount(selected_prims);
  1506. parcel->setParcelPrimBonus(parcel_prim_bonus);
  1507. parcel->setCleanOtherTime(other_clean_time);
  1508. parcel->setRegionPushOverride(region_push_override);
  1509. parcel->setRegionDenyAnonymousOverride(region_deny_anonymous_override);
  1510. parcel->setRegionDenyAgeUnverifiedOverride(region_deny_age_unverified_override);
  1511. parcel->setRegionAllowAccessOverride(region_allow_access_override);
  1512. parcel->setParcelEnvironmentVersion(cur_env_version);
  1513. parcel->setRegionAllowEnvironmentOverride(region_allow_env_override);
  1514. parcel->setObscureMOAP(bool(extended_flags));
  1515. parcel->unpackMessage(msg);
  1516. if (parcel == gViewerParcelMgr.mAgentParcel)
  1517. {
  1518. S32 bitmap_size = gViewerParcelMgr.mParcelsPerEdge *
  1519. gViewerParcelMgr.mParcelsPerEdge / 8;
  1520. U8* bitmap = new U8[bitmap_size];
  1521. msg->getBinaryDataFast(_PREHASH_ParcelData, _PREHASH_Bitmap,
  1522. bitmap, bitmap_size);
  1523. gViewerParcelMgr.writeAgentParcelFromBitmap(bitmap);
  1524. delete[] bitmap;
  1525. if (sequence_id != UPDATE_AGENT_PARCEL_SEQ_ID)
  1526. {
  1527. // Let interesting parties know about agent parcel change.
  1528. gViewerParcelMgr.mAgentParcelChangedSignal();
  1529. if (gViewerParcelMgr.mTeleportInProgress)
  1530. {
  1531. gViewerParcelMgr.mTeleportInProgress = false;
  1532. gViewerParcelMgr.mTeleportFinishedSignal(gAgent.getPositionGlobal(),
  1533. false);
  1534. }
  1535. }
  1536. if (gStatusBarp)
  1537. {
  1538. gStatusBarp->setDirty();
  1539. }
  1540. }
  1541. else if (agent_parcel_update)
  1542. {
  1543. // Updated agent parcel
  1544. gViewerParcelMgr.mAgentParcel->unpackMessage(msg);
  1545. parcel->setParcelEnvironmentVersion(parcel_env_version);
  1546. if (cur_env_version != parcel_env_version &&
  1547. gAgent.hasExtendedEnvironment())
  1548. {
  1549. LL_DEBUGS("Environment") << "Parcel environment version is "
  1550. << parcel->getParcelEnvironmentVersion()
  1551. << LL_ENDL;
  1552. gEnvironment.requestParcel(local_id);
  1553. }
  1554. }
  1555. }
  1556. // Handle updating selections, if necessary.
  1557. LLViewerRegion* region = gWorld.getRegion(msg->getSender());
  1558. if (sequence_id == SELECTED_PARCEL_SEQ_ID)
  1559. {
  1560. // Update selected counts
  1561. gViewerParcelMgr.mCurrentParcelSelection->mSelectedSelfCount =
  1562. self_count;
  1563. gViewerParcelMgr.mCurrentParcelSelection->mSelectedOtherCount =
  1564. other_count;
  1565. gViewerParcelMgr.mCurrentParcelSelection->mSelectedPublicCount =
  1566. public_count;
  1567. gViewerParcelMgr.mCurrentParcelSelection->mSelectedMultipleOwners =
  1568. request_result == PARCEL_RESULT_MULTIPLE;
  1569. // Select the whole parcel
  1570. if (region)
  1571. {
  1572. if (!snap_selection)
  1573. {
  1574. // Do not muck with the westsouth and eastnorth, just highlight
  1575. // it
  1576. LLVector3 west_south =
  1577. region->getPosRegionFromGlobal(gViewerParcelMgr.mWestSouth);
  1578. LLVector3 east_north =
  1579. region->getPosRegionFromGlobal(gViewerParcelMgr.mEastNorth);
  1580. gViewerParcelMgr.resetSegments(gViewerParcelMgr.mHighlightSegments);
  1581. gViewerParcelMgr.writeHighlightSegments(west_south.mV[VX],
  1582. west_south.mV[VY],
  1583. east_north.mV[VX],
  1584. east_north.mV[VY]);
  1585. gViewerParcelMgr.mCurrentParcelSelection->mWholeParcelSelected = false;
  1586. }
  1587. else if (local_id == 0)
  1588. {
  1589. // This is public land, just highlight the selection
  1590. gViewerParcelMgr.mWestSouth =
  1591. region->getPosGlobalFromRegion(aabb_min);
  1592. gViewerParcelMgr.mEastNorth =
  1593. region->getPosGlobalFromRegion(aabb_max);
  1594. gViewerParcelMgr.resetSegments(gViewerParcelMgr.mHighlightSegments);
  1595. gViewerParcelMgr.writeHighlightSegments(aabb_min.mV[VX],
  1596. aabb_min.mV[VY],
  1597. aabb_max.mV[VX],
  1598. aabb_max.mV[VY]);
  1599. gViewerParcelMgr.mCurrentParcelSelection->mWholeParcelSelected = true;
  1600. }
  1601. else
  1602. {
  1603. gViewerParcelMgr.mWestSouth =
  1604. region->getPosGlobalFromRegion(aabb_min);
  1605. gViewerParcelMgr.mEastNorth =
  1606. region->getPosGlobalFromRegion(aabb_max);
  1607. // Owned land, highlight the boundaries
  1608. S32 bitmap_size = gViewerParcelMgr.mParcelsPerEdge *
  1609. gViewerParcelMgr.mParcelsPerEdge / 8;
  1610. U8* bitmap = new U8[bitmap_size];
  1611. msg->getBinaryDataFast(_PREHASH_ParcelData, _PREHASH_Bitmap,
  1612. bitmap, bitmap_size);
  1613. gViewerParcelMgr.resetSegments(gViewerParcelMgr.mHighlightSegments);
  1614. gViewerParcelMgr.writeSegmentsFromBitmap(bitmap,
  1615. gViewerParcelMgr.mHighlightSegments);
  1616. delete[] bitmap;
  1617. bitmap = NULL;
  1618. gViewerParcelMgr.mCurrentParcelSelection->mWholeParcelSelected = true;
  1619. }
  1620. }
  1621. else // Just after login, we may receive a first reply for the agent
  1622. // parcel with a null host (0.0.0.0:0) after opening the "About
  1623. // land" floater...
  1624. {
  1625. LL_DEBUGS("ParcelMgr") << "Unknown region host: "
  1626. << msg->getSender() << LL_ENDL;
  1627. }
  1628. // Request access list information for this land
  1629. U32 flags = AL_ACCESS | AL_BAN;
  1630. if (gAgent.hasRegionCapability("RegionExperiences"))
  1631. {
  1632. // Only request these flags when experiences are supported
  1633. flags |= AL_ALLOW_EXPERIENCE | AL_BLOCK_EXPERIENCE;
  1634. }
  1635. gViewerParcelMgr.sendParcelAccessListRequest(flags);
  1636. // Request dwell for this land, if it's not public land.
  1637. gViewerParcelMgr.mSelectedDwell = DWELL_NAN;
  1638. if (local_id != 0)
  1639. {
  1640. gViewerParcelMgr.sendParcelDwellRequest();
  1641. }
  1642. gViewerParcelMgr.mSelected = true;
  1643. gViewerParcelMgr.notifySelectionObservers();
  1644. }
  1645. else if (sequence_id == COLLISION_NOT_IN_GROUP_PARCEL_SEQ_ID ||
  1646. sequence_id == COLLISION_NOT_ON_LIST_PARCEL_SEQ_ID ||
  1647. sequence_id == COLLISION_BANNED_PARCEL_SEQ_ID)
  1648. {
  1649. if (region != gAgent.getRegion())
  1650. {
  1651. llwarns << "Received a banned parcel collision message for a non-agent region. Ignoring."
  1652. << llendl;
  1653. return;
  1654. }
  1655. // We are about to collide with this parcel
  1656. gViewerParcelMgr.mRenderCollision = true;
  1657. gViewerParcelMgr.mCollisionTimer.reset();
  1658. // Differentiate this parcel if we are banned from it.
  1659. if (sequence_id == COLLISION_BANNED_PARCEL_SEQ_ID)
  1660. {
  1661. gViewerParcelMgr.mCollisionBanned = BA_BANNED;
  1662. }
  1663. else if (sequence_id == COLLISION_NOT_IN_GROUP_PARCEL_SEQ_ID)
  1664. {
  1665. gViewerParcelMgr.mCollisionBanned = BA_NOT_IN_GROUP;
  1666. }
  1667. else
  1668. {
  1669. gViewerParcelMgr.mCollisionBanned = BA_NOT_ON_LIST;
  1670. }
  1671. S32 bitmap_size = gViewerParcelMgr.mParcelsPerEdge *
  1672. gViewerParcelMgr.mParcelsPerEdge / 8;
  1673. U8* bitmap = new U8[bitmap_size];
  1674. msg->getBinaryDataFast(_PREHASH_ParcelData, _PREHASH_Bitmap,
  1675. bitmap, bitmap_size);
  1676. gViewerParcelMgr.resetSegments(gViewerParcelMgr.mCollisionSegments);
  1677. gViewerParcelMgr.writeSegmentsFromBitmap(bitmap,
  1678. gViewerParcelMgr.mCollisionSegments);
  1679. LLViewerParcelOverlay* overlay = region ? region->mParcelOverlay
  1680. : NULL;
  1681. if (overlay)
  1682. {
  1683. #if 0 // *HACK: do not reset collision parcels when receiving local data
  1684. // so that we can "build history" of collision parcels. This causes
  1685. // false positives sometimes when the parcel data is changing.
  1686. overlay->resetCollisionBitmap();
  1687. #endif
  1688. overlay->readCollisionBitmap(bitmap);
  1689. }
  1690. delete[] bitmap;
  1691. bitmap = NULL;
  1692. }
  1693. else if (sequence_id == HOVERED_PARCEL_SEQ_ID)
  1694. {
  1695. LLViewerRegion* region = gWorld.getRegion(msg->getSender());
  1696. if (region)
  1697. {
  1698. gViewerParcelMgr.mHoverWestSouth = region->getPosGlobalFromRegion(aabb_min);
  1699. gViewerParcelMgr.mHoverEastNorth = region->getPosGlobalFromRegion(aabb_max);
  1700. }
  1701. else
  1702. {
  1703. gViewerParcelMgr.mHoverWestSouth.clear();
  1704. gViewerParcelMgr.mHoverEastNorth.clear();
  1705. }
  1706. }
  1707. else if (sequence_id != UPDATE_AGENT_PARCEL_SEQ_ID)
  1708. {
  1709. // Look for music.
  1710. if (gAudiop)
  1711. {
  1712. if (parcel)
  1713. {
  1714. std::string music_url_raw = parcel->getMusicURL();
  1715. // Trim off whitespace from front and back
  1716. std::string music_url = music_url_raw;
  1717. LLStringUtil::trim(music_url);
  1718. // On entering a new parcel, stop the last stream if the new
  1719. // parcel has a different music url (an empty URL counts as
  1720. // different).
  1721. const std::string& stream_url = gAudiop->getInternetStreamURL();
  1722. if (music_url.empty() || music_url != stream_url)
  1723. {
  1724. // URL is different from one currently playing.
  1725. gAudiop->stopInternetStream();
  1726. // If there is a new music URL and it is valid, play it.
  1727. if (music_url.size() > 12 &&
  1728. (music_url.substr(0, 7) == "http://" ||
  1729. music_url.substr(0, 8) == "https://"))
  1730. {
  1731. // Only play music when you enter a new parcel if the
  1732. // control is in PLAY state. Changed as part of SL-4878
  1733. if (LLViewerParcelMedia::parcelMusicPlaying() &&
  1734. gSavedSettings.getBool("EnableStreamingMusic"))
  1735. {
  1736. LLViewerParcelMedia::playStreamingMusic(parcel);
  1737. }
  1738. }
  1739. else if (!gAudiop->getInternetStreamURL().empty())
  1740. {
  1741. llinfos << "Stopping parcel music" << llendl;
  1742. gAudiop->startInternetStream(LLStringUtil::null);
  1743. }
  1744. }
  1745. }
  1746. else
  1747. {
  1748. // Public land has no music
  1749. gAudiop->stopInternetStream();
  1750. }
  1751. }
  1752. // Now check for video
  1753. LLViewerParcelMedia::update(parcel);
  1754. }
  1755. }
  1756. //static
  1757. void LLViewerParcelMgr::processParcelAccessListReply(LLMessageSystem* msg,
  1758. void**)
  1759. {
  1760. LLParcel* parcel = gViewerParcelMgr.mCurrentParcel;
  1761. if (!parcel)
  1762. {
  1763. return;
  1764. }
  1765. LLUUID agent_id;
  1766. msg->getUUIDFast(_PREHASH_Data, _PREHASH_AgentID, agent_id);
  1767. #if 0 // ignored
  1768. S32 sequence_id = 0;
  1769. msg->getS32Fast(_PREHASH_Data, _PREHASH_SequenceID, sequence_id);
  1770. #endif
  1771. U32 message_flags = 0x0;
  1772. msg->getU32Fast(_PREHASH_Data, _PREHASH_Flags, message_flags);
  1773. S32 parcel_id = INVALID_PARCEL_ID;
  1774. msg->getS32Fast(_PREHASH_Data, _PREHASH_LocalID, parcel_id);
  1775. S32 local_id = parcel->getLocalID();
  1776. if (parcel_id != local_id && local_id != INVALID_PARCEL_ID)
  1777. {
  1778. llwarns << "Parcel access list reply for parcel " << parcel_id
  1779. << " which isn't the selected parcel " << local_id
  1780. << ", ignoring..." << llendl;
  1781. return;
  1782. }
  1783. if (message_flags & AL_ACCESS)
  1784. {
  1785. parcel->unpackAccessEntries(msg, &(parcel->mAccessList));
  1786. }
  1787. else if (message_flags & AL_BAN)
  1788. {
  1789. parcel->unpackAccessEntries(msg, &(parcel->mBanList));
  1790. }
  1791. else if (message_flags & AL_ALLOW_EXPERIENCE)
  1792. {
  1793. parcel->unpackExperienceEntries(msg, EXPERIENCE_KEY_TYPE_ALLOWED);
  1794. }
  1795. else if (message_flags & AL_BLOCK_EXPERIENCE)
  1796. {
  1797. parcel->unpackExperienceEntries(msg, EXPERIENCE_KEY_TYPE_BLOCKED);
  1798. }
  1799. #if 0
  1800. else if (message_flags & AL_RENTER)
  1801. {
  1802. parcel->unpackAccessEntries(msg, &(parcel->mRenterList));
  1803. }
  1804. #endif
  1805. gViewerParcelMgr.notifySelectionObservers();
  1806. }
  1807. //static
  1808. void LLViewerParcelMgr::processParcelDwellReply(LLMessageSystem* msg, void**)
  1809. {
  1810. LLParcel* parcel = gViewerParcelMgr.mCurrentParcel;
  1811. if (!parcel)
  1812. {
  1813. return;
  1814. }
  1815. LLUUID agent_id;
  1816. msg->getUUID(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  1817. S32 local_id;
  1818. msg->getS32(_PREHASH_Data, _PREHASH_LocalID, local_id);
  1819. LLUUID parcel_id;
  1820. msg->getUUID(_PREHASH_Data, _PREHASH_ParcelID, parcel_id);
  1821. F32 dwell;
  1822. msg->getF32(_PREHASH_Data, _PREHASH_Dwell, dwell);
  1823. if (local_id == parcel->getLocalID())
  1824. {
  1825. gViewerParcelMgr.mSelectedDwell = dwell;
  1826. gViewerParcelMgr.notifySelectionObservers();
  1827. }
  1828. }
  1829. void LLViewerParcelMgr::sendParcelAccessListUpdate(U32 which)
  1830. {
  1831. if (!mSelected || !mCurrentParcel)
  1832. {
  1833. return;
  1834. }
  1835. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(mWestSouth);
  1836. if (!region)
  1837. {
  1838. return;
  1839. }
  1840. S32 parcel_local_id = mCurrentParcel->getLocalID();
  1841. if (which & AL_ACCESS)
  1842. {
  1843. LL_DEBUGS("ParcelAccess") << "Sending parcel access list update"
  1844. << LL_ENDL;
  1845. sendParcelAccessListUpdate(AL_ACCESS, mCurrentParcel->mAccessList,
  1846. region, parcel_local_id);
  1847. }
  1848. if (which & AL_BAN)
  1849. {
  1850. LL_DEBUGS("ParcelAccess") << "Sending parcel ban list update"
  1851. << LL_ENDL;
  1852. sendParcelAccessListUpdate(AL_BAN, mCurrentParcel->mBanList,
  1853. region, parcel_local_id);
  1854. }
  1855. if (which & AL_ALLOW_EXPERIENCE)
  1856. {
  1857. sendParcelAccessListUpdate(AL_ALLOW_EXPERIENCE,
  1858. mCurrentParcel->getExperienceKeysByType(EXPERIENCE_KEY_TYPE_ALLOWED),
  1859. region, parcel_local_id);
  1860. }
  1861. if (which & AL_BLOCK_EXPERIENCE)
  1862. {
  1863. sendParcelAccessListUpdate(AL_BLOCK_EXPERIENCE,
  1864. mCurrentParcel->getExperienceKeysByType(EXPERIENCE_KEY_TYPE_BLOCKED),
  1865. region, parcel_local_id);
  1866. }
  1867. }
  1868. void LLViewerParcelMgr::sendParcelAccessListUpdate(U32 flags,
  1869. const access_map_t& entries,
  1870. LLViewerRegion* region,
  1871. S32 parcel_local_id)
  1872. {
  1873. bool is_access = (flags & (AL_ACCESS | AL_BAN)) != 0;
  1874. S32 count = entries.size();
  1875. S32 num_sections = (S32)ceil(count / PARCEL_MAX_ENTRIES_PER_PACKET);
  1876. S32 sequence_id = 1;
  1877. LLUUID transaction_id;
  1878. transaction_id.generate();
  1879. LLMessageSystem* msg = gMessageSystemp;
  1880. bool start_message = true;
  1881. bool initial = true;
  1882. access_map_t::const_iterator cit = entries.begin();
  1883. access_map_t::const_iterator end = entries.end();
  1884. while (cit != end || initial)
  1885. {
  1886. if (start_message)
  1887. {
  1888. msg->newMessageFast(_PREHASH_ParcelAccessListUpdate);
  1889. msg->nextBlockFast(_PREHASH_AgentData);
  1890. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  1891. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  1892. msg->nextBlockFast(_PREHASH_Data);
  1893. msg->addU32Fast(_PREHASH_Flags, flags);
  1894. msg->addS32(_PREHASH_LocalID, parcel_local_id);
  1895. msg->addUUIDFast(_PREHASH_TransactionID, transaction_id);
  1896. msg->addS32Fast(_PREHASH_SequenceID, sequence_id);
  1897. msg->addS32Fast(_PREHASH_Sections, num_sections);
  1898. start_message = false;
  1899. if (initial && cit == end)
  1900. {
  1901. // Pack an empty block if there will be no data
  1902. msg->nextBlockFast(_PREHASH_List);
  1903. msg->addUUIDFast(_PREHASH_ID, LLUUID::null);
  1904. msg->addS32Fast(_PREHASH_Time, 0);
  1905. msg->addU32Fast(_PREHASH_Flags, 0);
  1906. }
  1907. initial = false;
  1908. ++sequence_id;
  1909. }
  1910. while (cit != end && msg->getCurrentSendTotal() < MTUBYTES)
  1911. {
  1912. const LLAccessEntry& entry = cit->second;
  1913. msg->nextBlockFast(_PREHASH_List);
  1914. msg->addUUIDFast(_PREHASH_ID, entry.mID);
  1915. msg->addS32Fast(_PREHASH_Time, entry.mTime);
  1916. msg->addU32Fast(_PREHASH_Flags, entry.mFlags);
  1917. ++cit;
  1918. if (is_access)
  1919. {
  1920. LL_DEBUGS("ParcelAccess") << "Sending data for agent: "
  1921. << entry.mID << LL_ENDL;
  1922. }
  1923. }
  1924. start_message = true;
  1925. msg->sendReliable(region->getHost());
  1926. }
  1927. }
  1928. void LLViewerParcelMgr::deedLandToGroup()
  1929. {
  1930. if (!gCacheNamep) // Paranoia
  1931. {
  1932. return;
  1933. }
  1934. std::string group_name;
  1935. gCacheNamep->getGroupName(mCurrentParcel->getGroupID(), group_name);
  1936. LLSD args;
  1937. args["AREA"] = llformat("%d", mCurrentParcel->getArea());
  1938. args["GROUP_NAME"] = group_name;
  1939. if (mCurrentParcel->getContributeWithDeed())
  1940. {
  1941. std::string first_name, last_name;
  1942. gCacheNamep->getName(mCurrentParcel->getOwnerID(), first_name, last_name);
  1943. args["FIRST_NAME"] = first_name;
  1944. args["LAST_NAME"] = last_name;
  1945. gNotifications.add("DeedLandToGroupWithContribution", args, LLSD(),
  1946. deedAlertCB);
  1947. }
  1948. else
  1949. {
  1950. gNotifications.add("DeedLandToGroup", args, LLSD(), deedAlertCB);
  1951. }
  1952. }
  1953. //static
  1954. bool LLViewerParcelMgr::deedAlertCB(const LLSD& notification,
  1955. const LLSD& response)
  1956. {
  1957. if (LLNotification::getSelectedOption(notification, response) == 0)
  1958. {
  1959. LLUUID group_id;
  1960. LLParcel* parcel = gViewerParcelMgr.getParcelSelection()->getParcel();
  1961. if (parcel)
  1962. {
  1963. group_id = parcel->getGroupID();
  1964. }
  1965. gViewerParcelMgr.sendParcelDeed(group_id);
  1966. }
  1967. return false;
  1968. }
  1969. void LLViewerParcelMgr::startReleaseLand()
  1970. {
  1971. if (!mSelected || !mCurrentParcel)
  1972. {
  1973. gNotifications.add("CannotReleaseLandNothingSelected");
  1974. return;
  1975. }
  1976. if (mRequestResult == PARCEL_RESULT_NO_DATA)
  1977. {
  1978. gNotifications.add("CannotReleaseLandWatingForServer");
  1979. return;
  1980. }
  1981. if (mRequestResult == PARCEL_RESULT_MULTIPLE)
  1982. {
  1983. gNotifications.add("CannotReleaseLandSelected");
  1984. return;
  1985. }
  1986. if (!isParcelOwnedByAgent(mCurrentParcel, GP_LAND_RELEASE) &&
  1987. !gAgent.canManageEstate())
  1988. {
  1989. gNotifications.add("CannotReleaseLandDontOwn");
  1990. return;
  1991. }
  1992. LLVector3d parcel_center = (mWestSouth + mEastNorth) / 2.0;
  1993. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(parcel_center);
  1994. if (!region)
  1995. {
  1996. gNotifications.add("CannotReleaseLandRegionNotFound");
  1997. return;
  1998. }
  1999. #if 0
  2000. if (!gAgent.isGodlike() &&
  2001. region->getRegionFlag(REGION_FLAGS_BLOCK_LAND_RESELL))
  2002. {
  2003. LLSD args;
  2004. args["REGION"] = region->getName();
  2005. gNotifications.add("CannotReleaseLandNoTransfer", args);
  2006. return;
  2007. }
  2008. #endif
  2009. if (!mCurrentParcelSelection->mWholeParcelSelected)
  2010. {
  2011. gNotifications.add("CannotReleaseLandPartialSelection");
  2012. return;
  2013. }
  2014. // Compute claim price
  2015. LLSD args;
  2016. args["AREA"] = llformat("%d",mCurrentParcel->getArea());
  2017. gNotifications.add("ReleaseLandWarning", args, LLSD(), releaseAlertCB);
  2018. }
  2019. bool LLViewerParcelMgr::canAgentBuyParcel(LLParcel* parcel,
  2020. bool for_group) const
  2021. {
  2022. if (!parcel)
  2023. {
  2024. return false;
  2025. }
  2026. if (mSelected && parcel == mCurrentParcel &&
  2027. mRequestResult == PARCEL_RESULT_NO_DATA)
  2028. {
  2029. return false;
  2030. }
  2031. if (parcel->isPublic())
  2032. {
  2033. return true; // change this if want to make it gods only
  2034. }
  2035. LLViewerRegion* regionp = gViewerParcelMgr.getSelectionRegion();
  2036. if (regionp)
  2037. {
  2038. // If the region is PG, we are happy already, so do nothing, but if we
  2039. // are set to avoid either mature or adult, get us outta here.
  2040. U8 sim_access = regionp->getSimAccess();
  2041. if ((sim_access == SIM_ACCESS_MATURE && !gAgent.canAccessMature()) ||
  2042. (sim_access == SIM_ACCESS_ADULT && !gAgent.canAccessAdult()))
  2043. {
  2044. return false;
  2045. }
  2046. }
  2047. const LLUUID& authorize_buyer = parcel->getAuthorizedBuyerID();
  2048. if (!parcel->getForSale() ||
  2049. (parcel->getSalePrice() <= 0 && authorize_buyer.isNull()))
  2050. {
  2051. // Parcel not for sale to anyone
  2052. return false;
  2053. }
  2054. if (authorize_buyer.notNull() && authorize_buyer != gAgentID)
  2055. {
  2056. // Parcel is not reserved for buying by this agent
  2057. return false;
  2058. }
  2059. const LLUUID& parcel_owner = parcel->getOwnerID();
  2060. if (for_group)
  2061. {
  2062. if (parcel_owner == gAgent.getGroupID())
  2063. {
  2064. // Already owning this parcel ! We are actually selling it...
  2065. return false;
  2066. }
  2067. if (!gAgent.hasPowerInActiveGroup(GP_LAND_DEED))
  2068. {
  2069. // Agent not empowered with group land deeding
  2070. return false;
  2071. }
  2072. }
  2073. else if (parcel_owner == gAgentID)
  2074. {
  2075. // Already owning this parcel ! We are actually selling it...
  2076. return false;
  2077. }
  2078. return true;
  2079. }
  2080. void LLViewerParcelMgr::startBuyLand(bool is_for_group)
  2081. {
  2082. LLFloaterBuyLand::buyLand(getSelectionRegion(), mCurrentParcelSelection,
  2083. is_for_group);
  2084. }
  2085. void LLViewerParcelMgr::startSellLand()
  2086. {
  2087. LLFloaterSellLand::sellLand(getSelectionRegion(), mCurrentParcelSelection);
  2088. }
  2089. void LLViewerParcelMgr::startDivideLand()
  2090. {
  2091. if (!mSelected)
  2092. {
  2093. gNotifications.add("CannotDivideLandNothingSelected");
  2094. return;
  2095. }
  2096. if (mCurrentParcelSelection->mWholeParcelSelected)
  2097. {
  2098. gNotifications.add("CannotDivideLandPartialSelection");
  2099. return;
  2100. }
  2101. LLSD payload;
  2102. payload["west_south_border"] = ll_sd_from_vector3d(mWestSouth);
  2103. payload["east_north_border"] = ll_sd_from_vector3d(mEastNorth);
  2104. gNotifications.add("LandDivideWarning", LLSD(), payload,
  2105. callbackDivideLand);
  2106. }
  2107. //static
  2108. bool LLViewerParcelMgr::callbackDivideLand(const LLSD& notification,
  2109. const LLSD& response)
  2110. {
  2111. if (LLNotification::getSelectedOption(notification, response) == 0)
  2112. {
  2113. LLVector3d west_south_d =
  2114. ll_vector3d_from_sd(notification["payload"]["west_south_border"]);
  2115. LLVector3d east_north_d =
  2116. ll_vector3d_from_sd(notification["payload"]["east_north_border"]);
  2117. LLVector3d parcel_center = (west_south_d + east_north_d) / 2.0;
  2118. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(parcel_center);
  2119. if (!region)
  2120. {
  2121. gNotifications.add("CannotDivideLandNoRegion");
  2122. return false;
  2123. }
  2124. LLVector3 west_south = region->getPosRegionFromGlobal(west_south_d);
  2125. LLVector3 east_north = region->getPosRegionFromGlobal(east_north_d);
  2126. LLMessageSystem* msg = gMessageSystemp;
  2127. msg->newMessage(_PREHASH_ParcelDivide);
  2128. msg->nextBlock(_PREHASH_AgentData);
  2129. msg->addUUID(_PREHASH_AgentID, gAgentID);
  2130. msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
  2131. msg->nextBlock(_PREHASH_ParcelData);
  2132. msg->addF32(_PREHASH_West, west_south.mV[VX]);
  2133. msg->addF32(_PREHASH_South, west_south.mV[VY]);
  2134. msg->addF32(_PREHASH_East, east_north.mV[VX]);
  2135. msg->addF32(_PREHASH_North, east_north.mV[VY]);
  2136. msg->sendReliable(region->getHost());
  2137. }
  2138. return false;
  2139. }
  2140. void LLViewerParcelMgr::startJoinLand()
  2141. {
  2142. if (!mSelected)
  2143. {
  2144. gNotifications.add("CannotJoinLandNothingSelected");
  2145. return;
  2146. }
  2147. if (mCurrentParcelSelection->mWholeParcelSelected)
  2148. {
  2149. gNotifications.add("CannotJoinLandEntireParcelSelected");
  2150. return;
  2151. }
  2152. if (!mCurrentParcelSelection->mSelectedMultipleOwners)
  2153. {
  2154. gNotifications.add("CannotJoinLandSelection");
  2155. return;
  2156. }
  2157. LLSD payload;
  2158. payload["west_south_border"] = ll_sd_from_vector3d(mWestSouth);
  2159. payload["east_north_border"] = ll_sd_from_vector3d(mEastNorth);
  2160. gNotifications.add("JoinLandWarning", LLSD(), payload, callbackJoinLand);
  2161. }
  2162. //static
  2163. bool LLViewerParcelMgr::callbackJoinLand(const LLSD& notification,
  2164. const LLSD& response)
  2165. {
  2166. if (LLNotification::getSelectedOption(notification, response) == 0)
  2167. {
  2168. LLVector3d west_south_d =
  2169. ll_vector3d_from_sd(notification["payload"]["west_south_border"]);
  2170. LLVector3d east_north_d =
  2171. ll_vector3d_from_sd(notification["payload"]["east_north_border"]);
  2172. LLVector3d parcel_center = (west_south_d + east_north_d) / 2.0;
  2173. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(parcel_center);
  2174. if (!region)
  2175. {
  2176. gNotifications.add("CannotJoinLandNoRegion");
  2177. return false;
  2178. }
  2179. LLVector3 west_south = region->getPosRegionFromGlobal(west_south_d);
  2180. LLVector3 east_north = region->getPosRegionFromGlobal(east_north_d);
  2181. LLMessageSystem* msg = gMessageSystemp;
  2182. msg->newMessage(_PREHASH_ParcelJoin);
  2183. msg->nextBlock(_PREHASH_AgentData);
  2184. msg->addUUID(_PREHASH_AgentID, gAgentID);
  2185. msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
  2186. msg->nextBlock(_PREHASH_ParcelData);
  2187. msg->addF32(_PREHASH_West, west_south.mV[VX]);
  2188. msg->addF32(_PREHASH_South, west_south.mV[VY]);
  2189. msg->addF32(_PREHASH_East, east_north.mV[VX]);
  2190. msg->addF32(_PREHASH_North, east_north.mV[VY]);
  2191. msg->sendReliable(region->getHost());
  2192. }
  2193. return false;
  2194. }
  2195. void LLViewerParcelMgr::startDeedLandToGroup()
  2196. {
  2197. if (!mSelected || !mCurrentParcel)
  2198. {
  2199. gNotifications.add("CannotDeedLandNothingSelected");
  2200. return;
  2201. }
  2202. if (mRequestResult == PARCEL_RESULT_NO_DATA)
  2203. {
  2204. gNotifications.add("CannotDeedLandWaitingForServer");
  2205. return;
  2206. }
  2207. if (mRequestResult == PARCEL_RESULT_MULTIPLE)
  2208. {
  2209. gNotifications.add("CannotDeedLandMultipleSelected");
  2210. return;
  2211. }
  2212. LLVector3d parcel_center = (mWestSouth + mEastNorth) / 2.0;
  2213. LLViewerRegion* region = gWorld.getRegionFromPosGlobal(parcel_center);
  2214. if (!region)
  2215. {
  2216. gNotifications.add("CannotDeedLandNoRegion");
  2217. return;
  2218. }
  2219. #if 0
  2220. if (!gAgent.isGodlike() &&
  2221. region->getRegionFlag(REGION_FLAGS_BLOCK_LAND_RESELL) &&
  2222. mCurrentParcel->getOwnerID() != region->getOwner())
  2223. {
  2224. LLSD args;
  2225. args["REGION"] = region->getName();
  2226. gNotifications.add("CannotDeedLandNoTransfer", args);
  2227. return;
  2228. }
  2229. #endif
  2230. deedLandToGroup();
  2231. }
  2232. void LLViewerParcelMgr::reclaimParcel()
  2233. {
  2234. LLParcel* parcel = gViewerParcelMgr.getParcelSelection()->getParcel();
  2235. LLViewerRegion* regionp = gViewerParcelMgr.getSelectionRegion();
  2236. if (parcel && parcel->getOwnerID().notNull()
  2237. && parcel->getOwnerID() != gAgentID
  2238. && regionp && regionp->getOwner() == gAgentID)
  2239. {
  2240. LLMessageSystem* msg = gMessageSystemp;
  2241. msg->newMessage(_PREHASH_ParcelReclaim);
  2242. msg->nextBlock(_PREHASH_AgentData);
  2243. msg->addUUID(_PREHASH_AgentID, gAgentID);
  2244. msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
  2245. msg->nextBlock(_PREHASH_Data);
  2246. msg->addS32(_PREHASH_LocalID, parcel->getLocalID());
  2247. msg->sendReliable(regionp->getHost());
  2248. }
  2249. }
  2250. //static
  2251. bool LLViewerParcelMgr::releaseAlertCB(const LLSD& notification,
  2252. const LLSD& response)
  2253. {
  2254. if (LLNotification::getSelectedOption(notification, response) == 0)
  2255. {
  2256. // Send the release message, not a force
  2257. gViewerParcelMgr.sendParcelRelease();
  2258. }
  2259. return false;
  2260. }
  2261. void LLViewerParcelMgr::buyPass()
  2262. {
  2263. LLParcel* parcel = getParcelSelection()->getParcel();
  2264. if (!parcel) return;
  2265. LLViewerRegion* region = getSelectionRegion();
  2266. if (!region) return;
  2267. LLMessageSystem* msg = gMessageSystemp;
  2268. msg->newMessageFast(_PREHASH_ParcelBuyPass);
  2269. msg->nextBlock(_PREHASH_AgentData);
  2270. msg->addUUID(_PREHASH_AgentID, gAgentID);
  2271. msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
  2272. msg->nextBlockFast(_PREHASH_ParcelData);
  2273. msg->addS32Fast(_PREHASH_LocalID, parcel->getLocalID());
  2274. msg->sendReliable(region->getHost());
  2275. }
  2276. // Tells whether we are allowed to buy a pass or not
  2277. bool LLViewerParcelMgr::isCollisionBanned()
  2278. {
  2279. return !(mCollisionBanned == BA_ALLOWED ||
  2280. mCollisionBanned == BA_NOT_ON_LIST ||
  2281. mCollisionBanned == BA_NOT_IN_GROUP);
  2282. }
  2283. // This implementation should mirror LLSimParcelMgr::isParcelOwnedBy
  2284. //static
  2285. bool LLViewerParcelMgr::isParcelOwnedByAgent(const LLParcel* parcelp,
  2286. U64 group_proxy_power)
  2287. {
  2288. if (!parcelp)
  2289. {
  2290. return false;
  2291. }
  2292. if (gAgent.isGodlike() || // Gods can always assume ownership.
  2293. // The owner of a parcel automatically gets all powers.
  2294. parcelp->getOwnerID() == gAgentID)
  2295. {
  2296. return true;
  2297. }
  2298. // Only gods can assume 'ownership' of public land.
  2299. if (parcelp->isPublic())
  2300. {
  2301. return false;
  2302. }
  2303. // Return whether or not the agent has group_proxy_power powers in the
  2304. // parcel's group.
  2305. return gAgent.hasPowerInGroup(parcelp->getOwnerID(), group_proxy_power);
  2306. }
  2307. // This implementation should mirror llSimParcelMgr::isParcelModifiableBy
  2308. //static
  2309. bool LLViewerParcelMgr::isParcelModifiableByAgent(const LLParcel* parcelp,
  2310. U64 group_proxy_power)
  2311. {
  2312. if (!parcelp)
  2313. {
  2314. return false;
  2315. }
  2316. // If the parcel is not OS_LEASED for agent-owned parcels, then it cannot
  2317. // be modified anyway.
  2318. if (parcelp->getOwnerID() == gAgentID && !gAgent.isGodlike() &&
  2319. parcelp->getOwnershipStatus() != LLParcel::OS_LEASED)
  2320. {
  2321. return false;
  2322. }
  2323. // *NOTE: This should only work for leased parcels, but group owned
  2324. // parcels cannot be OS_LEASED yet. Phoenix 2003-12-15.
  2325. return isParcelOwnedByAgent(parcelp, group_proxy_power);
  2326. }
  2327. void sanitize_corners(const LLVector3d& corner1, const LLVector3d& corner2,
  2328. LLVector3d& west_south_bottom, LLVector3d& east_north_top)
  2329. {
  2330. west_south_bottom.mdV[VX] = llmin(corner1.mdV[VX], corner2.mdV[VX]);
  2331. west_south_bottom.mdV[VY] = llmin(corner1.mdV[VY], corner2.mdV[VY]);
  2332. west_south_bottom.mdV[VZ] = llmin(corner1.mdV[VZ], corner2.mdV[VZ]);
  2333. east_north_top.mdV[VX] = llmax(corner1.mdV[VX], corner2.mdV[VX]);
  2334. east_north_top.mdV[VY] = llmax(corner1.mdV[VY], corner2.mdV[VY]);
  2335. east_north_top.mdV[VZ] = llmax(corner1.mdV[VZ], corner2.mdV[VZ]);
  2336. }
  2337. LLViewerTexture* LLViewerParcelMgr::getBlockedImage() const
  2338. {
  2339. return sBlockedImage;
  2340. }
  2341. LLViewerTexture* LLViewerParcelMgr::getPassImage() const
  2342. {
  2343. return sPassImage;
  2344. }
  2345. boost::signals2::connection LLViewerParcelMgr::addAgentParcelChangedCB(parcel_changed_cb_t cb)
  2346. {
  2347. return mAgentParcelChangedSignal.connect(cb);
  2348. }
  2349. // This callback is called without delay (i.e. without waiting for the new
  2350. // parcel data) after the agent is teleported; it is used to close TP-related
  2351. // floaters on successful teleports.
  2352. boost::signals2::connection LLViewerParcelMgr::setTPArrivingCallback(parcel_changed_cb_t cb)
  2353. {
  2354. return mTeleportArrivingSignal.connect(cb);
  2355. }
  2356. // Set finish teleport callback. You can use it to observe all teleport events.
  2357. // NOTE: After local teleports we cannot rely on gAgent.getPositionGlobal(), so
  2358. // the new position gets passed explicitly. Use args of this callback to get
  2359. // global position of avatar after teleport event.
  2360. boost::signals2::connection LLViewerParcelMgr::setTPFinishedCallback(tp_finished_cb_t cb)
  2361. {
  2362. return mTeleportFinishedSignal.connect(cb);
  2363. }
  2364. boost::signals2::connection LLViewerParcelMgr::setTPFailedCallback(parcel_changed_cb_t cb)
  2365. {
  2366. return mTeleportFailedSignal.connect(cb);
  2367. }
  2368. // We are notified that the teleport has been finished. We should now propagate
  2369. // the notification via mTeleportFinishedSignal to all interested parties.
  2370. void LLViewerParcelMgr::onTeleportFinished(bool local,
  2371. const LLVector3d& new_pos)
  2372. {
  2373. mTeleportArrivingSignal();
  2374. // Treat only teleports within the same parcel as local (EXT-3139).
  2375. if (local && inAgentParcel(new_pos))
  2376. {
  2377. // Local teleport. We already have the agent parcel data.
  2378. // Emit the signal immediately.
  2379. mTeleportFinishedSignal(new_pos, local);
  2380. }
  2381. else
  2382. {
  2383. // Non-local teleport (inter-region or between different parcels of the
  2384. // same region). The agent parcel data has not been updated yet. Let's
  2385. // wait for the update and then emit the signal.
  2386. mTeleportInProgress = true;
  2387. }
  2388. }
  2389. void LLViewerParcelMgr::onTeleportFailed()
  2390. {
  2391. mTeleportFailedSignal();
  2392. }
  2393. ///////////////////////////////////////////////////////////////////////////////
  2394. // Methods for parcel info observers (implemented in llremoteparcelrequest.cpp
  2395. // in v3 viewers).
  2396. void LLViewerParcelMgr::addInfoObserver(const LLUUID& parcel_id,
  2397. LLParcelInfoObserver* obs)
  2398. {
  2399. if (!obs || parcel_id.isNull()) return;
  2400. for (info_obs_multimap_t::iterator
  2401. it = mInfoObservers.lower_bound(parcel_id),
  2402. end = mInfoObservers.upper_bound(parcel_id);
  2403. it != end; ++it)
  2404. {
  2405. if (it->second.get() == obs)
  2406. {
  2407. return;
  2408. }
  2409. }
  2410. mInfoObservers.emplace(parcel_id, obs->getObserverHandle());
  2411. }
  2412. void LLViewerParcelMgr::removeInfoObserver(const LLUUID& parcel_id,
  2413. LLParcelInfoObserver* obs)
  2414. {
  2415. if (!obs || parcel_id.isNull()) return;
  2416. for (info_obs_multimap_t::iterator
  2417. it = mInfoObservers.lower_bound(parcel_id),
  2418. end = mInfoObservers.upper_bound(parcel_id);
  2419. it != end; ++it)
  2420. {
  2421. if (it->second.get() == obs)
  2422. {
  2423. mInfoObservers.erase(it);
  2424. break;
  2425. }
  2426. }
  2427. }
  2428. //static
  2429. void LLViewerParcelMgr::processParcelInfoReply(LLMessageSystem* msg, void**)
  2430. {
  2431. LLParcelData parcel_data;
  2432. msg->getUUID(_PREHASH_Data, _PREHASH_ParcelID, parcel_data.mParcelId);
  2433. msg->getUUID(_PREHASH_Data, _PREHASH_OwnerID, parcel_data.mOwnerId);
  2434. msg->getString(_PREHASH_Data, _PREHASH_Name, parcel_data.mName);
  2435. msg->getString(_PREHASH_Data, _PREHASH_Desc, parcel_data.mDesc);
  2436. msg->getS32(_PREHASH_Data, _PREHASH_ActualArea, parcel_data.mActualArea);
  2437. msg->getS32(_PREHASH_Data, _PREHASH_BillableArea, parcel_data.mBillableArea);
  2438. msg->getU8(_PREHASH_Data, _PREHASH_Flags, parcel_data.mFlags);
  2439. msg->getF32(_PREHASH_Data, _PREHASH_GlobalX, parcel_data.mGlobalX);
  2440. msg->getF32(_PREHASH_Data, _PREHASH_GlobalY, parcel_data.mGlobalY);
  2441. msg->getF32(_PREHASH_Data, _PREHASH_GlobalZ, parcel_data.mGlobalZ);
  2442. msg->getString(_PREHASH_Data, _PREHASH_SimName, parcel_data.mSimName);
  2443. msg->getUUID(_PREHASH_Data, _PREHASH_SnapshotID, parcel_data.mSnapshotId);
  2444. msg->getF32(_PREHASH_Data, _PREHASH_Dwell, parcel_data.mDwell);
  2445. msg->getS32(_PREHASH_Data, _PREHASH_SalePrice, parcel_data.mSalePrice);
  2446. msg->getS32(_PREHASH_Data, _PREHASH_AuctionID, parcel_data.mAuctionId);
  2447. typedef std::vector<info_obs_multimap_t::iterator> deadlist_t;
  2448. deadlist_t dead_iters;
  2449. const LLUUID& parcel_id = parcel_data.mParcelId;
  2450. info_obs_multimap_t::iterator obs_it, obs_end;
  2451. obs_it = gViewerParcelMgr.mInfoObservers.lower_bound(parcel_id);
  2452. obs_end = gViewerParcelMgr.mInfoObservers.upper_bound(parcel_id);
  2453. while (obs_it != obs_end)
  2454. {
  2455. // Increment the loop iterator now since it may become invalid below
  2456. info_obs_multimap_t::iterator cur_it = obs_it++;
  2457. LLParcelInfoObserver* observer = cur_it->second.get();
  2458. if (observer)
  2459. {
  2460. // May invalidate cur_it if the observer removes itself
  2461. observer->processParcelInfo(parcel_data);
  2462. }
  2463. else
  2464. {
  2465. // The handle points to an expired observer, so do not keep it
  2466. dead_iters.push_back(cur_it);
  2467. }
  2468. }
  2469. // Remove iterators correpsonding to dead observers
  2470. for (deadlist_t::iterator it = dead_iters.begin(), end = dead_iters.end();
  2471. it != end; ++it)
  2472. {
  2473. gViewerParcelMgr.mInfoObservers.erase(*it);
  2474. }
  2475. }
  2476. void LLViewerParcelMgr::sendParcelInfoRequest(const LLUUID& parcel_id)
  2477. {
  2478. LLMessageSystem* msg = gMessageSystemp;
  2479. if (msg)
  2480. {
  2481. msg->newMessage(_PREHASH_ParcelInfoRequest);
  2482. msg->nextBlockFast(_PREHASH_AgentData);
  2483. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  2484. msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
  2485. msg->nextBlock(_PREHASH_Data);
  2486. msg->addUUID(_PREHASH_ParcelID, parcel_id);
  2487. gAgent.sendReliableMessage();
  2488. }
  2489. }
  2490. bool LLViewerParcelMgr::requestRegionParcelInfo(const std::string& url,
  2491. const LLUUID& region_id,
  2492. const LLVector3& region_pos,
  2493. const LLVector3d& global_pos,
  2494. LLHandle<LLParcelInfoObserver> obs_handle)
  2495. {
  2496. if (url.empty()) return false;
  2497. gCoros.launch("LLViewerParcelMgr::regionParcelInfoCoro",
  2498. boost::bind(&LLViewerParcelMgr::regionParcelInfoCoro, this,
  2499. url, region_id, region_pos, global_pos,
  2500. obs_handle));
  2501. return true;
  2502. }
  2503. void LLViewerParcelMgr::regionParcelInfoCoro(const std::string& url,
  2504. LLUUID region_id,
  2505. LLVector3 pos_region,
  2506. LLVector3d pos_global,
  2507. LLHandle<LLParcelInfoObserver> obs_handle)
  2508. {
  2509. LLSD body;
  2510. body["location"] = ll_sd_from_vector3(pos_region);
  2511. if (region_id.notNull())
  2512. {
  2513. body["region_id"] = region_id;
  2514. }
  2515. if (!pos_global.isExactlyZero())
  2516. {
  2517. U64 region_handle = to_region_handle(pos_global);
  2518. body["region_handle"] = ll_sd_from_U64(region_handle);
  2519. }
  2520. LLCoreHttpUtil::HttpCoroutineAdapter adapter("regionParcelInfoCoro");
  2521. LLSD result = adapter.postAndSuspend(url, body);
  2522. LLParcelInfoObserver* observer = obs_handle.get();
  2523. if (!observer) return; // Observer has since been removed
  2524. LLCore::HttpStatus status =
  2525. LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(result);
  2526. if (status)
  2527. {
  2528. if (result.isMap() && result.has("parcel_id"))
  2529. {
  2530. LLUUID parcel_id = result["parcel_id"];
  2531. observer->setParcelID(parcel_id);
  2532. }
  2533. else
  2534. {
  2535. llwarns << "Malformed response contents fetching info for parcel at: "
  2536. << pos_region << " - In region: " << region_id << llendl;
  2537. }
  2538. }
  2539. else
  2540. {
  2541. observer->setErrorStatus(status.getType(), status.getMessage());
  2542. }
  2543. }
  2544. ///////////////////////////////////////////////////////////////////////////////
  2545. // Methods that used to be in llglsandbox.cpp
  2546. // Used by lltoolselectland
  2547. void LLViewerParcelMgr::renderRect(const LLVector3d& west_south_bottom_global,
  2548. const LLVector3d& east_north_top_global)
  2549. {
  2550. LLGLSUIDefault gls_ui;
  2551. gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
  2552. LLGLDepthTest gls_depth(GL_TRUE);
  2553. LLVector3 west_south_bottom_agent =
  2554. gAgent.getPosAgentFromGlobal(west_south_bottom_global);
  2555. F32 west = west_south_bottom_agent.mV[VX];
  2556. F32 south = west_south_bottom_agent.mV[VY];
  2557. LLVector3 east_north_top_agent = gAgent.getPosAgentFromGlobal(east_north_top_global);
  2558. F32 east = east_north_top_agent.mV[VX];
  2559. F32 north = east_north_top_agent.mV[VY];
  2560. #if 0
  2561. F32 top = east_north_top_agent.mV[VZ] + 1.f;
  2562. F32 bottom = west_south_bottom_agent.mV[VZ] - 1.f;
  2563. #endif
  2564. // *HACK: at edge of last region of world, we need to make sure the region
  2565. // resolves correctly so we can get a height value.
  2566. constexpr F32 FUDGE = 0.01f;
  2567. F32 sw_bottom = gWorld.resolveLandHeightAgent(LLVector3(west, south, 0.f));
  2568. F32 se_bottom =
  2569. gWorld.resolveLandHeightAgent(LLVector3(east - FUDGE, south, 0.f));
  2570. F32 ne_bottom = gWorld.resolveLandHeightAgent(LLVector3(east - FUDGE,
  2571. north - FUDGE,
  2572. 0.f));
  2573. F32 nw_bottom = gWorld.resolveLandHeightAgent(LLVector3(west,
  2574. north - FUDGE,
  2575. 0.f));
  2576. F32 sw_top = sw_bottom + PARCEL_POST_HEIGHT;
  2577. F32 se_top = se_bottom + PARCEL_POST_HEIGHT;
  2578. F32 ne_top = ne_bottom + PARCEL_POST_HEIGHT;
  2579. F32 nw_top = nw_bottom + PARCEL_POST_HEIGHT;
  2580. LLUI::setLineWidth(2.f);
  2581. gGL.color4f(1.f, 1.f, 0.f, 1.f);
  2582. // Cheat and give this the same pick-name as land
  2583. gGL.begin(LLRender::LINES);
  2584. {
  2585. gGL.vertex3f(west, north, nw_bottom);
  2586. gGL.vertex3f(west, north, nw_top);
  2587. gGL.vertex3f(east, north, ne_bottom);
  2588. gGL.vertex3f(east, north, ne_top);
  2589. gGL.vertex3f(east, south, se_bottom);
  2590. gGL.vertex3f(east, south, se_top);
  2591. gGL.vertex3f(west, south, sw_bottom);
  2592. gGL.vertex3f(west, south, sw_top);
  2593. }
  2594. gGL.end();
  2595. gGL.color4f(1.f, 1.f, 0.f, 0.2f);
  2596. gGL.begin(LLRender::TRIANGLES);
  2597. {
  2598. gGL.vertex3f(west, north, nw_bottom);
  2599. gGL.vertex3f(west, north, nw_top);
  2600. gGL.vertex3f(east, north, ne_top);
  2601. gGL.vertex3f(west, north, nw_bottom);
  2602. gGL.vertex3f(east, north, ne_top);
  2603. gGL.vertex3f(east, north, ne_bottom);
  2604. gGL.vertex3f(east, north, ne_bottom);
  2605. gGL.vertex3f(east, north, ne_top);
  2606. gGL.vertex3f(east, south, se_top);
  2607. gGL.vertex3f(east, north, ne_bottom);
  2608. gGL.vertex3f(east, south, se_top);
  2609. gGL.vertex3f(east, south, se_bottom);
  2610. gGL.vertex3f(east, south, se_bottom);
  2611. gGL.vertex3f(east, south, se_top);
  2612. gGL.vertex3f(west, south, sw_top);
  2613. gGL.vertex3f(east, south, se_bottom);
  2614. gGL.vertex3f(west, south, sw_top);
  2615. gGL.vertex3f(west, south, sw_bottom);
  2616. gGL.vertex3f(west, south, sw_bottom);
  2617. gGL.vertex3f(west, south, sw_top);
  2618. gGL.vertex3f(west, north, nw_top);
  2619. gGL.vertex3f(west, south, sw_bottom);
  2620. gGL.vertex3f(west, north, nw_top);
  2621. gGL.vertex3f(west, north, nw_bottom);
  2622. }
  2623. gGL.end();
  2624. LLUI::setLineWidth(1.f);
  2625. }
  2626. // North = a wall going north/south. Need that info to set up texture
  2627. // coordinates correctly.
  2628. void LLViewerParcelMgr::renderOneSegment(F32 x1, F32 y1, F32 x2, F32 y2,
  2629. F32 height, U8 direction,
  2630. LLViewerRegion* regionp)
  2631. {
  2632. if (!regionp)
  2633. {
  2634. return;
  2635. }
  2636. // Variable region size support
  2637. F32 border = regionp->getWidth() - 0.1f;
  2638. // *HACK: at edge of last region of world, we need to make sure the region
  2639. // resolves correctly so we can get a height value.
  2640. F32 clamped_x1 = llmin(x1, border);
  2641. F32 clamped_y1 = llmin(y1, border);
  2642. F32 clamped_x2 = llmin(x2, border);
  2643. F32 clamped_y2 = llmin(y2, border);
  2644. F32 z1 = regionp->getLand().resolveHeightRegion(LLVector3(clamped_x1,
  2645. clamped_y1,
  2646. 0.f));
  2647. F32 z2 = regionp->getLand().resolveHeightRegion(LLVector3(clamped_x2,
  2648. clamped_y2,
  2649. 0.f));
  2650. // Convert x1 and x2 from region-local to agent coords.
  2651. LLVector3 origin = regionp->getOriginAgent();
  2652. x1 += origin.mV[VX];
  2653. x2 += origin.mV[VX];
  2654. y1 += origin.mV[VY];
  2655. y2 += origin.mV[VY];
  2656. if (height < 1.f)
  2657. {
  2658. F32 z = z1 + height;
  2659. gGL.vertex3f(x1, y1, z);
  2660. gGL.vertex3f(x1, y1, z1);
  2661. z = z2 + height;
  2662. gGL.vertex3f(x2, y2, z);
  2663. gGL.vertex3f(x2, y2, z);
  2664. gGL.vertex3f(x1, y1, z1);
  2665. gGL.vertex3f(x2, y2, z2);
  2666. }
  2667. else
  2668. {
  2669. F32 tex_coord1, tex_coord2;
  2670. if (direction == WEST_MASK)
  2671. {
  2672. tex_coord1 = y1;
  2673. tex_coord2 = y2;
  2674. }
  2675. else if (direction == SOUTH_MASK)
  2676. {
  2677. tex_coord1 = x1;
  2678. tex_coord2 = x2;
  2679. }
  2680. else if (direction == EAST_MASK)
  2681. {
  2682. tex_coord1 = y2;
  2683. tex_coord2 = y1;
  2684. }
  2685. else // if (direction == NORTH_MASK)
  2686. {
  2687. tex_coord1 = x2;
  2688. tex_coord2 = x1;
  2689. }
  2690. gGL.texCoord2f(tex_coord1 * 0.5f + 0.5f, z1 * 0.5f);
  2691. gGL.vertex3f(x1, y1, z1);
  2692. gGL.texCoord2f(tex_coord2 * 0.5f + 0.5f, z2 * 0.5f);
  2693. gGL.vertex3f(x2, y2, z2);
  2694. // Top edge stairsteps
  2695. F32 z = llmax(z2 + height, z1 + height);
  2696. gGL.texCoord2f(tex_coord1 * 0.5f + 0.5f, z * 0.5f);
  2697. gGL.vertex3f(x1, y1, z);
  2698. gGL.texCoord2f(tex_coord1 * 0.5f + 0.5f, z * 0.5f);
  2699. gGL.vertex3f(x1, y1, z);
  2700. gGL.texCoord2f(tex_coord2 * 0.5f+ 0.5f, z * 0.5f);
  2701. gGL.vertex3f(x2, y2, z);
  2702. gGL.texCoord2f(tex_coord1 * 0.5f + 0.5f, z1 * 0.5f);
  2703. gGL.vertex3f(x1, y1, z1);
  2704. }
  2705. }
  2706. void LLViewerParcelMgr::renderHighlightSegments(const U8* segments,
  2707. LLViewerRegion* regionp)
  2708. {
  2709. bool has_segments = false;
  2710. LLGLSUIDefault gls_ui;
  2711. gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
  2712. LLGLDepthTest gls_depth(GL_TRUE);
  2713. gGL.color4f(1.f, 1.f, 0.f, 0.2f);
  2714. const S32 stride = mParcelsPerEdge + 1;
  2715. for (S32 y = 0; y < stride; ++y)
  2716. {
  2717. for (S32 x = 0; x < stride; ++x)
  2718. {
  2719. U8 segment_mask = segments[x + y * stride];
  2720. if (segment_mask & SOUTH_MASK)
  2721. {
  2722. F32 x1 = x * PARCEL_GRID_STEP_METERS;
  2723. F32 y1 = y * PARCEL_GRID_STEP_METERS;
  2724. if (!has_segments)
  2725. {
  2726. has_segments = true;
  2727. gGL.begin(LLRender::TRIANGLES);
  2728. }
  2729. renderOneSegment(x1, y1, x1 + PARCEL_GRID_STEP_METERS, y1,
  2730. PARCEL_POST_HEIGHT, SOUTH_MASK, regionp);
  2731. }
  2732. if (segment_mask & WEST_MASK)
  2733. {
  2734. F32 x1 = x * PARCEL_GRID_STEP_METERS;
  2735. F32 y1 = y * PARCEL_GRID_STEP_METERS;
  2736. if (!has_segments)
  2737. {
  2738. has_segments = true;
  2739. gGL.begin(LLRender::TRIANGLES);
  2740. }
  2741. renderOneSegment(x1, y1, x1, y1 + PARCEL_GRID_STEP_METERS,
  2742. PARCEL_POST_HEIGHT, WEST_MASK, regionp);
  2743. }
  2744. }
  2745. }
  2746. if (has_segments)
  2747. {
  2748. gGL.end();
  2749. }
  2750. }
  2751. void LLViewerParcelMgr::renderCollisionSegments(U8* segments, bool use_pass,
  2752. LLViewerRegion* regionp)
  2753. {
  2754. LLVector3 pos = gAgent.getPositionAgent();
  2755. F32 pos_x = pos.mV[VX];
  2756. F32 pos_y = pos.mV[VY];
  2757. LLGLSUIDefault gls_ui;
  2758. LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
  2759. LLGLDisable cull(GL_CULL_FACE);
  2760. F32 collision_height;
  2761. if (mCollisionBanned == BA_BANNED ||
  2762. regionp->getRegionFlag(REGION_FLAGS_BLOCK_FLYOVER))
  2763. {
  2764. collision_height = BAN_HEIGHT;
  2765. }
  2766. else
  2767. {
  2768. collision_height = PARCEL_HEIGHT;
  2769. }
  2770. if (use_pass && mCollisionBanned == BA_NOT_ON_LIST)
  2771. {
  2772. gGL.getTexUnit(0)->bind(mPassImage);
  2773. }
  2774. else
  2775. {
  2776. gGL.getTexUnit(0)->bind(mBlockedImage);
  2777. }
  2778. gGL.begin(LLRender::TRIANGLES);
  2779. constexpr F32 MAX_ALPHA = 0.95f;
  2780. constexpr F32 MIN_ALPHA = 0.1f;
  2781. constexpr S32 DIST_OFFSET = 5;
  2782. constexpr S32 MIN_DIST_SQ = DIST_OFFSET * DIST_OFFSET;
  2783. // I made this setting configurable, since depending on the conditions
  2784. // (e.g. when riding a vehicle at high speed or with a high inertia), the
  2785. // user may want some more forewarning... HB
  2786. static LLCachedControl<U32> max_dist(gSavedSettings,
  2787. "RenderBanWallMaxDist");
  2788. const S32 max_dist_sq = llclamp(S32(max_dist * max_dist), 100, 2500);
  2789. const F32 alpha0 = 30.f / 169.f * F32(max_dist_sq);
  2790. const S32 stride = mParcelsPerEdge + 1;
  2791. F32 x1, y1; // Start point
  2792. F32 x2, y2; // End point
  2793. F32 alpha;
  2794. F32 dx, dy;
  2795. for (S32 y = 0; y < stride; ++y)
  2796. {
  2797. for (S32 x = 0; x < stride; ++x)
  2798. {
  2799. U8 segment_mask = segments[x + y * stride];
  2800. if (segment_mask & SOUTH_MASK)
  2801. {
  2802. x1 = x * PARCEL_GRID_STEP_METERS;
  2803. y1 = y * PARCEL_GRID_STEP_METERS;
  2804. x2 = x1 + PARCEL_GRID_STEP_METERS;
  2805. y2 = y1;
  2806. #if 0 // Silly... This does not take the sign into account ! HB
  2807. dy = pos_y - y1 + DIST_OFFSET;
  2808. #else // Seems (from observed effect) about right ! HB
  2809. dy = fabs(pos_y - y1);
  2810. if (dy >= DIST_OFFSET)
  2811. {
  2812. dy -= DIST_OFFSET;
  2813. }
  2814. #endif
  2815. if (pos_x < x1)
  2816. {
  2817. dx = pos_x - x1;
  2818. }
  2819. else if (pos_x > x2)
  2820. {
  2821. dx = pos_x - x2;
  2822. }
  2823. else
  2824. {
  2825. dx = 0.f;
  2826. }
  2827. F32 dist = dx * dx + dy * dy;
  2828. if (dist < MIN_DIST_SQ)
  2829. {
  2830. alpha = MAX_ALPHA;
  2831. }
  2832. else if (dist > max_dist_sq)
  2833. {
  2834. alpha = 0.f;
  2835. }
  2836. else
  2837. {
  2838. alpha = llclamp(alpha0 / dist, MIN_ALPHA, MAX_ALPHA);
  2839. }
  2840. if (alpha > 0.f)
  2841. {
  2842. gGL.color4f(1.f, 1.f, 1.f, alpha);
  2843. U8 direction = pos_y - y1 < 0.f ? SOUTH_MASK : NORTH_MASK;
  2844. // Avoid Z fighting
  2845. renderOneSegment(x1 + 0.1f, y1 + 0.1f,
  2846. x2 + 0.1f, y2 + 0.1f,
  2847. collision_height, direction, regionp);
  2848. }
  2849. }
  2850. if (segment_mask & WEST_MASK)
  2851. {
  2852. x1 = x * PARCEL_GRID_STEP_METERS;
  2853. y1 = y * PARCEL_GRID_STEP_METERS;
  2854. x2 = x1;
  2855. y2 = y1 + PARCEL_GRID_STEP_METERS;
  2856. #if 0 // Silly... This does not take the sign into account ! HB
  2857. dx = pos_x - x1 + DIST_OFFSET;
  2858. #else // Seems (from observed effect) about right ! HB
  2859. dx = fabs(pos_x - x1);
  2860. if (dx >= DIST_OFFSET)
  2861. {
  2862. dx -= DIST_OFFSET;
  2863. }
  2864. #endif
  2865. if (pos_y < y1)
  2866. {
  2867. dy = pos_y - y1;
  2868. }
  2869. else if (pos_y > y2)
  2870. {
  2871. dy = pos_y - y2;
  2872. }
  2873. else
  2874. {
  2875. dy = 0.f;
  2876. }
  2877. F32 dist = dx * dx + dy * dy;
  2878. if (dist < MIN_DIST_SQ)
  2879. {
  2880. alpha = MAX_ALPHA;
  2881. }
  2882. else if (dist > max_dist_sq)
  2883. {
  2884. alpha = 0.f;
  2885. }
  2886. else
  2887. {
  2888. alpha = llclamp(alpha0 / dist, MIN_ALPHA, MAX_ALPHA);
  2889. }
  2890. if (alpha > 0.f)
  2891. {
  2892. gGL.color4f(1.f, 1.f, 1.f, alpha);
  2893. U8 direction = pos_x - x1 > 0.f ? WEST_MASK : EAST_MASK;
  2894. // Avoid Z fighting
  2895. renderOneSegment(x1 + 0.1f, y1 + 0.1f,
  2896. x2 + 0.1f, y2 + 0.1f,
  2897. collision_height, direction, regionp);
  2898. }
  2899. }
  2900. }
  2901. }
  2902. gGL.end();
  2903. }