public AgentPreferencesServiceConnector(IConfigSource config, IHttpServer server, string configName) :
                base(config, server, configName)
        {
            IConfig serverConfig = config.Configs[m_ConfigName];
            if (serverConfig == null)
                throw new Exception(String.Format("No section {0} in config file", m_ConfigName));

            string service = serverConfig.GetString("LocalServiceModule", String.Empty);

            if (String.IsNullOrWhiteSpace(service))
                throw new Exception("No LocalServiceModule in config file");

            Object[] args = new Object[] { config };
            m_AgentPreferencesService = ServerUtils.LoadPlugin<IAgentPreferencesService>(service, args);

            IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); ;

            server.AddStreamHandler(new AgentPreferencesServerPostHandler(m_AgentPreferencesService, auth));
        }
        public void Initialise(IConfigSource source)
        {
            IConfig moduleConfig = source.Configs["Modules"];

            if (moduleConfig != null)
            {
                string name = moduleConfig.GetString("AgentPreferencesServices", "");
                if (name == Name)
                {
                    IConfig userConfig = source.Configs["AgentPreferencesService"];
                    if (userConfig == null)
                    {
                        m_log.Error("[AGENT PREFERENCES CONNECTOR]: AgentPreferencesService missing from OpenSim.ini");
                        return;
                    }

                    string serviceDll = userConfig.GetString("LocalServiceModule", String.Empty);

                    if (String.IsNullOrEmpty(serviceDll))
                    {
                        m_log.Error("[AGENT PREFERENCES CONNECTOR]: No AgentPreferencesModule named in section AgentPreferencesService");
                        return;
                    }

                    Object[] args = new Object[] { source };
                    m_AgentPreferencesService = ServerUtils.LoadPlugin <IAgentPreferencesService>(serviceDll, args);

                    if (m_AgentPreferencesService == null)
                    {
                        m_log.Error("[AGENT PREFERENCES CONNECTOR]: Can't load agent preferences service");
                        return;
                    }
                    m_Enabled = true;
                    m_log.Info("[AGENT PREFERENCES CONNECTOR]: Local agent preferences connector enabled");
                }
            }
        }
