示例#1
0
        /// <summary>
        /// Process individual messages that arrive via the EventQueue and convert each indvidual event into a format
        /// suitable for processing by the IMessage system
        /// </summary>
        /// <param name="req"></param>
        /// <param name="stage"></param>
        /// <returns></returns>
        private bool EventQueueGetHandler(CapsRequest req, CapsStage stage)
        {
            if (stage == CapsStage.Response && req.Response is OSDMap)
            {
                OSDMap map = (OSDMap)req.Response;

                if (map.ContainsKey("events"))
                {
                    OSDArray eventsArray = (OSDArray)map["events"];

                    for (int i = 0; i < eventsArray.Count; i++)
                    {
                        OSDMap bodyMap = (OSDMap)eventsArray[i];
                        if (OnEventMessageLog != null)
                        {
                            CapInfo     capInfo = new CapInfo(req.Info.URI, req.Info.Sim, bodyMap["message"].AsString());
                            CapsRequest capReq  = new CapsRequest(capInfo);
                            capReq.RequestHeaders  = req.RequestHeaders;
                            capReq.ResponseHeaders = req.ResponseHeaders;
                            capReq.Request         = null; // req.Request;
                            capReq.RawRequest      = null; // req.RawRequest;
                            capReq.RawResponse     = OSDParser.SerializeLLSDXmlBytes(bodyMap);
                            capReq.Response        = bodyMap;

                            OnEventMessageLog(capReq, CapsStage.Response);
                        }
                    }
                }
            }
            return(false);
        }
示例#2
0
 private bool CapsHandler(CapsRequest req, CapsStage stage)
 {
     if (OnMessageLog != null)
     {
         OnMessageLog(req, stage);
     }
     return(false);
 }
示例#3
0
        private bool FixupEventQueueGet(CapsRequest capReq, CapsStage stage)
        {
            if (stage != CapsStage.Response) return false;

            OSDMap map = (OSDMap)capReq.Response;
            OSDArray array = (OSDArray)map["events"];

            for (int i = 0; i < array.Count; i++)
            {
                OSDMap evt = (OSDMap)array[i];

                string message = evt["message"].AsString();
                OSDMap body = (OSDMap)evt["body"];

                if (message == "TeleportFinish" || message == "CrossedRegion")
                {
                    OSDMap info = null;
                    if (message == "TeleportFinish")
                        info = (OSDMap)(((OSDArray)body["Info"])[0]);
                    else
                        info = (OSDMap)(((OSDArray)body["RegionData"])[0]);
                    byte[] bytes = info["SimIP"].AsBinary();
                    uint simIP = Utils.BytesToUInt(bytes);
                    ushort simPort = (ushort)info["SimPort"].AsInteger();
                    string capsURL = info["SeedCapability"].AsString();

                    GenericCheck(ref simIP, ref simPort, ref capsURL, capReq.Info.Sim == activeCircuit);

                    info["SeedCapability"] = OSD.FromString(capsURL);
                    bytes[0] = (byte)(simIP % 256);
                    bytes[1] = (byte)((simIP >> 8) % 256);
                    bytes[2] = (byte)((simIP >> 16) % 256);
                    bytes[3] = (byte)((simIP >> 24) % 256);
                    info["SimIP"] = OSD.FromBinary(bytes);
                    info["SimPort"] = OSD.FromInteger(simPort);
                }
                else if (message == "EnableSimulator")
                {
                    OSDMap info = null;
                    info = (OSDMap)(((OSDArray)body["SimulatorInfo"])[0]);
                    byte[] bytes = info["IP"].AsBinary();
                    uint IP = Utils.BytesToUInt(bytes);
                    ushort Port = (ushort)info["Port"].AsInteger();
                    string capsURL = null;

                    GenericCheck(ref IP, ref Port, ref capsURL, capReq.Info.Sim == activeCircuit);

                    bytes[0] = (byte)(IP % 256);
                    bytes[1] = (byte)((IP >> 8) % 256);
                    bytes[2] = (byte)((IP >> 16) % 256);
                    bytes[3] = (byte)((IP >> 24) % 256);
                    info["IP"] = OSD.FromBinary(bytes);
                    info["Port"] = OSD.FromInteger(Port);
                }
                else if (message == "EstablishAgentCommunication")
                {
                    string ipAndPort = body["sim-ip-and-port"].AsString();
                    string[] pieces = ipAndPort.Split(':');
                    byte[] bytes = IPAddress.Parse(pieces[0]).GetAddressBytes();
                    uint simIP = Utils.BytesToUInt(bytes);
                    ushort simPort = (ushort)Convert.ToInt32(pieces[1]);

                    string capsURL = body["seed-capability"].AsString();

                    OpenMetaverse.Logger.Log("DEBUG: Got EstablishAgentCommunication for " + ipAndPort + " with seed cap " + capsURL, Helpers.LogLevel.Debug);

                    GenericCheck(ref simIP, ref simPort, ref capsURL, false);
                    body["seed-capability"] = OSD.FromString(capsURL);
                    string ipport = String.Format("{0}:{1}", new IPAddress(simIP), simPort);
                    body["sim-ip-and-port"] = OSD.FromString(ipport);

                    OpenMetaverse.Logger.Log("DEBUG: Modified EstablishAgentCommunication to " + body["sim-ip-and-port"].AsString() + " with seed cap " + capsURL, Helpers.LogLevel.Debug);
                }
            }
            return false;
        }
