aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Common/OpenSim.Servers/LoginServer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Common/OpenSim.Servers/LoginServer.cs')
-rw-r--r--Common/OpenSim.Servers/LoginServer.cs296
1 files changed, 0 insertions, 296 deletions
diff --git a/Common/OpenSim.Servers/LoginServer.cs b/Common/OpenSim.Servers/LoginServer.cs
deleted file mode 100644
index 4f4d76f..0000000
--- a/Common/OpenSim.Servers/LoginServer.cs
+++ /dev/null
@@ -1,296 +0,0 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28
29using Nwc.XmlRpc;
30using System;
31using System.IO;
32using System.Net;
33using System.Net.Sockets;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Threading;
37using System.Collections;
38using System.Security.Cryptography;
39using System.Xml;
40using libsecondlife;
41using OpenSim;
42using OpenSim.Framework.Interfaces;
43using OpenSim.Framework.Grid;
44using OpenSim.Framework.Inventory;
45using OpenSim.Framework.User;
46using OpenSim.Framework.Utilities;
47using OpenSim.Framework.Types;
48
49namespace OpenSim.UserServer
50{
51 public delegate void AddNewSessionHandler(Login loginData);
52 /// <summary>
53 /// When running in local (default) mode , handles client logins.
54 /// </summary>
55 public class LoginServer : LoginService, IUserServer
56 {
57 private IGridServer m_gridServer;
58 public IPAddress clientAddress = IPAddress.Loopback;
59 public IPAddress remoteAddress = IPAddress.Any;
60 private int NumClients;
61 private bool userAccounts = false;
62 private string _mpasswd;
63 private bool _needPasswd = false;
64 private LocalUserProfileManager userManager;
65 private int m_simPort;
66 private string m_simAddr;
67 private uint regionX;
68 private uint regionY;
69 private AddNewSessionHandler AddSession;
70
71 public LocalUserProfileManager LocalUserManager
72 {
73 get
74 {
75 return userManager;
76 }
77 }
78
79 public LoginServer( string simAddr, int simPort, uint regX, uint regY, bool useAccounts)
80 {
81 m_simPort = simPort;
82 m_simAddr = simAddr;
83 regionX = regX;
84 regionY = regY;
85 this.userAccounts = useAccounts;
86 }
87
88 public void SetSessionHandler(AddNewSessionHandler sessionHandler)
89 {
90 this.AddSession = sessionHandler;
91 this.userManager.SetSessionHandler(sessionHandler);
92 }
93
94 public void Startup()
95 {
96 this._needPasswd = false;
97
98 this._mpasswd = EncodePassword("testpass");
99
100 userManager = new LocalUserProfileManager(this.m_gridServer, m_simPort, m_simAddr, regionX, regionY);
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
113 LoginResponse loginResponse = new LoginResponse();
114 loginResponse.RegionX = regionX;
115 loginResponse.RegionY = regionY;
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 // 7 June 2007, AJD:
160 // [10:03:05] (@AdamZaius) Sandbox should work listening on 0.0.0.0 if you can fix the login XML reply
161 // OLD: loginResponse.SimAddress = m_simAddr.ToString();
162 loginResponse.SimAddress = "0.0.0.0";
163
164 // loginResponse.AgentID = Agent.ToStringHyphenated();
165 // loginResponse.SessionID = Session.ToStringHyphenated();
166 // loginResponse.SecureSessionID = secureSess.ToStringHyphenated();
167 loginResponse.CircuitCode = (Int32)(Util.RandomClass.Next());
168 XmlRpcResponse response = loginResponse.ToXmlRpcResponse();
169 Hashtable responseData = (Hashtable)response.Value;
170
171 //inventory
172 /* ArrayList InventoryList = (ArrayList)responseData["inventory-skeleton"];
173 Hashtable Inventory1 = (Hashtable)InventoryList[0];
174 Hashtable Inventory2 = (Hashtable)InventoryList[1];
175 LLUUID BaseFolderID = LLUUID.Random();
176 LLUUID InventoryFolderID = LLUUID.Random();
177 Inventory2["name"] = "Textures";
178 Inventory2["folder_id"] = BaseFolderID.ToStringHyphenated();
179 Inventory2["type_default"] = 0;
180 Inventory1["folder_id"] = InventoryFolderID.ToStringHyphenated();
181
182 ArrayList InventoryRoot = (ArrayList)responseData["inventory-root"];
183 Hashtable Inventoryroot = (Hashtable)InventoryRoot[0];
184 Inventoryroot["folder_id"] = InventoryFolderID.ToStringHyphenated();
185 */
186 CustomiseLoginResponse(responseData, first, last);
187
188 Login _login = new Login();
189 //copy data to login object
190 _login.First = first;
191 _login.Last = last;
192 _login.Agent = loginResponse.AgentID;
193 _login.Session = loginResponse.SessionID;
194 _login.SecureSession = loginResponse.SecureSessionID;
195 _login.CircuitCode = (uint) loginResponse.CircuitCode;
196 _login.BaseFolder = loginResponse.BaseFolderID;
197 _login.InventoryFolder = loginResponse.InventoryFolderID;
198
199 //working on local computer if so lets add to the gridserver's list of sessions?
200 /* if (m_gridServer.GetName() == "Local")
201 {
202 ((LocalGridBase)m_gridServer).AddNewSession(_login);
203 }*/
204 AddSession(_login);
205
206 return response;
207 }
208
209 protected virtual void CustomiseLoginResponse(Hashtable responseData, string first, string last)
210 {
211 }
212
213 protected virtual LLUUID GetAgentId(string firstName, string lastName)
214 {
215 LLUUID Agent;
216 int AgentRand = Util.RandomClass.Next(1, 9999);
217 Agent = new LLUUID("99998888-0100-" + AgentRand.ToString("0000") + "-8ec1-0b1d5cd6aead");
218 return Agent;
219 }
220
221 protected virtual bool Authenticate(string first, string last, string passwd)
222 {
223 if (this._needPasswd)
224 {
225 //every user needs the password to login
226 string encodedPass = passwd.Remove(0, 3); //remove $1$
227 if (encodedPass == this._mpasswd)
228 {
229 return true;
230 }
231 else
232 {
233 return false;
234 }
235 }
236 else
237 {
238 //do not need password to login
239 return true;
240 }
241 }
242
243 private static string EncodePassword(string passwd)
244 {
245 Byte[] originalBytes;
246 Byte[] encodedBytes;
247 MD5 md5;
248
249 md5 = new MD5CryptoServiceProvider();
250 originalBytes = ASCIIEncoding.Default.GetBytes(passwd);
251 encodedBytes = md5.ComputeHash(originalBytes);
252
253 return Regex.Replace(BitConverter.ToString(encodedBytes), "-", "").ToLower();
254 }
255
256 public bool CreateUserAccount(string firstName, string lastName, string password)
257 {
258 Console.WriteLine("creating new user account");
259 string mdPassword = EncodePassword(password);
260 Console.WriteLine("with password: " + mdPassword);
261 this.userManager.CreateNewProfile(firstName, lastName, mdPassword);
262
263 return true;
264 }
265
266 public UserProfile GetProfileByName(string firstName, string lastName)
267 {
268 return this.userManager.GetProfileByName(firstName, lastName);
269 }
270
271
272 //IUserServer implementation
273 public AgentInventory RequestAgentsInventory(LLUUID agentID)
274 {
275 AgentInventory aInventory = null;
276 if (this.userAccounts)
277 {
278 aInventory = this.userManager.GetUsersInventory(agentID);
279 }
280
281 return aInventory;
282 }
283
284 public bool UpdateAgentsInventory(LLUUID agentID, AgentInventory inventory)
285 {
286 return true;
287 }
288
289 public void SetServerInfo(string ServerUrl, string SendKey, string RecvKey)
290 {
291
292 }
293 }
294
295
296}