clockwerk-opensim-stable – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27  
28 using System;
29 using System.Collections.Generic;
30 using System.Reflection;
31 using log4net;
32 using Nini.Config;
33 using OpenMetaverse;
34 using OpenMetaverse.StructuredData;
35 using Mono.Addins;
36 using OpenSim.Framework;
37 using OpenSim.Region.CoreModules.World.WorldMap;
38 using OpenSim.Region.Framework.Interfaces;
39 using OpenSim.Region.Framework.Scenes;
40 using GridRegion = OpenSim.Services.Interfaces.GridRegion;
41  
42 namespace OpenSim.Region.CoreModules.Hypergrid
43 {
44 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "HGWorldMapModule")]
45 public class HGWorldMapModule : WorldMapModule
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48  
49 // Remember the map area that each client has been exposed to in this region
50 private Dictionary<UUID, List<MapBlockData>> m_SeenMapBlocks = new Dictionary<UUID, List<MapBlockData>>();
51  
52 private string m_MapImageServerURL = string.Empty;
53  
54 private IUserManagement m_UserManagement;
55  
56 #region INonSharedRegionModule Members
57  
58 public override void Initialise(IConfigSource source)
59 {
60 if (Util.GetConfigVarFromSections<string>(
61 source, "WorldMapModule", new string[] { "Map", "Startup" }, "WorldMap") == "HGWorldMap")
62 {
63 m_Enabled = true;
64  
65 m_MapImageServerURL = Util.GetConfigVarFromSections<string>(source, "MapTileURL", new string[] {"LoginService", "HGWorldMap", "SimulatorFeatures"});
66  
67 if (!string.IsNullOrEmpty(m_MapImageServerURL))
68 {
69 m_MapImageServerURL = m_MapImageServerURL.Trim();
70 if (!m_MapImageServerURL.EndsWith("/"))
71 m_MapImageServerURL = m_MapImageServerURL + "/";
72 }
73  
74  
75 }
76 }
77  
78 public override void AddRegion(Scene scene)
79 {
80 if (!m_Enabled)
81 return;
82  
83 base.AddRegion(scene);
84  
85 scene.EventManager.OnClientClosed += EventManager_OnClientClosed;
86 }
87  
88 public override void RegionLoaded(Scene scene)
89 {
90 if (!m_Enabled)
91 return;
92  
93 base.RegionLoaded(scene);
94 ISimulatorFeaturesModule featuresModule = m_scene.RequestModuleInterface<ISimulatorFeaturesModule>();
95  
96 if (featuresModule != null)
97 featuresModule.OnSimulatorFeaturesRequest += OnSimulatorFeaturesRequest;
98  
99 m_UserManagement = m_scene.RequestModuleInterface<IUserManagement>();
100  
101 }
102  
103 public override void RemoveRegion(Scene scene)
104 {
105 if (!m_Enabled)
106 return;
107  
108 scene.EventManager.OnClientClosed -= EventManager_OnClientClosed;
109 }
110  
111 public override string Name
112 {
113 get { return "HGWorldMap"; }
114 }
115  
116 #endregion
117  
118 void EventManager_OnClientClosed(UUID clientID, Scene scene)
119 {
120 ScenePresence sp = scene.GetScenePresence(clientID);
121 if (sp != null)
122 {
123 if (m_SeenMapBlocks.ContainsKey(clientID))
124 {
125 List<MapBlockData> mapBlocks = m_SeenMapBlocks[clientID];
126 foreach (MapBlockData b in mapBlocks)
127 {
128 b.Name = string.Empty;
129 b.Access = 254; // means 'simulator is offline'. We need this because the viewer ignores 255's
130 }
131  
132 m_log.DebugFormat("[HG MAP]: Resetting {0} blocks", mapBlocks.Count);
133 sp.ControllingClient.SendMapBlock(mapBlocks, 0);
134 m_SeenMapBlocks.Remove(clientID);
135 }
136 }
137 }
138  
139 protected override List<MapBlockData> GetAndSendBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag)
140 {
141 List<MapBlockData> mapBlocks = base.GetAndSendBlocks(remoteClient, minX, minY, maxX, maxY, flag);
142 lock (m_SeenMapBlocks)
143 {
144 if (!m_SeenMapBlocks.ContainsKey(remoteClient.AgentId))
145 {
146 m_SeenMapBlocks.Add(remoteClient.AgentId, mapBlocks);
147 }
148 else
149 {
150 List<MapBlockData> seen = m_SeenMapBlocks[remoteClient.AgentId];
151 List<MapBlockData> newBlocks = new List<MapBlockData>();
152 foreach (MapBlockData b in mapBlocks)
153 if (seen.Find(delegate(MapBlockData bdata) { return bdata.X == b.X && bdata.Y == b.Y; }) == null)
154 newBlocks.Add(b);
155 seen.AddRange(newBlocks);
156 }
157 }
158  
159 return mapBlocks;
160 }
161  
162 private void OnSimulatorFeaturesRequest(UUID agentID, ref OSDMap features)
163 {
164 if (m_UserManagement != null && !string.IsNullOrEmpty(m_MapImageServerURL) && !m_UserManagement.IsLocalGridUser(agentID))
165 {
166 OSD extras = new OSDMap();
167 if (features.ContainsKey("OpenSimExtras"))
168 extras = features["OpenSimExtras"];
169 else
170 features["OpenSimExtras"] = extras;
171  
172 ((OSDMap)extras)["map-server-url"] = m_MapImageServerURL;
173  
174 }
175 }
176 }
177  
178 class MapArea
179 {
180 public int minX;
181 public int minY;
182 public int maxX;
183 public int maxY;
184  
185 public MapArea(int mix, int miy, int max, int may)
186 {
187 minX = mix;
188 minY = miy;
189 maxX = max;
190 maxY = may;
191 }
192  
193 public void Print()
194 {
195 Console.WriteLine(String.Format(" --> Area is minX={0} minY={1} minY={2} maxY={3}", minX, minY, maxY, maxY));
196 }
197 }
198 }