示例#4
0
        private bool KnownCapDelegate(CapsRequest capReq, CapsStage stage)
        {
            lock (this)
            {
                if (!KnownCapsDelegates.ContainsKey(capReq.Info.CapType))
                    return false;

                if (stage == CapsStage.Response)
                {
                    if (capReq.Response != null)
                    {
                        OSDMap map = (OSDMap)capReq.Response;

                        if (map.ContainsKey("uploader"))
                        {
                            string val = map["uploader"].AsString();

                            if (!KnownCaps.ContainsKey(val))
                            {
                                CapInfo newCap = new CapInfo(val, capReq.Info.Sim, capReq.Info.CapType, CapsDataFormat.Binary, CapsDataFormat.OSD);
                                newCap.AddDelegate(new CapsDelegate(KnownCapDelegate));
                                lock (this) { KnownCaps[val] = newCap; }
                            }

                            map["uploader"] = OSD.FromString(loginURI + val);
                        }
                    }
                }

                List<CapsDelegate> delegates = KnownCapsDelegates[capReq.Info.CapType];

                foreach (CapsDelegate d in delegates)
                {
                    if (d(capReq, stage)) { return true; }
                }
            }

            return false;
        }
示例#5
0
        private bool FixupSeedCapsResponse(CapsRequest capReq, CapsStage stage)
        {
            if (stage != CapsStage.Response) return false;

            OSDMap nm = new OSDMap();

            if (capReq.Response.Type == OSDType.Map)
            {
                OSDMap m = (OSDMap)capReq.Response;
                
                foreach (string key in m.Keys)
                {
                    string val = m[key].AsString();

                    if (!String.IsNullOrEmpty(val))
                    {
                        if (!KnownCaps.ContainsKey(val))
                        {
                            CapInfo newCap = new CapInfo(val, capReq.Info.Sim, key);
                            newCap.AddDelegate(new CapsDelegate(KnownCapDelegate));
                            lock (this) { KnownCaps[val] = newCap; }
                        }
                        nm[key] = OSD.FromString(loginURI + val);
                    }
                    else
                    {
                        nm[key] = OSD.FromString(val);
                    }
                }
            }

            capReq.Response = nm;
            return false;
        }
示例#6
0
        private bool KnownCapDelegate(CapsRequest capReq, CapsStage stage)
        {
            lock (this)
            {
                if (!KnownCapsDelegates.ContainsKey(capReq.Info.CapType))
                    return false;

                List<CapsDelegate> delegates = KnownCapsDelegates[capReq.Info.CapType];

                foreach (CapsDelegate d in delegates)
                {
                    if (d(capReq, stage)) { return true; }
                }
            }

            return false;
        }
