diff options
Diffstat (limited to '')
-rw-r--r-- | OpenGridServices.GridServer/GridHttp.cs | 110 |
1 files changed, 91 insertions, 19 deletions
diff --git a/OpenGridServices.GridServer/GridHttp.cs b/OpenGridServices.GridServer/GridHttp.cs index 4bc9ef0..ed56b63 100644 --- a/OpenGridServices.GridServer/GridHttp.cs +++ b/OpenGridServices.GridServer/GridHttp.cs | |||
@@ -57,6 +57,7 @@ namespace OpenGridServices.GridServer | |||
57 | MainConsole.Instance.WriteLine("GridHttp.cs:StartHTTP() - Spawned main thread OK"); | 57 | MainConsole.Instance.WriteLine("GridHttp.cs:StartHTTP() - Spawned main thread OK"); |
58 | Listener = new HttpListener(); | 58 | Listener = new HttpListener(); |
59 | 59 | ||
60 | Listener.Prefixes.Add("http://+:8001/"); | ||
60 | Listener.Prefixes.Add("http://+:8001/sims/"); | 61 | Listener.Prefixes.Add("http://+:8001/sims/"); |
61 | Listener.Prefixes.Add("http://+:8001/gods/"); | 62 | Listener.Prefixes.Add("http://+:8001/gods/"); |
62 | Listener.Prefixes.Add("http://+:8001/highestuuid/"); | 63 | Listener.Prefixes.Add("http://+:8001/highestuuid/"); |
@@ -79,23 +80,30 @@ namespace OpenGridServices.GridServer | |||
79 | Hashtable requestData = (Hashtable)request.Params[0]; | 80 | Hashtable requestData = (Hashtable)request.Params[0]; |
80 | switch(request.MethodName) { | 81 | switch(request.MethodName) { |
81 | case "simulator_login": | 82 | case "simulator_login": |
82 | if(!(referrer=="simulator")) { | 83 | |
84 | /*if(!((string)requestData["authkey"]==OpenGrid_Main.thegrid.SimRecvKey)) { | ||
83 | XmlRpcResponse ErrorResp = new XmlRpcResponse(); | 85 | XmlRpcResponse ErrorResp = new XmlRpcResponse(); |
84 | Hashtable ErrorRespData = new Hashtable(); | 86 | Hashtable ErrorRespData = new Hashtable(); |
85 | ErrorRespData["error"]="Only simulators can login with this method"; | 87 | ErrorRespData["error"]="invalid key"; |
86 | ErrorResp.Value=ErrorRespData; | 88 | ErrorResp.Value=ErrorRespData; |
87 | return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(ErrorResp),"utf-16","utf-8")); | 89 | return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(ErrorResp),"utf-16","utf-8")); |
88 | } | 90 | }*/ |
89 | 91 | SimProfileBase TheSim = null; | |
90 | if(!((string)requestData["authkey"]==OpenGrid_Main.thegrid.SimRecvKey)) { | 92 | |
93 | if(requestData.ContainsKey("UUID")) { | ||
94 | TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByLLUUID(new LLUUID((string)requestData["UUID"])); | ||
95 | } else if (requestData.ContainsKey("region_handle")){ | ||
96 | TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle((ulong)Convert.ToUInt64(requestData["region_handle"])); | ||
97 | } | ||
98 | |||
99 | if(TheSim==null) { | ||
91 | XmlRpcResponse ErrorResp = new XmlRpcResponse(); | 100 | XmlRpcResponse ErrorResp = new XmlRpcResponse(); |
92 | Hashtable ErrorRespData = new Hashtable(); | 101 | Hashtable ErrorRespData = new Hashtable(); |
93 | ErrorRespData["error"]="invalid key"; | 102 | ErrorRespData["error"]="sim not found"; |
94 | ErrorResp.Value=ErrorRespData; | 103 | ErrorResp.Value=ErrorRespData; |
95 | return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(ErrorResp),"utf-16","utf-8")); | 104 | return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(ErrorResp),"utf-16","utf-8")); |
96 | } | 105 | } |
97 | 106 | ||
98 | SimProfileBase TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByLLUUID(new LLUUID((string)requestData["UUID"])); | ||
99 | XmlRpcResponse SimLoginResp = new XmlRpcResponse(); | 107 | XmlRpcResponse SimLoginResp = new XmlRpcResponse(); |
100 | Hashtable SimLoginRespData = new Hashtable(); | 108 | Hashtable SimLoginRespData = new Hashtable(); |
101 | 109 | ||
@@ -115,7 +123,8 @@ namespace OpenGridServices.GridServer | |||
115 | SimNeighboursData.Add(NeighbourBlock); | 123 | SimNeighboursData.Add(NeighbourBlock); |
116 | } | 124 | } |
117 | } | 125 | } |
118 | 126 | ||
127 | SimLoginRespData["UUID"]=TheSim.UUID; | ||
119 | SimLoginRespData["region_locx"]=TheSim.RegionLocX.ToString(); | 128 | SimLoginRespData["region_locx"]=TheSim.RegionLocX.ToString(); |
120 | SimLoginRespData["region_locy"]=TheSim.RegionLocY.ToString(); | 129 | SimLoginRespData["region_locy"]=TheSim.RegionLocY.ToString(); |
121 | SimLoginRespData["regionname"]=TheSim.regionname; | 130 | SimLoginRespData["regionname"]=TheSim.regionname; |
@@ -138,15 +147,24 @@ namespace OpenGridServices.GridServer | |||
138 | return ""; | 147 | return ""; |
139 | } | 148 | } |
140 | 149 | ||
141 | static string ParseREST(string requestBody, string requestURL, string HTTPmethod) { | 150 | static string ParseREST(string requestURL, string requestBody, string HTTPmethod) { |
142 | char[] splitter = {'/'}; | 151 | char[] splitter = {'/'}; |
143 | string[] rest_params = requestURL.Split(splitter); | 152 | string[] rest_params = requestURL.Split(splitter); |
144 | string req_type = rest_params[0]; // First part of the URL is the type of request - | 153 | string req_type = rest_params[0]; // First part of the URL is the type of request - |
145 | string respstring; | 154 | string respstring=""; |
155 | SimProfileBase TheSim; | ||
156 | Console.WriteLine(req_type); | ||
146 | switch(req_type) { | 157 | switch(req_type) { |
147 | case "sims": | 158 | case "regions": |
159 | // DIRTY HACK ALERT | ||
160 | Console.WriteLine("/regions/ accessed"); | ||
161 | TheSim=OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle((ulong)Convert.ToUInt64(rest_params[1])); | ||
162 | respstring=ParseREST("/regions/" + rest_params[1], requestBody, HTTPmethod); | ||
163 | break; | ||
164 | |||
165 | case "sims": | ||
148 | LLUUID UUID = new LLUUID((string)rest_params[1]); | 166 | LLUUID UUID = new LLUUID((string)rest_params[1]); |
149 | SimProfileBase TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByLLUUID(UUID); | 167 | TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByLLUUID(UUID); |
150 | if(!(TheSim==null)) { | 168 | if(!(TheSim==null)) { |
151 | switch(HTTPmethod) { | 169 | switch(HTTPmethod) { |
152 | case "GET": | 170 | case "GET": |
@@ -162,18 +180,67 @@ namespace OpenGridServices.GridServer | |||
162 | respstring+="</sim>"; | 180 | respstring+="</sim>"; |
163 | break; | 181 | break; |
164 | case "POST": | 182 | case "POST": |
183 | Console.WriteLine("Updating sim details....."); | ||
165 | XmlDocument doc = new XmlDocument(); | 184 | XmlDocument doc = new XmlDocument(); |
166 | doc.LoadXml(requestBody); | 185 | doc.LoadXml(requestBody); |
167 | XmlNode authkeynode = doc.FirstChild; | 186 | XmlNode authkeynode = doc.FirstChild; |
168 | if (authkeynode.Name != "authkey") | 187 | if (authkeynode.Name != "authkey") { |
169 | respstring = "<error>bad XML - expected authkey tag</error>"; | 188 | respstring = "ERROR! bad XML - expected authkey tag"; |
189 | return respstring; | ||
190 | } | ||
170 | XmlNode simnode = doc.ChildNodes[1]; | 191 | XmlNode simnode = doc.ChildNodes[1]; |
171 | if (simnode.Name != "sim") | 192 | if (simnode.Name != "sim") { |
172 | respstring = "<error>bad XML - expected sim tag</error>"; | 193 | respstring = "ERROR! bad XML - expected sim tag"; |
194 | return respstring; | ||
195 | } | ||
196 | if (authkeynode.Name != OpenGrid_Main.thegrid.SimRecvKey) { | ||
197 | respstring = "ERROR! invalid key"; | ||
198 | return respstring; | ||
199 | } | ||
200 | |||
201 | if (TheSim==null) { | ||
202 | respstring="ERROR! sim not found"; | ||
203 | return respstring; | ||
204 | } else { | ||
205 | for(int i=0; i<= simnode.ChildNodes.Count; i++) { | ||
206 | switch(simnode.ChildNodes[i].Name) { | ||
207 | case "uuid": | ||
208 | // should a sim be able to update it's own UUID? To be decided | ||
209 | // watch next week for the exciting conclusion in "the adventures of OpenGridServices.GridServer/GridHttp.cs:ParseREST() at line 190! | ||
210 | break; // and line 190's arch-enemy - THE BREAK STATEMENT! OH NOES!!!!! (this code written at 6:57AM, no sleep, lots of caffeine) | ||
211 | |||
212 | case "regionname": | ||
213 | TheSim.regionname=simnode.ChildNodes[i].InnerText; | ||
214 | break; | ||
215 | |||
216 | case "sim_ip": | ||
217 | TheSim.sim_ip=simnode.ChildNodes[i].InnerText; | ||
218 | break; | ||
219 | |||
220 | case "sim_port": | ||
221 | TheSim.sim_port=Convert.ToUInt32(simnode.ChildNodes[i].InnerText); | ||
222 | break; | ||
223 | |||
224 | case "region_locx": | ||
225 | TheSim.RegionLocX=Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); | ||
226 | TheSim.regionhandle=Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256)); | ||
227 | break; | ||
228 | |||
229 | case "region_locy": | ||
230 | TheSim.RegionLocY=Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); | ||
231 | TheSim.regionhandle=Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256)); | ||
232 | break; | ||
233 | } | ||
234 | } | ||
235 | respstring="OK"; | ||
236 | } | ||
237 | |||
238 | |||
173 | 239 | ||
174 | break; | 240 | break; |
175 | } | 241 | } |
176 | } | 242 | } |
243 | return respstring; | ||
177 | break; | 244 | break; |
178 | } | 245 | } |
179 | return ""; | 246 | return ""; |
@@ -209,9 +276,14 @@ namespace OpenGridServices.GridServer | |||
209 | response.AddHeader("Content-type","text/xml"); | 276 | response.AddHeader("Content-type","text/xml"); |
210 | break; | 277 | break; |
211 | 278 | ||
279 | case "text/plaintext": | ||
280 | // must be REST | ||
281 | responseString=ParseREST(request.RawUrl,requestBody,request.HttpMethod); | ||
282 | break; | ||
283 | |||
212 | case null: | 284 | case null: |
213 | // must be REST or invalid crap, so pass to the REST parser | 285 | // must be REST or invalid crap, so pass to the REST parser |
214 | responseString=ParseREST(request.Url.OriginalString,requestBody,request.HttpMethod); | 286 | responseString=ParseREST(request.RawUrl,requestBody,request.HttpMethod); |
215 | break; | 287 | break; |
216 | } | 288 | } |
217 | 289 | ||