aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJohan Berntsson2008-03-18 01:38:07 +0000
committerJohan Berntsson2008-03-18 01:38:07 +0000
commit040a887b9c5f22a79de3fdff3947b69d87221379 (patch)
tree401793a60499cd010ed360b6fbf991d42eb87798 /OpenSim
parent* Move missing texture request forward so that we don't actually ask the Asse... (diff)
downloadopensim-SC_OLD-040a887b9c5f22a79de3fdff3947b69d87221379.zip
opensim-SC_OLD-040a887b9c5f22a79de3fdff3947b69d87221379.tar.gz
opensim-SC_OLD-040a887b9c5f22a79de3fdff3947b69d87221379.tar.bz2
opensim-SC_OLD-040a887b9c5f22a79de3fdff3947b69d87221379.tar.xz
Last position will be stored in the DB on logout, and the avatar can continue from the same position in the next login (only with MySQL at the moment)
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/Communications/LoginService.cs4
-rw-r--r--OpenSim/Framework/Communications/UserManagerBase.cs57
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLManager.cs52
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLUserData.cs13
4 files changed, 115 insertions, 11 deletions
diff --git a/OpenSim/Framework/Communications/LoginService.cs b/OpenSim/Framework/Communications/LoginService.cs
index 3bf6096..fc02ff6 100644
--- a/OpenSim/Framework/Communications/LoginService.cs
+++ b/OpenSim/Framework/Communications/LoginService.cs
@@ -154,6 +154,10 @@ namespace OpenSim.Framework.UserManagement
154 154
155 if (userProfile.currentAgent != null && userProfile.currentAgent.agentOnline) 155 if (userProfile.currentAgent != null && userProfile.currentAgent.agentOnline)
156 { 156 {
157 //TODO: The following statements can cause trouble:
158 // If agentOnline could not turn from true back to false normally
159 // because of some problem, for instance, the crashment of server or client,
160 // the user cannot log in any longer.
157 userProfile.currentAgent = null; 161 userProfile.currentAgent = null;
158 m_userManager.CommitAgent(ref userProfile); 162 m_userManager.CommitAgent(ref userProfile);
159 163
diff --git a/OpenSim/Framework/Communications/UserManagerBase.cs b/OpenSim/Framework/Communications/UserManagerBase.cs
index 3380e90..b8e3114 100644
--- a/OpenSim/Framework/Communications/UserManagerBase.cs
+++ b/OpenSim/Framework/Communications/UserManagerBase.cs
@@ -27,6 +27,7 @@
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections;
30using System.Collections.Generic; 31using System.Collections.Generic;
31using System.Reflection; 32using System.Reflection;
32using System.Security.Cryptography; 33using System.Security.Cryptography;
@@ -337,7 +338,7 @@ namespace OpenSim.Framework.UserManagement
337 /// <param name="request">The users loginrequest</param> 338 /// <param name="request">The users loginrequest</param>
338 public void CreateAgent(UserProfileData profile, XmlRpcRequest request) 339 public void CreateAgent(UserProfileData profile, XmlRpcRequest request)
339 { 340 {
340 //Hashtable requestData = (Hashtable) request.Params[0]; 341 Hashtable requestData = (Hashtable) request.Params[0];
341 342
342 UserAgentData agent = new UserAgentData(); 343 UserAgentData agent = new UserAgentData();
343 344
@@ -362,9 +363,24 @@ namespace OpenSim.Framework.UserManagement
362 agent.currentPos = profile.homeLocation; 363 agent.currentPos = profile.homeLocation;
363 364
364 // If user specified additional start, use that 365 // If user specified additional start, use that
365// if (requestData.ContainsKey("start")) 366 if (requestData.ContainsKey("start"))
366// { 367 {
367// string startLoc = ((string) requestData["start"]).Trim(); 368 string startLoc = ((string)requestData["start"]).Trim();
369 if (("last" == startLoc) && (profile.currentAgent != null))
370 {
371 if ((profile.currentAgent.currentPos.X > 0)
372 && (profile.currentAgent.currentPos.Y > 0)
373 && (profile.currentAgent.currentPos.Z > 0)
374 )
375 {
376 // TODO: Right now, currentRegion has not been used in GridServer for requesting region.
377 // TODO: It is only using currentHandle.
378 agent.currentRegion = profile.currentAgent.currentRegion;
379 agent.currentHandle = profile.currentAgent.currentHandle;
380 agent.currentPos = profile.currentAgent.currentPos;
381 }
382 }
383
368// if (!(startLoc == "last" || startLoc == "home")) 384// if (!(startLoc == "last" || startLoc == "home"))
369// { 385// {
370// // Format: uri:Ahern&162&213&34 386// // Format: uri:Ahern&162&213&34
@@ -381,7 +397,7 @@ namespace OpenSim.Framework.UserManagement
381// { 397// {
382// } 398// }
383// } 399// }
384// } 400 }
385 401
386 // What time did the user login? 402 // What time did the user login?
387 agent.loginTime = Util.UnixTimeSinceEpoch(); 403 agent.loginTime = Util.UnixTimeSinceEpoch();
@@ -424,7 +440,7 @@ namespace OpenSim.Framework.UserManagement
424 { 440 {
425 userAgent.agentOnline = false; 441 userAgent.agentOnline = false;
426 userAgent.logoutTime = Util.UnixTimeSinceEpoch(); 442 userAgent.logoutTime = Util.UnixTimeSinceEpoch();
427 userAgent.sessionID = LLUUID.Zero; 443 //userAgent.sessionID = LLUUID.Zero;
428 if (regionid != null) 444 if (regionid != null)
429 { 445 {
430 userAgent.currentRegion = regionid; 446 userAgent.currentRegion = regionid;
@@ -493,8 +509,12 @@ namespace OpenSim.Framework.UserManagement
493 /// <returns>Successful?</returns> 509 /// <returns>Successful?</returns>
494 public bool CommitAgent(ref UserProfileData profile) 510 public bool CommitAgent(ref UserProfileData profile)
495 { 511 {
496 // TODO: how is this function different from setUserProfile? 512 // TODO: how is this function different from setUserProfile? -> Add AddUserAgent() here and commit both tables "users" and "agents"
497 return setUserProfile(profile); 513 // TODO: what is the logic should be?
514 bool ret = false;
515 ret = AddUserAgent(profile.currentAgent);
516 ret = ret & setUserProfile(profile);
517 return ret;
498 } 518 }
499 519
500 #endregion 520 #endregion
@@ -558,5 +578,26 @@ namespace OpenSim.Framework.UserManagement
558 public abstract UserProfileData SetupMasterUser(string firstName, string lastName); 578 public abstract UserProfileData SetupMasterUser(string firstName, string lastName);
559 public abstract UserProfileData SetupMasterUser(string firstName, string lastName, string password); 579 public abstract UserProfileData SetupMasterUser(string firstName, string lastName, string password);
560 public abstract UserProfileData SetupMasterUser(LLUUID uuid); 580 public abstract UserProfileData SetupMasterUser(LLUUID uuid);
581
582 /// <summary>
583 /// Add agent to DB
584 /// </summary>
585 /// <param name="agentdata">The agent data to be added</param>
586 public bool AddUserAgent(UserAgentData agentdata)
587 {
588 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
589 {
590 try
591 {
592 plugin.Value.AddNewUserAgent(agentdata);
593 return true;
594 }
595 catch (Exception e)
596 {
597 m_log.Info("[USERSTORAGE]: Unable to add agent via " + plugin.Key + "(" + e.ToString() + ")");
598 }
599 }
600 return false;
601 }
561 } 602 }
562} 603}
diff --git a/OpenSim/Framework/Data.MySQL/MySQLManager.cs b/OpenSim/Framework/Data.MySQL/MySQLManager.cs
index 0410643..46fd1bc 100644
--- a/OpenSim/Framework/Data.MySQL/MySQLManager.cs
+++ b/OpenSim/Framework/Data.MySQL/MySQLManager.cs
@@ -397,14 +397,14 @@ namespace OpenSim.Framework.Data.MySQL
397 // Agent Who? 397 // Agent Who?
398 retval.agentIP = (string) reader["agentIP"]; 398 retval.agentIP = (string) reader["agentIP"];
399 retval.agentPort = Convert.ToUInt32(reader["agentPort"].ToString()); 399 retval.agentPort = Convert.ToUInt32(reader["agentPort"].ToString());
400 retval.agentOnline = Convert.ToBoolean(reader["agentOnline"].ToString()); 400 retval.agentOnline = Convert.ToBoolean(Convert.ToInt16(reader["agentOnline"].ToString()));
401 401
402 // Login/Logout times (UNIX Epoch) 402 // Login/Logout times (UNIX Epoch)
403 retval.loginTime = Convert.ToInt32(reader["loginTime"].ToString()); 403 retval.loginTime = Convert.ToInt32(reader["loginTime"].ToString());
404 retval.logoutTime = Convert.ToInt32(reader["logoutTime"].ToString()); 404 retval.logoutTime = Convert.ToInt32(reader["logoutTime"].ToString());
405 405
406 // Current position 406 // Current position
407 retval.currentRegion = (string) reader["currentRegion"]; 407 retval.currentRegion = new LLUUID((string)reader["currentRegion"]);
408 retval.currentHandle = Convert.ToUInt64(reader["currentHandle"].ToString()); 408 retval.currentHandle = Convert.ToUInt64(reader["currentHandle"].ToString());
409 LLVector3.TryParse((string) reader["currentPos"], out retval.currentPos); 409 LLVector3.TryParse((string) reader["currentPos"], out retval.currentPos);
410 } 410 }
@@ -859,5 +859,53 @@ namespace OpenSim.Framework.Data.MySQL
859 859
860 return returnval; 860 return returnval;
861 } 861 }
862
863 /// <summary>
864 /// Creates a new agent and inserts it into the database
865 /// </summary>
866 /// <param name="agentdata">The agent data to be inserted</param>
867 /// <returns>Success?</returns>
868 public bool insertAgentRow(UserAgentData agentdata)
869 {
870 string sql = String.Empty;
871 sql += "REPLACE INTO ";
872 sql += "agents (UUID, sessionID, secureSessionID, agentIP, agentPort, agentOnline, loginTime, logoutTime, currentRegion, currentHandle, currentPos) VALUES ";
873 sql += "(?UUID, ?sessionID, ?secureSessionID, ?agentIP, ?agentPort, ?agentOnline, ?loginTime, ?logoutTime, ?currentRegion, ?currentHandle, ?currentPos);";
874 Dictionary<string, string> parameters = new Dictionary<string, string>();
875
876 parameters["?UUID"] = agentdata.UUID.ToString();
877 parameters["?sessionID"] = agentdata.sessionID.ToString();
878 parameters["?secureSessionID"] = agentdata.secureSessionID.ToString();
879 parameters["?agentIP"] = agentdata.agentIP.ToString();
880 parameters["?agentPort"] = agentdata.agentPort.ToString();
881 parameters["?agentOnline"] = (agentdata.agentOnline == true) ? "1" : "0";
882 parameters["?loginTime"] = agentdata.loginTime.ToString();
883 parameters["?logoutTime"] = agentdata.logoutTime.ToString();
884 parameters["?currentRegion"] = agentdata.currentRegion.ToString();
885 parameters["?currentHandle"] = agentdata.currentHandle.ToString();
886 parameters["?currentPos"] = "<" + ((int)agentdata.currentPos.X).ToString() + "," + ((int)agentdata.currentPos.Y).ToString() + "," + ((int)agentdata.currentPos.Z).ToString() + ">";
887
888 bool returnval = false;
889
890 try
891 {
892 IDbCommand result = Query(sql, parameters);
893
894 //Console.WriteLine(result.CommandText);
895 int x;
896 if ((x = result.ExecuteNonQuery()) > 0)
897 {
898 returnval = true;
899 }
900 result.Dispose();
901 }
902 catch (Exception e)
903 {
904 m_log.Error(e.ToString());
905 return false;
906 }
907
908 return returnval;
909 }
862 } 910 }
863} 911}
diff --git a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
index 2bba6ce..4c76461 100644
--- a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
+++ b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
@@ -585,7 +585,18 @@ namespace OpenSim.Framework.Data.MySQL
585 /// <param name="agent">The agent to create</param> 585 /// <param name="agent">The agent to create</param>
586 public void AddNewUserAgent(UserAgentData agent) 586 public void AddNewUserAgent(UserAgentData agent)
587 { 587 {
588 // Do nothing. 588 try
589 {
590 lock (database)
591 {
592 database.insertAgentRow(agent);
593 }
594 }
595 catch (Exception e)
596 {
597 database.Reconnect();
598 m_log.Error(e.ToString());
599 }
589 } 600 }
590 601
591 /// <summary> 602 /// <summary>