From f8acdeb437ff18762399c519e2416aceb2149609 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Mon, 6 Oct 2008 00:00:55 +0000 Subject: * Green dots on the mainmap for avatar. * Initial implementation * You'll only be able to seen green dots on regions on the map that have been updated. --- OpenSim/Framework/IClientAPI.cs | 9 ++ OpenSim/Framework/MapItemReplyStruct.cs | 42 ++++++ .../Region/ClientStack/LindenUDP/LLClientView.cs | 34 +++++ .../Environment/Modules/World/NPC/NPCAvatar.cs | 6 + .../Modules/World/WorldMap/WorldMapModule.cs | 168 +++++++++++++++++++++ .../Region/Examples/SimpleModule/MyNpcCharacter.cs | 6 + 6 files changed, 265 insertions(+) create mode 100644 OpenSim/Framework/MapItemReplyStruct.cs diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index c0d133e..7095387 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -310,6 +310,9 @@ namespace OpenSim.Framework public delegate void TerrainUnacked(IClientAPI remoteClient, int patchX, int patchY); public delegate void DirPlacesQuery(IClientAPI remoteClient, UUID queryID, string queryText, int queryFlags, int category, string simName, int queryStart); + + public delegate void MapItemRequest(IClientAPI remoteClient, uint flags, uint EstateID, bool godlike, uint itemtype, ulong regionhandle); + #endregion public struct DirPlacesReplyData @@ -546,6 +549,9 @@ namespace OpenSim.Framework event DirPlacesQuery OnDirPlacesQuery; + event MapItemRequest OnMapItemRequest; + + // void ActivateGesture(UUID assetId, UUID gestureId); // [Obsolete("IClientAPI.OutPacket SHOULD NOT EXIST outside of LLClientView please refactor appropriately.")] @@ -775,6 +781,9 @@ namespace OpenSim.Framework void SendScriptTeleportRequest(string objName, string simName, Vector3 pos, Vector3 lookAt); void SendDirPlacesReply(UUID queryID, DirPlacesReplyData[] data); + + void SendMapItemReply(mapItemReply[] replies, uint mapitemtype, uint flags); + void KillEndDone(); } } diff --git a/OpenSim/Framework/MapItemReplyStruct.cs b/OpenSim/Framework/MapItemReplyStruct.cs new file mode 100644 index 0000000..f088085 --- /dev/null +++ b/OpenSim/Framework/MapItemReplyStruct.cs @@ -0,0 +1,42 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using OpenMetaverse; + +namespace OpenSim.Framework +{ + public struct mapItemReply + { + public uint x; + public uint y; + public UUID id; + public int Extra; + public int Extra2; + public string name; + } +} diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 2187bc8..92275e8 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -262,6 +262,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP private DirPlacesQuery handlerDirPlacesQuery = null; + private MapItemRequest handlerMapItemRequest = null; + //private TerrainUnacked handlerUnackedTerrain = null; //** @@ -988,6 +990,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP public event DirPlacesQuery OnDirPlacesQuery; + public event MapItemRequest OnMapItemRequest; // voire si c'est necessaire public void ActivateGesture(UUID assetId, UUID gestureId) @@ -6215,6 +6218,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP //break; case PacketType.MapItemRequest: // TODO: handle this packet + MapItemRequestPacket mirpk = (MapItemRequestPacket)Pack; + //System.Console.WriteLine(mirpk.ToString()); + handlerMapItemRequest = OnMapItemRequest; + if (handlerMapItemRequest != null) + { + handlerMapItemRequest(this,mirpk.AgentData.Flags, mirpk.AgentData.EstateID, + mirpk.AgentData.Godlike,mirpk.RequestData.ItemType, + mirpk.RequestData.RegionHandle); + + } //m_log.Warn("[CLIENT]: unhandled MapItemRequest packet"); break; case PacketType.TransferAbort: @@ -6756,6 +6769,27 @@ namespace OpenSim.Region.ClientStack.LindenUDP OutPacket(packet, ThrottleOutPacketType.Task); } + public void SendMapItemReply(mapItemReply[] replies, uint mapitemtype, uint flags) + { + MapItemReplyPacket mirplk = new MapItemReplyPacket(); + mirplk.AgentData.AgentID = AgentId; + mirplk.RequestData.ItemType = mapitemtype; + mirplk.Data = new MapItemReplyPacket.DataBlock[replies.Length]; + for (int i = 0; i < replies.Length; i++ ) + { + MapItemReplyPacket.DataBlock mrdata = new MapItemReplyPacket.DataBlock(); + mrdata.X = replies[i].x; + mrdata.Y = replies[i].y; + mrdata.ID = replies[i].id; + mrdata.Extra = replies[i].Extra; + mrdata.Extra2 = replies[i].Extra2; + mrdata.Name = Utils.StringToBytes(replies[i].name); + mirplk.Data[i] = mrdata; + } + //System.Console.WriteLine(mirplk.ToString()); + OutPacket(mirplk, ThrottleOutPacketType.Task); + + } public void KillEndDone() { diff --git a/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs b/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs index 99c953c..ff54ed3 100644 --- a/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs @@ -324,6 +324,8 @@ namespace OpenSim.Region.Environment.Modules.World.NPC public event DirPlacesQuery OnDirPlacesQuery; + public event MapItemRequest OnMapItemRequest; + #pragma warning restore 67 #endregion @@ -895,6 +897,10 @@ namespace OpenSim.Region.Environment.Modules.World.NPC { } + public void SendMapItemReply(mapItemReply[] replies, uint mapitemtype, uint flags) + { + } + public void KillEndDone() { } diff --git a/OpenSim/Region/Environment/Modules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/Environment/Modules/World/WorldMap/WorldMapModule.cs index bc62e07..8091c59 100644 --- a/OpenSim/Region/Environment/Modules/World/WorldMap/WorldMapModule.cs +++ b/OpenSim/Region/Environment/Modules/World/WorldMap/WorldMapModule.cs @@ -31,9 +31,11 @@ using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; +using System.Net; using System.Reflection; using OpenMetaverse; using OpenMetaverse.Imaging; +using OpenMetaverse.StructuredData; using log4net; using Nini.Config; using OpenSim.Framework; @@ -45,6 +47,9 @@ using OpenSim.Region.Environment.Scenes; using OpenSim.Region.Environment.Types; using Caps = OpenSim.Framework.Communications.Capabilities.Caps; +using LLSD = OpenMetaverse.StructuredData.LLSD; +using LLSDMap = OpenMetaverse.StructuredData.LLSDMap; +using LLSDArray = OpenMetaverse.StructuredData.LLSDArray; namespace OpenSim.Region.Environment.Modules.World.WorldMap { @@ -85,6 +90,7 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap m_scene.AddHTTPHandler(regionimage, OnHTTPGetMapImage); + m_scene.AddLLSDHandler("/MAP/MapItems/" + scene.RegionInfo.RegionHandle.ToString(),HandleRemoteMapItemRequest); //QuadTree.Subdivide(); //QuadTree.Subdivide(); @@ -231,6 +237,7 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap //doFriendListUpdateOnline(client.AgentId); client.OnRequestMapBlocks += RequestMapBlocks; + client.OnMapItemRequest += HandleMapItemRequest; } private void ClientLoggedOut(UUID AgentId) { @@ -238,6 +245,109 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap } #endregion + public virtual void HandleMapItemRequest(IClientAPI remoteClient, uint flags, + uint EstateID, bool godlike, uint itemtype, ulong regionhandle) + { + if (itemtype == 6) // we only sevice 6 right now (avatar green dots) + { + RegionInfo mreg = m_scene.SceneGridService.RequestNeighbouringRegionInfo(regionhandle); + if (mreg != null) + { + string httpserver = "http://" + mreg.ExternalEndPoint.Address.ToString() + ":" + mreg.HttpPort + "/MAP/MapItems/" + regionhandle.ToString(); + List returnitems = new List(); + LLSDMap ramap = RequestMapItems(httpserver); + if (ramap.ContainsKey(itemtype.ToString())) + { + LLSDArray itemarray = (LLSDArray)ramap[itemtype.ToString()]; + for (int i = 0; i < itemarray.Count; i++) + { + LLSDMap mapitem = (LLSDMap)itemarray[i]; + mapItemReply mi = new mapItemReply(); + mi.x = (uint)mapitem["X"].AsInteger(); + mi.y = (uint)mapitem["Y"].AsInteger(); + mi.id = mapitem["ID"].AsUUID(); + mi.Extra = mapitem["Extra"].AsInteger(); + mi.Extra2 = mapitem["Extra2"].AsInteger(); + mi.name = mapitem["Name"].AsString(); + returnitems.Add(mi); + } + + } + remoteClient.SendMapItemReply(returnitems.ToArray(), itemtype, flags); + } + } + + } + + private LLSDMap RequestMapItems(string httpserver) + { + WebRequest mapitemsrequest = WebRequest.Create(httpserver); + mapitemsrequest.Method = "POST"; + mapitemsrequest.ContentType = "application/xml+llsd"; + LLSDMap RAMap = new LLSDMap(); + + string RAMapString = RAMap.ToString(); + LLSD LLSDofRAMap = RAMap; // RENAME if this works + + byte[] buffer = LLSDParser.SerializeXmlBytes(LLSDofRAMap); + LLSDMap responseMap = new LLSDMap(); + Stream os = null; + try + { // send the Post + mapitemsrequest.ContentLength = buffer.Length; //Count bytes to send + os = mapitemsrequest.GetRequestStream(); + os.Write(buffer, 0, buffer.Length); //Send it + os.Close(); + m_log.InfoFormat("[WorldMap]: Getting MapItems from Sim {0}", httpserver); + } + catch (WebException ex) + { + m_log.InfoFormat("[WorldMap] Bad send on GetMapItems {0}", ex.Message); + responseMap["connect"] = LLSD.FromBoolean(false); + + return responseMap; + } + + //m_log.Info("[OGP] waiting for a reply after rez avatar send"); + string response_mapItems_reply = null; + { // get the response + try + { + WebResponse webResponse = mapitemsrequest.GetResponse(); + if (webResponse == null) + { + //m_log.Info("[OGP:] Null reply on rez_avatar post"); + } + + StreamReader sr = new StreamReader(webResponse.GetResponseStream()); + response_mapItems_reply = sr.ReadToEnd().Trim(); + //m_log.InfoFormat("[OGP]: rez_avatar reply was {0} ", response_mapItems_reply); + + } + catch (WebException ex) + { + //m_log.InfoFormat("[OGP]: exception on read after send of rez avatar {0}", ex.Message); + responseMap["connect"] = LLSD.FromBoolean(false); + + return responseMap; + } + LLSD rezResponse = null; + try + { + rezResponse = LLSDParser.DeserializeXml(response_mapItems_reply); + + responseMap = (LLSDMap)rezResponse; + } + catch (Exception ex) + { + //m_log.InfoFormat("[OGP]: exception on parse of rez reply {0}", ex.Message); + responseMap["connect"] = LLSD.FromBoolean(false); + + return responseMap; + } + } + return responseMap; + } /// /// Requests map blocks in area of minX, maxX, minY, MaxY in world cordinates /// @@ -378,5 +488,63 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap } return null; } + public LLSD HandleRemoteMapItemRequest(string path, LLSD request, string endpoint) + { + uint xstart = 0; + uint ystart = 0; + + Helpers.LongToUInts(m_scene.RegionInfo.RegionHandle,out xstart,out ystart); + + LLSDMap responsemap = new LLSDMap(); + List avatars = m_scene.GetAvatars(); + LLSDArray responsearr = new LLSDArray(avatars.Count); + LLSDMap responsemapdata = new LLSDMap(); + int tc = System.Environment.TickCount; + /* + foreach (ScenePresence av in avatars) + { + responsemapdata = new LLSDMap(); + responsemapdata["X"] = LLSD.FromInteger((int)(xstart + av.AbsolutePosition.X)); + responsemapdata["Y"] = LLSD.FromInteger((int)(ystart + av.AbsolutePosition.Y)); + responsemapdata["ID"] = LLSD.FromUUID(UUID.Zero); + responsemapdata["Name"] = LLSD.FromString("TH"); + responsemapdata["Extra"] = LLSD.FromInteger(0); + responsemapdata["Extra2"] = LLSD.FromInteger(0); + responsearr.Add(responsemapdata); + } + responsemap["1"] = responsearr; + */ + if (avatars.Count == 0) + { + responsemapdata = new LLSDMap(); + responsemapdata["X"] = LLSD.FromInteger((int)(xstart + 1)); + responsemapdata["Y"] = LLSD.FromInteger((int)(ystart + 1)); + responsemapdata["ID"] = LLSD.FromUUID(UUID.Zero); + responsemapdata["Name"] = LLSD.FromString(Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString())); + responsemapdata["Extra"] = LLSD.FromInteger(0); + responsemapdata["Extra2"] = LLSD.FromInteger(0); + responsearr.Add(responsemapdata); + + responsemap["6"] = responsearr; + } + else + { + responsearr = new LLSDArray(avatars.Count); + foreach (ScenePresence av in avatars) + { + responsemapdata = new LLSDMap(); + responsemapdata["X"] = LLSD.FromInteger((int)(xstart + av.AbsolutePosition.X)); + responsemapdata["Y"] = LLSD.FromInteger((int)(ystart + av.AbsolutePosition.Y)); + responsemapdata["ID"] = LLSD.FromUUID(UUID.Zero); + responsemapdata["Name"] = LLSD.FromString(Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString())); + responsemapdata["Extra"] = LLSD.FromInteger(1); + responsemapdata["Extra2"] = LLSD.FromInteger(0); + responsearr.Add(responsemapdata); + } + responsemap["6"] = responsearr; + } + return responsemap; + } } + } diff --git a/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs index 6fbab0a..60a66aa 100644 --- a/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs @@ -219,6 +219,8 @@ namespace OpenSim.Region.Examples.SimpleModule public event DirPlacesQuery OnDirPlacesQuery; + public event MapItemRequest OnMapItemRequest; + #pragma warning restore 67 @@ -892,6 +894,10 @@ namespace OpenSim.Region.Examples.SimpleModule { } + public void SendMapItemReply(mapItemReply[] replies, uint mapitemtype, uint flags) + { + } + public void KillEndDone() { } -- cgit v1.1