aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGrid.Framework.Data
diff options
context:
space:
mode:
authorAdam Frisby2007-05-13 14:59:24 +0000
committerAdam Frisby2007-05-13 14:59:24 +0000
commitb1101797307504cfc2eea6317d4c4dc2b5964480 (patch)
tree35d7ec88ff9ce0171260ba7166bc6cb3c1fcbb4d /OpenGrid.Framework.Data
parentInventory should be working again in sandbox mode (diff)
downloadopensim-SC_OLD-b1101797307504cfc2eea6317d4c4dc2b5964480.zip
opensim-SC_OLD-b1101797307504cfc2eea6317d4c4dc2b5964480.tar.gz
opensim-SC_OLD-b1101797307504cfc2eea6317d4c4dc2b5964480.tar.bz2
opensim-SC_OLD-b1101797307504cfc2eea6317d4c4dc2b5964480.tar.xz
* 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.
Diffstat (limited to '')
-rw-r--r--OpenGrid.Framework.Data.MySQL/MySQLGridData.cs71
-rw-r--r--OpenGrid.Framework.Data.MySQL/MySQLManager.cs109
-rw-r--r--OpenGrid.Framework.Data/SimProfileData.cs26
-rw-r--r--OpenGrid.Framework.Data/UserProfileData.cs2
4 files changed, 125 insertions, 83 deletions
diff --git a/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs b/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs
index 4404a16..3dceff6 100644
--- a/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs
+++ b/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs
@@ -14,7 +14,7 @@ namespace OpenGrid.Framework.Data.MySQL
14 /// </summary> 14 /// </summary>
15 public void Initialise() 15 public void Initialise()
16 { 16 {
17 database = new MySQLManager("localhost", "db", "user", "password", "false"); 17 database = new MySQLManager("server", "database", "username", "password", "false");
18 } 18 }
19 19
20 /// <summary> 20 /// <summary>
@@ -42,17 +42,28 @@ namespace OpenGrid.Framework.Data.MySQL
42 /// <returns>Sim profile</returns> 42 /// <returns>Sim profile</returns>
43 public SimProfileData GetProfileByHandle(ulong handle) 43 public SimProfileData GetProfileByHandle(ulong handle)
44 { 44 {
45 Dictionary<string,string> param = new Dictionary<string,string>(); 45 try
46 param["handle"] = handle.ToString(); 46 {
47 lock (database)
48 {
49 Dictionary<string, string> param = new Dictionary<string, string>();
50 param["?handle"] = handle.ToString();
47 51
48 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE handle = @handle", param); 52 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE regionHandle = ?handle", param);
49 System.Data.IDataReader reader = result.ExecuteReader(); 53 System.Data.IDataReader reader = result.ExecuteReader();
50 54
51 SimProfileData row = database.getRow( reader ); 55 SimProfileData row = database.getSimRow(reader);
52 reader.Close(); 56 reader.Close();
53 result.Dispose(); 57 result.Dispose();
54 58
55 return row; 59 return row;
60 }
61 }
62 catch (Exception e)
63 {
64 Console.WriteLine(e.ToString());
65 return null;
66 }
56 } 67 }
57 68
58 /// <summary> 69 /// <summary>
@@ -62,28 +73,42 @@ namespace OpenGrid.Framework.Data.MySQL
62 /// <returns>The sim profile</returns> 73 /// <returns>The sim profile</returns>
63 public SimProfileData GetProfileByLLUUID(libsecondlife.LLUUID uuid) 74 public SimProfileData GetProfileByLLUUID(libsecondlife.LLUUID uuid)
64 { 75 {
65 Dictionary<string, string> param = new Dictionary<string, string>(); 76 try
66 param["uuid"] = uuid.ToStringHyphenated(); 77 {
78 lock (database)
79 {
80 Dictionary<string, string> param = new Dictionary<string, string>();
81 param["?uuid"] = uuid.ToStringHyphenated();
67 82
68 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param); 83 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = ?uuid", param);
69 System.Data.IDataReader reader = result.ExecuteReader(); 84 System.Data.IDataReader reader = result.ExecuteReader();
70 85
71 SimProfileData row = database.getRow(reader); 86 SimProfileData row = database.getSimRow(reader);
72 reader.Close(); 87 reader.Close();
73 result.Dispose(); 88 result.Dispose();
74 89
75 return row; 90 return row;
91 }
92 }
93 catch (Exception e)
94 {
95 Console.WriteLine(e.ToString());
96 return null;
97 }
76 } 98 }
77 99
78 public DataResponse AddProfile(SimProfileData profile) 100 public DataResponse AddProfile(SimProfileData profile)
79 { 101 {
80 if (database.insertRow(profile)) 102 lock (database)
81 {
82 return DataResponse.RESPONSE_OK;
83 }
84 else
85 { 103 {
86 return DataResponse.RESPONSE_ERROR; 104 if (database.insertRow(profile))
105 {
106 return DataResponse.RESPONSE_OK;
107 }
108 else
109 {
110 return DataResponse.RESPONSE_ERROR;
111 }
87 } 112 }
88 } 113 }
89 114
diff --git a/OpenGrid.Framework.Data.MySQL/MySQLManager.cs b/OpenGrid.Framework.Data.MySQL/MySQLManager.cs
index d3bfa18..7461b14 100644
--- a/OpenGrid.Framework.Data.MySQL/MySQLManager.cs
+++ b/OpenGrid.Framework.Data.MySQL/MySQLManager.cs
@@ -29,7 +29,7 @@ namespace OpenGrid.Framework.Data.MySQL
29 { 29 {
30 try 30 try
31 { 31 {
32 string connectionString = "Server=" + hostname + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";"; 32 string connectionString = "Server=" + hostname + ";Port=13306;Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";";
33 dbcon = new MySqlConnection(connectionString); 33 dbcon = new MySqlConnection(connectionString);
34 34
35 dbcon.Open(); 35 dbcon.Open();
@@ -57,24 +57,32 @@ namespace OpenGrid.Framework.Data.MySQL
57 /// <returns>A MySQL DB Command</returns> 57 /// <returns>A MySQL DB Command</returns>
58 public IDbCommand Query(string sql, Dictionary<string, string> parameters) 58 public IDbCommand Query(string sql, Dictionary<string, string> parameters)
59 { 59 {
60 MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand(); 60 try
61 dbcommand.CommandText = sql;
62 foreach (KeyValuePair<string, string> param in parameters)
63 { 61 {
64 dbcommand.Parameters.Add(param.Key, param.Value); 62 MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
63 dbcommand.CommandText = sql;
64 foreach (KeyValuePair<string, string> param in parameters)
65 {
66 dbcommand.Parameters.Add(param.Key, param.Value);
67 }
68
69 return (IDbCommand)dbcommand;
70 }
71 catch (Exception e)
72 {
73 Console.WriteLine("Failed during Query generation: " + e.ToString());
74 return null;
65 } 75 }
66
67 return (IDbCommand)dbcommand;
68 } 76 }
69 77
70 public SimProfileData getRow(IDataReader reader) 78 public SimProfileData getSimRow(IDataReader reader)
71 { 79 {
72 SimProfileData retval = new SimProfileData(); 80 SimProfileData retval = new SimProfileData();
73 81
74 if (reader.Read()) 82 if (reader.Read())
75 { 83 {
76 // Region Main 84 // Region Main
77 retval.regionHandle = (ulong)reader["regionHandle"]; 85 retval.regionHandle = Convert.ToUInt64(reader["regionHandle"].ToString());
78 retval.regionName = (string)reader["regionName"]; 86 retval.regionName = (string)reader["regionName"];
79 retval.UUID = new libsecondlife.LLUUID((string)reader["uuid"]); 87 retval.UUID = new libsecondlife.LLUUID((string)reader["uuid"]);
80 88
@@ -91,15 +99,15 @@ namespace OpenGrid.Framework.Data.MySQL
91 retval.serverURI = (string)reader["serverURI"]; 99 retval.serverURI = (string)reader["serverURI"];
92 100
93 // Location 101 // Location
94 retval.regionLocX = (uint)((int)reader["locX"]); 102 retval.regionLocX = Convert.ToUInt32(reader["locX"].ToString());
95 retval.regionLocY = (uint)((int)reader["locY"]); 103 retval.regionLocY = Convert.ToUInt32(reader["locY"].ToString());
96 retval.regionLocZ = (uint)((int)reader["locZ"]); 104 retval.regionLocZ = Convert.ToUInt32(reader["locZ"].ToString());
97 105
98 // Neighbours - 0 = No Override 106 // Neighbours - 0 = No Override
99 retval.regionEastOverrideHandle = (ulong)reader["eastOverrideHandle"]; 107 retval.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"].ToString());
100 retval.regionWestOverrideHandle = (ulong)reader["westOverrideHandle"]; 108 retval.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"].ToString());
101 retval.regionSouthOverrideHandle = (ulong)reader["southOverrideHandle"]; 109 retval.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"].ToString());
102 retval.regionNorthOverrideHandle = (ulong)reader["northOverrideHandle"]; 110 retval.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"].ToString());
103 111
104 // Assets 112 // Assets
105 retval.regionAssetURI = (string)reader["regionAssetURI"]; 113 retval.regionAssetURI = (string)reader["regionAssetURI"];
@@ -113,51 +121,57 @@ namespace OpenGrid.Framework.Data.MySQL
113 } 121 }
114 else 122 else
115 { 123 {
116 throw new Exception("No rows to return"); 124 throw new Exception("Unable to find region at coordinates");
125 return null;
117 } 126 }
118 return retval; 127 return retval;
119 } 128 }
120 129
121 public bool insertRow(SimProfileData profile) { 130 public bool insertRow(SimProfileData profile)
122 string sql = "REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, "; 131 {
132 string sql = "REPLACE INTO regions (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, ";
123 sql += "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, "; 133 sql += "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, ";
124 sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES "; 134 sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES ";
125 135
126 sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, "; 136 sql += "(?regionHandle, ?regionName, ?uuid, ?regionRecvKey, ?regionSecret, ?regionSendKey, ?regionDataURI, ";
127 sql += "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, "; 137 sql += "?serverIP, ?serverPort, ?serverURI, ?locX, ?locY, ?locZ, ?eastOverrideHandle, ?westOverrideHandle, ?southOverrideHandle, ?northOverrideHandle, ?regionAssetURI, ?regionAssetRecvKey, ";
128 sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey);"; 138 sql += "?regionAssetSendKey, ?regionUserURI, ?regionUserRecvKey, ?regionUserSendKey);";
129 139
130 Dictionary<string, string> parameters = new Dictionary<string,string>(); 140 Dictionary<string, string> parameters = new Dictionary<string, string>();
131 141
132 parameters["regionHandle"] = profile.regionHandle.ToString(); 142 parameters["?regionHandle"] = profile.regionHandle.ToString();
133 parameters["regionName"] = profile.regionName; 143 parameters["?regionName"] = profile.regionName.ToString();
134 parameters["uuid"] = profile.UUID.ToString(); 144 parameters["?uuid"] = profile.UUID.ToStringHyphenated();
135 parameters["regionRecvKey"] = profile.regionRecvKey; 145 parameters["?regionRecvKey"] = profile.regionRecvKey.ToString();
136 parameters["regionSendKey"] = profile.regionSendKey; 146 parameters["?regionSecret"] = profile.regionSecret.ToString();
137 parameters["regionDataURI"] = profile.regionDataURI; 147 parameters["?regionSendKey"] = profile.regionSendKey.ToString();
138 parameters["serverIP"] = profile.serverIP; 148 parameters["?regionDataURI"] = profile.regionDataURI.ToString();
139 parameters["serverPort"] = profile.serverPort.ToString(); 149 parameters["?serverIP"] = profile.serverIP.ToString();
140 parameters["serverURI"] = profile.serverURI; 150 parameters["?serverPort"] = profile.serverPort.ToString();
141 parameters["locX"] = profile.regionLocX.ToString(); 151 parameters["?serverURI"] = profile.serverURI.ToString();
142 parameters["locY"] = profile.regionLocY.ToString(); 152 parameters["?locX"] = profile.regionLocX.ToString();
143 parameters["locZ"] = profile.regionLocZ.ToString(); 153 parameters["?locY"] = profile.regionLocY.ToString();
144 parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString(); 154 parameters["?locZ"] = profile.regionLocZ.ToString();
145 parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString(); 155 parameters["?eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString();
146 parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString(); 156 parameters["?westOverrideHandle"] = profile.regionWestOverrideHandle.ToString();
147 parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString(); 157 parameters["?northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString();
148 parameters["regionAssetURI"] = profile.regionAssetURI; 158 parameters["?southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString();
149 parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey; 159 parameters["?regionAssetURI"] = profile.regionAssetURI.ToString();
150 parameters["regionAssetSendKey"] = profile.regionAssetSendKey; 160 parameters["?regionAssetRecvKey"] = profile.regionAssetRecvKey.ToString();
151 parameters["regionUserURI"] = profile.regionUserURI; 161 parameters["?regionAssetSendKey"] = profile.regionAssetSendKey.ToString();
152 parameters["regionUserRecvKey"] = profile.regionUserRecvKey; 162 parameters["?regionUserURI"] = profile.regionUserURI.ToString();
153 parameters["regionUserSendKey"] = profile.regionUserSendKey; 163 parameters["?regionUserRecvKey"] = profile.regionUserRecvKey.ToString();
164 parameters["?regionUserSendKey"] = profile.regionUserSendKey.ToString();
154 165
155 bool returnval = false; 166 bool returnval = false;
156 167
157 try 168 try
158 { 169 {
170
159 IDbCommand result = Query(sql, parameters); 171 IDbCommand result = Query(sql, parameters);
160 172
173 //Console.WriteLine(result.CommandText);
174
161 if (result.ExecuteNonQuery() == 1) 175 if (result.ExecuteNonQuery() == 1)
162 returnval = true; 176 returnval = true;
163 177
@@ -165,6 +179,7 @@ namespace OpenGrid.Framework.Data.MySQL
165 } 179 }
166 catch (Exception e) 180 catch (Exception e)
167 { 181 {
182 Console.WriteLine(e.ToString());
168 return false; 183 return false;
169 } 184 }
170 185
diff --git a/OpenGrid.Framework.Data/SimProfileData.cs b/OpenGrid.Framework.Data/SimProfileData.cs
index d5a5392..f86fb95 100644
--- a/OpenGrid.Framework.Data/SimProfileData.cs
+++ b/OpenGrid.Framework.Data/SimProfileData.cs
@@ -9,7 +9,7 @@ namespace OpenGrid.Framework.Data
9 /// <summary> 9 /// <summary>
10 /// The name of the region 10 /// The name of the region
11 /// </summary> 11 /// </summary>
12 public string regionName; 12 public string regionName = "";
13 13
14 /// <summary> 14 /// <summary>
15 /// A 64-bit number combining map position into a (mostly) unique ID 15 /// A 64-bit number combining map position into a (mostly) unique ID
@@ -32,9 +32,9 @@ namespace OpenGrid.Framework.Data
32 /// Authentication secrets 32 /// Authentication secrets
33 /// </summary> 33 /// </summary>
34 /// <remarks>Not very secure, needs improvement.</remarks> 34 /// <remarks>Not very secure, needs improvement.</remarks>
35 public string regionSendKey; 35 public string regionSendKey = "";
36 public string regionRecvKey; 36 public string regionRecvKey = "";
37 public string regionSecret; 37 public string regionSecret = "";
38 38
39 /// <summary> 39 /// <summary>
40 /// Whether the region is online 40 /// Whether the region is online
@@ -44,9 +44,9 @@ namespace OpenGrid.Framework.Data
44 /// <summary> 44 /// <summary>
45 /// Information about the server that the region is currently hosted on 45 /// Information about the server that the region is currently hosted on
46 /// </summary> 46 /// </summary>
47 public string serverIP; 47 public string serverIP = "";
48 public uint serverPort; 48 public uint serverPort;
49 public string serverURI; 49 public string serverURI = "";
50 50
51 /// <summary> 51 /// <summary>
52 /// Set of optional overrides. Can be used to create non-eulicidean spaces. 52 /// Set of optional overrides. Can be used to create non-eulicidean spaces.
@@ -60,20 +60,20 @@ namespace OpenGrid.Framework.Data
60 /// Optional: URI Location of the region database 60 /// Optional: URI Location of the region database
61 /// </summary> 61 /// </summary>
62 /// <remarks>Used for floating sim pools where the region data is not nessecarily coupled to a specific server</remarks> 62 /// <remarks>Used for floating sim pools where the region data is not nessecarily coupled to a specific server</remarks>
63 public string regionDataURI; 63 public string regionDataURI = "";
64 64
65 /// <summary> 65 /// <summary>
66 /// Region Asset Details 66 /// Region Asset Details
67 /// </summary> 67 /// </summary>
68 public string regionAssetURI; 68 public string regionAssetURI = "";
69 public string regionAssetSendKey; 69 public string regionAssetSendKey = "";
70 public string regionAssetRecvKey; 70 public string regionAssetRecvKey = "";
71 71
72 /// <summary> 72 /// <summary>
73 /// Region Userserver Details 73 /// Region Userserver Details
74 /// </summary> 74 /// </summary>
75 public string regionUserURI; 75 public string regionUserURI = "";
76 public string regionUserSendKey; 76 public string regionUserSendKey = "";
77 public string regionUserRecvKey; 77 public string regionUserRecvKey = "";
78 } 78 }
79} 79}
diff --git a/OpenGrid.Framework.Data/UserProfileData.cs b/OpenGrid.Framework.Data/UserProfileData.cs
index 3a54828..8d72c6b 100644
--- a/OpenGrid.Framework.Data/UserProfileData.cs
+++ b/OpenGrid.Framework.Data/UserProfileData.cs
@@ -15,6 +15,8 @@ namespace OpenGrid.Framework.Data
15 15
16 public ulong homeRegion; // RegionHandle of home 16 public ulong homeRegion; // RegionHandle of home
17 public LLVector3 homeLocation; // Home Location inside the sim 17 public LLVector3 homeLocation; // Home Location inside the sim
18 public LLVector3 homeLookAt; // Coordinates where the user is looking
19
18 20
19 public int created; // UNIX Epoch Timestamp (User Creation) 21 public int created; // UNIX Epoch Timestamp (User Creation)
20 public int lastLogin; // UNIX Epoch Timestamp (Last Login Time) 22 public int lastLogin; // UNIX Epoch Timestamp (Last Login Time)