1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
|
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Reflection;
using log4net;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.CoreModules.World.Land
{
/// <summary>
/// Keeps track of a specific piece of land's information
/// </summary>
public class LandObject : ILandObject
{
#region Member Variables
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
#pragma warning disable 0429
private const int landArrayMax = ((int)((int)Constants.RegionSize / 4) >= 64) ? (int)((int)Constants.RegionSize / 4) : 64;
#pragma warning restore 0429
private bool[,] m_landBitmap = new bool[landArrayMax,landArrayMax];
private int m_lastSeqId = 0;
protected LandData m_landData = new LandData();
protected Scene m_scene;
protected List<SceneObjectGroup> primsOverMe = new List<SceneObjectGroup>();
protected Dictionary<uint, UUID> m_listTransactions = new Dictionary<uint, UUID>();
public bool[,] LandBitmap
{
get { return m_landBitmap; }
set { m_landBitmap = value; }
}
#endregion
public int GetPrimsFree()
{
m_scene.EventManager.TriggerParcelPrimCountUpdate();
int free = GetSimulatorMaxPrimCount(this) - m_landData.SimwidePrims;
return free;
}
public LandData LandData
{
get { return m_landData; }
set { m_landData = value; }
}
public IPrimCounts PrimCounts { get; set; }
public UUID RegionUUID
{
get { return m_scene.RegionInfo.RegionID; }
}
public Vector3 StartPoint
{
get
{
for (int y = 0; y < landArrayMax; y++)
{
for (int x = 0; x < landArrayMax; x++)
{
if (LandBitmap[x, y])
return new Vector3(x * 4, y * 4, 0);
}
}
return new Vector3(-1, -1, -1);
}
}
public Vector3 EndPoint
{
get
{
for (int y = landArrayMax - 1; y >= 0; y--)
{
for (int x = landArrayMax - 1; x >= 0; x--)
{
if (LandBitmap[x, y])
{
return new Vector3(x * 4, y * 4, 0);
}
}
}
return new Vector3(-1, -1, -1);
}
}
#region Constructors
public LandObject(UUID owner_id, bool is_group_owned, Scene scene)
{
m_scene = scene;
LandData.OwnerID = owner_id;
if (is_group_owned)
LandData.GroupID = owner_id;
else
LandData.GroupID = UUID.Zero;
LandData.IsGroupOwned = is_group_owned;
}
#endregion
#region Member Functions
#region General Functions
/// <summary>
/// Checks to see if this land object contains a point
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns>Returns true if the piece of land contains the specified point</returns>
public bool ContainsPoint(int x, int y)
{
if (x >= 0 && y >= 0 && x < Constants.RegionSize && y < Constants.RegionSize)
{
return (LandBitmap[x / 4, y / 4] == true);
}
else
{
return false;
}
}
public ILandObject Copy()
{
ILandObject newLand = new LandObject(LandData.OwnerID, LandData.IsGroupOwned, m_scene);
//Place all new variables here!
newLand.LandBitmap = (bool[,]) (LandBitmap.Clone());
newLand.LandData = LandData.Copy();
return newLand;
}
static overrideParcelMaxPrimCountDelegate overrideParcelMaxPrimCount;
static overrideSimulatorMaxPrimCountDelegate overrideSimulatorMaxPrimCount;
public void SetParcelObjectMaxOverride(overrideParcelMaxPrimCountDelegate overrideDel)
{
overrideParcelMaxPrimCount = overrideDel;
}
public void SetSimulatorObjectMaxOverride(overrideSimulatorMaxPrimCountDelegate overrideDel)
{
overrideSimulatorMaxPrimCount = overrideDel;
}
public int GetParcelMaxPrimCount(ILandObject thisObject)
{
if (overrideParcelMaxPrimCount != null)
{
return overrideParcelMaxPrimCount(thisObject);
}
else
{
// Normal Calculations
int parcelMax = (int)(((float)LandData.Area / 65536.0f)
* (float)m_scene.RegionInfo.ObjectCapacity
* (float)m_scene.RegionInfo.RegionSettings.ObjectBonus);
// TODO: The calculation of ObjectBonus should be refactored. It does still not work in the same manner as SL!
return parcelMax;
}
}
public int GetSimulatorMaxPrimCount(ILandObject thisObject)
{
if (overrideSimulatorMaxPrimCount != null)
{
return overrideSimulatorMaxPrimCount(thisObject);
}
else
{
//Normal Calculations
int simMax = (int)(((float)LandData.SimwideArea / 65536.0f)
* (float)m_scene.RegionInfo.ObjectCapacity);
return simMax;
}
}
#endregion
#region Packet Request Handling
public void SendLandProperties(int sequence_id, bool snap_selection, int request_result, IClientAPI remote_client)
{
IEstateModule estateModule = m_scene.RequestModuleInterface<IEstateModule>();
uint regionFlags = 336723974 & ~((uint)(RegionFlags.AllowLandmark | RegionFlags.AllowSetHome));
if (estateModule != null)
regionFlags = estateModule.GetRegionFlags();
// In a perfect world, this would have worked.
//
// if ((landData.Flags & (uint)ParcelFlags.AllowLandmark) != 0)
// regionFlags |= (uint)RegionFlags.AllowLandmark;
// if (landData.OwnerID == remote_client.AgentId)
// regionFlags |= (uint)RegionFlags.AllowSetHome;
int seq_id;
if (snap_selection && (sequence_id == 0))
{
seq_id = m_lastSeqId;
}
else
{
seq_id = sequence_id;
m_lastSeqId = seq_id;
}
remote_client.SendLandProperties(seq_id,
snap_selection, request_result, this,
(float)m_scene.RegionInfo.RegionSettings.ObjectBonus,
GetParcelMaxPrimCount(this),
GetSimulatorMaxPrimCount(this), regionFlags);
}
public void UpdateLandProperties(LandUpdateArgs args, IClientAPI remote_client)
{
//Needs later group support
bool snap_selection = false;
LandData newData = LandData.Copy();
uint allowedDelta = 0;
// These two are always blocked as no client can set them anyway
// ParcelFlags.ForSaleObjects
// ParcelFlags.LindenHome
if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions))
{
allowedDelta |= (uint)(ParcelFlags.AllowLandmark |
ParcelFlags.AllowTerraform |
ParcelFlags.AllowDamage |
ParcelFlags.CreateObjects |
ParcelFlags.RestrictPushObject |
ParcelFlags.AllowOtherScripts |
ParcelFlags.AllowGroupScripts |
ParcelFlags.CreateGroupObjects |
ParcelFlags.AllowAPrimitiveEntry |
ParcelFlags.AllowGroupObjectEntry);
}
if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandSetSale))
{
if (args.AuthBuyerID != newData.AuthBuyerID ||
args.SalePrice != newData.SalePrice)
{
snap_selection = true;
}
newData.AuthBuyerID = args.AuthBuyerID;
newData.SalePrice = args.SalePrice;
if (!LandData.IsGroupOwned)
{
newData.GroupID = args.GroupID;
allowedDelta |= (uint)(ParcelFlags.AllowDeedToGroup |
ParcelFlags.ContributeWithDeed |
ParcelFlags.SellParcelObjects);
}
allowedDelta |= (uint)ParcelFlags.ForSale;
}
if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.FindPlaces))
{
newData.Category = args.Category;
allowedDelta |= (uint)(ParcelFlags.ShowDirectory |
ParcelFlags.AllowPublish |
ParcelFlags.MaturePublish);
}
if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.LandChangeIdentity))
{
newData.Description = args.Desc;
newData.Name = args.Name;
newData.SnapshotID = args.SnapshotID;
}
if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.SetLandingPoint))
{
newData.LandingType = args.LandingType;
newData.UserLocation = args.UserLocation;
newData.UserLookAt = args.UserLookAt;
}
if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.ChangeMedia))
{
newData.MediaAutoScale = args.MediaAutoScale;
newData.MediaID = args.MediaID;
newData.MediaURL = args.MediaURL;
newData.MusicURL = args.MusicURL;
newData.MediaType = args.MediaType;
newData.MediaDescription = args.MediaDescription;
newData.MediaWidth = args.MediaWidth;
newData.MediaHeight = args.MediaHeight;
newData.MediaLoop = args.MediaLoop;
newData.ObscureMusic = args.ObscureMusic;
newData.ObscureMedia = args.ObscureMedia;
allowedDelta |= (uint)(ParcelFlags.SoundLocal |
ParcelFlags.UrlWebPage |
ParcelFlags.UrlRawHtml |
ParcelFlags.AllowVoiceChat |
ParcelFlags.UseEstateVoiceChan);
}
if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.LandManagePasses))
{
newData.PassHours = args.PassHours;
newData.PassPrice = args.PassPrice;
allowedDelta |= (uint)ParcelFlags.UsePassList;
}
if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandManageAllowed))
{
allowedDelta |= (uint)(ParcelFlags.UseAccessGroup |
ParcelFlags.UseAccessList);
}
if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandManageBanned))
{
allowedDelta |= (uint)(ParcelFlags.UseBanList |
ParcelFlags.DenyAnonymous |
ParcelFlags.DenyAgeUnverified);
}
uint preserve = LandData.Flags & ~allowedDelta;
newData.Flags = preserve | (args.ParcelFlags & allowedDelta);
m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
SendLandUpdateToAvatarsOverMe(snap_selection);
}
public void UpdateLandSold(UUID avatarID, UUID groupID, bool groupOwned, uint AuctionID, int claimprice, int area)
{
LandData newData = LandData.Copy();
newData.OwnerID = avatarID;
newData.GroupID = groupID;
newData.IsGroupOwned = groupOwned;
//newData.auctionID = AuctionID;
newData.ClaimDate = Util.UnixTimeSinceEpoch();
newData.ClaimPrice = claimprice;
newData.SalePrice = 0;
newData.AuthBuyerID = UUID.Zero;
newData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
m_scene.EventManager.TriggerParcelPrimCountUpdate();
SendLandUpdateToAvatarsOverMe(true);
}
public void DeedToGroup(UUID groupID)
{
LandData newData = LandData.Copy();
newData.OwnerID = groupID;
newData.GroupID = groupID;
newData.IsGroupOwned = true;
// Reset show in directory flag on deed
newData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
m_scene.EventManager.TriggerParcelPrimCountUpdate();
SendLandUpdateToAvatarsOverMe(true);
}
public bool IsEitherBannedOrRestricted(UUID avatar)
{
if (IsBannedFromLand(avatar))
{
return true;
}
else if (IsRestrictedFromLand(avatar))
{
return true;
}
return false;
}
public bool IsBannedFromLand(UUID avatar)
{
if (m_scene.Permissions.IsAdministrator(avatar))
return false;
if ((LandData.Flags & (uint) ParcelFlags.UseBanList) > 0)
{
if (LandData.ParcelAccessList.FindIndex(
delegate(ParcelManager.ParcelAccessEntry e)
{
if (e.AgentID == avatar && e.Flags == AccessList.Ban)
return true;
return false;
}) != -1 && LandData.OwnerID != avatar)
{
return true;
}
}
return false;
}
public bool IsRestrictedFromLand(UUID avatar)
{
if (m_scene.Permissions.IsAdministrator(avatar))
return false;
if ((LandData.Flags & (uint) ParcelFlags.UseAccessList) > 0)
{
if (LandData.ParcelAccessList.FindIndex(
delegate(ParcelManager.ParcelAccessEntry e)
{
if (e.AgentID == avatar && e.Flags == AccessList.Access)
return true;
return false;
}) == -1 && LandData.OwnerID != avatar)
{
return true;
}
}
return false;
}
public void SendLandUpdateToClient(IClientAPI remote_client)
{
SendLandProperties(0, false, 0, remote_client);
}
public void SendLandUpdateToClient(bool snap_selection, IClientAPI remote_client)
{
m_scene.EventManager.TriggerParcelPrimCountUpdate();
SendLandProperties(0, snap_selection, 0, remote_client);
}
public void SendLandUpdateToAvatarsOverMe()
{
SendLandUpdateToAvatarsOverMe(false);
}
public void SendLandUpdateToAvatarsOverMe(bool snap_selection)
{
m_scene.ForEachScenePresence(delegate(ScenePresence avatar)
{
if (avatar.IsChildAgent)
return;
ILandObject over = null;
try
{
over =
m_scene.LandChannel.GetLandObject(Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.X), 0, ((int)Constants.RegionSize - 1)),
Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.Y), 0, ((int)Constants.RegionSize - 1)));
}
catch (Exception)
{
m_log.Warn("[LAND]: " + "unable to get land at x: " + Math.Round(avatar.AbsolutePosition.X) + " y: " +
Math.Round(avatar.AbsolutePosition.Y));
}
if (over != null)
{
if (over.LandData.LocalID == LandData.LocalID)
{
if (((over.LandData.Flags & (uint)ParcelFlags.AllowDamage) != 0) &&
m_scene.RegionInfo.RegionSettings.AllowDamage)
avatar.Invulnerable = false;
else
avatar.Invulnerable = true;
SendLandUpdateToClient(snap_selection, avatar.ControllingClient);
}
}
});
}
#endregion
#region AccessList Functions
public List<UUID> CreateAccessListArrayByFlag(AccessList flag)
{
List<UUID> list = new List<UUID>();
foreach (ParcelManager.ParcelAccessEntry entry in LandData.ParcelAccessList)
{
if (entry.Flags == flag)
{
list.Add(entry.AgentID);
}
}
if (list.Count == 0)
{
list.Add(UUID.Zero);
}
return list;
}
public void SendAccessList(UUID agentID, UUID sessionID, uint flags, int sequenceID,
IClientAPI remote_client)
{
if (flags == (uint) AccessList.Access || flags == (uint) AccessList.Both)
{
List<UUID> avatars = CreateAccessListArrayByFlag(AccessList.Access);
remote_client.SendLandAccessListData(avatars,(uint) AccessList.Access,LandData.LocalID);
}
if (flags == (uint) AccessList.Ban || flags == (uint) AccessList.Both)
{
List<UUID> avatars = CreateAccessListArrayByFlag(AccessList.Ban);
remote_client.SendLandAccessListData(avatars, (uint)AccessList.Ban, LandData.LocalID);
}
}
public void UpdateAccessList(uint flags, UUID transactionID,
int sequenceID, int sections,
List<ParcelManager.ParcelAccessEntry> entries,
IClientAPI remote_client)
{
LandData newData = LandData.Copy();
if ((!m_listTransactions.ContainsKey(flags)) ||
m_listTransactions[flags] != transactionID)
{
m_listTransactions[flags] = transactionID;
List<ParcelManager.ParcelAccessEntry> toRemove =
new List<ParcelManager.ParcelAccessEntry>();
foreach (ParcelManager.ParcelAccessEntry entry in newData.ParcelAccessList)
{
if (entry.Flags == (AccessList)flags)
toRemove.Add(entry);
}
foreach (ParcelManager.ParcelAccessEntry entry in toRemove)
{
newData.ParcelAccessList.Remove(entry);
}
// Checked here because this will always be the first
// and only packet in a transaction
if (entries.Count == 1 && entries[0].AgentID == UUID.Zero)
{
m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
return;
}
}
foreach (ParcelManager.ParcelAccessEntry entry in entries)
{
ParcelManager.ParcelAccessEntry temp =
new ParcelManager.ParcelAccessEntry();
temp.AgentID = entry.AgentID;
temp.Time = entry.Time;
temp.Flags = (AccessList)flags;
newData.ParcelAccessList.Add(temp);
}
m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
}
#endregion
#region Update Functions
public void UpdateLandBitmapByteArray()
{
LandData.Bitmap = ConvertLandBitmapToBytes();
}
/// <summary>
/// Update all settings in land such as area, bitmap byte array, etc
/// </summary>
public void ForceUpdateLandInfo()
{
UpdateAABBAndAreaValues();
UpdateLandBitmapByteArray();
}
public void SetLandBitmapFromByteArray()
{
LandBitmap = ConvertBytesToLandBitmap();
}
/// <summary>
/// Updates the AABBMin and AABBMax values after area/shape modification of the land object
/// </summary>
private void UpdateAABBAndAreaValues()
{
int min_x = 64;
int min_y = 64;
int max_x = 0;
int max_y = 0;
int tempArea = 0;
int x, y;
for (x = 0; x < 64; x++)
{
for (y = 0; y < 64; y++)
{
if (LandBitmap[x, y] == true)
{
if (min_x > x) min_x = x;
if (min_y > y) min_y = y;
if (max_x < x) max_x = x;
if (max_y < y) max_y = y;
tempArea += 16; //16sqm peice of land
}
}
}
int tx = min_x * 4;
if (tx > ((int)Constants.RegionSize - 1))
tx = ((int)Constants.RegionSize - 1);
int ty = min_y * 4;
if (ty > ((int)Constants.RegionSize - 1))
ty = ((int)Constants.RegionSize - 1);
LandData.AABBMin =
new Vector3((float) (min_x * 4), (float) (min_y * 4),
(float) m_scene.Heightmap[tx, ty]);
tx = max_x * 4;
if (tx > ((int)Constants.RegionSize - 1))
tx = ((int)Constants.RegionSize - 1);
ty = max_y * 4;
if (ty > ((int)Constants.RegionSize - 1))
ty = ((int)Constants.RegionSize - 1);
LandData.AABBMax =
new Vector3((float) (max_x * 4), (float) (max_y * 4),
(float) m_scene.Heightmap[tx, ty]);
LandData.Area = tempArea;
}
#endregion
#region Land Bitmap Functions
/// <summary>
/// Sets the land's bitmap manually
/// </summary>
/// <param name="bitmap">64x64 block representing where this land is on a map</param>
public void SetLandBitmap(bool[,] bitmap)
{
if (bitmap.GetLength(0) != 64 || bitmap.GetLength(1) != 64 || bitmap.Rank != 2)
{
//Throw an exception - The bitmap is not 64x64
//throw new Exception("Error: Invalid Parcel Bitmap");
}
else
{
//Valid: Lets set it
LandBitmap = bitmap;
ForceUpdateLandInfo();
}
}
/// <summary>
/// Gets the land's bitmap manually
/// </summary>
/// <returns></returns>
public bool[,] GetLandBitmap()
{
return LandBitmap;
}
/// <summary>
/// Full sim land object creation
/// </summary>
/// <returns></returns>
public bool[,] BasicFullRegionLandBitmap()
{
return GetSquareLandBitmap(0, 0, (int) Constants.RegionSize, (int) Constants.RegionSize);
}
/// <summary>
/// Used to modify the bitmap between the x and y points. Points use 64 scale
/// </summary>
/// <param name="start_x"></param>
/// <param name="start_y"></param>
/// <param name="end_x"></param>
/// <param name="end_y"></param>
/// <returns></returns>
public bool[,] GetSquareLandBitmap(int start_x, int start_y, int end_x, int end_y)
{
bool[,] tempBitmap = new bool[64,64];
tempBitmap.Initialize();
tempBitmap = ModifyLandBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, true);
return tempBitmap;
}
/// <summary>
/// Change a land bitmap at within a square and set those points to a specific value
/// </summary>
/// <param name="land_bitmap"></param>
/// <param name="start_x"></param>
/// <param name="start_y"></param>
/// <param name="end_x"></param>
/// <param name="end_y"></param>
/// <param name="set_value"></param>
/// <returns></returns>
public bool[,] ModifyLandBitmapSquare(bool[,] land_bitmap, int start_x, int start_y, int end_x, int end_y,
bool set_value)
{
if (land_bitmap.GetLength(0) != 64 || land_bitmap.GetLength(1) != 64 || land_bitmap.Rank != 2)
{
//Throw an exception - The bitmap is not 64x64
//throw new Exception("Error: Invalid Parcel Bitmap in modifyLandBitmapSquare()");
}
int x, y;
for (y = 0; y < 64; y++)
{
for (x = 0; x < 64; x++)
{
if (x >= start_x / 4 && x < end_x / 4
&& y >= start_y / 4 && y < end_y / 4)
{
land_bitmap[x, y] = set_value;
}
}
}
return land_bitmap;
}
/// <summary>
/// Join the true values of 2 bitmaps together
/// </summary>
/// <param name="bitmap_base"></param>
/// <param name="bitmap_add"></param>
/// <returns></returns>
public bool[,] MergeLandBitmaps(bool[,] bitmap_base, bool[,] bitmap_add)
{
if (bitmap_base.GetLength(0) != 64 || bitmap_base.GetLength(1) != 64 || bitmap_base.Rank != 2)
{
//Throw an exception - The bitmap is not 64x64
throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_base in mergeLandBitmaps");
}
if (bitmap_add.GetLength(0) != 64 || bitmap_add.GetLength(1) != 64 || bitmap_add.Rank != 2)
{
//Throw an exception - The bitmap is not 64x64
throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_add in mergeLandBitmaps");
}
int x, y;
for (y = 0; y < 64; y++)
{
for (x = 0; x < 64; x++)
{
if (bitmap_add[x, y])
{
bitmap_base[x, y] = true;
}
}
}
return bitmap_base;
}
/// <summary>
/// Converts the land bitmap to a packet friendly byte array
/// </summary>
/// <returns></returns>
private byte[] ConvertLandBitmapToBytes()
{
byte[] tempConvertArr = new byte[512];
byte tempByte = 0;
int x, y, i, byteNum = 0;
i = 0;
for (y = 0; y < 64; y++)
{
for (x = 0; x < 64; x++)
{
tempByte = Convert.ToByte(tempByte | Convert.ToByte(LandBitmap[x, y]) << (i++ % 8));
if (i % 8 == 0)
{
tempConvertArr[byteNum] = tempByte;
tempByte = (byte) 0;
i = 0;
byteNum++;
}
}
}
return tempConvertArr;
}
private bool[,] ConvertBytesToLandBitmap()
{
bool[,] tempConvertMap = new bool[landArrayMax, landArrayMax];
tempConvertMap.Initialize();
byte tempByte = 0;
int x = 0, y = 0, i = 0, bitNum = 0;
for (i = 0; i < 512; i++)
{
tempByte = LandData.Bitmap[i];
for (bitNum = 0; bitNum < 8; bitNum++)
{
bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte) 1);
tempConvertMap[x, y] = bit;
x++;
if (x > 63)
{
x = 0;
y++;
}
}
}
return tempConvertMap;
}
#endregion
#region Object Select and Object Owner Listing
public void SendForceObjectSelect(int local_id, int request_type, List<UUID> returnIDs, IClientAPI remote_client)
{
if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions))
{
List<uint> resultLocalIDs = new List<uint>();
try
{
lock (primsOverMe)
{
foreach (SceneObjectGroup obj in primsOverMe)
{
if (obj.LocalId > 0)
{
if (request_type == LandChannel.LAND_SELECT_OBJECTS_OWNER && obj.OwnerID == LandData.OwnerID)
{
resultLocalIDs.Add(obj.LocalId);
}
else if (request_type == LandChannel.LAND_SELECT_OBJECTS_GROUP && obj.GroupID == LandData.GroupID && LandData.GroupID != UUID.Zero)
{
resultLocalIDs.Add(obj.LocalId);
}
else if (request_type == LandChannel.LAND_SELECT_OBJECTS_OTHER &&
obj.OwnerID != remote_client.AgentId)
{
resultLocalIDs.Add(obj.LocalId);
}
else if (request_type == (int)ObjectReturnType.List && returnIDs.Contains(obj.OwnerID))
{
resultLocalIDs.Add(obj.LocalId);
}
}
}
}
} catch (InvalidOperationException)
{
m_log.Error("[LAND]: Unable to force select the parcel objects. Arr.");
}
remote_client.SendForceClientSelectObjects(resultLocalIDs);
}
}
/// <summary>
/// Notify the parcel owner each avatar that owns prims situated on their land. This notification includes
/// aggreagete details such as the number of prims.
///
/// </summary>
/// <param name="remote_client">
/// A <see cref="IClientAPI"/>
/// </param>
public void SendLandObjectOwners(IClientAPI remote_client)
{
if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions))
{
Dictionary<UUID, int> primCount = new Dictionary<UUID, int>();
List<UUID> groups = new List<UUID>();
lock (primsOverMe)
{
// m_log.DebugFormat(
// "[LAND OBJECT]: Request for SendLandObjectOwners() from {0} with {1} known prims on region",
// remote_client.Name, primsOverMe.Count);
try
{
foreach (SceneObjectGroup obj in primsOverMe)
{
try
{
if (!primCount.ContainsKey(obj.OwnerID))
{
primCount.Add(obj.OwnerID, 0);
}
}
catch (NullReferenceException)
{
m_log.Info("[LAND]: " + "Got Null Reference when searching land owners from the parcel panel");
}
try
{
primCount[obj.OwnerID] += obj.PrimCount;
}
catch (KeyNotFoundException)
{
m_log.Error("[LAND]: Unable to match a prim with it's owner.");
}
if (obj.OwnerID == obj.GroupID && (!groups.Contains(obj.OwnerID)))
groups.Add(obj.OwnerID);
}
}
catch (InvalidOperationException)
{
m_log.Error("[LAND]: Unable to Enumerate Land object arr.");
}
}
remote_client.SendLandObjectOwners(LandData, groups, primCount);
}
}
public Dictionary<UUID, int> GetLandObjectOwners()
{
Dictionary<UUID, int> ownersAndCount = new Dictionary<UUID, int>();
lock (primsOverMe)
{
try
{
foreach (SceneObjectGroup obj in primsOverMe)
{
if (!ownersAndCount.ContainsKey(obj.OwnerID))
{
ownersAndCount.Add(obj.OwnerID, 0);
}
ownersAndCount[obj.OwnerID] += obj.PrimCount;
}
}
catch (InvalidOperationException)
{
m_log.Error("[LAND]: Unable to enumerate land owners. arr.");
}
}
return ownersAndCount;
}
#endregion
#region Object Returning
public void ReturnObject(SceneObjectGroup obj)
{
SceneObjectGroup[] objs = new SceneObjectGroup[1];
objs[0] = obj;
m_scene.returnObjects(objs, obj.OwnerID);
}
public void ReturnLandObjects(uint type, UUID[] owners, UUID[] tasks, IClientAPI remote_client)
{
// m_log.DebugFormat(
// "[LAND OBJECT]: Request to return objects in {0} from {1}", LandData.Name, remote_client.Name);
Dictionary<UUID,List<SceneObjectGroup>> returns = new Dictionary<UUID,List<SceneObjectGroup>>();
lock (primsOverMe)
{
if (type == (uint)ObjectReturnType.Owner)
{
foreach (SceneObjectGroup obj in primsOverMe)
{
if (obj.OwnerID == m_landData.OwnerID)
{
if (!returns.ContainsKey(obj.OwnerID))
returns[obj.OwnerID] =
new List<SceneObjectGroup>();
returns[obj.OwnerID].Add(obj);
}
}
}
else if (type == (uint)ObjectReturnType.Group && m_landData.GroupID != UUID.Zero)
{
foreach (SceneObjectGroup obj in primsOverMe)
{
if (obj.GroupID == m_landData.GroupID)
{
if (!returns.ContainsKey(obj.OwnerID))
returns[obj.OwnerID] =
new List<SceneObjectGroup>();
returns[obj.OwnerID].Add(obj);
}
}
}
else if (type == (uint)ObjectReturnType.Other)
{
foreach (SceneObjectGroup obj in primsOverMe)
{
if (obj.OwnerID != m_landData.OwnerID &&
(obj.GroupID != m_landData.GroupID ||
m_landData.GroupID == UUID.Zero))
{
if (!returns.ContainsKey(obj.OwnerID))
returns[obj.OwnerID] =
new List<SceneObjectGroup>();
returns[obj.OwnerID].Add(obj);
}
}
}
else if (type == (uint)ObjectReturnType.List)
{
List<UUID> ownerlist = new List<UUID>(owners);
foreach (SceneObjectGroup obj in primsOverMe)
{
if (ownerlist.Contains(obj.OwnerID))
{
if (!returns.ContainsKey(obj.OwnerID))
returns[obj.OwnerID] =
new List<SceneObjectGroup>();
returns[obj.OwnerID].Add(obj);
}
}
}
}
foreach (List<SceneObjectGroup> ol in returns.Values)
{
if (m_scene.Permissions.CanReturnObjects(this, remote_client.AgentId, ol))
m_scene.returnObjects(ol.ToArray(), remote_client.AgentId);
}
}
#endregion
#region Object Adding/Removing from Parcel
public void ResetOverMeRecord()
{
lock (primsOverMe)
primsOverMe.Clear();
}
public void AddPrimOverMe(SceneObjectGroup obj)
{
lock (primsOverMe)
primsOverMe.Add(obj);
}
public void RemovePrimFromOverMe(SceneObjectGroup obj)
{
lock (primsOverMe)
primsOverMe.Remove(obj);
}
#endregion
/// <summary>
/// Set the media url for this land parcel
/// </summary>
/// <param name="url"></param>
public void SetMediaUrl(string url)
{
LandData.MediaURL = url;
SendLandUpdateToAvatarsOverMe();
}
/// <summary>
/// Set the music url for this land parcel
/// </summary>
/// <param name="url"></param>
public void SetMusicUrl(string url)
{
LandData.MusicURL = url;
SendLandUpdateToAvatarsOverMe();
}
#endregion
}
}
|