Beispiel #1
0
        // -----------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        // -----------------------------------------------------------------
        protected bool SetValueFromExpression(string expr, OSD ovalue)
        {
            Stack <string> path;

            if (!ParsePathExpression(expr, out path))
            {
                return(false);
            }

            if (path.Count == 0)
            {
                ValueStore  = ovalue;
                StringSpace = 0;
                return(true);
            }

            // pkey will be the final element in the path, we pull it out here to make sure
            // that the assignment works correctly
            string pkey  = path.Pop();
            string pexpr = PathExpressionToKey(path);

            if (pexpr != "")
            {
                pexpr += ".";
            }

            OSD result = ProcessPathExpression(ValueStore, path);

            if (result == null)
            {
                return(false);
            }

            // Check pkey, the last element in the path, for and extract array references
            MatchCollection amatches = m_ArrayPattern.Matches(pkey, 0);

            if (amatches.Count > 0)
            {
                if (result.Type != OSDType.Array)
                {
                    return(false);
                }

                OSDArray amap = result as OSDArray;

                Match           match  = amatches[0];
                GroupCollection groups = match.Groups;
                string          akey   = groups[1].Value;

                if (akey == "+")
                {
                    string npkey = String.Format("[{0}]", amap.Count);

                    if (ovalue != null)
                    {
                        StringSpace += ComputeSizeOf(ovalue);

                        amap.Add(ovalue);
                        InvokeNextCallback(pexpr + npkey);
                    }
                    return(true);
                }

                int aval = Convert.ToInt32(akey);
                if (0 <= aval && aval < amap.Count)
                {
                    if (ovalue == null)
                    {
                        StringSpace -= ComputeSizeOf(amap[aval]);
                        amap.RemoveAt(aval);
                    }
                    else
                    {
                        StringSpace -= ComputeSizeOf(amap[aval]);
                        StringSpace += ComputeSizeOf(ovalue);
                        amap[aval]   = ovalue;
                        InvokeNextCallback(pexpr + pkey);
                    }
                    return(true);
                }

                return(false);
            }

            // Check for and extract hash references
            MatchCollection hmatches = m_HashPattern.Matches(pkey, 0);

            if (hmatches.Count > 0)
            {
                Match           match  = hmatches[0];
                GroupCollection groups = match.Groups;
                string          hkey   = groups[1].Value;

                if (result is OSDMap)
                {
                    // this is the assignment case
                    OSDMap hmap = result as OSDMap;
                    if (ovalue != null)
                    {
                        StringSpace -= ComputeSizeOf(hmap[hkey]);
                        StringSpace += ComputeSizeOf(ovalue);

                        hmap[hkey] = ovalue;
                        InvokeNextCallback(pexpr + pkey);
                        return(true);
                    }

                    // this is the remove case
                    if (hmap.ContainsKey(hkey))
                    {
                        StringSpace -= ComputeSizeOf(hmap[hkey]);
                        hmap.Remove(hkey);
                        return(true);
                    }

                    return(false);
                }

                return(false);
            }

            // Shouldn't get here if the path was checked correctly
            m_log.WarnFormat("[JsonStore] invalid path expression");
            return(false);
        }
        public Hashtable GetEvents(UUID requestID, UUID pAgentId, string request)
        {
            OSDMap events = new OSDMap();

            try
            {
                OSD element;
                lock (queue)
                {
                    if (queue.Count == 0)
                    {
                        return(NoEvents(requestID, pAgentId));
                    }
                    element = queue.Dequeue();
                }

                OSDArray array = new OSDArray();
                if (element == null) // didn't have an event in 15s
                {
                    //return NoEvents(requestID, pAgentId);
                    // Send it a fake event to keep the client polling!   It doesn't like 502s like the proxys say!
                    OSDMap keepAliveEvent = new OSDMap(2)
                    {
                        { "body", new OSDMap() }, { "message", new OSDString("FAKEEVENT") }
                    };
                    element = keepAliveEvent;
                    array.Add(keepAliveEvent);
                    //MainConsole.Instance.DebugFormat("[EVENTQUEUE]: adding fake event for {0} in region {1}", pAgentId, m_scene.RegionInfo.RegionName);
                }

                array.Add(element);
                lock (queue)
                {
                    while (queue.Count > 0)
                    {
                        array.Add(queue.Dequeue());
                        m_ids++;
                    }
                }

                int removeAt = -1;
                //Look for disable Simulator EQMs so that we can disable ourselves safely
                foreach (OSD ev in array)
                {
                    try
                    {
                        if (ev.Type == OSDType.Map)
                        {
                            OSDMap map = (OSDMap)ev;
                            if (map.ContainsKey("message") && map["message"] == "DisableSimulator")
                            {
                                MainConsole.Instance.Debug("[EQService]: Sim Request to Disable Simulator " + m_service.RegionHandle);
                                removeAt = array.IndexOf(ev);
                                //This will be the last bunch of EQMs that go through, so we can safely die now
                                //Except that we can't do this, the client will freak if we do this
                                //m_service.ClientCaps.RemoveCAPS(m_service.RegionHandle);
                            }
                        }
                    }
                    catch
                    {
                    }
                }
                if (removeAt != -1)
                {
                    array.RemoveAt(removeAt);
                }

                events.Add("events", array);

                events.Add("id", new OSDInteger(m_ids));
                m_ids++;
            }
            catch (Exception ex)
            {
                MainConsole.Instance.Warn("[EQS]: Exception! " + ex);
            }
            Hashtable responsedata = new Hashtable();

            responsedata["int_response_code"]   = 200;
            responsedata["content_type"]        = "application/xml";
            responsedata["keepalive"]           = false;
            responsedata["reusecontext"]        = false;
            responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(events);
            //MainConsole.Instance.DebugFormat("[EVENTQUEUE]: sending response for {0} in region {1}: {2}", pAgentId, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]);
            return(responsedata);
        }
