2008-09-24 15:06:59 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2008-10-05 22:05:18 +00:00
|
|
|
using ExtensionLoader;
|
2008-09-24 15:06:59 +00:00
|
|
|
using OpenMetaverse;
|
|
|
|
|
using OpenMetaverse.StructuredData;
|
|
|
|
|
|
|
|
|
|
namespace Simian.Extensions
|
|
|
|
|
{
|
2008-10-29 20:11:28 +00:00
|
|
|
public class AccountManager : IExtension<Simian>, IAccountProvider, IPersistable
|
2008-09-24 15:06:59 +00:00
|
|
|
{
|
|
|
|
|
Simian server;
|
|
|
|
|
DoubleDictionary<string, UUID, Agent> accounts = new DoubleDictionary<string, UUID, Agent>();
|
|
|
|
|
|
2008-10-29 20:11:28 +00:00
|
|
|
public AccountManager()
|
2008-09-24 15:06:59 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-29 20:11:28 +00:00
|
|
|
public void Start(Simian server)
|
2008-09-24 15:06:59 +00:00
|
|
|
{
|
2008-10-29 20:11:28 +00:00
|
|
|
this.server = server;
|
2008-09-24 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddAccount(Agent agent)
|
|
|
|
|
{
|
2009-03-03 21:01:57 +00:00
|
|
|
accounts.Add(agent.FullName, agent.ID, agent);
|
2008-09-24 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-06 23:41:07 +00:00
|
|
|
#region Persistence
|
2008-09-24 15:06:59 +00:00
|
|
|
|
2008-10-30 01:50:59 +00:00
|
|
|
public OSD Serialize()
|
2008-09-24 15:06:59 +00:00
|
|
|
{
|
2008-10-30 01:50:59 +00:00
|
|
|
OSDArray array = new OSDArray(accounts.Count);
|
2008-09-24 15:06:59 +00:00
|
|
|
|
|
|
|
|
accounts.ForEach(delegate(Agent agent)
|
|
|
|
|
{
|
2008-12-29 20:44:28 +00:00
|
|
|
OSDMap agentMap = OSD.SerializeMembers(agent);
|
2009-03-03 21:01:57 +00:00
|
|
|
agentMap["AgentID"] = OSD.FromUUID(agent.ID);
|
2008-12-29 20:44:28 +00:00
|
|
|
array.Add(agentMap);
|
2008-09-24 15:06:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Logger.Log(String.Format("Serializing the agent store with {0} entries", accounts.Count),
|
|
|
|
|
Helpers.LogLevel.Info);
|
|
|
|
|
|
|
|
|
|
return array;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-30 01:50:59 +00:00
|
|
|
public void Deserialize(OSD serialized)
|
2008-09-24 15:06:59 +00:00
|
|
|
{
|
|
|
|
|
accounts.Clear();
|
|
|
|
|
|
2008-10-30 01:50:59 +00:00
|
|
|
OSDArray array = (OSDArray)serialized;
|
2008-09-24 15:06:59 +00:00
|
|
|
|
|
|
|
|
for (int i = 0; i < array.Count; i++)
|
|
|
|
|
{
|
2009-03-03 21:01:57 +00:00
|
|
|
Avatar avatar = new Avatar();
|
|
|
|
|
SimulationObject obj = new SimulationObject(avatar, server);
|
|
|
|
|
Agent agent = new Agent(obj);
|
2008-09-24 15:06:59 +00:00
|
|
|
object agentRef = (object)agent;
|
2008-12-29 20:44:28 +00:00
|
|
|
OSDMap map = array[i] as OSDMap;
|
|
|
|
|
OSD.DeserializeMembers(ref agentRef, map);
|
2008-09-24 15:06:59 +00:00
|
|
|
agent = (Agent)agentRef;
|
|
|
|
|
|
2009-03-03 21:01:57 +00:00
|
|
|
agent.Avatar.Prim.ID = map["AgentID"].AsUUID();
|
|
|
|
|
|
|
|
|
|
accounts.Add(agent.FullName, agent.ID, agent);
|
2008-09-24 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Log(String.Format("Deserialized the agent store with {0} entries", accounts.Count),
|
|
|
|
|
Helpers.LogLevel.Info);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-06 23:41:07 +00:00
|
|
|
#endregion Persistence
|
2008-09-24 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
}
|