From 17f56ccbdc5e2fa9493f2ccf7597b6cd1f26a72d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey Date: Wed, 18 Jun 2014 17:56:13 +0100 Subject: [PATCH] Add sendgeneric command to TestClient to allow one to send arbitrary GenericMessagePackets to the simulator for testing purposes --- .../Commands/Agent/GenericMessageCommand.cs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Programs/examples/TestClient/Commands/Agent/GenericMessageCommand.cs diff --git a/Programs/examples/TestClient/Commands/Agent/GenericMessageCommand.cs b/Programs/examples/TestClient/Commands/Agent/GenericMessageCommand.cs new file mode 100644 index 00000000..035ea348 --- /dev/null +++ b/Programs/examples/TestClient/Commands/Agent/GenericMessageCommand.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using OpenMetaverse.Packets; + +namespace OpenMetaverse.TestClient +{ + /// + /// Sends a packet of type GenericMessage to the simulator. + /// + public class GenericMessageCommand : Command + { + public GenericMessageCommand(TestClient testClient) + { + Name = "sendgeneric"; + Description = "send a generic UDP message to the simulator."; + Category = CommandCategory.Other; + } + + public override string Execute(string[] args, UUID fromAgentID) + { + UUID target; + + if (args.Length < 1) + return "Usage: sendgeneric method_name [value1 value2 ...]"; + + string methodName = args[0]; + + GenericMessagePacket gmp = new GenericMessagePacket(); + + gmp.AgentData.AgentID = Client.Self.AgentID; + gmp.AgentData.SessionID = Client.Self.SessionID; + gmp.AgentData.TransactionID = UUID.Zero; + + gmp.MethodData.Method = Utils.StringToBytes(methodName); + gmp.MethodData.Invoice = UUID.Zero; + + gmp.ParamList = new GenericMessagePacket.ParamListBlock[args.Length - 1]; + + StringBuilder sb = new StringBuilder(); + + for (int i = 1; i < args.Length; i++) + { + GenericMessagePacket.ParamListBlock paramBlock = new GenericMessagePacket.ParamListBlock(); + paramBlock.Parameter = Utils.StringToBytes(args[i]); + gmp.ParamList[i - 1] = paramBlock; + sb.AppendFormat(" {0}", args[i]); + } + + Client.Network.SendPacket(gmp); + + return string.Format("Sent generic message with method {0}, params{1}", methodName, sb); + } + } +} \ No newline at end of file