diff --git a/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs b/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs index 4404a16e53..3dceff6988 100644 --- a/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs +++ b/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs @@ -14,7 +14,7 @@ namespace OpenGrid.Framework.Data.MySQL /// public void Initialise() { - database = new MySQLManager("localhost", "db", "user", "password", "false"); + database = new MySQLManager("server", "database", "username", "password", "false"); } /// @@ -42,17 +42,28 @@ namespace OpenGrid.Framework.Data.MySQL /// Sim profile public SimProfileData GetProfileByHandle(ulong handle) { - Dictionary param = new Dictionary(); - param["handle"] = handle.ToString(); + try + { + lock (database) + { + Dictionary param = new Dictionary(); + param["?handle"] = handle.ToString(); - System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE handle = @handle", param); - System.Data.IDataReader reader = result.ExecuteReader(); + System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE regionHandle = ?handle", param); + System.Data.IDataReader reader = result.ExecuteReader(); - SimProfileData row = database.getRow( reader ); - reader.Close(); - result.Dispose(); + SimProfileData row = database.getSimRow(reader); + reader.Close(); + result.Dispose(); - return row; + return row; + } + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + return null; + } } /// @@ -62,28 +73,42 @@ namespace OpenGrid.Framework.Data.MySQL /// The sim profile public SimProfileData GetProfileByLLUUID(libsecondlife.LLUUID uuid) { - Dictionary param = new Dictionary(); - param["uuid"] = uuid.ToStringHyphenated(); + try + { + lock (database) + { + Dictionary param = new Dictionary(); + param["?uuid"] = uuid.ToStringHyphenated(); - System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param); - System.Data.IDataReader reader = result.ExecuteReader(); + System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = ?uuid", param); + System.Data.IDataReader reader = result.ExecuteReader(); - SimProfileData row = database.getRow(reader); - reader.Close(); - result.Dispose(); + SimProfileData row = database.getSimRow(reader); + reader.Close(); + result.Dispose(); - return row; + return row; + } + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + return null; + } } public DataResponse AddProfile(SimProfileData profile) { - if (database.insertRow(profile)) + lock (database) { - return DataResponse.RESPONSE_OK; - } - else - { - return DataResponse.RESPONSE_ERROR; + if (database.insertRow(profile)) + { + return DataResponse.RESPONSE_OK; + } + else + { + return DataResponse.RESPONSE_ERROR; + } } } diff --git a/OpenGrid.Framework.Data.MySQL/MySQLManager.cs b/OpenGrid.Framework.Data.MySQL/MySQLManager.cs index d3bfa18a75..7461b148bb 100644 --- a/OpenGrid.Framework.Data.MySQL/MySQLManager.cs +++ b/OpenGrid.Framework.Data.MySQL/MySQLManager.cs @@ -29,7 +29,7 @@ namespace OpenGrid.Framework.Data.MySQL { try { - string connectionString = "Server=" + hostname + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";"; + string connectionString = "Server=" + hostname + ";Port=13306;Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";"; dbcon = new MySqlConnection(connectionString); dbcon.Open(); @@ -57,24 +57,32 @@ namespace OpenGrid.Framework.Data.MySQL /// A MySQL DB Command public IDbCommand Query(string sql, Dictionary parameters) { - MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand(); - dbcommand.CommandText = sql; - foreach (KeyValuePair param in parameters) + try { - dbcommand.Parameters.Add(param.Key, param.Value); - } + MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand(); + dbcommand.CommandText = sql; + foreach (KeyValuePair param in parameters) + { + dbcommand.Parameters.Add(param.Key, param.Value); + } - return (IDbCommand)dbcommand; + return (IDbCommand)dbcommand; + } + catch (Exception e) + { + Console.WriteLine("Failed during Query generation: " + e.ToString()); + return null; + } } - public SimProfileData getRow(IDataReader reader) + public SimProfileData getSimRow(IDataReader reader) { SimProfileData retval = new SimProfileData(); if (reader.Read()) { // Region Main - retval.regionHandle = (ulong)reader["regionHandle"]; + retval.regionHandle = Convert.ToUInt64(reader["regionHandle"].ToString()); retval.regionName = (string)reader["regionName"]; retval.UUID = new libsecondlife.LLUUID((string)reader["uuid"]); @@ -91,15 +99,15 @@ namespace OpenGrid.Framework.Data.MySQL retval.serverURI = (string)reader["serverURI"]; // Location - retval.regionLocX = (uint)((int)reader["locX"]); - retval.regionLocY = (uint)((int)reader["locY"]); - retval.regionLocZ = (uint)((int)reader["locZ"]); + retval.regionLocX = Convert.ToUInt32(reader["locX"].ToString()); + retval.regionLocY = Convert.ToUInt32(reader["locY"].ToString()); + retval.regionLocZ = Convert.ToUInt32(reader["locZ"].ToString()); // Neighbours - 0 = No Override - retval.regionEastOverrideHandle = (ulong)reader["eastOverrideHandle"]; - retval.regionWestOverrideHandle = (ulong)reader["westOverrideHandle"]; - retval.regionSouthOverrideHandle = (ulong)reader["southOverrideHandle"]; - retval.regionNorthOverrideHandle = (ulong)reader["northOverrideHandle"]; + retval.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"].ToString()); + retval.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"].ToString()); + retval.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"].ToString()); + retval.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"].ToString()); // Assets retval.regionAssetURI = (string)reader["regionAssetURI"]; @@ -113,51 +121,57 @@ namespace OpenGrid.Framework.Data.MySQL } else { - throw new Exception("No rows to return"); + throw new Exception("Unable to find region at coordinates"); + return null; } return retval; } - public bool insertRow(SimProfileData profile) { - string sql = "REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, "; + public bool insertRow(SimProfileData profile) + { + string sql = "REPLACE INTO regions (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);"; + 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(); + 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; + parameters["?regionHandle"] = profile.regionHandle.ToString(); + parameters["?regionName"] = profile.regionName.ToString(); + parameters["?uuid"] = profile.UUID.ToStringHyphenated(); + parameters["?regionRecvKey"] = profile.regionRecvKey.ToString(); + parameters["?regionSecret"] = profile.regionSecret.ToString(); + parameters["?regionSendKey"] = profile.regionSendKey.ToString(); + parameters["?regionDataURI"] = profile.regionDataURI.ToString(); + parameters["?serverIP"] = profile.serverIP.ToString(); + parameters["?serverPort"] = profile.serverPort.ToString(); + parameters["?serverURI"] = profile.serverURI.ToString(); + 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.ToString(); + parameters["?regionAssetRecvKey"] = profile.regionAssetRecvKey.ToString(); + parameters["?regionAssetSendKey"] = profile.regionAssetSendKey.ToString(); + parameters["?regionUserURI"] = profile.regionUserURI.ToString(); + parameters["?regionUserRecvKey"] = profile.regionUserRecvKey.ToString(); + parameters["?regionUserSendKey"] = profile.regionUserSendKey.ToString(); bool returnval = false; try { + IDbCommand result = Query(sql, parameters); + //Console.WriteLine(result.CommandText); + if (result.ExecuteNonQuery() == 1) returnval = true; @@ -165,6 +179,7 @@ namespace OpenGrid.Framework.Data.MySQL } catch (Exception e) { + Console.WriteLine(e.ToString()); return false; } diff --git a/OpenGrid.Framework.Data/SimProfileData.cs b/OpenGrid.Framework.Data/SimProfileData.cs index d5a5392a8c..f86fb95fce 100644 --- a/OpenGrid.Framework.Data/SimProfileData.cs +++ b/OpenGrid.Framework.Data/SimProfileData.cs @@ -9,7 +9,7 @@ namespace OpenGrid.Framework.Data /// /// The name of the region /// - public string regionName; + public string regionName = ""; /// /// A 64-bit number combining map position into a (mostly) unique ID @@ -32,9 +32,9 @@ namespace OpenGrid.Framework.Data /// Authentication secrets /// /// Not very secure, needs improvement. - public string regionSendKey; - public string regionRecvKey; - public string regionSecret; + public string regionSendKey = ""; + public string regionRecvKey = ""; + public string regionSecret = ""; /// /// Whether the region is online @@ -44,9 +44,9 @@ namespace OpenGrid.Framework.Data /// /// Information about the server that the region is currently hosted on /// - public string serverIP; + public string serverIP = ""; public uint serverPort; - public string serverURI; + public string serverURI = ""; /// /// Set of optional overrides. Can be used to create non-eulicidean spaces. @@ -60,20 +60,20 @@ namespace OpenGrid.Framework.Data /// Optional: URI Location of the region database /// /// Used for floating sim pools where the region data is not nessecarily coupled to a specific server - public string regionDataURI; + public string regionDataURI = ""; /// /// Region Asset Details /// - public string regionAssetURI; - public string regionAssetSendKey; - public string regionAssetRecvKey; + public string regionAssetURI = ""; + public string regionAssetSendKey = ""; + public string regionAssetRecvKey = ""; /// /// Region Userserver Details /// - public string regionUserURI; - public string regionUserSendKey; - public string regionUserRecvKey; + public string regionUserURI = ""; + public string regionUserSendKey = ""; + public string regionUserRecvKey = ""; } } diff --git a/OpenGrid.Framework.Data/UserProfileData.cs b/OpenGrid.Framework.Data/UserProfileData.cs index 3a5482889f..8d72c6baf0 100644 --- a/OpenGrid.Framework.Data/UserProfileData.cs +++ b/OpenGrid.Framework.Data/UserProfileData.cs @@ -15,6 +15,8 @@ namespace OpenGrid.Framework.Data public ulong homeRegion; // RegionHandle of home public LLVector3 homeLocation; // Home Location inside the sim + public LLVector3 homeLookAt; // Coordinates where the user is looking + public int created; // UNIX Epoch Timestamp (User Creation) public int lastLogin; // UNIX Epoch Timestamp (Last Login Time) diff --git a/OpenGridServices.GridServer/GridManager.cs b/OpenGridServices.GridServer/GridManager.cs index 02a6a50170..cfccd02276 100644 --- a/OpenGridServices.GridServer/GridManager.cs +++ b/OpenGridServices.GridServer/GridManager.cs @@ -16,7 +16,7 @@ namespace OpenGridServices.GridServer class GridManager { Dictionary _plugins = new Dictionary(); - public string defaultRecvKey; + public OpenSim.Framework.Interfaces.GridConfig config; /// /// Adds a new grid server plugin - grid servers will be requested in the order they were loaded. @@ -269,7 +269,7 @@ namespace OpenGridServices.GridServer TheSim = new SimProfileData(); LLUUID UUID = new LLUUID(param); TheSim.UUID = UUID; - TheSim.regionRecvKey = defaultRecvKey; + TheSim.regionRecvKey = config.SimRecvKey; } XmlDocument doc = new XmlDocument(); @@ -291,6 +291,20 @@ namespace OpenGridServices.GridServer { return "ERROR! invalid key"; } + + //TheSim.regionSendKey = Cfg; + TheSim.regionRecvKey = config.SimRecvKey; + TheSim.regionSendKey = config.SimSendKey; + TheSim.regionSecret = config.SimRecvKey; + TheSim.regionDataURI = ""; + TheSim.regionAssetURI = config.DefaultAssetServer; + TheSim.regionAssetRecvKey = config.AssetRecvKey; + TheSim.regionAssetSendKey = config.AssetSendKey; + TheSim.regionUserURI = config.DefaultUserServer; + TheSim.regionUserSendKey = config.UserSendKey; + TheSim.regionUserRecvKey = config.UserRecvKey; + + for (int i = 0; i < simnode.ChildNodes.Count; i++) { switch (simnode.ChildNodes[i].Name) @@ -319,6 +333,8 @@ namespace OpenGridServices.GridServer } } + TheSim.serverURI = "http://" + TheSim.serverIP + ":" + TheSim.serverPort + "/"; + try { OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Attempting to add a new region to the grid - " + _plugins.Count + " storage provider(s) registered."); diff --git a/OpenGridServices.GridServer/Main.cs b/OpenGridServices.GridServer/Main.cs index 532e15da0a..69d75fd07c 100644 --- a/OpenGridServices.GridServer/Main.cs +++ b/OpenGridServices.GridServer/Main.cs @@ -47,7 +47,7 @@ namespace OpenGridServices.GridServer public class OpenGrid_Main : BaseServer, conscmd_callback { private string ConfigDll = "OpenGrid.Config.GridConfigDb4o.dll"; - private string GridDll = "OpenGrid.Framework.Data.DB4o.dll"; + private string GridDll = "OpenGrid.Framework.Data.MySQL.dll"; public GridConfig Cfg; public static OpenGrid_Main thegrid; @@ -98,7 +98,7 @@ namespace OpenGridServices.GridServer m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Connecting to Storage Server"); m_gridManager = new GridManager(); m_gridManager.AddPlugin(GridDll); // Made of win - m_gridManager.defaultRecvKey = Cfg.SimRecvKey; + m_gridManager.config = Cfg; m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Starting HTTP process"); BaseHttpServer httpServer = new BaseHttpServer(8001); diff --git a/SQL/regions.sql b/SQL/mysql-regions.sql similarity index 100% rename from SQL/regions.sql rename to SQL/mysql-regions.sql