aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenGrid.Framework.Data.MySQL/MySQLGridData.cs')
-rw-r--r--OpenGrid.Framework.Data.MySQL/MySQLGridData.cs193
1 files changed, 0 insertions, 193 deletions
diff --git a/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs b/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs
deleted file mode 100644
index 46183b4..0000000
--- a/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs
+++ /dev/null
@@ -1,193 +0,0 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenGrid.Framework.Data;
5
6namespace OpenGrid.Framework.Data.MySQL
7{
8 public class MySQLGridData : IGridData
9 {
10 private MySQLManager database;
11
12 /// <summary>
13 /// Initialises the Grid Interface
14 /// </summary>
15 public void Initialise()
16 {
17 database = new MySQLManager("localhost", "database", "username", "password", "false");
18 }
19
20 /// <summary>
21 /// Shuts down the grid interface
22 /// </summary>
23 public void Close()
24 {
25 database.Close();
26 }
27
28 public string getName()
29 {
30 return "MySql OpenGridData";
31 }
32
33 public string getVersion()
34 {
35 return "0.1";
36 }
37
38 public SimProfileData[] GetProfilesInRange(uint xmin, uint ymin, uint xmax, uint ymax)
39 {
40 try
41 {
42 lock (database)
43 {
44 Dictionary<string, string> param = new Dictionary<string, string>();
45 param["?xmin"] = xmin.ToString();
46 param["?ymin"] = ymin.ToString();
47 param["?xmax"] = xmax.ToString();
48 param["?ymax"] = ymax.ToString();
49
50 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE locX >= ?xmin AND locX <= ?xmax AND locY >= ?ymin AND locY <= ?ymax", param);
51 System.Data.IDataReader reader = result.ExecuteReader();
52
53 SimProfileData row;
54
55 List<SimProfileData> rows = new List<SimProfileData>();
56
57 while ((row = database.getSimRow(reader)) != null)
58 {
59 rows.Add(row);
60 }
61 reader.Close();
62 result.Dispose();
63
64 return rows.ToArray();
65
66 }
67 }
68 catch (Exception e)
69 {
70 Console.WriteLine(e.ToString());
71 return null;
72 }
73 }
74
75 /// <summary>
76 /// Returns a sim profile from it's location
77 /// </summary>
78 /// <param name="handle">Region location handle</param>
79 /// <returns>Sim profile</returns>
80 public SimProfileData GetProfileByHandle(ulong handle)
81 {
82 try
83 {
84 lock (database)
85 {
86 Dictionary<string, string> param = new Dictionary<string, string>();
87 param["?handle"] = handle.ToString();
88
89 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE regionHandle = ?handle", param);
90 System.Data.IDataReader reader = result.ExecuteReader();
91
92 SimProfileData row = database.getSimRow(reader);
93 reader.Close();
94 result.Dispose();
95
96 return row;
97 }
98 }
99 catch (Exception e)
100 {
101 Console.WriteLine(e.ToString());
102 return null;
103 }
104 }
105
106 /// <summary>
107 /// Returns a sim profile from it's UUID
108 /// </summary>
109 /// <param name="uuid">The region UUID</param>
110 /// <returns>The sim profile</returns>
111 public SimProfileData GetProfileByLLUUID(libsecondlife.LLUUID uuid)
112 {
113 try
114 {
115 lock (database)
116 {
117 Dictionary<string, string> param = new Dictionary<string, string>();
118 param["?uuid"] = uuid.ToStringHyphenated();
119
120 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = ?uuid", param);
121 System.Data.IDataReader reader = result.ExecuteReader();
122
123 SimProfileData row = database.getSimRow(reader);
124 reader.Close();
125 result.Dispose();
126
127 return row;
128 }
129 }
130 catch (Exception e)
131 {
132 Console.WriteLine(e.ToString());
133 return null;
134 }
135 }
136
137 public DataResponse AddProfile(SimProfileData profile)
138 {
139 lock (database)
140 {
141 if (database.insertRow(profile))
142 {
143 return DataResponse.RESPONSE_OK;
144 }
145 else
146 {
147 return DataResponse.RESPONSE_ERROR;
148 }
149 }
150 }
151
152 /// <summary>
153 /// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret.
154 /// </summary>
155 /// <param name="uuid">The UUID of the challenger</param>
156 /// <param name="handle">The attempted regionHandle of the challenger</param>
157 /// <param name="authkey">The secret</param>
158 /// <returns>Whether the secret and regionhandle match the database entry for UUID</returns>
159 public bool AuthenticateSim(libsecondlife.LLUUID uuid, ulong handle, string authkey)
160 {
161 bool throwHissyFit = false; // Should be true by 1.0
162
163 if (throwHissyFit)
164 throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential.");
165
166 SimProfileData data = GetProfileByLLUUID(uuid);
167
168 return (handle == data.regionHandle && authkey == data.regionSecret);
169 }
170
171 /// <summary>
172 /// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region
173 /// </summary>
174 /// <remarks>This requires a security audit.</remarks>
175 /// <param name="uuid"></param>
176 /// <param name="handle"></param>
177 /// <param name="authhash"></param>
178 /// <param name="challenge"></param>
179 /// <returns></returns>
180 public bool AuthenticateSim(libsecondlife.LLUUID uuid, ulong handle, string authhash, string challenge)
181 {
182 System.Security.Cryptography.SHA512Managed HashProvider = new System.Security.Cryptography.SHA512Managed();
183 System.Text.ASCIIEncoding TextProvider = new ASCIIEncoding();
184
185 byte[] stream = TextProvider.GetBytes(uuid.ToStringHyphenated() + ":" + handle.ToString() + ":" + challenge);
186 byte[] hash = HashProvider.ComputeHash(stream);
187
188 return false;
189 }
190 }
191
192
193}