aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/GridServers
diff options
context:
space:
mode:
authorgareth2007-03-22 10:11:15 +0000
committergareth2007-03-22 10:11:15 +0000
commit7daa3955bc3a1918e40962851f9e8d38597a245e (patch)
treebee3e1372a7eed0c1b220a8a49f7bee7d29a6b91 /src/GridServers
parentLoad XML for neighbourinfo from grid (diff)
downloadopensim-SC-7daa3955bc3a1918e40962851f9e8d38597a245e.zip
opensim-SC-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.gz
opensim-SC-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.bz2
opensim-SC-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.xz
brought zircon branch into trunk
Diffstat (limited to 'src/GridServers')
-rw-r--r--src/GridServers/LoginServer.cs350
1 files changed, 0 insertions, 350 deletions
diff --git a/src/GridServers/LoginServer.cs b/src/GridServers/LoginServer.cs
deleted file mode 100644
index dbf211d..0000000
--- a/src/GridServers/LoginServer.cs
+++ /dev/null
@@ -1,350 +0,0 @@
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;
42
43namespace OpenSim.GridServers
44{
45
46 /// <summary>
47 /// When running in local (default) mode , handles client logins.
48 /// </summary>
49 public class LoginServer : LoginService
50 {
51 public LoginServer(IGridServer gridServer)
52 {
53 _gridServer = gridServer;
54 }
55
56 private IGridServer _gridServer;
57 private ushort _loginPort = 8080;
58 public IPAddress clientAddress = IPAddress.Loopback;
59 public IPAddress remoteAddress = IPAddress.Any;
60 private Socket loginServer;
61 private int NumClients;
62 private string _defaultResponse;
63
64 private string _mpasswd;
65 private bool _needPasswd=false;
66
67 // InitializeLogin: initialize the login
68 private void InitializeLogin() {
69 loginServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
70 loginServer.Bind(new IPEndPoint(remoteAddress, _loginPort));
71 loginServer.Listen(1);
72
73 this._needPasswd=false;
74 //read in default response string
75 StreamReader SR;
76 string lines;
77 SR=File.OpenText("new-login.dat");
78
79 //lines=SR.ReadLine();
80
81 while(!SR.EndOfStream)
82 {
83 lines = SR.ReadLine();
84 _defaultResponse += lines;
85 //lines = SR.ReadLine();
86 }
87 SR.Close();
88 this._mpasswd = EncodePassword("testpass");
89 }
90
91 public void Startup()
92 {
93 this.InitializeLogin();
94 Thread runLoginProxy = new Thread(new ThreadStart(RunLogin));
95 runLoginProxy.IsBackground = true;
96 runLoginProxy.Start();
97 }
98
99 private void RunLogin()
100 {
101 Console.WriteLine("Starting Login Server");
102 try
103 {
104 for (;;)
105 {
106 Socket client = loginServer.Accept();
107 IPEndPoint clientEndPoint = (IPEndPoint)client.RemoteEndPoint;
108
109
110 NetworkStream networkStream = new NetworkStream(client);
111 StreamReader networkReader = new StreamReader(networkStream);
112 StreamWriter networkWriter = new StreamWriter(networkStream);
113
114 try
115 {
116 LoginRequest(networkReader, networkWriter);
117 }
118 catch (Exception e)
119 {
120 Console.WriteLine(e.Message);
121 }
122
123 networkWriter.Close();
124 networkReader.Close();
125 networkStream.Close();
126
127 client.Close();
128
129 // send any packets queued for injection
130
131 }
132 }
133 catch (Exception e)
134 {
135 Console.WriteLine(e.Message);
136 Console.WriteLine(e.StackTrace);
137 }
138 }
139
140 // ProxyLogin: proxy a login request
141 private void LoginRequest(StreamReader reader, StreamWriter writer)
142 {
143 lock(this)
144 {
145 string line;
146 int contentLength = 0;
147 // read HTTP header
148 do
149 {
150 // read one line of the header
151 line = reader.ReadLine();
152
153 // check for premature EOF
154 if (line == null)
155 throw new Exception("EOF in client HTTP header");
156
157 // look for Content-Length
158 Match match = (new Regex(@"Content-Length: (\d+)$")).Match(line);
159 if (match.Success)
160 contentLength = Convert.ToInt32(match.Groups[1].Captures[0].ToString());
161 } while (line != "");
162
163 // read the HTTP body into a buffer
164 char[] content = new char[contentLength];
165 reader.Read(content, 0, contentLength);
166
167 XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(new String(content));
168 if(request.MethodName == "login_to_simulator")
169 {
170 XmlRpcResponse response = ProcessRequest(request);
171
172 // forward the XML-RPC response to the client
173 writer.WriteLine("HTTP/1.0 200 OK");
174 writer.WriteLine("Content-type: text/xml");
175 writer.WriteLine();
176
177 XmlTextWriter responseWriter = new XmlTextWriter(writer);
178 XmlRpcResponseSerializer.Singleton.Serialize(responseWriter, response);
179 responseWriter.Close();
180 }
181 else
182 {
183 writer.WriteLine("HTTP/1.0 403 Authentication Forbidden");
184 writer.WriteLine();
185 }
186 }
187 }
188
189 private XmlRpcResponse ProcessRequest(XmlRpcRequest request)
190 {
191 XmlRpcResponse response = (XmlRpcResponse)(new XmlRpcResponseDeserializer()).Deserialize(this._defaultResponse);
192
193 Hashtable responseData = (Hashtable)response.Value;
194 Hashtable requestData = (Hashtable)request.Params[0];
195
196 string first;
197 string last;
198 string passwd;
199 LLUUID Agent;
200 LLUUID Session;
201
202 //get login name
203 if(requestData.Contains("first"))
204 {
205 first = (string)requestData["first"];
206 }
207 else
208 {
209 first = "test";
210 }
211
212 if(requestData.Contains("last"))
213 {
214 last = (string)requestData["last"];
215 }
216 else
217 {
218 last = "User"+NumClients.ToString();
219 }
220
221 if(requestData.Contains("passwd"))
222 {
223 passwd = (string)requestData["passwd"];
224 }
225 else
226 {
227 passwd = "notfound";
228 }
229
230 if( !Authenticate(first, last, passwd))
231 {
232 responseData["reason"] = "key";
233 responseData["message"] = "You have entered an invalid name/password combination. Check Caps/lock.";
234 responseData["login"] = "false";
235 }
236 else
237 {
238 NumClients++;
239
240 //create a agent and session LLUUID
241 Agent = GetAgentId( first, last );
242 Session = LLUUID.Random();
243
244 //create some login info
245 Hashtable LoginFlagsHash = new Hashtable();
246 LoginFlagsHash["daylight_savings"]="N";
247 LoginFlagsHash["stipend_since_login"]="N";
248 LoginFlagsHash["gendered"]="Y";
249 LoginFlagsHash["ever_logged_in"]="Y";
250 ArrayList LoginFlags=new ArrayList();
251 LoginFlags.Add(LoginFlagsHash);
252
253 Hashtable GlobalT = new Hashtable();
254 GlobalT["sun_texture_id"] = "cce0f112-878f-4586-a2e2-a8f104bba271";
255 GlobalT["cloud_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
256 GlobalT["moon_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
257 ArrayList GlobalTextures = new ArrayList();
258 GlobalTextures.Add(GlobalT);
259
260 responseData["sim_port"] = OpenSim_Main.cfg.IPListenPort;
261 responseData["sim_ip"] = OpenSim_Main.cfg.IPListenAddr;
262 responseData["agent_id"] = Agent.ToStringHyphenated();
263 responseData["session_id"] = Session.ToStringHyphenated();
264 responseData["seconds_since_epoch"]=(Int32)(DateTime.UtcNow - new DateTime(1970,1,1)).TotalSeconds;
265 responseData["login-flags"]=LoginFlags;
266 responseData["global-textures"]=GlobalTextures;
267
268 //inventory
269 ArrayList InventoryList = (ArrayList) responseData["inventory-skeleton"];
270 Hashtable Inventory1 = (Hashtable)InventoryList[0];
271 Hashtable Inventory2 = (Hashtable)InventoryList[1];
272 LLUUID BaseFolderID = LLUUID.Random();
273 LLUUID InventoryFolderID = LLUUID.Random();
274 Inventory2["name"] = "Base";
275 Inventory2["folder_id"] = BaseFolderID.ToStringHyphenated();
276 Inventory2["type_default"] =6;
277 Inventory1["folder_id"] = InventoryFolderID.ToStringHyphenated();
278
279 ArrayList InventoryRoot = (ArrayList) responseData["inventory-root"];
280 Hashtable Inventoryroot = (Hashtable)InventoryRoot[0];
281 Inventoryroot["folder_id"] = InventoryFolderID.ToStringHyphenated();
282
283 CustomiseLoginResponse( responseData, first, last );
284
285 Login _login = new Login();
286 //copy data to login object
287 _login.First = first;
288 _login.Last = last;
289 _login.Agent = Agent;
290 _login.Session = Session;
291 _login.BaseFolder = BaseFolderID;
292 _login.InventoryFolder = InventoryFolderID;
293
294 //working on local computer if so lets add to the gridserver's list of sessions?
295 if(OpenSim_Main.gridServers.GridServer.GetName() == "Local")
296 {
297 ((LocalGridBase)this._gridServer).AddNewSession(_login);
298 }
299 }
300 return response;
301 }
302
303 protected virtual void CustomiseLoginResponse( Hashtable responseData, string first, string last )
304 {
305 }
306
307 protected virtual LLUUID GetAgentId(string firstName, string lastName)
308 {
309 return LLUUID.Random();
310 }
311
312 protected virtual bool Authenticate(string first, string last, string passwd)
313 {
314 if(this._needPasswd)
315 {
316 //every user needs the password to login
317 string encodedPass = passwd.Remove(0,3); //remove $1$
318 if(encodedPass == this._mpasswd)
319 {
320 return true;
321 }
322 else
323 {
324 return false;
325 }
326 }
327 else
328 {
329 //do not need password to login
330 return true;
331 }
332 }
333
334 private static string EncodePassword(string passwd)
335 {
336 Byte[] originalBytes;
337 Byte[] encodedBytes;
338 MD5 md5;
339
340 md5 = new MD5CryptoServiceProvider();
341 originalBytes = ASCIIEncoding.Default.GetBytes(passwd);
342 encodedBytes = md5.ComputeHash(originalBytes);
343
344 return Regex.Replace(BitConverter.ToString(encodedBytes), "-", "").ToLower();
345 }
346
347 }
348
349
350}