opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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 using System;
28 using System.Collections.Generic;
29 using System.Reflection;
30  
31 using OpenSim.Region.Framework.Interfaces;
32 using OpenSim.Region.Framework.Scenes;
33 using OpenSim.Server.Base;
34 using OpenSim.Services.Interfaces;
35 using OpenSim.Services.Connectors;
36  
37 using OpenMetaverse;
38 using log4net;
39 using Mono.Addins;
40 using Nini.Config;
41  
42 namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser
43 {
44 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteGridUserServicesConnector")]
45 public class RemoteGridUserServicesConnector : ISharedRegionModule, IGridUserService
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48  
49 private const int KEEPTIME = 30; // 30 secs
50 private ExpiringCache<string, GridUserInfo> m_Infos = new ExpiringCache<string, GridUserInfo>();
51  
52 #region ISharedRegionModule
53  
54 private bool m_Enabled = false;
55  
56 private ActivityDetector m_ActivityDetector;
57 private IGridUserService m_RemoteConnector;
58  
59 public Type ReplaceableInterface
60 {
61 get { return null; }
62 }
63  
64 public string Name
65 {
66 get { return "RemoteGridUserServicesConnector"; }
67 }
68  
69 public void Initialise(IConfigSource source)
70 {
71 IConfig moduleConfig = source.Configs["Modules"];
72 if (moduleConfig != null)
73 {
74 string name = moduleConfig.GetString("GridUserServices", "");
75 if (name == Name)
76 {
77 m_RemoteConnector = new GridUserServicesConnector(source);
78  
79 m_Enabled = true;
80  
81 m_ActivityDetector = new ActivityDetector(this);
82  
83 m_log.Info("[REMOTE GRID USER CONNECTOR]: Remote grid user enabled");
84 }
85 }
86  
87 }
88  
89 public void PostInitialise()
90 {
91 }
92  
93 public void Close()
94 {
95 }
96  
97 public void AddRegion(Scene scene)
98 {
99 if (!m_Enabled)
100 return;
101  
102 scene.RegisterModuleInterface<IGridUserService>(this);
103 m_ActivityDetector.AddRegion(scene);
104  
105 m_log.InfoFormat("[REMOTE GRID USER CONNECTOR]: Enabled remote grid user for region {0}", scene.RegionInfo.RegionName);
106  
107 }
108  
109 public void RemoveRegion(Scene scene)
110 {
111 if (!m_Enabled)
112 return;
113  
114 m_ActivityDetector.RemoveRegion(scene);
115 }
116  
117 public void RegionLoaded(Scene scene)
118 {
119 if (!m_Enabled)
120 return;
121  
122 }
123  
124 #endregion
125  
126 #region IGridUserService
127  
128 public GridUserInfo LoggedIn(string userID)
129 {
130 m_log.Warn("[REMOTE GRID USER CONNECTOR]: LoggedIn not implemented at the simulators");
131 return null;
132 }
133  
134 public bool LoggedOut(string userID, UUID sessionID, UUID region, Vector3 position, Vector3 lookat)
135 {
136 if (m_Infos.Contains(userID))
137 m_Infos.Remove(userID);
138  
139 return m_RemoteConnector.LoggedOut(userID, sessionID, region, position, lookat);
140 }
141  
142  
143 public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
144 {
145 if (m_RemoteConnector.SetHome(userID, regionID, position, lookAt))
146 {
147 // Update the cache too
148 GridUserInfo info = null;
149 if (m_Infos.TryGetValue(userID, out info))
150 {
151 info.HomeRegionID = regionID;
152 info.HomePosition = position;
153 info.HomeLookAt = lookAt;
154 }
155 return true;
156 }
157  
158 return false;
159 }
160  
161 public bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt)
162 {
163 if (m_RemoteConnector.SetLastPosition(userID, sessionID, regionID, position, lookAt))
164 {
165 // Update the cache too
166 GridUserInfo info = null;
167 if (m_Infos.TryGetValue(userID, out info))
168 {
169 info.LastRegionID = regionID;
170 info.LastPosition = position;
171 info.LastLookAt = lookAt;
172 }
173 return true;
174 }
175  
176 return false;
177 }
178  
179 public GridUserInfo GetGridUserInfo(string userID)
180 {
181 GridUserInfo info = null;
182 if (m_Infos.TryGetValue(userID, out info))
183 return info;
184  
185 info = m_RemoteConnector.GetGridUserInfo(userID);
186  
187 m_Infos.AddOrUpdate(userID, info, KEEPTIME);
188  
189 return info;
190 }
191  
192 public GridUserInfo[] GetGridUserInfo(string[] userID)
193 {
194 return m_RemoteConnector.GetGridUserInfo(userID);
195 }
196  
197 #endregion
198  
199 }
200 }