aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorlbsa712009-03-12 10:50:59 +0000
committerlbsa712009-03-12 10:50:59 +0000
commit33f511ee4b5b4e1f8fe4fbb47d3b5b51e1d0104a (patch)
treeeb1bb1db8b93b4038d8f12d4d7abee2e5071b9fe /OpenSim
parentMove ArchiveConstants to OpenSim.Framework.Archive (diff)
downloadopensim-SC_OLD-33f511ee4b5b4e1f8fe4fbb47d3b5b51e1d0104a.zip
opensim-SC_OLD-33f511ee4b5b4e1f8fe4fbb47d3b5b51e1d0104a.tar.gz
opensim-SC_OLD-33f511ee4b5b4e1f8fe4fbb47d3b5b51e1d0104a.tar.bz2
opensim-SC_OLD-33f511ee4b5b4e1f8fe4fbb47d3b5b51e1d0104a.tar.xz
* Another stab at refactoring up the CustomiseResponse function. Two fixes:
* Sometimes, null is a valid return value to indicate 'none found'. doh. * Sometimes, the Grid server does not send simURI - this you need to reconstruct yourself. Euw. (I believe) this solves mantis issue #3287
Diffstat (limited to '')
-rw-r--r--OpenSim/Client/Linden/LLStandaloneLoginService.cs143
-rw-r--r--OpenSim/Data/RegionProfileData.cs15
-rw-r--r--OpenSim/Framework/Communications/LoginService.cs156
-rw-r--r--OpenSim/Framework/RegionInfo.cs3
-rw-r--r--OpenSim/Grid/UserServer.Modules/UserLoginService.cs196
-rw-r--r--OpenSim/Region/Communications/OGS1/OGS1GridServices.cs5
6 files changed, 219 insertions, 299 deletions
diff --git a/OpenSim/Client/Linden/LLStandaloneLoginService.cs b/OpenSim/Client/Linden/LLStandaloneLoginService.cs
index 8fe7172..b596e14 100644
--- a/OpenSim/Client/Linden/LLStandaloneLoginService.cs
+++ b/OpenSim/Client/Linden/LLStandaloneLoginService.cs
@@ -126,150 +126,17 @@ namespace OpenSim.Client.Linden
126 } 126 }
127 } 127 }
128 128
129 /// <summary> 129 protected override RegionInfo RequestClosestRegion(string region)
130 /// Customises the login response and fills in missing values.
131 /// </summary>
132 /// <param name="response">The existing response</param>
133 /// <param name="theUser">The user profile</param>
134 /// <param name="startLocationRequest">The requested start location</param>
135 public override bool CustomiseResponse(LoginResponse response, UserProfileData theUser, string startLocationRequest)
136 {
137 // add active gestures to login-response
138 AddActiveGestures(response, theUser);
139
140 // HomeLocation
141 RegionInfo homeInfo = null;
142
143 // use the homeRegionID if it is stored already. If not, use the regionHandle as before
144 UUID homeRegionId = theUser.HomeRegionID;
145 ulong homeRegionHandle = theUser.HomeRegion;
146 if (homeRegionId != UUID.Zero)
147 {
148 homeInfo = GetRegionInfo(homeRegionId);
149 }
150 else
151 {
152 homeInfo = GetRegionInfo(homeRegionHandle);
153 }
154
155 if (homeInfo != null)
156 {
157 response.Home =
158 string.Format(
159 "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
160 (homeInfo.RegionLocX * Constants.RegionSize),
161 (homeInfo.RegionLocY * Constants.RegionSize),
162 theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z,
163 theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z);
164 }
165 else
166 {
167 m_log.InfoFormat("not found the region at {0} {1}", theUser.HomeRegionX, theUser.HomeRegionY);
168 // Emergency mode: Home-region isn't available, so we can't request the region info.
169 // Use the stored home regionHandle instead.
170 // NOTE: If the home-region moves, this will be wrong until the users update their user-profile again
171 ulong regionX = homeRegionHandle >> 32;
172 ulong regionY = homeRegionHandle & 0xffffffff;
173 response.Home =
174 string.Format(
175 "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
176 regionX, regionY,
177 theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z,
178 theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z);
179
180 m_log.InfoFormat("[LOGIN] Home region of user {0} {1} is not available; using computed region position {2} {3}",
181 theUser.FirstName, theUser.SurName,
182 regionX, regionY);
183 }
184
185 // StartLocation
186 RegionInfo regionInfo = null;
187 if (startLocationRequest == "home")
188 {
189 regionInfo = homeInfo;
190 theUser.CurrentAgent.Position = theUser.HomeLocation;
191 response.LookAt = "[r" + theUser.HomeLookAt.X.ToString() + ",r" + theUser.HomeLookAt.Y.ToString() + ",r" + theUser.HomeLookAt.Z.ToString() + "]";
192 }
193 else if (startLocationRequest == "last")
194 {
195 UUID lastRegion = theUser.CurrentAgent.Region;
196 regionInfo = GetRegionInfo(lastRegion);
197 response.LookAt = "[r" + theUser.CurrentAgent.LookAt.X.ToString() + ",r" + theUser.CurrentAgent.LookAt.Y.ToString() + ",r" + theUser.CurrentAgent.LookAt.Z.ToString() + "]";
198 }
199 else
200 {
201 Regex reURI = new Regex(@"^uri:(?<region>[^&]+)&(?<x>\d+)&(?<y>\d+)&(?<z>\d+)$");
202 Match uriMatch = reURI.Match(startLocationRequest);
203 if (uriMatch == null)
204 {
205 m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, but can't process it", startLocationRequest);
206 }
207 else
208 {
209 string region = uriMatch.Groups["region"].ToString();
210 regionInfo = RequestClosestRegion(region);
211 if (regionInfo == null)
212 {
213 m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, can't locate region {1}", startLocationRequest, region);
214 }
215 else
216 {
217 theUser.CurrentAgent.Position = new Vector3(float.Parse(uriMatch.Groups["x"].Value),
218 float.Parse(uriMatch.Groups["y"].Value), float.Parse(uriMatch.Groups["z"].Value));
219 }
220 }
221 response.LookAt = "[r0,r1,r0]";
222 // can be: last, home, safe, url
223 response.StartLocation = "url";
224 }
225
226 if ((regionInfo != null) && (PrepareLoginToRegion(regionInfo, theUser, response)))
227 {
228 return true;
229 }
230
231 // StartLocation not available, send him to a nearby region instead
232 // regionInfo = m_gridService.RequestClosestRegion("");
233 //m_log.InfoFormat("[LOGIN]: StartLocation not available sending to region {0}", regionInfo.regionName);
234
235 // Send him to default region instead
236 ulong defaultHandle = (((ulong)m_defaultHomeX * Constants.RegionSize) << 32) |
237 ((ulong)m_defaultHomeY * Constants.RegionSize);
238
239 if ((regionInfo != null) && (defaultHandle == regionInfo.RegionHandle))
240 {
241 m_log.ErrorFormat("[LOGIN]: Not trying the default region since this is the same as the selected region");
242 return false;
243 }
244
245 m_log.Error("[LOGIN]: Sending user to default region " + defaultHandle + " instead");
246 regionInfo = GetRegionInfo(defaultHandle);
247
248 // Customise the response
249 //response.Home =
250 // string.Format(
251 // "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
252 // (SimInfo.regionLocX * Constants.RegionSize),
253 // (SimInfo.regionLocY*Constants.RegionSize),
254 // theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z,
255 // theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z);
256 theUser.CurrentAgent.Position = new Vector3(128, 128, 0);
257 response.StartLocation = "safe";
258
259 return PrepareLoginToRegion(regionInfo, theUser, response);
260 }
261
262 protected RegionInfo RequestClosestRegion(string region)
263 { 130 {
264 return m_regionsConnector.RequestClosestRegion(region); 131 return m_regionsConnector.RequestClosestRegion(region);
265 } 132 }
266 133
267 protected RegionInfo GetRegionInfo(ulong homeRegionHandle) 134 protected override RegionInfo GetRegionInfo(ulong homeRegionHandle)
268 { 135 {
269 return m_regionsConnector.RequestNeighbourInfo(homeRegionHandle); 136 return m_regionsConnector.RequestNeighbourInfo(homeRegionHandle);
270 } 137 }
271 138
272 protected RegionInfo GetRegionInfo(UUID homeRegionId) 139 protected override RegionInfo GetRegionInfo(UUID homeRegionId)
273 { 140 {
274 return m_regionsConnector.RequestNeighbourInfo(homeRegionId); 141 return m_regionsConnector.RequestNeighbourInfo(homeRegionId);
275 } 142 }
@@ -283,7 +150,7 @@ namespace OpenSim.Client.Linden
283 /// <param name="theUser"> 150 /// <param name="theUser">
284 /// A <see cref="UserProfileData"/> 151 /// A <see cref="UserProfileData"/>
285 /// </param> 152 /// </param>
286 private void AddActiveGestures(LoginResponse response, UserProfileData theUser) 153 protected override void AddActiveGestures(LoginResponse response, UserProfileData theUser)
287 { 154 {
288 List<InventoryItemBase> gestures = m_interServiceInventoryService.GetActiveGestures(theUser.ID); 155 List<InventoryItemBase> gestures = m_interServiceInventoryService.GetActiveGestures(theUser.ID);
289 //m_log.DebugFormat("[LOGIN]: AddActiveGestures, found {0}", gestures == null ? 0 : gestures.Count); 156 //m_log.DebugFormat("[LOGIN]: AddActiveGestures, found {0}", gestures == null ? 0 : gestures.Count);
@@ -309,7 +176,7 @@ namespace OpenSim.Client.Linden
309 /// <param name="user"></param> 176 /// <param name="user"></param>
310 /// <param name="response"></param> 177 /// <param name="response"></param>
311 /// <returns>true if the region was successfully contacted, false otherwise</returns> 178 /// <returns>true if the region was successfully contacted, false otherwise</returns>
312 protected bool PrepareLoginToRegion(RegionInfo regionInfo, UserProfileData user, LoginResponse response) 179 protected override bool PrepareLoginToRegion(RegionInfo regionInfo, UserProfileData user, LoginResponse response)
313 { 180 {
314 IPEndPoint endPoint = regionInfo.ExternalEndPoint; 181 IPEndPoint endPoint = regionInfo.ExternalEndPoint;
315 response.SimAddress = endPoint.Address.ToString(); 182 response.SimAddress = endPoint.Address.ToString();
diff --git a/OpenSim/Data/RegionProfileData.cs b/OpenSim/Data/RegionProfileData.cs
index 5476233..7dd4a41 100644
--- a/OpenSim/Data/RegionProfileData.cs
+++ b/OpenSim/Data/RegionProfileData.cs
@@ -282,7 +282,20 @@ namespace OpenSim.Data
282 282
283 public RegionInfo ToRegionInfo( ) 283 public RegionInfo ToRegionInfo( )
284 { 284 {
285 return RegionInfo.Create(UUID, regionName, regionLocX, regionLocY, serverIP, httpPort, serverPort, remotingPort); 285 return RegionInfo.Create(UUID, regionName, regionLocX, regionLocY, serverIP, httpPort, serverPort, remotingPort, serverURI );
286 }
287
288 public static RegionProfileData FromRegionInfo( RegionInfo regionInfo )
289 {
290 if( regionInfo == null )
291 {
292 return null;
293 }
294
295 return Create(regionInfo.RegionID, regionInfo.RegionName, regionInfo.RegionLocX,
296 regionInfo.RegionLocY, regionInfo.ExternalHostName,
297 (uint) regionInfo.ExternalEndPoint.Port, regionInfo.HttpPort, regionInfo.RemotingPort,
298 regionInfo.ServerURI);
286 } 299 }
287 300
288 public static RegionProfileData Create(UUID regionID, string regionName, uint locX, uint locY, string externalHostName, uint regionPort, uint httpPort, uint remotingPort, string serverUri) 301 public static RegionProfileData Create(UUID regionID, string regionName, uint locX, uint locY, string externalHostName, uint regionPort, uint httpPort, uint remotingPort, string serverUri)
diff --git a/OpenSim/Framework/Communications/LoginService.cs b/OpenSim/Framework/Communications/LoginService.cs
index 36d7280..278ea43 100644
--- a/OpenSim/Framework/Communications/LoginService.cs
+++ b/OpenSim/Framework/Communications/LoginService.cs
@@ -78,15 +78,6 @@ namespace OpenSim.Framework.Communications
78 } 78 }
79 79
80 /// <summary> 80 /// <summary>
81 /// Customises the login response and fills in missing values. This method also tells the login region to
82 /// expect a client connection.
83 /// </summary>
84 /// <param name="response">The existing response</param>
85 /// <param name="theUser">The user profile</param>
86 /// <returns>true on success, false if the region was not successfully told to expect a user connection</returns>
87 public abstract bool CustomiseResponse(LoginResponse response, UserProfileData theUser, string startLocationRequest);
88
89 /// <summary>
90 /// If the user is already logged in, try to notify the region that the user they've got is dead. 81 /// If the user is already logged in, try to notify the region that the user they've got is dead.
91 /// </summary> 82 /// </summary>
92 /// <param name="theUser"></param> 83 /// <param name="theUser"></param>
@@ -872,5 +863,152 @@ namespace OpenSim.Framework.Communications
872 m_log.InfoFormat("[LOGIN]: Login with web_login_key {0}", web_login_key); 863 m_log.InfoFormat("[LOGIN]: Login with web_login_key {0}", web_login_key);
873 } 864 }
874 } 865 }
866
867 /// <summary>
868 /// Customises the login response and fills in missing values. This method also tells the login region to
869 /// expect a client connection.
870 /// </summary>
871 /// <param name="response">The existing response</param>
872 /// <param name="theUser">The user profile</param>
873 /// <param name="startLocationRequest">The requested start location</param>
874 /// <returns>true on success, false if the region was not successfully told to expect a user connection</returns>
875 public bool CustomiseResponse(LoginResponse response, UserProfileData theUser, string startLocationRequest)
876 {
877 // add active gestures to login-response
878 AddActiveGestures(response, theUser);
879
880 // HomeLocation
881 RegionInfo homeInfo = null;
882
883 // use the homeRegionID if it is stored already. If not, use the regionHandle as before
884 UUID homeRegionId = theUser.HomeRegionID;
885 ulong homeRegionHandle = theUser.HomeRegion;
886 if (homeRegionId != UUID.Zero)
887 {
888 homeInfo = GetRegionInfo(homeRegionId);
889 }
890 else
891 {
892 homeInfo = GetRegionInfo(homeRegionHandle);
893 }
894
895 if (homeInfo != null)
896 {
897 response.Home =
898 string.Format(
899 "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
900 (homeInfo.RegionLocX * Constants.RegionSize),
901 (homeInfo.RegionLocY * Constants.RegionSize),
902 theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z,
903 theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z);
904 }
905 else
906 {
907 m_log.InfoFormat("not found the region at {0} {1}", theUser.HomeRegionX, theUser.HomeRegionY);
908 // Emergency mode: Home-region isn't available, so we can't request the region info.
909 // Use the stored home regionHandle instead.
910 // NOTE: If the home-region moves, this will be wrong until the users update their user-profile again
911 ulong regionX = homeRegionHandle >> 32;
912 ulong regionY = homeRegionHandle & 0xffffffff;
913 response.Home =
914 string.Format(
915 "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
916 regionX, regionY,
917 theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z,
918 theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z);
919
920 m_log.InfoFormat("[LOGIN] Home region of user {0} {1} is not available; using computed region position {2} {3}",
921 theUser.FirstName, theUser.SurName,
922 regionX, regionY);
923 }
924
925 // StartLocation
926 RegionInfo regionInfo = null;
927 if (startLocationRequest == "home")
928 {
929 regionInfo = homeInfo;
930 theUser.CurrentAgent.Position = theUser.HomeLocation;
931 response.LookAt = "[r" + theUser.HomeLookAt.X.ToString() + ",r" + theUser.HomeLookAt.Y.ToString() + ",r" + theUser.HomeLookAt.Z.ToString() + "]";
932 }
933 else if (startLocationRequest == "last")
934 {
935 UUID lastRegion = theUser.CurrentAgent.Region;
936 regionInfo = GetRegionInfo(lastRegion);
937 response.LookAt = "[r" + theUser.CurrentAgent.LookAt.X.ToString() + ",r" + theUser.CurrentAgent.LookAt.Y.ToString() + ",r" + theUser.CurrentAgent.LookAt.Z.ToString() + "]";
938 }
939 else
940 {
941 Regex reURI = new Regex(@"^uri:(?<region>[^&]+)&(?<x>\d+)&(?<y>\d+)&(?<z>\d+)$");
942 Match uriMatch = reURI.Match(startLocationRequest);
943 if (uriMatch == null)
944 {
945 m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, but can't process it", startLocationRequest);
946 }
947 else
948 {
949 string region = uriMatch.Groups["region"].ToString();
950 regionInfo = RequestClosestRegion(region);
951 if (regionInfo == null)
952 {
953 m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, can't locate region {1}", startLocationRequest, region);
954 }
955 else
956 {
957 theUser.CurrentAgent.Position = new Vector3(float.Parse(uriMatch.Groups["x"].Value),
958 float.Parse(uriMatch.Groups["y"].Value), float.Parse(uriMatch.Groups["z"].Value));
959 }
960 }
961 response.LookAt = "[r0,r1,r0]";
962 // can be: last, home, safe, url
963 response.StartLocation = "url";
964 }
965
966 if ((regionInfo != null) && (PrepareLoginToRegion(regionInfo, theUser, response)))
967 {
968 return true;
969 }
970
971 // StartLocation not available, send him to a nearby region instead
972 // regionInfo = m_gridService.RequestClosestRegion("");
973 //m_log.InfoFormat("[LOGIN]: StartLocation not available sending to region {0}", regionInfo.regionName);
974
975 // Send him to default region instead
976 ulong defaultHandle = (((ulong)m_defaultHomeX * Constants.RegionSize) << 32) |
977 ((ulong)m_defaultHomeY * Constants.RegionSize);
978
979 if ((regionInfo != null) && (defaultHandle == regionInfo.RegionHandle))
980 {
981 m_log.ErrorFormat("[LOGIN]: Not trying the default region since this is the same as the selected region");
982 return false;
983 }
984
985 m_log.Error("[LOGIN]: Sending user to default region " + defaultHandle + " instead");
986 regionInfo = GetRegionInfo(defaultHandle);
987
988 if( regionInfo == null )
989 {
990 m_log.ErrorFormat("[LOGIN]: No default region available. Aborting.");
991 return false;
992 }
993
994 // Customise the response
995 //response.Home =
996 // string.Format(
997 // "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
998 // (SimInfo.regionLocX * Constants.RegionSize),
999 // (SimInfo.regionLocY*Constants.RegionSize),
1000 // theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z,
1001 // theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z);
1002 theUser.CurrentAgent.Position = new Vector3(128, 128, 0);
1003 response.StartLocation = "safe";
1004
1005 return PrepareLoginToRegion(regionInfo, theUser, response);
1006 }
1007
1008 protected abstract RegionInfo RequestClosestRegion(string region);
1009 protected abstract RegionInfo GetRegionInfo(ulong homeRegionHandle);
1010 protected abstract RegionInfo GetRegionInfo(UUID homeRegionId);
1011 protected abstract void AddActiveGestures(LoginResponse response, UserProfileData theUser);
1012 protected abstract bool PrepareLoginToRegion(RegionInfo regionInfo, UserProfileData user, LoginResponse response);
875 } 1013 }
876} 1014}
diff --git a/OpenSim/Framework/RegionInfo.cs b/OpenSim/Framework/RegionInfo.cs
index c958c68..202b587 100644
--- a/OpenSim/Framework/RegionInfo.cs
+++ b/OpenSim/Framework/RegionInfo.cs
@@ -676,7 +676,7 @@ namespace OpenSim.Framework
676 proxyUrl = args["proxy_url"].AsString(); 676 proxyUrl = args["proxy_url"].AsString();
677 } 677 }
678 678
679 public static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, uint httpPort, uint simPort, uint remotingPort) 679 public static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, uint httpPort, uint simPort, uint remotingPort, string serverURI)
680 { 680 {
681 RegionInfo regionInfo; 681 RegionInfo regionInfo;
682 IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(externalHostName), (int)simPort); 682 IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(externalHostName), (int)simPort);
@@ -686,6 +686,7 @@ namespace OpenSim.Framework
686 regionInfo.HttpPort = httpPort; 686 regionInfo.HttpPort = httpPort;
687 regionInfo.RegionID = regionID; 687 regionInfo.RegionID = regionID;
688 regionInfo.RegionName = regionName; 688 regionInfo.RegionName = regionName;
689 regionInfo.ServerURI = serverURI;
689 return regionInfo; 690 return regionInfo;
690 } 691 }
691 } 692 }
diff --git a/OpenSim/Grid/UserServer.Modules/UserLoginService.cs b/OpenSim/Grid/UserServer.Modules/UserLoginService.cs
index 4e672f6..f7ee8ef 100644
--- a/OpenSim/Grid/UserServer.Modules/UserLoginService.cs
+++ b/OpenSim/Grid/UserServer.Modules/UserLoginService.cs
@@ -99,11 +99,11 @@ namespace OpenSim.Grid.UserServer.Modules
99 m_httpServer.AddStreamHandler(new OpenIdStreamHandler("GET", "/openid/server/", this)); 99 m_httpServer.AddStreamHandler(new OpenIdStreamHandler("GET", "/openid/server/", this));
100 } 100 }
101 } 101 }
102 102
103 public void setloginlevel(int level) 103 public void setloginlevel(int level)
104 { 104 {
105 m_minLoginLevel = level; 105 m_minLoginLevel = level;
106 m_log.InfoFormat("[GRID]: Login Level set to {0} ", level); 106 m_log.InfoFormat("[GRID]: Login Level set to {0} ", level);
107 } 107 }
108 public void setwelcometext(string text) 108 public void setwelcometext(string text)
109 { 109 {
@@ -199,155 +199,49 @@ namespace OpenSim.Grid.UserServer.Modules
199 //base.LogOffUser(theUser); 199 //base.LogOffUser(theUser);
200 } 200 }
201 201
202 /// <summary> 202 protected override RegionInfo RequestClosestRegion(string region)
203 /// Customises the login response and fills in missing values.
204 /// </summary>
205 /// <param name="response">The existing response</param>
206 /// <param name="theUser">The user profile</param>
207 /// <param name="startLocationRequest">The requested start location</param>
208 public override bool CustomiseResponse(LoginResponse response, UserProfileData theUser, string startLocationRequest)
209 { 203 {
210 // add active gestures to login-response 204 RegionProfileData profileData = m_regionProfileService.RequestSimProfileData(region,
211 AddActiveGestures(response, theUser); 205 m_config.GridServerURL, m_config.GridSendKey, m_config.GridRecvKey);
212
213 // HomeLocation
214 RegionProfileData homeInfo = null;
215 // use the homeRegionID if it is stored already. If not, use the regionHandle as before
216 UUID homeRegionId = theUser.HomeRegionID;
217 ulong homeRegionHandle = theUser.HomeRegion;
218 if (homeRegionId != UUID.Zero)
219 {
220 homeInfo = GetRegionInfo(homeRegionId);
221 }
222 else
223 {
224 homeInfo = GetRegionInfo(homeRegionHandle);
225 }
226 206
227 if (homeInfo != null) 207 if (profileData != null)
228 { 208 {
229 response.Home = 209 return profileData.ToRegionInfo();
230 string.Format(
231 "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
232 (homeInfo.regionLocX*Constants.RegionSize),
233 (homeInfo.regionLocY*Constants.RegionSize),
234 theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z,
235 theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z);
236 } 210 }
237 else 211 else
238 { 212 {
239 // Emergency mode: Home-region isn't available, so we can't request the region info. 213 return null;
240 // Use the stored home regionHandle instead.
241 // NOTE: If the home-region moves, this will be wrong until the users update their user-profile again
242 ulong regionX = homeRegionHandle >> 32;
243 ulong regionY = homeRegionHandle & 0xffffffff;
244 response.Home =
245 string.Format(
246 "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
247 regionX, regionY,
248 theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z,
249 theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z);
250 m_log.InfoFormat("[LOGIN] Home region of user {0} {1} is not available; using computed region position {2} {3}",
251 theUser.FirstName, theUser.SurName,
252 regionX, regionY);
253 } 214 }
215 }
254 216
255 // StartLocation 217 protected override RegionInfo GetRegionInfo(ulong homeRegionHandle)
256 RegionProfileData regionInfo = null; 218 {
257 if (startLocationRequest == "home") 219 RegionProfileData profileData = m_regionProfileService.RequestSimProfileData(homeRegionHandle,
258 { 220 m_config.GridServerURL, m_config.GridSendKey,
259 regionInfo = homeInfo; 221 m_config.GridRecvKey);
260 theUser.CurrentAgent.Position = theUser.HomeLocation; 222 if (profileData != null)
261 response.LookAt = "[r" + theUser.HomeLookAt.X.ToString() + ",r" + theUser.HomeLookAt.Y.ToString() + ",r" + theUser.HomeLookAt.Z.ToString() + "]";
262 }
263 else if (startLocationRequest == "last")
264 { 223 {
265 UUID lastRegion = theUser.CurrentAgent.Region; 224 return profileData.ToRegionInfo();
266 regionInfo = GetRegionInfo(lastRegion);
267 response.LookAt = "[r" + theUser.CurrentAgent.LookAt.X.ToString() + ",r" + theUser.CurrentAgent.LookAt.Y.ToString() + ",r" + theUser.CurrentAgent.LookAt.Z.ToString() + "]";
268 } 225 }
269 else 226 else
270 { 227 {
271 Regex reURI = new Regex(@"^uri:(?<region>[^&]+)&(?<x>\d+)&(?<y>\d+)&(?<z>\d+)$"); 228 return null;
272 Match uriMatch = reURI.Match(startLocationRequest);
273 if (uriMatch == null)
274 {
275 m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, but can't process it", startLocationRequest);
276 }
277 else
278 {
279 string region = uriMatch.Groups["region"].ToString();
280 regionInfo = RequestClosestRegion(region);
281 if (regionInfo == null)
282 {
283 m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, can't locate region {1}", startLocationRequest, region);
284 }
285 else
286 {
287 theUser.CurrentAgent.Position = new Vector3(float.Parse(uriMatch.Groups["x"].Value),
288 float.Parse(uriMatch.Groups["y"].Value), float.Parse(uriMatch.Groups["z"].Value));
289 }
290 }
291 response.LookAt = "[r0,r1,r0]";
292 // can be: last, home, safe, url
293 response.StartLocation = "url";
294 } 229 }
230 }
295 231
296 if ((regionInfo != null) && (PrepareLoginToRegion(regionInfo, theUser, response))) 232 protected override RegionInfo GetRegionInfo(UUID homeRegionId)
233 {
234 RegionProfileData profileData = m_regionProfileService.RequestSimProfileData(homeRegionId,
235 m_config.GridServerURL, m_config.GridSendKey,
236 m_config.GridRecvKey);
237 if (profileData != null)
297 { 238 {
298 return true; 239 return profileData.ToRegionInfo();
299 } 240 }
300 241 else
301 // StartLocation not available, send him to a nearby region instead
302 //regionInfo = RegionProfileData.RequestSimProfileData("", m_config.GridServerURL, m_config.GridSendKey, m_config.GridRecvKey);
303 //m_log.InfoFormat("[LOGIN]: StartLocation not available sending to region {0}", regionInfo.regionName);
304
305 // Send him to default region instead
306 // Load information from the gridserver
307 ulong defaultHandle = (((ulong) m_defaultHomeX * Constants.RegionSize) << 32) |
308 ((ulong) m_defaultHomeY * Constants.RegionSize);
309
310 if ((regionInfo != null) && (defaultHandle == regionInfo.regionHandle))
311 { 242 {
312 m_log.ErrorFormat("[LOGIN]: Not trying the default region since this is the same as the selected region"); 243 return null;
313 return false;
314 } 244 }
315
316 m_log.Error("[LOGIN]: Sending user to default region " + defaultHandle + " instead");
317 regionInfo = GetRegionInfo(defaultHandle);
318
319 // Customise the response
320 //response.Home =
321 // string.Format(
322 // "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
323 // (SimInfo.regionLocX * Constants.RegionSize),
324 // (SimInfo.regionLocY*Constants.RegionSize),
325 // theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z,
326 // theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z);
327 theUser.CurrentAgent.Position = new Vector3(128,128,0);
328 response.StartLocation = "safe";
329
330 return PrepareLoginToRegion(regionInfo, theUser, response);
331 }
332
333 protected RegionProfileData RequestClosestRegion(string region)
334 {
335 return m_regionProfileService.RequestSimProfileData(region,
336 m_config.GridServerURL, m_config.GridSendKey, m_config.GridRecvKey);
337 }
338
339 protected RegionProfileData GetRegionInfo(ulong homeRegionHandle)
340 {
341 return m_regionProfileService.RequestSimProfileData(homeRegionHandle,
342 m_config.GridServerURL, m_config.GridSendKey,
343 m_config.GridRecvKey);
344 }
345
346 protected RegionProfileData GetRegionInfo(UUID homeRegionId)
347 {
348 return m_regionProfileService.RequestSimProfileData(homeRegionId,
349 m_config.GridServerURL, m_config.GridSendKey,
350 m_config.GridRecvKey);
351 } 245 }
352 246
353 /// <summary> 247 /// <summary>
@@ -359,7 +253,7 @@ namespace OpenSim.Grid.UserServer.Modules
359 /// <param name="theUser"> 253 /// <param name="theUser">
360 /// A <see cref="UserProfileData"/> 254 /// A <see cref="UserProfileData"/>
361 /// </param> 255 /// </param>
362 private void AddActiveGestures(LoginResponse response, UserProfileData theUser) 256 protected override void AddActiveGestures(LoginResponse response, UserProfileData theUser)
363 { 257 {
364 List<InventoryItemBase> gestures = m_inventoryService.GetActiveGestures(theUser.ID); 258 List<InventoryItemBase> gestures = m_inventoryService.GetActiveGestures(theUser.ID);
365 //m_log.DebugFormat("[LOGIN]: AddActiveGestures, found {0}", gestures == null ? 0 : gestures.Count); 259 //m_log.DebugFormat("[LOGIN]: AddActiveGestures, found {0}", gestures == null ? 0 : gestures.Count);
@@ -377,18 +271,23 @@ namespace OpenSim.Grid.UserServer.Modules
377 response.ActiveGestures = list; 271 response.ActiveGestures = list;
378 } 272 }
379 273
274 protected override bool PrepareLoginToRegion(RegionInfo regionInfo, UserProfileData user, LoginResponse response)
275 {
276 return PrepareLoginToRegion(RegionProfileData.FromRegionInfo(regionInfo), user, response);
277 }
278
380 /// <summary> 279 /// <summary>
381 /// Prepare a login to the given region. This involves both telling the region to expect a connection 280 /// Prepare a login to the given region. This involves both telling the region to expect a connection
382 /// and appropriately customising the response to the user. 281 /// and appropriately customising the response to the user.
383 /// </summary> 282 /// </summary>
384 /// <param name="sim"></param> 283 /// <param name="regionInfo"></param>
385 /// <param name="user"></param> 284 /// <param name="user"></param>
386 /// <param name="response"></param> 285 /// <param name="response"></param>
387 /// <returns>true if the region was successfully contacted, false otherwise</returns> 286 /// <returns>true if the region was successfully contacted, false otherwise</returns>
388 private bool PrepareLoginToRegion(RegionProfileData regionInfo, UserProfileData user, LoginResponse response) 287 private bool PrepareLoginToRegion(RegionProfileData regionInfo, UserProfileData user, LoginResponse response)
389 { 288 {
390 try 289 try
391 { 290 {
392 response.SimAddress = Util.GetHostFromURL(regionInfo.serverURI).ToString(); 291 response.SimAddress = Util.GetHostFromURL(regionInfo.serverURI).ToString();
393 response.SimPort = uint.Parse(regionInfo.serverURI.Split(new char[] { '/', ':' })[4]); 292 response.SimPort = uint.Parse(regionInfo.serverURI.Split(new char[] { '/', ':' })[4]);
394 response.RegionX = regionInfo.regionLocX; 293 response.RegionX = regionInfo.regionLocX;
@@ -405,11 +304,11 @@ namespace OpenSim.Grid.UserServer.Modules
405 m_log.InfoFormat( 304 m_log.InfoFormat(
406 "[LOGIN]: Telling {0} @ {1},{2} ({3}) to prepare for client connection", 305 "[LOGIN]: Telling {0} @ {1},{2} ({3}) to prepare for client connection",
407 regionInfo.regionName, response.RegionX, response.RegionY, regionInfo.httpServerURI); 306 regionInfo.regionName, response.RegionX, response.RegionY, regionInfo.httpServerURI);
408 307
409 // Update agent with target sim 308 // Update agent with target sim
410 user.CurrentAgent.Region = regionInfo.UUID; 309 user.CurrentAgent.Region = regionInfo.UUID;
411 user.CurrentAgent.Handle = regionInfo.regionHandle; 310 user.CurrentAgent.Handle = regionInfo.regionHandle;
412 311
413 // Prepare notification 312 // Prepare notification
414 Hashtable loginParams = new Hashtable(); 313 Hashtable loginParams = new Hashtable();
415 loginParams["session_id"] = user.CurrentAgent.SessionID.ToString(); 314 loginParams["session_id"] = user.CurrentAgent.SessionID.ToString();
@@ -417,7 +316,7 @@ namespace OpenSim.Grid.UserServer.Modules
417 loginParams["firstname"] = user.FirstName; 316 loginParams["firstname"] = user.FirstName;
418 loginParams["lastname"] = user.SurName; 317 loginParams["lastname"] = user.SurName;
419 loginParams["agent_id"] = user.ID.ToString(); 318 loginParams["agent_id"] = user.ID.ToString();
420 loginParams["circuit_code"] = (Int32) Convert.ToUInt32(response.CircuitCode); 319 loginParams["circuit_code"] = (Int32)Convert.ToUInt32(response.CircuitCode);
421 loginParams["startpos_x"] = user.CurrentAgent.Position.X.ToString(); 320 loginParams["startpos_x"] = user.CurrentAgent.Position.X.ToString();
422 loginParams["startpos_y"] = user.CurrentAgent.Position.Y.ToString(); 321 loginParams["startpos_y"] = user.CurrentAgent.Position.Y.ToString();
423 loginParams["startpos_z"] = user.CurrentAgent.Position.Z.ToString(); 322 loginParams["startpos_z"] = user.CurrentAgent.Position.Z.ToString();
@@ -450,10 +349,10 @@ namespace OpenSim.Grid.UserServer.Modules
450 349
451 if (GridResp.Value != null) 350 if (GridResp.Value != null)
452 { 351 {
453 Hashtable resp = (Hashtable) GridResp.Value; 352 Hashtable resp = (Hashtable)GridResp.Value;
454 if (resp.ContainsKey("success")) 353 if (resp.ContainsKey("success"))
455 { 354 {
456 if ((string) resp["success"] == "FALSE") 355 if ((string)resp["success"] == "FALSE")
457 { 356 {
458 responseSuccess = false; 357 responseSuccess = false;
459 } 358 }
@@ -533,7 +432,7 @@ namespace OpenSim.Grid.UserServer.Modules
533 432
534 foreach (InventoryFolderBase InvFolder in folders) 433 foreach (InventoryFolderBase InvFolder in folders)
535 { 434 {
536// m_log.DebugFormat("[LOGIN]: Received agent inventory folder {0}", InvFolder.name); 435 // m_log.DebugFormat("[LOGIN]: Received agent inventory folder {0}", InvFolder.name);
537 436
538 if (InvFolder.ParentID == UUID.Zero) 437 if (InvFolder.ParentID == UUID.Zero)
539 { 438 {
@@ -542,8 +441,8 @@ namespace OpenSim.Grid.UserServer.Modules
542 TempHash = new Hashtable(); 441 TempHash = new Hashtable();
543 TempHash["name"] = InvFolder.Name; 442 TempHash["name"] = InvFolder.Name;
544 TempHash["parent_id"] = InvFolder.ParentID.ToString(); 443 TempHash["parent_id"] = InvFolder.ParentID.ToString();
545 TempHash["version"] = (Int32) InvFolder.Version; 444 TempHash["version"] = (Int32)InvFolder.Version;
546 TempHash["type_default"] = (Int32) InvFolder.Type; 445 TempHash["type_default"] = (Int32)InvFolder.Type;
547 TempHash["folder_id"] = InvFolder.ID.ToString(); 446 TempHash["folder_id"] = InvFolder.ID.ToString();
548 AgentInventoryArray.Add(TempHash); 447 AgentInventoryArray.Add(TempHash);
549 } 448 }
@@ -559,14 +458,14 @@ namespace OpenSim.Grid.UserServer.Modules
559 public XmlRpcResponse XmlRPCSetLoginParams(XmlRpcRequest request) 458 public XmlRpcResponse XmlRPCSetLoginParams(XmlRpcRequest request)
560 { 459 {
561 XmlRpcResponse response = new XmlRpcResponse(); 460 XmlRpcResponse response = new XmlRpcResponse();
562 Hashtable requestData = (Hashtable) request.Params[0]; 461 Hashtable requestData = (Hashtable)request.Params[0];
563 UserProfileData userProfile; 462 UserProfileData userProfile;
564 Hashtable responseData = new Hashtable(); 463 Hashtable responseData = new Hashtable();
565 464
566 UUID uid; 465 UUID uid;
567 string pass = requestData["password"].ToString(); 466 string pass = requestData["password"].ToString();
568 467
569 if (!UUID.TryParse((string) requestData["avatar_uuid"], out uid)) 468 if (!UUID.TryParse((string)requestData["avatar_uuid"], out uid))
570 { 469 {
571 responseData["error"] = "No authorization"; 470 responseData["error"] = "No authorization";
572 response.Value = responseData; 471 response.Value = responseData;
@@ -597,6 +496,5 @@ namespace OpenSim.Grid.UserServer.Modules
597 response.Value = responseData; 496 response.Value = responseData;
598 return response; 497 return response;
599 } 498 }
600
601 } 499 }
602} 500}
diff --git a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs
index 1a72f31..6191f27 100644
--- a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs
+++ b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs
@@ -416,11 +416,14 @@ namespace OpenSim.Region.Communications.OGS1
416 httpPort = Convert.ToUInt32((string)responseData["http_port"]); 416 httpPort = Convert.ToUInt32((string)responseData["http_port"]);
417 } 417 }
418 418
419 // Ok, so this is definitively the wrong place to do this, way too hard coded, but it doesn't seem we GET this info?
420
421 string simURI = "http://" + regionInfo.ExternalHostName + ":" + regionInfo.InternalEndPoint.Port;
419 422
420 // string externalUri = (string) responseData["sim_uri"]; 423 // string externalUri = (string) responseData["sim_uri"];
421 424
422 //IPEndPoint neighbourInternalEndPoint = new IPEndPoint(IPAddress.Parse(internalIpStr), (int) port); 425 //IPEndPoint neighbourInternalEndPoint = new IPEndPoint(IPAddress.Parse(internalIpStr), (int) port);
423 regionInfo = RegionInfo.Create(regionID, regionName, regX, regY, externalHostName, httpPort, simPort, remotingPort); 426 regionInfo = RegionInfo.Create(regionID, regionName, regX, regY, externalHostName, httpPort, simPort, remotingPort, simURI );
424 427
425 lock (m_remoteRegionInfoCache) 428 lock (m_remoteRegionInfoCache)
426 { 429 {