diff options
Diffstat (limited to '')
-rw-r--r-- | Common/OpenSim.Framework/UserProfileManager.cs | 272 |
1 files changed, 272 insertions, 0 deletions
diff --git a/Common/OpenSim.Framework/UserProfileManager.cs b/Common/OpenSim.Framework/UserProfileManager.cs new file mode 100644 index 0000000..18b3513 --- /dev/null +++ b/Common/OpenSim.Framework/UserProfileManager.cs | |||
@@ -0,0 +1,272 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Collections; | ||
4 | using System.Text; | ||
5 | using System.Text.RegularExpressions; | ||
6 | using System.Xml; | ||
7 | using libsecondlife; | ||
8 | using Nwc.XmlRpc; | ||
9 | using OpenSim.Framework.Sims; | ||
10 | using OpenSim.Framework.Inventory; | ||
11 | using OpenSim.Framework.Utilities; | ||
12 | |||
13 | namespace OpenSim.Framework.User | ||
14 | { | ||
15 | public class UserProfileManager : UserProfileManagerBase | ||
16 | { | ||
17 | public string GridURL; | ||
18 | public string GridSendKey; | ||
19 | public string GridRecvKey; | ||
20 | public string DefaultStartupMsg; | ||
21 | |||
22 | public UserProfileManager() | ||
23 | { | ||
24 | |||
25 | } | ||
26 | |||
27 | public void SetKeys(string sendKey, string recvKey, string url, string message) | ||
28 | { | ||
29 | GridRecvKey = recvKey; | ||
30 | GridSendKey = sendKey; | ||
31 | GridURL = url; | ||
32 | DefaultStartupMsg = message; | ||
33 | } | ||
34 | |||
35 | public virtual string ParseXMLRPC(string requestBody) | ||
36 | { | ||
37 | |||
38 | XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); | ||
39 | |||
40 | switch (request.MethodName) | ||
41 | { | ||
42 | case "login_to_simulator": | ||
43 | XmlRpcResponse response = XmlRpcLoginMethod(request); | ||
44 | |||
45 | return (Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(response), "utf-16", "utf-8")); | ||
46 | } | ||
47 | |||
48 | return ""; | ||
49 | } | ||
50 | |||
51 | public string RestDeleteUserSessionMethod( string request, string path, string param ) | ||
52 | { | ||
53 | LLUUID sessionid = new LLUUID(param); // get usersessions/sessionid | ||
54 | foreach (libsecondlife.LLUUID UUID in UserProfiles.Keys) | ||
55 | { | ||
56 | if ( UserProfiles[UUID].CurrentSessionID == sessionid) | ||
57 | { | ||
58 | UserProfiles[UUID].CurrentSessionID = null; | ||
59 | UserProfiles[UUID].CurrentSecureSessionID = null; | ||
60 | UserProfiles[UUID].Circuits.Clear(); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | return "OK"; | ||
65 | } | ||
66 | |||
67 | public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request) | ||
68 | { | ||
69 | XmlRpcResponse response = new XmlRpcResponse(); | ||
70 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
71 | |||
72 | bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && requestData.Contains("passwd")); | ||
73 | bool GoodLogin = false; | ||
74 | string firstname = ""; | ||
75 | string lastname = ""; | ||
76 | string passwd = ""; | ||
77 | |||
78 | if (GoodXML) | ||
79 | { | ||
80 | firstname = (string)requestData["first"]; | ||
81 | lastname = (string)requestData["last"]; | ||
82 | passwd = (string)requestData["passwd"]; | ||
83 | GoodLogin = AuthenticateUser(firstname, lastname, passwd); | ||
84 | } | ||
85 | |||
86 | |||
87 | if (!(GoodXML && GoodLogin)) | ||
88 | { | ||
89 | response = CreateErrorConnectingToGridResponse(); | ||
90 | } | ||
91 | else | ||
92 | { | ||
93 | UserProfile TheUser = GetProfileByName(firstname, lastname); | ||
94 | //we need to sort out how sessions are logged out , currently the sim tells the gridserver | ||
95 | //but if as this suggests the userserver handles it then please have the sim telling the userserver instead | ||
96 | //as it really makes things messy for sandbox mode | ||
97 | //if (!((TheUser.CurrentSessionID == null) && (TheUser.CurrentSecureSessionID == null))) | ||
98 | // { | ||
99 | // response = CreateAlreadyLoggedInResponse(); | ||
100 | // } | ||
101 | //else | ||
102 | //{ | ||
103 | try | ||
104 | { | ||
105 | Hashtable responseData = new Hashtable(); | ||
106 | |||
107 | LLUUID AgentID = TheUser.UUID; | ||
108 | TheUser.InitSessionData(); | ||
109 | |||
110 | //for loading data from a grid server, make any changes in CustomiseResponse() (or create a sub class of this and override that method) | ||
111 | //SimProfile SimInfo = new SimProfile(); | ||
112 | //SimInfo = SimInfo.LoadFromGrid(TheUser.homeregionhandle, GridURL, GridSendKey, GridRecvKey); | ||
113 | |||
114 | |||
115 | Hashtable GlobalT = new Hashtable(); | ||
116 | GlobalT["sun_texture_id"] = "cce0f112-878f-4586-a2e2-a8f104bba271"; | ||
117 | GlobalT["cloud_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621"; | ||
118 | GlobalT["moon_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621"; | ||
119 | ArrayList GlobalTextures = new ArrayList(); | ||
120 | GlobalTextures.Add(GlobalT); | ||
121 | |||
122 | Hashtable LoginFlagsHash = new Hashtable(); | ||
123 | LoginFlagsHash["daylight_savings"] = "N"; | ||
124 | LoginFlagsHash["stipend_since_login"] = "N"; | ||
125 | LoginFlagsHash["gendered"] = "Y"; | ||
126 | LoginFlagsHash["ever_logged_in"] = "Y"; | ||
127 | ArrayList LoginFlags = new ArrayList(); | ||
128 | LoginFlags.Add(LoginFlagsHash); | ||
129 | |||
130 | Hashtable uiconfig = new Hashtable(); | ||
131 | uiconfig["allow_first_life"] = "Y"; | ||
132 | ArrayList ui_config = new ArrayList(); | ||
133 | ui_config.Add(uiconfig); | ||
134 | |||
135 | Hashtable ClassifiedCategoriesHash = new Hashtable(); | ||
136 | ClassifiedCategoriesHash["category_name"] = "bla bla"; | ||
137 | ClassifiedCategoriesHash["category_id"] = (Int32)1; | ||
138 | ArrayList ClassifiedCategories = new ArrayList(); | ||
139 | ClassifiedCategories.Add(ClassifiedCategoriesHash); | ||
140 | |||
141 | ArrayList AgentInventory = new ArrayList(); | ||
142 | Console.WriteLine("adding inventory to response"); | ||
143 | Hashtable TempHash; | ||
144 | foreach (InventoryFolder InvFolder in TheUser.Inventory.InventoryFolders.Values) | ||
145 | { | ||
146 | TempHash = new Hashtable(); | ||
147 | Console.WriteLine("adding folder " + InvFolder.FolderName + ", ID: " + InvFolder.FolderID.ToStringHyphenated() + " with parent: " + InvFolder.ParentID.ToStringHyphenated()); | ||
148 | TempHash["name"] = InvFolder.FolderName; | ||
149 | TempHash["parent_id"] = InvFolder.ParentID.ToStringHyphenated(); | ||
150 | TempHash["version"] = (Int32)InvFolder.Version; | ||
151 | TempHash["type_default"] = (Int32)InvFolder.DefaultType; | ||
152 | TempHash["folder_id"] = InvFolder.FolderID.ToStringHyphenated(); | ||
153 | AgentInventory.Add(TempHash); | ||
154 | } | ||
155 | |||
156 | Hashtable InventoryRootHash = new Hashtable(); | ||
157 | InventoryRootHash["folder_id"] = TheUser.Inventory.InventoryRoot.FolderID.ToStringHyphenated(); | ||
158 | ArrayList InventoryRoot = new ArrayList(); | ||
159 | InventoryRoot.Add(InventoryRootHash); | ||
160 | |||
161 | Hashtable InitialOutfitHash = new Hashtable(); | ||
162 | InitialOutfitHash["folder_name"] = "Nightclub Female"; | ||
163 | InitialOutfitHash["gender"] = "female"; | ||
164 | ArrayList InitialOutfit = new ArrayList(); | ||
165 | InitialOutfit.Add(InitialOutfitHash); | ||
166 | |||
167 | uint circode = (uint)(Util.RandomClass.Next()); | ||
168 | //TheUser.AddSimCircuit(circode, SimInfo.UUID); | ||
169 | |||
170 | responseData["last_name"] = TheUser.lastname; | ||
171 | responseData["ui-config"] = ui_config; | ||
172 | responseData["sim_ip"] = "127.0.0.1"; //SimInfo.sim_ip.ToString(); | ||
173 | responseData["login-flags"] = LoginFlags; | ||
174 | responseData["global-textures"] = GlobalTextures; | ||
175 | responseData["classified_categories"] = ClassifiedCategories; | ||
176 | responseData["event_categories"] = new ArrayList(); | ||
177 | responseData["inventory-skeleton"] = AgentInventory; | ||
178 | responseData["inventory-skel-lib"] = new ArrayList(); | ||
179 | responseData["inventory-root"] = InventoryRoot; | ||
180 | responseData["event_notifications"] = new ArrayList(); | ||
181 | responseData["gestures"] = new ArrayList(); | ||
182 | responseData["inventory-lib-owner"] = new ArrayList(); | ||
183 | responseData["initial-outfit"] = InitialOutfit; | ||
184 | responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; | ||
185 | responseData["start_location"] = "last"; | ||
186 | responseData["home"] = "{'region_handle':[r" + (0 * 256).ToString() + ",r" + (0 * 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() + "]}"; | ||
187 | responseData["message"] = DefaultStartupMsg; | ||
188 | responseData["first_name"] = TheUser.firstname; | ||
189 | responseData["circuit_code"] = (Int32)circode; | ||
190 | responseData["sim_port"] = 0; //(Int32)SimInfo.sim_port; | ||
191 | responseData["secure_session_id"] = TheUser.CurrentSecureSessionID.ToStringHyphenated(); | ||
192 | responseData["look_at"] = "\n[r" + TheUser.homelookat.X.ToString() + ",r" + TheUser.homelookat.Y.ToString() + ",r" + TheUser.homelookat.Z.ToString() + "]\n"; | ||
193 | responseData["agent_id"] = AgentID.ToStringHyphenated(); | ||
194 | responseData["region_y"] = (Int32)0 * 256; // (Int32)SimInfo.RegionLocY * 256; | ||
195 | responseData["region_x"] = (Int32)0 * 256; //SimInfo.RegionLocX * 256; | ||
196 | responseData["seed_capability"] = ""; | ||
197 | responseData["agent_access"] = "M"; | ||
198 | responseData["session_id"] = TheUser.CurrentSessionID.ToStringHyphenated(); | ||
199 | responseData["login"] = "true"; | ||
200 | |||
201 | this.CustomiseResponse(ref responseData, TheUser); | ||
202 | response.Value = responseData; | ||
203 | // TheUser.SendDataToSim(SimInfo); | ||
204 | return response; | ||
205 | |||
206 | } | ||
207 | catch (Exception E) | ||
208 | { | ||
209 | Console.WriteLine(E.ToString()); | ||
210 | } | ||
211 | //} | ||
212 | } | ||
213 | return response; | ||
214 | |||
215 | } | ||
216 | |||
217 | private static XmlRpcResponse CreateErrorConnectingToGridResponse() | ||
218 | { | ||
219 | XmlRpcResponse response = new XmlRpcResponse(); | ||
220 | Hashtable ErrorRespData = new Hashtable(); | ||
221 | ErrorRespData["reason"] = "key"; | ||
222 | ErrorRespData["message"] = "Error connecting to grid. Please double check your login details and check with the grid owner if you are sure these are correct"; | ||
223 | ErrorRespData["login"] = "false"; | ||
224 | response.Value = ErrorRespData; | ||
225 | return response; | ||
226 | } | ||
227 | |||
228 | private static XmlRpcResponse CreateAlreadyLoggedInResponse() | ||
229 | { | ||
230 | XmlRpcResponse response = new XmlRpcResponse(); | ||
231 | Hashtable PresenceErrorRespData = new Hashtable(); | ||
232 | PresenceErrorRespData["reason"] = "presence"; | ||
233 | PresenceErrorRespData["message"] = "You appear to be already logged in, if this is not the case please wait for your session to timeout, if this takes longer than a few minutes please contact the grid owner"; | ||
234 | PresenceErrorRespData["login"] = "false"; | ||
235 | response.Value = PresenceErrorRespData; | ||
236 | return response; | ||
237 | } | ||
238 | |||
239 | public virtual void CustomiseResponse(ref Hashtable response, UserProfile theUser) | ||
240 | { | ||
241 | //default method set up to act as ogs user server | ||
242 | SimProfile SimInfo= new SimProfile(); | ||
243 | //get siminfo from grid server | ||
244 | SimInfo = SimInfo.LoadFromGrid(theUser.homeregionhandle, GridURL, GridSendKey, GridRecvKey); | ||
245 | Int32 circode = (Int32)Convert.ToUInt32(response["circuit_code"]); | ||
246 | theUser.AddSimCircuit((uint)circode, SimInfo.UUID); | ||
247 | response["home"] = "{'region_handle':[r" + (SimInfo.RegionLocX * 256).ToString() + ",r" + (SimInfo.RegionLocY * 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() + "]}"; | ||
248 | response["sim_ip"] = SimInfo.sim_ip; | ||
249 | response["sim_port"] = (Int32)SimInfo.sim_port; | ||
250 | response["region_y"] = (Int32)SimInfo.RegionLocY * 256; | ||
251 | response["region_x"] = (Int32)SimInfo.RegionLocX * 256; | ||
252 | |||
253 | //default is ogs user server, so let the sim know about the user via a XmlRpcRequest | ||
254 | Console.WriteLine(SimInfo.caps_url); | ||
255 | Hashtable SimParams = new Hashtable(); | ||
256 | SimParams["session_id"] = theUser.CurrentSessionID.ToString(); | ||
257 | SimParams["secure_session_id"] = theUser.CurrentSecureSessionID.ToString(); | ||
258 | SimParams["firstname"] = theUser.firstname; | ||
259 | SimParams["lastname"] = theUser.lastname; | ||
260 | SimParams["agent_id"] = theUser.UUID.ToString(); | ||
261 | SimParams["circuit_code"] = (Int32)circode; | ||
262 | SimParams["startpos_x"] = theUser.homepos.X.ToString(); | ||
263 | SimParams["startpos_y"] = theUser.homepos.Y.ToString(); | ||
264 | SimParams["startpos_z"] = theUser.homepos.Z.ToString(); | ||
265 | ArrayList SendParams = new ArrayList(); | ||
266 | SendParams.Add(SimParams); | ||
267 | |||
268 | XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams); | ||
269 | XmlRpcResponse GridResp = GridReq.Send(SimInfo.caps_url, 3000); | ||
270 | } | ||
271 | } | ||
272 | } | ||