diff options
author | Diva Canto | 2009-12-31 11:42:33 -0800 |
---|---|---|
committer | Diva Canto | 2009-12-31 11:42:33 -0800 |
commit | f4efa325bb8a1e4ae876ec5f080cf87c1f8c1de9 (patch) | |
tree | e6874f6f3d74249308a058375481f6516d877086 /OpenSim/Services | |
parent | Simulation handlers (agents & objects) completed. (diff) | |
download | opensim-SC_OLD-f4efa325bb8a1e4ae876ec5f080cf87c1f8c1de9.zip opensim-SC_OLD-f4efa325bb8a1e4ae876ec5f080cf87c1f8c1de9.tar.gz opensim-SC_OLD-f4efa325bb8a1e4ae876ec5f080cf87c1f8c1de9.tar.bz2 opensim-SC_OLD-f4efa325bb8a1e4ae876ec5f080cf87c1f8c1de9.tar.xz |
More progress on both the Simulation service and the Login service. Both still unfinished.
Diffstat (limited to 'OpenSim/Services')
-rw-r--r-- | OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs | 242 | ||||
-rw-r--r-- | OpenSim/Services/LLLoginService/LLLoginService.cs | 162 |
2 files changed, 402 insertions, 2 deletions
diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs new file mode 100644 index 0000000..6f71197 --- /dev/null +++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs | |||
@@ -0,0 +1,242 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Text; | ||
34 | |||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
38 | |||
39 | using OpenMetaverse; | ||
40 | using OpenMetaverse.StructuredData; | ||
41 | using log4net; | ||
42 | |||
43 | namespace OpenSim.Services.Connectors.Simulation | ||
44 | { | ||
45 | public class SimulationServiceConnector : ISimulationService | ||
46 | { | ||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private GridRegion m_Region; | ||
50 | |||
51 | public SimulationServiceConnector() | ||
52 | { | ||
53 | } | ||
54 | |||
55 | public SimulationServiceConnector(GridRegion region) | ||
56 | { | ||
57 | m_Region = region; | ||
58 | } | ||
59 | |||
60 | public IScene GetScene(ulong regionHandle) | ||
61 | { | ||
62 | return null; | ||
63 | } | ||
64 | |||
65 | #region Agents | ||
66 | |||
67 | public bool CreateAgent(ulong regionHandle, AgentCircuitData aCircuit, uint flags, out string reason) | ||
68 | { | ||
69 | reason = String.Empty; | ||
70 | |||
71 | // Eventually, we want to use a caps url instead of the agentID | ||
72 | string uri = string.Empty; | ||
73 | try | ||
74 | { | ||
75 | uri = "http://" + m_Region.ExternalEndPoint.Address + ":" + m_Region.HttpPort + "/agent/" + aCircuit.AgentID + "/"; | ||
76 | } | ||
77 | catch (Exception e) | ||
78 | { | ||
79 | m_log.Debug("[REST COMMS]: Unable to resolve external endpoint on agent create. Reason: " + e.Message); | ||
80 | reason = e.Message; | ||
81 | return false; | ||
82 | } | ||
83 | |||
84 | //Console.WriteLine(" >>> DoCreateChildAgentCall <<< " + uri); | ||
85 | |||
86 | HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri); | ||
87 | AgentCreateRequest.Method = "POST"; | ||
88 | AgentCreateRequest.ContentType = "application/json"; | ||
89 | AgentCreateRequest.Timeout = 10000; | ||
90 | //AgentCreateRequest.KeepAlive = false; | ||
91 | //AgentCreateRequest.Headers.Add("Authorization", authKey); | ||
92 | |||
93 | // Fill it in | ||
94 | OSDMap args = null; | ||
95 | try | ||
96 | { | ||
97 | args = aCircuit.PackAgentCircuitData(); | ||
98 | } | ||
99 | catch (Exception e) | ||
100 | { | ||
101 | m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message); | ||
102 | } | ||
103 | // Add the regionhandle and the name of the destination region | ||
104 | args["destination_handle"] = OSD.FromString(m_Region.RegionHandle.ToString()); | ||
105 | args["destination_name"] = OSD.FromString(m_Region.RegionName); | ||
106 | args["teleport_flags"] = OSD.FromString(flags.ToString()); | ||
107 | |||
108 | string strBuffer = ""; | ||
109 | byte[] buffer = new byte[1]; | ||
110 | try | ||
111 | { | ||
112 | strBuffer = OSDParser.SerializeJsonString(args); | ||
113 | Encoding str = Util.UTF8; | ||
114 | buffer = str.GetBytes(strBuffer); | ||
115 | |||
116 | } | ||
117 | catch (Exception e) | ||
118 | { | ||
119 | m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildCreate: {0}", e.Message); | ||
120 | // ignore. buffer will be empty, caller should check. | ||
121 | } | ||
122 | |||
123 | Stream os = null; | ||
124 | try | ||
125 | { // send the Post | ||
126 | AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
127 | os = AgentCreateRequest.GetRequestStream(); | ||
128 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
129 | //m_log.InfoFormat("[REST COMMS]: Posted CreateChildAgent request to remote sim {0}", uri); | ||
130 | } | ||
131 | //catch (WebException ex) | ||
132 | catch | ||
133 | { | ||
134 | //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message); | ||
135 | reason = "cannot contact remote region"; | ||
136 | return false; | ||
137 | } | ||
138 | finally | ||
139 | { | ||
140 | if (os != null) | ||
141 | os.Close(); | ||
142 | } | ||
143 | |||
144 | // Let's wait for the response | ||
145 | //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall"); | ||
146 | |||
147 | WebResponse webResponse = null; | ||
148 | StreamReader sr = null; | ||
149 | try | ||
150 | { | ||
151 | webResponse = AgentCreateRequest.GetResponse(); | ||
152 | if (webResponse == null) | ||
153 | { | ||
154 | m_log.Info("[REST COMMS]: Null reply on DoCreateChildAgentCall post"); | ||
155 | } | ||
156 | else | ||
157 | { | ||
158 | |||
159 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
160 | string response = sr.ReadToEnd().Trim(); | ||
161 | m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", response); | ||
162 | |||
163 | if (!String.IsNullOrEmpty(response)) | ||
164 | { | ||
165 | try | ||
166 | { | ||
167 | // we assume we got an OSDMap back | ||
168 | OSDMap r = Util.GetOSDMap(response); | ||
169 | bool success = r["success"].AsBoolean(); | ||
170 | reason = r["reason"].AsString(); | ||
171 | return success; | ||
172 | } | ||
173 | catch (NullReferenceException e) | ||
174 | { | ||
175 | m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", e.Message); | ||
176 | |||
177 | // check for old style response | ||
178 | if (response.ToLower().StartsWith("true")) | ||
179 | return true; | ||
180 | |||
181 | return false; | ||
182 | } | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | catch (WebException ex) | ||
187 | { | ||
188 | m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex.Message); | ||
189 | // ignore, really | ||
190 | } | ||
191 | finally | ||
192 | { | ||
193 | if (sr != null) | ||
194 | sr.Close(); | ||
195 | } | ||
196 | |||
197 | return true; | ||
198 | } | ||
199 | |||
200 | public bool UpdateAgent(ulong regionHandle, AgentData data) | ||
201 | { | ||
202 | return false; | ||
203 | } | ||
204 | |||
205 | public bool UpdateAgent(ulong regionHandle, AgentPosition data) | ||
206 | { | ||
207 | return false; | ||
208 | } | ||
209 | |||
210 | public bool RetrieveAgent(ulong regionHandle, UUID id, out IAgentData agent) | ||
211 | { | ||
212 | agent = null; | ||
213 | return false; | ||
214 | } | ||
215 | |||
216 | public bool ReleaseAgent(ulong regionHandle, UUID id, string uri) | ||
217 | { | ||
218 | return false; | ||
219 | } | ||
220 | |||
221 | public bool CloseAgent(ulong regionHandle, UUID id) | ||
222 | { | ||
223 | return false; | ||
224 | } | ||
225 | |||
226 | #endregion Agents | ||
227 | |||
228 | #region Objects | ||
229 | |||
230 | public bool CreateObject(ulong regionHandle, ISceneObject sog, bool isLocalCall) | ||
231 | { | ||
232 | return false; | ||
233 | } | ||
234 | |||
235 | public bool CreateObject(ulong regionHandle, UUID userID, UUID itemID) | ||
236 | { | ||
237 | return false; | ||
238 | } | ||
239 | |||
240 | #endregion Objects | ||
241 | } | ||
242 | } | ||
diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs index 2c31ed5..4501da2 100644 --- a/OpenSim/Services/LLLoginService/LLLoginService.cs +++ b/OpenSim/Services/LLLoginService/LLLoginService.cs | |||
@@ -1,6 +1,7 @@ | |||
1 | using System; | 1 | using System; |
2 | using System.Collections.Generic; | 2 | using System.Collections.Generic; |
3 | using System.Reflection; | 3 | using System.Reflection; |
4 | using System.Text.RegularExpressions; | ||
4 | 5 | ||
5 | using log4net; | 6 | using log4net; |
6 | using Nini.Config; | 7 | using Nini.Config; |
@@ -9,17 +10,24 @@ using OpenMetaverse; | |||
9 | using OpenSim.Framework; | 10 | using OpenSim.Framework; |
10 | using OpenSim.Server.Base; | 11 | using OpenSim.Server.Base; |
11 | using OpenSim.Services.Interfaces; | 12 | using OpenSim.Services.Interfaces; |
13 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
12 | 14 | ||
13 | namespace OpenSim.Services.LLLoginService | 15 | namespace OpenSim.Services.LLLoginService |
14 | { | 16 | { |
15 | public class LLLoginService : ILoginService | 17 | public class LLLoginService : ILoginService |
16 | { | 18 | { |
19 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
20 | |||
17 | private IUserAccountService m_UserAccountService; | 21 | private IUserAccountService m_UserAccountService; |
18 | private IAuthenticationService m_AuthenticationService; | 22 | private IAuthenticationService m_AuthenticationService; |
19 | private IInventoryService m_InventoryService; | 23 | private IInventoryService m_InventoryService; |
20 | private IGridService m_GridService; | 24 | private IGridService m_GridService; |
21 | private IPresenceService m_PresenceService; | 25 | private IPresenceService m_PresenceService; |
22 | 26 | ||
27 | private string m_DefaultRegionName; | ||
28 | private string m_LocalSimulationDll; | ||
29 | private string m_RemoteSimulationDll; | ||
30 | |||
23 | public LLLoginService(IConfigSource config) | 31 | public LLLoginService(IConfigSource config) |
24 | { | 32 | { |
25 | IConfig serverConfig = config.Configs["LoginService"]; | 33 | IConfig serverConfig = config.Configs["LoginService"]; |
@@ -32,6 +40,10 @@ namespace OpenSim.Services.LLLoginService | |||
32 | string gridService = serverConfig.GetString("GridService", String.Empty); | 40 | string gridService = serverConfig.GetString("GridService", String.Empty); |
33 | string presenceService = serverConfig.GetString("PresenceService", String.Empty); | 41 | string presenceService = serverConfig.GetString("PresenceService", String.Empty); |
34 | 42 | ||
43 | m_DefaultRegionName = serverConfig.GetString("DefaultRegion", String.Empty); | ||
44 | m_LocalSimulationDll = serverConfig.GetString("LocalSimulationService", String.Empty); | ||
45 | m_RemoteSimulationDll = serverConfig.GetString("RemoteSimulationService", String.Empty); | ||
46 | |||
35 | // These 3 are required; the other 2 aren't | 47 | // These 3 are required; the other 2 aren't |
36 | if (accountService == string.Empty || authService == string.Empty || | 48 | if (accountService == string.Empty || authService == string.Empty || |
37 | invService == string.Empty) | 49 | invService == string.Empty) |
@@ -57,8 +69,8 @@ namespace OpenSim.Services.LLLoginService | |||
57 | 69 | ||
58 | // Authenticate this user | 70 | // Authenticate this user |
59 | string token = m_AuthenticationService.Authenticate(account.PrincipalID, passwd, 30); | 71 | string token = m_AuthenticationService.Authenticate(account.PrincipalID, passwd, 30); |
60 | UUID session = UUID.Zero; | 72 | UUID secureSession = UUID.Zero; |
61 | if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out session))) | 73 | if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out secureSession))) |
62 | return LLFailedLoginResponse.UserProblem; | 74 | return LLFailedLoginResponse.UserProblem; |
63 | 75 | ||
64 | // Get the user's inventory | 76 | // Get the user's inventory |
@@ -66,9 +78,155 @@ namespace OpenSim.Services.LLLoginService | |||
66 | if ((inventorySkel == null) || (inventorySkel != null && inventorySkel.Count == 0)) | 78 | if ((inventorySkel == null) || (inventorySkel != null && inventorySkel.Count == 0)) |
67 | return LLFailedLoginResponse.InventoryProblem; | 79 | return LLFailedLoginResponse.InventoryProblem; |
68 | 80 | ||
81 | // Login the presence | ||
82 | UUID session = UUID.Random(); | ||
83 | if (m_PresenceService != null) | ||
84 | { | ||
85 | bool success = m_PresenceService.LoginAgent(account.PrincipalID.ToString(), session, secureSession); | ||
86 | if (!success) | ||
87 | return LLFailedLoginResponse.GridProblem; | ||
88 | } | ||
89 | |||
69 | // lots of things missing... need to do the simulation service | 90 | // lots of things missing... need to do the simulation service |
91 | string where = string.Empty; | ||
92 | Vector3 position = Vector3.Zero; | ||
93 | Vector3 lookAt = Vector3.Zero; | ||
94 | GridRegion destination = FindDestination(account, session, startLocation, out where, out position, out lookAt); | ||
95 | if (destination == null) | ||
96 | return LLFailedLoginResponse.GridProblem; | ||
97 | |||
98 | ISimulationService sim = null; | ||
99 | Object[] args = new Object[] { destination }; | ||
100 | // HG standalones have both a localSimulatonDll and a remoteSimulationDll | ||
101 | // non-HG standalones have just a localSimulationDll | ||
102 | // independent login servers have just a remoteSimulationDll | ||
103 | if (!startLocation.Contains("@") && (m_LocalSimulationDll != string.Empty)) | ||
104 | sim = ServerUtils.LoadPlugin<ISimulationService>(m_LocalSimulationDll, args); | ||
105 | else | ||
106 | sim = ServerUtils.LoadPlugin<ISimulationService>(m_RemoteSimulationDll, args); | ||
107 | |||
70 | 108 | ||
71 | return null; | 109 | return null; |
72 | } | 110 | } |
111 | |||
112 | private GridRegion FindDestination(UserAccount account, UUID sessionID, string startLocation, out string where, out Vector3 position, out Vector3 lookAt) | ||
113 | { | ||
114 | where = "home"; | ||
115 | position = new Vector3(128, 128, 0); | ||
116 | lookAt = new Vector3(0, 1, 0); | ||
117 | if (startLocation.Equals("home")) | ||
118 | { | ||
119 | // logging into home region | ||
120 | if (m_PresenceService == null || m_GridService == null) | ||
121 | return null; | ||
122 | |||
123 | GridRegion region = null; | ||
124 | PresenceInfo pinfo = m_PresenceService.GetAgent(sessionID); | ||
125 | // this should succeed; if it doesn't there's something wrong with this grid | ||
126 | if (pinfo == null) | ||
127 | return null; | ||
128 | |||
129 | if (pinfo.HomeRegionID.Equals(UUID.Zero)) | ||
130 | region = m_GridService.GetRegionByName(account.ScopeID, m_DefaultRegionName); | ||
131 | else | ||
132 | region = m_GridService.GetRegionByUUID(account.ScopeID, pinfo.HomeRegionID); | ||
133 | |||
134 | return region; | ||
135 | } | ||
136 | else if (startLocation.Equals("last")) | ||
137 | { | ||
138 | // logging into last visited region | ||
139 | where = "last"; | ||
140 | if (m_PresenceService == null || m_GridService == null) | ||
141 | return null; | ||
142 | |||
143 | GridRegion region = null; | ||
144 | PresenceInfo pinfo = m_PresenceService.GetAgent(sessionID); | ||
145 | // this should succeed; if it doesn't there's something wrong with this grid | ||
146 | if (pinfo == null) | ||
147 | return null; | ||
148 | |||
149 | if (pinfo.RegionID.Equals(UUID.Zero)) | ||
150 | region = m_GridService.GetRegionByName(account.ScopeID, m_DefaultRegionName); | ||
151 | else | ||
152 | { | ||
153 | region = m_GridService.GetRegionByUUID(account.ScopeID, pinfo.RegionID); | ||
154 | position = pinfo.Position; | ||
155 | lookAt = pinfo.LookAt; | ||
156 | } | ||
157 | return region; | ||
158 | |||
159 | } | ||
160 | else | ||
161 | { | ||
162 | // free uri form | ||
163 | // e.g. New Moon&135&46 New Moon@osgrid.org:8002&153&34 | ||
164 | where = "url"; | ||
165 | Regex reURI = new Regex(@"^uri:(?<region>[^&]+)&(?<x>\d+)&(?<y>\d+)&(?<z>\d+)$"); | ||
166 | Match uriMatch = reURI.Match(startLocation); | ||
167 | if (uriMatch == null) | ||
168 | { | ||
169 | m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, but can't process it", startLocation); | ||
170 | return null; | ||
171 | } | ||
172 | else | ||
173 | { | ||
174 | position = new Vector3(float.Parse(uriMatch.Groups["x"].Value), | ||
175 | float.Parse(uriMatch.Groups["y"].Value), | ||
176 | float.Parse(uriMatch.Groups["z"].Value)); | ||
177 | |||
178 | string regionName = uriMatch.Groups["region"].ToString(); | ||
179 | if (regionName != null) | ||
180 | { | ||
181 | if (!regionName.Contains("@")) | ||
182 | { | ||
183 | List<GridRegion> regions = m_GridService.GetRegionsByName(account.ScopeID, regionName, 1); | ||
184 | if ((regions == null) || (regions != null && regions.Count == 0)) | ||
185 | { | ||
186 | m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, can't locate region {1}", startLocation, regionName); | ||
187 | return null; | ||
188 | } | ||
189 | return regions[0]; | ||
190 | } | ||
191 | else | ||
192 | { | ||
193 | string[] parts = regionName.Split(new char[] { '@' }); | ||
194 | if (parts.Length < 2) | ||
195 | { | ||
196 | m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, can't locate region {1}", startLocation, regionName); | ||
197 | return null; | ||
198 | } | ||
199 | // Valid specification of a remote grid | ||
200 | regionName = parts[0]; | ||
201 | string domainLocator = parts[1]; | ||
202 | parts = domainLocator.Split(new char[] {':'}); | ||
203 | string domainName = parts[0]; | ||
204 | uint port = 0; | ||
205 | if (parts.Length > 1) | ||
206 | UInt32.TryParse(parts[1], out port); | ||
207 | GridRegion region = new GridRegion(); | ||
208 | region.ExternalHostName = domainName; | ||
209 | region.HttpPort = port; | ||
210 | region.RegionName = regionName; | ||
211 | return region; | ||
212 | } | ||
213 | |||
214 | } | ||
215 | else | ||
216 | { | ||
217 | if (m_PresenceService == null || m_GridService == null) | ||
218 | return null; | ||
219 | |||
220 | return m_GridService.GetRegionByName(account.ScopeID, m_DefaultRegionName); | ||
221 | |||
222 | } | ||
223 | } | ||
224 | //response.LookAt = "[r0,r1,r0]"; | ||
225 | //// can be: last, home, safe, url | ||
226 | //response.StartLocation = "url"; | ||
227 | |||
228 | } | ||
229 | |||
230 | } | ||
73 | } | 231 | } |
74 | } | 232 | } |