2007-04-28 20:54:02 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Xml;
|
2008-07-21 21:12:59 +00:00
|
|
|
using OpenMetaverse;
|
|
|
|
|
using OpenMetaverse.Packets;
|
|
|
|
|
using OpenMetaverse.Utilities;
|
2007-04-28 20:54:02 +00:00
|
|
|
|
2008-07-21 21:12:59 +00:00
|
|
|
namespace OpenMetaverse.TestClient
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2008-07-21 21:12:59 +00:00
|
|
|
public class TestClient : GridClient
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2008-07-25 05:15:05 +00:00
|
|
|
public UUID GroupID = UUID.Zero;
|
|
|
|
|
public Dictionary<UUID, GroupMember> GroupMembers;
|
2008-08-21 01:19:06 +00:00
|
|
|
public Dictionary<UUID, AvatarAppearancePacket> Appearances = new Dictionary<UUID, AvatarAppearancePacket>();
|
|
|
|
|
public Dictionary<string, Command> Commands = new Dictionary<string, Command>();
|
|
|
|
|
public bool Running = true;
|
2008-02-07 17:32:06 +00:00
|
|
|
public bool GroupCommands = false;
|
2007-04-28 20:54:02 +00:00
|
|
|
public string MasterName = String.Empty;
|
2008-07-25 05:15:05 +00:00
|
|
|
public UUID MasterKey = UUID.Zero;
|
2008-07-30 06:40:47 +00:00
|
|
|
public bool AllowObjectMaster = false;
|
2008-08-21 01:19:06 +00:00
|
|
|
public ClientManager ClientManager;
|
2008-04-09 20:02:07 +00:00
|
|
|
public VoiceManager VoiceManager;
|
2008-05-11 09:02:59 +00:00
|
|
|
// Shell-like inventory commands need to be aware of the 'current' inventory folder.
|
|
|
|
|
public InventoryFolder CurrentDirectory = null;
|
2007-04-28 20:54:02 +00:00
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
private Quaternion bodyRotation = Quaternion.Identity;
|
|
|
|
|
private Vector3 forward = new Vector3(0, 0.9999f, 0);
|
|
|
|
|
private Vector3 left = new Vector3(0.9999f, 0, 0);
|
|
|
|
|
private Vector3 up = new Vector3(0, 0, 0.9999f);
|
2007-04-28 20:54:02 +00:00
|
|
|
private System.Timers.Timer updateTimer;
|
2007-07-11 09:17:46 +00:00
|
|
|
|
2007-04-28 20:54:02 +00:00
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public TestClient(ClientManager manager)
|
|
|
|
|
{
|
2008-08-21 01:19:06 +00:00
|
|
|
ClientManager = manager;
|
2007-04-28 20:54:02 +00:00
|
|
|
|
2007-08-10 20:16:19 +00:00
|
|
|
updateTimer = new System.Timers.Timer(500);
|
2007-04-28 20:54:02 +00:00
|
|
|
updateTimer.Elapsed += new System.Timers.ElapsedEventHandler(updateTimer_Elapsed);
|
|
|
|
|
|
|
|
|
|
RegisterAllCommands(Assembly.GetExecutingAssembly());
|
|
|
|
|
|
2008-05-08 16:58:09 +00:00
|
|
|
Settings.LOG_LEVEL = Helpers.LogLevel.Debug;
|
2007-11-06 09:26:10 +00:00
|
|
|
Settings.LOG_RESENDS = false;
|
2007-04-28 20:54:02 +00:00
|
|
|
Settings.STORE_LAND_PATCHES = true;
|
2007-08-20 09:26:21 +00:00
|
|
|
Settings.ALWAYS_DECODE_OBJECTS = true;
|
2007-04-28 20:54:02 +00:00
|
|
|
Settings.ALWAYS_REQUEST_OBJECTS = true;
|
2007-08-10 20:16:19 +00:00
|
|
|
Settings.SEND_AGENT_UPDATES = true;
|
2008-04-07 15:10:01 +00:00
|
|
|
Settings.USE_TEXTURE_CACHE = true;
|
2007-04-28 20:54:02 +00:00
|
|
|
|
|
|
|
|
Network.RegisterCallback(PacketType.AgentDataUpdate, new NetworkManager.PacketCallback(AgentDataUpdateHandler));
|
2008-05-11 09:02:59 +00:00
|
|
|
Network.OnLogin += new NetworkManager.LoginCallback(LoginHandler);
|
2007-11-06 09:26:10 +00:00
|
|
|
Self.OnInstantMessage += new AgentManager.InstantMessageCallback(Self_OnInstantMessage);
|
2007-04-28 20:54:02 +00:00
|
|
|
Groups.OnGroupMembers += new GroupManager.GroupMembersCallback(GroupMembersHandler);
|
2007-11-06 09:26:10 +00:00
|
|
|
Inventory.OnObjectOffered += new InventoryManager.ObjectOfferedCallback(Inventory_OnInventoryObjectReceived);
|
2007-04-28 20:54:02 +00:00
|
|
|
|
|
|
|
|
Network.RegisterCallback(PacketType.AvatarAppearance, new NetworkManager.PacketCallback(AvatarAppearanceHandler));
|
2007-08-10 20:16:19 +00:00
|
|
|
Network.RegisterCallback(PacketType.AlertMessage, new NetworkManager.PacketCallback(AlertMessageHandler));
|
2008-04-09 20:02:07 +00:00
|
|
|
|
|
|
|
|
VoiceManager = new VoiceManager(this);
|
2008-08-21 01:19:06 +00:00
|
|
|
|
2007-04-28 20:54:02 +00:00
|
|
|
updateTimer.Start();
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-11 09:02:59 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Initialize everything that needs to be initialized once we're logged in.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="login">The status of the login</param>
|
|
|
|
|
/// <param name="message">Error message on failure, MOTD on success.</param>
|
2008-08-21 01:19:06 +00:00
|
|
|
public void LoginHandler(LoginStatus login, string message)
|
2008-05-11 09:02:59 +00:00
|
|
|
{
|
|
|
|
|
if (login == LoginStatus.Success)
|
|
|
|
|
{
|
2008-08-21 01:19:06 +00:00
|
|
|
// Start in the inventory root folder.
|
|
|
|
|
CurrentDirectory = Inventory.Store.RootFolder;
|
2008-05-11 09:02:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-28 20:54:02 +00:00
|
|
|
public void RegisterAllCommands(Assembly assembly)
|
|
|
|
|
{
|
|
|
|
|
foreach (Type t in assembly.GetTypes())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (t.IsSubclassOf(typeof(Command)))
|
|
|
|
|
{
|
|
|
|
|
ConstructorInfo info = t.GetConstructor(new Type[] { typeof(TestClient) });
|
|
|
|
|
Command command = (Command)info.Invoke(new object[] { this });
|
|
|
|
|
RegisterCommand(command);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RegisterCommand(Command command)
|
|
|
|
|
{
|
2008-08-21 01:19:06 +00:00
|
|
|
command.Client = this;
|
|
|
|
|
if (!Commands.ContainsKey(command.Name.ToLower()))
|
|
|
|
|
{
|
2007-07-11 09:17:46 +00:00
|
|
|
Commands.Add(command.Name.ToLower(), command);
|
2008-08-21 01:19:06 +00:00
|
|
|
}
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//breaks up large responses to deal with the max IM size
|
2008-07-25 05:15:05 +00:00
|
|
|
private void SendResponseIM(GridClient client, UUID fromAgentID, string data)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2008-08-21 01:19:06 +00:00
|
|
|
for (int i = 0; i < data.Length; i += 1024)
|
|
|
|
|
{
|
2007-04-28 20:54:02 +00:00
|
|
|
int y;
|
|
|
|
|
if ((i + 1023) > data.Length)
|
|
|
|
|
{
|
|
|
|
|
y = data.Length - i;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
y = 1023;
|
|
|
|
|
}
|
|
|
|
|
string message = data.Substring(i, y);
|
2007-12-21 05:31:13 +00:00
|
|
|
client.Self.InstantMessage(fromAgentID, message);
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
foreach (Command c in Commands.Values)
|
|
|
|
|
if (c.Active)
|
|
|
|
|
c.Think();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AgentDataUpdateHandler(Packet packet, Simulator sim)
|
|
|
|
|
{
|
|
|
|
|
AgentDataUpdatePacket p = (AgentDataUpdatePacket)packet;
|
2007-11-06 09:26:10 +00:00
|
|
|
if (p.AgentData.AgentID == sim.Client.Self.AgentID)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
GroupID = p.AgentData.ActiveGroupID;
|
|
|
|
|
|
2007-08-10 20:16:19 +00:00
|
|
|
sim.Client.Groups.RequestGroupMembers(GroupID);
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
private void GroupMembersHandler(Dictionary<UUID, GroupMember> members)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
GroupMembers = members;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AvatarAppearanceHandler(Packet packet, Simulator simulator)
|
|
|
|
|
{
|
|
|
|
|
AvatarAppearancePacket appearance = (AvatarAppearancePacket)packet;
|
|
|
|
|
|
|
|
|
|
lock (Appearances) Appearances[appearance.Sender.ID] = appearance;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-10 20:16:19 +00:00
|
|
|
private void AlertMessageHandler(Packet packet, Simulator simulator)
|
|
|
|
|
{
|
|
|
|
|
AlertMessagePacket message = (AlertMessagePacket)packet;
|
|
|
|
|
|
2008-08-12 22:38:02 +00:00
|
|
|
Logger.Log("[AlertMessage] " + Utils.BytesToString(message.AlertData.Message), Helpers.LogLevel.Info, this);
|
2007-08-10 20:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-22 18:16:38 +00:00
|
|
|
private void Self_OnInstantMessage(InstantMessage im, Simulator simulator)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2008-02-07 17:32:06 +00:00
|
|
|
bool groupIM = im.GroupIM && GroupMembers != null && GroupMembers.ContainsKey(im.FromAgentID) ? true : false;
|
|
|
|
|
|
2008-08-21 01:19:06 +00:00
|
|
|
if (im.FromAgentID == MasterKey || (GroupCommands && groupIM))
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2008-02-07 17:32:06 +00:00
|
|
|
// Received an IM from someone that is authenticated
|
|
|
|
|
Console.WriteLine("<{0} ({1})> {2}: {3} (@{4}:{5})", im.GroupIM ? "GroupIM" : "IM", im.Dialog, im.FromAgentName, im.Message, im.RegionID, im.Position);
|
|
|
|
|
|
|
|
|
|
if (im.Dialog == InstantMessageDialog.RequestTeleport)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Accepting teleport lure.");
|
|
|
|
|
Self.TeleportLureRespond(im.FromAgentID, true);
|
|
|
|
|
}
|
|
|
|
|
else if (
|
|
|
|
|
im.Dialog == InstantMessageDialog.MessageFromAgent ||
|
|
|
|
|
im.Dialog == InstantMessageDialog.MessageFromObject)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2008-10-10 21:53:47 +00:00
|
|
|
ClientManagerRef.ClientManager.DoCommandAll(im.Message, im.FromAgentID);
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-02-07 17:32:06 +00:00
|
|
|
else
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2008-02-07 17:32:06 +00:00
|
|
|
// Received an IM from someone that is not the bot's master, ignore
|
|
|
|
|
Console.WriteLine("<{0} ({1})> {2} (not master): {3} (@{4}:{5})", im.GroupIM ? "GroupIM" : "IM", im.Dialog, im.FromAgentName, im.Message,
|
|
|
|
|
im.RegionID, im.Position);
|
2007-07-13 14:49:36 +00:00
|
|
|
return;
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
2007-07-13 14:49:36 +00:00
|
|
|
}
|
2007-04-28 20:54:02 +00:00
|
|
|
|
2008-08-21 01:19:06 +00:00
|
|
|
private bool Inventory_OnInventoryObjectReceived(InstantMessage offer, AssetType type,
|
2008-07-25 05:15:05 +00:00
|
|
|
UUID objectID, bool fromTask)
|
2007-07-13 14:49:36 +00:00
|
|
|
{
|
2008-07-25 05:15:05 +00:00
|
|
|
if (MasterKey != UUID.Zero)
|
2007-07-13 14:49:36 +00:00
|
|
|
{
|
2008-05-06 00:31:03 +00:00
|
|
|
if (offer.FromAgentID != MasterKey)
|
2008-08-21 01:19:06 +00:00
|
|
|
return false;
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
2008-05-06 00:31:03 +00:00
|
|
|
else if (GroupMembers != null && !GroupMembers.ContainsKey(offer.FromAgentID))
|
2007-07-13 14:49:36 +00:00
|
|
|
{
|
2008-08-21 01:19:06 +00:00
|
|
|
return false;
|
2008-07-30 06:40:47 +00:00
|
|
|
}
|
2007-07-13 14:49:36 +00:00
|
|
|
|
2008-08-21 01:19:06 +00:00
|
|
|
return true;
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
2008-08-21 01:19:06 +00:00
|
|
|
}
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|