示例#7
0
        public bool FixupSeedCapsResponse(CapsRequest capReq, CapsStage stage)
        {
            if (stage != CapsStage.Response) return false;

            OSDMap nm = new OSDMap();

            if (capReq.Response.Type == OSDType.Map)
            {
                OSDMap m = (OSDMap)capReq.Response;

                foreach (string key in m.Keys)
                {
                    string val = m[key].AsString();

                    if (!String.IsNullOrEmpty(val))
                    {
                        if (!KnownCaps.ContainsKey(val))
                        {
                            CapInfo newCap = new CapInfo(val, capReq.Info.Sim, key);
                            newCap.AddDelegate(new CapsDelegate(KnownCapDelegate));
                            lock (this) { KnownCaps[val] = newCap; }
                            //Console.WriteLine("    >> Adding KnownCap " + val + " = " + newCap);
                        }
                        nm[key] = OSD.FromString(loginURI + val);
                        //Console.WriteLine("    >> Sending transformed Cap " + loginURI + val);
                    }
                    else
                    {
                        nm[key] = OSD.FromString(val);
                    }
                }
            }

            //Console.WriteLine("---------------");
            //lock (this)
            //{
            //    foreach (KeyValuePair<string, CapInfo> kvp in KnownCaps)
            //    {
            //        Console.WriteLine(" >> Key: " + kvp.Key + "; Value: " + kvp.Value.CapType);
            //    }
            //}
            //Console.WriteLine("---------------");

            capReq.Response = nm;
            return false;
        }
示例#8
0
        /// <summary>
        /// Process individual messages that arrive via the EventQueue and convert each indvidual event into a format
        /// suitable for processing by the IMessage system
        /// </summary>
        /// <param name="req"></param>
        /// <param name="stage"></param>
        /// <returns></returns>
        private bool EventQueueGetHandler(CapsRequest req, CapsStage stage)
        {
            if (stage == CapsStage.Response && req.Response is OSDMap)
            {
                OSDMap map = (OSDMap)req.Response;

                if (map.ContainsKey("events"))
                {
                    OSDArray eventsArray = (OSDArray)map["events"];

                    for (int i = 0; i < eventsArray.Count; i++)
                    {
                        OSDMap bodyMap = (OSDMap)eventsArray[i];
                        if (OnEventMessageLog != null)
                        {
                            CapInfo capInfo = new CapInfo(req.Info.URI, req.Info.Sim, bodyMap["message"].AsString());
                            CapsRequest capReq = new CapsRequest(capInfo);
                            capReq.RequestHeaders = req.RequestHeaders;
                            capReq.ResponseHeaders = req.ResponseHeaders;
                            capReq.Request = null;// req.Request;
                            capReq.RawRequest = null;// req.RawRequest;
                            capReq.RawResponse = OSDParser.SerializeLLSDXmlBytes(bodyMap);
                            capReq.Response = bodyMap;

                            OnEventMessageLog(capReq, CapsStage.Response);
                        }
                    }
                }
            }
            return false;
        }
示例#9
0
文件: Grider.cs 项目: diva/Grider
        bool LocalEQHandler(CapsRequest req, CapsStage stage)
        {
            if (stage != CapsStage.Response) return true; // shortcircuit, so don't foward to sim
            Console.WriteLine(">> LocalEQHandler " + stage.ToString() + " to " + req.Info.URI);

            int length = req.Info.URI.Length;
            string key = req.Info.URI.Substring(length - 37, 36);
            //Console.WriteLine("       key " + key);
            // it comes back on the Response phase
            EventQueue _eq = Agent.GetEventQueue(key);
            if (_eq == null)
            {
                Console.WriteLine("[GRIDER]: Agent has no EQ??? Creating new one");
                _eq = new EventQueue();
            }
            else
            {
                Console.WriteLine("[GRIDER]: Found Event Queue for agent " + key);
            }

            if (_eq.Run(req) == null)
                Agent.RemoveEventQueue(key);

            //    req.Response = new OSD();

            return false;
        }
