diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Hypergrid/HGWorldMapModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Hypergrid/HGWorldMapModule.cs | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/Hypergrid/HGWorldMapModule.cs b/OpenSim/Region/Environment/Modules/Hypergrid/HGWorldMapModule.cs new file mode 100644 index 0000000..7f8f285 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/Hypergrid/HGWorldMapModule.cs | |||
@@ -0,0 +1,178 @@ | |||
1 | /** | ||
2 | * Copyright (c) 2008, Contributors. All rights reserved. | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without modification, | ||
6 | * are permitted provided that the following conditions are met: | ||
7 | * | ||
8 | * * Redistributions of source code must retain the above copyright notice, | ||
9 | * this list of conditions and the following disclaimer. | ||
10 | * * Redistributions in binary form must reproduce the above copyright notice, | ||
11 | * this list of conditions and the following disclaimer in the documentation | ||
12 | * and/or other materials provided with the distribution. | ||
13 | * * Neither the name of the Organizations nor the names of Individual | ||
14 | * Contributors may be used to endorse or promote products derived from | ||
15 | * this software without specific prior written permission. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
20 | * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
22 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
24 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
25 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | |||
29 | |||
30 | using System; | ||
31 | using System.Collections; | ||
32 | using System.Collections.Generic; | ||
33 | using System.Drawing; | ||
34 | using System.Drawing.Imaging; | ||
35 | using System.IO; | ||
36 | using System.Net; | ||
37 | using System.Reflection; | ||
38 | using System.Threading; | ||
39 | using OpenMetaverse; | ||
40 | using OpenMetaverse.Imaging; | ||
41 | using OpenMetaverse.StructuredData; | ||
42 | using log4net; | ||
43 | using Nini.Config; | ||
44 | using Nwc.XmlRpc; | ||
45 | |||
46 | using OpenSim.Framework; | ||
47 | using OpenSim.Framework.Communications.Cache; | ||
48 | using OpenSim.Framework.Communications.Capabilities; | ||
49 | using OpenSim.Framework.Servers; | ||
50 | using OpenSim.Region.Environment.Interfaces; | ||
51 | using OpenSim.Region.Environment.Modules.World.WorldMap; | ||
52 | using OpenSim.Region.Environment.Scenes; | ||
53 | using OpenSim.Region.Environment.Types; | ||
54 | using Caps = OpenSim.Framework.Communications.Capabilities.Caps; | ||
55 | |||
56 | using OSD = OpenMetaverse.StructuredData.OSD; | ||
57 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; | ||
58 | using OSDArray = OpenMetaverse.StructuredData.OSDArray; | ||
59 | |||
60 | namespace OpenSim.Region.Environment.Modules.Hypergrid | ||
61 | { | ||
62 | public class HGWorldMapModule : WorldMapModule, IRegionModule | ||
63 | { | ||
64 | private static readonly ILog m_log = | ||
65 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
66 | |||
67 | #region IRegionModule Members | ||
68 | |||
69 | public override void Initialise(Scene scene, IConfigSource config) | ||
70 | { | ||
71 | IConfig startupConfig = config.Configs["Startup"]; | ||
72 | if (startupConfig.GetString("WorldMapModule", "WorldMap") == "HGWorldMap") | ||
73 | m_Enabled = true; | ||
74 | |||
75 | if (!m_Enabled) | ||
76 | return; | ||
77 | m_log.Info("[HGMap] Initializing..."); | ||
78 | m_scene = scene; | ||
79 | } | ||
80 | |||
81 | |||
82 | public override string Name | ||
83 | { | ||
84 | get { return "HGWorldMap"; } | ||
85 | } | ||
86 | |||
87 | |||
88 | #endregion | ||
89 | |||
90 | /// <summary> | ||
91 | /// Requests map blocks in area of minX, maxX, minY, MaxY in world cordinates | ||
92 | /// </summary> | ||
93 | /// <param name="minX"></param> | ||
94 | /// <param name="minY"></param> | ||
95 | /// <param name="maxX"></param> | ||
96 | /// <param name="maxY"></param> | ||
97 | public override void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag) | ||
98 | { | ||
99 | // | ||
100 | // WARNING!!! COPY & PASTE FROM SUPERCLASS | ||
101 | // The only difference is at the very end | ||
102 | // | ||
103 | |||
104 | m_log.Info("[HGMap]: Request map blocks " + minX + "-" + maxX + " " + minY + "-" + maxY); | ||
105 | |||
106 | //m_scene.ForEachScenePresence(delegate (ScenePresence sp) { | ||
107 | // if (!sp.IsChildAgent && sp.UUID == remoteClient.AgentId) | ||
108 | // { | ||
109 | // Console.WriteLine("XXX Root agent"); | ||
110 | // DoRequestMapBlocks(remoteClient, minX, minY, maxX, maxY, flag); | ||
111 | // } | ||
112 | //}; | ||
113 | |||
114 | List<MapBlockData> mapBlocks; | ||
115 | if ((flag & 0x10000) != 0) // user clicked on the map a tile that isn't visible | ||
116 | { | ||
117 | List<MapBlockData> response = new List<MapBlockData>(); | ||
118 | |||
119 | // this should return one mapblock at most. But make sure: Look whether the one we requested is in there | ||
120 | mapBlocks = m_scene.SceneGridService.RequestNeighbourMapBlocks(minX, minY, maxX, maxY); | ||
121 | if (mapBlocks != null) | ||
122 | { | ||
123 | foreach (MapBlockData block in mapBlocks) | ||
124 | { | ||
125 | if (block.X == minX && block.Y == minY) | ||
126 | { | ||
127 | // found it => add it to response | ||
128 | response.Add(block); | ||
129 | break; | ||
130 | } | ||
131 | } | ||
132 | } | ||
133 | response = mapBlocks; | ||
134 | if (response.Count == 0) | ||
135 | { | ||
136 | // response still empty => couldn't find the map-tile the user clicked on => tell the client | ||
137 | MapBlockData block = new MapBlockData(); | ||
138 | block.X = (ushort)minX; | ||
139 | block.Y = (ushort)minY; | ||
140 | block.Access = 254; // == not there | ||
141 | response.Add(block); | ||
142 | } | ||
143 | remoteClient.SendMapBlock(response, 0); | ||
144 | } | ||
145 | else | ||
146 | { | ||
147 | // normal mapblock request. Use the provided values | ||
148 | mapBlocks = m_scene.SceneGridService.RequestNeighbourMapBlocks(minX - 4, minY - 4, maxX + 4, maxY + 4); | ||
149 | |||
150 | // Different from super | ||
151 | FillInMap(mapBlocks, minX, minY, maxX, maxY); | ||
152 | // | ||
153 | |||
154 | remoteClient.SendMapBlock(mapBlocks, flag); | ||
155 | } | ||
156 | } | ||
157 | |||
158 | |||
159 | private void FillInMap(List<MapBlockData> mapBlocks, int minX, int minY, int maxX, int maxY) | ||
160 | { | ||
161 | for (int x = minX; x <= maxX; x++) | ||
162 | for (int y = minY; y <= maxY; y++) | ||
163 | { | ||
164 | MapBlockData mblock = mapBlocks.Find(delegate(MapBlockData mb) { return ((mb.X == x) && (mb.Y == y)); }); | ||
165 | if (mblock == null) | ||
166 | { | ||
167 | mblock = new MapBlockData(); | ||
168 | mblock.X = (ushort)x; | ||
169 | mblock.Y = (ushort)y; | ||
170 | mblock.Name = ""; | ||
171 | mblock.Access = 254; // not here??? | ||
172 | mblock.MapImageId = UUID.Zero; | ||
173 | mapBlocks.Add(mblock); | ||
174 | } | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | } | ||