You can now save profiles to a database. (Zomg!)

0.1-prestable
Adam Frisby 2007-05-05 23:04:47 +00:00
parent 51da80a850
commit 6d6117e019
6 changed files with 123 additions and 3 deletions

View File

@ -39,6 +39,11 @@ namespace OpenGrid.Framework.Data.DB4o
throw new Exception("Unable to find profile with UUID (" + uuid.ToStringHyphenated() + ")"); throw new Exception("Unable to find profile with UUID (" + uuid.ToStringHyphenated() + ")");
} }
public DataResponse AddProfile(SimProfileData profile)
{
return DataResponse.RESPONSE_OK;
}
public bool AuthenticateSim(LLUUID uuid, ulong handle, string key) { public bool AuthenticateSim(LLUUID uuid, ulong handle, string key) {
if (manager.profiles[uuid].regionRecvKey == key) if (manager.profiles[uuid].regionRecvKey == key)
return true; return true;

View File

@ -10,11 +10,13 @@ namespace OpenGrid.Framework.Data.DB4o
class DB4oManager class DB4oManager
{ {
public Dictionary<LLUUID, SimProfileData> profiles = new Dictionary<LLUUID, SimProfileData>(); public Dictionary<LLUUID, SimProfileData> profiles = new Dictionary<LLUUID, SimProfileData>();
string dbfl;
public DB4oManager(string db4odb) public DB4oManager(string db4odb)
{ {
dbfl = db4odb;
IObjectContainer database; IObjectContainer database;
database = Db4oFactory.OpenFile(db4odb); database = Db4oFactory.OpenFile(dbfl);
IObjectSet result = database.Get(typeof(SimProfileData)); IObjectSet result = database.Get(typeof(SimProfileData));
foreach(SimProfileData row in result) { foreach(SimProfileData row in result) {
profiles.Add(row.UUID, row); profiles.Add(row.UUID, row);
@ -22,6 +24,29 @@ namespace OpenGrid.Framework.Data.DB4o
database.Close(); database.Close();
} }
/// <summary>
/// Adds a new profile to the database (Warning: Probably slow.)
/// </summary>
/// <param name="row">The profile to add</param>
/// <returns>Successful?</returns>
public bool AddRow(SimProfileData row)
{
profiles.Add(row.UUID, row);
try
{
IObjectContainer database;
database = Db4oFactory.OpenFile(dbfl);
database.Set(row);
database.Close();
return true;
}
catch (Exception e)
{
return false;
}
}
} }
} }

View File

@ -75,6 +75,18 @@ namespace OpenGrid.Framework.Data.MySQL
return row; return row;
} }
public DataResponse AddProfile(SimProfileData profile)
{
if (database.insertRow(profile))
{
return DataResponse.RESPONSE_OK;
}
else
{
return DataResponse.RESPONSE_ERROR;
}
}
/// <summary> /// <summary>
/// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret. /// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret.
/// </summary> /// </summary>

View File

@ -117,5 +117,58 @@ namespace OpenGrid.Framework.Data.MySQL
} }
return retval; return retval;
} }
public bool insertRow(SimProfileData profile) {
string sql = "REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, ";
sql += "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, ";
sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES ";
sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, ";
sql += "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, ";
sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey);";
Dictionary<string, string> parameters = new Dictionary<string,string>();
parameters["regionHandle"] = profile.regionHandle.ToString();
parameters["regionName"] = profile.regionName;
parameters["uuid"] = profile.UUID.ToString();
parameters["regionRecvKey"] = profile.regionRecvKey;
parameters["regionSendKey"] = profile.regionSendKey;
parameters["regionDataURI"] = profile.regionDataURI;
parameters["serverIP"] = profile.serverIP;
parameters["serverPort"] = profile.serverPort.ToString();
parameters["serverURI"] = profile.serverURI;
parameters["locX"] = profile.regionLocX.ToString();
parameters["locY"] = profile.regionLocY.ToString();
parameters["locZ"] = profile.regionLocZ.ToString();
parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString();
parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString();
parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString();
parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString();
parameters["regionAssetURI"] = profile.regionAssetURI;
parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey;
parameters["regionAssetSendKey"] = profile.regionAssetSendKey;
parameters["regionUserURI"] = profile.regionUserURI;
parameters["regionUserRecvKey"] = profile.regionUserRecvKey;
parameters["regionUserSendKey"] = profile.regionUserSendKey;
bool returnval = false;
try
{
IDbCommand result = Query(sql, parameters);
if (result.ExecuteNonQuery() == 1)
returnval = true;
result.Dispose();
}
catch (Exception e)
{
return false;
}
return returnval;
}
} }
} }

View File

@ -4,6 +4,14 @@ using System.Text;
namespace OpenGrid.Framework.Data namespace OpenGrid.Framework.Data
{ {
public enum DataResponse
{
RESPONSE_OK,
RESPONSE_AUTHREQUIRED,
RESPONSE_INVALIDCREDENTIALS,
RESPONSE_ERROR
}
/// <summary> /// <summary>
/// A standard grid interface /// A standard grid interface
/// </summary> /// </summary>
@ -54,5 +62,12 @@ namespace OpenGrid.Framework.Data
/// </summary> /// </summary>
/// <returns>A string containing the plugin version</returns> /// <returns>A string containing the plugin version</returns>
string getVersion(); string getVersion();
/// <summary>
/// Adds a new profile to the database
/// </summary>
/// <param name="profile">The profile to add</param>
/// <returns>RESPONSE_OK if successful, error if not.</returns>
DataResponse AddProfile(SimProfileData profile);
} }
} }

View File

@ -320,7 +320,17 @@ namespace OpenGridServices.GridServer
try try
{ {
// NEEDS IMPLEMENTATION. foreach (KeyValuePair<string, IGridData> kvp in _plugins)
{
try
{
kvp.Value.AddProfile(TheSim);
}
catch (Exception e)
{
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("getRegionPlugin Handle " + kvp.Key + " unable to add new sim: " + e.ToString());
}
}
return "OK"; return "OK";
} }
catch (Exception e) catch (Exception e)