Simian:
* Added lots of members to Agent, preparing for serialization * Added Clear() and Count to DoubleDictionary * Moved CreateCircuit and unassociatedAgents functionality out of Simian core and into UDPServer extension git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@2237 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using OpenMetaverse;
|
||||
using OpenMetaverse.StructuredData;
|
||||
using OpenMetaverse.Packets;
|
||||
|
||||
namespace Simian.Extensions
|
||||
@@ -190,18 +191,107 @@ namespace Simian.Extensions
|
||||
Server.UDP.SendPacket(agent.AgentID, update, PacketCategory.Asset);
|
||||
}
|
||||
|
||||
void ClearWearables(Agent agent)
|
||||
{
|
||||
agent.ShapeItem = UUID.Zero;
|
||||
agent.ShapeAsset = UUID.Zero;
|
||||
agent.SkinItem = UUID.Zero;
|
||||
agent.SkinAsset = UUID.Zero;
|
||||
agent.HairItem = UUID.Zero;
|
||||
agent.HairAsset = UUID.Zero;
|
||||
agent.EyesItem = UUID.Zero;
|
||||
agent.EyesAsset = UUID.Zero;
|
||||
agent.ShirtItem = UUID.Zero;
|
||||
agent.ShirtAsset = UUID.Zero;
|
||||
agent.PantsItem = UUID.Zero;
|
||||
agent.PantsAsset = UUID.Zero;
|
||||
agent.ShoesItem = UUID.Zero;
|
||||
agent.ShoesAsset = UUID.Zero;
|
||||
agent.SocksItem = UUID.Zero;
|
||||
agent.SocksAsset = UUID.Zero;
|
||||
agent.JacketItem = UUID.Zero;
|
||||
agent.JacketAsset = UUID.Zero;
|
||||
agent.GlovesItem = UUID.Zero;
|
||||
agent.GlovesAsset = UUID.Zero;
|
||||
agent.UndershirtItem = UUID.Zero;
|
||||
agent.UndershirtAsset = UUID.Zero;
|
||||
agent.UnderpantsItem = UUID.Zero;
|
||||
agent.UnderpantsAsset = UUID.Zero;
|
||||
agent.SkirtItem = UUID.Zero;
|
||||
agent.SkirtAsset = UUID.Zero;
|
||||
}
|
||||
|
||||
void AgentIsNowWearingHandler(Packet packet, Agent agent)
|
||||
{
|
||||
AgentIsNowWearingPacket wearing = (AgentIsNowWearingPacket)packet;
|
||||
|
||||
Logger.DebugLog("Updating agent wearables");
|
||||
ClearWearables(agent);
|
||||
|
||||
lock (agent.Wearables)
|
||||
for (int i = 0; i < wearing.WearableData.Length; i++)
|
||||
{
|
||||
agent.Wearables.Clear();
|
||||
UUID assetID = UUID.Zero;
|
||||
UUID itemID = wearing.WearableData[i].ItemID;
|
||||
|
||||
for (int i = 0; i < wearing.WearableData.Length; i++)
|
||||
agent.Wearables[(WearableType)wearing.WearableData[i].WearableType] = wearing.WearableData[i].ItemID;
|
||||
InventoryObject invObj;
|
||||
if (agent.Inventory.TryGetValue(itemID, out invObj) && invObj is InventoryItem)
|
||||
assetID = ((InventoryItem)invObj).AssetID;
|
||||
|
||||
switch ((WearableType)wearing.WearableData[i].WearableType)
|
||||
{
|
||||
case WearableType.Shape:
|
||||
agent.ShapeAsset = assetID;
|
||||
agent.ShapeItem = itemID;
|
||||
break;
|
||||
case WearableType.Skin:
|
||||
agent.SkinAsset = assetID;
|
||||
agent.SkinItem = itemID;
|
||||
break;
|
||||
case WearableType.Hair:
|
||||
agent.HairAsset = assetID;
|
||||
agent.HairItem = itemID;
|
||||
break;
|
||||
case WearableType.Eyes:
|
||||
agent.EyesAsset = assetID;
|
||||
agent.EyesItem = itemID;
|
||||
break;
|
||||
case WearableType.Shirt:
|
||||
agent.ShirtAsset = assetID;
|
||||
agent.ShirtItem = itemID;
|
||||
break;
|
||||
case WearableType.Pants:
|
||||
agent.PantsAsset = assetID;
|
||||
agent.PantsItem = itemID;
|
||||
break;
|
||||
case WearableType.Shoes:
|
||||
agent.ShoesAsset = assetID;
|
||||
agent.ShoesItem = itemID;
|
||||
break;
|
||||
case WearableType.Socks:
|
||||
agent.SocksAsset = assetID;
|
||||
agent.SocksItem = itemID;
|
||||
break;
|
||||
case WearableType.Jacket:
|
||||
agent.JacketAsset = assetID;
|
||||
agent.JacketItem = itemID;
|
||||
break;
|
||||
case WearableType.Gloves:
|
||||
agent.GlovesAsset = assetID;
|
||||
agent.GlovesItem = itemID;
|
||||
break;
|
||||
case WearableType.Undershirt:
|
||||
agent.UndershirtAsset = assetID;
|
||||
agent.UndershirtItem = itemID;
|
||||
break;
|
||||
case WearableType.Underpants:
|
||||
agent.UnderpantsAsset = assetID;
|
||||
agent.UnderpantsItem = itemID;
|
||||
break;
|
||||
case WearableType.Skirt:
|
||||
agent.SkirtAsset = assetID;
|
||||
agent.SkirtItem = itemID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,6 +305,9 @@ namespace Simian.Extensions
|
||||
set.ObjectData.TextureEntry.Length);
|
||||
|
||||
// Update agent visual params
|
||||
if (agent.VisualParams == null)
|
||||
agent.VisualParams = new byte[set.VisualParam.Length];
|
||||
|
||||
for (int i = 0; i < set.VisualParam.Length; i++)
|
||||
agent.VisualParams[i] = set.VisualParam[i].ParamValue;
|
||||
|
||||
|
||||
@@ -123,6 +123,11 @@ namespace Simian
|
||||
return udpServer.RemoveClient(agent, endpoint);
|
||||
}
|
||||
|
||||
public uint CreateCircuit(Agent agent)
|
||||
{
|
||||
return udpServer.CreateCircuit(agent);
|
||||
}
|
||||
|
||||
public void SendPacket(UUID agentID, Packet packet, PacketCategory category)
|
||||
{
|
||||
udpServer.SendPacket(agentID, packet, category);
|
||||
@@ -150,6 +155,10 @@ namespace Simian
|
||||
BlockingQueue<IncomingPacket> packetInbox = new BlockingQueue<IncomingPacket>(Settings.PACKET_INBOX_SIZE);
|
||||
/// <summary></summary>
|
||||
DoubleDictionary<UUID, IPEndPoint, UDPClient> clients = new DoubleDictionary<UUID, IPEndPoint, UDPClient>();
|
||||
/// <summary></summary>
|
||||
Dictionary<uint, Agent> unassociatedAgents = new Dictionary<uint, Agent>();
|
||||
/// <summary></summary>
|
||||
int currentCircuitCode = 0;
|
||||
|
||||
public UDPServer(int port, Simian server)
|
||||
: base(port)
|
||||
@@ -192,6 +201,19 @@ namespace Simian
|
||||
return clients.Remove(agent.AgentID, endpoint);
|
||||
}
|
||||
|
||||
public uint CreateCircuit(Agent agent)
|
||||
{
|
||||
uint circuitCode = (uint)Interlocked.Increment(ref currentCircuitCode);
|
||||
|
||||
// Put this client in the list of clients that have not been associated with an IPEndPoint yet
|
||||
lock (unassociatedAgents)
|
||||
unassociatedAgents[circuitCode] = agent;
|
||||
|
||||
Logger.Log("Created a circuit for " + agent.FirstName, Helpers.LogLevel.Info);
|
||||
|
||||
return circuitCode;
|
||||
}
|
||||
|
||||
public void BroadcastPacket(Packet packet, PacketCategory category)
|
||||
{
|
||||
clients.ForEach(
|
||||
@@ -478,7 +500,7 @@ namespace Simian
|
||||
UseCircuitCodePacket useCircuitCode = (UseCircuitCodePacket)packet;
|
||||
|
||||
Agent agent;
|
||||
if (server.CompleteAgentConnection(useCircuitCode.CircuitCode.Code, out agent))
|
||||
if (CompleteAgentConnection(useCircuitCode.CircuitCode.Code, out agent))
|
||||
{
|
||||
AddClient(agent, address);
|
||||
if (clients.TryGetValue(agent.AgentID, out client))
|
||||
@@ -532,7 +554,7 @@ namespace Simian
|
||||
{
|
||||
}
|
||||
|
||||
private void IncomingPacketHandler()
|
||||
void IncomingPacketHandler()
|
||||
{
|
||||
IncomingPacket incomingPacket = new IncomingPacket();
|
||||
Packet packet = null;
|
||||
@@ -616,5 +638,37 @@ namespace Simian
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TryGetUnassociatedAgent(uint circuitCode, out Agent agent)
|
||||
{
|
||||
if (unassociatedAgents.TryGetValue(circuitCode, out agent))
|
||||
{
|
||||
lock (unassociatedAgents)
|
||||
unassociatedAgents.Remove(circuitCode);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CompleteAgentConnection(uint circuitCode, out Agent agent)
|
||||
{
|
||||
if (unassociatedAgents.TryGetValue(circuitCode, out agent))
|
||||
{
|
||||
lock (server.Agents)
|
||||
server.Agents[agent.AgentID] = agent;
|
||||
lock (unassociatedAgents)
|
||||
unassociatedAgents.Remove(circuitCode);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user