clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27  
28 using System;
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Diagnostics;
32 using System.Reflection;
33 using System.Text;
34 using log4net;
35 using Nini.Config;
36 using OpenMetaverse;
37 using OpenMetaverse.StructuredData;
38 using OpenMetaverse.Messages.Linden;
39 using Mono.Addins;
40 using OpenSim.Framework;
41 using OpenSim.Framework.Capabilities;
42 using OpenSim.Framework.Console;
43 using OpenSim.Framework.Servers;
44 using OpenSim.Framework.Servers.HttpServer;
45 using OpenSim.Region.Framework.Interfaces;
46 using OpenSim.Region.Framework.Scenes;
47 using OpenSim.Region.Physics.Manager;
48 using OpenSim.Services.Interfaces;
49 using Caps = OpenSim.Framework.Capabilities.Caps;
50 using GridRegion = OpenSim.Services.Interfaces.GridRegion;
51  
52 namespace OpenSim.Region.CoreModules.World.Land
53 {
54 // used for caching
55 internal class ExtendedLandData
56 {
57 public LandData LandData;
58 public ulong RegionHandle;
59 public uint X, Y;
60 public byte RegionAccess;
61 }
62  
63 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LandManagementModule")]
64 public class LandManagementModule : INonSharedRegionModule
65 {
66 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
67 private static readonly string LogHeader = "[LAND MANAGEMENT MODULE]";
68  
69 /// <summary>
70 /// Minimum land unit size in region co-ordinates.
71 /// </summary>
72 public const int LandUnit = 4;
73  
74 private static readonly string remoteParcelRequestPath = "0009/";
75  
76 private LandChannel landChannel;
77 private Scene m_scene;
78  
79 protected IGroupsModule m_groupManager;
80 protected IUserManagement m_userManager;
81 protected IPrimCountModule m_primCountModule;
82 protected IDialogModule m_Dialog;
83  
84 /// <value>
85 /// Local land ids at specified region co-ordinates (region size / 4)
86 /// </value>
87 private int[,] m_landIDList;
88  
89 /// <value>
90 /// Land objects keyed by local id
91 /// </value>
92 private readonly Dictionary<int, ILandObject> m_landList = new Dictionary<int, ILandObject>();
93  
94 private int m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1;
95  
96 private bool m_allowedForcefulBans = true;
97  
98 // caches ExtendedLandData
99 private Cache parcelInfoCache;
100  
101 /// <summary>
102 /// Record positions that avatar's are currently being forced to move to due to parcel entry restrictions.
103 /// </summary>
104 private Dictionary<UUID, Vector3> forcedPosition = new Dictionary<UUID, Vector3>();
105  
106 #region INonSharedRegionModule Members
107  
108 public Type ReplaceableInterface
109 {
110 get { return null; }
111 }
112  
113 public void Initialise(IConfigSource source)
114 {
115 }
116  
117 public void AddRegion(Scene scene)
118 {
119 m_scene = scene;
120 m_landIDList = new int[m_scene.RegionInfo.RegionSizeX / LandUnit, m_scene.RegionInfo.RegionSizeY / LandUnit];
121 landChannel = new LandChannel(scene, this);
122  
123 parcelInfoCache = new Cache();
124 parcelInfoCache.Size = 30; // the number of different parcel requests in this region to cache
125 parcelInfoCache.DefaultTTL = new TimeSpan(0, 5, 0);
126  
127 m_scene.EventManager.OnParcelPrimCountAdd += EventManagerOnParcelPrimCountAdd;
128 m_scene.EventManager.OnParcelPrimCountUpdate += EventManagerOnParcelPrimCountUpdate;
129 m_scene.EventManager.OnObjectBeingRemovedFromScene += EventManagerOnObjectBeingRemovedFromScene;
130 m_scene.EventManager.OnRequestParcelPrimCountUpdate += EventManagerOnRequestParcelPrimCountUpdate;
131  
132 m_scene.EventManager.OnAvatarEnteringNewParcel += EventManagerOnAvatarEnteringNewParcel;
133 m_scene.EventManager.OnClientMovement += EventManagerOnClientMovement;
134 m_scene.EventManager.OnValidateLandBuy += EventManagerOnValidateLandBuy;
135 m_scene.EventManager.OnLandBuy += EventManagerOnLandBuy;
136 m_scene.EventManager.OnNewClient += EventManagerOnNewClient;
137 m_scene.EventManager.OnMakeChildAgent += EventMakeChildAgent;
138 m_scene.EventManager.OnSignificantClientMovement += EventManagerOnSignificantClientMovement;
139 m_scene.EventManager.OnNoticeNoLandDataFromStorage += EventManagerOnNoLandDataFromStorage;
140 m_scene.EventManager.OnIncomingLandDataFromStorage += EventManagerOnIncomingLandDataFromStorage;
141 m_scene.EventManager.OnSetAllowForcefulBan += EventManagerOnSetAllowedForcefulBan;
142 m_scene.EventManager.OnRegisterCaps += EventManagerOnRegisterCaps;
143  
144 lock (m_scene)
145 {
146 m_scene.LandChannel = (ILandChannel)landChannel;
147 }
148  
149 RegisterCommands();
150 }
151  
152 public void RegionLoaded(Scene scene)
153 {
154 m_userManager = m_scene.RequestModuleInterface<IUserManagement>();
155 m_groupManager = m_scene.RequestModuleInterface<IGroupsModule>();
156 m_primCountModule = m_scene.RequestModuleInterface<IPrimCountModule>();
157 m_Dialog = m_scene.RequestModuleInterface<IDialogModule>();
158 }
159  
160 public void RemoveRegion(Scene scene)
161 {
162 // TODO: Release event manager listeners here
163 }
164  
165 // private bool OnVerifyUserConnection(ScenePresence scenePresence, out string reason)
166 // {
167 // ILandObject nearestParcel = m_scene.GetNearestAllowedParcel(scenePresence.UUID, scenePresence.AbsolutePosition.X, scenePresence.AbsolutePosition.Y);
168 // reason = "You are not allowed to enter this sim.";
169 // return nearestParcel != null;
170 // }
171  
172 void EventManagerOnNewClient(IClientAPI client)
173 {
174 //Register some client events
175 client.OnParcelPropertiesRequest += ClientOnParcelPropertiesRequest;
176 client.OnParcelDivideRequest += ClientOnParcelDivideRequest;
177 client.OnParcelJoinRequest += ClientOnParcelJoinRequest;
178 client.OnParcelPropertiesUpdateRequest += ClientOnParcelPropertiesUpdateRequest;
179 client.OnParcelSelectObjects += ClientOnParcelSelectObjects;
180 client.OnParcelObjectOwnerRequest += ClientOnParcelObjectOwnerRequest;
181 client.OnParcelAccessListRequest += ClientOnParcelAccessListRequest;
182 client.OnParcelAccessListUpdateRequest += ClientOnParcelAccessListUpdateRequest;
183 client.OnParcelAbandonRequest += ClientOnParcelAbandonRequest;
184 client.OnParcelGodForceOwner += ClientOnParcelGodForceOwner;
185 client.OnParcelReclaim += ClientOnParcelReclaim;
186 client.OnParcelInfoRequest += ClientOnParcelInfoRequest;
187 client.OnParcelDeedToGroup += ClientOnParcelDeedToGroup;
188 client.OnPreAgentUpdate += ClientOnPreAgentUpdate;
189 client.OnParcelEjectUser += ClientOnParcelEjectUser;
190 client.OnParcelFreezeUser += ClientOnParcelFreezeUser;
191 client.OnSetStartLocationRequest += ClientOnSetHome;
192  
193  
194 EntityBase presenceEntity;
195 if (m_scene.Entities.TryGetValue(client.AgentId, out presenceEntity) && presenceEntity is ScenePresence)
196 {
197 SendLandUpdate((ScenePresence)presenceEntity, true);
198 SendParcelOverlay(client);
199 }
200 }
201  
202 public void EventMakeChildAgent(ScenePresence avatar)
203 {
204 avatar.currentParcelUUID = UUID.Zero;
205 }
206  
207 void ClientOnPreAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData)
208 {
209 //If we are forcing a position for them to go
210 if (forcedPosition.ContainsKey(remoteClient.AgentId))
211 {
212 ScenePresence clientAvatar = m_scene.GetScenePresence(remoteClient.AgentId);
213  
214 //Putting the user into flying, both keeps the avatar in fligth when it bumps into something and stopped from going another direction AND
215 //When the avatar walks into a ban line on the ground, it prevents getting stuck
216 agentData.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY;
217  
218 //Make sure we stop if they get about to the right place to prevent yoyo and prevents getting stuck on banlines
219 if (Vector3.Distance(clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]) < .2)
220 {
221 // m_log.DebugFormat(
222 // "[LAND MANAGEMENT MODULE]: Stopping force position of {0} because {1} is close enough to {2}",
223 // clientAvatar.Name, clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]);
224  
225 forcedPosition.Remove(remoteClient.AgentId);
226 }
227 //if we are far away, teleport
228 else if (Vector3.Distance(clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]) > 3)
229 {
230 Vector3 forcePosition = forcedPosition[remoteClient.AgentId];
231 // m_log.DebugFormat(
232 // "[LAND MANAGEMENT MODULE]: Teleporting out {0} because {1} is too far from avatar position {2}",
233 // clientAvatar.Name, clientAvatar.AbsolutePosition, forcePosition);
234  
235 m_scene.RequestTeleportLocation(remoteClient, m_scene.RegionInfo.RegionHandle,
236 forcePosition, clientAvatar.Lookat, (uint)Constants.TeleportFlags.ForceRedirect);
237  
238 forcedPosition.Remove(remoteClient.AgentId);
239 }
240 else
241 {
242 // m_log.DebugFormat(
243 // "[LAND MANAGEMENT MODULE]: Forcing {0} from {1} to {2}",
244 // clientAvatar.Name, clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]);
245  
246 //Forces them toward the forced position we want if they aren't there yet
247 agentData.UseClientAgentPosition = true;
248 agentData.ClientAgentPosition = forcedPosition[remoteClient.AgentId];
249 }
250 }
251 }
252  
253 public void Close()
254 {
255 }
256  
257 public string Name
258 {
259 get { return "LandManagementModule"; }
260 }
261  
262 #endregion
263  
264 #region Parcel Add/Remove/Get/Create
265  
266 public void EventManagerOnSetAllowedForcefulBan(bool forceful)
267 {
268 AllowedForcefulBans = forceful;
269 }
270  
271 public void UpdateLandObject(int local_id, LandData data)
272 {
273 LandData newData = data.Copy();
274 newData.LocalID = local_id;
275  
276 ILandObject land;
277 lock (m_landList)
278 {
279 if (m_landList.TryGetValue(local_id, out land))
280 land.LandData = newData;
281 }
282  
283 if (land != null)
284 m_scene.EventManager.TriggerLandObjectUpdated((uint)local_id, land);
285 }
286  
287 public bool AllowedForcefulBans
288 {
289 get { return m_allowedForcefulBans; }
290 set { m_allowedForcefulBans = value; }
291 }
292  
293 /// <summary>
294 /// Resets the sim to the default land object (full sim piece of land owned by the default user)
295 /// </summary>
296 public void ResetSimLandObjects()
297 {
298 //Remove all the land objects in the sim and add a blank, full sim land object set to public
299 lock (m_landList)
300 {
301 m_landList.Clear();
302 m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1;
303 m_landIDList = new int[m_scene.RegionInfo.RegionSizeX / LandUnit, m_scene.RegionInfo.RegionSizeY / LandUnit];
304 }
305 }
306  
307 /// <summary>
308 /// Create a default parcel that spans the entire region and is owned by the estate owner.
309 /// </summary>
310 /// <returns>The parcel created.</returns>
311 protected ILandObject CreateDefaultParcel()
312 {
313 m_log.DebugFormat(
314 "[LAND MANAGEMENT MODULE]: Creating default parcel for region {0}", m_scene.RegionInfo.RegionName);
315  
316 ILandObject fullSimParcel = new LandObject(UUID.Zero, false, m_scene);
317 fullSimParcel.SetLandBitmap(fullSimParcel.GetSquareLandBitmap(0, 0,
318 (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY));
319 fullSimParcel.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
320 fullSimParcel.LandData.ClaimDate = Util.UnixTimeSinceEpoch();
321  
322 return AddLandObject(fullSimParcel);
323 }
324  
325 public List<ILandObject> AllParcels()
326 {
327 lock (m_landList)
328 {
329 return new List<ILandObject>(m_landList.Values);
330 }
331 }
332  
333 public List<ILandObject> ParcelsNearPoint(Vector3 position)
334 {
335 List<ILandObject> parcelsNear = new List<ILandObject>();
336 for (int x = -4; x <= 4; x += 4)
337 {
338 for (int y = -4; y <= 4; y += 4)
339 {
340 ILandObject check = GetLandObject(position.X + x, position.Y + y);
341 if (check != null)
342 {
343 if (!parcelsNear.Contains(check))
344 {
345 parcelsNear.Add(check);
346 }
347 }
348 }
349 }
350  
351 return parcelsNear;
352 }
353  
354 public void SendYouAreBannedNotice(ScenePresence avatar)
355 {
356 if (AllowedForcefulBans)
357 {
358 avatar.ControllingClient.SendAlertMessage(
359 "You are not allowed on this parcel because you are banned. Please go away.");
360 }
361 else
362 {
363 avatar.ControllingClient.SendAlertMessage(
364 "You are not allowed on this parcel because you are banned; however, the grid administrator has disabled ban lines globally. Please obey the land owner's requests or you can be banned from the entire sim!");
365 }
366 }
367  
368 private void ForceAvatarToPosition(ScenePresence avatar, Vector3? position)
369 {
370 if (m_scene.Permissions.IsGod(avatar.UUID)) return;
371 if (position.HasValue)
372 {
373 forcedPosition[avatar.ControllingClient.AgentId] = (Vector3)position;
374 }
375 }
376  
377 public void SendYouAreRestrictedNotice(ScenePresence avatar)
378 {
379 avatar.ControllingClient.SendAlertMessage(
380 "You are not allowed on this parcel because the land owner has restricted access.");
381 }
382  
383 public void EventManagerOnAvatarEnteringNewParcel(ScenePresence avatar, int localLandID, UUID regionID)
384 {
385 if (m_scene.RegionInfo.RegionID == regionID)
386 {
387 ILandObject parcelAvatarIsEntering;
388 lock (m_landList)
389 {
390 parcelAvatarIsEntering = m_landList[localLandID];
391 }
392  
393 if (parcelAvatarIsEntering != null)
394 {
395 if (avatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT)
396 {
397 if (parcelAvatarIsEntering.IsBannedFromLand(avatar.UUID))
398 {
399 SendYouAreBannedNotice(avatar);
400 ForceAvatarToPosition(avatar, m_scene.GetNearestAllowedPosition(avatar));
401 }
402 else if (parcelAvatarIsEntering.IsRestrictedFromLand(avatar.UUID))
403 {
404 SendYouAreRestrictedNotice(avatar);
405 ForceAvatarToPosition(avatar, m_scene.GetNearestAllowedPosition(avatar));
406 }
407 else
408 {
409 avatar.sentMessageAboutRestrictedParcelFlyingDown = true;
410 }
411 }
412 else
413 {
414 avatar.sentMessageAboutRestrictedParcelFlyingDown = true;
415 }
416 }
417 }
418 }
419  
420 public void SendOutNearestBanLine(IClientAPI client)
421 {
422 ScenePresence sp = m_scene.GetScenePresence(client.AgentId);
423 if (sp == null || sp.IsChildAgent)
424 return;
425  
426 List<ILandObject> checkLandParcels = ParcelsNearPoint(sp.AbsolutePosition);
427 foreach (ILandObject checkBan in checkLandParcels)
428 {
429 if (checkBan.IsBannedFromLand(client.AgentId))
430 {
431 checkBan.SendLandProperties((int)ParcelPropertiesStatus.CollisionBanned, false, (int)ParcelResult.Single, client);
432 return; //Only send one
433 }
434 if (checkBan.IsRestrictedFromLand(client.AgentId))
435 {
436 checkBan.SendLandProperties((int)ParcelPropertiesStatus.CollisionNotOnAccessList, false, (int)ParcelResult.Single, client);
437 return; //Only send one
438 }
439 }
440 return;
441 }
442  
443 public void SendLandUpdate(ScenePresence avatar, bool force)
444 {
445 ILandObject over = GetLandObject((int)Math.Min(((int)m_scene.RegionInfo.RegionSizeX - 1), Math.Max(0, Math.Round(avatar.AbsolutePosition.X))),
446 (int)Math.Min(((int)m_scene.RegionInfo.RegionSizeY - 1), Math.Max(0, Math.Round(avatar.AbsolutePosition.Y))));
447  
448 if (over != null)
449 {
450 if (force)
451 {
452 if (!avatar.IsChildAgent)
453 {
454 over.SendLandUpdateToClient(avatar.ControllingClient);
455 m_scene.EventManager.TriggerAvatarEnteringNewParcel(avatar, over.LandData.LocalID,
456 m_scene.RegionInfo.RegionID);
457 }
458 }
459  
460 if (avatar.currentParcelUUID != over.LandData.GlobalID)
461 {
462 if (!avatar.IsChildAgent)
463 {
464 over.SendLandUpdateToClient(avatar.ControllingClient);
465 avatar.currentParcelUUID = over.LandData.GlobalID;
466 m_scene.EventManager.TriggerAvatarEnteringNewParcel(avatar, over.LandData.LocalID,
467 m_scene.RegionInfo.RegionID);
468 }
469 }
470 }
471 }
472  
473 public void SendLandUpdate(ScenePresence avatar)
474 {
475 SendLandUpdate(avatar, false);
476 }
477  
478 public void EventManagerOnSignificantClientMovement(ScenePresence clientAvatar)
479 {
480 SendLandUpdate(clientAvatar);
481 SendOutNearestBanLine(clientAvatar.ControllingClient);
482 ILandObject parcel = GetLandObject(clientAvatar.AbsolutePosition.X, clientAvatar.AbsolutePosition.Y);
483 if (parcel != null)
484 {
485 if (clientAvatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT &&
486 clientAvatar.sentMessageAboutRestrictedParcelFlyingDown)
487 {
488 EventManagerOnAvatarEnteringNewParcel(clientAvatar, parcel.LandData.LocalID,
489 m_scene.RegionInfo.RegionID);
490 //They are going under the safety line!
491 if (!parcel.IsBannedFromLand(clientAvatar.UUID))
492 {
493 clientAvatar.sentMessageAboutRestrictedParcelFlyingDown = false;
494 }
495 }
496 else if (clientAvatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT &&
497 parcel.IsBannedFromLand(clientAvatar.UUID))
498 {
499 //once we've sent the message once, keep going toward the target until we are done
500 if (forcedPosition.ContainsKey(clientAvatar.ControllingClient.AgentId))
501 {
502 SendYouAreBannedNotice(clientAvatar);
503 ForceAvatarToPosition(clientAvatar, m_scene.GetNearestAllowedPosition(clientAvatar));
504 }
505 }
506 else if (parcel.IsRestrictedFromLand(clientAvatar.UUID))
507 {
508 //once we've sent the message once, keep going toward the target until we are done
509 if (forcedPosition.ContainsKey(clientAvatar.ControllingClient.AgentId))
510 {
511 SendYouAreRestrictedNotice(clientAvatar);
512 ForceAvatarToPosition(clientAvatar, m_scene.GetNearestAllowedPosition(clientAvatar));
513 }
514 }
515 else
516 {
517 //when we are finally in a safe place, lets release the forced position lock
518 forcedPosition.Remove(clientAvatar.ControllingClient.AgentId);
519 }
520 }
521 }
522  
523 /// <summary>
524 /// Like handleEventManagerOnSignificantClientMovement, but called with an AgentUpdate regardless of distance.
525 /// </summary>
526 /// <param name="avatar"></param>
527 public void EventManagerOnClientMovement(ScenePresence avatar)
528 {
529 Vector3 pos = avatar.AbsolutePosition;
530 ILandObject over = GetLandObject(pos.X, pos.Y);
531 if (over != null)
532 {
533 if (!over.IsRestrictedFromLand(avatar.UUID) && (!over.IsBannedFromLand(avatar.UUID) || pos.Z >= LandChannel.BAN_LINE_SAFETY_HIEGHT))
534 avatar.lastKnownAllowedPosition = pos;
535 }
536 }
537  
538 public void ClientOnParcelAccessListRequest(UUID agentID, UUID sessionID, uint flags, int sequenceID,
539 int landLocalID, IClientAPI remote_client)
540 {
541 ILandObject land;
542 lock (m_landList)
543 {
544 m_landList.TryGetValue(landLocalID, out land);
545 }
546  
547 if (land != null)
548 {
549 land.SendAccessList(agentID, sessionID, flags, sequenceID, remote_client);
550 }
551 }
552  
553 public void ClientOnParcelAccessListUpdateRequest(UUID agentID,
554 uint flags, int landLocalID, UUID transactionID, int sequenceID,
555 int sections, List<LandAccessEntry> entries,
556 IClientAPI remote_client)
557 {
558 // Flags is the list to update, it can mean either the ban or
559 // the access list (WTH is a pass list? Mentioned in ParcelFlags)
560 //
561 // There may be multiple packets, because these can get LONG.
562 // Use transactionID to determine a new chain of packets since
563 // packets may have come in out of sequence and that would be
564 // a big mess if using the sequenceID
565 ILandObject land;
566 lock (m_landList)
567 {
568 m_landList.TryGetValue(landLocalID, out land);
569 }
570  
571 if (land != null)
572 {
573 GroupPowers requiredPowers = GroupPowers.LandManageAllowed;
574 if (flags == (uint)AccessList.Ban)
575 requiredPowers = GroupPowers.LandManageBanned;
576  
577 if (m_scene.Permissions.CanEditParcelProperties(agentID,
578 land, requiredPowers))
579 {
580 land.UpdateAccessList(flags, transactionID, sequenceID,
581 sections, entries, remote_client);
582 }
583 }
584 else
585 {
586 m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Invalid local land ID {0}", landLocalID);
587 }
588 }
589  
590 /// <summary>
591 /// Adds a land object to the stored list and adds them to the landIDList to what they own
592 /// </summary>
593 /// <param name="new_land">
594 /// The land object being added.
595 /// Will return null if this overlaps with an existing parcel that has not had its bitmap adjusted.
596 /// </param>
597 public ILandObject AddLandObject(ILandObject land)
598 {
599 ILandObject new_land = land.Copy();
600  
601 // Only now can we add the prim counts to the land object - we rely on the global ID which is generated
602 // as a random UUID inside LandData initialization
603 if (m_primCountModule != null)
604 new_land.PrimCounts = m_primCountModule.GetPrimCounts(new_land.LandData.GlobalID);
605  
606 lock (m_landList)
607 {
608 int newLandLocalID = m_lastLandLocalID + 1;
609 new_land.LandData.LocalID = newLandLocalID;
610  
611 bool[,] landBitmap = new_land.GetLandBitmap();
612 // m_log.DebugFormat("{0} AddLandObject. new_land.bitmapSize=({1},{2}). newLocalID={3}",
613 // LogHeader, landBitmap.GetLength(0), landBitmap.GetLength(1), newLandLocalID);
614  
615 if (landBitmap.GetLength(0) != m_landIDList.GetLength(0) || landBitmap.GetLength(1) != m_landIDList.GetLength(1))
616 {
617 // Going to variable sized regions can cause mismatches
618 m_log.ErrorFormat("{0} AddLandObject. Added land bitmap different size than region ID map. bitmapSize=({1},{2}), landIDSize=({3},{4})",
619 LogHeader, landBitmap.GetLength(0), landBitmap.GetLength(1), m_landIDList.GetLength(0), m_landIDList.GetLength(1) );
620 }
621 else
622 {
623 // If other land objects still believe that they occupy any parts of the same space,
624 // then do not allow the add to proceed.
625 for (int x = 0; x < landBitmap.GetLength(0); x++)
626 {
627 for (int y = 0; y < landBitmap.GetLength(1); y++)
628 {
629 if (landBitmap[x, y])
630 {
631 int lastRecordedLandId = m_landIDList[x, y];
632  
633 if (lastRecordedLandId > 0)
634 {
635 ILandObject lastRecordedLo = m_landList[lastRecordedLandId];
636  
637 if (lastRecordedLo.LandBitmap[x, y])
638 {
639 m_log.ErrorFormat(
640 "{0}: Cannot add parcel \"{1}\", local ID {2} at tile {3},{4} because this is still occupied by parcel \"{5}\", local ID {6} in {7}",
641 LogHeader, new_land.LandData.Name, new_land.LandData.LocalID, x, y,
642 lastRecordedLo.LandData.Name, lastRecordedLo.LandData.LocalID, m_scene.Name);
643  
644 return null;
645 }
646 }
647 }
648 }
649 }
650  
651 for (int x = 0; x < landBitmap.GetLength(0); x++)
652 {
653 for (int y = 0; y < landBitmap.GetLength(1); y++)
654 {
655 if (landBitmap[x, y])
656 {
657 // m_log.DebugFormat(
658 // "[LAND MANAGEMENT MODULE]: Registering parcel {0} for land co-ord ({1}, {2}) on {3}",
659 // new_land.LandData.Name, x, y, m_scene.RegionInfo.RegionName);
660  
661 m_landIDList[x, y] = newLandLocalID;
662 }
663 }
664 }
665 }
666  
667 m_landList.Add(newLandLocalID, new_land);
668 m_lastLandLocalID++;
669 }
670  
671 new_land.ForceUpdateLandInfo();
672 m_scene.EventManager.TriggerLandObjectAdded(new_land);
673  
674 return new_land;
675 }
676  
677 /// <summary>
678 /// Removes a land object from the list. Will not remove if local_id is still owning an area in landIDList
679 /// </summary>
680 /// <param name="local_id">Land.localID of the peice of land to remove.</param>
681 public void removeLandObject(int local_id)
682 {
683 ILandObject land;
684 lock (m_landList)
685 {
686 for (int x = 0; x < m_landIDList.GetLength(0); x++)
687 {
688 for (int y = 0; y < m_landIDList.GetLength(1); y++)
689 {
690 if (m_landIDList[x, y] == local_id)
691 {
692 m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Not removing land object {0}; still being used at {1}, {2}",
693 local_id, x, y);
694 return;
695 //throw new Exception("Could not remove land object. Still being used at " + x + ", " + y);
696 }
697 }
698 }
699  
700 land = m_landList[local_id];
701 m_landList.Remove(local_id);
702 }
703  
704 m_scene.EventManager.TriggerLandObjectRemoved(land.LandData.GlobalID);
705 }
706  
707 /// <summary>
708 /// Clear the scene of all parcels
709 /// </summary>
710 public void Clear(bool setupDefaultParcel)
711 {
712 List<ILandObject> parcels;
713 lock (m_landList)
714 {
715 parcels = new List<ILandObject>(m_landList.Values);
716 }
717  
718 foreach (ILandObject lo in parcels)
719 {
720 //m_scene.SimulationDataService.RemoveLandObject(lo.LandData.GlobalID);
721 m_scene.EventManager.TriggerLandObjectRemoved(lo.LandData.GlobalID);
722 }
723  
724 lock (m_landList)
725 {
726 m_landList.Clear();
727  
728 ResetSimLandObjects();
729 }
730  
731 if (setupDefaultParcel)
732 CreateDefaultParcel();
733 }
734  
735 private void performFinalLandJoin(ILandObject master, ILandObject slave)
736 {
737 bool[,] landBitmapSlave = slave.GetLandBitmap();
738 lock (m_landList)
739 {
740 for (int x = 0; x < landBitmapSlave.GetLength(0); x++)
741 {
742 for (int y = 0; y < landBitmapSlave.GetLength(1); y++)
743 {
744 if (landBitmapSlave[x, y])
745 {
746 m_landIDList[x, y] = master.LandData.LocalID;
747 }
748 }
749 }
750 }
751  
752 removeLandObject(slave.LandData.LocalID);
753 UpdateLandObject(master.LandData.LocalID, master.LandData);
754 }
755  
756 public ILandObject GetLandObject(int parcelLocalID)
757 {
758 lock (m_landList)
759 {
760 if (m_landList.ContainsKey(parcelLocalID))
761 {
762 return m_landList[parcelLocalID];
763 }
764 }
765 return null;
766 }
767  
768 /// <summary>
769 /// Get the land object at the specified point
770 /// </summary>
771 /// <param name="x_float">Value between 0 - 256 on the x axis of the point</param>
772 /// <param name="y_float">Value between 0 - 256 on the y axis of the point</param>
773 /// <returns>Land object at the point supplied</returns>
774 public ILandObject GetLandObject(float x_float, float y_float)
775 {
776 return GetLandObject((int)x_float, (int)y_float, true /* returnNullIfLandObjectNotFound */);
777 /*
778 int x;
779 int y;
780  
781 if (x_float >= m_scene.RegionInfo.RegionSizeX || x_float < 0 || y_float >= m_scene.RegionInfo.RegionSizeX || y_float < 0)
782 return null;
783  
784 try
785 {
786 x = Convert.ToInt32(Math.Floor(Convert.ToDouble(x_float) / (float)landUnit));
787 y = Convert.ToInt32(Math.Floor(Convert.ToDouble(y_float) / (float)landUnit));
788 }
789 catch (OverflowException)
790 {
791 return null;
792 }
793  
794 if (x >= (m_scene.RegionInfo.RegionSizeX / landUnit)
795 || y >= (m_scene.RegionInfo.RegionSizeY / landUnit)
796 || x < 0
797 || y < 0)
798 {
799 return null;
800 }
801  
802 lock (m_landList)
803 {
804 // Corner case. If an autoreturn happens during sim startup
805 // we will come here with the list uninitialized
806 //
807 // int landId = m_landIDList[x, y];
808  
809 // if (landId == 0)
810 // m_log.DebugFormat(
811 // "[LAND MANAGEMENT MODULE]: No land object found at ({0}, {1}) on {2}",
812 // x, y, m_scene.RegionInfo.RegionName);
813  
814 try
815 {
816 if (m_landList.ContainsKey(m_landIDList[x, y]))
817 return m_landList[m_landIDList[x, y]];
818 }
819 catch (Exception e)
820 {
821 m_log.DebugFormat("{0} GetLandObject exception. x={1}, y={2}, m_landIDList.len=({3},{4})",
822 LogHeader, x, y, m_landIDList.GetLength(0), m_landIDList.GetLength(1));
823 }
824  
825 return null;
826 }
827 */
828 }
829  
830 // Public entry.
831 // Throws exception if land object is not found
832 public ILandObject GetLandObject(int x, int y)
833 {
834 return GetLandObject(x, y, false /* returnNullIfLandObjectNotFound */);
835 }
836  
837 /// <summary>
838 /// Given a region position, return the parcel land object for that location
839 /// </summary>
840 /// <returns>
841 /// The land object.
842 /// </returns>
843 /// <param name='x'></param>
844 /// <param name='y'></param>
845 /// <param name='returnNullIfLandObjectNotFound'>
846 /// Return null if the land object requested is not within the region's bounds.
847 /// </param>
848 private ILandObject GetLandObject(int x, int y, bool returnNullIfLandObjectOutsideBounds)
849 {
850 if (x >= m_scene.RegionInfo.RegionSizeX || y >= m_scene.RegionInfo.RegionSizeY || x < 0 || y < 0)
851 {
852 // These exceptions here will cause a lot of complaints from the users specifically because
853 // they happen every time at border crossings
854 if (returnNullIfLandObjectOutsideBounds)
855 return null;
856 else
857 throw new Exception(
858 String.Format("{0} GetLandObject for non-existent position. Region={1}, pos=<{2},{3}",
859 LogHeader, m_scene.RegionInfo.RegionName, x, y)
860 );
861 }
862  
863 return m_landList[m_landIDList[x / 4, y / 4]];
864 }
865  
866 // Create a 'parcel is here' bitmap for the parcel identified by the passed landID
867 private bool[,] CreateBitmapForID(int landID)
868 {
869 bool[,] ret = new bool[m_landIDList.GetLength(0), m_landIDList.GetLength(1)];
870  
871 for (int xx = 0; xx < m_landIDList.GetLength(0); xx++)
872 for (int yy = 0; yy < m_landIDList.GetLength(0); yy++)
873 if (m_landIDList[xx, yy] == landID)
874 ret[xx, yy] = true;
875  
876 return ret;
877 }
878  
879 #endregion
880  
881 #region Parcel Modification
882  
883 public void ResetOverMeRecords()
884 {
885 lock (m_landList)
886 {
887 foreach (LandObject p in m_landList.Values)
888 {
889 p.ResetOverMeRecord();
890 }
891 }
892 }
893  
894 public void EventManagerOnParcelPrimCountAdd(SceneObjectGroup obj)
895 {
896 Vector3 position = obj.AbsolutePosition;
897 ILandObject landUnderPrim = GetLandObject(position.X, position.Y);
898 if (landUnderPrim != null)
899 {
900 ((LandObject)landUnderPrim).AddPrimOverMe(obj);
901 }
902 }
903  
904 public void EventManagerOnObjectBeingRemovedFromScene(SceneObjectGroup obj)
905 {
906 lock (m_landList)
907 {
908 foreach (LandObject p in m_landList.Values)
909 {
910 p.RemovePrimFromOverMe(obj);
911 }
912 }
913 }
914  
915 public void FinalizeLandPrimCountUpdate()
916 {
917 //Get Simwide prim count for owner
918 Dictionary<UUID, List<LandObject>> landOwnersAndParcels = new Dictionary<UUID, List<LandObject>>();
919 lock (m_landList)
920 {
921 foreach (LandObject p in m_landList.Values)
922 {
923 if (!landOwnersAndParcels.ContainsKey(p.LandData.OwnerID))
924 {
925 List<LandObject> tempList = new List<LandObject>();
926 tempList.Add(p);
927 landOwnersAndParcels.Add(p.LandData.OwnerID, tempList);
928 }
929 else
930 {
931 landOwnersAndParcels[p.LandData.OwnerID].Add(p);
932 }
933 }
934 }
935  
936 foreach (UUID owner in landOwnersAndParcels.Keys)
937 {
938 int simArea = 0;
939 int simPrims = 0;
940 foreach (LandObject p in landOwnersAndParcels[owner])
941 {
942 simArea += p.LandData.Area;
943 simPrims += p.PrimCounts.Total;
944 }
945  
946 foreach (LandObject p in landOwnersAndParcels[owner])
947 {
948 p.LandData.SimwideArea = simArea;
949 p.LandData.SimwidePrims = simPrims;
950 }
951 }
952 }
953  
954 public void EventManagerOnParcelPrimCountUpdate()
955 {
956 // m_log.DebugFormat(
957 // "[LAND MANAGEMENT MODULE]: Triggered EventManagerOnParcelPrimCountUpdate() for {0}",
958 // m_scene.RegionInfo.RegionName);
959  
960 ResetOverMeRecords();
961 EntityBase[] entities = m_scene.Entities.GetEntities();
962 foreach (EntityBase obj in entities)
963 {
964 if (obj != null)
965 {
966 if ((obj is SceneObjectGroup) && !obj.IsDeleted && !((SceneObjectGroup) obj).IsAttachment)
967 {
968 m_scene.EventManager.TriggerParcelPrimCountAdd((SceneObjectGroup) obj);
969 }
970 }
971 }
972 FinalizeLandPrimCountUpdate();
973 }
974  
975 public void EventManagerOnRequestParcelPrimCountUpdate()
976 {
977 ResetOverMeRecords();
978 m_scene.EventManager.TriggerParcelPrimCountUpdate();
979 FinalizeLandPrimCountUpdate();
980 }
981  
982 /// <summary>
983 /// Subdivides a piece of land
984 /// </summary>
985 /// <param name="start_x">West Point</param>
986 /// <param name="start_y">South Point</param>
987 /// <param name="end_x">East Point</param>
988 /// <param name="end_y">North Point</param>
989 /// <param name="attempting_user_id">UUID of user who is trying to subdivide</param>
990 /// <returns>Returns true if successful</returns>
991 private void subdivide(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id)
992 {
993 //First, lets loop through the points and make sure they are all in the same peice of land
994 //Get the land object at start
995  
996 ILandObject startLandObject = GetLandObject(start_x, start_y);
997  
998 if (startLandObject == null) return;
999  
1000 //Loop through the points
1001 try
1002 {
1003 int totalX = end_x - start_x;
1004 int totalY = end_y - start_y;
1005 for (int y = 0; y < totalY; y++)
1006 {
1007 for (int x = 0; x < totalX; x++)
1008 {
1009 ILandObject tempLandObject = GetLandObject(start_x + x, start_y + y);
1010 if (tempLandObject == null) return;
1011 if (tempLandObject != startLandObject) return;
1012 }
1013 }
1014 }
1015 catch (Exception)
1016 {
1017 return;
1018 }
1019  
1020 //If we are still here, then they are subdividing within one piece of land
1021 //Check owner
1022 if (!m_scene.Permissions.CanEditParcelProperties(attempting_user_id, startLandObject, GroupPowers.LandDivideJoin))
1023 {
1024 return;
1025 }
1026  
1027 //Lets create a new land object with bitmap activated at that point (keeping the old land objects info)
1028 ILandObject newLand = startLandObject.Copy();
1029 newLand.LandData.Name = newLand.LandData.Name;
1030 newLand.LandData.GlobalID = UUID.Random();
1031 newLand.LandData.Dwell = 0;
1032  
1033 newLand.SetLandBitmap(newLand.GetSquareLandBitmap(start_x, start_y, end_x, end_y));
1034  
1035 //Now, lets set the subdivision area of the original to false
1036 int startLandObjectIndex = startLandObject.LandData.LocalID;
1037 lock (m_landList)
1038 {
1039 m_landList[startLandObjectIndex].SetLandBitmap(
1040 newLand.ModifyLandBitmapSquare(startLandObject.GetLandBitmap(), start_x, start_y, end_x, end_y, false));
1041 m_landList[startLandObjectIndex].ForceUpdateLandInfo();
1042 }
1043  
1044 //Now add the new land object
1045 ILandObject result = AddLandObject(newLand);
1046  
1047 if (result != null)
1048 {
1049 UpdateLandObject(startLandObject.LandData.LocalID, startLandObject.LandData);
1050 result.SendLandUpdateToAvatarsOverMe();
1051 }
1052 }
1053  
1054 /// <summary>
1055 /// Join 2 land objects together
1056 /// </summary>
1057 /// <param name="start_x">x value in first piece of land</param>
1058 /// <param name="start_y">y value in first piece of land</param>
1059 /// <param name="end_x">x value in second peice of land</param>
1060 /// <param name="end_y">y value in second peice of land</param>
1061 /// <param name="attempting_user_id">UUID of the avatar trying to join the land objects</param>
1062 /// <returns>Returns true if successful</returns>
1063 private void join(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id)
1064 {
1065 end_x -= 4;
1066 end_y -= 4;
1067  
1068 List<ILandObject> selectedLandObjects = new List<ILandObject>();
1069 int stepYSelected;
1070 for (stepYSelected = start_y; stepYSelected <= end_y; stepYSelected += 4)
1071 {
1072 int stepXSelected;
1073 for (stepXSelected = start_x; stepXSelected <= end_x; stepXSelected += 4)
1074 {
1075 ILandObject p = GetLandObject(stepXSelected, stepYSelected);
1076  
1077 if (p != null)
1078 {
1079 if (!selectedLandObjects.Contains(p))
1080 {
1081 selectedLandObjects.Add(p);
1082 }
1083 }
1084 }
1085 }
1086 ILandObject masterLandObject = selectedLandObjects[0];
1087 selectedLandObjects.RemoveAt(0);
1088  
1089 if (selectedLandObjects.Count < 1)
1090 {
1091 return;
1092 }
1093 if (!m_scene.Permissions.CanEditParcelProperties(attempting_user_id, masterLandObject, GroupPowers.LandDivideJoin))
1094 {
1095 return;
1096 }
1097 foreach (ILandObject p in selectedLandObjects)
1098 {
1099 if (p.LandData.OwnerID != masterLandObject.LandData.OwnerID)
1100 {
1101 return;
1102 }
1103 }
1104  
1105 lock (m_landList)
1106 {
1107 foreach (ILandObject slaveLandObject in selectedLandObjects)
1108 {
1109 m_landList[masterLandObject.LandData.LocalID].SetLandBitmap(
1110 slaveLandObject.MergeLandBitmaps(masterLandObject.GetLandBitmap(), slaveLandObject.GetLandBitmap()));
1111 performFinalLandJoin(masterLandObject, slaveLandObject);
1112 }
1113 }
1114  
1115 masterLandObject.SendLandUpdateToAvatarsOverMe();
1116 }
1117  
1118 public void Join(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id)
1119 {
1120 join(start_x, start_y, end_x, end_y, attempting_user_id);
1121 }
1122  
1123 public void Subdivide(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id)
1124 {
1125 subdivide(start_x, start_y, end_x, end_y, attempting_user_id);
1126 }
1127  
1128 #endregion
1129  
1130 #region Parcel Updating
1131  
1132 /// <summary>
1133 /// Where we send the ParcelOverlay packet to the client
1134 /// </summary>
1135 /// <param name="remote_client">The object representing the client</param>
1136 public void SendParcelOverlay(IClientAPI remote_client)
1137 {
1138 const int LAND_BLOCKS_PER_PACKET = 1024;
1139  
1140 byte[] byteArray = new byte[LAND_BLOCKS_PER_PACKET];
1141 int byteArrayCount = 0;
1142 int sequenceID = 0;
1143  
1144 // Layer data is in landUnit (4m) chunks
1145 for (int y = 0; y < m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / LandUnit); y++)
1146 {
1147 for (int x = 0; x < m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / LandUnit); x++)
1148 {
1149 byteArray[byteArrayCount] = BuildLayerByte(GetLandObject(x * LandUnit, y * LandUnit), x, y, remote_client);
1150 byteArrayCount++;
1151 if (byteArrayCount >= LAND_BLOCKS_PER_PACKET)
1152 {
1153 remote_client.SendLandParcelOverlay(byteArray, sequenceID);
1154 byteArrayCount = 0;
1155 sequenceID++;
1156 byteArray = new byte[LAND_BLOCKS_PER_PACKET];
1157 }
1158  
1159 }
1160 }
1161  
1162 if (byteArrayCount != 0)
1163 {
1164 remote_client.SendLandParcelOverlay(byteArray, sequenceID);
1165 }
1166 }
1167  
1168 private byte BuildLayerByte(ILandObject currentParcelBlock, int x, int y, IClientAPI remote_client)
1169 {
1170 byte tempByte = 0; //This represents the byte for the current 4x4
1171  
1172 if (currentParcelBlock != null)
1173 {
1174 if (currentParcelBlock.LandData.OwnerID == remote_client.AgentId)
1175 {
1176 //Owner Flag
1177 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_OWNED_BY_REQUESTER);
1178 }
1179 else if (currentParcelBlock.LandData.SalePrice > 0 &&
1180 (currentParcelBlock.LandData.AuthBuyerID == UUID.Zero ||
1181 currentParcelBlock.LandData.AuthBuyerID == remote_client.AgentId))
1182 {
1183 //Sale Flag
1184 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_IS_FOR_SALE);
1185 }
1186 else if (currentParcelBlock.LandData.OwnerID == UUID.Zero)
1187 {
1188 //Public Flag
1189 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_PUBLIC);
1190 }
1191 else
1192 {
1193 //Other Flag
1194 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_OWNED_BY_OTHER);
1195 }
1196  
1197 //Now for border control
1198  
1199 ILandObject westParcel = null;
1200 ILandObject southParcel = null;
1201 if (x > 0)
1202 {
1203 westParcel = GetLandObject((x - 1) * LandUnit, y * LandUnit);
1204 }
1205 if (y > 0)
1206 {
1207 southParcel = GetLandObject(x * LandUnit, (y - 1) * LandUnit);
1208 }
1209  
1210 if (x == 0)
1211 {
1212 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST);
1213 }
1214 else if (westParcel != null && westParcel != currentParcelBlock)
1215 {
1216 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST);
1217 }
1218  
1219 if (y == 0)
1220 {
1221 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH);
1222 }
1223 else if (southParcel != null && southParcel != currentParcelBlock)
1224 {
1225 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH);
1226 }
1227  
1228 }
1229  
1230 return tempByte;
1231 }
1232  
1233 public void ClientOnParcelPropertiesRequest(int start_x, int start_y, int end_x, int end_y, int sequence_id,
1234 bool snap_selection, IClientAPI remote_client)
1235 {
1236 //Get the land objects within the bounds
1237 List<ILandObject> temp = new List<ILandObject>();
1238 int inc_x = end_x - start_x;
1239 int inc_y = end_y - start_y;
1240 for (int x = 0; x < inc_x; x++)
1241 {
1242 for (int y = 0; y < inc_y; y++)
1243 {
1244 ILandObject currentParcel = GetLandObject(start_x + x, start_y + y);
1245  
1246 if (currentParcel != null)
1247 {
1248 if (!temp.Contains(currentParcel))
1249 {
1250 currentParcel.ForceUpdateLandInfo();
1251 temp.Add(currentParcel);
1252 }
1253 }
1254 }
1255 }
1256  
1257 int requestResult = LandChannel.LAND_RESULT_SINGLE;
1258 if (temp.Count > 1)
1259 {
1260 requestResult = LandChannel.LAND_RESULT_MULTIPLE;
1261 }
1262  
1263 for (int i = 0; i < temp.Count; i++)
1264 {
1265 temp[i].SendLandProperties(sequence_id, snap_selection, requestResult, remote_client);
1266 }
1267  
1268 SendParcelOverlay(remote_client);
1269 }
1270  
1271 public void ClientOnParcelPropertiesUpdateRequest(LandUpdateArgs args, int localID, IClientAPI remote_client)
1272 {
1273 ILandObject land;
1274 lock (m_landList)
1275 {
1276 m_landList.TryGetValue(localID, out land);
1277 }
1278  
1279 if (land != null)
1280 {
1281 land.UpdateLandProperties(args, remote_client);
1282 m_scene.EventManager.TriggerOnParcelPropertiesUpdateRequest(args, localID, remote_client);
1283 }
1284 }
1285  
1286 public void ClientOnParcelDivideRequest(int west, int south, int east, int north, IClientAPI remote_client)
1287 {
1288 subdivide(west, south, east, north, remote_client.AgentId);
1289 }
1290  
1291 public void ClientOnParcelJoinRequest(int west, int south, int east, int north, IClientAPI remote_client)
1292 {
1293 join(west, south, east, north, remote_client.AgentId);
1294 }
1295  
1296 public void ClientOnParcelSelectObjects(int local_id, int request_type,
1297 List<UUID> returnIDs, IClientAPI remote_client)
1298 {
1299 m_landList[local_id].SendForceObjectSelect(local_id, request_type, returnIDs, remote_client);
1300 }
1301  
1302 public void ClientOnParcelObjectOwnerRequest(int local_id, IClientAPI remote_client)
1303 {
1304 ILandObject land;
1305 lock (m_landList)
1306 {
1307 m_landList.TryGetValue(local_id, out land);
1308 }
1309  
1310 if (land != null)
1311 {
1312 m_scene.EventManager.TriggerParcelPrimCountUpdate();
1313 m_landList[local_id].SendLandObjectOwners(remote_client);
1314 }
1315 else
1316 {
1317 m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Invalid land object {0} passed for parcel object owner request", local_id);
1318 }
1319 }
1320  
1321 public void ClientOnParcelGodForceOwner(int local_id, UUID ownerID, IClientAPI remote_client)
1322 {
1323 ILandObject land;
1324 lock (m_landList)
1325 {
1326 m_landList.TryGetValue(local_id, out land);
1327 }
1328  
1329 if (land != null)
1330 {
1331 if (m_scene.Permissions.IsGod(remote_client.AgentId))
1332 {
1333 land.LandData.OwnerID = ownerID;
1334 land.LandData.GroupID = UUID.Zero;
1335 land.LandData.IsGroupOwned = false;
1336 land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
1337  
1338 m_scene.ForEachClient(SendParcelOverlay);
1339 land.SendLandUpdateToClient(true, remote_client);
1340 UpdateLandObject(land.LandData.LocalID, land.LandData);
1341 }
1342 }
1343 }
1344  
1345 public void ClientOnParcelAbandonRequest(int local_id, IClientAPI remote_client)
1346 {
1347 ILandObject land;
1348 lock (m_landList)
1349 {
1350 m_landList.TryGetValue(local_id, out land);
1351 }
1352  
1353 if (land != null)
1354 {
1355 if (m_scene.Permissions.CanAbandonParcel(remote_client.AgentId, land))
1356 {
1357 land.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
1358 land.LandData.GroupID = UUID.Zero;
1359 land.LandData.IsGroupOwned = false;
1360 land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
1361  
1362 m_scene.ForEachClient(SendParcelOverlay);
1363 land.SendLandUpdateToClient(true, remote_client);
1364 UpdateLandObject(land.LandData.LocalID, land.LandData);
1365 }
1366 }
1367 }
1368  
1369 public void ClientOnParcelReclaim(int local_id, IClientAPI remote_client)
1370 {
1371 ILandObject land;
1372 lock (m_landList)
1373 {
1374 m_landList.TryGetValue(local_id, out land);
1375 }
1376  
1377 if (land != null)
1378 {
1379 if (m_scene.Permissions.CanReclaimParcel(remote_client.AgentId, land))
1380 {
1381 land.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
1382 land.LandData.ClaimDate = Util.UnixTimeSinceEpoch();
1383 land.LandData.GroupID = UUID.Zero;
1384 land.LandData.IsGroupOwned = false;
1385 land.LandData.SalePrice = 0;
1386 land.LandData.AuthBuyerID = UUID.Zero;
1387 land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
1388  
1389 m_scene.ForEachClient(SendParcelOverlay);
1390 land.SendLandUpdateToClient(true, remote_client);
1391 UpdateLandObject(land.LandData.LocalID, land.LandData);
1392 }
1393 }
1394 }
1395 #endregion
1396  
1397 // If the economy has been validated by the economy module,
1398 // and land has been validated as well, this method transfers
1399 // the land ownership
1400  
1401 public void EventManagerOnLandBuy(Object o, EventManager.LandBuyArgs e)
1402 {
1403 if (e.economyValidated && e.landValidated)
1404 {
1405 ILandObject land;
1406 lock (m_landList)
1407 {
1408 m_landList.TryGetValue(e.parcelLocalID, out land);
1409 }
1410  
1411 if (land != null)
1412 {
1413 land.UpdateLandSold(e.agentId, e.groupId, e.groupOwned, (uint)e.transactionID, e.parcelPrice, e.parcelArea);
1414 }
1415 }
1416 }
1417  
1418 // After receiving a land buy packet, first the data needs to
1419 // be validated. This method validates the right to buy the
1420 // parcel
1421  
1422 public void EventManagerOnValidateLandBuy(Object o, EventManager.LandBuyArgs e)
1423 {
1424 if (e.landValidated == false)
1425 {
1426 ILandObject lob = null;
1427 lock (m_landList)
1428 {
1429 m_landList.TryGetValue(e.parcelLocalID, out lob);
1430 }
1431  
1432 if (lob != null)
1433 {
1434 UUID AuthorizedID = lob.LandData.AuthBuyerID;
1435 int saleprice = lob.LandData.SalePrice;
1436 UUID pOwnerID = lob.LandData.OwnerID;
1437  
1438 bool landforsale = ((lob.LandData.Flags &
1439 (uint)(ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects)) != 0);
1440 if ((AuthorizedID == UUID.Zero || AuthorizedID == e.agentId) && e.parcelPrice >= saleprice && landforsale)
1441 {
1442 // TODO I don't think we have to lock it here, no?
1443 //lock (e)
1444 //{
1445 e.parcelOwnerID = pOwnerID;
1446 e.landValidated = true;
1447 //}
1448 }
1449 }
1450 }
1451 }
1452  
1453 void ClientOnParcelDeedToGroup(int parcelLocalID, UUID groupID, IClientAPI remote_client)
1454 {
1455 ILandObject land;
1456 lock (m_landList)
1457 {
1458 m_landList.TryGetValue(parcelLocalID, out land);
1459 }
1460  
1461 if (!m_scene.Permissions.CanDeedParcel(remote_client.AgentId, land))
1462 return;
1463  
1464 if (land != null)
1465 {
1466 land.DeedToGroup(groupID);
1467 }
1468 }
1469  
1470 #region Land Object From Storage Functions
1471  
1472 private void EventManagerOnIncomingLandDataFromStorage(List<LandData> data)
1473 {
1474 // m_log.DebugFormat(
1475 // "[LAND MANAGMENT MODULE]: Processing {0} incoming parcels on {1}", data.Count, m_scene.Name);
1476  
1477 // Prevent race conditions from any auto-creation of new parcels for varregions whilst we are still loading
1478 // the existing parcels.
1479 lock (m_landList)
1480 {
1481 for (int i = 0; i < data.Count; i++)
1482 IncomingLandObjectFromStorage(data[i]);
1483  
1484 // Layer data is in landUnit (4m) chunks
1485 for (int y = 0; y < m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / LandUnit); y++)
1486 {
1487 for (int x = 0; x < m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / LandUnit); x++)
1488 {
1489 if (m_landIDList[x, y] == 0)
1490 {
1491 if (m_landList.Count == 1)
1492 {
1493 m_log.DebugFormat(
1494 "[{0}]: Auto-extending land parcel as landID at {1},{2} is 0 and only one land parcel is present in {3}",
1495 LogHeader, x, y, m_scene.Name);
1496  
1497 int onlyParcelID = 0;
1498 ILandObject onlyLandObject = null;
1499 foreach (KeyValuePair<int, ILandObject> kvp in m_landList)
1500 {
1501 onlyParcelID = kvp.Key;
1502 onlyLandObject = kvp.Value;
1503 break;
1504 }
1505  
1506 // There is only one parcel. Grow it to fill all the unallocated spaces.
1507 for (int xx = 0; xx < m_landIDList.GetLength(0); xx++)
1508 for (int yy = 0; yy < m_landIDList.GetLength(1); yy++)
1509 if (m_landIDList[xx, yy] == 0)
1510 m_landIDList[xx, yy] = onlyParcelID;
1511  
1512 onlyLandObject.LandBitmap = CreateBitmapForID(onlyParcelID);
1513 }
1514 else if (m_landList.Count > 1)
1515 {
1516 m_log.DebugFormat(
1517 "{0}: Auto-creating land parcel as landID at {1},{2} is 0 and more than one land parcel is present in {3}",
1518 LogHeader, x, y, m_scene.Name);
1519  
1520 // There are several other parcels so we must create a new one for the unassigned space
1521 ILandObject newLand = new LandObject(UUID.Zero, false, m_scene);
1522 // Claim all the unclaimed "0" ids
1523 newLand.SetLandBitmap(CreateBitmapForID(0));
1524 newLand.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
1525 newLand.LandData.ClaimDate = Util.UnixTimeSinceEpoch();
1526 newLand = AddLandObject(newLand);
1527 }
1528 else
1529 {
1530 // We should never reach this point as the separate code path when no land data exists should have fired instead.
1531 m_log.WarnFormat(
1532 "{0}: Ignoring request to auto-create parcel in {1} as there are no other parcels present",
1533 LogHeader, m_scene.Name);
1534 }
1535 }
1536 }
1537 }
1538 }
1539 }
1540  
1541 private void IncomingLandObjectFromStorage(LandData data)
1542 {
1543 ILandObject new_land = new LandObject(data, m_scene);
1544 new_land.SetLandBitmapFromByteArray();
1545 AddLandObject(new_land);
1546 }
1547  
1548 public void ReturnObjectsInParcel(int localID, uint returnType, UUID[] agentIDs, UUID[] taskIDs, IClientAPI remoteClient)
1549 {
1550 if (localID != -1)
1551 {
1552 ILandObject selectedParcel = null;
1553 lock (m_landList)
1554 {
1555 m_landList.TryGetValue(localID, out selectedParcel);
1556 }
1557  
1558 if (selectedParcel == null)
1559 return;
1560  
1561 selectedParcel.ReturnLandObjects(returnType, agentIDs, taskIDs, remoteClient);
1562 }
1563 else
1564 {
1565 if (returnType != 1)
1566 {
1567 m_log.WarnFormat("[LAND MANAGEMENT MODULE]: ReturnObjectsInParcel: unknown return type {0}", returnType);
1568 return;
1569 }
1570  
1571 // We get here when the user returns objects from the list of Top Colliders or Top Scripts.
1572 // In that case we receive specific object UUID's, but no parcel ID.
1573  
1574 Dictionary<UUID, HashSet<SceneObjectGroup>> returns = new Dictionary<UUID, HashSet<SceneObjectGroup>>();
1575  
1576 foreach (UUID groupID in taskIDs)
1577 {
1578 SceneObjectGroup obj = m_scene.GetSceneObjectGroup(groupID);
1579 if (obj != null)
1580 {
1581 if (!returns.ContainsKey(obj.OwnerID))
1582 returns[obj.OwnerID] = new HashSet<SceneObjectGroup>();
1583 returns[obj.OwnerID].Add(obj);
1584 }
1585 else
1586 {
1587 m_log.WarnFormat("[LAND MANAGEMENT MODULE]: ReturnObjectsInParcel: unknown object {0}", groupID);
1588 }
1589 }
1590  
1591 int num = 0;
1592 foreach (HashSet<SceneObjectGroup> objs in returns.Values)
1593 num += objs.Count;
1594 m_log.DebugFormat("[LAND MANAGEMENT MODULE]: Returning {0} specific object(s)", num);
1595  
1596 foreach (HashSet<SceneObjectGroup> objs in returns.Values)
1597 {
1598 List<SceneObjectGroup> objs2 = new List<SceneObjectGroup>(objs);
1599 if (m_scene.Permissions.CanReturnObjects(null, remoteClient.AgentId, objs2))
1600 {
1601 m_scene.returnObjects(objs2.ToArray(), remoteClient.AgentId);
1602 }
1603 else
1604 {
1605 m_log.WarnFormat("[LAND MANAGEMENT MODULE]: ReturnObjectsInParcel: not permitted to return {0} object(s) belonging to user {1}",
1606 objs2.Count, objs2[0].OwnerID);
1607 }
1608 }
1609 }
1610 }
1611  
1612 public void EventManagerOnNoLandDataFromStorage()
1613 {
1614 ResetSimLandObjects();
1615 CreateDefaultParcel();
1616 }
1617  
1618 #endregion
1619  
1620 public void setParcelObjectMaxOverride(overrideParcelMaxPrimCountDelegate overrideDel)
1621 {
1622 lock (m_landList)
1623 {
1624 foreach (LandObject obj in m_landList.Values)
1625 {
1626 obj.SetParcelObjectMaxOverride(overrideDel);
1627 }
1628 }
1629 }
1630  
1631 public void setSimulatorObjectMaxOverride(overrideSimulatorMaxPrimCountDelegate overrideDel)
1632 {
1633 }
1634  
1635 #region CAPS handler
1636  
1637 private void EventManagerOnRegisterCaps(UUID agentID, Caps caps)
1638 {
1639 string capsBase = "/CAPS/" + caps.CapsObjectPath;
1640 caps.RegisterHandler(
1641 "RemoteParcelRequest",
1642 new RestStreamHandler(
1643 "POST",
1644 capsBase + remoteParcelRequestPath,
1645 (request, path, param, httpRequest, httpResponse)
1646 => RemoteParcelRequest(request, path, param, agentID, caps),
1647 "RemoteParcelRequest",
1648 agentID.ToString()));
1649  
1650 UUID parcelCapID = UUID.Random();
1651 caps.RegisterHandler(
1652 "ParcelPropertiesUpdate",
1653 new RestStreamHandler(
1654 "POST",
1655 "/CAPS/" + parcelCapID,
1656 (request, path, param, httpRequest, httpResponse)
1657 => ProcessPropertiesUpdate(request, path, param, agentID, caps),
1658 "ParcelPropertiesUpdate",
1659 agentID.ToString()));
1660 }
1661 private string ProcessPropertiesUpdate(string request, string path, string param, UUID agentID, Caps caps)
1662 {
1663 IClientAPI client;
1664 if (!m_scene.TryGetClient(agentID, out client))
1665 {
1666 m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Unable to retrieve IClientAPI for {0}", agentID);
1667 return LLSDHelpers.SerialiseLLSDReply(new LLSDEmpty());
1668 }
1669  
1670 ParcelPropertiesUpdateMessage properties = new ParcelPropertiesUpdateMessage();
1671 OpenMetaverse.StructuredData.OSDMap args = (OpenMetaverse.StructuredData.OSDMap) OSDParser.DeserializeLLSDXml(request);
1672  
1673 properties.Deserialize(args);
1674  
1675 LandUpdateArgs land_update = new LandUpdateArgs();
1676 int parcelID = properties.LocalID;
1677 land_update.AuthBuyerID = properties.AuthBuyerID;
1678 land_update.Category = properties.Category;
1679 land_update.Desc = properties.Desc;
1680 land_update.GroupID = properties.GroupID;
1681 land_update.LandingType = (byte) properties.Landing;
1682 land_update.MediaAutoScale = (byte) Convert.ToInt32(properties.MediaAutoScale);
1683 land_update.MediaID = properties.MediaID;
1684 land_update.MediaURL = properties.MediaURL;
1685 land_update.MusicURL = properties.MusicURL;
1686 land_update.Name = properties.Name;
1687 land_update.ParcelFlags = (uint) properties.ParcelFlags;
1688 land_update.PassHours = (int) properties.PassHours;
1689 land_update.PassPrice = (int) properties.PassPrice;
1690 land_update.SalePrice = (int) properties.SalePrice;
1691 land_update.SnapshotID = properties.SnapshotID;
1692 land_update.UserLocation = properties.UserLocation;
1693 land_update.UserLookAt = properties.UserLookAt;
1694 land_update.MediaDescription = properties.MediaDesc;
1695 land_update.MediaType = properties.MediaType;
1696 land_update.MediaWidth = properties.MediaWidth;
1697 land_update.MediaHeight = properties.MediaHeight;
1698 land_update.MediaLoop = properties.MediaLoop;
1699 land_update.ObscureMusic = properties.ObscureMusic;
1700 land_update.ObscureMedia = properties.ObscureMedia;
1701  
1702 ILandObject land;
1703 lock (m_landList)
1704 {
1705 m_landList.TryGetValue(parcelID, out land);
1706 }
1707  
1708 if (land != null)
1709 {
1710 land.UpdateLandProperties(land_update, client);
1711 m_scene.EventManager.TriggerOnParcelPropertiesUpdateRequest(land_update, parcelID, client);
1712 }
1713 else
1714 {
1715 m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Unable to find parcelID {0}", parcelID);
1716 }
1717 return LLSDHelpers.SerialiseLLSDReply(new LLSDEmpty());
1718 }
1719 // we cheat here: As we don't have (and want) a grid-global parcel-store, we can't return the
1720 // "real" parcelID, because we wouldn't be able to map that to the region the parcel belongs to.
1721 // So, we create a "fake" parcelID by using the regionHandle (64 bit), and the local (integer) x
1722 // and y coordinate (each 8 bit), encoded in a UUID (128 bit).
1723 //
1724 // Request format:
1725 // <llsd>
1726 // <map>
1727 // <key>location</key>
1728 // <array>
1729 // <real>1.23</real>
1730 // <real>45..6</real>
1731 // <real>78.9</real>
1732 // </array>
1733 // <key>region_id</key>
1734 // <uuid>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</uuid>
1735 // </map>
1736 // </llsd>
1737 private string RemoteParcelRequest(string request, string path, string param, UUID agentID, Caps caps)
1738 {
1739 UUID parcelID = UUID.Zero;
1740 try
1741 {
1742 Hashtable hash = new Hashtable();
1743 hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
1744 if (hash.ContainsKey("region_id") && hash.ContainsKey("location"))
1745 {
1746 UUID regionID = (UUID)hash["region_id"];
1747 ArrayList list = (ArrayList)hash["location"];
1748 uint x = (uint)(double)list[0];
1749 uint y = (uint)(double)list[1];
1750 if (hash.ContainsKey("region_handle"))
1751 {
1752 // if you do a "About Landmark" on a landmark a second time, the viewer sends the
1753 // region_handle it got earlier via RegionHandleRequest
1754 ulong regionHandle = Util.BytesToUInt64Big((byte[])hash["region_handle"]);
1755 parcelID = Util.BuildFakeParcelID(regionHandle, x, y);
1756 }
1757 else if (regionID == m_scene.RegionInfo.RegionID)
1758 {
1759 // a parcel request for a local parcel => no need to query the grid
1760 parcelID = Util.BuildFakeParcelID(m_scene.RegionInfo.RegionHandle, x, y);
1761 }
1762 else
1763 {
1764 // a parcel request for a parcel in another region. Ask the grid about the region
1765 GridRegion info = m_scene.GridService.GetRegionByUUID(UUID.Zero, regionID);
1766 if (info != null)
1767 parcelID = Util.BuildFakeParcelID(info.RegionHandle, x, y);
1768 }
1769 }
1770 }
1771 catch (LLSD.LLSDParseException e)
1772 {
1773 m_log.ErrorFormat("[LAND MANAGEMENT MODULE]: Fetch error: {0}", e.Message);
1774 m_log.ErrorFormat("[LAND MANAGEMENT MODULE]: ... in request {0}", request);
1775 }
1776 catch (InvalidCastException)
1777 {
1778 m_log.ErrorFormat("[LAND MANAGEMENT MODULE]: Wrong type in request {0}", request);
1779 }
1780  
1781 LLSDRemoteParcelResponse response = new LLSDRemoteParcelResponse();
1782 response.parcel_id = parcelID;
1783 m_log.DebugFormat("[LAND MANAGEMENT MODULE]: Got parcelID {0}", parcelID);
1784  
1785 return LLSDHelpers.SerialiseLLSDReply(response);
1786 }
1787  
1788 #endregion
1789  
1790 private void ClientOnParcelInfoRequest(IClientAPI remoteClient, UUID parcelID)
1791 {
1792 if (parcelID == UUID.Zero)
1793 return;
1794  
1795 ExtendedLandData data = (ExtendedLandData)parcelInfoCache.Get(parcelID.ToString(),
1796 delegate(string id)
1797 {
1798 UUID parcel = UUID.Zero;
1799 UUID.TryParse(id, out parcel);
1800 // assume we've got the parcelID we just computed in RemoteParcelRequest
1801 ExtendedLandData extLandData = new ExtendedLandData();
1802 Util.ParseFakeParcelID(parcel, out extLandData.RegionHandle,
1803 out extLandData.X, out extLandData.Y);
1804 m_log.DebugFormat("[LAND MANAGEMENT MODULE]: Got parcelinfo request for regionHandle {0}, x/y {1}/{2}",
1805 extLandData.RegionHandle, extLandData.X, extLandData.Y);
1806  
1807 // for this region or for somewhere else?
1808 if (extLandData.RegionHandle == m_scene.RegionInfo.RegionHandle)
1809 {
1810 extLandData.LandData = this.GetLandObject(extLandData.X, extLandData.Y).LandData;
1811 extLandData.RegionAccess = m_scene.RegionInfo.AccessLevel;
1812 }
1813 else
1814 {
1815 ILandService landService = m_scene.RequestModuleInterface<ILandService>();
1816 extLandData.LandData = landService.GetLandData(m_scene.RegionInfo.ScopeID,
1817 extLandData.RegionHandle,
1818 extLandData.X,
1819 extLandData.Y,
1820 out extLandData.RegionAccess);
1821 if (extLandData.LandData == null)
1822 {
1823 // we didn't find the region/land => don't cache
1824 return null;
1825 }
1826 }
1827 return extLandData;
1828 });
1829  
1830 if (data != null) // if we found some data, send it
1831 {
1832 GridRegion info;
1833 if (data.RegionHandle == m_scene.RegionInfo.RegionHandle)
1834 {
1835 info = new GridRegion(m_scene.RegionInfo);
1836 }
1837 else
1838 {
1839 // most likely still cached from building the extLandData entry
1840 uint x = 0, y = 0;
1841 Util.RegionHandleToWorldLoc(data.RegionHandle, out x, out y);
1842 info = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
1843 }
1844 // we need to transfer the fake parcelID, not the one in landData, so the viewer can match it to the landmark.
1845 m_log.DebugFormat("[LAND MANAGEMENT MODULE]: got parcelinfo for parcel {0} in region {1}; sending...",
1846 data.LandData.Name, data.RegionHandle);
1847 // HACK for now
1848 RegionInfo r = new RegionInfo();
1849 r.RegionName = info.RegionName;
1850 r.RegionLocX = (uint)info.RegionLocX;
1851 r.RegionLocY = (uint)info.RegionLocY;
1852 r.RegionSettings.Maturity = (int)Util.ConvertAccessLevelToMaturity(data.RegionAccess);
1853 remoteClient.SendParcelInfo(r, data.LandData, parcelID, data.X, data.Y);
1854 }
1855 else
1856 m_log.Debug("[LAND MANAGEMENT MODULE]: got no parcelinfo; not sending");
1857 }
1858  
1859 public void setParcelOtherCleanTime(IClientAPI remoteClient, int localID, int otherCleanTime)
1860 {
1861 ILandObject land;
1862 lock (m_landList)
1863 {
1864 m_landList.TryGetValue(localID, out land);
1865 }
1866  
1867 if (land == null) return;
1868  
1869 if (!m_scene.Permissions.CanEditParcelProperties(remoteClient.AgentId, land, GroupPowers.LandOptions))
1870 return;
1871  
1872 land.LandData.OtherCleanTime = otherCleanTime;
1873  
1874 UpdateLandObject(localID, land.LandData);
1875 }
1876  
1877 Dictionary<UUID, System.Threading.Timer> Timers = new Dictionary<UUID, System.Threading.Timer>();
1878  
1879 public void ClientOnParcelFreezeUser(IClientAPI client, UUID parcelowner, uint flags, UUID target)
1880 {
1881 ScenePresence targetAvatar = null;
1882 ((Scene)client.Scene).TryGetScenePresence(target, out targetAvatar);
1883 ScenePresence parcelManager = null;
1884 ((Scene)client.Scene).TryGetScenePresence(client.AgentId, out parcelManager);
1885 System.Threading.Timer Timer;
1886  
1887 if (targetAvatar.UserLevel == 0)
1888 {
1889 ILandObject land = ((Scene)client.Scene).LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y);
1890 if (!((Scene)client.Scene).Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze))
1891 return;
1892 if (flags == 0)
1893 {
1894 targetAvatar.AllowMovement = false;
1895 targetAvatar.ControllingClient.SendAlertMessage(parcelManager.Firstname + " " + parcelManager.Lastname + " has frozen you for 30 seconds. You cannot move or interact with the world.");
1896 parcelManager.ControllingClient.SendAlertMessage("Avatar Frozen.");
1897 System.Threading.TimerCallback timeCB = new System.Threading.TimerCallback(OnEndParcelFrozen);
1898 Timer = new System.Threading.Timer(timeCB, targetAvatar, 30000, 0);
1899 Timers.Add(targetAvatar.UUID, Timer);
1900 }
1901 else
1902 {
1903 targetAvatar.AllowMovement = true;
1904 targetAvatar.ControllingClient.SendAlertMessage(parcelManager.Firstname + " " + parcelManager.Lastname + " has unfrozen you.");
1905 parcelManager.ControllingClient.SendAlertMessage("Avatar Unfrozen.");
1906 Timers.TryGetValue(targetAvatar.UUID, out Timer);
1907 Timers.Remove(targetAvatar.UUID);
1908 Timer.Dispose();
1909 }
1910 }
1911 }
1912  
1913 private void OnEndParcelFrozen(object avatar)
1914 {
1915 ScenePresence targetAvatar = (ScenePresence)avatar;
1916 targetAvatar.AllowMovement = true;
1917 System.Threading.Timer Timer;
1918 Timers.TryGetValue(targetAvatar.UUID, out Timer);
1919 Timers.Remove(targetAvatar.UUID);
1920 targetAvatar.ControllingClient.SendAgentAlertMessage("The freeze has worn off; you may go about your business.", false);
1921 }
1922  
1923 public void ClientOnParcelEjectUser(IClientAPI client, UUID parcelowner, uint flags, UUID target)
1924 {
1925 ScenePresence targetAvatar = null;
1926 ScenePresence parcelManager = null;
1927  
1928 // Must have presences
1929 if (!m_scene.TryGetScenePresence(target, out targetAvatar) ||
1930 !m_scene.TryGetScenePresence(client.AgentId, out parcelManager))
1931 return;
1932  
1933 // Cannot eject estate managers or gods
1934 if (m_scene.Permissions.IsAdministrator(target))
1935 return;
1936  
1937 // Check if you even have permission to do this
1938 ILandObject land = m_scene.LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y);
1939 if (!m_scene.Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze) &&
1940 !m_scene.Permissions.IsAdministrator(client.AgentId))
1941 return;
1942 Vector3 pos = m_scene.GetNearestAllowedPosition(targetAvatar, land);
1943  
1944 targetAvatar.TeleportWithMomentum(pos, null);
1945 targetAvatar.ControllingClient.SendAlertMessage("You have been ejected by " + parcelManager.Firstname + " " + parcelManager.Lastname);
1946 parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected.");
1947  
1948 if ((flags & 1) != 0) // Ban TODO: Remove magic number
1949 {
1950 LandAccessEntry entry = new LandAccessEntry();
1951 entry.AgentID = targetAvatar.UUID;
1952 entry.Flags = AccessList.Ban;
1953 entry.Expires = 0; // Perm
1954  
1955 land.LandData.ParcelAccessList.Add(entry);
1956 }
1957 }
1958  
1959 /// <summary>
1960 /// Sets the Home Point. The LoginService uses this to know where to put a user when they log-in
1961 /// </summary>
1962 /// <param name="remoteClient"></param>
1963 /// <param name="regionHandle"></param>
1964 /// <param name="position"></param>
1965 /// <param name="lookAt"></param>
1966 /// <param name="flags"></param>
1967 public virtual void ClientOnSetHome(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
1968 {
1969 // Let's find the parcel in question
1970 ILandObject land = landChannel.GetLandObject(position);
1971 if (land == null || m_scene.GridUserService == null)
1972 {
1973 m_Dialog.SendAlertToUser(remoteClient, "Set Home request failed.");
1974 return;
1975 }
1976  
1977 // Gather some data
1978 ulong gpowers = remoteClient.GetGroupPowers(land.LandData.GroupID);
1979 SceneObjectGroup telehub = null;
1980 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero)
1981 // Does the telehub exist in the scene?
1982 telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject);
1983  
1984 // Can the user set home here?
1985 if (// Required: local user; foreign users cannot set home
1986 m_scene.UserManagementModule.IsLocalGridUser(remoteClient.AgentId) &&
1987 (// (a) gods and land managers can set home
1988 m_scene.Permissions.IsAdministrator(remoteClient.AgentId) ||
1989 m_scene.Permissions.IsGod(remoteClient.AgentId) ||
1990 // (b) land owners can set home
1991 remoteClient.AgentId == land.LandData.OwnerID ||
1992 // (c) members of the land-associated group in roles that can set home
1993 ((gpowers & (ulong)GroupPowers.AllowSetHome) == (ulong)GroupPowers.AllowSetHome) ||
1994 // (d) parcels with telehubs can be the home of anyone
1995 (telehub != null && land.ContainsPoint((int)telehub.AbsolutePosition.X, (int)telehub.AbsolutePosition.Y))))
1996 {
1997 if (m_scene.GridUserService.SetHome(remoteClient.AgentId.ToString(), land.RegionUUID, position, lookAt))
1998 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
1999 m_Dialog.SendAlertToUser(remoteClient, "Home position set.");
2000 else
2001 m_Dialog.SendAlertToUser(remoteClient, "Set Home request failed.");
2002 }
2003 else
2004 m_Dialog.SendAlertToUser(remoteClient, "You are not allowed to set your home location in this parcel.");
2005 }
2006  
2007 protected void RegisterCommands()
2008 {
2009 ICommands commands = MainConsole.Instance.Commands;
2010  
2011 commands.AddCommand(
2012 "Land", false, "land clear",
2013 "land clear",
2014 "Clear all the parcels from the region.",
2015 "Command will ask for confirmation before proceeding.",
2016 HandleClearCommand);
2017  
2018 commands.AddCommand(
2019 "Land", false, "land show",
2020 "land show [<local-land-id>]",
2021 "Show information about the parcels on the region.",
2022 "If no local land ID is given, then summary information about all the parcels is shown.\n"
2023 + "If a local land ID is given then full information about that parcel is shown.",
2024 HandleShowCommand);
2025 }
2026  
2027 protected void HandleClearCommand(string module, string[] args)
2028 {
2029 if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_scene))
2030 return;
2031  
2032 string response = MainConsole.Instance.CmdPrompt(
2033 string.Format(
2034 "Are you sure that you want to clear all land parcels from {0} (y or n)", m_scene.Name),
2035 "n");
2036  
2037 if (response.ToLower() == "y")
2038 {
2039 Clear(true);
2040 MainConsole.Instance.OutputFormat("Cleared all parcels from {0}", m_scene.Name);
2041 }
2042 else
2043 {
2044 MainConsole.Instance.OutputFormat("Aborting clear of all parcels from {0}", m_scene.Name);
2045 }
2046 }
2047  
2048 protected void HandleShowCommand(string module, string[] args)
2049 {
2050 if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_scene))
2051 return;
2052  
2053 StringBuilder report = new StringBuilder();
2054  
2055 if (args.Length <= 2)
2056 {
2057 AppendParcelsSummaryReport(report);
2058 }
2059 else
2060 {
2061 int landLocalId;
2062  
2063 if (!ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, args[2], out landLocalId))
2064 return;
2065  
2066 ILandObject lo;
2067  
2068 lock (m_landList)
2069 {
2070 if (!m_landList.TryGetValue(landLocalId, out lo))
2071 {
2072 MainConsole.Instance.OutputFormat("No parcel found with local ID {0}", landLocalId);
2073 return;
2074 }
2075 }
2076  
2077 AppendParcelReport(report, lo);
2078 }
2079  
2080 MainConsole.Instance.Output(report.ToString());
2081 }
2082  
2083 private void AppendParcelsSummaryReport(StringBuilder report)
2084 {
2085 report.AppendFormat("Land information for {0}\n", m_scene.Name);
2086  
2087 ConsoleDisplayTable cdt = new ConsoleDisplayTable();
2088 cdt.AddColumn("Parcel Name", ConsoleDisplayUtil.ParcelNameSize);
2089 cdt.AddColumn("ID", 3);
2090 cdt.AddColumn("Area", 6);
2091 cdt.AddColumn("Starts", ConsoleDisplayUtil.VectorSize);
2092 cdt.AddColumn("Ends", ConsoleDisplayUtil.VectorSize);
2093 cdt.AddColumn("Owner", ConsoleDisplayUtil.UserNameSize);
2094  
2095 lock (m_landList)
2096 {
2097 foreach (ILandObject lo in m_landList.Values)
2098 {
2099 LandData ld = lo.LandData;
2100 string ownerName;
2101 if (ld.IsGroupOwned)
2102 {
2103 GroupRecord rec = m_groupManager.GetGroupRecord(ld.GroupID);
2104 ownerName = (rec != null) ? rec.GroupName : "Unknown Group";
2105 }
2106 else
2107 {
2108 ownerName = m_userManager.GetUserName(ld.OwnerID);
2109 }
2110 cdt.AddRow(
2111 ld.Name, ld.LocalID, ld.Area, lo.StartPoint, lo.EndPoint, ownerName);
2112 }
2113 }
2114  
2115 report.Append(cdt.ToString());
2116 }
2117  
2118 private void AppendParcelReport(StringBuilder report, ILandObject lo)
2119 {
2120 LandData ld = lo.LandData;
2121  
2122 ConsoleDisplayList cdl = new ConsoleDisplayList();
2123 cdl.AddRow("Parcel name", ld.Name);
2124 cdl.AddRow("Local ID", ld.LocalID);
2125 cdl.AddRow("Description", ld.Description);
2126 cdl.AddRow("Snapshot ID", ld.SnapshotID);
2127 cdl.AddRow("Area", ld.Area);
2128 cdl.AddRow("Starts", lo.StartPoint);
2129 cdl.AddRow("Ends", lo.EndPoint);
2130 cdl.AddRow("AABB Min", ld.AABBMin);
2131 cdl.AddRow("AABB Max", ld.AABBMax);
2132 string ownerName;
2133 if (ld.IsGroupOwned)
2134 {
2135 GroupRecord rec = m_groupManager.GetGroupRecord(ld.GroupID);
2136 ownerName = (rec != null) ? rec.GroupName : "Unknown Group";
2137 }
2138 else
2139 {
2140 ownerName = m_userManager.GetUserName(ld.OwnerID);
2141 }
2142 cdl.AddRow("Owner", ownerName);
2143 cdl.AddRow("Is group owned?", ld.IsGroupOwned);
2144 cdl.AddRow("GroupID", ld.GroupID);
2145  
2146 cdl.AddRow("Status", ld.Status);
2147 cdl.AddRow("Flags", (ParcelFlags)ld.Flags);
2148  
2149 cdl.AddRow("Landing Type", (LandingType)ld.LandingType);
2150 cdl.AddRow("User Location", ld.UserLocation);
2151 cdl.AddRow("User look at", ld.UserLookAt);
2152  
2153 cdl.AddRow("Other clean time", ld.OtherCleanTime);
2154  
2155 cdl.AddRow("Max Prims", lo.GetParcelMaxPrimCount());
2156 IPrimCounts pc = lo.PrimCounts;
2157 cdl.AddRow("Owner Prims", pc.Owner);
2158 cdl.AddRow("Group Prims", pc.Group);
2159 cdl.AddRow("Other Prims", pc.Others);
2160 cdl.AddRow("Selected Prims", pc.Selected);
2161 cdl.AddRow("Total Prims", pc.Total);
2162  
2163 cdl.AddRow("Music URL", ld.MusicURL);
2164 cdl.AddRow("Obscure Music", ld.ObscureMusic);
2165  
2166 cdl.AddRow("Media ID", ld.MediaID);
2167 cdl.AddRow("Media Autoscale", Convert.ToBoolean(ld.MediaAutoScale));
2168 cdl.AddRow("Media URL", ld.MediaURL);
2169 cdl.AddRow("Media Type", ld.MediaType);
2170 cdl.AddRow("Media Description", ld.MediaDescription);
2171 cdl.AddRow("Media Width", ld.MediaWidth);
2172 cdl.AddRow("Media Height", ld.MediaHeight);
2173 cdl.AddRow("Media Loop", ld.MediaLoop);
2174 cdl.AddRow("Obscure Media", ld.ObscureMedia);
2175  
2176 cdl.AddRow("Parcel Category", ld.Category);
2177  
2178 cdl.AddRow("Claim Date", ld.ClaimDate);
2179 cdl.AddRow("Claim Price", ld.ClaimPrice);
2180 cdl.AddRow("Pass Hours", ld.PassHours);
2181 cdl.AddRow("Pass Price", ld.PassPrice);
2182  
2183 cdl.AddRow("Auction ID", ld.AuctionID);
2184 cdl.AddRow("Authorized Buyer ID", ld.AuthBuyerID);
2185 cdl.AddRow("Sale Price", ld.SalePrice);
2186  
2187 cdl.AddToStringBuilder(report);
2188 }
2189 }
2190 }