示例#10
0
        void ProxyManager_OnMessageLog(CapsRequest req, CapsStage stage)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new MethodInvoker(delegate()
                    {
                        ProxyManager_OnMessageLog(req, stage);
                    }));
            }
            else
            {
                ListViewItem found = FindListViewItem(listViewMessageFilters, req.Info.CapType, false);

                if (found != null && found.Checked)
                {
                    PacketCounter++;

                    int size = 0;
                    string cType = String.Empty;
                    if (req.RawRequest != null)
                    {
                        size += req.RawRequest.Length;
                        cType = req.RequestHeaders.Get("Content-Type"); //req.RequestHeaders["Content-Type"];
                    }
                    if (req.RawResponse != null)
                    {
                        size += req.RawResponse.Length;
                        cType = req.ResponseHeaders.Get("Content-Type");
                    }
                    string[] s = { PacketCounter.ToString(), found.SubItems[1].Text, req.Info.CapType, size.ToString(), req.Info.URI, cType };
                    ListViewItem session = new ListViewItem(s);
                    session.BackColor = found.BackColor;

                    session.Tag = req;

                    if (stage == CapsStage.Request)
                    {
                        CapsOutCounter++;
                        CapsOutBytes += req.Request.ToString().Length;
                        session.ImageIndex = 1;
                    }
                    else
                    {
                        CapsInCounter++;
                        CapsInBytes += req.Response.ToString().Length;
                        session.ImageIndex = 0;
                    }

                    AddSession(session);
                }
                else
                {
                    if (found == null)
                    {
                        // must be a new event not in KnownCaps, lets add it to the listview
                        ListViewItem addedItem = listViewMessageFilters.Items.Add(new ListViewItem(req.Info.CapType));
                        addedItem.BackColor = Color.AliceBlue;

                        if (autoAddNewDiscoveredMessagesToolStripMenuItem.Checked)
                            addedItem.Checked = true;
                    }
                }
            }
        }
示例#11
0
        /// <summary>
        /// Adds a new EventQueue message to the Message Filters listview.
        /// </summary>
        /// <param name="req"></param>
        /// <param name="stage"></param>
        void ProxyManager_OnEventMessageLog(CapsRequest req, CapsStage stage)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new MethodInvoker(delegate()
                {
                    ProxyManager_OnEventMessageLog(req, stage);
                }));
            }
            else
            {

                ListViewItem foundCap = FindListViewItem(listViewMessageFilters, req.Info.CapType, false);

                if (foundCap == null)
                {
                    ListViewItem addedItem = listViewMessageFilters.Items.Add(new ListViewItem(req.Info.CapType, new ListViewGroup("EventQueue Messages")));
                    addedItem.SubItems.Add("EventMessage");
                    addedItem.BackColor = Color.AliceBlue;

                    if (autoAddNewDiscoveredMessagesToolStripMenuItem.Checked)
                        addedItem.Checked = true;
                }
                else
                {
                    ProxyManager_OnMessageLog(req, CapsStage.Response);
                }
            }
        }
示例#12
0
文件: Grider.cs 项目: diva/Grider
        bool UpdateNotecardHandler(CapsRequest req, CapsStage stage)
        {
            Console.WriteLine(">> UpdateNotecard " + stage.ToString() + " to " + req.Info.URI);

            if (stage != CapsStage.Response) return true; // shortcircuit, so don't foward to sim

            string uri = (string)UserInventory.CapsHandlers["UpdateNotecardAgentInventory"]; //req.Info.URI;
            Console.WriteLine("[GRIDER]: Forwarding caps request to " + uri);
            Console.WriteLine("[GRIDER]:  request is " + req.Request);
            proxy.ForwardCaps(uri, req);
            return false;
        }
