mirror of
https://github.com/opensim/opensim.git
synced 2026-08-07 17:55:48 +08:00
Plumbs in attachment persistence and adds the tables. Currently MySQL only, no user functionality yet.
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
@@ -660,6 +661,26 @@ namespace OpenSim.Data.MySQL
|
||||
}
|
||||
|
||||
|
||||
// Read attachment list from data reader
|
||||
public Hashtable readAttachments(IDataReader r)
|
||||
{
|
||||
Hashtable ret = new Hashtable();
|
||||
|
||||
while(r.Read())
|
||||
{
|
||||
int attachpoint = Convert.ToInt32(r["attachpoint"]);
|
||||
if(ret.ContainsKey(attachpoint))
|
||||
continue;
|
||||
Hashtable item = new Hashtable();
|
||||
item.Add("item", r["item"].ToString());
|
||||
item.Add("asset", r["asset"].ToString());
|
||||
|
||||
ret.Add(attachpoint, item);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a new row into the log database
|
||||
/// </summary>
|
||||
@@ -1176,5 +1197,35 @@ namespace OpenSim.Data.MySQL
|
||||
|
||||
}
|
||||
|
||||
public void writeAttachments(LLUUID agentID, Hashtable data)
|
||||
{
|
||||
string sql = "delete from avatarattachments where UUID = ?uuid";
|
||||
|
||||
MySqlCommand cmd = (MySqlCommand) dbcon.CreateCommand();
|
||||
cmd.CommandText = sql;
|
||||
cmd.Parameters.AddWithValue("?uuid", agentID.ToString());
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
sql = "insert into avatarattachments (UUID, attachpoint, item, asset) values (?uuid, ?attchpoint, ?item, ?asset)";
|
||||
|
||||
cmd = (MySqlCommand) dbcon.CreateCommand();
|
||||
cmd.CommandText = sql;
|
||||
|
||||
foreach(DictionaryEntry e in data)
|
||||
{
|
||||
int attachpoint = Convert.ToInt32(e.Key);
|
||||
|
||||
Hashtable item = (Hashtable)e.Value;
|
||||
|
||||
cmd.Parameters.Clear();
|
||||
cmd.Parameters.AddWithValue("?uuid", agentID.ToString());
|
||||
cmd.Parameters.AddWithValue("?attachpoint", attachpoint);
|
||||
cmd.Parameters.AddWithValue("?item", item["item"]);
|
||||
cmd.Parameters.AddWithValue("?asset", item["asset"]);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Reflection;
|
||||
@@ -34,6 +35,7 @@ using libsecondlife;
|
||||
using log4net;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Data.Base;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace OpenSim.Data.MySQL
|
||||
{
|
||||
@@ -737,6 +739,8 @@ namespace OpenSim.Data.MySQL
|
||||
reader.Dispose();
|
||||
result.Dispose();
|
||||
|
||||
appearance.SetAttachments(GetUserAttachments(user));
|
||||
|
||||
return appearance;
|
||||
}
|
||||
}
|
||||
@@ -762,6 +766,8 @@ namespace OpenSim.Data.MySQL
|
||||
{
|
||||
appearance.Owner = user;
|
||||
database.insertAppearanceRow(appearance);
|
||||
|
||||
UpdateUserAttachments(user, appearance.GetAttachments());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -818,5 +824,24 @@ namespace OpenSim.Data.MySQL
|
||||
{
|
||||
get {return "0.1";}
|
||||
}
|
||||
|
||||
public Hashtable GetUserAttachments(LLUUID agentID)
|
||||
{
|
||||
MySqlCommand cmd = (MySqlCommand) (database.Connection.CreateCommand());
|
||||
cmd.CommandText = "select attachpoint, item, asset from avatarattachments where UUID = ?uuid";
|
||||
cmd.Parameters.AddWithValue("?uuid", agentID.ToString());
|
||||
|
||||
IDataReader r = cmd.ExecuteReader();
|
||||
|
||||
return database.readAttachments(r);
|
||||
}
|
||||
|
||||
public void UpdateUserAttachments(LLUUID agentID, Hashtable data)
|
||||
{
|
||||
if(data == null)
|
||||
return;
|
||||
|
||||
database.writeAttachments(agentID, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
OpenSim/Data/MySQL/Resources/005_UserStore.sql
Normal file
5
OpenSim/Data/MySQL/Resources/005_UserStore.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE `avatarattachments` (`UUID` char(36) NOT NULL, `attachpoint` int(11) NOT NULL, `item` char(36) NOT NULL, `asset` char(36) NOT NULL) ENGINE=InnoDB;
|
||||
|
||||
COMMIT;
|
||||
Reference in New Issue
Block a user