Skip to content

Commit

Permalink
* Fixing TestClient commands to use new ObjectPrimitives signature
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamFrisby committed Aug 16, 2024
1 parent 064ad1b commit 24cc6eb
Show file tree
Hide file tree
Showing 30 changed files with 242 additions and 229 deletions.
15 changes: 3 additions & 12 deletions Programs/examples/TestClient/Commands/Agent/BotsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,23 @@ private void Avatars_ViewerEffectPointAt(object sender, ViewerEffectPointAtEvent
{
lock (m_AgentList)
{
if (m_AgentList.ContainsKey(e.SourceID))
m_AgentList[e.SourceID] = true;
else
m_AgentList.Add(e.SourceID, true);
m_AgentList[e.SourceID] = true;
}
}

private void Avatars_ViewerEffectLookAt(object sender, ViewerEffectLookAtEventArgs e)
{
lock (m_AgentList)
{
if (m_AgentList.ContainsKey(e.SourceID))
m_AgentList[e.SourceID] = true;
else
m_AgentList.Add(e.SourceID, true);
m_AgentList[e.SourceID] = true;
}
}

private void Avatars_ViewerEffect(object sender, ViewerEffectEventArgs e)
{
lock (m_AgentList)
{
if (m_AgentList.ContainsKey(e.SourceID))
m_AgentList[e.SourceID] = true;
else
m_AgentList.Add(e.SourceID, true);
m_AgentList[e.SourceID] = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public PlayAnimationCommand(TestClient testClient)

private string Usage()
{
string usage = "Usage:\n" +
"\tplay list - list the built in animations\n" +
"\tplay show - show any currently playing animations\n" +
"\tplay UUID - play an animation asset\n" +
"\tplay ANIMATION - where ANIMATION is one of the values returned from \"play list\"\n";
const string usage = "Usage:\n" +
"\tplay list - list the built in animations\n" +
"\tplay show - show any currently playing animations\n" +
"\tplay UUID - play an animation asset\n" +
"\tplay ANIMATION - where ANIMATION is one of the values returned from \"play list\"\n";
return usage;
}

Expand Down
14 changes: 9 additions & 5 deletions Programs/examples/TestClient/Commands/Agent/TouchCommand.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Linq;

namespace OpenMetaverse.TestClient
{
public class TouchCommand: Command
Expand All @@ -18,14 +20,16 @@ public override string Execute(string[] args, UUID fromAgentID)

if (UUID.TryParse(args[0], out target))
{
Primitive targetPrim = Client.Network.CurrentSim.ObjectsPrimitives.Find(
prim => prim.ID == target
var targetPrim = Client.Network.CurrentSim.ObjectsPrimitives.FirstOrDefault(
prim => prim.Value.ID == target
);

if (targetPrim != null)
var primitive = targetPrim.Value;

if (primitive != null)
{
Client.Self.Touch(targetPrim.LocalID);
return "Touched prim " + targetPrim.LocalID;
Client.Self.Touch(primitive.LocalID);
return "Touched prim " + primitive.LocalID;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace OpenMetaverse.TestClient
{
Expand All @@ -15,9 +16,12 @@ public AttachmentsCommand(TestClient testClient)

public override string Execute(string[] args, UUID fromAgentID)
{
List<Primitive> attachments = Client.Network.CurrentSim.ObjectsPrimitives.FindAll(
prim => prim.ParentID == Client.Self.LocalID
);
var attachments = Client.Network.CurrentSim.ObjectsPrimitives
.Where(
prim => prim.Value.ParentID == Client.Self.LocalID
)
.Select(i => i.Value)
.ToList();

foreach (var prim in attachments)
{
Expand Down
12 changes: 5 additions & 7 deletions Programs/examples/TestClient/Commands/Communication/IMCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace OpenMetaverse.TestClient
Expand Down Expand Up @@ -56,14 +57,11 @@ public override string Execute(string[] args, UUID fromAgentID)

void Avatars_AvatarPickerReply(object sender, AvatarPickerReplyEventArgs e)
{
foreach (KeyValuePair<UUID, string> kvp in e.Avatars)
foreach (var kvp in e.Avatars.Where(kvp => string.Equals(kvp.Value, ToAvatarName, StringComparison.CurrentCultureIgnoreCase)))
{
if (kvp.Value.ToLower() == ToAvatarName.ToLower())
{
Name2Key[ToAvatarName.ToLower()] = kvp.Key;
NameSearchEvent.Set();
return;
}
Name2Key[ToAvatarName.ToLower()] = kvp.Key;
NameSearchEvent.Set();
return;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
using System.Text;
/*
* Copyright (c) 2006-2016, openmetaverse.co
* All rights reserved.
*
* - 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.
* - Neither the name of the openmetaverse.co 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 COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR 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.Text;

namespace OpenMetaverse.TestClient.Commands
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void Directory_DirGroups(object sender, DirGroupsReplyEventArgs e)
Console.WriteLine(groupRetrieved.GroupName + "\t\t\t(" +
Name + " UUID " + groupRetrieved.GroupID + ")");

if (groupRetrieved.GroupName.ToLower() == groupName.ToLower())
if (string.Equals(groupRetrieved.GroupName, groupName, StringComparison.CurrentCultureIgnoreCase))
{
resolvedGroupID = groupRetrieved.GroupID;
resolvedGroupName = groupRetrieved.GroupName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,9 @@ void bwBackup_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)

private void bwBackup_DoWork(object sender, DoWorkEventArgs e)
{
string[] args;

TextItemsFound = 0;

args = (string[])e.Argument;
var args = (string[])e.Argument;

lock (CurrentDownloads) CurrentDownloads.Clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ public override string Execute(string[] args, UUID fromAgentID)

if (DownloadHandle.WaitOne(120 * 1000, false))
{
if (Success)
return $"Saved {AssetID}.{assetType.ToString().ToLower()}";
else
return $"Failed to download asset {AssetID}, perhaps {assetType} is the incorrect asset type?";
return Success ? $"Saved {AssetID}.{assetType.ToString().ToLower()}"
: $"Failed to download asset {AssetID}, perhaps {assetType} is the incorrect asset type?";
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (c) 2006-2016, openmetaverse.co
* Copyright (c) 2021-2022, Sjofn LLC.
* All rights reserved.
Expand Down Expand Up @@ -29,7 +29,12 @@
using System.Text;
using System.IO;
using System.Collections.Generic;
using CSJ2K;
using OpenMetaverse.Assets;
using OpenMetaverse.Imaging;
using Pfim;
using SkiaSharp;
using Targa = OpenMetaverse.Imaging.Targa;

namespace OpenMetaverse.TestClient
{
Expand Down Expand Up @@ -114,15 +119,15 @@ private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asse
try
{
File.WriteAllBytes(assetTexture.AssetID + ".jp2", assetTexture.AssetData);
Console.WriteLine("Wrote JPEG2000 image " + assetTexture.AssetID + ".jp2");
Console.WriteLine($"Wrote JPEG2000 image {assetTexture.AssetID}.jp2");

using (var reader = new OpenJpegDotNet.IO.Reader(assetTexture.AssetData))
using (var bitmap = J2kImage.FromBytes(assetTexture.AssetData).As<SKBitmap>())
{
reader.ReadHeader();
OpenJpegDotNet.RawImage tga = reader.Decode().ToTarga();
File.WriteAllBytes(assetTexture.AssetID + ".tga", tga.Bytes);
var mi = new ManagedImage(bitmap);
var bytes = Targa.Encode(mi);
File.WriteAllBytes(assetTexture.AssetID + ".tga", bytes);
Console.WriteLine($"Wrote TGA image {assetTexture.AssetID}.tga");
}
Console.WriteLine("Wrote TGA image " + assetTexture.AssetID + ".tga");
}
catch (Exception e)
{
Expand All @@ -131,7 +136,7 @@ private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asse
}
else
{
Console.WriteLine("Failed to download image " + assetTexture.AssetID);
Console.WriteLine($"Failed to download image {assetTexture.AssetID}");
}

OutfitAssets.Remove(assetTexture.AssetID);
Expand Down
24 changes: 10 additions & 14 deletions Programs/examples/TestClient/Commands/Inventory/GiveItemCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public override string Execute(string[] args, UUID fromAgentID)
Manager = Client.Inventory;
Inventory = Manager.Store;
string ret = "";
string nl = "\n";

string target = args.Aggregate(string.Empty, (current, t) => current + t + " ");
target = target.TrimEnd();
Expand All @@ -37,24 +36,21 @@ public override string Execute(string[] args, UUID fromAgentID)
// WARNING: Uses local copy of inventory contents, need to download them first.
List<InventoryBase> contents = Inventory.GetContents(Client.CurrentDirectory);
bool found = false;
foreach (InventoryBase b in contents)
foreach (var b in contents.Where(b => inventoryName == b.Name || inventoryName == b.UUID.ToString()))
{
if (inventoryName == b.Name || inventoryName == b.UUID.ToString())
found = true;
if (b is InventoryItem item)
{
found = true;
if (b is InventoryItem item)
{
Manager.GiveItem(item.UUID, item.Name, item.AssetType, dest, true);
ret += "Gave " + item.Name + " (" + item.AssetType + ")" + nl;
}
else
{
ret += "Unable to give folder " + b.Name + nl;
}
Manager.GiveItem(item.UUID, item.Name, item.AssetType, dest, true);
ret += "Gave " + item.Name + " (" + item.AssetType + ")" + '\n';
}
else
{
ret += "Unable to give folder " + b.Name + '\n';
}
}
if (!found)
ret += "No inventory item named " + inventoryName + " found." + nl;
ret += "No inventory item named " + inventoryName + " found." + '\n';

return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public override string Execute(string[] args, UUID fromAgentID)
// WARNING: Uses local copy of inventory contents, need to download them first.
List<InventoryBase> contents = Inventory.GetContents(Client.CurrentDirectory);
string displayString = "";
string nl = "\n"; // New line character
// Pretty simple, just print out the contents.
foreach (InventoryBase b in contents)
{
Expand All @@ -49,15 +48,15 @@ public override string Execute(string[] args, UUID fromAgentID)
displayString += PermMaskString(item.Permissions.EveryoneMask);
displayString += " " + item.UUID;
displayString += " " + item.Name;
displayString += nl;
displayString += '\n';
displayString += " AssetID: " + item.AssetUUID;
}
}
else
{
displayString += b.Name;
}
displayString += nl;
displayString += '\n';
}
return displayString;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace OpenMetaverse.TestClient
{
Expand All @@ -22,11 +23,16 @@ public override string Execute(string[] args, UUID fromAgentID)
if (!UUID.TryParse(args[0], out objectID))
return "Usage: objectinventory [objectID]";

Primitive found = Client.Network.CurrentSim.ObjectsPrimitives.Find(prim => prim.ID == objectID);
if (found != null)
objectLocalID = found.LocalID;
var found = Client.Network.CurrentSim.ObjectsPrimitives.FirstOrDefault(prim => prim.Value.ID == objectID);

if (found.Value != null)
{
objectLocalID = found.Value.LocalID;
}
else
{
return "Couldn't find prim " + objectID;
}

List<InventoryBase> items = Client.Inventory.GetTaskInventory(objectID, objectLocalID, 1000 * 30);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace OpenMetaverse.TestClient
Expand All @@ -24,11 +25,15 @@ public override string Execute(string[] args, UUID fromAgentID)
if (!UUID.TryParse(args[0], out objectID))
return "Usage: taskrunning objectID [[scriptName] true|false]";

Primitive found = Client.Network.CurrentSim.ObjectsPrimitives.Find(prim => prim.ID == objectID);
if (found != null)
objectLocalID = found.LocalID;
var found = Client.Network.CurrentSim.ObjectsPrimitives.FirstOrDefault(prim => prim.Value.ID == objectID);
if (found.Value != null)
{
objectLocalID = found.Value.LocalID;
}
else
{
return $"Couldn't find prim {objectID}";
}

List<InventoryBase> items = Client.Inventory.GetTaskInventory(objectID, objectLocalID, 1000 * 30);

Expand Down
Loading

0 comments on commit 24cc6eb

Please sign in to comment.