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
|
/*
* 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.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using log4net;
using Mono.Addins;
using NDesk.Options;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Framework.Monitoring;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.Framework.Scenes.Serialization;
namespace OpenSim.Region.CoreModules.World.Objects.Commands
{
/// <summary>
/// A module that holds commands for manipulating objects in the scene.
/// </summary>
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ObjectCommandsModule")]
public class ObjectCommandsModule : INonSharedRegionModule
{
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private Scene m_scene;
private ICommandConsole m_console;
public string Name { get { return "Object Commands Module"; } }
public Type ReplaceableInterface { get { return null; } }
public void Initialise(IConfigSource source)
{
// m_log.DebugFormat("[OBJECT COMMANDS MODULE]: INITIALIZED MODULE");
}
public void PostInitialise()
{
// m_log.DebugFormat("[OBJECT COMMANDS MODULE]: POST INITIALIZED MODULE");
}
public void Close()
{
// m_log.DebugFormat("[OBJECT COMMANDS MODULE]: CLOSED MODULE");
}
public void AddRegion(Scene scene)
{
// m_log.DebugFormat("[OBJECT COMMANDS MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
m_scene = scene;
m_console = MainConsole.Instance;
m_console.Commands.AddCommand(
"Objects", false, "delete object owner",
"delete object owner <UUID>",
"Delete scene objects by owner",
"Command will ask for confirmation before proceeding.",
HandleDeleteObject);
m_console.Commands.AddCommand(
"Objects", false, "delete object creator",
"delete object creator <UUID>",
"Delete scene objects by creator",
"Command will ask for confirmation before proceeding.",
HandleDeleteObject);
m_console.Commands.AddCommand(
"Objects", false, "delete object id",
"delete object id <UUID-or-localID>",
"Delete a scene object by uuid or localID",
HandleDeleteObject);
m_console.Commands.AddCommand(
"Objects", false, "delete object name",
"delete object name [--regex] <name>",
"Delete a scene object by name.",
"Command will ask for confirmation before proceeding.\n"
+ "If --regex is specified then the name is treatead as a regular expression",
HandleDeleteObject);
m_console.Commands.AddCommand(
"Objects", false, "delete object outside",
"delete object outside",
"Delete all scene objects outside region boundaries",
"Command will ask for confirmation before proceeding.",
HandleDeleteObject);
m_console.Commands.AddCommand(
"Objects",
false,
"delete object pos",
"delete object pos <start-coord> to <end-coord>",
"Delete scene objects within the given area.",
ConsoleUtil.CoordHelp,
HandleDeleteObject);
m_console.Commands.AddCommand(
"Objects",
false,
"show object id",
"show object id [--full] <UUID-or-localID>",
"Show details of a scene object with the given UUID or localID",
"The --full option will print out information on all the parts of the object.\n"
+ "For yet more detailed part information, use the \"show part\" commands.",
HandleShowObjectById);
m_console.Commands.AddCommand(
"Objects",
false,
"show object name",
"show object name [--full] [--regex] <name>",
"Show details of scene objects with the given name.",
"The --full option will print out information on all the parts of the object.\n"
+ "For yet more detailed part information, use the \"show part\" commands.\n"
+ "If --regex is specified then the name is treatead as a regular expression.",
HandleShowObjectByName);
m_console.Commands.AddCommand(
"Objects",
false,
"show object pos",
"show object pos [--full] <start-coord> to <end-coord>",
"Show details of scene objects within the given area.",
"The --full option will print out information on all the parts of the object.\n"
+ "For yet more detailed part information, use the \"show part\" commands.\n"
+ ConsoleUtil.CoordHelp,
HandleShowObjectByPos);
m_console.Commands.AddCommand(
"Objects",
false,
"show part id",
"show part id <UUID-or-localID>",
"Show details of a scene object part with the given UUID or localID", HandleShowPartById);
m_console.Commands.AddCommand(
"Objects",
false,
"show part name",
"show part name [--regex] <name>",
"Show details of scene object parts with the given name.",
"If --regex is specified then the name is treated as a regular expression",
HandleShowPartByName);
m_console.Commands.AddCommand(
"Objects",
false,
"show part pos",
"show part pos <start-coord> to <end-coord>",
"Show details of scene object parts within the given area.",
ConsoleUtil.CoordHelp,
HandleShowPartByPos);
m_console.Commands.AddCommand(
"Objects",
false,
"dump object id",
"dump object id <UUID-or-localID>",
"Dump the formatted serialization of the given object to the file <UUID>.xml",
"e.g. dump object uuid c1ed6809-cc24-4061-a4c2-93082a2d1f1d will dump serialization to c1ed6809-cc24-4061-a4c2-93082a2d1f1d.xml\n"
+ "To locate the UUID or localID in the first place, you need to use the other show object commands.\n"
+ "If a local ID is given then the filename used is still that for the UUID",
HandleDumpObjectById);
}
public void RemoveRegion(Scene scene)
{
// m_log.DebugFormat("[OBJECTS COMMANDS MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
}
public void RegionLoaded(Scene scene)
{
// m_log.DebugFormat("[OBJECTS COMMANDS MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
}
/// <summary>
/// Outputs the sogs to console.
/// </summary>
/// <param name='searchPredicate'></param>
/// <param name='showFull'>If true then output all part details. If false then output summary.</param>
private void OutputSogsToConsole(Predicate<SceneObjectGroup> searchPredicate, bool showFull)
{
List<SceneObjectGroup> sceneObjects = m_scene.GetSceneObjectGroups().FindAll(searchPredicate);
StringBuilder sb = new StringBuilder();
foreach (SceneObjectGroup so in sceneObjects)
{
AddSceneObjectReport(sb, so, showFull);
sb.Append("\n");
}
sb.AppendFormat("{0} object(s) found in {1}\n", sceneObjects.Count, m_scene.Name);
m_console.OutputFormat(sb.ToString());
}
private void OutputSopsToConsole(Predicate<SceneObjectPart> searchPredicate, bool showFull)
{
List<SceneObjectGroup> sceneObjects = m_scene.GetSceneObjectGroups();
List<SceneObjectPart> parts = new List<SceneObjectPart>();
sceneObjects.ForEach(so => parts.AddRange(Array.FindAll<SceneObjectPart>(so.Parts, searchPredicate)));
StringBuilder sb = new StringBuilder();
foreach (SceneObjectPart part in parts)
{
AddScenePartReport(sb, part, showFull);
sb.Append("\n");
}
sb.AppendFormat("{0} parts found in {1}\n", parts.Count, m_scene.Name);
m_console.OutputFormat(sb.ToString());
}
private void HandleShowObjectById(string module, string[] cmdparams)
{
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
return;
bool showFull = false;
OptionSet options = new OptionSet().Add("full", v => showFull = v != null );
List<string> mainParams = options.Parse(cmdparams);
if (mainParams.Count < 4)
{
m_console.OutputFormat("Usage: show object uuid <uuid>");
return;
}
UUID uuid;
uint localId;
if (!ConsoleUtil.TryParseConsoleId(m_console, mainParams[3], out uuid, out localId))
return;
SceneObjectGroup so;
if (localId != ConsoleUtil.LocalIdNotFound)
so = m_scene.GetSceneObjectGroup(localId);
else
so = m_scene.GetSceneObjectGroup(uuid);
if (so == null)
{
// m_console.OutputFormat("No part found with uuid {0}", objectUuid);
return;
}
StringBuilder sb = new StringBuilder();
AddSceneObjectReport(sb, so, showFull);
m_console.OutputFormat(sb.ToString());
}
private void HandleShowObjectByName(string module, string[] cmdparams)
{
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
return;
bool showFull = false;
bool useRegex = false;
OptionSet options = new OptionSet();
options.Add("full", v => showFull = v != null );
options.Add("regex", v => useRegex = v != null );
List<string> mainParams = options.Parse(cmdparams);
if (mainParams.Count < 4)
{
m_console.OutputFormat("Usage: show object name [--full] [--regex] <name>");
return;
}
string name = mainParams[3];
Predicate<SceneObjectGroup> searchPredicate;
if (useRegex)
{
Regex nameRegex = new Regex(name);
searchPredicate = so => nameRegex.IsMatch(so.Name);
}
else
{
searchPredicate = so => so.Name == name;
}
OutputSogsToConsole(searchPredicate, showFull);
}
private void HandleShowObjectByPos(string module, string[] cmdparams)
{
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
return;
bool showFull = false;
OptionSet options = new OptionSet().Add("full", v => showFull = v != null );
List<string> mainParams = options.Parse(cmdparams);
if (mainParams.Count < 5)
{
m_console.OutputFormat("Usage: show object pos [--full] <start-coord> to <end-coord>");
return;
}
Vector3 startVector, endVector;
if (!TryParseVectorRange(cmdparams.Skip(3).Take(3), out startVector, out endVector))
return;
Predicate<SceneObjectGroup> searchPredicate
= so => Util.IsInsideBox(so.AbsolutePosition, startVector, endVector);
OutputSogsToConsole(searchPredicate, showFull);
}
private void HandleShowPartById(string module, string[] cmdparams)
{
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
return;
// bool showFull = false;
OptionSet options = new OptionSet();
// options.Add("full", v => showFull = v != null );
List<string> mainParams = options.Parse(cmdparams);
if (mainParams.Count < 4)
{
//m_console.OutputFormat("Usage: show part id [--full] <UUID-or-localID>");
m_console.OutputFormat("Usage: show part id <UUID-or-localID>");
return;
}
UUID objectUuid;
uint localId;
if (!ConsoleUtil.TryParseConsoleId(m_console, mainParams[3], out objectUuid, out localId))
return;
SceneObjectPart sop;
if (localId == ConsoleUtil.LocalIdNotFound)
sop = m_scene.GetSceneObjectPart(objectUuid);
else
sop = m_scene.GetSceneObjectPart(localId);
if (sop == null)
{
// m_console.OutputFormat("No part found with uuid {0}", objectUuid);
return;
}
StringBuilder sb = new StringBuilder();
AddScenePartReport(sb, sop, true);
m_console.OutputFormat(sb.ToString());
}
private void HandleShowPartByPos(string module, string[] cmdparams)
{
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
return;
// bool showFull = false;
OptionSet options = new OptionSet();
// options.Add("full", v => showFull = v != null );
List<string> mainParams = options.Parse(cmdparams);
if (mainParams.Count < 5)
{
//m_console.OutputFormat("Usage: show part pos <start-coord> to <end-coord>");
m_console.OutputFormat("Usage: show part pos [--full] <start-coord> to <end-coord>");
return;
}
string rawConsoleStartVector = mainParams[3];
Vector3 startVector;
if (!ConsoleUtil.TryParseConsoleMinVector(rawConsoleStartVector, out startVector))
{
m_console.OutputFormat("Error: Start vector '{0}' does not have a valid format", rawConsoleStartVector);
return;
}
string rawConsoleEndVector = mainParams[5];
Vector3 endVector;
if (!ConsoleUtil.TryParseConsoleMaxVector(rawConsoleEndVector, out endVector))
{
m_console.OutputFormat("Error: End vector '{0}' does not have a valid format", rawConsoleEndVector);
return;
}
OutputSopsToConsole(sop => Util.IsInsideBox(sop.AbsolutePosition, startVector, endVector), true);
}
private void HandleShowPartByName(string module, string[] cmdparams)
{
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
return;
// bool showFull = false;
bool useRegex = false;
OptionSet options = new OptionSet();
// options.Add("full", v => showFull = v != null );
options.Add("regex", v => useRegex = v != null );
List<string> mainParams = options.Parse(cmdparams);
if (mainParams.Count < 4)
{
m_console.OutputFormat("Usage: show part name [--regex] <name>");
//m_console.OutputFormat("Usage: show part name [--full] [--regex] <name>");
return;
}
string name = mainParams[3];
Predicate<SceneObjectPart> searchPredicate;
if (useRegex)
{
Regex nameRegex = new Regex(name);
searchPredicate = sop => nameRegex.IsMatch(sop.Name);
}
else
{
searchPredicate = sop => sop.Name == name;
}
OutputSopsToConsole(searchPredicate, true);
}
private void HandleDumpObjectById(string module, string[] cmdparams)
{
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
return;
if (cmdparams.Length < 4)
{
m_console.OutputFormat("Usage: dump object id <UUID-or-localID>");
return;
}
UUID objectUuid;
uint localId;
if (!ConsoleUtil.TryParseConsoleId(m_console, cmdparams[3], out objectUuid, out localId))
return;
SceneObjectGroup so;
if (localId == ConsoleUtil.LocalIdNotFound)
so = m_scene.GetSceneObjectGroup(objectUuid);
else
so = m_scene.GetSceneObjectGroup(localId);
if (so == null)
{
// m_console.OutputFormat("No part found with uuid {0}", objectUuid);
return;
}
// In case we found it via local ID.
objectUuid = so.UUID;
string fileName = string.Format("{0}.xml", objectUuid);
if (!ConsoleUtil.CheckFileDoesNotExist(m_console, fileName))
return;
using (XmlTextWriter xtw = new XmlTextWriter(fileName, Encoding.UTF8))
{
xtw.Formatting = Formatting.Indented;
SceneObjectSerializer.ToOriginalXmlFormat(so, xtw, true);
}
m_console.OutputFormat("Object dumped to file {0}", fileName);
}
/// <summary>
/// Append a scene object report to an input StringBuilder
/// </summary>
/// <returns></returns>
/// <param name='sb'></param>
/// <param name='so'</param>
/// <param name='showFull'>
/// If true then information on all parts of an object is appended.
/// If false then only summary information about an object is appended.
/// </param>
private StringBuilder AddSceneObjectReport(StringBuilder sb, SceneObjectGroup so, bool showFull)
{
if (showFull)
{
foreach (SceneObjectPart sop in so.Parts)
{
AddScenePartReport(sb, sop, false);
sb.Append("\n");
}
}
else
{
AddSummarySceneObjectReport(sb, so);
}
return sb;
}
private StringBuilder AddSummarySceneObjectReport(StringBuilder sb, SceneObjectGroup so)
{
ConsoleDisplayList cdl = new ConsoleDisplayList();
cdl.AddRow("Name", so.Name);
cdl.AddRow("Description", so.Description);
cdl.AddRow("Local ID", so.LocalId);
cdl.AddRow("UUID", so.UUID);
cdl.AddRow("Location", string.Format("{0} @ {1}", so.AbsolutePosition, so.Scene.Name));
cdl.AddRow("Parts", so.PrimCount);
cdl.AddRow("Flags", so.RootPart.Flags);
return sb.Append(cdl.ToString());
}
/// <summary>
/// Append a scene object part report to an input StringBuilder
/// </summary>
/// <returns></returns>
/// <param name='sb'></param>
/// <param name='sop'</param>
/// <param name='showFull'>
/// If true then information on each inventory item will be shown.
/// If false then only summary inventory information is shown.
/// </param>
private StringBuilder AddScenePartReport(StringBuilder sb, SceneObjectPart sop, bool showFull)
{
ConsoleDisplayList cdl = new ConsoleDisplayList();
cdl.AddRow("Name", sop.Name);
cdl.AddRow("Description", sop.Description);
cdl.AddRow("Local ID", sop.LocalId);
cdl.AddRow("UUID", sop.UUID);
cdl.AddRow("Location", string.Format("{0} @ {1}", sop.AbsolutePosition, sop.ParentGroup.Scene.Name));
cdl.AddRow(
"Parent",
sop.IsRoot ? "Is Root" : string.Format("{0} {1}", sop.ParentGroup.Name, sop.ParentGroup.UUID));
cdl.AddRow("Link number", sop.LinkNum);
cdl.AddRow("Flags", sop.Flags);
if (showFull)
{
PrimitiveBaseShape s = sop.Shape;
cdl.AddRow("FlexiDrag", s.FlexiDrag);
cdl.AddRow("FlexiEntry", s.FlexiEntry);
cdl.AddRow("FlexiForce", string.Format("<{0},{1},{2}>", s.FlexiForceX, s.FlexiForceY, s.FlexiForceZ));
cdl.AddRow("FlexiGravity", s.FlexiGravity);
cdl.AddRow("FlexiSoftness", s.FlexiSoftness);
cdl.AddRow("HollowShape", s.HollowShape);
cdl.AddRow(
"LightColor",
string.Format("<{0},{1},{2},{3}>", s.LightColorR, s.LightColorB, s.LightColorG, s.LightColorA));
cdl.AddRow("LightCutoff", s.LightCutoff);
cdl.AddRow("LightEntry", s.LightEntry);
cdl.AddRow("LightFalloff", s.LightFalloff);
cdl.AddRow("LightIntensity", s.LightIntensity);
cdl.AddRow("LightRadius", s.LightRadius);
cdl.AddRow("Location (relative)", sop.RelativePosition);
cdl.AddRow("Media", string.Format("{0} entries", s.Media != null ? s.Media.Count.ToString() : "n/a"));
cdl.AddRow("PathBegin", s.PathBegin);
cdl.AddRow("PathEnd", s.PathEnd);
cdl.AddRow("PathCurve", s.PathCurve);
cdl.AddRow("PathRadiusOffset", s.PathRadiusOffset);
cdl.AddRow("PathRevolutions", s.PathRevolutions);
cdl.AddRow("PathScale", string.Format("<{0},{1}>", s.PathScaleX, s.PathScaleY));
cdl.AddRow("PathSkew", string.Format("<{0},{1}>", s.PathShearX, s.PathShearY));
cdl.AddRow("FlexiDrag", s.PathSkew);
cdl.AddRow("PathTaper", string.Format("<{0},{1}>", s.PathTaperX, s.PathTaperY));
cdl.AddRow("PathTwist", s.PathTwist);
cdl.AddRow("PathTwistBegin", s.PathTwistBegin);
cdl.AddRow("PCode", s.PCode);
cdl.AddRow("ProfileBegin", s.ProfileBegin);
cdl.AddRow("ProfileEnd", s.ProfileEnd);
cdl.AddRow("ProfileHollow", s.ProfileHollow);
cdl.AddRow("ProfileShape", s.ProfileShape);
cdl.AddRow("ProjectionAmbiance", s.ProjectionAmbiance);
cdl.AddRow("ProjectionEntry", s.ProjectionEntry);
cdl.AddRow("ProjectionFocus", s.ProjectionFocus);
cdl.AddRow("ProjectionFOV", s.ProjectionFOV);
cdl.AddRow("ProjectionTextureUUID", s.ProjectionTextureUUID);
cdl.AddRow("Rotation (Relative)", sop.RotationOffset);
cdl.AddRow("Rotation (World)", sop.GetWorldRotation());
cdl.AddRow("Scale", s.Scale);
cdl.AddRow(
"SculptData",
string.Format("{0} bytes", s.SculptData != null ? s.SculptData.Length.ToString() : "n/a"));
cdl.AddRow("SculptEntry", s.SculptEntry);
cdl.AddRow("SculptTexture", s.SculptTexture);
cdl.AddRow("SculptType", s.SculptType);
cdl.AddRow("State", s.State);
// TODO, need to display more information about textures but in a compact format
// to stop output becoming huge.
for (int i = 0; i < sop.GetNumberOfSides(); i++)
{
Primitive.TextureEntryFace teFace = s.Textures.FaceTextures[i];
UUID textureID;
if (teFace != null)
textureID = teFace.TextureID;
else
textureID = s.Textures.DefaultTexture.TextureID;
cdl.AddRow(string.Format("Face {0} texture ID", i), textureID);
}
//cdl.AddRow("Textures", string.Format("{0} entries", s.Textures.
}
object itemsOutput;
if (showFull)
{
StringBuilder itemsSb = new StringBuilder("\n");
itemsOutput = AddScenePartItemsReport(itemsSb, sop.Inventory).ToString();
}
else
{
itemsOutput = sop.Inventory.Count;
}
cdl.AddRow("Items", itemsOutput);
return sb.Append(cdl.ToString());
}
private StringBuilder AddScenePartItemsReport(StringBuilder sb, IEntityInventory inv)
{
ConsoleDisplayTable cdt = new ConsoleDisplayTable();
cdt.Indent = 2;
cdt.AddColumn("Name", 50);
cdt.AddColumn("Type", 12);
cdt.AddColumn("Running", 7);
cdt.AddColumn("Item UUID", 36);
cdt.AddColumn("Asset UUID", 36);
foreach (TaskInventoryItem item in inv.GetInventoryItems())
{
bool foundScriptInstance, scriptRunning;
foundScriptInstance
= SceneObjectPartInventory.TryGetScriptInstanceRunning(m_scene, item, out scriptRunning);
cdt.AddRow(
item.Name,
((InventoryType)item.InvType).ToString(),
foundScriptInstance ? scriptRunning.ToString() : "n/a",
item.ItemID.ToString(),
item.AssetID.ToString());
}
return sb.Append(cdt.ToString());
}
private void HandleDeleteObject(string module, string[] cmd)
{
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
return;
if (cmd.Length < 3)
return;
string mode = cmd[2];
string o = "";
if (mode != "outside")
{
if (cmd.Length < 4)
return;
o = cmd[3];
}
List<SceneObjectGroup> deletes = null;
UUID match;
bool requireConfirmation = true;
switch (mode)
{
case "owner":
if (!UUID.TryParse(o, out match))
return;
deletes = new List<SceneObjectGroup>();
m_scene.ForEachSOG(delegate (SceneObjectGroup g)
{
if (g.OwnerID == match && !g.IsAttachment)
deletes.Add(g);
});
// if (deletes.Count == 0)
// m_console.OutputFormat("No objects were found with owner {0}", match);
break;
case "creator":
if (!UUID.TryParse(o, out match))
return;
deletes = new List<SceneObjectGroup>();
m_scene.ForEachSOG(delegate (SceneObjectGroup g)
{
if (g.RootPart.CreatorID == match && !g.IsAttachment)
deletes.Add(g);
});
// if (deletes.Count == 0)
// m_console.OutputFormat("No objects were found with creator {0}", match);
break;
case "id":
UUID uuid;
uint localId;
if (!ConsoleUtil.TryParseConsoleId(m_console, o, out uuid, out localId))
return;
requireConfirmation = false;
deletes = new List<SceneObjectGroup>();
SceneObjectGroup so;
if (localId == ConsoleUtil.LocalIdNotFound)
so = m_scene.GetSceneObjectGroup(uuid);
else
so = m_scene.GetSceneObjectGroup(localId);
if (so!= null && !so.IsAttachment)
deletes.Add(so);
// if (deletes.Count == 0)
// m_console.OutputFormat("No objects were found with uuid {0}", match);
break;
case "name":
deletes = GetDeleteCandidatesByName(module, cmd);
break;
case "outside":
deletes = new List<SceneObjectGroup>();
m_scene.ForEachSOG(delegate (SceneObjectGroup g)
{
SceneObjectPart rootPart = g.RootPart;
bool delete = false;
if (rootPart.GroupPosition.Z < 0.0 || rootPart.GroupPosition.Z > 10000.0)
{
delete = true;
}
else
{
ILandObject parcel
= m_scene.LandChannel.GetLandObject(rootPart.GroupPosition.X, rootPart.GroupPosition.Y);
if (parcel == null || parcel.LandData.Name == "NO LAND")
delete = true;
}
if (delete && !g.IsAttachment && !deletes.Contains(g))
deletes.Add(g);
});
if (deletes.Count == 0)
m_console.OutputFormat("No objects were found outside region bounds");
break;
case "pos":
deletes = GetDeleteCandidatesByPos(module, cmd);
break;
default:
m_console.OutputFormat("Unrecognized mode {0}", mode);
return;
}
if (deletes == null || deletes.Count <= 0)
return;
if (requireConfirmation)
{
string response = MainConsole.Instance.CmdPrompt(
string.Format(
"Are you sure that you want to delete {0} objects from {1}",
deletes.Count, m_scene.RegionInfo.RegionName),
"y/N");
if (response.ToLower() != "y")
{
MainConsole.Instance.OutputFormat(
"Aborting delete of {0} objects from {1}", deletes.Count, m_scene.RegionInfo.RegionName);
return;
}
}
m_console.OutputFormat("Deleting {0} objects in {1}", deletes.Count, m_scene.RegionInfo.RegionName);
foreach (SceneObjectGroup g in deletes)
{
m_console.OutputFormat("Deleting object {0} {1}", g.UUID, g.Name);
m_scene.DeleteSceneObject(g, false);
}
}
private List<SceneObjectGroup> GetDeleteCandidatesByName(string module, string[] cmdparams)
{
bool useRegex = false;
OptionSet options = new OptionSet().Add("regex", v=> useRegex = v != null );
List<string> mainParams = options.Parse(cmdparams);
if (mainParams.Count < 4)
{
m_console.OutputFormat("Usage: delete object name [--regex] <name>");
return null;
}
string name = mainParams[3];
List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>();
Action<SceneObjectGroup> searchAction;
if (useRegex)
{
Regex nameRegex = new Regex(name);
searchAction = so => { if (nameRegex.IsMatch(so.Name)) { sceneObjects.Add(so); }};
}
else
{
searchAction = so => { if (so.Name == name) { sceneObjects.Add(so); }};
}
m_scene.ForEachSOG(searchAction);
if (sceneObjects.Count == 0)
m_console.OutputFormat("No objects with name {0} found in {1}", name, m_scene.RegionInfo.RegionName);
return sceneObjects;
}
/// <summary>
/// Get scene object delete candidates by position
/// </summary>
/// <param name='module'></param>
/// <param name='cmdparams'></param>
/// <returns>null if parsing failed on one of the arguments, otherwise a list of objects to delete. If there
/// are no objects to delete then the list will be empty./returns>
private List<SceneObjectGroup> GetDeleteCandidatesByPos(string module, string[] cmdparams)
{
if (cmdparams.Length < 5)
{
m_console.OutputFormat("Usage: delete object pos <start-coord> to <end-coord>");
return null;
}
Vector3 startVector, endVector;
if (!TryParseVectorRange(cmdparams.Skip(3).Take(3), out startVector, out endVector))
return null;
return m_scene.GetSceneObjectGroups().FindAll(
so => !so.IsAttachment && Util.IsInsideBox(so.AbsolutePosition, startVector, endVector));
}
private bool TryParseVectorRange(IEnumerable<string> rawComponents, out Vector3 startVector, out Vector3 endVector)
{
string rawConsoleStartVector = rawComponents.Take(1).Single();
if (!ConsoleUtil.TryParseConsoleMinVector(rawConsoleStartVector, out startVector))
{
m_console.OutputFormat("Error: Start vector '{0}' does not have a valid format", rawConsoleStartVector);
endVector = Vector3.Zero;
return false;
}
string rawConsoleEndVector = rawComponents.Skip(1).Take(1).Single();
if (!ConsoleUtil.TryParseConsoleMaxVector(rawConsoleEndVector, out endVector))
{
m_console.OutputFormat("Error: End vector '{0}' does not have a valid format", rawConsoleEndVector);
return false;
}
return true;
}
}
}
|