示例#13
0
文件: Grider.cs 项目: diva/Grider
        bool SeedCapHandler(CapsRequest req, CapsStage stage)
        {
            Console.WriteLine(">> SeedCapability " + stage.ToString() + " to " + req.Info.URI);

            if (stage != CapsStage.Response) return false;

            if (req.Response.Type == OSDType.Map)
            {
                OSDMap nm = (OSDMap)req.Response;

                // First, let's fix the EventQueue Cap
                if (nm["EventQueueGet"] != null)
                    Console.WriteLine("[GRIDER]: Original EQGet Cap " + nm["EventQueueGet"].AsString());
                else
                    Console.WriteLine("[GRIDER]: SeedCap response did not have EQGet Cap");

                //Agent.NextEQID = UUID.Random().ToString();
                string eqkey = Agent.LocalEQCAP + Agent.NextEQID + "/";

                nm["EventQueueGet"] = OSD.FromString(proxy.loginURI + eqkey);
                Console.WriteLine("[GRIDFER]: New EQGet Cap " + nm["EventQueueGet"].AsString());

                if (!proxy.KnownCaps.ContainsKey(eqkey))
                {
                    CapInfo newCap = new CapInfo(eqkey, req.Info.Sim, eqkey);
                    newCap.AddDelegate(new CapsDelegate(LocalEQHandler));
                    lock (proxy)
                        proxy.KnownCaps[eqkey] = newCap;
                }

                // Then, let's fix the UpdateScriptAgent Cap
                if (nm["UpdateScriptAgent"] != null)
                    Console.WriteLine("[GRIDER]: Original UpdateScriptAgent Cap " + nm["UpdateScriptAgent"].AsString());
                else
                    Console.WriteLine("[GRIDER]: SeedCap response did not have UpdateScriptAgent Cap");
                if (UserInventory.CapsHandlers.ContainsKey("UpdateScriptAgent"))
                {
                    string newcap = (string)UserInventory.CapsHandlers["UpdateScriptAgent"];
                    nm["UpdateScriptAgent"] = OSD.FromString(proxy.loginURI + newcap);
                    nm["UpdateNotecardAgentInventory"] = OSD.FromString(proxy.loginURI + newcap);
                    nm["UpdateScriptAgentInventory"] = OSD.FromString(proxy.loginURI + newcap);
                    if (!proxy.KnownCaps.ContainsKey(newcap))
                    {
                        CapInfo newCap = new CapInfo(newcap, req.Info.Sim, "UpdateScriptAgent");
                        lock (proxy)
                            proxy.KnownCaps[newcap] = newCap;
                    }
                    nm["UpdateScriptAgent"] = OSD.FromString(newcap);
                    nm["UpdateNotecardAgentInventory"] = OSD.FromString(newcap);
                    nm["UpdateScriptAgentInventory"] = OSD.FromString(newcap);

                    Console.WriteLine("[GRIDER]: New UpdateScriptAgent Cap " + nm["UpdateScriptAgent"].AsString());
                }
                else
                    Console.WriteLine("[GRIDER]: UserInventory does not contain UpdateScriptAgent Cap");
                if (UserInventory.CapsHandlers.ContainsKey("NewFileAgentInventory"))
                {
                    string newcap = (string)UserInventory.CapsHandlers["NewFileAgentInventory"];
                    if (!proxy.KnownCaps.ContainsKey(newcap))
                    {
                        CapInfo newCap = new CapInfo(newcap, req.Info.Sim, "NewFileAgentInventory");
                        lock (proxy)
                            proxy.KnownCaps[newcap] = newCap;
                    }
                    nm["NewFileAgentInventory"] = OSD.FromString(newcap);

                    Console.WriteLine("[GRIDER]: New NewFileAgentInventory Cap " + nm["NewFileAgentInventory"].AsString());
                }
                else
                    Console.WriteLine("[GRIDER]: UserInventory does not contain NewFileAgentInventory Cap");

            }

            //Console.WriteLine("---------------");
            //lock (this)
            //{
            //    foreach (KeyValuePair<string, CapInfo> kvp in KnownCaps)
            //    {
            //        Console.WriteLine(" >> Key: " + kvp.Key + "; Value: " + kvp.Value.CapType);
            //    }
            //}
            //Console.WriteLine("---------------");

            return false;
        }
