aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Servers
diff options
context:
space:
mode:
authorlbsa712007-03-29 19:42:58 +0000
committerlbsa712007-03-29 19:42:58 +0000
commitfeaf036aa2d83d493f1a5c7bb3ba7bec57f4c41e (patch)
treea0fe02996a7d0cd226ab7a658ad55e204c3a2410 /Servers
parent* Now the rest handlers try to match path as close as possibly, so it's possi... (diff)
downloadopensim-SC_OLD-feaf036aa2d83d493f1a5c7bb3ba7bec57f4c41e.zip
opensim-SC_OLD-feaf036aa2d83d493f1a5c7bb3ba7bec57f4c41e.tar.gz
opensim-SC_OLD-feaf036aa2d83d493f1a5c7bb3ba7bec57f4c41e.tar.bz2
opensim-SC_OLD-feaf036aa2d83d493f1a5c7bb3ba7bec57f4c41e.tar.xz
* Moved LoginServer and LocalUserProfileManager to OpenSim.Servers
Diffstat (limited to 'Servers')
-rw-r--r--Servers/LocalUserProfileManager.cs109
-rw-r--r--Servers/LoginServer.cs305
-rw-r--r--Servers/OpenSim.Servers.csproj6
-rw-r--r--Servers/OpenSim.Servers.dll.build2
4 files changed, 422 insertions, 0 deletions
diff --git a/Servers/LocalUserProfileManager.cs b/Servers/LocalUserProfileManager.cs
new file mode 100644
index 0000000..6166e02
--- /dev/null
+++ b/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/Servers/LoginServer.cs b/Servers/LoginServer.cs
new file mode 100644
index 0000000..e0c090a
--- /dev/null
+++ b/Servers/LoginServer.cs
@@ -0,0 +1,305 @@
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
50 /// <summary>
51 /// When running in local (default) mode , handles client logins.
52 /// </summary>
53 public class LoginServer : LoginService, IUserServer
54 {
55 private IGridServer m_gridServer;
56 public IPAddress clientAddress = IPAddress.Loopback;
57 public IPAddress remoteAddress = IPAddress.Any;
58 private int NumClients;
59 private string _defaultResponse;
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
67 public LocalUserProfileManager LocalUserManager
68 {
69 get
70 {
71 return userManager;
72 }
73 }
74
75 public LoginServer(IGridServer gridServer, string simAddr, int simPort, bool useAccounts)
76 {
77 m_gridServer = gridServer;
78 m_simPort = simPort;
79 m_simAddr = simAddr;
80 this.userAccounts = useAccounts;
81 }
82
83 public void Startup()
84 {
85 this._needPasswd = false;
86 //read in default response string
87 StreamReader SR;
88 string lines;
89 SR = File.OpenText("new-login.dat");
90
91 while (!SR.EndOfStream)
92 {
93 lines = SR.ReadLine();
94 _defaultResponse += lines;
95 }
96 SR.Close();
97 this._mpasswd = EncodePassword("testpass");
98
99 userManager = new LocalUserProfileManager(this.m_gridServer, m_simPort, m_simAddr);
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 LLUUID Agent;
112 LLUUID Session;
113
114 XmlRpcResponse response = new XmlRpcResponse();
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 Hashtable loginError = new Hashtable();
147 loginError["reason"] = "key"; ;
148 loginError["message"] = "You have entered an invalid name/password combination. Check Caps/lock.";
149 loginError["login"] = "false";
150 response.Value = loginError;
151 }
152
153 NumClients++;
154
155 //create a agent and session LLUUID
156 Agent = GetAgentId(first, last);
157 int SessionRand = Util.RandomClass.Next(1, 999);
158 Session = new LLUUID("aaaabbbb-0200-" + SessionRand.ToString("0000") + "-8664-58f53e442797");
159 LLUUID secureSess = LLUUID.Random();
160 //create some login info
161 Hashtable LoginFlagsHash = new Hashtable();
162 LoginFlagsHash["daylight_savings"] = "N";
163 LoginFlagsHash["stipend_since_login"] = "N";
164 LoginFlagsHash["gendered"] = "Y";
165 LoginFlagsHash["ever_logged_in"] = "Y";
166 ArrayList LoginFlags = new ArrayList();
167 LoginFlags.Add(LoginFlagsHash);
168
169 Hashtable GlobalT = new Hashtable();
170 GlobalT["sun_texture_id"] = "cce0f112-878f-4586-a2e2-a8f104bba271";
171 GlobalT["cloud_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
172 GlobalT["moon_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
173 ArrayList GlobalTextures = new ArrayList();
174 GlobalTextures.Add(GlobalT);
175
176 response = (XmlRpcResponse)(new XmlRpcResponseDeserializer()).Deserialize(this._defaultResponse);
177 Hashtable responseData = (Hashtable)response.Value;
178
179 responseData["sim_port"] = m_simPort;
180 responseData["sim_ip"] = m_simAddr;
181 responseData["agent_id"] = Agent.ToStringHyphenated();
182 responseData["session_id"] = Session.ToStringHyphenated();
183 responseData["secure_session_id"] = secureSess.ToStringHyphenated();
184 responseData["circuit_code"] = (Int32)(Util.RandomClass.Next());
185 responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
186 responseData["login-flags"] = LoginFlags;
187 responseData["global-textures"] = GlobalTextures;
188
189 //inventory
190 ArrayList InventoryList = (ArrayList)responseData["inventory-skeleton"];
191 Hashtable Inventory1 = (Hashtable)InventoryList[0];
192 Hashtable Inventory2 = (Hashtable)InventoryList[1];
193 LLUUID BaseFolderID = LLUUID.Random();
194 LLUUID InventoryFolderID = LLUUID.Random();
195 Inventory2["name"] = "Textures";
196 Inventory2["folder_id"] = BaseFolderID.ToStringHyphenated();
197 Inventory2["type_default"] = 0;
198 Inventory1["folder_id"] = InventoryFolderID.ToStringHyphenated();
199
200 ArrayList InventoryRoot = (ArrayList)responseData["inventory-root"];
201 Hashtable Inventoryroot = (Hashtable)InventoryRoot[0];
202 Inventoryroot["folder_id"] = InventoryFolderID.ToStringHyphenated();
203
204 CustomiseLoginResponse(responseData, first, last);
205
206 Login _login = new Login();
207 //copy data to login object
208 _login.First = first;
209 _login.Last = last;
210 _login.Agent = Agent;
211 _login.Session = Session;
212 _login.SecureSession = secureSess;
213 _login.BaseFolder = BaseFolderID;
214 _login.InventoryFolder = InventoryFolderID;
215
216 //working on local computer if so lets add to the gridserver's list of sessions?
217 if (m_gridServer.GetName() == "Local")
218 {
219 ((LocalGridBase)m_gridServer).AddNewSession(_login);
220 }
221
222 return response;
223 }
224
225 protected virtual void CustomiseLoginResponse(Hashtable responseData, string first, string last)
226 {
227 }
228
229 protected virtual LLUUID GetAgentId(string firstName, string lastName)
230 {
231 LLUUID Agent;
232 int AgentRand = Util.RandomClass.Next(1, 9999);
233 Agent = new LLUUID("99998888-0100-" + AgentRand.ToString("0000") + "-8ec1-0b1d5cd6aead");
234 return Agent;
235 }
236
237 protected virtual bool Authenticate(string first, string last, string passwd)
238 {
239 if (this._needPasswd)
240 {
241 //every user needs the password to login
242 string encodedPass = passwd.Remove(0, 3); //remove $1$
243 if (encodedPass == this._mpasswd)
244 {
245 return true;
246 }
247 else
248 {
249 return false;
250 }
251 }
252 else
253 {
254 //do not need password to login
255 return true;
256 }
257 }
258
259 private static string EncodePassword(string passwd)
260 {
261 Byte[] originalBytes;
262 Byte[] encodedBytes;
263 MD5 md5;
264
265 md5 = new MD5CryptoServiceProvider();
266 originalBytes = ASCIIEncoding.Default.GetBytes(passwd);
267 encodedBytes = md5.ComputeHash(originalBytes);
268
269 return Regex.Replace(BitConverter.ToString(encodedBytes), "-", "").ToLower();
270 }
271
272 public bool CreateUserAccount(string firstName, string lastName, string password)
273 {
274 Console.WriteLine("creating new user account");
275 string mdPassword = EncodePassword(password);
276 Console.WriteLine("with password: " + mdPassword);
277 this.userManager.CreateNewProfile(firstName, lastName, mdPassword);
278 return true;
279 }
280
281 //IUserServer implementation
282 public AgentInventory RequestAgentsInventory(LLUUID agentID)
283 {
284 AgentInventory aInventory = null;
285 if (this.userAccounts)
286 {
287 aInventory = this.userManager.GetUsersInventory(agentID);
288 }
289
290 return aInventory;
291 }
292
293 public bool UpdateAgentsInventory(LLUUID agentID, AgentInventory inventory)
294 {
295 return true;
296 }
297
298 public void SetServerInfo(string ServerUrl, string SendKey, string RecvKey)
299 {
300
301 }
302 }
303
304
305}
diff --git a/Servers/OpenSim.Servers.csproj b/Servers/OpenSim.Servers.csproj
index d85c029..bff2454 100644
--- a/Servers/OpenSim.Servers.csproj
+++ b/Servers/OpenSim.Servers.csproj
@@ -92,6 +92,12 @@
92 <Compile Include="IRestHandler.cs"> 92 <Compile Include="IRestHandler.cs">
93 <SubType>Code</SubType> 93 <SubType>Code</SubType>
94 </Compile> 94 </Compile>
95 <Compile Include="LocalUserProfileManager.cs">
96 <SubType>Code</SubType>
97 </Compile>
98 <Compile Include="LoginServer.cs">
99 <SubType>Code</SubType>
100 </Compile>
95 <Compile Include="XmlRpcMethod.cs"> 101 <Compile Include="XmlRpcMethod.cs">
96 <SubType>Code</SubType> 102 <SubType>Code</SubType>
97 </Compile> 103 </Compile>
diff --git a/Servers/OpenSim.Servers.dll.build b/Servers/OpenSim.Servers.dll.build
index 48e8dec..4bf9d18 100644
--- a/Servers/OpenSim.Servers.dll.build
+++ b/Servers/OpenSim.Servers.dll.build
@@ -13,6 +13,8 @@
13 <sources failonempty="true"> 13 <sources failonempty="true">
14 <include name="BaseHttpServer.cs" /> 14 <include name="BaseHttpServer.cs" />
15 <include name="IRestHandler.cs" /> 15 <include name="IRestHandler.cs" />
16 <include name="LocalUserProfileManager.cs" />
17 <include name="LoginServer.cs" />
16 <include name="XmlRpcMethod.cs" /> 18 <include name="XmlRpcMethod.cs" />
17 </sources> 19 </sources>
18 <references basedir="${project::get-base-directory()}"> 20 <references basedir="${project::get-base-directory()}">