diff options
author | gareth | 2007-03-14 03:32:02 +0000 |
---|---|---|
committer | gareth | 2007-03-14 03:32:02 +0000 |
commit | 5d2cadf6de749dab1430c016a29e09461d288693 (patch) | |
tree | 4f5698b45404b0898070419438719ff71ec3877c /ogs/userserver/src | |
parent | added movement etc from r191 (diff) | |
download | opensim-SC_OLD-5d2cadf6de749dab1430c016a29e09461d288693.zip opensim-SC_OLD-5d2cadf6de749dab1430c016a29e09461d288693.tar.gz opensim-SC_OLD-5d2cadf6de749dab1430c016a29e09461d288693.tar.bz2 opensim-SC_OLD-5d2cadf6de749dab1430c016a29e09461d288693.tar.xz |
Merged ogs-cs into trunk
Diffstat (limited to 'ogs/userserver/src')
-rw-r--r-- | ogs/userserver/src/ConsoleCmds.cs | 57 | ||||
-rw-r--r-- | ogs/userserver/src/Main.cs | 114 | ||||
-rw-r--r-- | ogs/userserver/src/UserHttp.cs | 287 | ||||
-rw-r--r-- | ogs/userserver/src/UserProfiles.cs | 223 | ||||
-rw-r--r-- | ogs/userserver/src/Util.cs | 87 |
5 files changed, 768 insertions, 0 deletions
diff --git a/ogs/userserver/src/ConsoleCmds.cs b/ogs/userserver/src/ConsoleCmds.cs new file mode 100644 index 0000000..f2568fc --- /dev/null +++ b/ogs/userserver/src/ConsoleCmds.cs | |||
@@ -0,0 +1,57 @@ | |||
1 | /* | ||
2 | Copyright (c) OpenSim project, http://osgrid.org/ | ||
3 | |||
4 | |||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions are met: | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the <organization> nor the | ||
15 | * names of its contributors may be used to endorse or promote products | ||
16 | * derived from this software without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY | ||
19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
21 | * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY | ||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | using System; | ||
31 | using System.Text; | ||
32 | using ServerConsole; | ||
33 | |||
34 | namespace OpenGridServices | ||
35 | { | ||
36 | |||
37 | public class UserConsole : conscmd_callback { | ||
38 | public UserConsole() { } | ||
39 | |||
40 | public override void RunCmd(string cmd, string[] cmdparams) { | ||
41 | switch(cmd) { | ||
42 | case "help": | ||
43 | ServerConsole.MainConsole.Instance.WriteLine("shutdown - shutdown the user server (USE CAUTION!)" | ||
44 | ); | ||
45 | break; | ||
46 | |||
47 | case "shutdown": | ||
48 | ServerConsole.MainConsole.Instance.Close(); | ||
49 | Environment.Exit(0); | ||
50 | break; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | public override void Show(string ShowWhat) { | ||
55 | } | ||
56 | } | ||
57 | } | ||
diff --git a/ogs/userserver/src/Main.cs b/ogs/userserver/src/Main.cs new file mode 100644 index 0000000..40ef916 --- /dev/null +++ b/ogs/userserver/src/Main.cs | |||
@@ -0,0 +1,114 @@ | |||
1 | /* | ||
2 | Copyright (c) OpenSim project, http://osgrid.org/ | ||
3 | |||
4 | |||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions are met: | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the <organization> nor the | ||
15 | * names of its contributors may be used to endorse or promote products | ||
16 | * derived from this software without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY | ||
19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
21 | * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY | ||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | using System; | ||
31 | using System.Collections; | ||
32 | using System.Collections.Generic; | ||
33 | using System.Text; | ||
34 | using libsecondlife; | ||
35 | using ServerConsole; | ||
36 | |||
37 | namespace OpenGridServices | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// </summary> | ||
41 | public class OpenUser_Main | ||
42 | { | ||
43 | |||
44 | public static OpenUser_Main userserver; | ||
45 | |||
46 | public UserHTTPServer _httpd; | ||
47 | public UserProfileManager _profilemanager; | ||
48 | public UserProfile GridGod; | ||
49 | public string DefaultStartupMsg; | ||
50 | public string GridURL; | ||
51 | public string GridSendKey; | ||
52 | public string GridRecvKey; | ||
53 | |||
54 | public Dictionary<LLUUID, UserProfile> UserSessions = new Dictionary<LLUUID, UserProfile>(); | ||
55 | |||
56 | [STAThread] | ||
57 | public static void Main( string[] args ) | ||
58 | { | ||
59 | Console.WriteLine("OpenUser " + VersionInfo.Version + "\n"); | ||
60 | Console.WriteLine("Starting...\n"); | ||
61 | ServerConsole.MainConsole.Instance = new MServerConsole(ServerConsole.ConsoleBase.ConsoleType.Local, "", 0, "opengrid-console.log", "OpenUser", new UserConsole()); | ||
62 | |||
63 | userserver = new OpenUser_Main(); | ||
64 | userserver.Startup(); | ||
65 | |||
66 | ServerConsole.MainConsole.Instance.WriteLine("\nEnter help for a list of commands\n"); | ||
67 | |||
68 | while(true) { | ||
69 | ServerConsole.MainConsole.Instance.MainConsolePrompt(); | ||
70 | } | ||
71 | } | ||
72 | |||
73 | public void Startup() { | ||
74 | ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please press enter to retain default settings"); | ||
75 | |||
76 | this.GridURL=ServerConsole.MainConsole.Instance.CmdPrompt("Grid URL: "); | ||
77 | this.GridSendKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to send to grid: "); | ||
78 | this.GridRecvKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to expect from grid: "); | ||
79 | |||
80 | this.DefaultStartupMsg=ServerConsole.MainConsole.Instance.CmdPrompt("Default startup message for clients [Welcome to OGS!] :","Welcome to OGS!"); | ||
81 | |||
82 | ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Creating user profile manager"); | ||
83 | _profilemanager = new UserProfileManager(); | ||
84 | _profilemanager.InitUserProfiles(); | ||
85 | |||
86 | |||
87 | string tempfirstname; | ||
88 | string templastname; | ||
89 | string tempMD5Passwd; | ||
90 | ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please configure the grid god user:"); | ||
91 | tempfirstname=ServerConsole.MainConsole.Instance.CmdPrompt("First name: "); | ||
92 | templastname=ServerConsole.MainConsole.Instance.CmdPrompt("Last name: "); | ||
93 | tempMD5Passwd=ServerConsole.MainConsole.Instance.PasswdPrompt("Password: "); | ||
94 | |||
95 | System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider(); | ||
96 | byte[] bs = System.Text.Encoding.UTF8.GetBytes(tempMD5Passwd); | ||
97 | bs = x.ComputeHash(bs); | ||
98 | System.Text.StringBuilder s = new System.Text.StringBuilder(); | ||
99 | foreach (byte b in bs) | ||
100 | { | ||
101 | s.Append(b.ToString("x2").ToLower()); | ||
102 | } | ||
103 | tempMD5Passwd = "$1$" + s.ToString(); | ||
104 | |||
105 | GridGod=_profilemanager.CreateNewProfile(tempfirstname,templastname,tempMD5Passwd); | ||
106 | _profilemanager.SetGod(GridGod.UUID); | ||
107 | GridGod.homelookat = new LLVector3(-0.57343f, -0.819255f, 0f); | ||
108 | GridGod.homepos = new LLVector3(128f,128f,23f); | ||
109 | |||
110 | ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process"); | ||
111 | _httpd = new UserHTTPServer(); | ||
112 | } | ||
113 | } | ||
114 | } | ||
diff --git a/ogs/userserver/src/UserHttp.cs b/ogs/userserver/src/UserHttp.cs new file mode 100644 index 0000000..bc232fb --- /dev/null +++ b/ogs/userserver/src/UserHttp.cs | |||
@@ -0,0 +1,287 @@ | |||
1 | /* | ||
2 | Copyright (c) OpenGrid project, http://osgrid.org/ | ||
3 | |||
4 | |||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions are met: | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the <organization> nor the | ||
15 | * names of its contributors may be used to endorse or promote products | ||
16 | * derived from this software without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY | ||
19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
21 | * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY | ||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | using System; | ||
31 | using System.Text; | ||
32 | using Nwc.XmlRpc; | ||
33 | using System.Threading; | ||
34 | using System.Text.RegularExpressions; | ||
35 | using System.Net; | ||
36 | using System.IO; | ||
37 | using System.Collections; | ||
38 | using System.Collections.Generic; | ||
39 | using libsecondlife; | ||
40 | using ServerConsole; | ||
41 | |||
42 | namespace OpenGridServices | ||
43 | { | ||
44 | public class UserHTTPServer { | ||
45 | public Thread HTTPD; | ||
46 | public HttpListener Listener; | ||
47 | |||
48 | public UserHTTPServer() { | ||
49 | ServerConsole.MainConsole.Instance.WriteLine("Starting up HTTP Server"); | ||
50 | HTTPD = new Thread(new ThreadStart(StartHTTP)); | ||
51 | HTTPD.Start(); | ||
52 | } | ||
53 | |||
54 | public void StartHTTP() { | ||
55 | ServerConsole.MainConsole.Instance.WriteLine("UserHttp.cs:StartHTTP() - Spawned main thread OK"); | ||
56 | Listener = new HttpListener(); | ||
57 | |||
58 | Listener.Prefixes.Add("http://+:8002/userserver/"); | ||
59 | Listener.Prefixes.Add("http://+:8002/usersessions/"); | ||
60 | Listener.Start(); | ||
61 | |||
62 | HttpListenerContext context; | ||
63 | while(true) { | ||
64 | context = Listener.GetContext(); | ||
65 | ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | static string ParseXMLRPC(string requestBody) { | ||
70 | XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); | ||
71 | |||
72 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
73 | switch(request.MethodName) { | ||
74 | case "login_to_simulator": | ||
75 | bool GoodXML= (requestData.Contains("first") && requestData.Contains("last") && requestData.Contains("passwd")); | ||
76 | bool GoodLogin=false; | ||
77 | string firstname=""; | ||
78 | string lastname=""; | ||
79 | string passwd=""; | ||
80 | |||
81 | if(GoodXML) { | ||
82 | firstname=(string)requestData["first"]; | ||
83 | lastname=(string)requestData["last"]; | ||
84 | passwd=(string)requestData["passwd"]; | ||
85 | GoodLogin=OpenUser_Main.userserver._profilemanager.AuthenticateUser(firstname,lastname,passwd); | ||
86 | } | ||
87 | |||
88 | |||
89 | if(!(GoodXML && GoodLogin)) { | ||
90 | XmlRpcResponse LoginErrorResp = new XmlRpcResponse(); | ||
91 | Hashtable ErrorRespData = new Hashtable(); | ||
92 | ErrorRespData["reason"]="key"; | ||
93 | 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"; | ||
94 | ErrorRespData["login"]="false"; | ||
95 | LoginErrorResp.Value=ErrorRespData; | ||
96 | return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(LoginErrorResp)," encoding=\"utf-16\"","" )); | ||
97 | } | ||
98 | |||
99 | UserProfile TheUser=OpenUser_Main.userserver._profilemanager.GetProfileByName(firstname,lastname); | ||
100 | |||
101 | if(!((TheUser.CurrentSessionID==null) && (TheUser.CurrentSecureSessionID==null))) { | ||
102 | XmlRpcResponse PresenceErrorResp = new XmlRpcResponse(); | ||
103 | Hashtable PresenceErrorRespData = new Hashtable(); | ||
104 | PresenceErrorRespData["reason"]="presence"; | ||
105 | 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"; | ||
106 | PresenceErrorRespData["login"]="false"; | ||
107 | PresenceErrorResp.Value=PresenceErrorRespData; | ||
108 | return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(PresenceErrorResp)," encoding=\"utf-16\"","" )); | ||
109 | |||
110 | } | ||
111 | |||
112 | try { | ||
113 | LLUUID AgentID = TheUser.UUID; | ||
114 | TheUser.InitSessionData(); | ||
115 | SimProfile SimInfo = new SimProfile(); | ||
116 | SimInfo = SimInfo.LoadFromGrid(TheUser.homeregionhandle,OpenUser_Main.userserver.GridURL,OpenUser_Main.userserver.GridSendKey,OpenUser_Main.userserver.GridRecvKey); | ||
117 | |||
118 | XmlRpcResponse LoginGoodResp = new XmlRpcResponse(); | ||
119 | Hashtable LoginGoodData = new Hashtable(); | ||
120 | |||
121 | Hashtable GlobalT = new Hashtable(); | ||
122 | GlobalT["sun_texture_id"] = "cce0f112-878f-4586-a2e2-a8f104bba271"; | ||
123 | GlobalT["cloud_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621"; | ||
124 | GlobalT["moon_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621"; | ||
125 | ArrayList GlobalTextures = new ArrayList(); | ||
126 | GlobalTextures.Add(GlobalT); | ||
127 | |||
128 | Hashtable LoginFlagsHash = new Hashtable(); | ||
129 | LoginFlagsHash["daylight_savings"]="N"; | ||
130 | LoginFlagsHash["stipend_since_login"]="N"; | ||
131 | LoginFlagsHash["gendered"]="Y"; | ||
132 | LoginFlagsHash["ever_logged_in"]="Y"; | ||
133 | ArrayList LoginFlags=new ArrayList(); | ||
134 | LoginFlags.Add(LoginFlagsHash); | ||
135 | |||
136 | Hashtable uiconfig = new Hashtable(); | ||
137 | uiconfig["allow_first_life"]="Y"; | ||
138 | ArrayList ui_config=new ArrayList(); | ||
139 | ui_config.Add(uiconfig); | ||
140 | |||
141 | Hashtable ClassifiedCategoriesHash = new Hashtable(); | ||
142 | ClassifiedCategoriesHash["category_name"]="bla bla"; | ||
143 | ClassifiedCategoriesHash["category_id"]=(Int32)1; | ||
144 | ArrayList ClassifiedCategories = new ArrayList(); | ||
145 | ClassifiedCategories.Add(ClassifiedCategoriesHash); | ||
146 | |||
147 | ArrayList AgentInventory = new ArrayList(); | ||
148 | foreach(InventoryFolder InvFolder in TheUser.InventoryFolders.Values) { | ||
149 | Hashtable TempHash = new Hashtable(); | ||
150 | TempHash["name"]=InvFolder.FolderName; | ||
151 | TempHash["parent_id"]=InvFolder.ParentID.ToStringHyphenated(); | ||
152 | TempHash["version"]=(Int32)InvFolder.Version; | ||
153 | TempHash["type_default"]=(Int32)InvFolder.DefaultType; | ||
154 | TempHash["folder_id"]=InvFolder.FolderID.ToStringHyphenated(); | ||
155 | AgentInventory.Add(TempHash); | ||
156 | } | ||
157 | |||
158 | Hashtable InventoryRootHash = new Hashtable(); | ||
159 | InventoryRootHash["folder_id"]=TheUser.InventoryRoot.FolderID.ToStringHyphenated(); | ||
160 | ArrayList InventoryRoot = new ArrayList(); | ||
161 | InventoryRoot.Add(InventoryRootHash); | ||
162 | |||
163 | Hashtable InitialOutfitHash = new Hashtable(); | ||
164 | InitialOutfitHash["folder_name"]="Nightclub Female"; | ||
165 | InitialOutfitHash["gender"]="female"; | ||
166 | ArrayList InitialOutfit = new ArrayList(); | ||
167 | InitialOutfit.Add(InitialOutfitHash); | ||
168 | |||
169 | uint circode = (uint)(new Random()).Next(); | ||
170 | TheUser.AddSimCircuit(circode, SimInfo.UUID); | ||
171 | |||
172 | LoginGoodData["last_name"]="\"" + TheUser.firstname + "\""; | ||
173 | LoginGoodData["ui-config"]=ui_config; | ||
174 | LoginGoodData["sim_ip"]=SimInfo.sim_ip.ToString(); | ||
175 | LoginGoodData["login-flags"]=LoginFlags; | ||
176 | LoginGoodData["global-textures"]=GlobalTextures; | ||
177 | LoginGoodData["classified_categories"]=ClassifiedCategories; | ||
178 | LoginGoodData["event_categories"]=new ArrayList(); | ||
179 | LoginGoodData["inventory-skeleton"]=AgentInventory; | ||
180 | LoginGoodData["inventory-skel-lib"]=new ArrayList(); | ||
181 | LoginGoodData["inventory-root"]=InventoryRoot; | ||
182 | LoginGoodData["event_notifications"]=new ArrayList(); | ||
183 | LoginGoodData["gestures"]=new ArrayList(); | ||
184 | LoginGoodData["inventory-lib-owner"]=new ArrayList(); | ||
185 | LoginGoodData["initial-outfit"]=InitialOutfit; | ||
186 | LoginGoodData["seconds_since_epoch"]=(Int32)(DateTime.UtcNow - new DateTime(1970,1,1)).TotalSeconds; | ||
187 | LoginGoodData["start_location"]="last"; | ||
188 | LoginGoodData["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() + "]}"; | ||
189 | LoginGoodData["message"]=OpenUser_Main.userserver.DefaultStartupMsg; | ||
190 | LoginGoodData["first_name"]="\"" + firstname + "\""; | ||
191 | LoginGoodData["circuit_code"]=(Int32)circode; | ||
192 | LoginGoodData["sim_port"]=(Int32)SimInfo.sim_port; | ||
193 | LoginGoodData["secure_session_id"]=TheUser.CurrentSecureSessionID.ToStringHyphenated(); | ||
194 | LoginGoodData["look_at"]="\n[r" + TheUser.homelookat.X.ToString() + ",r" + TheUser.homelookat.Y.ToString() + ",r" + TheUser.homelookat.Z.ToString() + "]\n"; | ||
195 | LoginGoodData["agent_id"]=AgentID.ToStringHyphenated(); | ||
196 | LoginGoodData["region_y"]=(Int32)SimInfo.RegionLocY*256; | ||
197 | LoginGoodData["region_x"]=(Int32)SimInfo.RegionLocX*256; | ||
198 | LoginGoodData["seed_capability"]=null; | ||
199 | LoginGoodData["agent_access"]="M"; | ||
200 | LoginGoodData["session_id"]=TheUser.CurrentSessionID.ToStringHyphenated(); | ||
201 | LoginGoodData["login"]="true"; | ||
202 | |||
203 | LoginGoodResp.Value=LoginGoodData; | ||
204 | TheUser.SendDataToSim(SimInfo); | ||
205 | return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(LoginGoodResp),"utf-16","utf-8" )); | ||
206 | |||
207 | } catch (Exception E) { | ||
208 | Console.WriteLine(E.ToString()); | ||
209 | } | ||
210 | |||
211 | break; | ||
212 | } | ||
213 | |||
214 | return ""; | ||
215 | } | ||
216 | |||
217 | static string ParseREST(HttpListenerRequest www_req) { | ||
218 | Console.WriteLine("INCOMING REST - " + www_req.RawUrl); | ||
219 | |||
220 | char[] splitter = {'/'}; | ||
221 | string[] rest_params = www_req.RawUrl.Split(splitter); | ||
222 | string req_type = rest_params[1]; // First part of the URL is the type of request - usersessions/userprofiles/inventory/blabla | ||
223 | switch(req_type) { | ||
224 | case "usersessions": | ||
225 | LLUUID sessionid = new LLUUID(rest_params[2]); // get usersessions/sessionid | ||
226 | if(www_req.HttpMethod=="DELETE") { | ||
227 | foreach (libsecondlife.LLUUID UUID in OpenUser_Main.userserver._profilemanager.UserProfiles.Keys) { | ||
228 | if(OpenUser_Main.userserver._profilemanager.UserProfiles[UUID].CurrentSessionID==sessionid) { | ||
229 | OpenUser_Main.userserver._profilemanager.UserProfiles[UUID].CurrentSessionID=null; | ||
230 | OpenUser_Main.userserver._profilemanager.UserProfiles[UUID].CurrentSecureSessionID=null; | ||
231 | OpenUser_Main.userserver._profilemanager.UserProfiles[UUID].Circuits.Clear(); | ||
232 | } | ||
233 | } | ||
234 | |||
235 | } | ||
236 | return "OK"; | ||
237 | break; | ||
238 | } | ||
239 | |||
240 | return ""; | ||
241 | } | ||
242 | |||
243 | |||
244 | static void HandleRequest(Object stateinfo) { | ||
245 | HttpListenerContext context=(HttpListenerContext)stateinfo; | ||
246 | |||
247 | HttpListenerRequest request = context.Request; | ||
248 | HttpListenerResponse response = context.Response; | ||
249 | |||
250 | response.KeepAlive=false; | ||
251 | response.SendChunked=false; | ||
252 | |||
253 | System.IO.Stream body = request.InputStream; | ||
254 | System.Text.Encoding encoding = System.Text.Encoding.UTF8; | ||
255 | System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding); | ||
256 | |||
257 | string requestBody = reader.ReadToEnd(); | ||
258 | body.Close(); | ||
259 | reader.Close(); | ||
260 | |||
261 | string responseString=""; | ||
262 | switch(request.ContentType) { | ||
263 | case "text/xml": | ||
264 | // must be XML-RPC, so pass to the XML-RPC parser | ||
265 | |||
266 | responseString=ParseXMLRPC(requestBody); | ||
267 | response.AddHeader("Content-type","text/xml"); | ||
268 | break; | ||
269 | |||
270 | case "text/plaintext": | ||
271 | responseString=ParseREST(request); | ||
272 | response.AddHeader("Content-type","text/plaintext"); | ||
273 | break; | ||
274 | } | ||
275 | |||
276 | |||
277 | byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); | ||
278 | System.IO.Stream output = response.OutputStream; | ||
279 | response.SendChunked=false; | ||
280 | response.ContentLength64=buffer.Length; | ||
281 | output.Write(buffer,0,buffer.Length); | ||
282 | output.Close(); | ||
283 | } | ||
284 | } | ||
285 | |||
286 | |||
287 | } | ||
diff --git a/ogs/userserver/src/UserProfiles.cs b/ogs/userserver/src/UserProfiles.cs new file mode 100644 index 0000000..4586ab3 --- /dev/null +++ b/ogs/userserver/src/UserProfiles.cs | |||
@@ -0,0 +1,223 @@ | |||
1 | /* | ||
2 | Copyright (c) OpenGrid project, http://osgrid.org/ | ||
3 | |||
4 | |||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions are met: | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the <organization> nor the | ||
15 | * names of its contributors may be used to endorse or promote products | ||
16 | * derived from this software without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY | ||
19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
21 | * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY | ||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | using System; | ||
31 | using System.Text; | ||
32 | using System.Collections; | ||
33 | using System.Collections.Generic; | ||
34 | using libsecondlife; | ||
35 | using Nwc.XmlRpc; | ||
36 | using ServerConsole; | ||
37 | |||
38 | namespace OpenGridServices | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// </summary> | ||
42 | public class UserProfileManager { | ||
43 | |||
44 | public Dictionary<LLUUID, UserProfile> UserProfiles = new Dictionary<LLUUID, UserProfile>(); | ||
45 | |||
46 | public UserProfileManager() { | ||
47 | } | ||
48 | |||
49 | public void InitUserProfiles() { | ||
50 | // TODO: need to load from database | ||
51 | } | ||
52 | |||
53 | public UserProfile GetProfileByName(string firstname, string lastname) { | ||
54 | foreach (libsecondlife.LLUUID UUID in UserProfiles.Keys) { | ||
55 | if((UserProfiles[UUID].firstname==firstname) && (UserProfiles[UUID].lastname==lastname)) return UserProfiles[UUID]; | ||
56 | } | ||
57 | return null; | ||
58 | } | ||
59 | |||
60 | public UserProfile GetProfileByLLUUID(LLUUID ProfileLLUUID) { | ||
61 | return UserProfiles[ProfileLLUUID]; | ||
62 | } | ||
63 | |||
64 | public bool AuthenticateUser(string firstname, string lastname, string passwd) { | ||
65 | UserProfile TheUser=GetProfileByName(firstname, lastname); | ||
66 | if(TheUser != null) | ||
67 | if(TheUser.MD5passwd==passwd) { | ||
68 | return true; | ||
69 | } else { | ||
70 | return false; | ||
71 | } else return false; | ||
72 | |||
73 | } | ||
74 | |||
75 | public void SetGod(LLUUID GodID) { | ||
76 | this.UserProfiles[GodID].IsGridGod=true; | ||
77 | } | ||
78 | |||
79 | public UserProfile CreateNewProfile(string firstname, string lastname, string MD5passwd) { | ||
80 | UserProfile newprofile = new UserProfile(); | ||
81 | newprofile.homeregionhandle=Util.UIntsToLong((997*256), (996*256)); | ||
82 | newprofile.firstname=firstname; | ||
83 | newprofile.lastname=lastname; | ||
84 | newprofile.MD5passwd=MD5passwd; | ||
85 | newprofile.UUID=LLUUID.Random(); | ||
86 | this.UserProfiles.Add(newprofile.UUID,newprofile); | ||
87 | return newprofile; | ||
88 | } | ||
89 | |||
90 | } | ||
91 | |||
92 | public class UserProfile { | ||
93 | |||
94 | public string firstname; | ||
95 | public string lastname; | ||
96 | public ulong homeregionhandle; | ||
97 | public LLVector3 homepos; | ||
98 | public LLVector3 homelookat; | ||
99 | |||
100 | public bool IsGridGod=false; | ||
101 | public bool IsLocal=true; // will be used in future for visitors from foreign grids | ||
102 | public string AssetURL; | ||
103 | public string MD5passwd; | ||
104 | |||
105 | public LLUUID CurrentSessionID; | ||
106 | public LLUUID CurrentSecureSessionID; | ||
107 | public LLUUID UUID; | ||
108 | public Dictionary<LLUUID, uint> Circuits = new Dictionary<LLUUID, uint>(); // tracks circuit codes | ||
109 | |||
110 | public InventoryFolder InventoryRoot; | ||
111 | public Dictionary<LLUUID, InventoryFolder> InventoryFolders; | ||
112 | public Dictionary<LLUUID, InventoryItem> InventoryItems; | ||
113 | |||
114 | public UserProfile() { | ||
115 | Circuits = new Dictionary<LLUUID, uint>(); | ||
116 | InventoryFolders = new Dictionary<LLUUID, InventoryFolder>(); | ||
117 | InventoryItems = new Dictionary<LLUUID, InventoryItem>(); | ||
118 | InventoryRoot=new InventoryFolder(); | ||
119 | InventoryRoot.FolderID = LLUUID.Random(); | ||
120 | InventoryRoot.ParentID=new LLUUID(); | ||
121 | InventoryRoot.Version=1; | ||
122 | InventoryRoot.DefaultType=8; | ||
123 | InventoryRoot.FolderName="My Inventory"; | ||
124 | InventoryFolders.Add(InventoryRoot.FolderID, InventoryRoot); | ||
125 | homeregionhandle=Util.UIntsToLong((997*256), (996*256));; | ||
126 | } | ||
127 | |||
128 | public void InitSessionData() { | ||
129 | CurrentSessionID=LLUUID.Random(); | ||
130 | CurrentSecureSessionID=LLUUID.Random(); | ||
131 | } | ||
132 | |||
133 | public void AddSimCircuit(uint circuit_code, LLUUID region_UUID) { | ||
134 | if(this.Circuits.ContainsKey(region_UUID)== false) | ||
135 | this.Circuits.Add(region_UUID, circuit_code); | ||
136 | } | ||
137 | |||
138 | public void SendDataToSim(SimProfile TheSim) { | ||
139 | Console.WriteLine(TheSim.caps_url); | ||
140 | Hashtable SimParams = new Hashtable(); | ||
141 | SimParams["session_id"]=this.CurrentSessionID.ToString(); | ||
142 | SimParams["secure_session_id"]=this.CurrentSecureSessionID.ToString(); | ||
143 | SimParams["firstname"]=this.firstname; | ||
144 | SimParams["lastname"]=this.lastname; | ||
145 | SimParams["agent_id"]=this.UUID.ToString(); | ||
146 | SimParams["circuit_code"]=(Int32)this.Circuits[TheSim.UUID]; | ||
147 | ArrayList SendParams = new ArrayList(); | ||
148 | SendParams.Add(SimParams); | ||
149 | |||
150 | XmlRpcRequest GridReq = new XmlRpcRequest("expect_user",SendParams); | ||
151 | XmlRpcResponse GridResp = GridReq.Send(TheSim.caps_url,3000); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | public class InventoryFolder { | ||
156 | public LLUUID FolderID; | ||
157 | public LLUUID ParentID; | ||
158 | public string FolderName; | ||
159 | public ushort DefaultType; | ||
160 | public ushort Version; | ||
161 | } | ||
162 | |||
163 | public class InventoryItem { //TODO: Fixup this and add full permissions etc | ||
164 | public LLUUID FolderID; | ||
165 | public LLUUID OwnerID; | ||
166 | public LLUUID ItemID; | ||
167 | public LLUUID AssetID; | ||
168 | public LLUUID CreatorID = LLUUID.Zero; | ||
169 | public sbyte InvType; | ||
170 | public sbyte Type; | ||
171 | public string Name; | ||
172 | public string Description; | ||
173 | } | ||
174 | |||
175 | public class SimProfile { | ||
176 | public LLUUID UUID; | ||
177 | public ulong regionhandle; | ||
178 | public string regionname; | ||
179 | public string sim_ip; | ||
180 | public uint sim_port; | ||
181 | public string caps_url; | ||
182 | public uint RegionLocX; | ||
183 | public uint RegionLocY; | ||
184 | public string sendkey; | ||
185 | public string recvkey; | ||
186 | |||
187 | |||
188 | public SimProfile LoadFromGrid(ulong region_handle, string GridURL, string SendKey, string RecvKey) { | ||
189 | try { | ||
190 | Hashtable GridReqParams = new Hashtable(); | ||
191 | GridReqParams["region_handle"]=region_handle.ToString(); | ||
192 | GridReqParams["caller"]="userserver"; | ||
193 | GridReqParams["authkey"]=SendKey; | ||
194 | ArrayList SendParams = new ArrayList(); | ||
195 | SendParams.Add(GridReqParams); | ||
196 | XmlRpcRequest GridReq = new XmlRpcRequest("get_sim_info",SendParams); | ||
197 | |||
198 | XmlRpcResponse GridResp = GridReq.Send(GridURL,3000); | ||
199 | |||
200 | Hashtable RespData=(Hashtable)GridResp.Value; | ||
201 | this.UUID = new LLUUID((string)RespData["UUID"]); | ||
202 | this.regionhandle = (ulong)Convert.ToUInt64(RespData["regionhandle"]); | ||
203 | this.regionname=(string)RespData["regionname"]; | ||
204 | this.sim_ip=(string)RespData["sim_ip"]; | ||
205 | this.sim_port=(uint)Convert.ToUInt16(RespData["sim_port"]); | ||
206 | this.caps_url=(string)RespData["caps_url"]; | ||
207 | this.RegionLocX=(uint)Convert.ToUInt32(RespData["RegionLocX"]); | ||
208 | this.RegionLocY=(uint)Convert.ToUInt32(RespData["RegionLocY"]); | ||
209 | this.sendkey=(string)RespData["sendkey"]; | ||
210 | this.recvkey=(string)RespData["recvkey"]; | ||
211 | } catch(Exception e) { | ||
212 | Console.WriteLine(e.ToString()); | ||
213 | } | ||
214 | return this; | ||
215 | } | ||
216 | |||
217 | public SimProfile() { | ||
218 | } | ||
219 | |||
220 | |||
221 | } | ||
222 | |||
223 | } | ||
diff --git a/ogs/userserver/src/Util.cs b/ogs/userserver/src/Util.cs new file mode 100644 index 0000000..1efa471 --- /dev/null +++ b/ogs/userserver/src/Util.cs | |||
@@ -0,0 +1,87 @@ | |||
1 | /* | ||
2 | Copyright (c) OpenSim project, http://osgrid.org/ | ||
3 | |||
4 | * Copyright (c) <year>, <copyright holder> | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions are met: | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the <organization> nor the | ||
15 | * names of its contributors may be used to endorse or promote products | ||
16 | * derived from this software without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY | ||
19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
21 | * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY | ||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | using System; | ||
31 | using System.Collections.Generic; | ||
32 | using System.Threading; | ||
33 | using libsecondlife; | ||
34 | using libsecondlife.Packets; | ||
35 | |||
36 | namespace OpenGridServices | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// </summary> | ||
40 | /// | ||
41 | public class Util | ||
42 | { | ||
43 | public static ulong UIntsToLong(uint X, uint Y) | ||
44 | { | ||
45 | return Helpers.UIntsToLong(X,Y); | ||
46 | } | ||
47 | public Util() | ||
48 | { | ||
49 | |||
50 | } | ||
51 | } | ||
52 | |||
53 | public class QueItem { | ||
54 | public QueItem() | ||
55 | { | ||
56 | } | ||
57 | |||
58 | public Packet Packet; | ||
59 | public bool Incoming; | ||
60 | } | ||
61 | |||
62 | |||
63 | public class BlockingQueue< T > { | ||
64 | private Queue< T > _queue = new Queue< T >(); | ||
65 | private object _queueSync = new object(); | ||
66 | |||
67 | public void Enqueue(T value) | ||
68 | { | ||
69 | lock(_queueSync) | ||
70 | { | ||
71 | _queue.Enqueue(value); | ||
72 | Monitor.Pulse(_queueSync); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | public T Dequeue() | ||
77 | { | ||
78 | lock(_queueSync) | ||
79 | { | ||
80 | if( _queue.Count < 1) | ||
81 | Monitor.Wait(_queueSync); | ||
82 | |||
83 | return _queue.Dequeue(); | ||
84 | } | ||
85 | } | ||
86 | } | ||
87 | } | ||