* Clearing up confusion with Agent.Avatar by making it a SimulationObject that is passed in through the constructor. This should prevent duplicate notions of an avatar in the scene * Fixed the "you don't own this object" issue after moving a prim. The fix is rather hacky and will be replaced when we stop sending full object updates for every change git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@2465 52acb1d6-8a22-11de-b505-999d5b087335
117 lines
3.3 KiB
C#
117 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using ExtensionLoader;
|
|
using OpenMetaverse;
|
|
using OpenMetaverse.StructuredData;
|
|
|
|
namespace Simian.Extensions
|
|
{
|
|
public class AccountManager : IExtension<Simian>, IAccountProvider, IPersistable
|
|
{
|
|
Simian server;
|
|
DoubleDictionary<string, UUID, Agent> accounts = new DoubleDictionary<string, UUID, Agent>();
|
|
|
|
public AccountManager()
|
|
{
|
|
}
|
|
|
|
public void Start(Simian server)
|
|
{
|
|
this.server = server;
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
}
|
|
|
|
public void AddAccount(Agent agent)
|
|
{
|
|
accounts.Add(agent.FullName, agent.ID, agent);
|
|
}
|
|
|
|
public bool RemoveAccount(UUID agentID)
|
|
{
|
|
Agent agent;
|
|
if (accounts.TryGetValue(agentID, out agent))
|
|
return accounts.Remove(agent.FullName, agentID);
|
|
else
|
|
return false;
|
|
}
|
|
|
|
public Agent CreateInstance(UUID agentID)
|
|
{
|
|
Agent agent;
|
|
if (accounts.TryGetValue(agentID, out agent))
|
|
{
|
|
// Random session IDs
|
|
agent.SessionID = UUID.Random();
|
|
agent.SecureSessionID = UUID.Random();
|
|
|
|
return agent;
|
|
}
|
|
else
|
|
{
|
|
Logger.Log(String.Format("Agent {0} does not exist in the account store", agentID),
|
|
Helpers.LogLevel.Error);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public bool TryGetAccount(UUID agentID, out Agent agent)
|
|
{
|
|
return accounts.TryGetValue(agentID, out agent);
|
|
}
|
|
|
|
public bool TryGetAccount(string fullName, out Agent agent)
|
|
{
|
|
return accounts.TryGetValue(fullName, out agent);
|
|
}
|
|
|
|
#region Persistence
|
|
|
|
public OSD Serialize()
|
|
{
|
|
OSDArray array = new OSDArray(accounts.Count);
|
|
|
|
accounts.ForEach(delegate(Agent agent)
|
|
{
|
|
OSDMap agentMap = OSD.SerializeMembers(agent);
|
|
agentMap["AgentID"] = OSD.FromUUID(agent.ID);
|
|
array.Add(agentMap);
|
|
});
|
|
|
|
Logger.Log(String.Format("Serializing the agent store with {0} entries", accounts.Count),
|
|
Helpers.LogLevel.Info);
|
|
|
|
return array;
|
|
}
|
|
|
|
public void Deserialize(OSD serialized)
|
|
{
|
|
accounts.Clear();
|
|
|
|
OSDArray array = (OSDArray)serialized;
|
|
|
|
for (int i = 0; i < array.Count; i++)
|
|
{
|
|
Avatar avatar = new Avatar();
|
|
SimulationObject obj = new SimulationObject(avatar, server);
|
|
Agent agent = new Agent(obj);
|
|
object agentRef = (object)agent;
|
|
OSDMap map = array[i] as OSDMap;
|
|
OSD.DeserializeMembers(ref agentRef, map);
|
|
agent = (Agent)agentRef;
|
|
|
|
agent.Avatar.Prim.ID = map["AgentID"].AsUUID();
|
|
|
|
accounts.Add(agent.FullName, agent.ID, agent);
|
|
}
|
|
|
|
Logger.Log(String.Format("Deserialized the agent store with {0} entries", accounts.Count),
|
|
Helpers.LogLevel.Info);
|
|
}
|
|
|
|
#endregion Persistence
|
|
}
|
|
}
|