Esempio n. 3
0
        public AgentPreferencesServiceConnector(IConfigSource config, IHttpServer server, string configName) :
            base(config, server, configName)
        {
            IConfig serverConfig = config.Configs[m_ConfigName];

            if (serverConfig == null)
            {
                throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
            }

            string service = serverConfig.GetString("LocalServiceModule", String.Empty);

            if (String.IsNullOrWhiteSpace(service))
            {
                throw new Exception("No LocalServiceModule in config file");
            }

            Object[] args = new Object[] { config };
            m_AgentPreferencesService = ServerUtils.LoadPlugin <IAgentPreferencesService>(service, args);

            IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);;

            server.AddStreamHandler(new AgentPreferencesServerPostHandler(m_AgentPreferencesService, auth));
        }
 public AgentPreferencesServerPostHandler(IAgentPreferencesService service, IServiceAuth auth) :
     base("POST", "/agentprefs", auth)
 {
     m_AgentPreferencesService = service;
 }
 public AgentPreferencesServerPostHandler(IAgentPreferencesService service, IServiceAuth auth) :
 base("POST", "/agentprefs", auth)
 {
     m_AgentPreferencesService = service;
 }
        public void UpdateAgentPreferences(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID agent)
        {
            if (httpRequest.HttpMethod != "POST")
            {
                httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            //m_log.DebugFormat("[AgentPrefs]: UpdateAgentPreferences for {0}", agent.ToString());
            OSDMap req;

            try
            {
                req = (OSDMap)OSDParser.DeserializeLLSDXml(httpRequest.InputStream);
            }
            catch
            {
                httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
                return;
            }

            IAgentPreferencesService aps = m_scenes[0].AgentPreferencesService;
            AgentPrefs data = null;

            if (aps != null)
            {
                data = aps.GetAgentPreferences(agent);
            }

            if (data == null)
            {
                data = new AgentPrefs(agent);
            }

            bool changed = false;
            OSD  tmp;

            if (req.TryGetValue("access_prefs", out tmp) && tmp is OSDMap)
            {
                OSDMap accessPrefs = (OSDMap)tmp;  // We could check with ContainsKey...
                data.AccessPrefs = accessPrefs["max"].AsString();
                changed          = true;
            }
            if (req.TryGetValue("default_object_perm_masks", out tmp) && tmp is OSDMap)
            {
                OSDMap permsMap = (OSDMap)tmp;
                data.PermEveryone  = permsMap["Everyone"].AsInteger();
                data.PermGroup     = permsMap["Group"].AsInteger();
                data.PermNextOwner = permsMap["NextOwner"].AsInteger();
                changed            = true;
            }
            if (req.TryGetValue("hover_height", out tmp))
            {
                data.HoverHeight = (float)tmp.AsReal();
                changed          = true;
            }
            if (req.TryGetValue("language", out tmp))
            {
                data.Language = tmp.AsString();
                changed       = true;
            }
            if (req.TryGetValue("language_is_public", out tmp))
            {
                data.LanguageIsPublic = tmp.AsBoolean();
                changed = true;
            }

            if (changed)
            {
                aps?.StoreAgentPreferences(data);
            }

            IAvatarFactoryModule afm = m_scenes[0].RequestModuleInterface <IAvatarFactoryModule>();

            afm?.SetPreferencesHoverZ(agent, (float)data.HoverHeight);

            OSDMap resp            = new OSDMap();
            OSDMap respAccessPrefs = new OSDMap();

            respAccessPrefs["max"] = data.AccessPrefs;
            resp["access_prefs"]   = respAccessPrefs;

            OSDMap respDefaultPerms = new OSDMap();

            respDefaultPerms["Everyone"]  = data.PermEveryone;
            respDefaultPerms["Group"]     = data.PermGroup;
            respDefaultPerms["NextOwner"] = data.PermNextOwner;

            resp["default_object_perm_masks"] = respDefaultPerms;
            resp["god_level"]          = 0; // *TODO: Add this
            resp["hover_height"]       = data.HoverHeight;
            resp["language"]           = data.Language;
            resp["language_is_public"] = data.LanguageIsPublic;

            httpResponse.RawBuffer  = OSDParser.SerializeLLSDXmlBytes(resp);
            httpResponse.StatusCode = (int)HttpStatusCode.OK;
        }
        public void Initialise(IConfigSource source)
        {
            IConfig moduleConfig = source.Configs["Modules"];
            if (moduleConfig != null)
            {
                string name = moduleConfig.GetString("AgentPreferencesServices", "");
                if (name == Name)
                {
                    IConfig userConfig = source.Configs["AgentPreferencesService"];
                    if (userConfig == null)
                    {
                        m_log.Error("[AGENT PREFERENCES CONNECTOR]: AgentPreferencesService missing from OpenSim.ini");
                        return;
                    }

                    string serviceDll = userConfig.GetString("LocalServiceModule", String.Empty);

                    if (String.IsNullOrEmpty(serviceDll))
                    {
                        m_log.Error("[AGENT PREFERENCES CONNECTOR]: No AgentPreferencesModule named in section AgentPreferencesService");
                        return;
                    }

                    Object[] args = new Object[] { source };
                    m_AgentPreferencesService = ServerUtils.LoadPlugin<IAgentPreferencesService>(serviceDll, args);

                    if (m_AgentPreferencesService == null)
                    {
                        m_log.Error("[AGENT PREFERENCES CONNECTOR]: Can't load agent preferences service");
                        return;
                    }
                    m_Enabled = true;
                    m_log.Info("[AGENT PREFERENCES CONNECTOR]: Local agent preferences connector enabled");
                }
            }
        }