From 6d6117e0196e8aabccee2a8879b0b6ad950ab3ab Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Sat, 5 May 2007 23:04:47 +0000 Subject: You can now save profiles to a database. (Zomg!) --- OpenGrid.Framework.Data.DB4o/DB4oGridData.cs | 5 +++ OpenGrid.Framework.Data.DB4o/DB4oManager.cs | 29 +++++++++++++- OpenGrid.Framework.Data.MySQL/MySQLGridData.cs | 12 ++++++ OpenGrid.Framework.Data.MySQL/MySQLManager.cs | 53 ++++++++++++++++++++++++++ OpenGrid.Framework.Data/GridData.cs | 15 ++++++++ OpenGridServices.GridServer/GridManager.cs | 12 +++++- 6 files changed, 123 insertions(+), 3 deletions(-) diff --git a/OpenGrid.Framework.Data.DB4o/DB4oGridData.cs b/OpenGrid.Framework.Data.DB4o/DB4oGridData.cs index d15e343..c8152f4 100644 --- a/OpenGrid.Framework.Data.DB4o/DB4oGridData.cs +++ b/OpenGrid.Framework.Data.DB4o/DB4oGridData.cs @@ -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; diff --git a/OpenGrid.Framework.Data.DB4o/DB4oManager.cs b/OpenGrid.Framework.Data.DB4o/DB4oManager.cs index f889636..3ebcee2 100644 --- a/OpenGrid.Framework.Data.DB4o/DB4oManager.cs +++ b/OpenGrid.Framework.Data.DB4o/DB4oManager.cs @@ -10,11 +10,13 @@ namespace OpenGrid.Framework.Data.DB4o class DB4oManager { public Dictionary profiles = new Dictionary(); - + 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(); } + /// + /// Adds a new profile to the database (Warning: Probably slow.) + /// + /// The profile to add + /// Successful? + 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; + } + } + } } diff --git a/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs b/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs index 0a84cdb..4404a16 100644 --- a/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs +++ b/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs @@ -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; + } + } + /// /// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret. /// diff --git a/OpenGrid.Framework.Data.MySQL/MySQLManager.cs b/OpenGrid.Framework.Data.MySQL/MySQLManager.cs index 057cd42..d3bfa18 100644 --- a/OpenGrid.Framework.Data.MySQL/MySQLManager.cs +++ b/OpenGrid.Framework.Data.MySQL/MySQLManager.cs @@ -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 parameters = new Dictionary(); + + 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; + } } } diff --git a/OpenGrid.Framework.Data/GridData.cs b/OpenGrid.Framework.Data/GridData.cs index 3b052fb..d5516b2 100644 --- a/OpenGrid.Framework.Data/GridData.cs +++ b/OpenGrid.Framework.Data/GridData.cs @@ -4,6 +4,14 @@ using System.Text; namespace OpenGrid.Framework.Data { + public enum DataResponse + { + RESPONSE_OK, + RESPONSE_AUTHREQUIRED, + RESPONSE_INVALIDCREDENTIALS, + RESPONSE_ERROR + } + /// /// A standard grid interface /// @@ -54,5 +62,12 @@ namespace OpenGrid.Framework.Data /// /// A string containing the plugin version string getVersion(); + + /// + /// Adds a new profile to the database + /// + /// The profile to add + /// RESPONSE_OK if successful, error if not. + DataResponse AddProfile(SimProfileData profile); } } diff --git a/OpenGridServices.GridServer/GridManager.cs b/OpenGridServices.GridServer/GridManager.cs index b3b97a1..8cff0d3 100644 --- a/OpenGridServices.GridServer/GridManager.cs +++ b/OpenGridServices.GridServer/GridManager.cs @@ -320,7 +320,17 @@ namespace OpenGridServices.GridServer try { - // NEEDS IMPLEMENTATION. + foreach (KeyValuePair 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) -- cgit v1.1