* 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>
public void Initialise()
{
database = new MySQLManager("localhost", "db", "user", "password", "false");
database = new MySQLManager("server", "database", "username", "password", "false");
}
/// <summary>
@ -42,17 +42,28 @@ namespace OpenGrid.Framework.Data.MySQL
/// <returns>Sim profile</returns>
public SimProfileData GetProfileByHandle(ulong handle)
{
Dictionary<string,string> param = new Dictionary<string,string>();
param["handle"] = handle.ToString();
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
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;
}
}
/// <summary>
@ -62,28 +73,42 @@ namespace OpenGrid.Framework.Data.MySQL
/// <returns>The sim profile</returns>
public SimProfileData GetProfileByLLUUID(libsecondlife.LLUUID uuid)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["uuid"] = uuid.ToStringHyphenated();
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
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;
}
}
}

View File

@ -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
/// <returns>A MySQL DB Command</returns>
public IDbCommand Query(string sql, Dictionary<string, string> parameters)
{
MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
dbcommand.CommandText = sql;
foreach (KeyValuePair<string, string> param in parameters)
try
{
dbcommand.Parameters.Add(param.Key, param.Value);
}
MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
dbcommand.CommandText = sql;
foreach (KeyValuePair<string, string> 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<string, string> parameters = new Dictionary<string,string>();
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;
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;
}

View File

@ -9,7 +9,7 @@ namespace OpenGrid.Framework.Data
/// <summary>
/// The name of the region
/// </summary>
public string regionName;
public string regionName = "";
/// <summary>
/// A 64-bit number combining map position into a (mostly) unique ID
@ -32,9 +32,9 @@ namespace OpenGrid.Framework.Data
/// Authentication secrets
/// </summary>
/// <remarks>Not very secure, needs improvement.</remarks>
public string regionSendKey;
public string regionRecvKey;
public string regionSecret;
public string regionSendKey = "";
public string regionRecvKey = "";
public string regionSecret = "";
/// <summary>
/// Whether the region is online
@ -44,9 +44,9 @@ namespace OpenGrid.Framework.Data
/// <summary>
/// Information about the server that the region is currently hosted on
/// </summary>
public string serverIP;
public string serverIP = "";
public uint serverPort;
public string serverURI;
public string serverURI = "";
/// <summary>
/// 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
/// </summary>
/// <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>
/// Region Asset Details
/// </summary>
public string regionAssetURI;
public string regionAssetSendKey;
public string regionAssetRecvKey;
public string regionAssetURI = "";
public string regionAssetSendKey = "";
public string regionAssetRecvKey = "";
/// <summary>
/// Region Userserver Details
/// </summary>
public string regionUserURI;
public string regionUserSendKey;
public string regionUserRecvKey;
public string regionUserURI = "";
public string regionUserSendKey = "";
public string regionUserRecvKey = "";
}
}

View File

@ -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)

View File

@ -16,7 +16,7 @@ namespace OpenGridServices.GridServer
class GridManager
{
Dictionary<string, IGridData> _plugins = new Dictionary<string, IGridData>();
public string defaultRecvKey;
public OpenSim.Framework.Interfaces.GridConfig config;
/// <summary>
/// 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.");

View File

@ -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);