示例#14
0
        /// <summary>
        /// Adds a new EventQueue message to the Message Filters listview.
        /// </summary>
        /// <param name="req"></param>
        /// <param name="stage"></param>
        void ProxyManager_OnEventMessageLog(CapsRequest req, CapsStage stage)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new MethodInvoker(() => ProxyManager_OnEventMessageLog(req, stage)));
            }
            else
            {
                ListViewItem foundCap = FindListViewItem(listViewMessageFilters, req.Info.CapType, false);

                if (foundCap == null)
                {
                    ListViewItem addedItem = listViewMessageFilters.Items.Add(new ListViewItem(req.Info.CapType,
                        listViewMessageFilters.Groups["EventQueueMessages"]));

                    addedItem.SubItems.Add(PROTO_EVENTMESSAGE);
                    addedItem.BackColor = Color_Event;

                    if (autoAddNewDiscoveredMessagesToolStripMenuItem.Checked)
                        addedItem.Checked = true;
                }
                else
                {
                    ProxyManager_OnMessageLog(req, CapsStage.Response);
                }
            }
        }
示例#15
0
 private bool CapsHandler(CapsRequest req, CapsStage stage)
 {
     if (OnMessageLog != null)
         OnMessageLog(req, stage);
     return false;
 }
示例#16
0
        /// <summary>
        /// Handle Capabilities 
        /// </summary>        
        private void ProxyManager_OnMessageLog(CapsRequest req, CapsStage stage)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new MethodInvoker(() => ProxyManager_OnMessageLog(req, stage)));
            }
            else
            {
                ListViewItem found = FindListViewItem(listViewMessageFilters, req.Info.CapType, false);

                if (found != null && found.Checked)
                {
                    PacketCounter++;

                    int size = 0;
                    string contentType = String.Empty;
                    if (req.RawRequest != null)
                    {
                        size += req.RawRequest.Length;
                        contentType = req.RequestHeaders.Get("Content-Type"); //req.RequestHeaders["Content-Type"];
                    }
                    if (req.RawResponse != null)
                    {
                        size += req.RawResponse.Length;
                        contentType = req.ResponseHeaders.Get("Content-Type");
                    }

                    Direction direction;
                    if (stage == CapsStage.Request)
                    {
                        CapsOutCounter++;
                        CapsOutBytes += req.Request.ToString().Length;
                        direction = Direction.Outgoing;
                    }
                    else
                    {
                        CapsInCounter++;
                        CapsInBytes += req.Response.ToString().Length;
                        direction = Direction.Incoming;
                    }

                    string proto = found.SubItems[1].Text;

                    Session capsSession = null;
                    if (found.Group.Header.Equals("Capabilities"))
                    {
                        capsSession = new SessionCaps(req.RawRequest, req.RawResponse, req.RequestHeaders,
                        req.ResponseHeaders, direction, req.Info.URI, req.Info.CapType, proto);
                    }
                    else
                    {
                        capsSession = new SessionEvent(req.RawResponse, req.ResponseHeaders, req.Info.URI, req.Info.CapType, proto);
                    }

                    string[] s = { PacketCounter.ToString(), capsSession.Protocol, capsSession.Name, capsSession.Length.ToString(), capsSession.Host, capsSession.ContentType };
                    ListViewItem session = new ListViewItem(s);

                    session.ImageIndex = (int)direction;
                    session.Tag = capsSession;

                    session.BackColor = found.BackColor;

                    m_SessionViewItems.Add(capsSession);
                }
                else
                {
                    if (found == null)
                    {
                        // must be a new event not in KnownCaps, lets add it to the listview
                        ListViewItem addedItem = listViewMessageFilters.Items.Add(new ListViewItem(req.Info.CapType));
                        addedItem.BackColor = Color_Cap;

                        if (autoAddNewDiscoveredMessagesToolStripMenuItem.Checked)
                            addedItem.Checked = true;
                    }
                }
            }
        }
示例#17
0
文件: Grider.cs 项目: diva/Grider
 bool EventQueueGetHandler(CapsRequest req, CapsStage stage)
 {
     Console.WriteLine(">> EventQueuGet ");
     return false;
 }