aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices.GridServer/GridManager.cs
diff options
context:
space:
mode:
authorAdam Frisby2007-05-04 06:53:32 +0000
committerAdam Frisby2007-05-04 06:53:32 +0000
commit9804b0e5f3fd75879d8da364f1e7b03b1d672564 (patch)
tree71cfa887b5a194eeb06c92d1b50e054958cc3229 /OpenGridServices.GridServer/GridManager.cs
parentGrid server V2.0! Now with extra crunchy SQL support. (diff)
downloadopensim-SC_OLD-9804b0e5f3fd75879d8da364f1e7b03b1d672564.zip
opensim-SC_OLD-9804b0e5f3fd75879d8da364f1e7b03b1d672564.tar.gz
opensim-SC_OLD-9804b0e5f3fd75879d8da364f1e7b03b1d672564.tar.bz2
opensim-SC_OLD-9804b0e5f3fd75879d8da364f1e7b03b1d672564.tar.xz
* Deleted old sim profiles
* Added new grid manager replacement
Diffstat (limited to '')
-rw-r--r--OpenGridServices.GridServer/GridManager.cs286
1 files changed, 286 insertions, 0 deletions
diff --git a/OpenGridServices.GridServer/GridManager.cs b/OpenGridServices.GridServer/GridManager.cs
new file mode 100644
index 0000000..0569816
--- /dev/null
+++ b/OpenGridServices.GridServer/GridManager.cs
@@ -0,0 +1,286 @@
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Text;
5using System.Reflection;
6using OpenGrid.Framework.Data;
7using OpenSim.Framework.Utilities;
8using OpenSim.Framework.Console;
9using OpenSim.Framework.Sims;
10using libsecondlife;
11using Nwc.XmlRpc;
12using System.Xml;
13
14namespace OpenGridServices.GridServer
15{
16 class GridManager
17 {
18 Dictionary<string, IGridData> _plugins = new Dictionary<string, IGridData>();
19
20 public void AddPlugin(string FileName)
21 {
22 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
23
24 foreach (Type pluginType in pluginAssembly.GetTypes())
25 {
26 if (pluginType.IsPublic)
27 {
28 if (!pluginType.IsAbstract)
29 {
30 Type typeInterface = pluginType.GetInterface("IGridData", true);
31
32 if (typeInterface != null)
33 {
34 IGridData plug = (IGridData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
35 plug.Initialise();
36 this._plugins.Add(plug.getName(),plug);
37
38 }
39
40 typeInterface = null;
41 }
42 }
43 }
44
45 pluginAssembly = null;
46 }
47
48 public SimProfileData getRegion(libsecondlife.LLUUID uuid)
49 {
50 foreach(KeyValuePair<string,IGridData> kvp in _plugins) {
51 try
52 {
53 return kvp.Value.GetProfileByLLUUID(uuid);
54 }
55 catch (Exception e)
56 {
57 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("getRegionPlugin UUID " + kvp.Key + " is made of fail: " + e.ToString());
58 }
59 }
60 return null;
61 }
62
63 public SimProfileData getRegion(ulong handle)
64 {
65 foreach (KeyValuePair<string, IGridData> kvp in _plugins)
66 {
67 try
68 {
69 return kvp.Value.GetProfileByHandle(handle);
70 }
71 catch (Exception e)
72 {
73 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("getRegionPlugin Handle " + kvp.Key + " is made of fail: " + e.ToString());
74 }
75 }
76 return null;
77 }
78
79 /// <summary>
80 /// Returns a XML String containing a list of the neighbouring regions
81 /// </summary>
82 /// <param name="reqhandle">The regionhandle for the center sim</param>
83 /// <returns>An XML string containing neighbour entities</returns>
84 public string GetXMLNeighbours(ulong reqhandle)
85 {
86 string response = "";
87 SimProfileData central_region = getRegion(reqhandle);
88 SimProfileData neighbour;
89 for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++)
90 {
91 if (getRegion(Util.UIntsToLong((uint)((central_region.regionLocX + x) * 256), (uint)(central_region.regionLocY + y) * 256)) != null)
92 {
93 neighbour = getRegion(Util.UIntsToLong((uint)((central_region.regionLocX + x) * 256), (uint)(central_region.regionLocY + y) * 256));
94 response += "<neighbour>";
95 response += "<sim_ip>" + neighbour.serverIP + "</sim_ip>";
96 response += "<sim_port>" + neighbour.serverPort.ToString() + "</sim_port>";
97 response += "<locx>" + neighbour.regionLocX.ToString() + "</locx>";
98 response += "<locy>" + neighbour.regionLocY.ToString() + "</locy>";
99 response += "<regionhandle>" + neighbour.regionHandle.ToString() + "</regionhandle>";
100 response += "</neighbour>";
101
102 }
103 }
104 return response;
105 }
106
107 public XmlRpcResponse XmlRpcLoginToSimulatorMethod(XmlRpcRequest request)
108 {
109 XmlRpcResponse response = new XmlRpcResponse();
110 Hashtable responseData = new Hashtable();
111 response.Value = responseData;
112
113 SimProfileData TheSim = null;
114 Hashtable requestData = (Hashtable)request.Params[0];
115
116 if (requestData.ContainsKey("UUID"))
117 {
118 TheSim = getRegion(new LLUUID((string)requestData["UUID"]));
119 }
120 else if (requestData.ContainsKey("region_handle"))
121 {
122 TheSim = getRegion((ulong)Convert.ToUInt64(requestData["region_handle"]));
123 }
124
125 if (TheSim == null)
126 {
127 responseData["error"] = "sim not found";
128 }
129 else
130 {
131
132 ArrayList SimNeighboursData = new ArrayList();
133
134 SimProfileData neighbour;
135 Hashtable NeighbourBlock;
136 for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++)
137 {
138 if (getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256)) != null)
139 {
140 neighbour = getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256));
141
142 NeighbourBlock = new Hashtable();
143 NeighbourBlock["sim_ip"] = neighbour.serverIP;
144 NeighbourBlock["sim_port"] = neighbour.serverPort.ToString();
145 NeighbourBlock["region_locx"] = neighbour.regionLocX.ToString();
146 NeighbourBlock["region_locy"] = neighbour.regionLocY.ToString();
147 NeighbourBlock["UUID"] = neighbour.UUID.ToString();
148
149 if (neighbour.UUID != TheSim.UUID) SimNeighboursData.Add(NeighbourBlock);
150 }
151 }
152
153 responseData["UUID"] = TheSim.UUID.ToString();
154 responseData["region_locx"] = TheSim.regionLocX.ToString();
155 responseData["region_locy"] = TheSim.regionLocY.ToString();
156 responseData["regionname"] = TheSim.regionName;
157 responseData["estate_id"] = "1";
158 responseData["neighbours"] = SimNeighboursData;
159
160 responseData["sim_ip"] = TheSim.serverIP;
161 responseData["sim_port"] = TheSim.serverPort.ToString();
162 responseData["asset_url"] = TheSim.regionAssetURI;
163 responseData["asset_sendkey"] = TheSim.regionAssetSendKey;
164 responseData["asset_recvkey"] = TheSim.regionAssetRecvKey;
165 responseData["user_url"] = TheSim.regionUserURI;
166 responseData["user_sendkey"] = TheSim.regionUserSendKey;
167 responseData["user_recvkey"] = TheSim.regionUserRecvKey;
168 responseData["authkey"] = TheSim.regionSecret;
169 }
170
171 return response;
172 }
173
174
175 public string RestGetRegionMethod(string request, string path, string param)
176 {
177 return RestGetSimMethod("", "/sims/", param);
178 }
179
180 public string RestSetRegionMethod(string request, string path, string param)
181 {
182 return RestSetSimMethod("", "/sims/", param);
183 }
184
185
186 public string RestGetSimMethod(string request, string path, string param)
187 {
188 string respstring = String.Empty;
189
190 SimProfileData TheSim;
191 LLUUID UUID = new LLUUID(param);
192 TheSim = getRegion(UUID);
193
194 if (!(TheSim == null))
195 {
196 respstring = "<Root>";
197 respstring += "<authkey>" + TheSim.regionSendKey + "</authkey>";
198 respstring += "<sim>";
199 respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>";
200 respstring += "<regionname>" + TheSim.regionName + "</regionname>";
201 respstring += "<sim_ip>" + TheSim.serverIP + "</sim_ip>";
202 respstring += "<sim_port>" + TheSim.serverPort.ToString() + "</sim_port>";
203 respstring += "<region_locx>" + TheSim.regionLocX.ToString() + "</region_locx>";
204 respstring += "<region_locy>" + TheSim.regionLocY.ToString() + "</region_locy>";
205 respstring += "<estate_id>1</estate_id>";
206 respstring += "</sim>";
207 respstring += "</Root>";
208 }
209
210 return respstring;
211 }
212
213
214 public string RestSetSimMethod(string request, string path, string param)
215 {
216 Console.WriteLine("SimProfiles.cs:RestSetSimMethod() - processing request......");
217 SimProfileData TheSim;
218 TheSim = getRegion(new LLUUID(param));
219 if ((TheSim) == null)
220 {
221 TheSim = new SimProfileData();
222 LLUUID UUID = new LLUUID(param);
223 TheSim.UUID = UUID;
224 }
225
226 XmlDocument doc = new XmlDocument();
227 doc.LoadXml(request);
228 XmlNode rootnode = doc.FirstChild;
229 XmlNode authkeynode = rootnode.ChildNodes[0];
230 if (authkeynode.Name != "authkey")
231 {
232 return "ERROR! bad XML - expected authkey tag";
233 }
234
235 XmlNode simnode = rootnode.ChildNodes[1];
236 if (simnode.Name != "sim")
237 {
238 return "ERROR! bad XML - expected sim tag";
239 }
240
241 if (authkeynode.InnerText != TheSim.regionRecvKey)
242 {
243 return "ERROR! invalid key";
244 }
245 for (int i = 0; i < simnode.ChildNodes.Count; i++)
246 {
247 switch (simnode.ChildNodes[i].Name)
248 {
249 case "regionname":
250 TheSim.regionName = simnode.ChildNodes[i].InnerText;
251 break;
252
253 case "sim_ip":
254 TheSim.serverIP = simnode.ChildNodes[i].InnerText;
255 break;
256
257 case "sim_port":
258 TheSim.serverPort = Convert.ToUInt32(simnode.ChildNodes[i].InnerText);
259 break;
260
261 case "region_locx":
262 TheSim.regionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
263 TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256));
264 break;
265
266 case "region_locy":
267 TheSim.regionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
268 TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256));
269 break;
270 }
271 }
272
273 try
274 {
275 // NEEDS IMPLEMENTATION.
276 return "OK";
277 }
278 catch (Exception e)
279 {
280 return "ERROR! could not save to database! (" + e.ToString() + ")";
281 }
282
283 }
284
285 }
286}