aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.Servers
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim.Servers')
-rw-r--r--OpenSim.Servers/BaseHttpServer.cs224
-rw-r--r--OpenSim.Servers/IRestHandler.cs8
-rw-r--r--OpenSim.Servers/LocalUserProfileManager.cs109
-rw-r--r--OpenSim.Servers/LoginResponse.cs398
-rw-r--r--OpenSim.Servers/LoginServer.cs283
-rw-r--r--OpenSim.Servers/OpenSim.Servers.csproj115
-rw-r--r--OpenSim.Servers/OpenSim.Servers.dll.build48
-rw-r--r--OpenSim.Servers/XmlRpcMethod.cs7
8 files changed, 1192 insertions, 0 deletions
diff --git a/OpenSim.Servers/BaseHttpServer.cs b/OpenSim.Servers/BaseHttpServer.cs
new file mode 100644
index 0000000..2f73f46
--- /dev/null
+++ b/OpenSim.Servers/BaseHttpServer.cs
@@ -0,0 +1,224 @@
1using System;
2using System.Collections.Generic;
3using System.Net;
4using System.Text;
5using System.Text.RegularExpressions;
6using System.Threading;
7//using OpenSim.CAPS;
8using Nwc.XmlRpc;
9using System.Collections;
10
11namespace OpenSim.Servers
12{
13 public class BaseHttpServer
14 {
15 protected Thread m_workerThread;
16 protected HttpListener m_httpListener;
17 protected Dictionary<string, RestMethod> m_restHandlers = new Dictionary<string, RestMethod>();
18 protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>();
19 protected int m_port;
20
21 public BaseHttpServer(int port)
22 {
23 m_port = port;
24 }
25
26 public bool AddRestHandler(string method, string path, RestMethod handler)
27 {
28 string methodKey = String.Format("{0}: {1}", method, path);
29
30 if (!this.m_restHandlers.ContainsKey(methodKey))
31 {
32 this.m_restHandlers.Add(methodKey, handler);
33 return true;
34 }
35
36 //must already have a handler for that path so return false
37 return false;
38 }
39
40 public bool AddXmlRPCHandler(string method, XmlRpcMethod handler)
41 {
42 if (!this.m_rpcHandlers.ContainsKey(method))
43 {
44 this.m_rpcHandlers.Add(method, handler);
45 return true;
46 }
47
48 //must already have a handler for that path so return false
49 return false;
50 }
51
52 protected virtual string ProcessXMLRPCMethod(string methodName, XmlRpcRequest request)
53 {
54 XmlRpcResponse response;
55
56 XmlRpcMethod method;
57 if( this.m_rpcHandlers.TryGetValue( methodName, out method ) )
58 {
59 response = method(request);
60 }
61 else
62 {
63 response = new XmlRpcResponse();
64 Hashtable unknownMethodError = new Hashtable();
65 unknownMethodError["reason"] = "XmlRequest"; ;
66 unknownMethodError["message"] = "Unknown Rpc request";
67 unknownMethodError["login"] = "false";
68 response.Value = unknownMethodError;
69 }
70
71 return XmlRpcResponseSerializer.Singleton.Serialize(response);
72 }
73
74 protected virtual string ParseREST(string request, string path, string method)
75 {
76 string response;
77 RestMethod handler;
78
79 string requestKey = String.Format("{0}: {1}", method, path);
80
81 string bestMatch = String.Empty;
82 foreach( string currentKey in m_restHandlers.Keys )
83 {
84 if( requestKey.StartsWith( currentKey ))
85 {
86 if(currentKey.Length > bestMatch.Length )
87 {
88 bestMatch = currentKey;
89 }
90 }
91 }
92
93 if (m_restHandlers.TryGetValue(bestMatch, out handler))
94 {
95 response = handler(request, path);
96
97 }
98 else
99 {
100 response = String.Empty;
101 }
102
103 return response;
104 }
105
106 protected virtual string ParseLLSDXML(string requestBody)
107 {
108 // dummy function for now - IMPLEMENT ME!
109 return "";
110 }
111
112 protected virtual string ParseXMLRPC(string requestBody)
113 {
114 string responseString = String.Empty;
115
116 try
117 {
118 XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
119
120 string methodName = request.MethodName;
121
122 responseString = ProcessXMLRPCMethod(methodName, request );
123 }
124 catch (Exception e)
125 {
126 Console.WriteLine(e.ToString());
127 }
128 return responseString;
129 }
130
131 public virtual void HandleRequest(Object stateinfo)
132 {
133 HttpListenerContext context = (HttpListenerContext)stateinfo;
134
135 HttpListenerRequest request = context.Request;
136 HttpListenerResponse response = context.Response;
137
138 response.KeepAlive = false;
139 response.SendChunked = false;
140
141 System.IO.Stream body = request.InputStream;
142 System.Text.Encoding encoding = System.Text.Encoding.UTF8;
143 System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
144
145 string requestBody = reader.ReadToEnd();
146 body.Close();
147 reader.Close();
148
149 //Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType);
150 //Console.WriteLine(requestBody);
151
152 string responseString = "";
153 switch (request.ContentType)
154 {
155 case "text/xml":
156 // must be XML-RPC, so pass to the XML-RPC parser
157
158 responseString = ParseXMLRPC(requestBody);
159 responseString = Regex.Replace(responseString, "utf-16", "utf-8");
160
161 response.AddHeader("Content-type", "text/xml");
162 break;
163
164 case "application/xml":
165 // probably LLSD we hope, otherwise it should be ignored by the parser
166 responseString = ParseLLSDXML(requestBody);
167 response.AddHeader("Content-type", "application/xml");
168 break;
169
170 case "application/x-www-form-urlencoded":
171 // a form data POST so send to the REST parser
172 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
173 response.AddHeader("Content-type", "text/html");
174 break;
175
176 case null:
177 // must be REST or invalid crap, so pass to the REST parser
178 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
179 response.AddHeader("Content-type", "text/html");
180 break;
181
182 }
183
184 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
185 System.IO.Stream output = response.OutputStream;
186 response.SendChunked = false;
187 response.ContentLength64 = buffer.Length;
188 output.Write(buffer, 0, buffer.Length);
189 output.Close();
190 }
191
192 public void Start()
193 {
194 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("BaseHttpServer.cs: Starting up HTTP Server");
195
196 m_workerThread = new Thread(new ThreadStart(StartHTTP));
197 m_workerThread.IsBackground = true;
198 m_workerThread.Start();
199 }
200
201 private void StartHTTP()
202 {
203 try
204 {
205 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("BaseHttpServer.cs: StartHTTP() - Spawned main thread OK");
206 m_httpListener = new HttpListener();
207
208 m_httpListener.Prefixes.Add("http://+:" + m_port + "/");
209 m_httpListener.Start();
210
211 HttpListenerContext context;
212 while (true)
213 {
214 context = m_httpListener.GetContext();
215 ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context);
216 }
217 }
218 catch (Exception e)
219 {
220 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(e.Message);
221 }
222 }
223 }
224}
diff --git a/OpenSim.Servers/IRestHandler.cs b/OpenSim.Servers/IRestHandler.cs
new file mode 100644
index 0000000..08737cc
--- /dev/null
+++ b/OpenSim.Servers/IRestHandler.cs
@@ -0,0 +1,8 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Servers
6{
7 public delegate string RestMethod( string request, string path );
8}
diff --git a/OpenSim.Servers/LocalUserProfileManager.cs b/OpenSim.Servers/LocalUserProfileManager.cs
new file mode 100644
index 0000000..6166e02
--- /dev/null
+++ b/OpenSim.Servers/LocalUserProfileManager.cs
@@ -0,0 +1,109 @@
1/*
2* Copyright (c) OpenSim project, http://sim.opensecondlife.org/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
10* documentation and/or other materials provided with the distribution.
11* * Neither the name of the <organization> nor the
12* names of its contributors may be used to endorse or promote products
13* derived from this software without specific prior written permission.
14*
15* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
16* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
19* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*
26*/
27
28using System;
29using System.Collections.Generic;
30using System.Collections;
31using System.Text;
32using OpenSim.Framework.User;
33using OpenSim.Framework.Grid;
34using OpenSim.Framework.Inventory;
35using OpenSim.Framework.Interfaces;
36using libsecondlife;
37
38namespace OpenSim.UserServer
39{
40 public class LocalUserProfileManager : UserProfileManager
41 {
42 private IGridServer m_gridServer;
43 private int m_port;
44 private string m_ipAddr;
45
46 public LocalUserProfileManager(IGridServer gridServer, int simPort, string ipAddr)
47 {
48 m_gridServer = gridServer;
49 m_port = simPort;
50 m_ipAddr = ipAddr;
51 }
52
53 public override void InitUserProfiles()
54 {
55 // TODO: need to load from database
56 }
57
58 public override void CustomiseResponse(ref System.Collections.Hashtable response, UserProfile theUser)
59 {
60 Int32 circode = (Int32)response["circuit_code"];
61 theUser.AddSimCircuit((uint)circode, LLUUID.Random());
62 response["home"] = "{'region_handle':[r" + (997 * 256).ToString() + ",r" + (996 * 256).ToString() + "], 'position':[r" + theUser.homepos.X.ToString() + ",r" + theUser.homepos.Y.ToString() + ",r" + theUser.homepos.Z.ToString() + "], 'look_at':[r" + theUser.homelookat.X.ToString() + ",r" + theUser.homelookat.Y.ToString() + ",r" + theUser.homelookat.Z.ToString() + "]}";
63 response["sim_port"] = m_port;
64 response["sim_ip"] = m_ipAddr;
65 response["region_y"] = (Int32)996 * 256;
66 response["region_x"] = (Int32)997* 256;
67
68 string first;
69 string last;
70 if (response.Contains("first_name"))
71 {
72 first = (string)response["first_name"];
73 }
74 else
75 {
76 first = "test";
77 }
78
79 if (response.Contains("last_name"))
80 {
81 last = (string)response["last_name"];
82 }
83 else
84 {
85 last = "User";
86 }
87
88 ArrayList InventoryList = (ArrayList)response["inventory-skeleton"];
89 Hashtable Inventory1 = (Hashtable)InventoryList[0];
90
91 Login _login = new Login();
92 //copy data to login object
93 _login.First = first;
94 _login.Last = last;
95 _login.Agent = new LLUUID((string)response["agent_id"]) ;
96 _login.Session = new LLUUID((string)response["session_id"]);
97 _login.SecureSession = new LLUUID((string)response["secure_session_id"]);
98 _login.BaseFolder = null;
99 _login.InventoryFolder = new LLUUID((string)Inventory1["folder_id"]);
100
101 //working on local computer if so lets add to the gridserver's list of sessions?
102 if (m_gridServer.GetName() == "Local")
103 {
104 Console.WriteLine("adding login data to gridserver");
105 ((LocalGridBase)this.m_gridServer).AddNewSession(_login);
106 }
107 }
108 }
109}
diff --git a/OpenSim.Servers/LoginResponse.cs b/OpenSim.Servers/LoginResponse.cs
new file mode 100644
index 0000000..2e29889
--- /dev/null
+++ b/OpenSim.Servers/LoginResponse.cs
@@ -0,0 +1,398 @@
1/*
2* Copyright (c) OpenSim project, http://sim.opensecondlife.org/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
10* documentation and/or other materials provided with the distribution.
11* * Neither the name of the <organization> nor the
12* names of its contributors may be used to endorse or promote products
13* derived from this software without specific prior written permission.
14*
15* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
16* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
19* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*
26*/
27
28using Nwc.XmlRpc;
29using System;
30using System.IO;
31using System.Net;
32using System.Net.Sockets;
33using System.Text;
34using System.Text.RegularExpressions;
35using System.Threading;
36using System.Collections;
37using System.Security.Cryptography;
38using System.Xml;
39using libsecondlife;
40using OpenSim;
41using OpenSim.Framework.Interfaces;
42using OpenSim.Framework.Grid;
43using OpenSim.Framework.Inventory;
44using OpenSim.Framework.User;
45using OpenSim.Framework.Utilities;
46
47namespace OpenSim.UserServer
48{
49 /// <summary>
50 /// A temp class to handle login response.
51 /// Should make use of UserProfileManager where possible.
52 /// </summary>
53
54 public class LoginResponse
55 {
56 private Hashtable loginFlagsHash;
57 private Hashtable globalTexturesHash;
58 private Hashtable loginError;
59
60 private ArrayList loginFlags;
61 private ArrayList globalTextures;
62
63 // Login Flags
64 private string dst;
65 private string stipendSinceLogin;
66 private string gendered;
67 private string everLoggedIn;
68 private string login;
69 private string simPort;
70 private string simAddress;
71 private string agentID;
72 private string sessionID;
73 private string secureSessionID;
74 private Int32 circuitCode;
75
76 // Global Textures
77 private string sunTexture;
78 private string cloudTexture;
79 private string moonTexture;
80
81 // Error Flags
82 private string errorReason;
83 private string errorMessage;
84
85 // Response
86 private XmlRpcResponse xmlRpcResponse;
87 private XmlRpcResponse defaultXmlRpcResponse;
88 private string defaultTextResponse;
89
90 public LoginResponse()
91 {
92 this.loginFlags = new ArrayList();
93 this.globalTextures = new ArrayList();
94 this.SetDefaultValues();
95 } // LoginServer
96
97 // This will go away as we replace new-login.dat:
98 private void GetDefaultResponse()
99 {
100 try
101 {
102 // read in default response string
103 StreamReader SR;
104 string lines;
105 SR = File.OpenText("new-login.dat");
106
107 this.defaultTextResponse = "";
108 while (!SR.EndOfStream)
109 {
110 lines = SR.ReadLine();
111 this.defaultTextResponse += lines;
112 }
113 SR.Close();
114 this.defaultXmlRpcResponse = (XmlRpcResponse)(new XmlRpcResponseDeserializer()).Deserialize(this.defaultTextResponse);
115 }
116 catch (Exception E)
117 {
118 Console.WriteLine(E.ToString());
119 }
120 } // GetDefaultResponse
121
122 public void SetDefaultValues()
123 {
124 this.GetDefaultResponse();
125
126 this.DST = "N";
127 this.StipendSinceLogin = "N";
128 this.Gendered = "Y";
129 this.EverLoggedIn = "Y";
130 this.login = "false";
131
132 this.SunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271";
133 this.CloudTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
134 this.MoonTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
135
136 this.ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock.";
137 this.ErrorReason = "key";
138
139 } // SetDefaultValues
140
141 private XmlRpcResponse GenerateResponse(string reason, string message, string login)
142 {
143 // Overwrite any default values;
144 this.xmlRpcResponse = new XmlRpcResponse();
145
146 // Ensure Login Failed message/reason;
147 this.ErrorMessage = message;
148 this.ErrorReason = reason;
149
150 this.loginError = new Hashtable();
151 this.loginError["reason"] = this.ErrorReason;
152 this.loginError["message"] = this.ErrorMessage;
153 this.loginError["login"] = login;
154 this.xmlRpcResponse.Value = this.loginError;
155 return (this.xmlRpcResponse);
156 } // GenerateResponse
157
158 public XmlRpcResponse LoginFailedResponse()
159 {
160 return (this.GenerateResponse("key", "You have entered an invalid name/password combination. Check Caps/lock.", "false"));
161 } // LoginFailedResponse
162
163 public XmlRpcResponse ConnectionFailedResponse()
164 {
165 return (this.LoginFailedResponse());
166 } // CreateErrorConnectingToGridResponse()
167
168 public XmlRpcResponse CreateAlreadyLoggedInResponse()
169 {
170 return(this.GenerateResponse("presence", "You appear to be already logged in, if this is not the case please wait for your session to timeout, if this takes longer than a few minutes please contact the grid owner", "false"));
171 } // CreateAlreadyLoggedInResponse()
172
173 public XmlRpcResponse ToXmlRpcResponse()
174 {
175 this.xmlRpcResponse = this.defaultXmlRpcResponse;
176 Hashtable responseData = (Hashtable)this.xmlRpcResponse.Value;
177
178 this.loginFlagsHash = new Hashtable();
179 this.loginFlagsHash["daylight_savings"] = this.DST;
180 this.loginFlagsHash["stipend_since_login"] = this.StipendSinceLogin;
181 this.loginFlagsHash["gendered"] = this.Gendered;
182 this.loginFlagsHash["ever_logged_in"] = this.EverLoggedIn;
183 this.loginFlags.Add(this.loginFlagsHash);
184
185 this.globalTexturesHash = new Hashtable();
186 this.globalTexturesHash["sun_texture_id"] = this.SunTexture;
187 this.globalTexturesHash["cloud_texture_id"] = this.CloudTexture;
188 this.globalTexturesHash["moon_texture_id"] = this.MoonTexture;
189 this.globalTextures.Add(this.globalTexturesHash);
190
191 responseData["sim_port"] = this.SimPort;
192 responseData["sim_ip"] = this.SimAddress;
193 responseData["agent_id"] = this.AgentID;
194 responseData["session_id"] = this.SessionID;
195 responseData["secure_session_id"] = this.SecureSessionID;
196 responseData["circuit_code"] = this.CircuitCode;
197 responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
198 responseData["login-flags"] = this.loginFlags;
199 responseData["global-textures"] = this.globalTextures;
200
201 return (this.xmlRpcResponse);
202
203 } // ToXmlRpcResponse
204
205 public string Login
206 {
207 get
208 {
209 return this.login;
210 }
211 set
212 {
213 this.login = value;
214 }
215 } // Login
216
217 public string DST
218 {
219 get
220 {
221 return this.dst;
222 }
223 set
224 {
225 this.dst = value;
226 }
227 } // DST
228
229 public string StipendSinceLogin
230 {
231 get
232 {
233 return this.stipendSinceLogin;
234 }
235 set
236 {
237 this.stipendSinceLogin = value;
238 }
239 } // StipendSinceLogin
240
241 public string Gendered
242 {
243 get
244 {
245 return this.gendered;
246 }
247 set
248 {
249 this.gendered = value;
250 }
251 } // Gendered
252
253 public string EverLoggedIn
254 {
255 get
256 {
257 return this.everLoggedIn;
258 }
259 set
260 {
261 this.everLoggedIn = value;
262 }
263 } // EverLoggedIn
264
265 public string SimPort
266 {
267 get
268 {
269 return this.simPort;
270 }
271 set
272 {
273 this.simPort = value;
274 }
275 } // SimPort
276
277 public string SimAddress
278 {
279 get
280 {
281 return this.simAddress;
282 }
283 set
284 {
285 this.simAddress = value;
286 }
287 } // SimAddress
288
289 public string AgentID
290 {
291 get
292 {
293 return this.agentID;
294 }
295 set
296 {
297 this.agentID = value;
298 }
299 } // AgentID
300
301 public string SessionID
302 {
303 get
304 {
305 return this.sessionID;
306 }
307 set
308 {
309 this.sessionID = value;
310 }
311 } // SessionID
312
313 public string SecureSessionID
314 {
315 get
316 {
317 return this.secureSessionID;
318 }
319 set
320 {
321 this.secureSessionID = value;
322 }
323 } // SecureSessionID
324
325 public Int32 CircuitCode
326 {
327 get
328 {
329 return this.circuitCode;
330 }
331 set
332 {
333 this.circuitCode = value;
334 }
335 } // CircuitCode
336
337 public string SunTexture
338 {
339 get
340 {
341 return this.sunTexture;
342 }
343 set
344 {
345 this.sunTexture = value;
346 }
347 } // SunTexture
348
349 public string CloudTexture
350 {
351 get
352 {
353 return this.cloudTexture;
354 }
355 set
356 {
357 this.cloudTexture = value;
358 }
359 } // CloudTexture
360
361 public string MoonTexture
362 {
363 get
364 {
365 return this.moonTexture;
366 }
367 set
368 {
369 this.moonTexture = value;
370 }
371 } // MoonTexture
372
373 public string ErrorReason
374 {
375 get
376 {
377 return this.errorReason;
378 }
379 set
380 {
381 this.errorReason = value;
382 }
383 } // ErrorReason
384
385 public string ErrorMessage
386 {
387 get
388 {
389 return this.errorMessage;
390 }
391 set
392 {
393 this.errorMessage = value;
394 }
395 } // ErrorMessage
396
397 } // LoginResponse
398} // namespace OpenSim.UserServer \ No newline at end of file
diff --git a/OpenSim.Servers/LoginServer.cs b/OpenSim.Servers/LoginServer.cs
new file mode 100644
index 0000000..b814639
--- /dev/null
+++ b/OpenSim.Servers/LoginServer.cs
@@ -0,0 +1,283 @@
1/*
2* Copyright (c) OpenSim project, http://sim.opensecondlife.org/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
10* documentation and/or other materials provided with the distribution.
11* * Neither the name of the <organization> nor the
12* names of its contributors may be used to endorse or promote products
13* derived from this software without specific prior written permission.
14*
15* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
16* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
19* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*
26*/
27
28using Nwc.XmlRpc;
29using System;
30using System.IO;
31using System.Net;
32using System.Net.Sockets;
33using System.Text;
34using System.Text.RegularExpressions;
35using System.Threading;
36using System.Collections;
37using System.Security.Cryptography;
38using System.Xml;
39using libsecondlife;
40using OpenSim;
41using OpenSim.Framework.Interfaces;
42using OpenSim.Framework.Grid;
43using OpenSim.Framework.Inventory;
44using OpenSim.Framework.User;
45using OpenSim.Framework.Utilities;
46
47namespace OpenSim.UserServer
48{
49 /// <summary>
50 /// When running in local (default) mode , handles client logins.
51 /// </summary>
52 public class LoginServer : LoginService, IUserServer
53 {
54 private IGridServer m_gridServer;
55 public IPAddress clientAddress = IPAddress.Loopback;
56 public IPAddress remoteAddress = IPAddress.Any;
57 private int NumClients;
58 private string _defaultResponse;
59 private bool userAccounts = false;
60 private string _mpasswd;
61 private bool _needPasswd = false;
62 private LocalUserProfileManager userManager;
63 private int m_simPort;
64 private string m_simAddr;
65
66 public LocalUserProfileManager LocalUserManager
67 {
68 get
69 {
70 return userManager;
71 }
72 }
73
74 public LoginServer(IGridServer gridServer, string simAddr, int simPort, bool useAccounts)
75 {
76 m_gridServer = gridServer;
77 m_simPort = simPort;
78 m_simAddr = simAddr;
79 this.userAccounts = useAccounts;
80 }
81
82 public void Startup()
83 {
84 this._needPasswd = false;
85 // read in default response string
86 /* StreamReader SR;
87 string lines;
88 SR = File.OpenText("new-login.dat");
89
90 while (!SR.EndOfStream)
91 {
92 lines = SR.ReadLine();
93 _defaultResponse += lines;
94 }
95 SR.Close();
96 * */
97
98 this._mpasswd = EncodePassword("testpass");
99
100 userManager = new LocalUserProfileManager(this.m_gridServer, m_simPort, m_simAddr);
101 //userManager.InitUserProfiles();
102 userManager.SetKeys("", "", "", "Welcome to OpenSim");
103 }
104
105 public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
106 {
107 Console.WriteLine("login attempt");
108 Hashtable requestData = (Hashtable)request.Params[0];
109 string first;
110 string last;
111 string passwd;
112 LLUUID Agent;
113 LLUUID Session;
114
115 LoginResponse loginResponse = new LoginResponse();
116
117 //get login name
118 if (requestData.Contains("first"))
119 {
120 first = (string)requestData["first"];
121 }
122 else
123 {
124 first = "test";
125 }
126
127 if (requestData.Contains("last"))
128 {
129 last = (string)requestData["last"];
130 }
131 else
132 {
133 last = "User" + NumClients.ToString();
134 }
135
136 if (requestData.Contains("passwd"))
137 {
138 passwd = (string)requestData["passwd"];
139 }
140 else
141 {
142 passwd = "notfound";
143 }
144
145 if (!Authenticate(first, last, passwd))
146 {
147 return loginResponse.LoginFailedResponse();
148 }
149
150 NumClients++;
151
152 // Create a agent and session LLUUID
153 Agent = GetAgentId(first, last);
154 int SessionRand = Util.RandomClass.Next(1, 999);
155 Session = new LLUUID("aaaabbbb-0200-" + SessionRand.ToString("0000") + "-8664-58f53e442797");
156 LLUUID secureSess = LLUUID.Random();
157
158 loginResponse.SimPort = m_simPort.ToString();
159 loginResponse.SimAddress = m_simAddr.ToString();
160 loginResponse.AgentID = Agent.ToStringHyphenated();
161 loginResponse.SessionID = Session.ToStringHyphenated();
162 loginResponse.SecureSessionID = secureSess.ToStringHyphenated();
163 loginResponse.CircuitCode = (Int32)(Util.RandomClass.Next());
164 XmlRpcResponse response = loginResponse.ToXmlRpcResponse();
165 Hashtable responseData = (Hashtable)response.Value;
166
167 // inventory
168 ArrayList InventoryList = (ArrayList)responseData["inventory-skeleton"];
169 Hashtable Inventory1 = (Hashtable)InventoryList[0];
170 Hashtable Inventory2 = (Hashtable)InventoryList[1];
171 LLUUID BaseFolderID = LLUUID.Random();
172 LLUUID InventoryFolderID = LLUUID.Random();
173 Inventory2["name"] = "Textures";
174 Inventory2["folder_id"] = BaseFolderID.ToStringHyphenated();
175 Inventory2["type_default"] = 0;
176 Inventory1["folder_id"] = InventoryFolderID.ToStringHyphenated();
177
178 ArrayList InventoryRoot = (ArrayList)responseData["inventory-root"];
179 Hashtable Inventoryroot = (Hashtable)InventoryRoot[0];
180 Inventoryroot["folder_id"] = InventoryFolderID.ToStringHyphenated();
181
182 CustomiseLoginResponse(responseData, first, last);
183
184 Login _login = new Login();
185 //copy data to login object
186 _login.First = first;
187 _login.Last = last;
188 _login.Agent = Agent;
189 _login.Session = Session;
190 _login.SecureSession = secureSess;
191 _login.BaseFolder = BaseFolderID;
192 _login.InventoryFolder = InventoryFolderID;
193
194 //working on local computer if so lets add to the gridserver's list of sessions?
195 if (m_gridServer.GetName() == "Local")
196 {
197 ((LocalGridBase)m_gridServer).AddNewSession(_login);
198 }
199
200 return response;
201 }
202
203 protected virtual void CustomiseLoginResponse(Hashtable responseData, string first, string last)
204 {
205 }
206
207 protected virtual LLUUID GetAgentId(string firstName, string lastName)
208 {
209 LLUUID Agent;
210 int AgentRand = Util.RandomClass.Next(1, 9999);
211 Agent = new LLUUID("99998888-0100-" + AgentRand.ToString("0000") + "-8ec1-0b1d5cd6aead");
212 return Agent;
213 }
214
215 protected virtual bool Authenticate(string first, string last, string passwd)
216 {
217 if (this._needPasswd)
218 {
219 //every user needs the password to login
220 string encodedPass = passwd.Remove(0, 3); //remove $1$
221 if (encodedPass == this._mpasswd)
222 {
223 return true;
224 }
225 else
226 {
227 return false;
228 }
229 }
230 else
231 {
232 //do not need password to login
233 return true;
234 }
235 }
236
237 private static string EncodePassword(string passwd)
238 {
239 Byte[] originalBytes;
240 Byte[] encodedBytes;
241 MD5 md5;
242
243 md5 = new MD5CryptoServiceProvider();
244 originalBytes = ASCIIEncoding.Default.GetBytes(passwd);
245 encodedBytes = md5.ComputeHash(originalBytes);
246
247 return Regex.Replace(BitConverter.ToString(encodedBytes), "-", "").ToLower();
248 }
249
250 public bool CreateUserAccount(string firstName, string lastName, string password)
251 {
252 Console.WriteLine("creating new user account");
253 string mdPassword = EncodePassword(password);
254 Console.WriteLine("with password: " + mdPassword);
255 this.userManager.CreateNewProfile(firstName, lastName, mdPassword);
256 return true;
257 }
258
259 //IUserServer implementation
260 public AgentInventory RequestAgentsInventory(LLUUID agentID)
261 {
262 AgentInventory aInventory = null;
263 if (this.userAccounts)
264 {
265 aInventory = this.userManager.GetUsersInventory(agentID);
266 }
267
268 return aInventory;
269 }
270
271 public bool UpdateAgentsInventory(LLUUID agentID, AgentInventory inventory)
272 {
273 return true;
274 }
275
276 public void SetServerInfo(string ServerUrl, string SendKey, string RecvKey)
277 {
278
279 }
280 }
281
282
283}
diff --git a/OpenSim.Servers/OpenSim.Servers.csproj b/OpenSim.Servers/OpenSim.Servers.csproj
new file mode 100644
index 0000000..652d9ce
--- /dev/null
+++ b/OpenSim.Servers/OpenSim.Servers.csproj
@@ -0,0 +1,115 @@
1<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <PropertyGroup>
3 <ProjectType>Local</ProjectType>
4 <ProductVersion>8.0.50727</ProductVersion>
5 <SchemaVersion>2.0</SchemaVersion>
6 <ProjectGuid>{8BB20F0A-0000-0000-0000-000000000000}</ProjectGuid>
7 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
8 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
9 <ApplicationIcon></ApplicationIcon>
10 <AssemblyKeyContainerName>
11 </AssemblyKeyContainerName>
12 <AssemblyName>OpenSim.Servers</AssemblyName>
13 <DefaultClientScript>JScript</DefaultClientScript>
14 <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
15 <DefaultTargetSchema>IE50</DefaultTargetSchema>
16 <DelaySign>false</DelaySign>
17 <OutputType>Library</OutputType>
18 <AppDesignerFolder></AppDesignerFolder>
19 <RootNamespace>OpenSim.Servers</RootNamespace>
20 <StartupObject></StartupObject>
21 <FileUpgradeFlags>
22 </FileUpgradeFlags>
23 </PropertyGroup>
24 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
25 <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
26 <BaseAddress>285212672</BaseAddress>
27 <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
28 <ConfigurationOverrideFile>
29 </ConfigurationOverrideFile>
30 <DefineConstants>TRACE;DEBUG</DefineConstants>
31 <DocumentationFile></DocumentationFile>
32 <DebugSymbols>True</DebugSymbols>
33 <FileAlignment>4096</FileAlignment>
34 <Optimize>False</Optimize>
35 <OutputPath>..\bin\</OutputPath>
36 <RegisterForComInterop>False</RegisterForComInterop>
37 <RemoveIntegerChecks>False</RemoveIntegerChecks>
38 <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
39 <WarningLevel>4</WarningLevel>
40 <NoWarn></NoWarn>
41 </PropertyGroup>
42 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
43 <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
44 <BaseAddress>285212672</BaseAddress>
45 <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
46 <ConfigurationOverrideFile>
47 </ConfigurationOverrideFile>
48 <DefineConstants>TRACE</DefineConstants>
49 <DocumentationFile></DocumentationFile>
50 <DebugSymbols>False</DebugSymbols>
51 <FileAlignment>4096</FileAlignment>
52 <Optimize>True</Optimize>
53 <OutputPath>..\bin\</OutputPath>
54 <RegisterForComInterop>False</RegisterForComInterop>
55 <RemoveIntegerChecks>False</RemoveIntegerChecks>
56 <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
57 <WarningLevel>4</WarningLevel>
58 <NoWarn></NoWarn>
59 </PropertyGroup>
60 <ItemGroup>
61 <Reference Include="System" >
62 <HintPath>System.dll</HintPath>
63 <Private>False</Private>
64 </Reference>
65 <Reference Include="System.Xml" >
66 <HintPath>System.Xml.dll</HintPath>
67 <Private>False</Private>
68 </Reference>
69 <Reference Include="libsecondlife.dll" >
70 <HintPath>..\bin\libsecondlife.dll</HintPath>
71 <Private>False</Private>
72 </Reference>
73 </ItemGroup>
74 <ItemGroup>
75 <ProjectReference Include="..\OpenSim.Framework\OpenSim.Framework.csproj">
76 <Name>OpenSim.Framework</Name>
77 <Project>{8ACA2445-0000-0000-0000-000000000000}</Project>
78 <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
79 <Private>False</Private>
80 </ProjectReference>
81 <ProjectReference Include="..\OpenSim.Framework.Console\OpenSim.Framework.Console.csproj">
82 <Name>OpenSim.Framework.Console</Name>
83 <Project>{A7CD0630-0000-0000-0000-000000000000}</Project>
84 <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
85 <Private>False</Private>
86 </ProjectReference>
87 </ItemGroup>
88 <ItemGroup>
89 <Compile Include="BaseHttpServer.cs">
90 <SubType>Code</SubType>
91 </Compile>
92 <Compile Include="IRestHandler.cs">
93 <SubType>Code</SubType>
94 </Compile>
95 <Compile Include="LocalUserProfileManager.cs">
96 <SubType>Code</SubType>
97 </Compile>
98 <Compile Include="LoginResponse.cs">
99 <SubType>Code</SubType>
100 </Compile>
101 <Compile Include="LoginServer.cs">
102 <SubType>Code</SubType>
103 </Compile>
104 <Compile Include="XmlRpcMethod.cs">
105 <SubType>Code</SubType>
106 </Compile>
107 </ItemGroup>
108 <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
109 <PropertyGroup>
110 <PreBuildEvent>
111 </PreBuildEvent>
112 <PostBuildEvent>
113 </PostBuildEvent>
114 </PropertyGroup>
115</Project>
diff --git a/OpenSim.Servers/OpenSim.Servers.dll.build b/OpenSim.Servers/OpenSim.Servers.dll.build
new file mode 100644
index 0000000..1d4b496
--- /dev/null
+++ b/OpenSim.Servers/OpenSim.Servers.dll.build
@@ -0,0 +1,48 @@
1<?xml version="1.0" ?>
2<project name="OpenSim.Servers" default="build">
3 <target name="build">
4 <echo message="Build Directory is ${project::get-base-directory()}/${build.dir}" />
5 <mkdir dir="${project::get-base-directory()}/${build.dir}" />
6 <copy todir="${project::get-base-directory()}/${build.dir}">
7 <fileset basedir="${project::get-base-directory()}">
8 </fileset>
9 </copy>
10 <csc target="library" debug="${build.debug}" unsafe="False" define="TRACE;DEBUG" output="${project::get-base-directory()}/${build.dir}/${project::get-name()}.dll">
11 <resources prefix="OpenSim.Servers" dynamicprefix="true" >
12 </resources>
13 <sources failonempty="true">
14 <include name="BaseHttpServer.cs" />
15 <include name="IRestHandler.cs" />
16 <include name="LocalUserProfileManager.cs" />
17 <include name="LoginResponse.cs" />
18 <include name="LoginServer.cs" />
19 <include name="XmlRpcMethod.cs" />
20 </sources>
21 <references basedir="${project::get-base-directory()}">
22 <lib>
23 <include name="${project::get-base-directory()}" />
24 <include name="${project::get-base-directory()}/${build.dir}" />
25 </lib>
26 <include name="System.dll" />
27 <include name="System.Xml.dll" />
28 <include name="../bin/OpenSim.Framework.dll" />
29 <include name="../bin/OpenSim.Framework.Console.dll" />
30 <include name="../bin/libsecondlife.dll" />
31 </references>
32 </csc>
33 <echo message="Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/../bin/" />
34 <mkdir dir="${project::get-base-directory()}/../bin/"/>
35 <copy todir="${project::get-base-directory()}/../bin/">
36 <fileset basedir="${project::get-base-directory()}/${build.dir}/" >
37 <include name="*.dll"/>
38 <include name="*.exe"/>
39 </fileset>
40 </copy>
41 </target>
42 <target name="clean">
43 <delete dir="${bin.dir}" failonerror="false" />
44 <delete dir="${obj.dir}" failonerror="false" />
45 </target>
46 <target name="doc" description="Creates documentation.">
47 </target>
48</project>
diff --git a/OpenSim.Servers/XmlRpcMethod.cs b/OpenSim.Servers/XmlRpcMethod.cs
new file mode 100644
index 0000000..2295405
--- /dev/null
+++ b/OpenSim.Servers/XmlRpcMethod.cs
@@ -0,0 +1,7 @@
1using System;
2using Nwc.XmlRpc;
3
4namespace OpenSim.Servers
5{
6 public delegate XmlRpcResponse XmlRpcMethod( XmlRpcRequest request );
7}