You can now save profiles to a database. (Zomg!)
parent
51da80a850
commit
6d6117e019
|
@ -39,6 +39,11 @@ namespace OpenGrid.Framework.Data.DB4o
|
|||
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) {
|
||||
if (manager.profiles[uuid].regionRecvKey == key)
|
||||
return true;
|
||||
|
|
|
@ -10,11 +10,13 @@ namespace OpenGrid.Framework.Data.DB4o
|
|||
class DB4oManager
|
||||
{
|
||||
public Dictionary<LLUUID, SimProfileData> profiles = new Dictionary<LLUUID, SimProfileData>();
|
||||
string dbfl;
|
||||
|
||||
public DB4oManager(string db4odb)
|
||||
{
|
||||
dbfl = db4odb;
|
||||
IObjectContainer database;
|
||||
database = Db4oFactory.OpenFile(db4odb);
|
||||
database = Db4oFactory.OpenFile(dbfl);
|
||||
IObjectSet result = database.Get(typeof(SimProfileData));
|
||||
foreach(SimProfileData row in result) {
|
||||
profiles.Add(row.UUID, row);
|
||||
|
@ -22,6 +24,29 @@ namespace OpenGrid.Framework.Data.DB4o
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,6 +75,18 @@ namespace OpenGrid.Framework.Data.MySQL
|
|||
return row;
|
||||
}
|
||||
|
||||
public DataResponse AddProfile(SimProfileData profile)
|
||||
{
|
||||
if (database.insertRow(profile))
|
||||
{
|
||||
return DataResponse.RESPONSE_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DataResponse.RESPONSE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret.
|
||||
/// </summary>
|
||||
|
|
|
@ -117,5 +117,58 @@ namespace OpenGrid.Framework.Data.MySQL
|
|||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,14 @@ using System.Text;
|
|||
|
||||
namespace OpenGrid.Framework.Data
|
||||
{
|
||||
public enum DataResponse
|
||||
{
|
||||
RESPONSE_OK,
|
||||
RESPONSE_AUTHREQUIRED,
|
||||
RESPONSE_INVALIDCREDENTIALS,
|
||||
RESPONSE_ERROR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A standard grid interface
|
||||
/// </summary>
|
||||
|
@ -54,5 +62,12 @@ namespace OpenGrid.Framework.Data
|
|||
/// </summary>
|
||||
/// <returns>A string containing the plugin version</returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -320,7 +320,17 @@ namespace OpenGridServices.GridServer
|
|||
|
||||
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";
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
Loading…
Reference in New Issue