From 6e8d94685d4e5784398ff656fdab169310dc219a Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 4 Jan 2010 02:52:43 +0000 Subject: AvatarStore. Untested, but complete --- OpenSim/Data/IAvatarData.cs | 2 + OpenSim/Data/MySQL/MySQLGenericTableHandler.cs | 10 ++-- OpenSim/Data/MySQL/Resources/001_Avatar.sql | 5 ++ OpenSim/Services/AvatarService/AvatarService.cs | 63 ++++++++++++++++++++----- 4 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 OpenSim/Data/MySQL/Resources/001_Avatar.sql diff --git a/OpenSim/Data/IAvatarData.cs b/OpenSim/Data/IAvatarData.cs index 59213da..0a18e21 100644 --- a/OpenSim/Data/IAvatarData.cs +++ b/OpenSim/Data/IAvatarData.cs @@ -43,5 +43,7 @@ namespace OpenSim.Data { AvatarBaseData[] Get(string field, string val); bool Store(AvatarBaseData data); + bool Delete(UUID principalID, string name); + bool Delete(string field, string val); } } diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs index 873d6d4..1a97fee 100644 --- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs +++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs @@ -95,12 +95,12 @@ namespace OpenSim.Data.MySQL } } - public T[] Get(string field, string key) + public virtual T[] Get(string field, string key) { return Get(new string[] { field }, new string[] { key }); } - public T[] Get(string[] fields, string[] keys) + public virtual T[] Get(string[] fields, string[] keys) { if (fields.Length != keys.Length) return new T[0]; @@ -184,7 +184,7 @@ namespace OpenSim.Data.MySQL return result.ToArray(); } - public T[] Get(string where) + public virtual T[] Get(string where) { MySqlCommand cmd = new MySqlCommand(); @@ -196,7 +196,7 @@ namespace OpenSim.Data.MySQL return DoQuery(cmd); } - public bool Store(T row) + public virtual bool Store(T row) { MySqlCommand cmd = new MySqlCommand(); @@ -234,7 +234,7 @@ namespace OpenSim.Data.MySQL return false; } - public bool Delete(string field, string val) + public virtual bool Delete(string field, string val) { MySqlCommand cmd = new MySqlCommand(); diff --git a/OpenSim/Data/MySQL/Resources/001_Avatar.sql b/OpenSim/Data/MySQL/Resources/001_Avatar.sql new file mode 100644 index 0000000..27a3072 --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/001_Avatar.sql @@ -0,0 +1,5 @@ +BEGIN; + +CREATE TABLE Avatars (PrincipalID CHAR(36) NOT NULL, Name VARCHAR(32) NOT NULL, Value VARCHAR(255) NOT NULL DEFAULT '', PRIMARY KEY(PrincipalID, Name), KEY(PrincipalID)); + +COMMIT; diff --git a/OpenSim/Services/AvatarService/AvatarService.cs b/OpenSim/Services/AvatarService/AvatarService.cs index ffcdcc5..0b351a2 100644 --- a/OpenSim/Services/AvatarService/AvatarService.cs +++ b/OpenSim/Services/AvatarService/AvatarService.cs @@ -53,45 +53,86 @@ namespace OpenSim.Services.AvatarService public AvatarData GetAvatar(UUID principalID) { - AvatarBaseData[] av = m_Database.Get("PrincipalID", principalID.ToString()); if (av.Length == 0) return null; AvatarData ret = new AvatarData(); - ret.AvatarType = Convert.ToInt32(av[0].Data["AvatarType"]); + ret.Data = new Dictionary(); - av[0].Data.Remove("AvatarType"); - - ret.Data = av[0].Data; + foreach (AvatarBaseData b in av) + { + if (b.Data["Name"] == "AvatarType") + ret.AvatarType = Convert.ToInt32(b.Data["Value"]); + else + ret.Data[b.Data["Name"]] = b.Data["Value"]; + } return ret; } public bool SetAvatar(UUID principalID, AvatarData avatar) { + m_Database.Delete("PrincipalID", principalID.ToString()); + AvatarBaseData av = new AvatarBaseData(); + av.Data = new Dictionary(); av.PrincipalID = principalID; - av.Data = avatar.Data; - av.Data["AvatarType"] = avatar.AvatarType.ToString(); + av.Data["Name"] = "AvatarType"; + av.Data["Value"] = avatar.AvatarType.ToString(); + + if (!m_Database.Store(av)) + return false; - return m_Database.Store(av); + foreach (KeyValuePair kvp in avatar.Data) + { + av.Data["Name"] = kvp.Key; + av.Data["Value"] = kvp.Value; + + if (!m_Database.Store(av)) + { + m_Database.Delete("PrincipalID", principalID.ToString()); + return false; + } + } + + return true; } public bool ResetAvatar(UUID principalID) { - return false; + return m_Database.Delete("PrincipalID", principalID.ToString()); } public bool SetItems(UUID principalID, string[] names, string[] values) { - return false; + AvatarBaseData av = new AvatarBaseData(); + av.Data = new Dictionary(); + av.PrincipalID = principalID; + + if (names.Length != values.Length) + return false; + + for (int i = 0 ; i < names.Length ; i++) + { + av.Data["Name"] = names[i]; + av.Data["Value"] = values[i]; + + if (!m_Database.Store(av)) + return false; + } + + return true; } public bool RemoveItems(UUID principalID, string[] names) { - return false; + foreach (string name in names) + { + m_Database.Delete(principalID, name); + } + return true; } } } -- cgit v1.1