aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorMelanie2010-01-04 02:52:43 +0000
committerMelanie2010-01-04 02:52:43 +0000
commit6e8d94685d4e5784398ff656fdab169310dc219a (patch)
tree41afa2c07f493c013a9535e4ea81a7866f5620f2 /OpenSim
parentSome work on avatar service. Retrieval and storage done (diff)
downloadopensim-SC_OLD-6e8d94685d4e5784398ff656fdab169310dc219a.zip
opensim-SC_OLD-6e8d94685d4e5784398ff656fdab169310dc219a.tar.gz
opensim-SC_OLD-6e8d94685d4e5784398ff656fdab169310dc219a.tar.bz2
opensim-SC_OLD-6e8d94685d4e5784398ff656fdab169310dc219a.tar.xz
AvatarStore. Untested, but complete
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/IAvatarData.cs2
-rw-r--r--OpenSim/Data/MySQL/MySQLGenericTableHandler.cs10
-rw-r--r--OpenSim/Data/MySQL/Resources/001_Avatar.sql5
-rw-r--r--OpenSim/Services/AvatarService/AvatarService.cs63
4 files changed, 64 insertions, 16 deletions
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
43 { 43 {
44 AvatarBaseData[] Get(string field, string val); 44 AvatarBaseData[] Get(string field, string val);
45 bool Store(AvatarBaseData data); 45 bool Store(AvatarBaseData data);
46 bool Delete(UUID principalID, string name);
47 bool Delete(string field, string val);
46 } 48 }
47} 49}
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
95 } 95 }
96 } 96 }
97 97
98 public T[] Get(string field, string key) 98 public virtual T[] Get(string field, string key)
99 { 99 {
100 return Get(new string[] { field }, new string[] { key }); 100 return Get(new string[] { field }, new string[] { key });
101 } 101 }
102 102
103 public T[] Get(string[] fields, string[] keys) 103 public virtual T[] Get(string[] fields, string[] keys)
104 { 104 {
105 if (fields.Length != keys.Length) 105 if (fields.Length != keys.Length)
106 return new T[0]; 106 return new T[0];
@@ -184,7 +184,7 @@ namespace OpenSim.Data.MySQL
184 return result.ToArray(); 184 return result.ToArray();
185 } 185 }
186 186
187 public T[] Get(string where) 187 public virtual T[] Get(string where)
188 { 188 {
189 MySqlCommand cmd = new MySqlCommand(); 189 MySqlCommand cmd = new MySqlCommand();
190 190
@@ -196,7 +196,7 @@ namespace OpenSim.Data.MySQL
196 return DoQuery(cmd); 196 return DoQuery(cmd);
197 } 197 }
198 198
199 public bool Store(T row) 199 public virtual bool Store(T row)
200 { 200 {
201 MySqlCommand cmd = new MySqlCommand(); 201 MySqlCommand cmd = new MySqlCommand();
202 202
@@ -234,7 +234,7 @@ namespace OpenSim.Data.MySQL
234 return false; 234 return false;
235 } 235 }
236 236
237 public bool Delete(string field, string val) 237 public virtual bool Delete(string field, string val)
238 { 238 {
239 MySqlCommand cmd = new MySqlCommand(); 239 MySqlCommand cmd = new MySqlCommand();
240 240
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 @@
1BEGIN;
2
3CREATE TABLE Avatars (PrincipalID CHAR(36) NOT NULL, Name VARCHAR(32) NOT NULL, Value VARCHAR(255) NOT NULL DEFAULT '', PRIMARY KEY(PrincipalID, Name), KEY(PrincipalID));
4
5COMMIT;
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
53 53
54 public AvatarData GetAvatar(UUID principalID) 54 public AvatarData GetAvatar(UUID principalID)
55 { 55 {
56
57 AvatarBaseData[] av = m_Database.Get("PrincipalID", principalID.ToString()); 56 AvatarBaseData[] av = m_Database.Get("PrincipalID", principalID.ToString());
58 if (av.Length == 0) 57 if (av.Length == 0)
59 return null; 58 return null;
60 59
61 AvatarData ret = new AvatarData(); 60 AvatarData ret = new AvatarData();
62 ret.AvatarType = Convert.ToInt32(av[0].Data["AvatarType"]); 61 ret.Data = new Dictionary<string,string>();
63 62
64 av[0].Data.Remove("AvatarType"); 63 foreach (AvatarBaseData b in av)
65 64 {
66 ret.Data = av[0].Data; 65 if (b.Data["Name"] == "AvatarType")
66 ret.AvatarType = Convert.ToInt32(b.Data["Value"]);
67 else
68 ret.Data[b.Data["Name"]] = b.Data["Value"];
69 }
67 70
68 return ret; 71 return ret;
69 } 72 }
70 73
71 public bool SetAvatar(UUID principalID, AvatarData avatar) 74 public bool SetAvatar(UUID principalID, AvatarData avatar)
72 { 75 {
76 m_Database.Delete("PrincipalID", principalID.ToString());
77
73 AvatarBaseData av = new AvatarBaseData(); 78 AvatarBaseData av = new AvatarBaseData();
79 av.Data = new Dictionary<string,string>();
74 80
75 av.PrincipalID = principalID; 81 av.PrincipalID = principalID;
76 av.Data = avatar.Data; 82 av.Data["Name"] = "AvatarType";
77 av.Data["AvatarType"] = avatar.AvatarType.ToString(); 83 av.Data["Value"] = avatar.AvatarType.ToString();
84
85 if (!m_Database.Store(av))
86 return false;
78 87
79 return m_Database.Store(av); 88 foreach (KeyValuePair<string,string> kvp in avatar.Data)
89 {
90 av.Data["Name"] = kvp.Key;
91 av.Data["Value"] = kvp.Value;
92
93 if (!m_Database.Store(av))
94 {
95 m_Database.Delete("PrincipalID", principalID.ToString());
96 return false;
97 }
98 }
99
100 return true;
80 } 101 }
81 102
82 public bool ResetAvatar(UUID principalID) 103 public bool ResetAvatar(UUID principalID)
83 { 104 {
84 return false; 105 return m_Database.Delete("PrincipalID", principalID.ToString());
85 } 106 }
86 107
87 public bool SetItems(UUID principalID, string[] names, string[] values) 108 public bool SetItems(UUID principalID, string[] names, string[] values)
88 { 109 {
89 return false; 110 AvatarBaseData av = new AvatarBaseData();
111 av.Data = new Dictionary<string,string>();
112 av.PrincipalID = principalID;
113
114 if (names.Length != values.Length)
115 return false;
116
117 for (int i = 0 ; i < names.Length ; i++)
118 {
119 av.Data["Name"] = names[i];
120 av.Data["Value"] = values[i];
121
122 if (!m_Database.Store(av))
123 return false;
124 }
125
126 return true;
90 } 127 }
91 128
92 public bool RemoveItems(UUID principalID, string[] names) 129 public bool RemoveItems(UUID principalID, string[] names)
93 { 130 {
94 return false; 131 foreach (string name in names)
132 {
133 m_Database.Delete(principalID, name);
134 }
135 return true;
95 } 136 }
96 } 137 }
97} 138}