aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Common-Source/OpenSim.Servers/LoginServer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Common-Source/OpenSim.Servers/LoginServer.cs')
-rw-r--r--Common-Source/OpenSim.Servers/LoginServer.cs284
1 files changed, 0 insertions, 284 deletions
diff --git a/Common-Source/OpenSim.Servers/LoginServer.cs b/Common-Source/OpenSim.Servers/LoginServer.cs
deleted file mode 100644
index 6fd174b..0000000
--- a/Common-Source/OpenSim.Servers/LoginServer.cs
+++ /dev/null
@@ -1,284 +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.Interfaces;
42using OpenSim.Framework.Grid;
43using OpenSim.Framework.Inventory;
44using OpenSim.Framework.User;
45using OpenSim.Framework.Utilities;
46using OpenSim.Framework.Types;
47
48namespace OpenSim.UserServer
49{
50 public delegate void AddNewSessionHandler(Login loginData);
51 /// <summary>
52 /// When running in local (default) mode , handles client logins.
53 /// </summary>
54 public class LoginServer : LoginService, IUserServer
55 {
56 private IGridServer m_gridServer;
57 public IPAddress clientAddress = IPAddress.Loopback;
58 public IPAddress remoteAddress = IPAddress.Any;
59 private int NumClients;
60 private bool userAccounts = false;
61 private string _mpasswd;
62 private bool _needPasswd = false;
63 private LocalUserProfileManager userManager;
64 private int m_simPort;
65 private string m_simAddr;
66 private uint regionX;
67 private uint regionY;
68 private AddNewSessionHandler AddSession;
69
70 public LocalUserProfileManager LocalUserManager
71 {
72 get
73 {
74 return userManager;
75 }
76 }
77
78 public LoginServer( string simAddr, int simPort, uint regX, uint regY, bool useAccounts)
79 {
80 m_simPort = simPort;
81 m_simAddr = simAddr;
82 regionX = regX;
83 regionY = regY;
84 this.userAccounts = useAccounts;
85 }
86
87 public void SetSessionHandler(AddNewSessionHandler sessionHandler)
88 {
89 this.AddSession = sessionHandler;
90 this.userManager.SetSessionHandler(sessionHandler);
91 }
92
93 public void Startup()
94 {
95 this._needPasswd = false;
96
97 this._mpasswd = EncodePassword("testpass");
98
99 userManager = new LocalUserProfileManager(this.m_gridServer, m_simPort, m_simAddr, regionX, regionY);
100 //userManager.InitUserProfiles();
101 userManager.SetKeys("", "", "", "Welcome to OpenSim");
102 }
103
104 public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
105 {
106 Console.WriteLine("login attempt");
107 Hashtable requestData = (Hashtable)request.Params[0];
108 string first;
109 string last;
110 string passwd;
111
112 LoginResponse loginResponse = new LoginResponse();
113 loginResponse.RegionX = regionX;
114 loginResponse.RegionY = regionY;
115
116 //get login name
117 if (requestData.Contains("first"))
118 {
119 first = (string)requestData["first"];
120 }
121 else
122 {
123 first = "test";
124 }
125
126 if (requestData.Contains("last"))
127 {
128 last = (string)requestData["last"];
129 }
130 else
131 {
132 last = "User" + NumClients.ToString();
133 }
134
135 if (requestData.Contains("passwd"))
136 {
137 passwd = (string)requestData["passwd"];
138 }
139 else
140 {
141 passwd = "notfound";
142 }
143
144 if (!Authenticate(first, last, passwd))
145 {
146 return loginResponse.LoginFailedResponse();
147 }
148
149 NumClients++;
150
151 // Create a agent and session LLUUID
152 // Agent = GetAgentId(first, last);
153 // int SessionRand = Util.RandomClass.Next(1, 999);
154 // Session = new LLUUID("aaaabbbb-0200-" + SessionRand.ToString("0000") + "-8664-58f53e442797");
155 // LLUUID secureSess = LLUUID.Random();
156
157 loginResponse.SimPort = m_simPort.ToString();
158 loginResponse.SimAddress = m_simAddr.ToString();
159 // loginResponse.AgentID = Agent.ToStringHyphenated();
160 // loginResponse.SessionID = Session.ToStringHyphenated();
161 // loginResponse.SecureSessionID = secureSess.ToStringHyphenated();
162 loginResponse.CircuitCode = (Int32)(Util.RandomClass.Next());
163 XmlRpcResponse response = loginResponse.ToXmlRpcResponse();
164 Hashtable responseData = (Hashtable)response.Value;
165
166 //inventory
167 /* ArrayList InventoryList = (ArrayList)responseData["inventory-skeleton"];
168 Hashtable Inventory1 = (Hashtable)InventoryList[0];
169 Hashtable Inventory2 = (Hashtable)InventoryList[1];
170 LLUUID BaseFolderID = LLUUID.Random();
171 LLUUID InventoryFolderID = LLUUID.Random();
172 Inventory2["name"] = "Textures";
173 Inventory2["folder_id"] = BaseFolderID.ToStringHyphenated();
174 Inventory2["type_default"] = 0;
175 Inventory1["folder_id"] = InventoryFolderID.ToStringHyphenated();
176
177 ArrayList InventoryRoot = (ArrayList)responseData["inventory-root"];
178 Hashtable Inventoryroot = (Hashtable)InventoryRoot[0];
179 Inventoryroot["folder_id"] = InventoryFolderID.ToStringHyphenated();
180 */
181 CustomiseLoginResponse(responseData, first, last);
182
183 Login _login = new Login();
184 //copy data to login object
185 _login.First = first;
186 _login.Last = last;
187 _login.Agent = loginResponse.AgentID;
188 _login.Session = loginResponse.SessionID;
189 _login.SecureSession = loginResponse.SecureSessionID;
190 _login.CircuitCode = (uint) loginResponse.CircuitCode;
191 _login.BaseFolder = loginResponse.BaseFolderID;
192 _login.InventoryFolder = loginResponse.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 AddSession(_login);
200
201 return response;
202 }
203
204 protected virtual void CustomiseLoginResponse(Hashtable responseData, string first, string last)
205 {
206 }
207
208 protected virtual LLUUID GetAgentId(string firstName, string lastName)
209 {
210 LLUUID Agent;
211 int AgentRand = Util.RandomClass.Next(1, 9999);
212 Agent = new LLUUID("99998888-0100-" + AgentRand.ToString("0000") + "-8ec1-0b1d5cd6aead");
213 return Agent;
214 }
215
216 protected virtual bool Authenticate(string first, string last, string passwd)
217 {
218 if (this._needPasswd)
219 {
220 //every user needs the password to login
221 string encodedPass = passwd.Remove(0, 3); //remove $1$
222 if (encodedPass == this._mpasswd)
223 {
224 return true;
225 }
226 else
227 {
228 return false;
229 }
230 }
231 else
232 {
233 //do not need password to login
234 return true;
235 }
236 }
237
238 private static string EncodePassword(string passwd)
239 {
240 Byte[] originalBytes;
241 Byte[] encodedBytes;
242 MD5 md5;
243
244 md5 = new MD5CryptoServiceProvider();
245 originalBytes = ASCIIEncoding.Default.GetBytes(passwd);
246 encodedBytes = md5.ComputeHash(originalBytes);
247
248 return Regex.Replace(BitConverter.ToString(encodedBytes), "-", "").ToLower();
249 }
250
251 public bool CreateUserAccount(string firstName, string lastName, string password)
252 {
253 Console.WriteLine("creating new user account");
254 string mdPassword = EncodePassword(password);
255 Console.WriteLine("with password: " + mdPassword);
256 this.userManager.CreateNewProfile(firstName, lastName, mdPassword);
257 return true;
258 }
259
260 //IUserServer implementation
261 public AgentInventory RequestAgentsInventory(LLUUID agentID)
262 {
263 AgentInventory aInventory = null;
264 if (this.userAccounts)
265 {
266 aInventory = this.userManager.GetUsersInventory(agentID);
267 }
268
269 return aInventory;
270 }
271
272 public bool UpdateAgentsInventory(LLUUID agentID, AgentInventory inventory)
273 {
274 return true;
275 }
276
277 public void SetServerInfo(string ServerUrl, string SendKey, string RecvKey)
278 {
279
280 }
281 }
282
283
284}