aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorMelanie2010-05-08 13:31:36 +0100
committerMelanie2010-05-08 13:31:36 +0100
commit14fcc2510ef9f1effc06d7e99b57f7f74de08eac (patch)
treee52f145ef2aac9a9cc7fb32a6a40e62f67991743 /OpenSim
parentMerge branch 'master' into careminster-presence-refactor (diff)
parenttest commit for panda (diff)
downloadopensim-SC_OLD-14fcc2510ef9f1effc06d7e99b57f7f74de08eac.zip
opensim-SC_OLD-14fcc2510ef9f1effc06d7e99b57f7f74de08eac.tar.gz
opensim-SC_OLD-14fcc2510ef9f1effc06d7e99b57f7f74de08eac.tar.bz2
opensim-SC_OLD-14fcc2510ef9f1effc06d7e99b57f7f74de08eac.tar.xz
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs2
-rw-r--r--OpenSim/Data/IGridUserData.cs9
-rw-r--r--OpenSim/Data/IPresenceData.cs4
-rw-r--r--OpenSim/Data/MSSQL/MSSQLGridUserData.cs8
-rw-r--r--OpenSim/Data/MSSQL/MSSQLPresenceData.cs72
-rw-r--r--OpenSim/Data/MySQL/MySQLGridUserData.cs9
-rw-r--r--OpenSim/Data/MySQL/MySQLPresenceData.cs66
-rw-r--r--OpenSim/Data/MySQL/Resources/001_GridUserStore.sql17
-rw-r--r--OpenSim/Data/MySQL/Resources/001_Presence.sql10
-rw-r--r--OpenSim/Data/MySQL/Resources/002_Presence.sql7
-rw-r--r--OpenSim/Data/MySQL/Resources/003_Presence.sql6
-rw-r--r--OpenSim/Data/Null/NullPresenceData.cs62
-rw-r--r--OpenSim/Data/SQLite/Resources/001_GridUserStore.sql16
-rw-r--r--OpenSim/Data/SQLite/SQLiteGridUserData.cs61
-rw-r--r--OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs9
-rw-r--r--OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs9
-rw-r--r--OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml4
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs116
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/LocalGridUserServiceConnector.cs69
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/RemoteGridUserServiceConnector.cs153
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs13
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs12
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs13
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs12
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs21
-rw-r--r--OpenSim/Region/Physics/Meshing/PrimMesher.cs103
-rw-r--r--OpenSim/Region/Physics/Meshing/SculptMap.cs176
-rw-r--r--OpenSim/Region/Physics/Meshing/SculptMesh.cs152
-rw-r--r--OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs61
-rw-r--r--OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs278
-rw-r--r--OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs45
-rw-r--r--OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs196
-rw-r--r--OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs54
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs88
-rw-r--r--OpenSim/Services/HypergridService/UserAgentService.cs21
-rw-r--r--OpenSim/Services/Interfaces/IGridUserService.cs42
-rw-r--r--OpenSim/Services/Interfaces/IPresenceService.cs30
-rw-r--r--OpenSim/Services/LLLoginService/LLLoginResponse.cs4
-rw-r--r--OpenSim/Services/LLLoginService/LLLoginService.cs63
-rw-r--r--OpenSim/Services/PresenceService/PresenceService.cs79
-rw-r--r--OpenSim/Services/UserAccountService/GridUserService.cs95
-rw-r--r--OpenSim/Services/UserAccountService/UserAccountService.cs10
-rw-r--r--OpenSim/Tests/Clients/Presence/PresenceClient.cs19
43 files changed, 1648 insertions, 648 deletions
diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
index 9f6414b..6da5558 100644
--- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
+++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
@@ -1729,7 +1729,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController
1729 GridRegion home = m_app.SceneManager.CurrentOrFirstScene.GridService.GetRegionByPosition(scopeID, 1729 GridRegion home = m_app.SceneManager.CurrentOrFirstScene.GridService.GetRegionByPosition(scopeID,
1730 (int)(regX * Constants.RegionSize), (int)(regY * Constants.RegionSize)); 1730 (int)(regX * Constants.RegionSize), (int)(regY * Constants.RegionSize));
1731 if (home != null) 1731 if (home != null)
1732 m_app.SceneManager.CurrentOrFirstScene.PresenceService.SetHomeLocation(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); 1732 m_app.SceneManager.CurrentOrFirstScene.GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
1733 } 1733 }
1734 else 1734 else
1735 { 1735 {
diff --git a/OpenSim/Data/IGridUserData.cs b/OpenSim/Data/IGridUserData.cs
index bd7a435..e15a1f8 100644
--- a/OpenSim/Data/IGridUserData.cs
+++ b/OpenSim/Data/IGridUserData.cs
@@ -37,6 +37,11 @@ namespace OpenSim.Data
37 { 37 {
38 public string UserID; 38 public string UserID;
39 public Dictionary<string, string> Data; 39 public Dictionary<string, string> Data;
40
41 public GridUserData()
42 {
43 Data = new Dictionary<string, string>();
44 }
40 } 45 }
41 46
42 /// <summary> 47 /// <summary>
@@ -44,7 +49,7 @@ namespace OpenSim.Data
44 /// </summary> 49 /// </summary>
45 public interface IGridUserData 50 public interface IGridUserData
46 { 51 {
47 GridUserData GetGridUserData(string userID); 52 GridUserData Get(string userID);
48 bool StoreGridUserData(GridUserData data); 53 bool Store(GridUserData data);
49 } 54 }
50} \ No newline at end of file 55} \ No newline at end of file
diff --git a/OpenSim/Data/IPresenceData.cs b/OpenSim/Data/IPresenceData.cs
index 71d0e31..b871f56 100644
--- a/OpenSim/Data/IPresenceData.cs
+++ b/OpenSim/Data/IPresenceData.cs
@@ -50,10 +50,8 @@ namespace OpenSim.Data
50 50
51 PresenceData Get(UUID sessionID); 51 PresenceData Get(UUID sessionID);
52 void LogoutRegionAgents(UUID regionID); 52 void LogoutRegionAgents(UUID regionID);
53 bool ReportAgent(UUID sessionID, UUID regionID, string position, string lookAt); 53 bool ReportAgent(UUID sessionID, UUID regionID);
54 bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt);
55 PresenceData[] Get(string field, string data); 54 PresenceData[] Get(string field, string data);
56 void Prune(string userID);
57 bool Delete(string field, string val); 55 bool Delete(string field, string val);
58 } 56 }
59} 57}
diff --git a/OpenSim/Data/MSSQL/MSSQLGridUserData.cs b/OpenSim/Data/MSSQL/MSSQLGridUserData.cs
index 9993720..1870273 100644
--- a/OpenSim/Data/MSSQL/MSSQLGridUserData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLGridUserData.cs
@@ -46,11 +46,11 @@ namespace OpenSim.Data.MSSQL
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 47
48 public MSSQLGridUserData(string connectionString, string realm) : 48 public MSSQLGridUserData(string connectionString, string realm) :
49 base(connectionString, realm, "UserGrid") 49 base(connectionString, realm, "GridUserStore")
50 { 50 {
51 } 51 }
52 52
53 public GridUserData GetGridUserData(string userID) 53 public GridUserData Get(string userID)
54 { 54 {
55 GridUserData[] ret = Get("UserID", userID); 55 GridUserData[] ret = Get("UserID", userID);
56 56
@@ -60,9 +60,5 @@ namespace OpenSim.Data.MSSQL
60 return ret[0]; 60 return ret[0];
61 } 61 }
62 62
63 public bool StoreGridUserData(GridUserData data)
64 {
65 return Store(data);
66 }
67 } 63 }
68} 64}
diff --git a/OpenSim/Data/MSSQL/MSSQLPresenceData.cs b/OpenSim/Data/MSSQL/MSSQLPresenceData.cs
index 5a4ad3a..e7b3d9c 100644
--- a/OpenSim/Data/MSSQL/MSSQLPresenceData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLPresenceData.cs
@@ -67,7 +67,7 @@ namespace OpenSim.Data.MSSQL
67 using (SqlCommand cmd = new SqlCommand()) 67 using (SqlCommand cmd = new SqlCommand())
68 { 68 {
69 69
70 cmd.CommandText = String.Format("UPDATE {0} SET Online='false' WHERE [RegionID]=@RegionID", m_Realm); 70 cmd.CommandText = String.Format("DELETE FROM {0} WHERE [RegionID]=@RegionID", m_Realm);
71 71
72 cmd.Parameters.Add(m_database.CreateParameter("@RegionID", regionID.ToString())); 72 cmd.Parameters.Add(m_database.CreateParameter("@RegionID", regionID.ToString()));
73 cmd.Connection = conn; 73 cmd.Connection = conn;
@@ -76,8 +76,7 @@ namespace OpenSim.Data.MSSQL
76 } 76 }
77 } 77 }
78 78
79 public bool ReportAgent(UUID sessionID, UUID regionID, string position, 79 public bool ReportAgent(UUID sessionID, UUID regionID)
80 string lookAt)
81 { 80 {
82 PresenceData[] pd = Get("SessionID", sessionID.ToString()); 81 PresenceData[] pd = Get("SessionID", sessionID.ToString());
83 if (pd.Length == 0) 82 if (pd.Length == 0)
@@ -88,16 +87,11 @@ namespace OpenSim.Data.MSSQL
88 { 87 {
89 88
90 cmd.CommandText = String.Format(@"UPDATE {0} SET 89 cmd.CommandText = String.Format(@"UPDATE {0} SET
91 [RegionID] = @RegionID, 90 [RegionID] = @RegionID
92 [Position] = @Position,
93 [LookAt] = @LookAt,
94 [Online] = 'true'
95 WHERE [SessionID] = @SessionID", m_Realm); 91 WHERE [SessionID] = @SessionID", m_Realm);
96 92
97 cmd.Parameters.Add(m_database.CreateParameter("@SessionID", sessionID.ToString())); 93 cmd.Parameters.Add(m_database.CreateParameter("@SessionID", sessionID.ToString()));
98 cmd.Parameters.Add(m_database.CreateParameter("@RegionID", regionID.ToString())); 94 cmd.Parameters.Add(m_database.CreateParameter("@RegionID", regionID.ToString()));
99 cmd.Parameters.Add(m_database.CreateParameter("@Position", position.ToString()));
100 cmd.Parameters.Add(m_database.CreateParameter("@LookAt", lookAt.ToString()));
101 cmd.Connection = conn; 95 cmd.Connection = conn;
102 conn.Open(); 96 conn.Open();
103 if (cmd.ExecuteNonQuery() == 0) 97 if (cmd.ExecuteNonQuery() == 0)
@@ -106,65 +100,5 @@ namespace OpenSim.Data.MSSQL
106 return true; 100 return true;
107 } 101 }
108 102
109 public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
110 {
111 PresenceData[] pd = Get("UserID", userID);
112 if (pd.Length == 0)
113 return false;
114
115 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
116 using (SqlCommand cmd = new SqlCommand())
117 {
118
119 cmd.CommandText = String.Format(@"UPDATE {0} SET
120 [HomeRegionID] = @HomeRegionID,
121 [HomePosition] = @HomePosition,
122 [HomeLookAt] = @HomeLookAt
123 WHERE [UserID] = @UserID", m_Realm);
124
125 cmd.Parameters.Add(m_database.CreateParameter("@UserID", userID));
126 cmd.Parameters.Add(m_database.CreateParameter("@HomeRegionID", regionID.ToString()));
127 cmd.Parameters.Add(m_database.CreateParameter("@HomePosition", position));
128 cmd.Parameters.Add(m_database.CreateParameter("@HomeLookAt", lookAt));
129 cmd.Connection = conn;
130 conn.Open();
131 if (cmd.ExecuteNonQuery() == 0)
132 return false;
133 }
134 return true;
135 }
136
137 public void Prune(string userID)
138 {
139 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
140 using (SqlCommand cmd = new SqlCommand())
141 {
142 cmd.CommandText = String.Format("SELECT * from {0} WHERE [UserID] = @UserID", m_Realm);
143
144 cmd.Parameters.Add(m_database.CreateParameter("@UserID", userID));
145 cmd.Connection = conn;
146 conn.Open();
147
148 using (SqlDataReader reader = cmd.ExecuteReader())
149 {
150 List<UUID> deleteSessions = new List<UUID>();
151 int online = 0;
152
153 while (reader.Read())
154 {
155 if (bool.Parse(reader["Online"].ToString()))
156 online++;
157 else
158 deleteSessions.Add(new UUID(reader["SessionID"].ToString()));
159 }
160
161 if (online == 0 && deleteSessions.Count > 0)
162 deleteSessions.RemoveAt(0);
163
164 foreach (UUID s in deleteSessions)
165 Delete("SessionID", s.ToString());
166 }
167 }
168 }
169 } 103 }
170} 104}
diff --git a/OpenSim/Data/MySQL/MySQLGridUserData.cs b/OpenSim/Data/MySQL/MySQLGridUserData.cs
index df29ecd..a9ce94d 100644
--- a/OpenSim/Data/MySQL/MySQLGridUserData.cs
+++ b/OpenSim/Data/MySQL/MySQLGridUserData.cs
@@ -44,9 +44,9 @@ namespace OpenSim.Data.MySQL
44 { 44 {
45// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 45// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 46
47 public MySQLGridUserData(string connectionString, string realm) : base(connectionString, realm, "UserGrid") {} 47 public MySQLGridUserData(string connectionString, string realm) : base(connectionString, realm, "GridUserStore") {}
48 48
49 public GridUserData GetGridUserData(string userID) 49 public GridUserData Get(string userID)
50 { 50 {
51 GridUserData[] ret = Get("UserID", userID); 51 GridUserData[] ret = Get("UserID", userID);
52 52
@@ -56,9 +56,6 @@ namespace OpenSim.Data.MySQL
56 return ret[0]; 56 return ret[0];
57 } 57 }
58 58
59 public bool StoreGridUserData(GridUserData data) 59
60 {
61 return Store(data);
62 }
63 } 60 }
64} \ No newline at end of file 61} \ No newline at end of file
diff --git a/OpenSim/Data/MySQL/MySQLPresenceData.cs b/OpenSim/Data/MySQL/MySQLPresenceData.cs
index 143dbe3..71caa1a 100644
--- a/OpenSim/Data/MySQL/MySQLPresenceData.cs
+++ b/OpenSim/Data/MySQL/MySQLPresenceData.cs
@@ -65,15 +65,14 @@ namespace OpenSim.Data.MySQL
65 { 65 {
66 MySqlCommand cmd = new MySqlCommand(); 66 MySqlCommand cmd = new MySqlCommand();
67 67
68 cmd.CommandText = String.Format("update {0} set Online='false' where `RegionID`=?RegionID", m_Realm); 68 cmd.CommandText = String.Format("delete from {0} where `RegionID`=?RegionID", m_Realm);
69 69
70 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); 70 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
71 71
72 ExecuteNonQuery(cmd); 72 ExecuteNonQuery(cmd);
73 } 73 }
74 74
75 public bool ReportAgent(UUID sessionID, UUID regionID, string position, 75 public bool ReportAgent(UUID sessionID, UUID regionID)
76 string lookAt)
77 { 76 {
78 PresenceData[] pd = Get("SessionID", sessionID.ToString()); 77 PresenceData[] pd = Get("SessionID", sessionID.ToString());
79 if (pd.Length == 0) 78 if (pd.Length == 0)
@@ -81,12 +80,10 @@ namespace OpenSim.Data.MySQL
81 80
82 MySqlCommand cmd = new MySqlCommand(); 81 MySqlCommand cmd = new MySqlCommand();
83 82
84 cmd.CommandText = String.Format("update {0} set RegionID=?RegionID, Position=?Position, LookAt=?LookAt, Online='true' where `SessionID`=?SessionID", m_Realm); 83 cmd.CommandText = String.Format("update {0} set RegionID=?RegionID where `SessionID`=?SessionID", m_Realm);
85 84
86 cmd.Parameters.AddWithValue("?SessionID", sessionID.ToString()); 85 cmd.Parameters.AddWithValue("?SessionID", sessionID.ToString());
87 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); 86 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
88 cmd.Parameters.AddWithValue("?Position", position.ToString());
89 cmd.Parameters.AddWithValue("?LookAt", lookAt.ToString());
90 87
91 if (ExecuteNonQuery(cmd) == 0) 88 if (ExecuteNonQuery(cmd) == 0)
92 return false; 89 return false;
@@ -94,62 +91,5 @@ namespace OpenSim.Data.MySQL
94 return true; 91 return true;
95 } 92 }
96 93
97 public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
98 {
99 PresenceData[] pd = Get("UserID", userID);
100 if (pd.Length == 0)
101 return false;
102
103 MySqlCommand cmd = new MySqlCommand();
104
105 cmd.CommandText = String.Format("update {0} set HomeRegionID=?HomeRegionID, HomePosition=?HomePosition, HomeLookAt=?HomeLookAt where UserID=?UserID", m_Realm);
106
107 cmd.Parameters.AddWithValue("?UserID", userID);
108 cmd.Parameters.AddWithValue("?HomeRegionID", regionID.ToString());
109 cmd.Parameters.AddWithValue("?HomePosition", position);
110 cmd.Parameters.AddWithValue("?HomeLookAt", lookAt);
111
112 if (ExecuteNonQuery(cmd) == 0)
113 return false;
114
115 return true;
116 }
117
118 public void Prune(string userID)
119 {
120 MySqlCommand cmd = new MySqlCommand();
121
122 cmd.CommandText = String.Format("select * from {0} where UserID=?UserID", m_Realm);
123
124 cmd.Parameters.AddWithValue("?UserID", userID);
125
126 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
127 {
128 dbcon.Open();
129
130 cmd.Connection = dbcon;
131
132 using (IDataReader reader = cmd.ExecuteReader())
133 {
134 List<UUID> deleteSessions = new List<UUID>();
135 int online = 0;
136
137 while (reader.Read())
138 {
139 if (bool.Parse(reader["Online"].ToString()))
140 online++;
141 else
142 deleteSessions.Add(new UUID(reader["SessionID"].ToString()));
143 }
144
145 // Leave one session behind so that we can pick up details such as home location
146 if (online == 0 && deleteSessions.Count > 0)
147 deleteSessions.RemoveAt(0);
148
149 foreach (UUID s in deleteSessions)
150 Delete("SessionID", s.ToString());
151 }
152 }
153 }
154 } 94 }
155} 95}
diff --git a/OpenSim/Data/MySQL/Resources/001_GridUserStore.sql b/OpenSim/Data/MySQL/Resources/001_GridUserStore.sql
new file mode 100644
index 0000000..ce4ab96
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/001_GridUserStore.sql
@@ -0,0 +1,17 @@
1BEGIN;
2
3CREATE TABLE `GridUser` (
4 `UserID` VARCHAR(255) NOT NULL,
5 `HomeRegionID` CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
6 `HomePosition` CHAR(64) NOT NULL DEFAULT '<0,0,0>',
7 `HomeLookAt` CHAR(64) NOT NULL DEFAULT '<0,0,0>',
8 `LastRegionID` CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
9 `LastPosition` CHAR(64) NOT NULL DEFAULT '<0,0,0>',
10 `LastLookAt` CHAR(64) NOT NULL DEFAULT '<0,0,0>',
11 `Online` CHAR(5) NOT NULL DEFAULT 'false',
12 `Login` CHAR(16) NOT NULL DEFAULT '0',
13 `Logout` CHAR(16) NOT NULL DEFAULT '0',
14 PRIMARY KEY (`UserID`)
15) ENGINE=InnoDB;
16
17COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/001_Presence.sql b/OpenSim/Data/MySQL/Resources/001_Presence.sql
index b8abaf7..84fa057 100644
--- a/OpenSim/Data/MySQL/Resources/001_Presence.sql
+++ b/OpenSim/Data/MySQL/Resources/001_Presence.sql
@@ -4,12 +4,10 @@ CREATE TABLE `Presence` (
4 `UserID` VARCHAR(255) NOT NULL, 4 `UserID` VARCHAR(255) NOT NULL,
5 `RegionID` CHAR(36) NOT NULL, 5 `RegionID` CHAR(36) NOT NULL,
6 `SessionID` CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', 6 `SessionID` CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
7 `SecureSessionID` CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', 7 `SecureSessionID` CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'
8 `Online` CHAR(5) NOT NULL DEFAULT 'false',
9 `Login` CHAR(16) NOT NULL DEFAULT '0',
10 `Logout` CHAR(16) NOT NULL DEFAULT '0',
11 `Position` CHAR(64) NOT NULL DEFAULT '<0,0,0>',
12 `LookAt` CHAR(64) NOT NULL DEFAULT '<0,0,0>'
13) ENGINE=InnoDB; 8) ENGINE=InnoDB;
14 9
10CREATE UNIQUE INDEX SessionID ON Presence(SessionID);
11CREATE INDEX UserID ON Presence(UserID);
12
15COMMIT; 13COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/002_Presence.sql b/OpenSim/Data/MySQL/Resources/002_Presence.sql
deleted file mode 100644
index e65f105..0000000
--- a/OpenSim/Data/MySQL/Resources/002_Presence.sql
+++ /dev/null
@@ -1,7 +0,0 @@
1BEGIN;
2
3ALTER TABLE Presence ADD COLUMN `HomeRegionID` CHAR(36) NOT NULL;
4ALTER TABLE Presence ADD COLUMN `HomePosition` CHAR(64) NOT NULL DEFAULT '<0,0,0>';
5ALTER TABLE Presence ADD COLUMN `HomeLookAt` CHAR(64) NOT NULL DEFAULT '<0,0,0>';
6
7COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/003_Presence.sql b/OpenSim/Data/MySQL/Resources/003_Presence.sql
deleted file mode 100644
index 0efefa8..0000000
--- a/OpenSim/Data/MySQL/Resources/003_Presence.sql
+++ /dev/null
@@ -1,6 +0,0 @@
1BEGIN;
2
3CREATE UNIQUE INDEX SessionID ON Presence(SessionID);
4CREATE INDEX UserID ON Presence(UserID);
5
6COMMIT;
diff --git a/OpenSim/Data/Null/NullPresenceData.cs b/OpenSim/Data/Null/NullPresenceData.cs
index b98b5c9..91f1cc5 100644
--- a/OpenSim/Data/Null/NullPresenceData.cs
+++ b/OpenSim/Data/Null/NullPresenceData.cs
@@ -96,45 +96,20 @@ namespace OpenSim.Data.Null
96 m_presenceData.Remove(u); 96 m_presenceData.Remove(u);
97 } 97 }
98 98
99 public bool ReportAgent(UUID sessionID, UUID regionID, string position, string lookAt) 99 public bool ReportAgent(UUID sessionID, UUID regionID)
100 { 100 {
101 if (Instance != this) 101 if (Instance != this)
102 return Instance.ReportAgent(sessionID, regionID, position, lookAt); 102 return Instance.ReportAgent(sessionID, regionID);
103 103
104 if (m_presenceData.ContainsKey(sessionID)) 104 if (m_presenceData.ContainsKey(sessionID))
105 { 105 {
106 m_presenceData[sessionID].RegionID = regionID; 106 m_presenceData[sessionID].RegionID = regionID;
107 m_presenceData[sessionID].Data["Position"] = position;
108 m_presenceData[sessionID].Data["LookAt"] = lookAt;
109 return true; 107 return true;
110 } 108 }
111 109
112 return false; 110 return false;
113 } 111 }
114 112
115 public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
116 {
117 if (Instance != this)
118 return Instance.SetHomeLocation(userID, regionID, position, lookAt);
119
120 bool foundone = false;
121 foreach (PresenceData p in m_presenceData.Values)
122 {
123 if (p.UserID == userID)
124 {
125// m_log.DebugFormat(
126// "[NULL PRESENCE DATA]: Setting home location {0} {1} {2} for {3}",
127// regionID, position, lookAt, p.UserID);
128
129 p.Data["HomeRegionID"] = regionID.ToString();
130 p.Data["HomePosition"] = position.ToString();
131 p.Data["HomeLookAt"] = lookAt.ToString();
132 foundone = true;
133 }
134 }
135
136 return foundone;
137 }
138 113
139 public PresenceData[] Get(string field, string data) 114 public PresenceData[] Get(string field, string data)
140 { 115 {
@@ -193,39 +168,6 @@ namespace OpenSim.Data.Null
193 return presences.ToArray(); 168 return presences.ToArray();
194 } 169 }
195 170
196 public void Prune(string userID)
197 {
198 if (Instance != this)
199 {
200 Instance.Prune(userID);
201 return;
202 }
203
204// m_log.DebugFormat("[NULL PRESENCE DATA]: Prune called for {0}", userID);
205
206 List<UUID> deleteSessions = new List<UUID>();
207 int online = 0;
208
209 foreach (KeyValuePair<UUID, PresenceData> kvp in m_presenceData)
210 {
211// m_log.DebugFormat("Online: {0}", kvp.Value.Data["Online"]);
212
213 bool on = false;
214 if (bool.TryParse(kvp.Value.Data["Online"], out on) && on)
215 online++;
216 else
217 deleteSessions.Add(kvp.Key);
218 }
219
220// m_log.DebugFormat("[NULL PRESENCE DATA]: online [{0}], deleteSession.Count [{1}]", online, deleteSessions.Count);
221
222 // Leave one session behind so that we can pick up details such as home location
223 if (online == 0 && deleteSessions.Count > 0)
224 deleteSessions.RemoveAt(0);
225
226 foreach (UUID s in deleteSessions)
227 m_presenceData.Remove(s);
228 }
229 171
230 public bool Delete(string field, string data) 172 public bool Delete(string field, string data)
231 { 173 {
diff --git a/OpenSim/Data/SQLite/Resources/001_GridUserStore.sql b/OpenSim/Data/SQLite/Resources/001_GridUserStore.sql
new file mode 100644
index 0000000..1a24613
--- /dev/null
+++ b/OpenSim/Data/SQLite/Resources/001_GridUserStore.sql
@@ -0,0 +1,16 @@
1BEGIN TRANSACTION;
2
3CREATE TABLE GridUser (
4 UserID VARCHAR(255) primary key,
5 HomeRegionID CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
6 HomePosition CHAR(64) NOT NULL DEFAULT '<0,0,0>',
7 HomeLookAt CHAR(64) NOT NULL DEFAULT '<0,0,0>',
8 LastRegionID CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
9 LastPosition CHAR(64) NOT NULL DEFAULT '<0,0,0>',
10 LastLookAt CHAR(64) NOT NULL DEFAULT '<0,0,0>',
11 Online CHAR(5) NOT NULL DEFAULT 'false',
12 Login CHAR(16) NOT NULL DEFAULT '0',
13 Logout CHAR(16) NOT NULL DEFAULT '0'
14) ;
15
16COMMIT;
diff --git a/OpenSim/Data/SQLite/SQLiteGridUserData.cs b/OpenSim/Data/SQLite/SQLiteGridUserData.cs
new file mode 100644
index 0000000..1bb5ed8
--- /dev/null
+++ b/OpenSim/Data/SQLite/SQLiteGridUserData.cs
@@ -0,0 +1,61 @@
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
28using System;
29using System.Collections.Generic;
30using System.Data;
31using System.Reflection;
32using System.Threading;
33using log4net;
34using OpenMetaverse;
35using OpenSim.Framework;
36
37namespace OpenSim.Data.SQLite
38{
39 /// <summary>
40 /// A SQL Interface for user grid data
41 /// </summary>
42 public class SQLiteGridUserData : SQLiteGenericTableHandler<GridUserData>, IGridUserData
43 {
44// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45
46 public SQLiteGridUserData(string connectionString, string realm)
47 : base(connectionString, realm, "GridUserStore") {}
48
49 public new GridUserData Get(string userID)
50 {
51 GridUserData[] ret = Get("UserID", userID);
52
53 if (ret.Length == 0)
54 return null;
55
56 return ret[0];
57 }
58
59
60 }
61} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
index f2b03e4..ef37f63 100644
--- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
@@ -526,11 +526,12 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
526 { 526 {
527 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Request to teleport {0} {1} home", client.FirstName, client.LastName); 527 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Request to teleport {0} {1} home", client.FirstName, client.LastName);
528 528
529 OpenSim.Services.Interfaces.PresenceInfo pinfo = m_aScene.PresenceService.GetAgent(client.SessionId); 529 //OpenSim.Services.Interfaces.PresenceInfo pinfo = m_aScene.PresenceService.GetAgent(client.SessionId);
530 GridUserInfo uinfo = m_aScene.GridUserService.GetGridUserInfo(client.AgentId.ToString());
530 531
531 if (pinfo != null) 532 if (uinfo != null)
532 { 533 {
533 GridRegion regionInfo = m_aScene.GridService.GetRegionByUUID(UUID.Zero, pinfo.HomeRegionID); 534 GridRegion regionInfo = m_aScene.GridService.GetRegionByUUID(UUID.Zero, uinfo.HomeRegionID);
534 if (regionInfo == null) 535 if (regionInfo == null)
535 { 536 {
536 // can't find the Home region: Tell viewer and abort 537 // can't find the Home region: Tell viewer and abort
@@ -539,7 +540,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
539 } 540 }
540 // a little eekie that this goes back to Scene and with a forced cast, will fix that at some point... 541 // a little eekie that this goes back to Scene and with a forced cast, will fix that at some point...
541 ((Scene)(client.Scene)).RequestTeleportLocation( 542 ((Scene)(client.Scene)).RequestTeleportLocation(
542 client, regionInfo.RegionHandle, pinfo.HomePosition, pinfo.HomeLookAt, 543 client, regionInfo.RegionHandle, uinfo.HomePosition, uinfo.HomeLookAt,
543 (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome)); 544 (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome));
544 } 545 }
545 } 546 }
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
index 28593fc..137dfec 100644
--- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
@@ -154,7 +154,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
154 bool success = connector.LoginAgentToGrid(agentCircuit, reg, finalDestination, out reason); 154 bool success = connector.LoginAgentToGrid(agentCircuit, reg, finalDestination, out reason);
155 if (success) 155 if (success)
156 // Log them out of this grid 156 // Log them out of this grid
157 m_aScene.PresenceService.LogoutAgent(agentCircuit.SessionID, sp.AbsolutePosition, sp.Lookat); 157 m_aScene.PresenceService.LogoutAgent(agentCircuit.SessionID);
158 158
159 return success; 159 return success;
160 } 160 }
@@ -238,6 +238,13 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
238 { 238 {
239 if (obj.IsLoggingOut) 239 if (obj.IsLoggingOut)
240 { 240 {
241 object sp = null;
242 if (obj.Scene.TryGetScenePresence(obj.AgentId, out sp))
243 {
244 if (((ScenePresence)sp).IsChildAgent)
245 return;
246 }
247
241 AgentCircuitData aCircuit = ((Scene)(obj.Scene)).AuthenticateHandler.GetAgentCircuitData(obj.CircuitCode); 248 AgentCircuitData aCircuit = ((Scene)(obj.Scene)).AuthenticateHandler.GetAgentCircuitData(obj.CircuitCode);
242 249
243 if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) 250 if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
diff --git a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml
index 0a5ff3f..ee07075 100644
--- a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml
+++ b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml
@@ -59,9 +59,11 @@
59 <RegionModule id="RemoteUserAccountServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts.RemoteUserAccountServicesConnector" /> 59 <RegionModule id="RemoteUserAccountServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts.RemoteUserAccountServicesConnector" />
60 60
61 <RegionModule id="LocalGridUserServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser.LocalGridUserServicesConnector" /> 61 <RegionModule id="LocalGridUserServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser.LocalGridUserServicesConnector" />
62 62 <RegionModule id="RemoteGridUserServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser.RemoteGridUserServicesConnector" />
63
63 <RegionModule id="LocalSimulationConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation.LocalSimulationConnectorModule" /> 64 <RegionModule id="LocalSimulationConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation.LocalSimulationConnectorModule" />
64 <RegionModule id="RemoteSimulationConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation.RemoteSimulationConnectorModule" /> 65 <RegionModule id="RemoteSimulationConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation.RemoteSimulationConnectorModule" />
66
65 <!-- Service connectors IN modules --> 67 <!-- Service connectors IN modules -->
66 <RegionModule id="AssetServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Asset.AssetServiceInConnectorModule" /> 68 <RegionModule id="AssetServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Asset.AssetServiceInConnectorModule" />
67 <RegionModule id="InventoryServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Inventory.InventoryServiceInConnectorModule" /> 69 <RegionModule id="InventoryServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Inventory.InventoryServiceInConnectorModule" />
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs
new file mode 100644
index 0000000..6c01927
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs
@@ -0,0 +1,116 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Reflection;
30
31using OpenSim.Framework;
32using OpenSim.Region.Framework.Scenes;
33using OpenSim.Services.Interfaces;
34
35using OpenMetaverse;
36using log4net;
37
38namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser
39{
40 public class ActivityDetector
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
44 private IGridUserService m_GridUserService;
45 private Scene m_aScene;
46
47 public ActivityDetector(IGridUserService guservice)
48 {
49 m_GridUserService = guservice;
50 m_log.DebugFormat("[ACTIVITY DETECTOR]: starting ");
51 }
52
53 public void AddRegion(Scene scene)
54 {
55 // For now the only events we listen to are these
56 // But we could trigger the position update more often
57 scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
58 scene.EventManager.OnNewClient += OnNewClient;
59 scene.EventManager.OnAvatarEnteringNewParcel += OnEnteringNewParcel;
60
61 if (m_aScene == null)
62 m_aScene = scene;
63 }
64
65 public void RemoveRegion(Scene scene)
66 {
67 scene.EventManager.OnMakeRootAgent -= OnMakeRootAgent;
68 scene.EventManager.OnNewClient -= OnNewClient;
69 }
70
71 public void OnMakeRootAgent(ScenePresence sp)
72 {
73 m_log.DebugFormat("[ACTIVITY DETECTOR]: Detected root presence {0} in {1}", sp.UUID, sp.Scene.RegionInfo.RegionName);
74
75 m_GridUserService.SetLastPosition(sp.UUID.ToString(), sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
76 }
77
78 public void OnNewClient(IClientAPI client)
79 {
80 client.OnConnectionClosed += OnConnectionClose;
81 }
82
83 public void OnConnectionClose(IClientAPI client)
84 {
85 if (client.IsLoggingOut)
86 {
87 object sp = null;
88 Vector3 position = new Vector3(128, 128, 0);
89 Vector3 lookat = new Vector3(0, 1, 0);
90
91 if (client.Scene.TryGetScenePresence(client.AgentId, out sp))
92 {
93 if (sp is ScenePresence)
94 {
95 if (((ScenePresence)sp).IsChildAgent)
96 return;
97
98 position = ((ScenePresence)sp).AbsolutePosition;
99 lookat = ((ScenePresence)sp).Lookat;
100 }
101 }
102 m_log.DebugFormat("[ACTIVITY DETECTOR]: Detected client logout {0} in {1}", client.AgentId, client.Scene.RegionInfo.RegionName);
103 m_GridUserService.LoggedOut(client.AgentId.ToString(), client.Scene.RegionInfo.RegionID, position, lookat);
104 }
105
106 }
107
108 void OnEnteringNewParcel(ScenePresence sp, int localLandID, UUID regionID)
109 {
110 // TODO: grab the parcel ID from ILandModule
111 // and send that along
112 m_GridUserService.SetLastPosition(sp.UUID.ToString(), sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
113 }
114
115 }
116}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/LocalGridUserServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/LocalGridUserServiceConnector.cs
index d5fae23..d914a57 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/LocalGridUserServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/LocalGridUserServiceConnector.cs
@@ -41,13 +41,19 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser
41{ 41{
42 public class LocalGridUserServicesConnector : ISharedRegionModule, IGridUserService 42 public class LocalGridUserServicesConnector : ISharedRegionModule, IGridUserService
43 { 43 {
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 44 private static readonly ILog m_log =
45 LogManager.GetLogger(
46 MethodBase.GetCurrentMethod().DeclaringType);
45 47
46 private IGridUserService m_service; 48 private IGridUserService m_GridUserService;
49
50 private ActivityDetector m_ActivityDetector;
47 51
48 private bool m_Enabled = false; 52 private bool m_Enabled = false;
49 53
50 public Type ReplaceableInterface 54 #region ISharedRegionModule
55
56 public Type ReplaceableInterface
51 { 57 {
52 get { return null; } 58 get { return null; }
53 } 59 }
@@ -68,7 +74,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser
68 IConfig userConfig = source.Configs["GridUserService"]; 74 IConfig userConfig = source.Configs["GridUserService"];
69 if (userConfig == null) 75 if (userConfig == null)
70 { 76 {
71 m_log.Error("[LOCAL GRID USER SERVICE CONNECTOR]: GridUserService missing from ini files"); 77 m_log.Error("[LOCAL GRID USER SERVICE CONNECTOR]: GridUserService missing from OpenSim.ini");
72 return; 78 return;
73 } 79 }
74 80
@@ -81,15 +87,20 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser
81 } 87 }
82 88
83 Object[] args = new Object[] { source }; 89 Object[] args = new Object[] { source };
84 m_service = ServerUtils.LoadPlugin<IGridUserService>(serviceDll, args); 90 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(serviceDll, args);
85 91
86 if (m_service == null) 92 if (m_GridUserService == null)
87 { 93 {
88 m_log.Error("[LOCAL GRID USER SERVICE CONNECTOR]: Can't load GridUser service"); 94 m_log.ErrorFormat(
95 "[LOCAL GRID USER SERVICE CONNECTOR]: Cannot load user account service specified as {0}", serviceDll);
89 return; 96 return;
90 } 97 }
98
99 m_ActivityDetector = new ActivityDetector(this);
100
91 m_Enabled = true; 101 m_Enabled = true;
92 m_log.Info("[LOCAL GRID USER SERVICE CONNECTOR]: Local GridUser connector enabled"); 102
103 m_log.Info("[LOCAL GRID USER SERVICE CONNECTOR]: Local grid user connector enabled");
93 } 104 }
94 } 105 }
95 } 106 }
@@ -111,29 +122,57 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser
111 if (!m_Enabled) 122 if (!m_Enabled)
112 return; 123 return;
113 124
114 scene.RegisterModuleInterface<IGridUserService>(m_service); 125 scene.RegisterModuleInterface<IGridUserService>(m_GridUserService);
126 m_ActivityDetector.AddRegion(scene);
115 } 127 }
116 128
117 public void RemoveRegion(Scene scene) 129 public void RemoveRegion(Scene scene)
118 { 130 {
119 if (!m_Enabled) 131 if (!m_Enabled)
120 return; 132 return;
133
134 scene.UnregisterModuleInterface<IGridUserService>(this);
135 m_ActivityDetector.RemoveRegion(scene);
121 } 136 }
122 137
123 public void RegionLoaded(Scene scene) 138 public void RegionLoaded(Scene scene)
124 { 139 {
125 if (!m_Enabled) 140 if (!m_Enabled)
126 return; 141 return;
142
143 m_log.InfoFormat("[LOCAL GRID USER SERVICE CONNECTOR]: Enabled local grid user for region {0}", scene.RegionInfo.RegionName);
127 } 144 }
128 145
129 public GridUserInfo GetGridUserInfo(string userID) 146 #endregion
147
148 #region IGridUserService
149
150 public GridUserInfo LoggedIn(string userID)
130 { 151 {
131 return m_service.GetGridUserInfo(userID); 152 return m_GridUserService.LoggedIn(userID);
132 } 153 }
133 154
134 public bool StoreGridUserInfo(GridUserInfo info) 155 public bool LoggedOut(string userID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
135 { 156 {
136 return m_service.StoreGridUserInfo(info); 157 return m_GridUserService.LoggedOut(userID, regionID, lastPosition, lastLookAt);
137 } 158 }
159
160 public bool SetHome(string userID, UUID homeID, Vector3 homePosition, Vector3 homeLookAt)
161 {
162 return m_GridUserService.SetHome(userID, homeID, homePosition, homeLookAt);
163 }
164
165 public bool SetLastPosition(string userID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
166 {
167 return m_GridUserService.SetLastPosition(userID, regionID, lastPosition, lastLookAt);
168 }
169
170 public GridUserInfo GetGridUserInfo(string userID)
171 {
172 return m_GridUserService.GetGridUserInfo(userID);
173 }
174
175 #endregion
176
138 } 177 }
139} \ No newline at end of file 178}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/RemoteGridUserServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/RemoteGridUserServiceConnector.cs
new file mode 100644
index 0000000..e3e2e61
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/RemoteGridUserServiceConnector.cs
@@ -0,0 +1,153 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Reflection;
30
31using OpenSim.Region.Framework.Interfaces;
32using OpenSim.Region.Framework.Scenes;
33using OpenSim.Server.Base;
34using OpenSim.Services.Interfaces;
35using OpenSim.Services.Connectors;
36
37using OpenMetaverse;
38using log4net;
39using Nini.Config;
40
41namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser
42{
43 public class RemoteGridUserServicesConnector : ISharedRegionModule, IGridUserService
44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46
47 #region ISharedRegionModule
48
49 private bool m_Enabled = false;
50
51 private ActivityDetector m_ActivityDetector;
52 private IGridUserService m_RemoteConnector;
53
54 public Type ReplaceableInterface
55 {
56 get { return null; }
57 }
58
59 public string Name
60 {
61 get { return "RemoteGridUserServicesConnector"; }
62 }
63
64 public void Initialise(IConfigSource source)
65 {
66 IConfig moduleConfig = source.Configs["Modules"];
67 if (moduleConfig != null)
68 {
69 string name = moduleConfig.GetString("GridUserServices", "");
70 if (name == Name)
71 {
72 m_RemoteConnector = new GridUserServicesConnector(source);
73
74 m_Enabled = true;
75
76 m_ActivityDetector = new ActivityDetector(this);
77
78 m_log.Info("[REMOTE GRID USER CONNECTOR]: Remote grid user enabled");
79 }
80 }
81
82 }
83
84 public void PostInitialise()
85 {
86 }
87
88 public void Close()
89 {
90 }
91
92 public void AddRegion(Scene scene)
93 {
94 if (!m_Enabled)
95 return;
96
97 scene.RegisterModuleInterface<IGridUserService>(this);
98 m_ActivityDetector.AddRegion(scene);
99
100 m_log.InfoFormat("[REMOTE GRID USER CONNECTOR]: Enabled remote grid user for region {0}", scene.RegionInfo.RegionName);
101
102 }
103
104 public void RemoveRegion(Scene scene)
105 {
106 if (!m_Enabled)
107 return;
108
109 m_ActivityDetector.RemoveRegion(scene);
110 }
111
112 public void RegionLoaded(Scene scene)
113 {
114 if (!m_Enabled)
115 return;
116
117 }
118
119 #endregion
120
121 #region IGridUserService
122
123 public GridUserInfo LoggedIn(string userID)
124 {
125 m_log.Warn("[REMOTE GRID USER CONNECTOR]: LoggedIn not implemented at the simulators");
126 return null;
127 }
128
129 public bool LoggedOut(string userID, UUID region, Vector3 position, Vector3 lookat)
130 {
131 return m_RemoteConnector.LoggedOut(userID, region, position, lookat);
132 }
133
134
135 public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
136 {
137 return m_RemoteConnector.SetHome(userID, regionID, position, lookAt);
138 }
139
140 public bool SetLastPosition(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
141 {
142 return m_RemoteConnector.SetLastPosition(userID, regionID, position, lookAt);
143 }
144
145 public GridUserInfo GetGridUserInfo(string userID)
146 {
147 return m_RemoteConnector.GetGridUserInfo(userID);
148 }
149
150 #endregion
151
152 }
153}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs
index c402a3f..49dd633 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs
@@ -167,9 +167,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
167 return false; 167 return false;
168 } 168 }
169 169
170 public bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookat) 170 public bool LogoutAgent(UUID sessionID)
171 { 171 {
172 return m_PresenceService.LogoutAgent(sessionID, position, lookat); 172 return m_PresenceService.LogoutAgent(sessionID);
173 } 173 }
174 174
175 175
@@ -178,9 +178,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
178 return m_PresenceService.LogoutRegionAgents(regionID); 178 return m_PresenceService.LogoutRegionAgents(regionID);
179 } 179 }
180 180
181 public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) 181 public bool ReportAgent(UUID sessionID, UUID regionID)
182 { 182 {
183 return m_PresenceService.ReportAgent(sessionID, regionID, position, lookAt); 183 return m_PresenceService.ReportAgent(sessionID, regionID);
184 } 184 }
185 185
186 public PresenceInfo GetAgent(UUID sessionID) 186 public PresenceInfo GetAgent(UUID sessionID)
@@ -193,11 +193,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
193 return m_PresenceService.GetAgents(userIDs); 193 return m_PresenceService.GetAgents(userIDs);
194 } 194 }
195 195
196 public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
197 {
198 return m_PresenceService.SetHomeLocation(userID, regionID, position, lookAt);
199 }
200
201 #endregion 196 #endregion
202 197
203 } 198 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs
index 7a75a89..62b8278 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs
@@ -72,7 +72,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
72 public void OnMakeRootAgent(ScenePresence sp) 72 public void OnMakeRootAgent(ScenePresence sp)
73 { 73 {
74 m_log.DebugFormat("[PRESENCE DETECTOR]: Detected root presence {0} in {1}", sp.UUID, sp.Scene.RegionInfo.RegionName); 74 m_log.DebugFormat("[PRESENCE DETECTOR]: Detected root presence {0} in {1}", sp.UUID, sp.Scene.RegionInfo.RegionName);
75 m_PresenceService.ReportAgent(sp.ControllingClient.SessionId, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat); 75 m_PresenceService.ReportAgent(sp.ControllingClient.SessionId, sp.Scene.RegionInfo.RegionID);
76 } 76 }
77 77
78 public void OnNewClient(IClientAPI client) 78 public void OnNewClient(IClientAPI client)
@@ -85,19 +85,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
85 if (client.IsLoggingOut) 85 if (client.IsLoggingOut)
86 { 86 {
87 object sp = null; 87 object sp = null;
88 Vector3 position = new Vector3(128, 128, 0);
89 Vector3 lookat = new Vector3(0, 1, 0);
90
91 if (client.Scene.TryGetScenePresence(client.AgentId, out sp)) 88 if (client.Scene.TryGetScenePresence(client.AgentId, out sp))
92 { 89 {
93 if (sp is ScenePresence) 90 if (sp is ScenePresence)
94 { 91 {
95 position = ((ScenePresence)sp).AbsolutePosition; 92 if (((ScenePresence)sp).IsChildAgent)
96 lookat = ((ScenePresence)sp).Lookat; 93 return;
97 } 94 }
98 } 95 }
99 96
100 m_PresenceService.LogoutAgent(client.SessionId, position, lookat); 97 m_log.DebugFormat("[PRESENCE DETECTOR]: Detected client logout {0} in {1}", client.AgentId, client.Scene.RegionInfo.RegionName);
98 m_PresenceService.LogoutAgent(client.SessionId);
101 } 99 }
102 100
103 } 101 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs
index 5f3666e..bf4e9ab 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs
@@ -127,9 +127,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
127 return false; 127 return false;
128 } 128 }
129 129
130 public bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookat) 130 public bool LogoutAgent(UUID sessionID)
131 { 131 {
132 return m_RemoteConnector.LogoutAgent(sessionID, position, lookat); 132 return m_RemoteConnector.LogoutAgent(sessionID);
133 } 133 }
134 134
135 135
@@ -138,9 +138,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
138 return m_RemoteConnector.LogoutRegionAgents(regionID); 138 return m_RemoteConnector.LogoutRegionAgents(regionID);
139 } 139 }
140 140
141 public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) 141 public bool ReportAgent(UUID sessionID, UUID regionID)
142 { 142 {
143 return m_RemoteConnector.ReportAgent(sessionID, regionID, position, lookAt); 143 return m_RemoteConnector.ReportAgent(sessionID, regionID);
144 } 144 }
145 145
146 public PresenceInfo GetAgent(UUID sessionID) 146 public PresenceInfo GetAgent(UUID sessionID)
@@ -153,11 +153,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
153 return m_RemoteConnector.GetAgents(userIDs); 153 return m_RemoteConnector.GetAgents(userIDs);
154 } 154 }
155 155
156 public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
157 {
158 return m_RemoteConnector.SetHomeLocation(userID, regionID, position, lookAt);
159 }
160
161 #endregion 156 #endregion
162 157
163 } 158 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs
index 63a28fc..ef910f4 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs
@@ -90,27 +90,25 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence.Tests
90 PresenceInfo result = m_LocalConnector.GetAgent(session1); 90 PresenceInfo result = m_LocalConnector.GetAgent(session1);
91 Assert.IsNotNull(result, "Retrieved GetAgent is null"); 91 Assert.IsNotNull(result, "Retrieved GetAgent is null");
92 Assert.That(result.UserID, Is.EqualTo(user1), "Retrieved userID does not match"); 92 Assert.That(result.UserID, Is.EqualTo(user1), "Retrieved userID does not match");
93 Assert.IsTrue(result.Online, "Agent just logged in but is offline");
94 93
95 UUID region1 = UUID.Random(); 94 UUID region1 = UUID.Random();
96 bool r = m_LocalConnector.ReportAgent(session1, region1, Vector3.Zero, Vector3.Zero); 95 bool r = m_LocalConnector.ReportAgent(session1, region1);
97 Assert.IsTrue(r, "First ReportAgent returned false"); 96 Assert.IsTrue(r, "First ReportAgent returned false");
98 result = m_LocalConnector.GetAgent(session1); 97 result = m_LocalConnector.GetAgent(session1);
99 Assert.That(result.RegionID, Is.EqualTo(region1), "Agent is not in the right region (region1)"); 98 Assert.That(result.RegionID, Is.EqualTo(region1), "Agent is not in the right region (region1)");
100 99
101 UUID region2 = UUID.Random(); 100 UUID region2 = UUID.Random();
102 r = m_LocalConnector.ReportAgent(session1, region2, Vector3.Zero, Vector3.Zero); 101 r = m_LocalConnector.ReportAgent(session1, region2);
103 Assert.IsTrue(r, "Second ReportAgent returned false"); 102 Assert.IsTrue(r, "Second ReportAgent returned false");
104 result = m_LocalConnector.GetAgent(session1); 103 result = m_LocalConnector.GetAgent(session1);
105 Assert.That(result.RegionID, Is.EqualTo(region2), "Agent is not in the right region (region2)"); 104 Assert.That(result.RegionID, Is.EqualTo(region2), "Agent is not in the right region (region2)");
106 105
107 r = m_LocalConnector.LogoutAgent(session1, Vector3.Zero, Vector3.UnitY); 106 r = m_LocalConnector.LogoutAgent(session1);
108 Assert.IsTrue(r, "LogoutAgent returned false"); 107 Assert.IsTrue(r, "LogoutAgent returned false");
109 result = m_LocalConnector.GetAgent(session1); 108 result = m_LocalConnector.GetAgent(session1);
110 Assert.IsNotNull(result, "Agent session disappeared from storage after logout"); 109 Assert.IsNull(result, "Agent session is still stored after logout");
111 Assert.IsFalse(result.Online, "Agent is reported to be Online after logout");
112 110
113 r = m_LocalConnector.ReportAgent(session1, region1, Vector3.Zero, Vector3.Zero); 111 r = m_LocalConnector.ReportAgent(session1, region1);
114 Assert.IsFalse(r, "ReportAgent of non-logged in user returned true"); 112 Assert.IsFalse(r, "ReportAgent of non-logged in user returned true");
115 } 113 }
116 } 114 }
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 0ca5948..2197ced 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -318,7 +318,18 @@ namespace OpenSim.Region.Framework.Scenes
318 return m_AvatarService; 318 return m_AvatarService;
319 } 319 }
320 } 320 }
321 321
322 protected IGridUserService m_GridUserService;
323 public IGridUserService GridUserService
324 {
325 get
326 {
327 if (m_GridUserService == null)
328 m_GridUserService = RequestModuleInterface<IGridUserService>();
329 return m_GridUserService;
330 }
331 }
332
322 protected IXMLRPC m_xmlrpcModule; 333 protected IXMLRPC m_xmlrpcModule;
323 protected IWorldComm m_worldCommModule; 334 protected IWorldComm m_worldCommModule;
324 public IAttachmentsModule AttachmentsModule { get; set; } 335 public IAttachmentsModule AttachmentsModule { get; set; }
@@ -1334,8 +1345,8 @@ namespace OpenSim.Region.Framework.Scenes
1334 if (defaultRegions != null && defaultRegions.Count >= 1) 1345 if (defaultRegions != null && defaultRegions.Count >= 1)
1335 home = defaultRegions[0]; 1346 home = defaultRegions[0];
1336 1347
1337 if (PresenceService != null && home != null) 1348 if (GridUserService != null && home != null)
1338 PresenceService.SetHomeLocation(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); 1349 GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
1339 else 1350 else
1340 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.", 1351 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.",
1341 first, last); 1352 first, last);
@@ -3123,7 +3134,7 @@ namespace OpenSim.Region.Framework.Scenes
3123 /// <param name="flags"></param> 3134 /// <param name="flags"></param>
3124 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) 3135 public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
3125 { 3136 {
3126 if (PresenceService.SetHomeLocation(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) 3137 if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt))
3127 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. 3138 // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
3128 m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); 3139 m_dialogModule.SendAlertToUser(remoteClient, "Home position set.");
3129 else 3140 else
@@ -3577,7 +3588,7 @@ namespace OpenSim.Region.Framework.Scenes
3577 3588
3578 OpenSim.Services.Interfaces.PresenceInfo pinfo = presence.GetAgent(agent.SessionID); 3589 OpenSim.Services.Interfaces.PresenceInfo pinfo = presence.GetAgent(agent.SessionID);
3579 3590
3580 if (pinfo == null || (pinfo != null && pinfo.Online == false)) 3591 if (pinfo == null)
3581 { 3592 {
3582 reason = String.Format("Failed to verify user {0} {1}, access denied to region {2}.", agent.firstname, agent.lastname, RegionInfo.RegionName); 3593 reason = String.Format("Failed to verify user {0} {1}, access denied to region {2}.", agent.firstname, agent.lastname, RegionInfo.RegionName);
3583 return false; 3594 return false;
diff --git a/OpenSim/Region/Physics/Meshing/PrimMesher.cs b/OpenSim/Region/Physics/Meshing/PrimMesher.cs
index 932943c..53022ad 100644
--- a/OpenSim/Region/Physics/Meshing/PrimMesher.cs
+++ b/OpenSim/Region/Physics/Meshing/PrimMesher.cs
@@ -257,7 +257,6 @@ namespace PrimMesher
257 public int uv2; 257 public int uv2;
258 public int uv3; 258 public int uv3;
259 259
260
261 public Face(int v1, int v2, int v3) 260 public Face(int v1, int v2, int v3)
262 { 261 {
263 primFace = 0; 262 primFace = 0;
@@ -630,6 +629,9 @@ namespace PrimMesher
630 internal int numOuterVerts = 0; 629 internal int numOuterVerts = 0;
631 internal int numHollowVerts = 0; 630 internal int numHollowVerts = 0;
632 631
632 internal int outerFaceNumber = -1;
633 internal int hollowFaceNumber = -1;
634
633 internal bool calcVertexNormals = false; 635 internal bool calcVertexNormals = false;
634 internal int bottomFaceNumber = 0; 636 internal int bottomFaceNumber = 0;
635 internal int numPrimFaces = 0; 637 internal int numPrimFaces = 0;
@@ -936,10 +938,10 @@ namespace PrimMesher
936 938
937 if (calcVertexNormals && hasProfileCut) 939 if (calcVertexNormals && hasProfileCut)
938 { 940 {
941 int lastOuterVertIndex = this.numOuterVerts - 1;
942
939 if (hasHollow) 943 if (hasHollow)
940 { 944 {
941 int lastOuterVertIndex = this.numOuterVerts - 1;
942
943 this.cut1CoordIndices.Add(0); 945 this.cut1CoordIndices.Add(0);
944 this.cut1CoordIndices.Add(this.coords.Count - 1); 946 this.cut1CoordIndices.Add(this.coords.Count - 1);
945 947
@@ -955,6 +957,12 @@ namespace PrimMesher
955 957
956 else 958 else
957 { 959 {
960 this.cut1CoordIndices.Add(0);
961 this.cut1CoordIndices.Add(1);
962
963 this.cut2CoordIndices.Add(lastOuterVertIndex);
964 this.cut2CoordIndices.Add(0);
965
958 this.cutNormal1.X = this.vertexNormals[1].Y; 966 this.cutNormal1.X = this.vertexNormals[1].Y;
959 this.cutNormal1.Y = -this.vertexNormals[1].X; 967 this.cutNormal1.Y = -this.vertexNormals[1].X;
960 968
@@ -979,11 +987,14 @@ namespace PrimMesher
979 // I know it's ugly but so is the whole concept of prim face numbers 987 // I know it's ugly but so is the whole concept of prim face numbers
980 988
981 int faceNum = 1; // start with outer faces 989 int faceNum = 1; // start with outer faces
990 this.outerFaceNumber = faceNum;
991
982 int startVert = hasProfileCut && !hasHollow ? 1 : 0; 992 int startVert = hasProfileCut && !hasHollow ? 1 : 0;
983 if (startVert > 0) 993 if (startVert > 0)
984 this.faceNumbers.Add(-1); 994 this.faceNumbers.Add(-1);
985 for (int i = 0; i < this.numOuterVerts - 1; i++) 995 for (int i = 0; i < this.numOuterVerts - 1; i++)
986 this.faceNumbers.Add(sides < 5 ? faceNum++ : faceNum); 996 //this.faceNumbers.Add(sides < 5 ? faceNum++ : faceNum);
997 this.faceNumbers.Add(sides < 5 && i < sides ? faceNum++ : faceNum);
987 998
988 //if (!hasHollow && !hasProfileCut) 999 //if (!hasHollow && !hasProfileCut)
989 // this.bottomFaceNumber = faceNum++; 1000 // this.bottomFaceNumber = faceNum++;
@@ -993,12 +1004,15 @@ namespace PrimMesher
993 if (sides > 4 && (hasHollow || hasProfileCut)) 1004 if (sides > 4 && (hasHollow || hasProfileCut))
994 faceNum++; 1005 faceNum++;
995 1006
1007 if (sides < 5 && (hasHollow || hasProfileCut) && this.numOuterVerts < sides)
1008 faceNum++;
1009
996 if (hasHollow) 1010 if (hasHollow)
997 { 1011 {
998 for (int i = 0; i < this.numHollowVerts; i++) 1012 for (int i = 0; i < this.numHollowVerts; i++)
999 this.faceNumbers.Add(faceNum); 1013 this.faceNumbers.Add(faceNum);
1000 1014
1001 faceNum++; 1015 this.hollowFaceNumber = faceNum++;
1002 } 1016 }
1003 //if (hasProfileCut || hasHollow) 1017 //if (hasProfileCut || hasHollow)
1004 // this.bottomFaceNumber = faceNum++; 1018 // this.bottomFaceNumber = faceNum++;
@@ -1006,11 +1020,11 @@ namespace PrimMesher
1006 1020
1007 if (hasHollow && hasProfileCut) 1021 if (hasHollow && hasProfileCut)
1008 this.faceNumbers.Add(faceNum++); 1022 this.faceNumbers.Add(faceNum++);
1023
1009 for (int i = 0; i < this.faceNumbers.Count; i++) 1024 for (int i = 0; i < this.faceNumbers.Count; i++)
1010 if (this.faceNumbers[i] == -1) 1025 if (this.faceNumbers[i] == -1)
1011 this.faceNumbers[i] = faceNum++; 1026 this.faceNumbers[i] = faceNum++;
1012 1027
1013
1014 this.numPrimFaces = faceNum; 1028 this.numPrimFaces = faceNum;
1015 } 1029 }
1016 1030
@@ -1455,11 +1469,15 @@ namespace PrimMesher
1455 public float revolutions = 1.0f; 1469 public float revolutions = 1.0f;
1456 public int stepsPerRevolution = 24; 1470 public int stepsPerRevolution = 24;
1457 1471
1472 private int profileOuterFaceNumber = -1;
1473 private int profileHollowFaceNumber = -1;
1474
1458 private bool hasProfileCut = false; 1475 private bool hasProfileCut = false;
1459 private bool hasHollow = false; 1476 private bool hasHollow = false;
1460 public bool calcVertexNormals = false; 1477 public bool calcVertexNormals = false;
1461 private bool normalsProcessed = false; 1478 private bool normalsProcessed = false;
1462 public bool viewerMode = false; 1479 public bool viewerMode = false;
1480 public bool sphereMode = false;
1463 1481
1464 public int numPrimFaces = 0; 1482 public int numPrimFaces = 0;
1465 1483
@@ -1491,10 +1509,35 @@ namespace PrimMesher
1491 s += "\nradius...............: " + this.radius.ToString(); 1509 s += "\nradius...............: " + this.radius.ToString();
1492 s += "\nrevolutions..........: " + this.revolutions.ToString(); 1510 s += "\nrevolutions..........: " + this.revolutions.ToString();
1493 s += "\nstepsPerRevolution...: " + this.stepsPerRevolution.ToString(); 1511 s += "\nstepsPerRevolution...: " + this.stepsPerRevolution.ToString();
1512 s += "\nsphereMode...........: " + this.sphereMode.ToString();
1513 s += "\nhasProfileCut........: " + this.hasProfileCut.ToString();
1514 s += "\nhasHollow............: " + this.hasHollow.ToString();
1515 s += "\nviewerMode...........: " + this.viewerMode.ToString();
1494 1516
1495 return s; 1517 return s;
1496 } 1518 }
1497 1519
1520 public int ProfileOuterFaceNumber
1521 {
1522 get { return profileOuterFaceNumber; }
1523 }
1524
1525 public int ProfileHollowFaceNumber
1526 {
1527 get { return profileHollowFaceNumber; }
1528 }
1529
1530 public bool HasProfileCut
1531 {
1532 get { return hasProfileCut; }
1533 }
1534
1535 public bool HasHollow
1536 {
1537 get { return hasHollow; }
1538 }
1539
1540
1498 /// <summary> 1541 /// <summary>
1499 /// Constructs a PrimMesh object and creates the profile for extrusion. 1542 /// Constructs a PrimMesh object and creates the profile for extrusion.
1500 /// </summary> 1543 /// </summary>
@@ -1531,8 +1574,12 @@ namespace PrimMesher
1531 if (hollow < 0.0f) 1574 if (hollow < 0.0f)
1532 this.hollow = 0.0f; 1575 this.hollow = 0.0f;
1533 1576
1534 this.hasProfileCut = (this.profileStart > 0.0f || this.profileEnd < 1.0f); 1577 //if (sphereMode)
1535 this.hasHollow = (this.hollow > 0.001f); 1578 // this.hasProfileCut = this.profileEnd - this.profileStart < 0.4999f;
1579 //else
1580 // //this.hasProfileCut = (this.profileStart > 0.0f || this.profileEnd < 1.0f);
1581 // this.hasProfileCut = this.profileEnd - this.profileStart < 0.9999f;
1582 //this.hasHollow = (this.hollow > 0.001f);
1536 } 1583 }
1537 1584
1538 /// <summary> 1585 /// <summary>
@@ -1540,6 +1587,8 @@ namespace PrimMesher
1540 /// </summary> 1587 /// </summary>
1541 public void Extrude(PathType pathType) 1588 public void Extrude(PathType pathType)
1542 { 1589 {
1590 bool needEndFaces = false;
1591
1543 this.coords = new List<Coord>(); 1592 this.coords = new List<Coord>();
1544 this.faces = new List<Face>(); 1593 this.faces = new List<Face>();
1545 1594
@@ -1565,6 +1614,12 @@ namespace PrimMesher
1565 steps = (int)(steps * 4.5 * length); 1614 steps = (int)(steps * 4.5 * length);
1566 } 1615 }
1567 1616
1617 if (sphereMode)
1618 this.hasProfileCut = this.profileEnd - this.profileStart < 0.4999f;
1619 else
1620 //this.hasProfileCut = (this.profileStart > 0.0f || this.profileEnd < 1.0f);
1621 this.hasProfileCut = this.profileEnd - this.profileStart < 0.9999f;
1622 this.hasHollow = (this.hollow > 0.001f);
1568 1623
1569 float twistBegin = this.twistBegin / 360.0f * twoPi; 1624 float twistBegin = this.twistBegin / 360.0f * twoPi;
1570 float twistEnd = this.twistEnd / 360.0f * twoPi; 1625 float twistEnd = this.twistEnd / 360.0f * twoPi;
@@ -1634,6 +1689,32 @@ namespace PrimMesher
1634 1689
1635 this.numPrimFaces = profile.numPrimFaces; 1690 this.numPrimFaces = profile.numPrimFaces;
1636 1691
1692 //profileOuterFaceNumber = profile.faceNumbers[0];
1693 //if (!needEndFaces)
1694 // profileOuterFaceNumber--;
1695 //profileOuterFaceNumber = needEndFaces ? 1 : 0;
1696
1697
1698 //if (hasHollow)
1699 //{
1700 // if (needEndFaces)
1701 // profileHollowFaceNumber = profile.faceNumbers[profile.numOuterVerts + 1];
1702 // else
1703 // profileHollowFaceNumber = profile.faceNumbers[profile.numOuterVerts] - 1;
1704 //}
1705
1706
1707 profileOuterFaceNumber = profile.outerFaceNumber;
1708 if (!needEndFaces)
1709 profileOuterFaceNumber--;
1710
1711 if (hasHollow)
1712 {
1713 profileHollowFaceNumber = profile.hollowFaceNumber;
1714 if (!needEndFaces)
1715 profileHollowFaceNumber--;
1716 }
1717
1637 int cut1Vert = -1; 1718 int cut1Vert = -1;
1638 int cut2Vert = -1; 1719 int cut2Vert = -1;
1639 if (hasProfileCut) 1720 if (hasProfileCut)
@@ -1673,7 +1754,7 @@ namespace PrimMesher
1673 1754
1674 path.Create(pathType, steps); 1755 path.Create(pathType, steps);
1675 1756
1676 bool needEndFaces = false; 1757
1677 if (pathType == PathType.Circular) 1758 if (pathType == PathType.Circular)
1678 { 1759 {
1679 needEndFaces = false; 1760 needEndFaces = false;
@@ -1761,7 +1842,7 @@ namespace PrimMesher
1761 int startVert = coordsLen + 1; 1842 int startVert = coordsLen + 1;
1762 int endVert = this.coords.Count; 1843 int endVert = this.coords.Count;
1763 1844
1764 if (sides < 5 || this.hasProfileCut || hollow > 0.0f) 1845 if (sides < 5 || this.hasProfileCut || this.hasHollow)
1765 startVert--; 1846 startVert--;
1766 1847
1767 for (int i = startVert; i < endVert; i++) 1848 for (int i = startVert; i < endVert; i++)
@@ -1813,11 +1894,13 @@ namespace PrimMesher
1813 u1 -= (int)u1; 1894 u1 -= (int)u1;
1814 if (u2 < 0.1f) 1895 if (u2 < 0.1f)
1815 u2 = 1.0f; 1896 u2 = 1.0f;
1897 //this.profileOuterFaceNumber = primFaceNum;
1816 } 1898 }
1817 else if (whichVert > profile.coords.Count - profile.numHollowVerts - 1) 1899 else if (whichVert > profile.coords.Count - profile.numHollowVerts - 1)
1818 { 1900 {
1819 u1 *= 2.0f; 1901 u1 *= 2.0f;
1820 u2 *= 2.0f; 1902 u2 *= 2.0f;
1903 //this.profileHollowFaceNumber = primFaceNum;
1821 } 1904 }
1822 } 1905 }
1823 1906
diff --git a/OpenSim/Region/Physics/Meshing/SculptMap.cs b/OpenSim/Region/Physics/Meshing/SculptMap.cs
new file mode 100644
index 0000000..d2d71de
--- /dev/null
+++ b/OpenSim/Region/Physics/Meshing/SculptMap.cs
@@ -0,0 +1,176 @@
1/*
2 * Copyright (c) Contributors
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// to build without references to System.Drawing, comment this out
29#define SYSTEM_DRAWING
30
31using System;
32using System.Collections.Generic;
33using System.Text;
34
35#if SYSTEM_DRAWING
36using System.Drawing;
37using System.Drawing.Imaging;
38
39namespace PrimMesher
40{
41 public class SculptMap
42 {
43 public int width;
44 public int height;
45 public byte[] redBytes;
46 public byte[] greenBytes;
47 public byte[] blueBytes;
48
49 public SculptMap()
50 {
51 }
52
53 public SculptMap(Bitmap bm, int lod)
54 {
55 int bmW = bm.Width;
56 int bmH = bm.Height;
57
58 if (bmW == 0 || bmH == 0)
59 throw new Exception("SculptMap: bitmap has no data");
60
61 int numLodPixels = lod * 2 * lod * 2; // (32 * 2)^2 = 64^2 pixels for default sculpt map image
62
63 bool needsScaling = false;
64
65 width = bmW;
66 height = bmH;
67 while (width * height > numLodPixels)
68 {
69 width >>= 1;
70 height >>= 1;
71 needsScaling = true;
72 }
73
74
75
76 try
77 {
78 if (needsScaling)
79 bm = ScaleImage(bm, width, height,
80 System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor);
81 }
82
83 catch (Exception e)
84 {
85 throw new Exception("Exception in ScaleImage(): e: " + e.ToString());
86 }
87
88 if (width * height > lod * lod)
89 {
90 width >>= 1;
91 height >>= 1;
92 }
93
94 int numBytes = (width + 1) * (height + 1);
95 redBytes = new byte[numBytes];
96 greenBytes = new byte[numBytes];
97 blueBytes = new byte[numBytes];
98
99 int byteNdx = 0;
100
101 try
102 {
103 for (int y = 0; y <= height; y++)
104 {
105 for (int x = 0; x <= width; x++)
106 {
107 int bmY = y < height ? y * 2 : y * 2 - 1;
108 int bmX = x < width ? x * 2 : x * 2 - 1;
109 Color c = bm.GetPixel(bmX, bmY);
110
111 redBytes[byteNdx] = c.R;
112 greenBytes[byteNdx] = c.G;
113 blueBytes[byteNdx] = c.B;
114
115 ++byteNdx;
116 }
117 }
118 }
119 catch (Exception e)
120 {
121 throw new Exception("Caught exception processing byte arrays in SculptMap(): e: " + e.ToString());
122 }
123
124 width++;
125 height++;
126 }
127
128 public List<List<Coord>> ToRows(bool mirror)
129 {
130 int numRows = height;
131 int numCols = width;
132
133 List<List<Coord>> rows = new List<List<Coord>>(numRows);
134
135 float pixScale = 1.0f / 255;
136
137 int rowNdx, colNdx;
138 int smNdx = 0;
139
140 for (rowNdx = 0; rowNdx < numRows; rowNdx++)
141 {
142 List<Coord> row = new List<Coord>(numCols);
143 for (colNdx = 0; colNdx < numCols; colNdx++)
144 {
145 if (mirror)
146 row.Add(new Coord(-(redBytes[smNdx] * pixScale - 0.5f), (greenBytes[smNdx] * pixScale - 0.5f), blueBytes[smNdx] * pixScale - 0.5f));
147 else
148 row.Add(new Coord(redBytes[smNdx] * pixScale - 0.5f, greenBytes[smNdx] * pixScale - 0.5f, blueBytes[smNdx] * pixScale - 0.5f));
149
150 ++smNdx;
151 }
152 rows.Add(row);
153 }
154 return rows;
155 }
156
157 private Bitmap ScaleImage(Bitmap srcImage, int destWidth, int destHeight,
158 System.Drawing.Drawing2D.InterpolationMode interpMode)
159 {
160 Bitmap scaledImage = new Bitmap(srcImage, destWidth, destHeight);
161 scaledImage.SetResolution(96.0f, 96.0f);
162
163 Graphics grPhoto = Graphics.FromImage(scaledImage);
164 grPhoto.InterpolationMode = interpMode;
165
166 grPhoto.DrawImage(srcImage,
167 new Rectangle(0, 0, destWidth, destHeight),
168 new Rectangle(0, 0, srcImage.Width, srcImage.Height),
169 GraphicsUnit.Pixel);
170
171 grPhoto.Dispose();
172 return scaledImage;
173 }
174 }
175}
176#endif
diff --git a/OpenSim/Region/Physics/Meshing/SculptMesh.cs b/OpenSim/Region/Physics/Meshing/SculptMesh.cs
index ebc5be6..6aa8fe4 100644
--- a/OpenSim/Region/Physics/Meshing/SculptMesh.cs
+++ b/OpenSim/Region/Physics/Meshing/SculptMesh.cs
@@ -53,50 +53,6 @@ namespace PrimMesher
53 public enum SculptType { sphere = 1, torus = 2, plane = 3, cylinder = 4 }; 53 public enum SculptType { sphere = 1, torus = 2, plane = 3, cylinder = 4 };
54 54
55#if SYSTEM_DRAWING 55#if SYSTEM_DRAWING
56 private Bitmap ScaleImage(Bitmap srcImage, float scale, bool removeAlpha)
57 {
58 int sourceWidth = srcImage.Width;
59 int sourceHeight = srcImage.Height;
60 int sourceX = 0;
61 int sourceY = 0;
62
63 int destX = 0;
64 int destY = 0;
65 int destWidth = (int)(srcImage.Width * scale);
66 int destHeight = (int)(srcImage.Height * scale);
67
68 Bitmap scaledImage;
69
70 if (removeAlpha)
71 {
72 if (srcImage.PixelFormat == PixelFormat.Format32bppArgb)
73 for (int y = 0; y < srcImage.Height; y++)
74 for (int x = 0; x < srcImage.Width; x++)
75 {
76 Color c = srcImage.GetPixel(x, y);
77 srcImage.SetPixel(x, y, Color.FromArgb(255, c.R, c.G, c.B));
78 }
79
80 scaledImage = new Bitmap(destWidth, destHeight,
81 PixelFormat.Format24bppRgb);
82 }
83 else
84 scaledImage = new Bitmap(srcImage, destWidth, destHeight);
85
86 scaledImage.SetResolution(96.0f, 96.0f);
87
88 Graphics grPhoto = Graphics.FromImage(scaledImage);
89 grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
90
91 grPhoto.DrawImage(srcImage,
92 new Rectangle(destX, destY, destWidth, destHeight),
93 new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
94 GraphicsUnit.Pixel);
95
96 grPhoto.Dispose();
97 return scaledImage;
98 }
99
100 56
101 public SculptMesh SculptMeshFromFile(string fileName, SculptType sculptType, int lod, bool viewerMode) 57 public SculptMesh SculptMeshFromFile(string fileName, SculptType sculptType, int lod, bool viewerMode)
102 { 58 {
@@ -106,6 +62,7 @@ namespace PrimMesher
106 return sculptMesh; 62 return sculptMesh;
107 } 63 }
108 64
65
109 public SculptMesh(string fileName, int sculptType, int lod, int viewerMode, int mirror, int invert) 66 public SculptMesh(string fileName, int sculptType, int lod, int viewerMode, int mirror, int invert)
110 { 67 {
111 Bitmap bitmap = (Bitmap)Bitmap.FromFile(fileName); 68 Bitmap bitmap = (Bitmap)Bitmap.FromFile(fileName);
@@ -296,36 +253,53 @@ namespace PrimMesher
296 return rows; 253 return rows;
297 } 254 }
298 255
299 256 private List<List<Coord>> bitmap2CoordsSampled(Bitmap bitmap, int scale, bool mirror)
300 void _SculptMesh(Bitmap sculptBitmap, SculptType sculptType, int lod, bool viewerMode, bool mirror, bool invert)
301 { 257 {
302 coords = new List<Coord>(); 258 int numRows = bitmap.Height / scale;
303 faces = new List<Face>(); 259 int numCols = bitmap.Width / scale;
304 normals = new List<Coord>(); 260 List<List<Coord>> rows = new List<List<Coord>>(numRows);
305 uvs = new List<UVCoord>();
306 261
307 sculptType = (SculptType)(((int)sculptType) & 0x07); 262 float pixScale = 1.0f / 256.0f;
308 263
309 if (mirror) 264 int imageX, imageY = 0;
310 if (sculptType == SculptType.plane) 265
311 invert = !invert; 266 int rowNdx, colNdx;
312 267
313 float sculptBitmapLod = (float)Math.Sqrt(sculptBitmap.Width * sculptBitmap.Height); 268 for (rowNdx = 0; rowNdx <= numRows; rowNdx++)
269 {
270 List<Coord> row = new List<Coord>(numCols);
271 imageY = rowNdx * scale;
272 if (rowNdx == numRows) imageY--;
273 for (colNdx = 0; colNdx <= numCols; colNdx++)
274 {
275 imageX = colNdx * scale;
276 if (colNdx == numCols) imageX--;
314 277
315 float sourceScaleFactor = (float)(lod) / sculptBitmapLod; 278 Color c = bitmap.GetPixel(imageX, imageY);
279 if (c.A != 255)
280 {
281 bitmap.SetPixel(imageX, imageY, Color.FromArgb(255, c.R, c.G, c.B));
282 c = bitmap.GetPixel(imageX, imageY);
283 }
316 284
317 float fScale = 1.0f / sourceScaleFactor; 285 if (mirror)
286 row.Add(new Coord(-(c.R * pixScale - 0.5f), c.G * pixScale - 0.5f, c.B * pixScale - 0.5f));
287 else
288 row.Add(new Coord(c.R * pixScale - 0.5f, c.G * pixScale - 0.5f, c.B * pixScale - 0.5f));
318 289
319 int iScale = (int)fScale; 290 }
320 if (iScale < 1) iScale = 1; 291 rows.Add(row);
321 if (iScale > 2 && iScale % 2 == 0) 292 }
322 _SculptMesh(bitmap2Coords(ScaleImage(sculptBitmap, 64.0f / sculptBitmapLod, true), 64 / lod, mirror), sculptType, viewerMode, mirror, invert); 293 return rows;
323 else
324 _SculptMesh(bitmap2Coords(sculptBitmap, iScale, mirror), sculptType, viewerMode, mirror, invert);
325 } 294 }
326#endif
327 295
328 296
297 void _SculptMesh(Bitmap sculptBitmap, SculptType sculptType, int lod, bool viewerMode, bool mirror, bool invert)
298 {
299 _SculptMesh(new SculptMap(sculptBitmap, lod).ToRows(mirror), sculptType, viewerMode, mirror, invert);
300 }
301#endif
302
329 void _SculptMesh(List<List<Coord>> rows, SculptType sculptType, bool viewerMode, bool mirror, bool invert) 303 void _SculptMesh(List<List<Coord>> rows, SculptType sculptType, bool viewerMode, bool mirror, bool invert)
330 { 304 {
331 coords = new List<Coord>(); 305 coords = new List<Coord>();
@@ -349,8 +323,18 @@ namespace PrimMesher
349 323
350 if (sculptType != SculptType.plane) 324 if (sculptType != SculptType.plane)
351 { 325 {
352 for (int rowNdx = 0; rowNdx < rows.Count; rowNdx++) 326 if (rows.Count % 2 == 0)
353 rows[rowNdx].Add(rows[rowNdx][0]); 327 {
328 for (int rowNdx = 0; rowNdx < rows.Count; rowNdx++)
329 rows[rowNdx].Add(rows[rowNdx][0]);
330 }
331 else
332 {
333 int lastIndex = rows[0].Count - 1;
334
335 for (int i = 0; i < rows.Count; i++)
336 rows[i][0] = rows[i][lastIndex];
337 }
354 } 338 }
355 339
356 Coord topPole = rows[0][width / 2]; 340 Coord topPole = rows[0][width / 2];
@@ -358,23 +342,41 @@ namespace PrimMesher
358 342
359 if (sculptType == SculptType.sphere) 343 if (sculptType == SculptType.sphere)
360 { 344 {
361 int count = rows[0].Count; 345 if (rows.Count % 2 == 0)
362 List<Coord> topPoleRow = new List<Coord>(count); 346 {
363 List<Coord> bottomPoleRow = new List<Coord>(count); 347 int count = rows[0].Count;
348 List<Coord> topPoleRow = new List<Coord>(count);
349 List<Coord> bottomPoleRow = new List<Coord>(count);
364 350
365 for (int i = 0; i < count; i++) 351 for (int i = 0; i < count; i++)
352 {
353 topPoleRow.Add(topPole);
354 bottomPoleRow.Add(bottomPole);
355 }
356 rows.Insert(0, topPoleRow);
357 rows.Add(bottomPoleRow);
358 }
359 else
366 { 360 {
367 topPoleRow.Add(topPole); 361 int count = rows[0].Count;
368 bottomPoleRow.Add(bottomPole); 362
363 List<Coord> topPoleRow = rows[0];
364 List<Coord> bottomPoleRow = rows[rows.Count - 1];
365
366 for (int i = 0; i < count; i++)
367 {
368 topPoleRow[i] = topPole;
369 bottomPoleRow[i] = bottomPole;
370 }
369 } 371 }
370 rows.Insert(0, topPoleRow);
371 rows.Add(bottomPoleRow);
372 } 372 }
373 else if (sculptType == SculptType.torus) 373
374 if (sculptType == SculptType.torus)
374 rows.Add(rows[0]); 375 rows.Add(rows[0]);
375 376
376 int coordsDown = rows.Count; 377 int coordsDown = rows.Count;
377 int coordsAcross = rows[0].Count; 378 int coordsAcross = rows[0].Count;
379 int lastColumn = coordsAcross - 1;
378 380
379 float widthUnit = 1.0f / (coordsAcross - 1); 381 float widthUnit = 1.0f / (coordsAcross - 1);
380 float heightUnit = 1.0f / (coordsDown - 1); 382 float heightUnit = 1.0f / (coordsDown - 1);
diff --git a/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs b/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs
new file mode 100644
index 0000000..66f35e3
--- /dev/null
+++ b/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs
@@ -0,0 +1,61 @@
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
28using System;
29using Nini.Config;
30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base;
34
35namespace OpenSim.Server.Handlers.GridUser
36{
37 public class GridUserServiceConnector : ServiceConnector
38 {
39 private IGridUserService m_GridUserService;
40 private string m_ConfigName = "GridUserService";
41
42 public GridUserServiceConnector(IConfigSource config, IHttpServer server, string configName) :
43 base(config, server, configName)
44 {
45 IConfig serverConfig = config.Configs[m_ConfigName];
46 if (serverConfig == null)
47 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
48
49 string service = serverConfig.GetString("LocalServiceModule",
50 String.Empty);
51
52 if (service == String.Empty)
53 throw new Exception("No LocalServiceModule in config file");
54
55 Object[] args = new Object[] { config };
56 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(service, args);
57
58 server.AddStreamHandler(new GridUserServerPostHandler(m_GridUserService));
59 }
60 }
61}
diff --git a/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs
new file mode 100644
index 0000000..f8fa429
--- /dev/null
+++ b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs
@@ -0,0 +1,278 @@
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
28using Nini.Config;
29using log4net;
30using System;
31using System.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using System.Collections.Generic;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using OpenSim.Framework;
42using OpenSim.Framework.Servers.HttpServer;
43using OpenMetaverse;
44
45namespace OpenSim.Server.Handlers.GridUser
46{
47 public class GridUserServerPostHandler : BaseStreamHandler
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IGridUserService m_GridUserService;
52
53 public GridUserServerPostHandler(IGridUserService service) :
54 base("POST", "/griduser")
55 {
56 m_GridUserService = service;
57 }
58
59 public override byte[] Handle(string path, Stream requestData,
60 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
61 {
62 StreamReader sr = new StreamReader(requestData);
63 string body = sr.ReadToEnd();
64 sr.Close();
65 body = body.Trim();
66
67 //m_log.DebugFormat("[XXX]: query String: {0}", body);
68 string method = string.Empty;
69 try
70 {
71 Dictionary<string, object> request =
72 ServerUtils.ParseQueryString(body);
73
74 if (!request.ContainsKey("METHOD"))
75 return FailureResult();
76
77 method = request["METHOD"].ToString();
78
79 switch (method)
80 {
81 case "loggedin":
82 return LoggedIn(request);
83 case "loggedout":
84 return LoggedOut(request);
85 case "sethome":
86 return SetHome(request);
87 case "setposition":
88 return SetPosition(request);
89 case "getgriduserinfo":
90 return GetGridUserInfo(request);
91 }
92 m_log.DebugFormat("[GRID USER HANDLER]: unknown method request: {0}", method);
93 }
94 catch (Exception e)
95 {
96 m_log.DebugFormat("[GRID USER HANDLER]: Exception in method {0}: {1}", method, e);
97 }
98
99 return FailureResult();
100
101 }
102
103 byte[] LoggedIn(Dictionary<string, object> request)
104 {
105 string user = String.Empty;
106
107 if (!request.ContainsKey("UserID"))
108 return FailureResult();
109
110 user = request["UserID"].ToString();
111
112 GridUserInfo guinfo = m_GridUserService.LoggedIn(user);
113
114 Dictionary<string, object> result = new Dictionary<string, object>();
115 result["result"] = guinfo.ToKeyValuePairs();
116
117 string xmlString = ServerUtils.BuildXmlResponse(result);
118 //m_log.DebugFormat("[GRID USER HANDLER]: resp string: {0}", xmlString);
119 UTF8Encoding encoding = new UTF8Encoding();
120 return encoding.GetBytes(xmlString);
121
122 }
123
124 byte[] LoggedOut(Dictionary<string, object> request)
125 {
126 string userID = string.Empty;
127 UUID regionID = UUID.Zero;
128 Vector3 position = Vector3.Zero;
129 Vector3 lookat = Vector3.Zero;
130
131 if (!UnpackArgs(request, out userID, out regionID, out position, out lookat))
132 return FailureResult();
133
134 if (m_GridUserService.LoggedOut(userID, regionID, position, lookat))
135 return SuccessResult();
136
137 return FailureResult();
138 }
139
140 byte[] SetHome(Dictionary<string, object> request)
141 {
142 string user = string.Empty;
143 UUID region = UUID.Zero;
144 Vector3 position = new Vector3(128, 128, 70);
145 Vector3 look = Vector3.Zero;
146
147 if (!UnpackArgs(request, out user, out region, out position, out look))
148 return FailureResult();
149
150 if (m_GridUserService.SetHome(user, region, position, look))
151 return SuccessResult();
152
153 return FailureResult();
154 }
155
156 byte[] SetPosition(Dictionary<string, object> request)
157 {
158 string user = string.Empty;
159 UUID region = UUID.Zero;
160 Vector3 position = new Vector3(128, 128, 70);
161 Vector3 look = Vector3.Zero;
162
163 if (!request.ContainsKey("UserID") || !request.ContainsKey("RegionID"))
164 return FailureResult();
165
166 if (!UnpackArgs(request, out user, out region, out position, out look))
167 return FailureResult();
168
169 if (m_GridUserService.SetLastPosition(user, region, position, look))
170 return SuccessResult();
171
172 return FailureResult();
173 }
174
175 byte[] GetGridUserInfo(Dictionary<string, object> request)
176 {
177 string user = String.Empty;
178
179 if (!request.ContainsKey("UserID"))
180 return FailureResult();
181
182 user = request["UserID"].ToString();
183
184 GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(user);
185
186 Dictionary<string, object> result = new Dictionary<string, object>();
187 result["result"] = guinfo.ToKeyValuePairs();
188
189 string xmlString = ServerUtils.BuildXmlResponse(result);
190 //m_log.DebugFormat("[GRID USER HANDLER]: resp string: {0}", xmlString);
191 UTF8Encoding encoding = new UTF8Encoding();
192 return encoding.GetBytes(xmlString);
193
194 }
195
196 private bool UnpackArgs(Dictionary<string, object> request, out string user, out UUID region, out Vector3 position, out Vector3 lookAt)
197 {
198 user = string.Empty;
199 region = UUID.Zero;
200 position = new Vector3(128, 128, 70);
201 lookAt = Vector3.Zero;
202
203 if (!request.ContainsKey("UserID") || !request.ContainsKey("RegionID"))
204 return false;
205
206 user = request["UserID"].ToString();
207
208 if (!UUID.TryParse(request["RegionID"].ToString(), out region))
209 return false;
210
211 if (request.ContainsKey("Position"))
212 Vector3.TryParse(request["Position"].ToString(), out position);
213
214 if (request.ContainsKey("LookAt"))
215 Vector3.TryParse(request["LookAt"].ToString(), out lookAt);
216
217 return true;
218 }
219
220
221 private byte[] SuccessResult()
222 {
223 XmlDocument doc = new XmlDocument();
224
225 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
226 "", "");
227
228 doc.AppendChild(xmlnode);
229
230 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
231 "");
232
233 doc.AppendChild(rootElement);
234
235 XmlElement result = doc.CreateElement("", "result", "");
236 result.AppendChild(doc.CreateTextNode("Success"));
237
238 rootElement.AppendChild(result);
239
240 return DocToBytes(doc);
241 }
242
243 private byte[] FailureResult()
244 {
245 XmlDocument doc = new XmlDocument();
246
247 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
248 "", "");
249
250 doc.AppendChild(xmlnode);
251
252 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
253 "");
254
255 doc.AppendChild(rootElement);
256
257 XmlElement result = doc.CreateElement("", "result", "");
258 result.AppendChild(doc.CreateTextNode("Failure"));
259
260 rootElement.AppendChild(result);
261
262 return DocToBytes(doc);
263 }
264
265 private byte[] DocToBytes(XmlDocument doc)
266 {
267 MemoryStream ms = new MemoryStream();
268 XmlTextWriter xw = new XmlTextWriter(ms, null);
269 xw.Formatting = Formatting.Indented;
270 doc.WriteTo(xw);
271 xw.Flush();
272
273 return ms.ToArray();
274 }
275
276
277 }
278}
diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
index 4ebf933..3104917 100644
--- a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
@@ -90,8 +90,6 @@ namespace OpenSim.Server.Handlers.Presence
90 return GetAgent(request); 90 return GetAgent(request);
91 case "getagents": 91 case "getagents":
92 return GetAgents(request); 92 return GetAgents(request);
93 case "sethome":
94 return SetHome(request);
95 } 93 }
96 m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method); 94 m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method);
97 } 95 }
@@ -140,12 +138,7 @@ namespace OpenSim.Server.Handlers.Presence
140 if (!UUID.TryParse(request["SessionID"].ToString(), out session)) 138 if (!UUID.TryParse(request["SessionID"].ToString(), out session))
141 return FailureResult(); 139 return FailureResult();
142 140
143 if (request.ContainsKey("Position") && request["Position"] != null) 141 if (m_PresenceService.LogoutAgent(session))
144 Vector3.TryParse(request["Position"].ToString(), out position);
145 if (request.ContainsKey("LookAt") && request["Position"] != null)
146 Vector3.TryParse(request["LookAt"].ToString(), out lookat);
147
148 if (m_PresenceService.LogoutAgent(session, position, lookat))
149 return SuccessResult(); 142 return SuccessResult();
150 143
151 return FailureResult(); 144 return FailureResult();
@@ -171,8 +164,6 @@ namespace OpenSim.Server.Handlers.Presence
171 { 164 {
172 UUID session = UUID.Zero; 165 UUID session = UUID.Zero;
173 UUID region = UUID.Zero; 166 UUID region = UUID.Zero;
174 Vector3 position = new Vector3(128, 128, 70);
175 Vector3 look = Vector3.Zero;
176 167
177 if (!request.ContainsKey("SessionID") || !request.ContainsKey("RegionID")) 168 if (!request.ContainsKey("SessionID") || !request.ContainsKey("RegionID"))
178 return FailureResult(); 169 return FailureResult();
@@ -183,13 +174,7 @@ namespace OpenSim.Server.Handlers.Presence
183 if (!UUID.TryParse(request["RegionID"].ToString(), out region)) 174 if (!UUID.TryParse(request["RegionID"].ToString(), out region))
184 return FailureResult(); 175 return FailureResult();
185 176
186 if (request.ContainsKey("position")) 177 if (m_PresenceService.ReportAgent(session, region))
187 Vector3.TryParse(request["position"].ToString(), out position);
188
189 if (request.ContainsKey("lookAt"))
190 Vector3.TryParse(request["lookAt"].ToString(), out look);
191
192 if (m_PresenceService.ReportAgent(session, region, position, look))
193 { 178 {
194 return SuccessResult(); 179 return SuccessResult();
195 } 180 }
@@ -318,31 +303,5 @@ namespace OpenSim.Server.Handlers.Presence
318 return ms.ToArray(); 303 return ms.ToArray();
319 } 304 }
320 305
321 byte[] SetHome(Dictionary<string, object> request)
322 {
323 UUID region = UUID.Zero;
324 Vector3 position = new Vector3(128, 128, 70);
325 Vector3 look = Vector3.Zero;
326
327 if (!request.ContainsKey("UserID") || !request.ContainsKey("RegionID"))
328 return FailureResult();
329
330 string user = request["UserID"].ToString();
331
332 if (!UUID.TryParse(request["RegionID"].ToString(), out region))
333 return FailureResult();
334
335 if (request.ContainsKey("position"))
336 Vector3.TryParse(request["position"].ToString(), out position);
337
338 if (request.ContainsKey("lookAt"))
339 Vector3.TryParse(request["lookAt"].ToString(), out look);
340
341 if (m_PresenceService.SetHomeLocation(user, region, position, look))
342 return SuccessResult();
343
344 return FailureResult();
345 }
346
347 } 306 }
348} 307}
diff --git a/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs b/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs
index 0e85067..b4500a5 100644
--- a/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs
+++ b/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs
@@ -25,14 +25,206 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using log4net;
28using System; 29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39using OpenSim.Server.Base;
40using OpenMetaverse;
29 41
30namespace OpenSim.Services.Connectors 42namespace OpenSim.Services.Connectors
31{ 43{
32 public class GridUserServiceConnector 44 public class GridUserServicesConnector : IGridUserService
33 { 45 {
34 public GridUserServiceConnector() 46 private static readonly ILog m_log =
47 LogManager.GetLogger(
48 MethodBase.GetCurrentMethod().DeclaringType);
49
50 private string m_ServerURI = String.Empty;
51
52 public GridUserServicesConnector()
53 {
54 }
55
56 public GridUserServicesConnector(string serverURI)
57 {
58 m_ServerURI = serverURI.TrimEnd('/');
59 }
60
61 public GridUserServicesConnector(IConfigSource source)
62 {
63 Initialise(source);
64 }
65
66 public virtual void Initialise(IConfigSource source)
67 {
68 IConfig gridConfig = source.Configs["GridUserService"];
69 if (gridConfig == null)
70 {
71 m_log.Error("[GRID USER CONNECTOR]: GridUserService missing from OpenSim.ini");
72 throw new Exception("GridUser connector init error");
73 }
74
75 string serviceURI = gridConfig.GetString("GridUserServerURI",
76 String.Empty);
77
78 if (serviceURI == String.Empty)
79 {
80 m_log.Error("[GRID USER CONNECTOR]: No Server URI named in section GridUserService");
81 throw new Exception("GridUser connector init error");
82 }
83 m_ServerURI = serviceURI;
84 }
85
86
87 #region IPresenceService
88
89
90 public GridUserInfo LoggedIn(string userID)
91 {
92 Dictionary<string, object> sendData = new Dictionary<string, object>();
93 //sendData["SCOPEID"] = scopeID.ToString();
94 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
95 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
96 sendData["METHOD"] = "loggedin";
97
98 sendData["UserID"] = userID;
99
100 return Get(sendData);
101
102 }
103
104 public bool LoggedOut(string userID, UUID region, Vector3 position, Vector3 lookat)
105 {
106 Dictionary<string, object> sendData = new Dictionary<string, object>();
107 //sendData["SCOPEID"] = scopeID.ToString();
108 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
109 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
110 sendData["METHOD"] = "loggedout";
111
112 return Set(sendData, userID, region, position, lookat);
113 }
114
115 public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
116 {
117 Dictionary<string, object> sendData = new Dictionary<string, object>();
118 //sendData["SCOPEID"] = scopeID.ToString();
119 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
120 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
121 sendData["METHOD"] = "sethome";
122
123 return Set(sendData, userID, regionID, position, lookAt);
124 }
125
126 public bool SetLastPosition(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
127 {
128 Dictionary<string, object> sendData = new Dictionary<string, object>();
129 //sendData["SCOPEID"] = scopeID.ToString();
130 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
131 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
132 sendData["METHOD"] = "setposition";
133
134 return Set(sendData, userID, regionID, position, lookAt);
135 }
136
137 public GridUserInfo GetGridUserInfo(string userID)
138 {
139 Dictionary<string, object> sendData = new Dictionary<string, object>();
140 //sendData["SCOPEID"] = scopeID.ToString();
141 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
142 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
143 sendData["METHOD"] = "getgriduserinfo";
144
145 sendData["UserID"] = userID;
146
147 return Get(sendData);
148 }
149
150 #endregion
151
152 protected bool Set(Dictionary<string, object> sendData, string userID, UUID regionID, Vector3 position, Vector3 lookAt)
153 {
154 sendData["UserID"] = userID;
155 sendData["RegionID"] = regionID.ToString();
156 sendData["Position"] = position.ToString();
157 sendData["LookAt"] = lookAt.ToString();
158
159 string reqString = ServerUtils.BuildQueryString(sendData);
160 // m_log.DebugFormat("[GRID USER CONNECTOR]: queryString = {0}", reqString);
161 try
162 {
163 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
164 m_ServerURI + "/griduser",
165 reqString);
166 if (reply != string.Empty)
167 {
168 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
169
170 if (replyData.ContainsKey("result"))
171 {
172 if (replyData["result"].ToString().ToLower() == "success")
173 return true;
174 else
175 return false;
176 }
177 else
178 m_log.DebugFormat("[GRID USER CONNECTOR]: SetPosition reply data does not contain result field");
179
180 }
181 else
182 m_log.DebugFormat("[GRID USER CONNECTOR]: SetPosition received empty reply");
183 }
184 catch (Exception e)
185 {
186 m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server: {0}", e.Message);
187 }
188
189 return false;
190 }
191
192 protected GridUserInfo Get(Dictionary<string, object> sendData)
35 { 193 {
194 string reqString = ServerUtils.BuildQueryString(sendData);
195 // m_log.DebugFormat("[GRID USER CONNECTOR]: queryString = {0}", reqString);
196 try
197 {
198 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
199 m_ServerURI + "/griduser",
200 reqString);
201 if (reply != string.Empty)
202 {
203 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
204 GridUserInfo guinfo = null;
205
206 if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null))
207 {
208 if (replyData["result"] is Dictionary<string, object>)
209 {
210 guinfo = new GridUserInfo((Dictionary<string, object>)replyData["result"]);
211 }
212 }
213
214 return guinfo;
215
216 }
217 else
218 m_log.DebugFormat("[GRID USER CONNECTOR]: Loggedin received empty reply");
219 }
220 catch (Exception e)
221 {
222 m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server: {0}", e.Message);
223 }
224
225 return null;
226
36 } 227 }
228
37 } 229 }
38} 230}
diff --git a/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs
index 23621b7..41ebeaf 100644
--- a/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs
@@ -132,7 +132,7 @@ namespace OpenSim.Services.Connectors
132 132
133 } 133 }
134 134
135 public bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookat) 135 public bool LogoutAgent(UUID sessionID)
136 { 136 {
137 Dictionary<string, object> sendData = new Dictionary<string, object>(); 137 Dictionary<string, object> sendData = new Dictionary<string, object>();
138 //sendData["SCOPEID"] = scopeID.ToString(); 138 //sendData["SCOPEID"] = scopeID.ToString();
@@ -141,8 +141,6 @@ namespace OpenSim.Services.Connectors
141 sendData["METHOD"] = "logout"; 141 sendData["METHOD"] = "logout";
142 142
143 sendData["SessionID"] = sessionID.ToString(); 143 sendData["SessionID"] = sessionID.ToString();
144 sendData["Position"] = position.ToString();
145 sendData["LookAt"] = lookat.ToString();
146 144
147 string reqString = ServerUtils.BuildQueryString(sendData); 145 string reqString = ServerUtils.BuildQueryString(sendData);
148 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); 146 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
@@ -220,7 +218,7 @@ namespace OpenSim.Services.Connectors
220 return false; 218 return false;
221 } 219 }
222 220
223 public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) 221 public bool ReportAgent(UUID sessionID, UUID regionID)
224 { 222 {
225 Dictionary<string, object> sendData = new Dictionary<string, object>(); 223 Dictionary<string, object> sendData = new Dictionary<string, object>();
226 //sendData["SCOPEID"] = scopeID.ToString(); 224 //sendData["SCOPEID"] = scopeID.ToString();
@@ -230,8 +228,6 @@ namespace OpenSim.Services.Connectors
230 228
231 sendData["SessionID"] = sessionID.ToString(); 229 sendData["SessionID"] = sessionID.ToString();
232 sendData["RegionID"] = regionID.ToString(); 230 sendData["RegionID"] = regionID.ToString();
233 sendData["position"] = position.ToString();
234 sendData["lookAt"] = lookAt.ToString();
235 231
236 string reqString = ServerUtils.BuildQueryString(sendData); 232 string reqString = ServerUtils.BuildQueryString(sendData);
237 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); 233 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
@@ -371,52 +367,6 @@ namespace OpenSim.Services.Connectors
371 } 367 }
372 368
373 369
374 public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
375 {
376 Dictionary<string, object> sendData = new Dictionary<string, object>();
377 //sendData["SCOPEID"] = scopeID.ToString();
378 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
379 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
380 sendData["METHOD"] = "sethome";
381
382 sendData["UserID"] = userID;
383 sendData["RegionID"] = regionID.ToString();
384 sendData["position"] = position.ToString();
385 sendData["lookAt"] = lookAt.ToString();
386
387 string reqString = ServerUtils.BuildQueryString(sendData);
388 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
389 try
390 {
391 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
392 m_ServerURI + "/presence",
393 reqString);
394 if (reply != string.Empty)
395 {
396 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
397
398 if (replyData.ContainsKey("result"))
399 {
400 if (replyData["result"].ToString().ToLower() == "success")
401 return true;
402 else
403 return false;
404 }
405 else
406 m_log.DebugFormat("[PRESENCE CONNECTOR]: SetHomeLocation reply data does not contain result field");
407
408 }
409 else
410 m_log.DebugFormat("[PRESENCE CONNECTOR]: SetHomeLocation received empty reply");
411 }
412 catch (Exception e)
413 {
414 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
415 }
416
417 return false;
418 }
419
420 #endregion 370 #endregion
421 371
422 } 372 }
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs
index c324272..e48b7de 100644
--- a/OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs
@@ -51,7 +51,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
51 /// message routing) to the SimianGrid backend 51 /// message routing) to the SimianGrid backend
52 /// </summary> 52 /// </summary>
53 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] 53 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
54 public class SimianPresenceServiceConnector : IPresenceService, ISharedRegionModule 54 public class SimianPresenceServiceConnector : IPresenceService, IGridUserService, ISharedRegionModule
55 { 55 {
56 private static readonly ILog m_log = 56 private static readonly ILog m_log =
57 LogManager.GetLogger( 57 LogManager.GetLogger(
@@ -73,6 +73,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
73 if (!String.IsNullOrEmpty(m_serverUrl)) 73 if (!String.IsNullOrEmpty(m_serverUrl))
74 { 74 {
75 scene.RegisterModuleInterface<IPresenceService>(this); 75 scene.RegisterModuleInterface<IPresenceService>(this);
76 scene.RegisterModuleInterface<IGridUserService>(this);
76 77
77 scene.EventManager.OnMakeRootAgent += MakeRootAgentHandler; 78 scene.EventManager.OnMakeRootAgent += MakeRootAgentHandler;
78 scene.EventManager.OnNewClient += NewClientHandler; 79 scene.EventManager.OnNewClient += NewClientHandler;
@@ -86,6 +87,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
86 if (!String.IsNullOrEmpty(m_serverUrl)) 87 if (!String.IsNullOrEmpty(m_serverUrl))
87 { 88 {
88 scene.UnregisterModuleInterface<IPresenceService>(this); 89 scene.UnregisterModuleInterface<IPresenceService>(this);
90 scene.UnregisterModuleInterface<IGridUserService>(this);
89 91
90 scene.EventManager.OnMakeRootAgent -= MakeRootAgentHandler; 92 scene.EventManager.OnMakeRootAgent -= MakeRootAgentHandler;
91 scene.EventManager.OnNewClient -= NewClientHandler; 93 scene.EventManager.OnNewClient -= NewClientHandler;
@@ -151,7 +153,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
151 return success; 153 return success;
152 } 154 }
153 155
154 public bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookAt) 156 public bool LogoutAgent(UUID sessionID)
155 { 157 {
156 m_log.InfoFormat("[SIMIAN PRESENCE CONNECTOR]: Logout requested for agent with sessionID " + sessionID); 158 m_log.InfoFormat("[SIMIAN PRESENCE CONNECTOR]: Logout requested for agent with sessionID " + sessionID);
157 159
@@ -189,7 +191,12 @@ namespace OpenSim.Services.Connectors.SimianGrid
189 return success; 191 return success;
190 } 192 }
191 193
192 public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) 194 public bool ReportAgent(UUID sessionID, UUID regionID)
195 {
196 return ReportAgent(sessionID, regionID, Vector3.Zero, Vector3.Zero);
197 }
198
199 protected bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt)
193 { 200 {
194 //m_log.DebugFormat("[SIMIAN PRESENCE CONNECTOR]: Updating session data for agent with sessionID " + sessionID); 201 //m_log.DebugFormat("[SIMIAN PRESENCE CONNECTOR]: Updating session data for agent with sessionID " + sessionID);
195 202
@@ -261,7 +268,23 @@ namespace OpenSim.Services.Connectors.SimianGrid
261 return presences.ToArray(); 268 return presences.ToArray();
262 } 269 }
263 270
264 public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) 271 #endregion IPresenceService
272
273 #region IGridUserService
274
275 public GridUserInfo LoggedIn(string userID)
276 {
277 // never implemented at the sim
278 return null;
279 }
280
281 public bool LoggedOut(string userID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
282 {
283 // Not needed for simian grid, event handler is doing it
284 return true;
285 }
286
287 public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
265 { 288 {
266 m_log.DebugFormat("[SIMIAN PRESENCE CONNECTOR]: Setting home location for user " + userID); 289 m_log.DebugFormat("[SIMIAN PRESENCE CONNECTOR]: Setting home location for user " + userID);
267 290
@@ -281,7 +304,35 @@ namespace OpenSim.Services.Connectors.SimianGrid
281 return success; 304 return success;
282 } 305 }
283 306
284 #endregion IPresenceService 307 public bool SetLastPosition(string userID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
308 {
309 // Not needed for simian grid, presence detection is doing it
310 return true;
311 }
312
313 public GridUserInfo GetGridUserInfo(string user)
314 {
315 m_log.DebugFormat("[SIMIAN PRESENCE CONNECTOR]: Requesting session data for agent " + user);
316
317 UUID userID = new UUID(user);
318 m_log.DebugFormat("[SIMIAN PRESENCE CONNECTOR]: Requesting user data for " + userID);
319
320 NameValueCollection requestArgs = new NameValueCollection
321 {
322 { "RequestMethod", "GetUser" },
323 { "UserID", userID.ToString() }
324 };
325
326 OSDMap userResponse = WebUtil.PostToService(m_serverUrl, requestArgs);
327 if (userResponse["Success"].AsBoolean())
328 return ResponseToGridUserInfo(userResponse);
329 else
330 m_log.Warn("[SIMIAN PRESENCE CONNECTOR]: Failed to retrieve user data for " + userID + ": " + userResponse["Message"].AsString());
331
332 return null;
333 }
334
335 #endregion
285 336
286 #region Presence Detection 337 #region Presence Detection
287 338
@@ -325,7 +376,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
325 SetLastLocation(client.SessionId); 376 SetLastLocation(client.SessionId);
326 } 377 }
327 378
328 LogoutAgent(client.SessionId, Vector3.Zero, Vector3.UnitX); 379 LogoutAgent(client.SessionId);
329 } 380 }
330 } 381 }
331 382
@@ -478,6 +529,31 @@ namespace OpenSim.Services.Connectors.SimianGrid
478 return info; 529 return info;
479 } 530 }
480 531
532 private GridUserInfo ResponseToGridUserInfo(OSDMap userResponse)
533 {
534 if (userResponse != null && userResponse["User"] is OSDMap)
535 {
536
537 GridUserInfo info = new GridUserInfo();
538
539 info.Online = true;
540 info.UserID = userResponse["UserID"].AsUUID().ToString();
541 info.LastRegionID = userResponse["SceneID"].AsUUID();
542 info.LastPosition = userResponse["ScenePosition"].AsVector3();
543 info.LastLookAt = userResponse["SceneLookAt"].AsVector3();
544
545 OSDMap user = (OSDMap)userResponse["User"];
546
547 info.Login = user["LastLoginDate"].AsDate();
548 info.Logout = user["LastLogoutDate"].AsDate();
549 DeserializeLocation(user["HomeLocation"].AsString(), out info.HomeRegionID, out info.HomePosition, out info.HomeLookAt);
550
551 return info;
552 }
553
554 return null;
555 }
556
481 private string SerializeLocation(UUID regionID, Vector3 position, Vector3 lookAt) 557 private string SerializeLocation(UUID regionID, Vector3 position, Vector3 lookAt)
482 { 558 {
483 return "{" + String.Format("\"SceneID\":\"{0}\",\"Position\":\"{1}\",\"LookAt\":\"{2}\"", regionID, position, lookAt) + "}"; 559 return "{" + String.Format("\"SceneID\":\"{0}\",\"Position\":\"{1}\",\"LookAt\":\"{2}\"", regionID, position, lookAt) + "}";
diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs
index 26f211b..3af7ef9 100644
--- a/OpenSim/Services/HypergridService/UserAgentService.cs
+++ b/OpenSim/Services/HypergridService/UserAgentService.cs
@@ -59,7 +59,7 @@ namespace OpenSim.Services.HypergridService
59 59
60 static bool m_Initialized = false; 60 static bool m_Initialized = false;
61 61
62 protected static IPresenceService m_PresenceService; 62 protected static IGridUserService m_GridUserService;
63 protected static IGridService m_GridService; 63 protected static IGridService m_GridService;
64 protected static GatekeeperServiceConnector m_GatekeeperConnector; 64 protected static GatekeeperServiceConnector m_GatekeeperConnector;
65 65
@@ -74,14 +74,14 @@ namespace OpenSim.Services.HypergridService
74 throw new Exception(String.Format("No section UserAgentService in config file")); 74 throw new Exception(String.Format("No section UserAgentService in config file"));
75 75
76 string gridService = serverConfig.GetString("GridService", String.Empty); 76 string gridService = serverConfig.GetString("GridService", String.Empty);
77 string presenceService = serverConfig.GetString("PresenceService", String.Empty); 77 string gridUserService = serverConfig.GetString("GridUserService", String.Empty);
78 78
79 if (gridService == string.Empty || presenceService == string.Empty) 79 if (gridService == string.Empty || gridUserService == string.Empty)
80 throw new Exception(String.Format("Incomplete specifications, UserAgent Service cannot function.")); 80 throw new Exception(String.Format("Incomplete specifications, UserAgent Service cannot function."));
81 81
82 Object[] args = new Object[] { config }; 82 Object[] args = new Object[] { config };
83 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args); 83 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
84 m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args); 84 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(gridUserService, args);
85 m_GatekeeperConnector = new GatekeeperServiceConnector(); 85 m_GatekeeperConnector = new GatekeeperServiceConnector();
86 86
87 m_Initialized = true; 87 m_Initialized = true;
@@ -95,15 +95,14 @@ namespace OpenSim.Services.HypergridService
95 m_log.DebugFormat("[USER AGENT SERVICE]: Request to get home region of user {0}", userID); 95 m_log.DebugFormat("[USER AGENT SERVICE]: Request to get home region of user {0}", userID);
96 96
97 GridRegion home = null; 97 GridRegion home = null;
98 PresenceInfo[] presences = m_PresenceService.GetAgents(new string[] { userID.ToString() }); 98 GridUserInfo uinfo = m_GridUserService.GetGridUserInfo(userID.ToString());
99 if (presences != null && presences.Length > 0) 99 if (uinfo != null)
100 { 100 {
101 UUID homeID = presences[0].HomeRegionID; 101 if (uinfo.HomeRegionID != UUID.Zero)
102 if (homeID != UUID.Zero)
103 { 102 {
104 home = m_GridService.GetRegionByUUID(UUID.Zero, homeID); 103 home = m_GridService.GetRegionByUUID(UUID.Zero, uinfo.HomeRegionID);
105 position = presences[0].HomePosition; 104 position = uinfo.HomePosition;
106 lookAt = presences[0].HomeLookAt; 105 lookAt = uinfo.HomeLookAt;
107 } 106 }
108 if (home == null) 107 if (home == null)
109 { 108 {
diff --git a/OpenSim/Services/Interfaces/IGridUserService.cs b/OpenSim/Services/Interfaces/IGridUserService.cs
index a7c2c6f..e629dff 100644
--- a/OpenSim/Services/Interfaces/IGridUserService.cs
+++ b/OpenSim/Services/Interfaces/IGridUserService.cs
@@ -37,39 +37,79 @@ namespace OpenSim.Services.Interfaces
37 public class GridUserInfo 37 public class GridUserInfo
38 { 38 {
39 public string UserID; 39 public string UserID;
40
40 public UUID HomeRegionID; 41 public UUID HomeRegionID;
41 public Vector3 HomePosition; 42 public Vector3 HomePosition;
42 public Vector3 HomeLookAt; 43 public Vector3 HomeLookAt;
43 44
45 public UUID LastRegionID;
46 public Vector3 LastPosition;
47 public Vector3 LastLookAt;
48
49 public bool Online;
50 public DateTime Login;
51 public DateTime Logout;
52
44 public GridUserInfo() {} 53 public GridUserInfo() {}
45 54
46 public GridUserInfo(Dictionary<string, object> kvp) 55 public GridUserInfo(Dictionary<string, object> kvp)
47 { 56 {
48 if (kvp.ContainsKey("UserID")) 57 if (kvp.ContainsKey("UserID"))
49 UserID = kvp["UserID"].ToString(); 58 UserID = kvp["UserID"].ToString();
59
50 if (kvp.ContainsKey("HomeRegionID")) 60 if (kvp.ContainsKey("HomeRegionID"))
51 UUID.TryParse(kvp["HomeRegionID"].ToString(), out HomeRegionID); 61 UUID.TryParse(kvp["HomeRegionID"].ToString(), out HomeRegionID);
52 if (kvp.ContainsKey("HomePosition")) 62 if (kvp.ContainsKey("HomePosition"))
53 Vector3.TryParse(kvp["HomePosition"].ToString(), out HomePosition); 63 Vector3.TryParse(kvp["HomePosition"].ToString(), out HomePosition);
54 if (kvp.ContainsKey("HomeLookAt")) 64 if (kvp.ContainsKey("HomeLookAt"))
55 Vector3.TryParse(kvp["HomeLookAt"].ToString(), out HomeLookAt); 65 Vector3.TryParse(kvp["HomeLookAt"].ToString(), out HomeLookAt);
66
67 if (kvp.ContainsKey("LastRegionID"))
68 UUID.TryParse(kvp["LastRegionID"].ToString(), out HomeRegionID);
69 if (kvp.ContainsKey("LastPosition"))
70 Vector3.TryParse(kvp["LastPosition"].ToString(), out LastPosition);
71 if (kvp.ContainsKey("LastLookAt"))
72 Vector3.TryParse(kvp["LastLookAt"].ToString(), out LastLookAt);
73
74 if (kvp.ContainsKey("Login"))
75 DateTime.TryParse(kvp["Login"].ToString(), out Login);
76 if (kvp.ContainsKey("Logout"))
77 DateTime.TryParse(kvp["Logout"].ToString(), out Logout);
78 if (kvp.ContainsKey("Online"))
79 Boolean.TryParse(kvp["Online"].ToString(), out Online);
80
56 } 81 }
57 82
58 public Dictionary<string, object> ToKeyValuePairs() 83 public Dictionary<string, object> ToKeyValuePairs()
59 { 84 {
60 Dictionary<string, object> result = new Dictionary<string, object>(); 85 Dictionary<string, object> result = new Dictionary<string, object>();
61 result["UserID"] = UserID; 86 result["UserID"] = UserID;
87
62 result["HomeRegionID"] = HomeRegionID.ToString(); 88 result["HomeRegionID"] = HomeRegionID.ToString();
63 result["HomePosition"] = HomePosition.ToString(); 89 result["HomePosition"] = HomePosition.ToString();
64 result["HomeLookAt"] = HomeLookAt.ToString(); 90 result["HomeLookAt"] = HomeLookAt.ToString();
65 91
92 result["LastRegionID"] = LastRegionID.ToString();
93 result["LastPosition"] = LastPosition.ToString();
94 result["LastLookAt"] = LastLookAt.ToString();
95
96 result["Online"] = Online.ToString();
97 result["Login"] = Login.ToString();
98 result["Logout"] = Logout.ToString();
99
100
66 return result; 101 return result;
67 } 102 }
68 } 103 }
69 104
70 public interface IGridUserService 105 public interface IGridUserService
71 { 106 {
107 GridUserInfo LoggedIn(string userID);
108 bool LoggedOut(string userID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt);
109
110 bool SetHome(string userID, UUID homeID, Vector3 homePosition, Vector3 homeLookAt);
111 bool SetLastPosition(string userID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt);
112
72 GridUserInfo GetGridUserInfo(string userID); 113 GridUserInfo GetGridUserInfo(string userID);
73 bool StoreGridUserInfo(GridUserInfo info);
74 } 114 }
75} \ No newline at end of file 115} \ No newline at end of file
diff --git a/OpenSim/Services/Interfaces/IPresenceService.cs b/OpenSim/Services/Interfaces/IPresenceService.cs
index b4c1859..abbae2c 100644
--- a/OpenSim/Services/Interfaces/IPresenceService.cs
+++ b/OpenSim/Services/Interfaces/IPresenceService.cs
@@ -55,23 +55,6 @@ namespace OpenSim.Services.Interfaces
55 UserID = kvp["UserID"].ToString(); 55 UserID = kvp["UserID"].ToString();
56 if (kvp.ContainsKey("RegionID")) 56 if (kvp.ContainsKey("RegionID"))
57 UUID.TryParse(kvp["RegionID"].ToString(), out RegionID); 57 UUID.TryParse(kvp["RegionID"].ToString(), out RegionID);
58 if (kvp.ContainsKey("login"))
59 DateTime.TryParse(kvp["login"].ToString(), out Login);
60 if (kvp.ContainsKey("logout"))
61 DateTime.TryParse(kvp["logout"].ToString(), out Logout);
62 if (kvp.ContainsKey("lookAt"))
63 Vector3.TryParse(kvp["lookAt"].ToString(), out LookAt);
64 if (kvp.ContainsKey("online"))
65 Boolean.TryParse(kvp["online"].ToString(), out Online);
66 if (kvp.ContainsKey("position"))
67 Vector3.TryParse(kvp["position"].ToString(), out Position);
68 if (kvp.ContainsKey("HomeRegionID"))
69 UUID.TryParse(kvp["HomeRegionID"].ToString(), out HomeRegionID);
70 if (kvp.ContainsKey("HomePosition"))
71 Vector3.TryParse(kvp["HomePosition"].ToString(), out HomePosition);
72 if (kvp.ContainsKey("HomeLookAt"))
73 Vector3.TryParse(kvp["HomeLookAt"].ToString(), out HomeLookAt);
74
75 } 58 }
76 59
77 public Dictionary<string, object> ToKeyValuePairs() 60 public Dictionary<string, object> ToKeyValuePairs()
@@ -79,14 +62,6 @@ namespace OpenSim.Services.Interfaces
79 Dictionary<string, object> result = new Dictionary<string, object>(); 62 Dictionary<string, object> result = new Dictionary<string, object>();
80 result["UserID"] = UserID; 63 result["UserID"] = UserID;
81 result["RegionID"] = RegionID.ToString(); 64 result["RegionID"] = RegionID.ToString();
82 result["online"] = Online.ToString();
83 result["login"] = Login.ToString();
84 result["logout"] = Logout.ToString();
85 result["position"] = Position.ToString();
86 result["lookAt"] = LookAt.ToString();
87 result["HomeRegionID"] = HomeRegionID.ToString();
88 result["HomePosition"] = HomePosition.ToString();
89 result["HomeLookAt"] = HomeLookAt.ToString();
90 65
91 return result; 66 return result;
92 } 67 }
@@ -115,11 +90,10 @@ namespace OpenSim.Services.Interfaces
115 public interface IPresenceService 90 public interface IPresenceService
116 { 91 {
117 bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID); 92 bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID);
118 bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookAt); 93 bool LogoutAgent(UUID sessionID);
119 bool LogoutRegionAgents(UUID regionID); 94 bool LogoutRegionAgents(UUID regionID);
120 95
121 bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt); 96 bool ReportAgent(UUID sessionID, UUID regionID);
122 bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt);
123 97
124 PresenceInfo GetAgent(UUID sessionID); 98 PresenceInfo GetAgent(UUID sessionID);
125 PresenceInfo[] GetAgents(string[] userIDs); 99 PresenceInfo[] GetAgents(string[] userIDs);
diff --git a/OpenSim/Services/LLLoginService/LLLoginResponse.cs b/OpenSim/Services/LLLoginService/LLLoginResponse.cs
index 0cd8f5b..dc5ca51 100644
--- a/OpenSim/Services/LLLoginService/LLLoginResponse.cs
+++ b/OpenSim/Services/LLLoginService/LLLoginResponse.cs
@@ -220,7 +220,7 @@ namespace OpenSim.Services.LLLoginService
220 SetDefaultValues(); 220 SetDefaultValues();
221 } 221 }
222 222
223 public LLLoginResponse(UserAccount account, AgentCircuitData aCircuit, PresenceInfo pinfo, 223 public LLLoginResponse(UserAccount account, AgentCircuitData aCircuit, GridUserInfo pinfo,
224 GridRegion destination, List<InventoryFolderBase> invSkel, FriendInfo[] friendsList, ILibraryService libService, 224 GridRegion destination, List<InventoryFolderBase> invSkel, FriendInfo[] friendsList, ILibraryService libService,
225 string where, string startlocation, Vector3 position, Vector3 lookAt, string message, 225 string where, string startlocation, Vector3 position, Vector3 lookAt, string message,
226 GridRegion home, IPEndPoint clientIP) 226 GridRegion home, IPEndPoint clientIP)
@@ -288,7 +288,7 @@ namespace OpenSim.Services.LLLoginService
288 } 288 }
289 } 289 }
290 290
291 private void FillOutHomeData(PresenceInfo pinfo, GridRegion home) 291 private void FillOutHomeData(GridUserInfo pinfo, GridRegion home)
292 { 292 {
293 int x = 1000 * (int)Constants.RegionSize, y = 1000 * (int)Constants.RegionSize; 293 int x = 1000 * (int)Constants.RegionSize, y = 1000 * (int)Constants.RegionSize;
294 if (home != null) 294 if (home != null)
diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs
index 9efdd11..398fe4f 100644
--- a/OpenSim/Services/LLLoginService/LLLoginService.cs
+++ b/OpenSim/Services/LLLoginService/LLLoginService.cs
@@ -53,6 +53,7 @@ namespace OpenSim.Services.LLLoginService
53 private static bool Initialized = false; 53 private static bool Initialized = false;
54 54
55 protected IUserAccountService m_UserAccountService; 55 protected IUserAccountService m_UserAccountService;
56 protected IGridUserService m_GridUserService;
56 protected IAuthenticationService m_AuthenticationService; 57 protected IAuthenticationService m_AuthenticationService;
57 protected IInventoryService m_InventoryService; 58 protected IInventoryService m_InventoryService;
58 protected IGridService m_GridService; 59 protected IGridService m_GridService;
@@ -82,6 +83,7 @@ namespace OpenSim.Services.LLLoginService
82 throw new Exception(String.Format("No section LoginService in config file")); 83 throw new Exception(String.Format("No section LoginService in config file"));
83 84
84 string accountService = m_LoginServerConfig.GetString("UserAccountService", String.Empty); 85 string accountService = m_LoginServerConfig.GetString("UserAccountService", String.Empty);
86 string gridUserService = m_LoginServerConfig.GetString("GridUserService", String.Empty);
85 string agentService = m_LoginServerConfig.GetString("UserAgentService", String.Empty); 87 string agentService = m_LoginServerConfig.GetString("UserAgentService", String.Empty);
86 string authService = m_LoginServerConfig.GetString("AuthenticationService", String.Empty); 88 string authService = m_LoginServerConfig.GetString("AuthenticationService", String.Empty);
87 string invService = m_LoginServerConfig.GetString("InventoryService", String.Empty); 89 string invService = m_LoginServerConfig.GetString("InventoryService", String.Empty);
@@ -105,8 +107,10 @@ namespace OpenSim.Services.LLLoginService
105 107
106 Object[] args = new Object[] { config }; 108 Object[] args = new Object[] { config };
107 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args); 109 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args);
110 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(gridUserService, args);
108 m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authService, args); 111 m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authService, args);
109 m_InventoryService = ServerUtils.LoadPlugin<IInventoryService>(invService, args); 112 m_InventoryService = ServerUtils.LoadPlugin<IInventoryService>(invService, args);
113
110 if (gridService != string.Empty) 114 if (gridService != string.Empty)
111 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args); 115 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
112 if (presenceService != string.Empty) 116 if (presenceService != string.Empty)
@@ -277,8 +281,6 @@ namespace OpenSim.Services.LLLoginService
277 // 281 //
278 // Login the presence 282 // Login the presence
279 // 283 //
280 PresenceInfo presence = null;
281 GridRegion home = null;
282 if (m_PresenceService != null) 284 if (m_PresenceService != null)
283 { 285 {
284 success = m_PresenceService.LoginAgent(account.PrincipalID.ToString(), session, secureSession); 286 success = m_PresenceService.LoginAgent(account.PrincipalID.ToString(), session, secureSession);
@@ -287,28 +289,35 @@ namespace OpenSim.Services.LLLoginService
287 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: could not login presence"); 289 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: could not login presence");
288 return LLFailedLoginResponse.GridProblem; 290 return LLFailedLoginResponse.GridProblem;
289 } 291 }
290
291 // Get the updated presence info
292 presence = m_PresenceService.GetAgent(session);
293
294 // Get the home region
295 if ((presence.HomeRegionID != UUID.Zero) && m_GridService != null)
296 {
297 home = m_GridService.GetRegionByUUID(scopeID, presence.HomeRegionID);
298 }
299 } 292 }
300 293
301 // 294 //
295 // Change Online status and get the home region
296 //
297 GridRegion home = null;
298 GridUserInfo guinfo = m_GridUserService.LoggedIn(account.PrincipalID.ToString());
299 if (guinfo != null && (guinfo.HomeRegionID != UUID.Zero) && m_GridService != null)
300 {
301 home = m_GridService.GetRegionByUUID(scopeID, guinfo.HomeRegionID);
302 }
303 if (guinfo == null)
304 {
305 // something went wrong, make something up, so that we don't have to test this anywhere else
306 guinfo = new GridUserInfo();
307 guinfo.LastPosition = guinfo.HomePosition = new Vector3(128, 128, 30);
308 }
309
310 //
302 // Find the destination region/grid 311 // Find the destination region/grid
303 // 312 //
304 string where = string.Empty; 313 string where = string.Empty;
305 Vector3 position = Vector3.Zero; 314 Vector3 position = Vector3.Zero;
306 Vector3 lookAt = Vector3.Zero; 315 Vector3 lookAt = Vector3.Zero;
307 GridRegion gatekeeper = null; 316 GridRegion gatekeeper = null;
308 GridRegion destination = FindDestination(account, scopeID, presence, session, startLocation, out gatekeeper, out where, out position, out lookAt); 317 GridRegion destination = FindDestination(account, scopeID, guinfo, session, startLocation, home, out gatekeeper, out where, out position, out lookAt);
309 if (destination == null) 318 if (destination == null)
310 { 319 {
311 m_PresenceService.LogoutAgent(session, presence.Position, presence.LookAt); 320 m_PresenceService.LogoutAgent(session);
312 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: destination not found"); 321 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: destination not found");
313 return LLFailedLoginResponse.GridProblem; 322 return LLFailedLoginResponse.GridProblem;
314 } 323 }
@@ -330,7 +339,7 @@ namespace OpenSim.Services.LLLoginService
330 339
331 if (aCircuit == null) 340 if (aCircuit == null)
332 { 341 {
333 m_PresenceService.LogoutAgent(session, presence.Position, presence.LookAt); 342 m_PresenceService.LogoutAgent(session);
334 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: {0}", reason); 343 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: {0}", reason);
335 return LLFailedLoginResponse.AuthorizationProblem; 344 return LLFailedLoginResponse.AuthorizationProblem;
336 345
@@ -346,7 +355,7 @@ namespace OpenSim.Services.LLLoginService
346 // 355 //
347 // Finally, fill out the response and return it 356 // Finally, fill out the response and return it
348 // 357 //
349 LLLoginResponse response = new LLLoginResponse(account, aCircuit, presence, destination, inventorySkel, friendsList, m_LibraryService, 358 LLLoginResponse response = new LLLoginResponse(account, aCircuit, guinfo, destination, inventorySkel, friendsList, m_LibraryService,
350 where, startLocation, position, lookAt, m_WelcomeMessage, home, clientIP); 359 where, startLocation, position, lookAt, m_WelcomeMessage, home, clientIP);
351 360
352 m_log.DebugFormat("[LLOGIN SERVICE]: All clear. Sending login response to client."); 361 m_log.DebugFormat("[LLOGIN SERVICE]: All clear. Sending login response to client.");
@@ -356,12 +365,12 @@ namespace OpenSim.Services.LLLoginService
356 { 365 {
357 m_log.WarnFormat("[LLOGIN SERVICE]: Exception processing login for {0} {1}: {2} {3}", firstName, lastName, e.ToString(), e.StackTrace); 366 m_log.WarnFormat("[LLOGIN SERVICE]: Exception processing login for {0} {1}: {2} {3}", firstName, lastName, e.ToString(), e.StackTrace);
358 if (m_PresenceService != null) 367 if (m_PresenceService != null)
359 m_PresenceService.LogoutAgent(session, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); 368 m_PresenceService.LogoutAgent(session);
360 return LLFailedLoginResponse.InternalError; 369 return LLFailedLoginResponse.InternalError;
361 } 370 }
362 } 371 }
363 372
364 protected GridRegion FindDestination(UserAccount account, UUID scopeID, PresenceInfo pinfo, UUID sessionID, string startLocation, out GridRegion gatekeeper, out string where, out Vector3 position, out Vector3 lookAt) 373 protected GridRegion FindDestination(UserAccount account, UUID scopeID, GridUserInfo pinfo, UUID sessionID, string startLocation, GridRegion home, out GridRegion gatekeeper, out string where, out Vector3 position, out Vector3 lookAt)
365 { 374 {
366 m_log.DebugFormat("[LLOGIN SERVICE]: FindDestination for start location {0}", startLocation); 375 m_log.DebugFormat("[LLOGIN SERVICE]: FindDestination for start location {0}", startLocation);
367 376
@@ -383,7 +392,7 @@ namespace OpenSim.Services.LLLoginService
383 392
384 bool tryDefaults = false; 393 bool tryDefaults = false;
385 394
386 if (pinfo.HomeRegionID.Equals(UUID.Zero)) 395 if (home == null)
387 { 396 {
388 m_log.WarnFormat( 397 m_log.WarnFormat(
389 "[LLOGIN SERVICE]: User {0} {1} tried to login to a 'home' start location but they have none set", 398 "[LLOGIN SERVICE]: User {0} {1} tried to login to a 'home' start location but they have none set",
@@ -393,16 +402,10 @@ namespace OpenSim.Services.LLLoginService
393 } 402 }
394 else 403 else
395 { 404 {
396 region = m_GridService.GetRegionByUUID(scopeID, pinfo.HomeRegionID); 405 region = home;
397 406
398 if (null == region) 407 position = pinfo.HomePosition;
399 { 408 lookAt = pinfo.HomeLookAt;
400 m_log.WarnFormat(
401 "[LLOGIN SERVICE]: User {0} {1} has a recorded home region of {2} but this cannot be found by the grid service",
402 account.FirstName, account.LastName, pinfo.HomeRegionID);
403
404 tryDefaults = true;
405 }
406 } 409 }
407 410
408 if (tryDefaults) 411 if (tryDefaults)
@@ -438,7 +441,7 @@ namespace OpenSim.Services.LLLoginService
438 441
439 GridRegion region = null; 442 GridRegion region = null;
440 443
441 if (pinfo.RegionID.Equals(UUID.Zero) || (region = m_GridService.GetRegionByUUID(scopeID, pinfo.RegionID)) == null) 444 if (pinfo.LastRegionID.Equals(UUID.Zero) || (region = m_GridService.GetRegionByUUID(scopeID, pinfo.LastRegionID)) == null)
442 { 445 {
443 List<GridRegion> defaults = m_GridService.GetDefaultRegions(scopeID); 446 List<GridRegion> defaults = m_GridService.GetDefaultRegions(scopeID);
444 if (defaults != null && defaults.Count > 0) 447 if (defaults != null && defaults.Count > 0)
@@ -460,8 +463,8 @@ namespace OpenSim.Services.LLLoginService
460 } 463 }
461 else 464 else
462 { 465 {
463 position = pinfo.Position; 466 position = pinfo.LastPosition;
464 lookAt = pinfo.LookAt; 467 lookAt = pinfo.LastLookAt;
465 } 468 }
466 469
467 return region; 470 return region;
diff --git a/OpenSim/Services/PresenceService/PresenceService.cs b/OpenSim/Services/PresenceService/PresenceService.cs
index ea8d673..7e7e98e 100644
--- a/OpenSim/Services/PresenceService/PresenceService.cs
+++ b/OpenSim/Services/PresenceService/PresenceService.cs
@@ -54,8 +54,6 @@ namespace OpenSim.Services.PresenceService
54 public bool LoginAgent(string userID, UUID sessionID, 54 public bool LoginAgent(string userID, UUID sessionID,
55 UUID secureSessionID) 55 UUID secureSessionID)
56 { 56 {
57 m_Database.Prune(userID);
58
59 PresenceData[] d = m_Database.Get("UserID", userID); 57 PresenceData[] d = m_Database.Get("UserID", userID);
60 58
61 PresenceData data = new PresenceData(); 59 PresenceData data = new PresenceData();
@@ -65,24 +63,6 @@ namespace OpenSim.Services.PresenceService
65 data.SessionID = sessionID; 63 data.SessionID = sessionID;
66 data.Data = new Dictionary<string, string>(); 64 data.Data = new Dictionary<string, string>();
67 data.Data["SecureSessionID"] = secureSessionID.ToString(); 65 data.Data["SecureSessionID"] = secureSessionID.ToString();
68 data.Data["Online"] = "true";
69 data.Data["Login"] = Util.UnixTimeSinceEpoch().ToString();
70 if (d != null && d.Length > 0)
71 {
72 data.Data["HomeRegionID"] = d[0].Data["HomeRegionID"];
73 data.Data["HomePosition"] = d[0].Data["HomePosition"];
74 data.Data["HomeLookAt"] = d[0].Data["HomeLookAt"];
75 data.Data["Position"] = d[0].Data["Position"];
76 data.Data["LookAt"] = d[0].Data["LookAt"];
77
78 data.RegionID = d[0].RegionID;
79 }
80 else
81 {
82 data.Data["HomeRegionID"] = UUID.Zero.ToString();
83 data.Data["HomePosition"] = new Vector3(128, 128, 0).ToString();
84 data.Data["HomeLookAt"] = new Vector3(0, 1, 0).ToString();
85 }
86 66
87 m_Database.Store(data); 67 m_Database.Store(data);
88 68
@@ -91,28 +71,10 @@ namespace OpenSim.Services.PresenceService
91 return true; 71 return true;
92 } 72 }
93 73
94 public bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookat) 74 public bool LogoutAgent(UUID sessionID)
95 { 75 {
96 PresenceData data = m_Database.Get(sessionID); 76 m_log.DebugFormat("[PRESENCE SERVICE]: Session {0} logout", sessionID);
97 if (data == null) 77 return m_Database.Delete("SessionID", sessionID.ToString());
98 return false;
99
100 PresenceData[] d = m_Database.Get("UserID", data.UserID);
101
102 m_log.DebugFormat("[PRESENCE SERVICE]: LogoutAgent {0} with {1} sessions currently present", data.UserID, d.Length);
103 if (d.Length > 1)
104 {
105 m_Database.Delete("UserID", data.UserID);
106 }
107
108 data.Data["Online"] = "false";
109 data.Data["Logout"] = Util.UnixTimeSinceEpoch().ToString();
110 data.Data["Position"] = position.ToString();
111 data.Data["LookAt"] = lookat.ToString();
112
113 m_Database.Store(data);
114
115 return true;
116 } 78 }
117 79
118 public bool LogoutRegionAgents(UUID regionID) 80 public bool LogoutRegionAgents(UUID regionID)
@@ -123,7 +85,7 @@ namespace OpenSim.Services.PresenceService
123 } 85 }
124 86
125 87
126 public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) 88 public bool ReportAgent(UUID sessionID, UUID regionID)
127 { 89 {
128 m_log.DebugFormat("[PRESENCE SERVICE]: ReportAgent with session {0} in region {1}", sessionID, regionID); 90 m_log.DebugFormat("[PRESENCE SERVICE]: ReportAgent with session {0} in region {1}", sessionID, regionID);
129 try 91 try
@@ -134,14 +96,7 @@ namespace OpenSim.Services.PresenceService
134 if (pdata.Data == null) 96 if (pdata.Data == null)
135 return false; 97 return false;
136 98
137 if (!pdata.Data.ContainsKey("Online") || (pdata.Data.ContainsKey("Online") && pdata.Data["Online"] == "false")) 99 return m_Database.ReportAgent(sessionID, regionID);
138 {
139 m_log.WarnFormat("[PRESENCE SERVICE]: Someone tried to report presence of an agent who's not online");
140 return false;
141 }
142
143 return m_Database.ReportAgent(sessionID, regionID,
144 position.ToString(), lookAt.ToString());
145 } 100 }
146 catch (Exception e) 101 catch (Exception e)
147 { 102 {
@@ -160,22 +115,10 @@ namespace OpenSim.Services.PresenceService
160 115
161 ret.UserID = data.UserID; 116 ret.UserID = data.UserID;
162 ret.RegionID = data.RegionID; 117 ret.RegionID = data.RegionID;
163 if (data.Data.ContainsKey("Online"))
164 ret.Online = bool.Parse(data.Data["Online"]);
165 if (data.Data.ContainsKey("Login"))
166 ret.Login = Util.ToDateTime(Convert.ToInt32(data.Data["Login"]));
167 if (data.Data.ContainsKey("Logout"))
168 ret.Logout = Util.ToDateTime(Convert.ToInt32(data.Data["Logout"]));
169 if (data.Data.ContainsKey("Position")) 118 if (data.Data.ContainsKey("Position"))
170 ret.Position = Vector3.Parse(data.Data["Position"]); 119 ret.Position = Vector3.Parse(data.Data["Position"]);
171 if (data.Data.ContainsKey("LookAt")) 120 if (data.Data.ContainsKey("LookAt"))
172 ret.LookAt = Vector3.Parse(data.Data["LookAt"]); 121 ret.LookAt = Vector3.Parse(data.Data["LookAt"]);
173 if (data.Data.ContainsKey("HomeRegionID"))
174 ret.HomeRegionID = new UUID(data.Data["HomeRegionID"]);
175 if (data.Data.ContainsKey("HomePosition"))
176 ret.HomePosition = Vector3.Parse(data.Data["HomePosition"]);
177 if (data.Data.ContainsKey("HomeLookAt"))
178 ret.HomeLookAt = Vector3.Parse(data.Data["HomeLookAt"]);
179 122
180 return ret; 123 return ret;
181 } 124 }
@@ -195,16 +138,8 @@ namespace OpenSim.Services.PresenceService
195 138
196 ret.UserID = d.UserID; 139 ret.UserID = d.UserID;
197 ret.RegionID = d.RegionID; 140 ret.RegionID = d.RegionID;
198 ret.Online = bool.Parse(d.Data["Online"]);
199 ret.Login = Util.ToDateTime(Convert.ToInt32(
200 d.Data["Login"]));
201 ret.Logout = Util.ToDateTime(Convert.ToInt32(
202 d.Data["Logout"]));
203 ret.Position = Vector3.Parse(d.Data["Position"]); 141 ret.Position = Vector3.Parse(d.Data["Position"]);
204 ret.LookAt = Vector3.Parse(d.Data["LookAt"]); 142 ret.LookAt = Vector3.Parse(d.Data["LookAt"]);
205 ret.HomeRegionID = new UUID(d.Data["HomeRegionID"]);
206 ret.HomePosition = Vector3.Parse(d.Data["HomePosition"]);
207 ret.HomeLookAt = Vector3.Parse(d.Data["HomeLookAt"]);
208 143
209 info.Add(ret); 144 info.Add(ret);
210 } 145 }
@@ -214,9 +149,5 @@ namespace OpenSim.Services.PresenceService
214 return info.ToArray(); 149 return info.ToArray();
215 } 150 }
216 151
217 public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
218 {
219 return m_Database.SetHomeLocation(userID, regionID, position, lookAt);
220 }
221 } 152 }
222} 153}
diff --git a/OpenSim/Services/UserAccountService/GridUserService.cs b/OpenSim/Services/UserAccountService/GridUserService.cs
index c6e33bb..697ba63 100644
--- a/OpenSim/Services/UserAccountService/GridUserService.cs
+++ b/OpenSim/Services/UserAccountService/GridUserService.cs
@@ -31,6 +31,7 @@ using System.Reflection;
31using Nini.Config; 31using Nini.Config;
32using OpenSim.Data; 32using OpenSim.Data;
33using OpenSim.Services.Interfaces; 33using OpenSim.Services.Interfaces;
34using OpenSim.Framework;
34using OpenSim.Framework.Console; 35using OpenSim.Framework.Console;
35using GridRegion = OpenSim.Services.Interfaces.GridRegion; 36using GridRegion = OpenSim.Services.Interfaces.GridRegion;
36 37
@@ -50,27 +51,109 @@ namespace OpenSim.Services.UserAccountService
50 51
51 public GridUserInfo GetGridUserInfo(string userID) 52 public GridUserInfo GetGridUserInfo(string userID)
52 { 53 {
53 GridUserData d = m_Database.GetGridUserData(userID); 54 GridUserData d = m_Database.Get(userID);
54 55
56 if (d == null)
57 return null;
58
55 GridUserInfo info = new GridUserInfo(); 59 GridUserInfo info = new GridUserInfo();
56 info.UserID = d.UserID; 60 info.UserID = d.UserID;
57 info.HomeRegionID = new UUID(d.Data["HomeRegionID"]); 61 info.HomeRegionID = new UUID(d.Data["HomeRegionID"]);
58 info.HomePosition = Vector3.Parse(d.Data["HomePosition"]); 62 info.HomePosition = Vector3.Parse(d.Data["HomePosition"]);
59 info.HomeLookAt = Vector3.Parse(d.Data["HomeLookAt"]); 63 info.HomeLookAt = Vector3.Parse(d.Data["HomeLookAt"]);
60 64
65 info.LastRegionID = new UUID(d.Data["LastRegionID"]);
66 info.LastPosition = Vector3.Parse(d.Data["LastPosition"]);
67 info.LastLookAt = Vector3.Parse(d.Data["LastLookAt"]);
68
69 info.Online = bool.Parse(d.Data["Online"]);
70 info.Login = Util.ToDateTime(Convert.ToInt32(d.Data["Login"]));
71 info.Logout = Util.ToDateTime(Convert.ToInt32(d.Data["Logout"]));
72
61 return info; 73 return info;
62 } 74 }
63 75
64 public bool StoreGridUserInfo(GridUserInfo info) 76 public GridUserInfo LoggedIn(string userID)
77 {
78 m_log.DebugFormat("[GRID USER SERVICE]: User {0} is online", userID);
79 GridUserData d = m_Database.Get(userID);
80
81 if (d == null)
82 {
83 d = new GridUserData();
84 d.UserID = userID;
85 }
86
87 d.Data["Online"] = true.ToString();
88 d.Data["Login"] = Util.UnixTimeSinceEpoch().ToString();
89
90 m_Database.Store(d);
91
92 return GetGridUserInfo(userID);
93 }
94
95 public bool LoggedOut(string userID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
96 {
97 m_log.DebugFormat("[GRID USER SERVICE]: User {0} is offline", userID);
98 GridUserData d = m_Database.Get(userID);
99
100 if (d == null)
101 {
102 d = new GridUserData();
103 d.UserID = userID;
104 }
105
106 d.Data["Online"] = false.ToString();
107 d.Data["Logout"] = Util.UnixTimeSinceEpoch().ToString();
108 d.Data["LastRegionID"] = regionID.ToString();
109 d.Data["LastPosition"] = lastPosition.ToString();
110 d.Data["LastLookAt"] = lastLookAt.ToString();
111
112 return m_Database.Store(d);
113 }
114
115 protected bool StoreGridUserInfo(GridUserInfo info)
65 { 116 {
66 GridUserData d = new GridUserData(); 117 GridUserData d = new GridUserData();
67 118
68 d.Data["UserID"] = info.UserID;
69 d.Data["HomeRegionID"] = info.HomeRegionID.ToString(); 119 d.Data["HomeRegionID"] = info.HomeRegionID.ToString();
70 d.Data["HomePosition"] = info.HomePosition.ToString(); 120 d.Data["HomePosition"] = info.HomePosition.ToString();
71 d.Data["HomeLookAt"] = info.HomeLookAt.ToString(); 121 d.Data["HomeLookAt"] = info.HomeLookAt.ToString();
72 122
73 return m_Database.StoreGridUserData(d); 123 return m_Database.Store(d);
124 }
125
126 public bool SetHome(string userID, UUID homeID, Vector3 homePosition, Vector3 homeLookAt)
127 {
128 GridUserData d = m_Database.Get(userID);
129 if (d == null)
130 {
131 d = new GridUserData();
132 d.UserID = userID;
133 }
134
135 d.Data["HomeRegionID"] = homeID.ToString();
136 d.Data["HomePosition"] = homePosition.ToString();
137 d.Data["HomeLookAt"] = homeLookAt.ToString();
138
139 return m_Database.Store(d);
140 }
141
142 public bool SetLastPosition(string userID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
143 {
144 //m_log.DebugFormat("[Grid User Service]: SetLastPosition for {0}", userID);
145 GridUserData d = m_Database.Get(userID);
146 if (d == null)
147 {
148 d = new GridUserData();
149 d.UserID = userID;
150 }
151
152 d.Data["LastRegionID"] = regionID.ToString();
153 d.Data["LastPosition"] = lastPosition.ToString();
154 d.Data["LastLookAt"] = lastLookAt.ToString();
155
156 return m_Database.Store(d);
74 } 157 }
75 } 158 }
76} \ No newline at end of file 159} \ No newline at end of file
diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs
index 35e2826..6923293 100644
--- a/OpenSim/Services/UserAccountService/UserAccountService.cs
+++ b/OpenSim/Services/UserAccountService/UserAccountService.cs
@@ -46,7 +46,7 @@ namespace OpenSim.Services.UserAccountService
46 46
47 protected IGridService m_GridService; 47 protected IGridService m_GridService;
48 protected IAuthenticationService m_AuthenticationService; 48 protected IAuthenticationService m_AuthenticationService;
49 protected IPresenceService m_PresenceService; 49 protected IGridUserService m_GridUserService;
50 protected IInventoryService m_InventoryService; 50 protected IInventoryService m_InventoryService;
51 51
52 public UserAccountService(IConfigSource config) 52 public UserAccountService(IConfigSource config)
@@ -69,9 +69,9 @@ namespace OpenSim.Services.UserAccountService
69 if (authServiceDll != string.Empty) 69 if (authServiceDll != string.Empty)
70 m_AuthenticationService = LoadPlugin<IAuthenticationService>(authServiceDll, new Object[] { config }); 70 m_AuthenticationService = LoadPlugin<IAuthenticationService>(authServiceDll, new Object[] { config });
71 71
72 string presenceServiceDll = userConfig.GetString("PresenceService", string.Empty); 72 string presenceServiceDll = userConfig.GetString("GridUserService", string.Empty);
73 if (presenceServiceDll != string.Empty) 73 if (presenceServiceDll != string.Empty)
74 m_PresenceService = LoadPlugin<IPresenceService>(presenceServiceDll, new Object[] { config }); 74 m_GridUserService = LoadPlugin<IGridUserService>(presenceServiceDll, new Object[] { config });
75 75
76 string invServiceDll = userConfig.GetString("InventoryService", string.Empty); 76 string invServiceDll = userConfig.GetString("InventoryService", string.Empty);
77 if (invServiceDll != string.Empty) 77 if (invServiceDll != string.Empty)
@@ -333,8 +333,8 @@ namespace OpenSim.Services.UserAccountService
333 if (defaultRegions != null && defaultRegions.Count >= 1) 333 if (defaultRegions != null && defaultRegions.Count >= 1)
334 home = defaultRegions[0]; 334 home = defaultRegions[0];
335 335
336 if (m_PresenceService != null && home != null) 336 if (m_GridUserService != null && home != null)
337 m_PresenceService.SetHomeLocation(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); 337 m_GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
338 else 338 else
339 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.", 339 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.",
340 firstName, lastName); 340 firstName, lastName);
diff --git a/OpenSim/Tests/Clients/Presence/PresenceClient.cs b/OpenSim/Tests/Clients/Presence/PresenceClient.cs
index 4f959f6..0f6b80e 100644
--- a/OpenSim/Tests/Clients/Presence/PresenceClient.cs
+++ b/OpenSim/Tests/Clients/Presence/PresenceClient.cs
@@ -77,7 +77,7 @@ namespace OpenSim.Tests.Clients.PresenceClient
77 pinfo.UserID, pinfo.Online, pinfo.RegionID, pinfo.HomeRegionID); 77 pinfo.UserID, pinfo.Online, pinfo.RegionID, pinfo.HomeRegionID);
78 78
79 System.Console.WriteLine("\n"); 79 System.Console.WriteLine("\n");
80 success = m_Connector.ReportAgent(session1, region1, new Vector3(128, 128, 128), new Vector3(4, 5, 6)); 80 success = m_Connector.ReportAgent(session1, region1);
81 if (success) 81 if (success)
82 m_log.InfoFormat("[PRESENCE CLIENT]: Successfully reported session {0} in region {1}", user1, region1); 82 m_log.InfoFormat("[PRESENCE CLIENT]: Successfully reported session {0} in region {1}", user1, region1);
83 else 83 else
@@ -90,20 +90,7 @@ namespace OpenSim.Tests.Clients.PresenceClient
90 pinfo.UserID, pinfo.Online, pinfo.RegionID, pinfo.HomeRegionID); 90 pinfo.UserID, pinfo.Online, pinfo.RegionID, pinfo.HomeRegionID);
91 91
92 System.Console.WriteLine("\n"); 92 System.Console.WriteLine("\n");
93 success = m_Connector.SetHomeLocation(user1.ToString(), region1, new Vector3(128, 128, 128), new Vector3(4, 5, 6)); 93 success = m_Connector.LogoutAgent(session1);
94 if (success)
95 m_log.InfoFormat("[PRESENCE CLIENT]: Successfully set home for user {0} in region {1}", user1, region1);
96 else
97 m_log.InfoFormat("[PRESENCE CLIENT]: failed to set home for user {0}", user1);
98 pinfo = m_Connector.GetAgent(session1);
99 if (pinfo == null)
100 m_log.InfoFormat("[PRESENCE CLIENT]: Unable to retrieve presence for {0} for third time", user1);
101 else
102 m_log.InfoFormat("[PRESENCE CLIENT]: Presence retrieved correctly: userID={0}; Online={1}; regionID={2}; homeRegion={3}",
103 pinfo.UserID, pinfo.Online, pinfo.RegionID, pinfo.HomeRegionID);
104
105 System.Console.WriteLine("\n");
106 success = m_Connector.LogoutAgent(session1, Vector3.Zero, Vector3.UnitY);
107 if (success) 94 if (success)
108 m_log.InfoFormat("[PRESENCE CLIENT]: Successfully logged out user {0}", user1); 95 m_log.InfoFormat("[PRESENCE CLIENT]: Successfully logged out user {0}", user1);
109 else 96 else
@@ -116,7 +103,7 @@ namespace OpenSim.Tests.Clients.PresenceClient
116 pinfo.UserID, pinfo.Online, pinfo.RegionID, pinfo.HomeRegionID); 103 pinfo.UserID, pinfo.Online, pinfo.RegionID, pinfo.HomeRegionID);
117 104
118 System.Console.WriteLine("\n"); 105 System.Console.WriteLine("\n");
119 success = m_Connector.ReportAgent(session1, UUID.Random(), Vector3.Zero, Vector3.Zero); 106 success = m_Connector.ReportAgent(session1, UUID.Random());
120 if (success) 107 if (success)
121 m_log.InfoFormat("[PRESENCE CLIENT]: Report agent succeeded, but this is wrong"); 108 m_log.InfoFormat("[PRESENCE CLIENT]: Report agent succeeded, but this is wrong");
122 else 109 else