* Fixed MySQL Grid Manager

* Added preliminary support for DB UserServer (incomplete)
* Added better handling of defaults to Grid Manager.
* Renamed SQL/regions.sql to SQL/mysql-regions.sql.
zircon^2
Adam Frisby 2007-05-13 14:59:24 +00:00
parent 5917d36219
commit b110179730
7 changed files with 143 additions and 85 deletions

View File

@ -14,7 +14,7 @@ namespace OpenGrid.Framework.Data.MySQL
/// </summary> /// </summary>
public void Initialise() public void Initialise()
{ {
database = new MySQLManager("localhost", "db", "user", "password", "false"); database = new MySQLManager("server", "database", "username", "password", "false");
} }
/// <summary> /// <summary>
@ -41,19 +41,30 @@ namespace OpenGrid.Framework.Data.MySQL
/// <param name="handle">Region location handle</param> /// <param name="handle">Region location handle</param>
/// <returns>Sim profile</returns> /// <returns>Sim profile</returns>
public SimProfileData GetProfileByHandle(ulong handle) public SimProfileData GetProfileByHandle(ulong handle)
{
try
{
lock (database)
{ {
Dictionary<string, string> param = new Dictionary<string, string>(); Dictionary<string, string> param = new Dictionary<string, string>();
param["handle"] = handle.ToString(); param["?handle"] = handle.ToString();
System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE handle = @handle", param); System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE regionHandle = ?handle", param);
System.Data.IDataReader reader = result.ExecuteReader(); System.Data.IDataReader reader = result.ExecuteReader();
SimProfileData row = database.getRow( reader ); SimProfileData row = database.getSimRow(reader);
reader.Close(); reader.Close();
result.Dispose(); result.Dispose();
return row; return row;
} }
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return null;
}
}
/// <summary> /// <summary>
/// Returns a sim profile from it's UUID /// Returns a sim profile from it's UUID
@ -61,21 +72,34 @@ namespace OpenGrid.Framework.Data.MySQL
/// <param name="uuid">The region UUID</param> /// <param name="uuid">The region UUID</param>
/// <returns>The sim profile</returns> /// <returns>The sim profile</returns>
public SimProfileData GetProfileByLLUUID(libsecondlife.LLUUID uuid) public SimProfileData GetProfileByLLUUID(libsecondlife.LLUUID uuid)
{
try
{
lock (database)
{ {
Dictionary<string, string> param = new Dictionary<string, string>(); Dictionary<string, string> param = new Dictionary<string, string>();
param["uuid"] = uuid.ToStringHyphenated(); param["?uuid"] = uuid.ToStringHyphenated();
System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param); System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = ?uuid", param);
System.Data.IDataReader reader = result.ExecuteReader(); System.Data.IDataReader reader = result.ExecuteReader();
SimProfileData row = database.getRow(reader); SimProfileData row = database.getSimRow(reader);
reader.Close(); reader.Close();
result.Dispose(); result.Dispose();
return row; return row;
} }
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return null;
}
}
public DataResponse AddProfile(SimProfileData profile) public DataResponse AddProfile(SimProfileData profile)
{
lock (database)
{ {
if (database.insertRow(profile)) if (database.insertRow(profile))
{ {
@ -86,6 +110,7 @@ namespace OpenGrid.Framework.Data.MySQL
return DataResponse.RESPONSE_ERROR; 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.

View File

@ -29,7 +29,7 @@ namespace OpenGrid.Framework.Data.MySQL
{ {
try 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 = new MySqlConnection(connectionString);
dbcon.Open(); dbcon.Open();
@ -56,6 +56,8 @@ namespace OpenGrid.Framework.Data.MySQL
/// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param> /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param>
/// <returns>A MySQL DB Command</returns> /// <returns>A MySQL DB Command</returns>
public IDbCommand Query(string sql, Dictionary<string, string> parameters) public IDbCommand Query(string sql, Dictionary<string, string> parameters)
{
try
{ {
MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand(); MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
dbcommand.CommandText = sql; dbcommand.CommandText = sql;
@ -66,15 +68,21 @@ namespace OpenGrid.Framework.Data.MySQL
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(); SimProfileData retval = new SimProfileData();
if (reader.Read()) if (reader.Read())
{ {
// Region Main // Region Main
retval.regionHandle = (ulong)reader["regionHandle"]; retval.regionHandle = Convert.ToUInt64(reader["regionHandle"].ToString());
retval.regionName = (string)reader["regionName"]; retval.regionName = (string)reader["regionName"];
retval.UUID = new libsecondlife.LLUUID((string)reader["uuid"]); retval.UUID = new libsecondlife.LLUUID((string)reader["uuid"]);
@ -91,15 +99,15 @@ namespace OpenGrid.Framework.Data.MySQL
retval.serverURI = (string)reader["serverURI"]; retval.serverURI = (string)reader["serverURI"];
// Location // Location
retval.regionLocX = (uint)((int)reader["locX"]); retval.regionLocX = Convert.ToUInt32(reader["locX"].ToString());
retval.regionLocY = (uint)((int)reader["locY"]); retval.regionLocY = Convert.ToUInt32(reader["locY"].ToString());
retval.regionLocZ = (uint)((int)reader["locZ"]); retval.regionLocZ = Convert.ToUInt32(reader["locZ"].ToString());
// Neighbours - 0 = No Override // Neighbours - 0 = No Override
retval.regionEastOverrideHandle = (ulong)reader["eastOverrideHandle"]; retval.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"].ToString());
retval.regionWestOverrideHandle = (ulong)reader["westOverrideHandle"]; retval.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"].ToString());
retval.regionSouthOverrideHandle = (ulong)reader["southOverrideHandle"]; retval.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"].ToString());
retval.regionNorthOverrideHandle = (ulong)reader["northOverrideHandle"]; retval.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"].ToString());
// Assets // Assets
retval.regionAssetURI = (string)reader["regionAssetURI"]; retval.regionAssetURI = (string)reader["regionAssetURI"];
@ -113,51 +121,57 @@ namespace OpenGrid.Framework.Data.MySQL
} }
else else
{ {
throw new Exception("No rows to return"); throw new Exception("Unable to find region at coordinates");
return null;
} }
return retval; return retval;
} }
public bool insertRow(SimProfileData profile) { public bool insertRow(SimProfileData profile)
string sql = "REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, "; {
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 += "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, ";
sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES "; sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES ";
sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, "; sql += "(?regionHandle, ?regionName, ?uuid, ?regionRecvKey, ?regionSecret, ?regionSendKey, ?regionDataURI, ";
sql += "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, "; sql += "?serverIP, ?serverPort, ?serverURI, ?locX, ?locY, ?locZ, ?eastOverrideHandle, ?westOverrideHandle, ?southOverrideHandle, ?northOverrideHandle, ?regionAssetURI, ?regionAssetRecvKey, ";
sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey);"; sql += "?regionAssetSendKey, ?regionUserURI, ?regionUserRecvKey, ?regionUserSendKey);";
Dictionary<string, string> parameters = new Dictionary<string, string>(); Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["regionHandle"] = profile.regionHandle.ToString(); parameters["?regionHandle"] = profile.regionHandle.ToString();
parameters["regionName"] = profile.regionName; parameters["?regionName"] = profile.regionName.ToString();
parameters["uuid"] = profile.UUID.ToString(); parameters["?uuid"] = profile.UUID.ToStringHyphenated();
parameters["regionRecvKey"] = profile.regionRecvKey; parameters["?regionRecvKey"] = profile.regionRecvKey.ToString();
parameters["regionSendKey"] = profile.regionSendKey; parameters["?regionSecret"] = profile.regionSecret.ToString();
parameters["regionDataURI"] = profile.regionDataURI; parameters["?regionSendKey"] = profile.regionSendKey.ToString();
parameters["serverIP"] = profile.serverIP; parameters["?regionDataURI"] = profile.regionDataURI.ToString();
parameters["serverPort"] = profile.serverPort.ToString(); parameters["?serverIP"] = profile.serverIP.ToString();
parameters["serverURI"] = profile.serverURI; parameters["?serverPort"] = profile.serverPort.ToString();
parameters["locX"] = profile.regionLocX.ToString(); parameters["?serverURI"] = profile.serverURI.ToString();
parameters["locY"] = profile.regionLocY.ToString(); parameters["?locX"] = profile.regionLocX.ToString();
parameters["locZ"] = profile.regionLocZ.ToString(); parameters["?locY"] = profile.regionLocY.ToString();
parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString(); parameters["?locZ"] = profile.regionLocZ.ToString();
parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString(); parameters["?eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString();
parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString(); parameters["?westOverrideHandle"] = profile.regionWestOverrideHandle.ToString();
parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString(); parameters["?northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString();
parameters["regionAssetURI"] = profile.regionAssetURI; parameters["?southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString();
parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey; parameters["?regionAssetURI"] = profile.regionAssetURI.ToString();
parameters["regionAssetSendKey"] = profile.regionAssetSendKey; parameters["?regionAssetRecvKey"] = profile.regionAssetRecvKey.ToString();
parameters["regionUserURI"] = profile.regionUserURI; parameters["?regionAssetSendKey"] = profile.regionAssetSendKey.ToString();
parameters["regionUserRecvKey"] = profile.regionUserRecvKey; parameters["?regionUserURI"] = profile.regionUserURI.ToString();
parameters["regionUserSendKey"] = profile.regionUserSendKey; parameters["?regionUserRecvKey"] = profile.regionUserRecvKey.ToString();
parameters["?regionUserSendKey"] = profile.regionUserSendKey.ToString();
bool returnval = false; bool returnval = false;
try try
{ {
IDbCommand result = Query(sql, parameters); IDbCommand result = Query(sql, parameters);
//Console.WriteLine(result.CommandText);
if (result.ExecuteNonQuery() == 1) if (result.ExecuteNonQuery() == 1)
returnval = true; returnval = true;
@ -165,6 +179,7 @@ namespace OpenGrid.Framework.Data.MySQL
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine(e.ToString());
return false; return false;
} }

View File

@ -9,7 +9,7 @@ namespace OpenGrid.Framework.Data
/// <summary> /// <summary>
/// The name of the region /// The name of the region
/// </summary> /// </summary>
public string regionName; public string regionName = "";
/// <summary> /// <summary>
/// A 64-bit number combining map position into a (mostly) unique ID /// A 64-bit number combining map position into a (mostly) unique ID
@ -32,9 +32,9 @@ namespace OpenGrid.Framework.Data
/// Authentication secrets /// Authentication secrets
/// </summary> /// </summary>
/// <remarks>Not very secure, needs improvement.</remarks> /// <remarks>Not very secure, needs improvement.</remarks>
public string regionSendKey; public string regionSendKey = "";
public string regionRecvKey; public string regionRecvKey = "";
public string regionSecret; public string regionSecret = "";
/// <summary> /// <summary>
/// Whether the region is online /// Whether the region is online
@ -44,9 +44,9 @@ namespace OpenGrid.Framework.Data
/// <summary> /// <summary>
/// Information about the server that the region is currently hosted on /// Information about the server that the region is currently hosted on
/// </summary> /// </summary>
public string serverIP; public string serverIP = "";
public uint serverPort; public uint serverPort;
public string serverURI; public string serverURI = "";
/// <summary> /// <summary>
/// Set of optional overrides. Can be used to create non-eulicidean spaces. /// 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 /// Optional: URI Location of the region database
/// </summary> /// </summary>
/// <remarks>Used for floating sim pools where the region data is not nessecarily coupled to a specific server</remarks> /// <remarks>Used for floating sim pools where the region data is not nessecarily coupled to a specific server</remarks>
public string regionDataURI; public string regionDataURI = "";
/// <summary> /// <summary>
/// Region Asset Details /// Region Asset Details
/// </summary> /// </summary>
public string regionAssetURI; public string regionAssetURI = "";
public string regionAssetSendKey; public string regionAssetSendKey = "";
public string regionAssetRecvKey; public string regionAssetRecvKey = "";
/// <summary> /// <summary>
/// Region Userserver Details /// Region Userserver Details
/// </summary> /// </summary>
public string regionUserURI; public string regionUserURI = "";
public string regionUserSendKey; public string regionUserSendKey = "";
public string regionUserRecvKey; public string regionUserRecvKey = "";
} }
} }

View File

@ -15,6 +15,8 @@ namespace OpenGrid.Framework.Data
public ulong homeRegion; // RegionHandle of home public ulong homeRegion; // RegionHandle of home
public LLVector3 homeLocation; // Home Location inside the sim 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 created; // UNIX Epoch Timestamp (User Creation)
public int lastLogin; // UNIX Epoch Timestamp (Last Login Time) public int lastLogin; // UNIX Epoch Timestamp (Last Login Time)

View File

@ -16,7 +16,7 @@ namespace OpenGridServices.GridServer
class GridManager class GridManager
{ {
Dictionary<string, IGridData> _plugins = new Dictionary<string, IGridData>(); Dictionary<string, IGridData> _plugins = new Dictionary<string, IGridData>();
public string defaultRecvKey; public OpenSim.Framework.Interfaces.GridConfig config;
/// <summary> /// <summary>
/// Adds a new grid server plugin - grid servers will be requested in the order they were loaded. /// 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(); TheSim = new SimProfileData();
LLUUID UUID = new LLUUID(param); LLUUID UUID = new LLUUID(param);
TheSim.UUID = UUID; TheSim.UUID = UUID;
TheSim.regionRecvKey = defaultRecvKey; TheSim.regionRecvKey = config.SimRecvKey;
} }
XmlDocument doc = new XmlDocument(); XmlDocument doc = new XmlDocument();
@ -291,6 +291,20 @@ namespace OpenGridServices.GridServer
{ {
return "ERROR! invalid key"; 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++) for (int i = 0; i < simnode.ChildNodes.Count; i++)
{ {
switch (simnode.ChildNodes[i].Name) switch (simnode.ChildNodes[i].Name)
@ -319,6 +333,8 @@ namespace OpenGridServices.GridServer
} }
} }
TheSim.serverURI = "http://" + TheSim.serverIP + ":" + TheSim.serverPort + "/";
try 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."); 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.");

View File

@ -47,7 +47,7 @@ namespace OpenGridServices.GridServer
public class OpenGrid_Main : BaseServer, conscmd_callback public class OpenGrid_Main : BaseServer, conscmd_callback
{ {
private string ConfigDll = "OpenGrid.Config.GridConfigDb4o.dll"; 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 GridConfig Cfg;
public static OpenGrid_Main thegrid; 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_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Connecting to Storage Server");
m_gridManager = new GridManager(); m_gridManager = new GridManager();
m_gridManager.AddPlugin(GridDll); // Made of win 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"); m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Starting HTTP process");
BaseHttpServer httpServer = new BaseHttpServer(8001); BaseHttpServer httpServer = new BaseHttpServer(8001);