aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.Servers/LoginServer.cs
diff options
context:
space:
mode:
authorMW2007-04-11 13:40:29 +0000
committerMW2007-04-11 13:40:29 +0000
commitbea8e2b82654b558f7131fa262a613de62df9124 (patch)
treeec59130668dee7cff27fcc49925ae64bf7997bb7 /OpenSim.Servers/LoginServer.cs
parentThought OpenSim.Config had been deleted a long time ago. (diff)
downloadopensim-SC-bea8e2b82654b558f7131fa262a613de62df9124.zip
opensim-SC-bea8e2b82654b558f7131fa262a613de62df9124.tar.gz
opensim-SC-bea8e2b82654b558f7131fa262a613de62df9124.tar.bz2
opensim-SC-bea8e2b82654b558f7131fa262a613de62df9124.tar.xz
Renamed the Servers directory to OpenSim.Servers
Diffstat (limited to 'OpenSim.Servers/LoginServer.cs')
-rw-r--r--OpenSim.Servers/LoginServer.cs283
1 files changed, 283 insertions, 0 deletions
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}