Beispiel #3
0
        public Hashtable GetEvents(UUID requestID, UUID pAgentId, string request)
        {
            OSDMap events = new OSDMap();
            try
            {
                OSD element;
                lock (queue)
                {
                    if (queue.Count == 0)
                        return NoEvents(requestID, pAgentId);
                    element = queue.Dequeue();
                }

                OSDArray array = new OSDArray();
                if (element == null) // didn't have an event in 15s
                {
                    //return NoEvents(requestID, pAgentId);
                    // Send it a fake event to keep the client polling!   It doesn't like 502s like the proxys say!
                    OSDMap keepAliveEvent = new OSDMap(2)
                                                {{"body", new OSDMap()}, {"message", new OSDString("FAKEEVENT")}};
                    element = keepAliveEvent;
                    array.Add(keepAliveEvent);
                    //MainConsole.Instance.DebugFormat("[EVENTQUEUE]: adding fake event for {0} in region {1}", pAgentId, m_scene.RegionInfo.RegionName);
                }

                array.Add(element);
                lock (queue)
                {
                    while (queue.Count > 0)
                    {
                        array.Add(queue.Dequeue());
                        m_ids++;
                    }
                }

                int removeAt = -1;
                //Look for disable Simulator EQMs so that we can disable ourselves safely
                foreach (OSD ev in array)
                {
                    try
                    {
                        if (ev.Type == OSDType.Map)
                        {
                            OSDMap map = (OSDMap) ev;
                            if (map.ContainsKey("message") && map["message"] == "DisableSimulator")
                            {
                                MainConsole.Instance.Debug("[EQService]: Sim Request to Disable Simulator " + m_service.RegionHandle);
                                removeAt = array.IndexOf(ev);
                                //This will be the last bunch of EQMs that go through, so we can safely die now
                                //Except that we can't do this, the client will freak if we do this
                                //m_service.ClientCaps.RemoveCAPS(m_service.RegionHandle);
                            }
                        }
                    }
                    catch
                    {
                    }
                }
                if (removeAt != -1)
                    array.RemoveAt(removeAt);

                events.Add("events", array);

                events.Add("id", new OSDInteger(m_ids));
                m_ids++;
            }
            catch (Exception ex)
            {
                MainConsole.Instance.Warn("[EQS]: Exception! " + ex);
            }
            Hashtable responsedata = new Hashtable();
            responsedata["int_response_code"] = 200;
            responsedata["content_type"] = "application/xml";
            responsedata["keepalive"] = false;
            responsedata["reusecontext"] = false;
            responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(events);
            //MainConsole.Instance.DebugFormat("[EVENTQUEUE]: sending response for {0} in region {1}: {2}", pAgentId, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]);
            return responsedata;
        }
Beispiel #4
0
        // -----------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        // -----------------------------------------------------------------
        protected bool SetValueFromExpression(string expr, OSD ovalue)
        {
            Stack <string> path = ParsePathExpression(expr);

            if (path.Count == 0)
            {
                m_ValueStore = ovalue;
                return(true);
            }

            string pkey  = path.Pop();
            string pexpr = PathExpressionToKey(path);

            if (pexpr != "")
            {
                pexpr += ".";
            }

            OSD result = ProcessPathExpression(m_ValueStore, path);

            if (result == null)
            {
                return(false);
            }

            Regex           aPattern = new Regex("\\[([0-9]+|\\+)\\]");
            MatchCollection amatches = aPattern.Matches(pkey, 0);

            if (amatches.Count > 0)
            {
                if (result.Type != OSDType.Array)
                {
                    return(false);
                }

                OSDArray amap = result as OSDArray;

                Match           match  = amatches[0];
                GroupCollection groups = match.Groups;
                string          akey   = groups[1].Value;

                if (akey == "+")
                {
                    string npkey = String.Format("[{0}]", amap.Count);

                    amap.Add(ovalue);
                    InvokeNextCallback(pexpr + npkey);
                    return(true);
                }

                int aval = Convert.ToInt32(akey);
                if (0 <= aval && aval < amap.Count)
                {
                    if (ovalue == null)
                    {
                        amap.RemoveAt(aval);
                    }
                    else
                    {
                        amap[aval] = ovalue;
                        InvokeNextCallback(pexpr + pkey);
                    }
                    return(true);
                }

                return(false);
            }

            Regex           hPattern = new Regex("{([^}]+)}");
            MatchCollection hmatches = hPattern.Matches(pkey, 0);

            if (hmatches.Count > 0)
            {
                Match           match  = hmatches[0];
                GroupCollection groups = match.Groups;
                string          hkey   = groups[1].Value;

                if (result is OSDMap)
                {
                    OSDMap hmap = result as OSDMap;
                    if (ovalue != null)
                    {
                        hmap[hkey] = ovalue;
                        InvokeNextCallback(pexpr + pkey);
                    }
                    else if (hmap.ContainsKey(hkey))
                    {
                        hmap.Remove(hkey);
                    }

                    return(true);
                }

                return(false);
            }

            // Shouldn't get here if the path was checked correctly
            m_log.WarnFormat("[JsonStore] invalid path expression");
            return(false);
        }