public bool Cross(ScenePresence agent, bool isFlying)
        {
            Scene scene = agent.Scene;
            Vector3 pos = agent.AbsolutePosition;
            Vector3 newpos = new Vector3(pos.X, pos.Y, pos.Z);
            uint neighbourx;
            uint neighboury;
            const float boundaryDistance = 1.7f;

            // assuming that the need for crossing was verified by callers

            int x, y;

            if (scene.RegionInfo.CombinedRegionHandle != 0) // we are a slave region send to main region
            {
                Utils.LongToUInts(scene.RegionInfo.CombinedRegionHandle, out neighbourx, out neighboury);

                agent.IsInTransit = true;

                Vector3 newposition = pos;
                newposition.X += ((int)scene.RegionInfo.RegionLocX * Constants.RegionSize - (int)neighbourx);
                newposition.Y += ((int)scene.RegionInfo.RegionLocY * Constants.RegionSize - (int)neighboury);
                agent.ControllingClient.SendAgentAlertMessage(
                    String.Format("Relocating you in root region"), false);

                InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
                return true;
            }

            if (pos.X - boundaryDistance < 0) // going W
            {
                x = -1;
                newpos.X = Constants.RegionSize + pos.X - boundaryDistance;
            }
            else // assume we are going E
            {
                x = ((int)(pos.X + boundaryDistance) / (int)Constants.RegionSize);
                newpos.X = pos.X - x * (int)Constants.RegionSize;
            }

            x += (int)scene.RegionInfo.RegionLocX;
            neighbourx = (uint)x;
            x *= (int)Constants.RegionSize;

            if (pos.Y - boundaryDistance < 0) // going S  SW or SE
            {
                y = -1;
                newpos.Y = Constants.RegionSize + pos.Y - boundaryDistance;
            }
            else // assume we are going N NW or NE
            {
                y = ((int)(pos.Y + boundaryDistance) / (int)Constants.RegionSize);
                newpos.Y = pos.Y - y * (int)Constants.RegionSize;
            }

            y += (int)scene.RegionInfo.RegionLocY;
            neighboury = (uint)y;
            y *= (int)Constants.RegionSize;


            //            int x = (int)(neighbourx * Constants.RegionSize), y = (int)(neighboury * Constants.RegionSize);

            ulong neighbourHandle = Utils.UIntsToLong((uint)x, (uint)y);

            ExpiringCache<ulong, DateTime> r;
            DateTime banUntil;

            if (m_bannedRegions.TryGetValue(agent.ControllingClient.AgentId, out r))
            {
                if (r.TryGetValue(neighbourHandle, out banUntil))
                {
                    if (DateTime.Now < banUntil)
                        return false;
                    r.Remove(neighbourHandle);
                }
            }
            else
            {
                r = null;
            }


            GridRegion neighbourRegion = scene.GridService.GetRegionByPosition(scene.RegionInfo.ScopeID, x, y);

            if (neighbourRegion == null)
                return false;

            string reason;
            string version;
            if (!scene.SimulationService.QueryAccess(neighbourRegion, agent.ControllingClient.AgentId, newpos, out version, out reason))
            {
                agent.ControllingClient.SendAlertMessage("Cannot region cross into banned parcel");
                if (r == null)
                {
                    r = new ExpiringCache<ulong, DateTime>();
                    r.Add(neighbourHandle, DateTime.Now + TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));

                    m_bannedRegions.Add(agent.ControllingClient.AgentId, r, TimeSpan.FromSeconds(45));
                }
                else
                {
                    r.Add(neighbourHandle, DateTime.Now + TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));
                }
                return false;
            }

            agent.IsInTransit = true;

            CrossAgentToNewRegionDelegate d = CrossAgentToNewRegionAsync;
            d.BeginInvoke(agent, newpos, neighbourx, neighboury, neighbourRegion, isFlying, version, CrossAgentToNewRegionCompleted, d);

            return true;
        }
        public HGInstantMessageService(IConfigSource config, IInstantMessageSimConnector imConnector)
        {
            if (imConnector != null)
            {
                m_IMSimConnector = imConnector;
            }

            if (!m_Initialized)
            {
                m_Initialized = true;

                IConfig serverConfig = config.Configs["HGInstantMessageService"];
                if (serverConfig == null)
                {
                    throw new Exception(String.Format("No section HGInstantMessageService in config file"));
                }

                string gridService      = serverConfig.GetString("GridService", String.Empty);
                string presenceService  = serverConfig.GetString("PresenceService", String.Empty);
                string userAgentService = serverConfig.GetString("UserAgentService", String.Empty);
                m_InGatekeeper = serverConfig.GetBoolean("InGatekeeper", false);
                m_log.DebugFormat("[HG IM SERVICE]: Starting... InRobust? {0}", m_InGatekeeper);

                if (gridService == string.Empty || presenceService == string.Empty)
                {
                    throw new Exception(String.Format("Incomplete specifications, InstantMessage Service cannot function."));
                }

                Object[] args = new Object[] { config };
                m_GridService     = ServerUtils.LoadPlugin <IGridService>(gridService, args);
                m_PresenceService = ServerUtils.LoadPlugin <IPresenceService>(presenceService, args);
                try
                {
                    m_UserAgentService = ServerUtils.LoadPlugin <IUserAgentService>(userAgentService, args);
                }
                catch
                {
                    m_log.WarnFormat("[HG IM SERVICE]: Unable to create User Agent Service. Missing config var  in [HGInstantMessageService]?");
                }

                m_RegionCache = new ExpiringCache <UUID, GridRegion>();

                IConfig cnf = config.Configs["Messaging"];
                if (cnf == null)
                {
                    return;
                }

                m_ForwardOfflineGroupMessages = cnf.GetBoolean("ForwardOfflineGroupMessages", false);

                if (m_InGatekeeper)
                {
                    string offlineIMService = cnf.GetString("OfflineIMService", string.Empty);
                    if (offlineIMService != string.Empty)
                    {
                        m_OfflineIMService = ServerUtils.LoadPlugin <IOfflineIMService>(offlineIMService, args);
                    }
                }
            }
        }
Beispiel #3
0
        public void RegionLoaded(Scene scene)
        {
            if (m_Enabled)
            {
                if (m_AssetService == null)
                {
                    m_AssetService = scene.RequestModuleInterface <IAssetService>();
                }
                lock (timerLock)
                {
                    if (!m_timerRunning)
                    {
                        if (m_FileCacheEnabled && (m_FileExpiration > TimeSpan.Zero) && (m_FileExpirationCleanupTimer > TimeSpan.Zero))
                        {
                            m_CacheCleanTimer           = new System.Timers.Timer(m_FileExpirationCleanupTimer.TotalMilliseconds);
                            m_CacheCleanTimer.AutoReset = false;
                            m_CacheCleanTimer.Elapsed  += CleanupExpiredFiles;
                            m_CacheCleanTimer.Start();
                            m_timerRunning = true;
                        }
                    }
                }
                if (m_MemoryCacheEnabled)
                {
                    m_MemoryCache = new ExpiringCache <string, AssetBase>();
                }

                lock (weakAssetReferencesLock)
                    weakAssetReferences = new Dictionary <string, WeakReference>();
            }
        }
Beispiel #4
0
        public void Clear()
        {
            if (m_LogLevel >= 2)
            {
                m_log.Debug("[FLOTSAM ASSET CACHE]: Clearing caches.");
            }

            if (m_FileCacheEnabled && Directory.Exists(m_CacheDirectory))
            {
                foreach (string dir in Directory.GetDirectories(m_CacheDirectory))
                {
                    Directory.Delete(dir);
                }
            }

            if (m_MemoryCacheEnabled)
            {
                m_MemoryCache = new ExpiringCache <string, AssetBase>();
            }
            if (m_negativeCacheEnabled)
            {
                m_negativeCache = new ExpiringCache <string, object>();
            }

            lock (weakAssetReferencesLock)
                weakAssetReferences = new Dictionary <string, WeakReference>();
        }
 public UserAccountCache()
 {
     // Warning: the size values are a bit fuzzy. What matters
     // most for this cache is the count value (128 entries).
     m_UUIDCache = new ExpiringCache<UUID, UserAccount>();
     m_NameCache = new ExpiringCache<string, UUID>(); // this one is unbound
 }
Beispiel #6
0
        public void Get_ExpiredValue_SavesNewValueWithCorrectExpirationTime()
        {
            // this test extends just checking a new value is returned, it ensures the new value is stored in the dictionary for subsequent cached requests after initial expiration, this fixes a bug where the cache never stored the value after an initial expiration.
            var itemLifeSpan = TimeSpan.FromMinutes(1);
            var cache        = new ExpiringCache <int, object>(k => null, itemLifeSpan);
            var key          = default(int);
            var value        = cache[key];
            var expiredValue = cache.GetCurrentValue(key);

            expiredValue.ExpiresAt = DateTime.Now.Add(-itemLifeSpan);
            Expect(expiredValue.Equals(expiredValue));
            Expect(expiredValue.IsExpired());

            var beforeLoaded = DateTime.Now;

            value = cache[key];
            var afterLoaded = DateTime.Now;

            var currentValue = cache.GetCurrentValue(key);

            Expect(currentValue != expiredValue);
            var lowerEnd = beforeLoaded.Add(itemLifeSpan);
            var upperEnd = afterLoaded.Add(itemLifeSpan);

            Expect(currentValue.ExpiresAt, Is.InRange(lowerEnd, upperEnd));
        }
        public void Equals_DifferentCachedValues_NotEqual()
        {
            var item = new ExpiringCache<int, int>.CachedValue(1, DateTime.Now);
            var otherItem = new ExpiringCache<int, int>.CachedValue(1, DateTime.Now);

            Expect(item, Is.Not.EqualTo(otherItem));
        }
Beispiel #8
0
        public void Equals_DifferentCachedValues_NotEqual()
        {
            var item = new ExpiringCache <int, int> .CachedValue(1, DateTime.Now);

            var otherItem = new ExpiringCache <int, int> .CachedValue(1, DateTime.Now);

            Expect(item, Is.Not.EqualTo(otherItem));
        }
Beispiel #9
0
        public void Get_KeyWithNullValue_ReturnsNull()
        {
            var cache = new ExpiringCache <int, object>(k => null, TimeSpan.FromMinutes(100));

            var value = cache[1];

            Expect(value, Is.Null);
        }
        public void Get_KeyWithNullValue_ReturnsNull()
        {
            var cache = new ExpiringCache<int, object>(k => null, TimeSpan.FromMinutes(100));

            var value = cache[1];

            Expect(value, Is.Null);
        }
        public void Get_KeyWithChangingValue_StaysSameWhileCached()
        {
            var cache = new ExpiringCache<int, object>(k => 1, TimeSpan.FromMinutes(100));
            var value = cache[1];
            Expect(value, Is.EqualTo(1));
            cache.OnMissingOrExpired = k => 2;

            value = cache[1];

            Expect(value, Is.EqualTo(1));
        }
Beispiel #12
0
        public void Initialise(IConfigSource config)
        {
            IConfig groupsConfig = config.Configs["Groups"];

            if (groupsConfig == null)
            {
                // Do not run this module by default.
                return;
            }
            else
            {
                // if groups aren't enabled, we're not needed.
                // if we're not specified as the connector to use, then we're not wanted
                if ((groupsConfig.GetBoolean("Enabled", false) == false) ||
                    (groupsConfig.GetString("ServicesConnectorModule", "XmlRpcGroupsServicesConnector") != Name))
                {
                    m_connectorEnabled = false;
                    return;
                }

                m_log.DebugFormat("[XMLRPC-GROUPS-CONNECTOR]: Initializing {0}", this.Name);

                m_groupsServerURI = groupsConfig.GetString("GroupsServerURI", string.Empty);
                if ((m_groupsServerURI == null) ||
                    (m_groupsServerURI == string.Empty))
                {
                    m_log.ErrorFormat("Please specify a valid URL for GroupsServerURI in OpenSim.ini, [Groups]");
                    m_connectorEnabled = false;
                    return;
                }

                m_disableKeepAlive = groupsConfig.GetBoolean("XmlRpcDisableKeepAlive", false);

                m_groupReadKey  = groupsConfig.GetString("XmlRpcServiceReadKey", string.Empty);
                m_groupWriteKey = groupsConfig.GetString("XmlRpcServiceWriteKey", string.Empty);


                m_cacheTimeout = groupsConfig.GetInt("GroupsCacheTimeout", 30);
                if (m_cacheTimeout == 0)
                {
                    m_log.WarnFormat("[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Disabled.");
                }
                else
                {
                    m_log.InfoFormat("[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Timeout set to {0}.", m_cacheTimeout);
                }

                m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", false);

                // If we got all the config options we need, lets start'er'up
                m_memoryCache      = new ExpiringCache <string, XmlRpcResponse>();
                m_connectorEnabled = true;
            }
        }
Beispiel #13
0
        public void AddOrUpdate(string path, string language, string languagePath)
        {
            ExpiringCache <string, string> map;

            if (!m_Cache.TryGetValue(path, out map))
            {
                map = new ExpiringCache <string, string>();
            }
            map.AddOrUpdate(language, languagePath, m_CachingTime);
            m_Cache[path] = map;
        }
Beispiel #14
0
        public void Get_KeyWithChangingValue_StaysSameWhileCached()
        {
            var cache = new ExpiringCache <int, object>(k => 1, TimeSpan.FromMinutes(100));
            var value = cache[1];

            Expect(value, Is.EqualTo(1));
            cache.OnMissingOrExpired = k => 2;

            value = cache[1];

            Expect(value, Is.EqualTo(1));
        }
        public SimianInventoryServiceConnector(string url)
        {
            if (!url.EndsWith("/") && !url.EndsWith("="))
            {
                url = url + '/';
            }
            m_serverUrl = url;

            if (m_ItemCache == null)
            {
                m_ItemCache = new ExpiringCache <UUID, InventoryItemBase>();
            }
        }
        public void Get_ExpiredValue_LoadsNewValue()
        {
            var cache = new ExpiringCache<int, object>(k => 0, TimeSpan.FromMinutes(-1));
            cache.ItemLifeSpan = TimeSpan.FromMinutes(-1);
            var key = 1;
            var value = cache[key];
            Expect(value, Is.EqualTo(0));
            cache.OnMissingOrExpired = k => 1;

            value = cache[key];

            Expect(value, Is.EqualTo(1));
        }
        // GET api/<controller>
        public IEnumerable <CalendarEvent> Get()
        {
            if (_cachedEvents == null)
            {
                _cachedEvents = new ExpiringCache <IEnumerable <CalendarEvent> >(GetEvents(null, null),
                                                                                 TimeSpan.FromMinutes(int.Parse(ConfigurationManager.AppSettings["GoogleCalendarMinutesToCacheEvents"])));
            }
            else if (_cachedEvents.IsExpired())
            {
                _cachedEvents.Refresh(GetEvents(null, null));
            }

            return(_cachedEvents.Item);
        }
Beispiel #18
0
        public void Get_ExpiredValue_LoadsNewValue()
        {
            var cache = new ExpiringCache <int, object>(k => 0, TimeSpan.FromMinutes(-1));

            cache.ItemLifeSpan = TimeSpan.FromMinutes(-1);
            var key   = 1;
            var value = cache[key];

            Expect(value, Is.EqualTo(0));
            cache.OnMissingOrExpired = k => 1;

            value = cache[key];

            Expect(value, Is.EqualTo(1));
        }
        public void Initialise(IConfigSource config)
        {
            IConfig groupsConfig = config.Configs["Groups"];

            if (groupsConfig == null)
            {
                // Do not run this module by default.
                return;
            }

            // if groups aren't enabled, we're not needed.
            // if we're not specified as the connector to use, then we're not wanted
            if ((groupsConfig.GetBoolean("Enabled", false) == false) ||
                (groupsConfig.GetString("MessagingModule", "") != Name))
            {
                m_groupMessagingEnabled = false;
                return;
            }

            m_groupMessagingEnabled = groupsConfig.GetBoolean("MessagingEnabled", true);

            if (!m_groupMessagingEnabled)
            {
                return;
            }

            m_messageOnlineAgentsOnly = groupsConfig.GetBoolean("MessageOnlineUsersOnly", false);

            if (m_messageOnlineAgentsOnly)
            {
                m_usersOnlineCache = new ExpiringCache <UUID, PresenceInfo[]>();
            }
            else
            {
                m_log.Error("[Groups.Messaging]: GroupsMessagingModule V2 requires MessageOnlineUsersOnly = true");
                m_groupMessagingEnabled = false;
                return;
            }

            m_debugEnabled = groupsConfig.GetBoolean("MessagingDebugEnabled", m_debugEnabled);

            m_log.InfoFormat(
                "[Groups.Messaging]: GroupsMessagingModule enabled with MessageOnlineOnly = {0}, DebugEnabled = {1}",
                m_messageOnlineAgentsOnly, m_debugEnabled);
        }
        private void CommonInit(IConfigSource source)
        {
            IConfig gridConfig = source.Configs["InventoryService"];

            if (gridConfig != null)
            {
                string serviceUrl = gridConfig.GetString("InventoryServerURI");
                if (!String.IsNullOrEmpty(serviceUrl))
                {
                    if (!serviceUrl.EndsWith("/") && !serviceUrl.EndsWith("="))
                    {
                        serviceUrl = serviceUrl + '/';
                    }
                    m_serverUrl = serviceUrl;

                    gridConfig = source.Configs["UserAccountService"];
                    if (gridConfig != null)
                    {
                        serviceUrl = gridConfig.GetString("UserAccountServerURI");
                        if (!String.IsNullOrEmpty(serviceUrl))
                        {
                            m_userServerUrl = serviceUrl;
                            m_Enabled       = true;
                            if (m_ItemCache == null)
                            {
                                m_ItemCache = new ExpiringCache <UUID, InventoryItemBase>();
                            }
                        }
                    }
                }
            }

            if (String.IsNullOrEmpty(m_serverUrl))
            {
                m_log.Info("[SIMIAN INVENTORY CONNECTOR]: No InventoryServerURI specified, disabling connector");
            }
            else if (String.IsNullOrEmpty(m_userServerUrl))
            {
                m_log.Info("[SIMIAN INVENTORY CONNECTOR]: No UserAccountServerURI specified, disabling connector");
            }
        }
        public void Initialise(IConfigSource config)
        {
            if (m_log.IsDebugEnabled)
            {
                m_log.InfoFormat("[GroupsMessagingModule]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
            }

            IConfig groupsConfig = config.Configs["Groups"];

            if (groupsConfig == null)
            {
                // Do not run this module by default.
                return;
            }

            // if groups aren't enabled, we're not needed.
            // if we're not specified as the connector to use, then we're not wanted
            if ((groupsConfig.GetBoolean("Enabled", false) == false) ||
                (groupsConfig.GetString("MessagingModule", "") != Name))
            {
                m_groupMessagingEnabled = false;
                return;
            }

            m_groupMessagingEnabled = groupsConfig.GetBoolean("MessagingEnabled", true);

            if (!m_groupMessagingEnabled)
            {
                return;
            }

            m_messageOnlineAgentsOnly = groupsConfig.GetBoolean("MessageOnlineUsersOnly", false);

            if (m_messageOnlineAgentsOnly)
            {
                m_usersOnlineCache = new ExpiringCache <UUID, PresenceInfo[]>();
            }

            m_log.InfoFormat("[GroupsMessagingModule]: GroupsMessagingModule enabled with MessageOnlineOnly = {0}", m_messageOnlineAgentsOnly);
        }
        public void Get_ExpiredValue_SavesNewValueWithCorrectExpirationTime()
        {
            // this test extends just checking a new value is returned, it ensures the new value is stored in the dictionary for subsequent cached requests after initial expiration, this fixes a bug where the cache never stored the value after an initial expiration.
            var itemLifeSpan = TimeSpan.FromMinutes(1);
            var cache = new ExpiringCache<int, object>(k => null, itemLifeSpan);
            var key = default(int);
            var value = cache[key];
            var expiredValue = cache.GetCurrentValue(key);
            expiredValue.ExpiresAt = DateTime.Now.Add(-itemLifeSpan);
            Expect(expiredValue.Equals(expiredValue));
            Expect(expiredValue.IsExpired());

            var beforeLoaded = DateTime.Now;
            value = cache[key];
            var afterLoaded = DateTime.Now;

            var currentValue = cache.GetCurrentValue(key);
            Expect(currentValue != expiredValue);
            var lowerEnd = beforeLoaded.Add(itemLifeSpan);
            var upperEnd = afterLoaded.Add(itemLifeSpan);
            Expect(currentValue.ExpiresAt, Is.InRange(lowerEnd, upperEnd));
        }
Beispiel #23
0
        public void Initialise(IConfigSource source)
        {
            if (Simian.IsSimianEnabled(source, "UserAccountServices", this.Name))
            {
                IConfig assetConfig = source.Configs["UserAccountService"];
                if (assetConfig == null)
                {
                    m_log.Error("[SIMIAN ACCOUNT CONNECTOR]: UserAccountService missing from OpenSim.ini");
                    throw new Exception("User account connector init error");
                }

                string serviceURI = assetConfig.GetString("UserAccountServerURI");
                if (String.IsNullOrEmpty(serviceURI))
                {
                    m_log.Error("[SIMIAN ACCOUNT CONNECTOR]: No UserAccountServerURI in section UserAccountService, skipping SimianUserAccountServiceConnector");
                    throw new Exception("User account connector init error");
                }

                m_accountCache = new ExpiringCache <UUID, UserAccount>();
                m_serverUrl    = serviceURI;
            }
        }
 public GenericAccountCache(double expirationTime)
 {
     CACHE_EXPIRATION_SECONDS = expirationTime;
     m_UUIDCache = new ExpiringCache <UUID, T>();
     m_NameCache = new ExpiringCache <string, UUID>();
 }
        public void Initialise(IConfigSource config)
        {
            IConfig groupsConfig = config.Configs["Groups"];

            if (groupsConfig == null)
            {
                // Do not run this module by default.
                return;
            }
            else
            {
                // if groups aren't enabled, we're not needed.
                // if we're not specified as the connector to use, then we're not wanted
                if ((groupsConfig.GetBoolean("Enabled", false) == false)
                     || (groupsConfig.GetString("MessagingModule", "") != Name))
                {
                    m_groupMessagingEnabled = false;
                    return;
                }

                m_groupMessagingEnabled = groupsConfig.GetBoolean("MessagingEnabled", true);

                if (!m_groupMessagingEnabled)
                {
                    return;
                }

                m_messageOnlineAgentsOnly = groupsConfig.GetBoolean("MessageOnlineUsersOnly", false);

                if (m_messageOnlineAgentsOnly)
                     m_usersOnlineCache = new ExpiringCache<UUID, PresenceInfo[]>();

                m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", true);
            }

            m_log.InfoFormat(
                "[GROUPS-MESSAGING]: GroupsMessagingModule enabled with MessageOnlineOnly = {0}, DebugEnabled = {1}",
                m_messageOnlineAgentsOnly, m_debugEnabled);
        }
Beispiel #26
0
 // Add this agent in this region as a banned person
 public void Add(ulong pRegionHandle, UUID pAgentID)
 {
     if (!m_bannedRegions.TryGetValue(pAgentID, out m_idCache))
     {
         m_idCache = new ExpiringCache<ulong, DateTime>();
         m_bannedRegions.Add(pAgentID, m_idCache, TimeSpan.FromSeconds(45));
     }
     m_idCache.Add(pRegionHandle, DateTime.Now + TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));
 }
Beispiel #27
0
        public void Initialise(IConfigSource source)
        {
            IConfig moduleConfig = source.Configs["Modules"];

            if (moduleConfig != null)
            {
                string name = moduleConfig.GetString("AssetCaching", String.Empty);

                if (name == Name)
                {
                    m_MemoryCache   = new ExpiringCache <string, AssetBase>();
                    m_negativeCache = new ExpiringCache <string, object>();
                    m_Enabled       = true;

                    m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} enabled", this.Name);

                    IConfig assetConfig = source.Configs["AssetCache"];
                    if (assetConfig == null)
                    {
                        m_log.Debug(
                            "[FLOTSAM ASSET CACHE]: AssetCache section missing from config (not copied config-include/FlotsamCache.ini.example?  Using defaults.");
                    }
                    else
                    {
                        m_FileCacheEnabled = assetConfig.GetBoolean("FileCacheEnabled", m_FileCacheEnabled);
                        m_CacheDirectory   = assetConfig.GetString("CacheDirectory", m_DefaultCacheDirectory);

                        m_MemoryCacheEnabled = assetConfig.GetBoolean("MemoryCacheEnabled", m_MemoryCacheEnabled);
                        m_MemoryExpiration   = assetConfig.GetDouble("MemoryCacheTimeout", m_MemoryExpiration);
                        m_MemoryExpiration  *= 3600.0; // config in hours to seconds

                        m_negativeCacheEnabled     = assetConfig.GetBoolean("NegativeCacheEnabled", m_negativeCacheEnabled);
                        m_negativeExpiration       = assetConfig.GetInt("NegativeCacheTimeout", m_negativeExpiration);
                        m_negativeCacheSliding     = assetConfig.GetBoolean("NegativeCacheSliding", m_negativeCacheSliding);
                        m_updateFileTimeOnCacheHit = assetConfig.GetBoolean("UpdateFileTimeOnCacheHit", m_updateFileTimeOnCacheHit);

    #if WAIT_ON_INPROGRESS_REQUESTS
                        m_WaitOnInprogressTimeout = assetConfig.GetInt("WaitOnInprogressTimeout", 3000);
    #endif

                        m_LogLevel       = assetConfig.GetInt("LogLevel", m_LogLevel);
                        m_HitRateDisplay = (ulong)assetConfig.GetLong("HitRateDisplay", (long)m_HitRateDisplay);

                        m_FileExpiration = TimeSpan.FromHours(assetConfig.GetDouble("FileCacheTimeout", m_DefaultFileExpiration));
                        m_FileExpirationCleanupTimer
                            = TimeSpan.FromHours(
                                  assetConfig.GetDouble("FileCleanupTimer", m_FileExpirationCleanupTimer.TotalHours));

                        m_CacheDirectoryTiers   = assetConfig.GetInt("CacheDirectoryTiers", m_CacheDirectoryTiers);
                        m_CacheDirectoryTierLen = assetConfig.GetInt("CacheDirectoryTierLength", m_CacheDirectoryTierLen);

                        m_CacheWarnAt = assetConfig.GetInt("CacheWarnAt", m_CacheWarnAt);
                    }

                    m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Directory {0}", m_CacheDirectory);


                    if (m_CacheDirectoryTiers < 1)
                    {
                        m_CacheDirectoryTiers = 1;
                    }
                    else if (m_CacheDirectoryTiers > 3)
                    {
                        m_CacheDirectoryTiers = 3;
                    }

                    if (m_CacheDirectoryTierLen < 1)
                    {
                        m_CacheDirectoryTierLen = 1;
                    }
                    else if (m_CacheDirectoryTierLen > 4)
                    {
                        m_CacheDirectoryTierLen = 4;
                    }

                    MainConsole.Instance.Commands.AddCommand("Assets", true, "fcache status", "fcache status", "Display cache status", HandleConsoleCommand);
                    MainConsole.Instance.Commands.AddCommand("Assets", true, "fcache clear", "fcache clear [file] [memory]", "Remove all assets in the cache.  If file or memory is specified then only this cache is cleared.", HandleConsoleCommand);
                    MainConsole.Instance.Commands.AddCommand("Assets", true, "fcache assets", "fcache assets", "Attempt a deep scan and cache of all assets in all scenes", HandleConsoleCommand);
                    MainConsole.Instance.Commands.AddCommand("Assets", true, "fcache expire", "fcache expire <datetime>", "Purge cached assets older then the specified date/time", HandleConsoleCommand);
                }
            }
        }
        public void Initialize(IConfigSource config, IRegistryCore registry)
        {
            IConfig moduleConfig = config.Configs ["Modules"];

            if (moduleConfig != null)
            {
                string name = moduleConfig.GetString("AssetCaching", string.Empty);

                if (name == Name)
                {
                    m_MemoryCache = new ExpiringCache <string, AssetBase> ();

                    IConfig assetConfig = config.Configs ["AssetCache"];
                    if (assetConfig == null)
                    {
                        // MainConsole.Instance.Warn("[Flotsam asset cache]: AssetCache missing from WhiteCore.ini, using defaults.");
                        // MainConsole.Instance.InfoFormat("[Flotsam asset cache]: Cache Directory", m_CacheDirectory);
                        return;
                    }

                    m_CacheDirectory = assetConfig.GetString("CacheDirectory", m_CacheDirectory);
                    if (m_CacheDirectory == "")
                    {
                        var defpath = registry.RequestModuleInterface <ISimulationBase> ().DefaultDataPath;
                        m_CacheDirectory = Path.Combine(defpath, Constants.DEFAULT_ASSETCACHE_DIR);
                        m_CacheDirectory = Path.Combine(m_CacheDirectory, "flotsam");
                    }
                    MainConsole.Instance.InfoFormat("[Flotsam asset cache]: Cache Directory '{0}'", m_CacheDirectory);

                    m_MemoryCacheEnabled = assetConfig.GetBoolean("MemoryCacheEnabled", false);
                    m_MemoryExpiration   =
                        TimeSpan.FromHours(assetConfig.GetDouble("MemoryCacheTimeout", m_DefaultMemoryExpiration));

#if WAIT_ON_INPROGRESS_REQUESTS
                    m_WaitOnInprogressTimeout = assetConfig.GetInt("WaitOnInprogressTimeout", 3000);
#endif

                    m_logLevel       = assetConfig.GetInt("LogLevel", 0);
                    m_HitRateDisplay = (ulong)assetConfig.GetInt("HitRateDisplay", 1000);

                    m_FileExpiration             = TimeSpan.FromHours(assetConfig.GetDouble("FileCacheTimeout", m_DefaultFileExpiration));
                    m_FileExpirationCleanupTimer = TimeSpan.FromHours(assetConfig.GetDouble("FileCleanupTimer", m_DefaultFileExpiration));
                    if ((m_FileExpiration > TimeSpan.Zero) && (m_FileExpirationCleanupTimer > TimeSpan.Zero))
                    {
                        m_CacheCleanTimer = new Timer(m_FileExpirationCleanupTimer.TotalMilliseconds)
                        {
                            AutoReset = true
                        };
                        m_CacheCleanTimer.Elapsed += CleanupExpiredFiles;
                        lock (m_CacheCleanTimer)
                            m_CacheCleanTimer.Start();
                    }

                    m_CacheDirectoryTiers = assetConfig.GetInt("CacheDirectoryTiers", 1);
                    if (m_CacheDirectoryTiers < 1)
                    {
                        m_CacheDirectoryTiers = 1;
                    }
                    else if (m_CacheDirectoryTiers > 3)
                    {
                        m_CacheDirectoryTiers = 3;
                    }

                    m_CacheDirectoryTierLen = assetConfig.GetInt("CacheDirectoryTierLength", 3);
                    if (m_CacheDirectoryTierLen < 1)
                    {
                        m_CacheDirectoryTierLen = 1;
                    }
                    else if (m_CacheDirectoryTierLen > 4)
                    {
                        m_CacheDirectoryTierLen = 4;
                    }

                    m_CacheWarnAt = assetConfig.GetInt("CacheWarnAt", 30000);

                    m_DeepScanBeforePurge = assetConfig.GetBoolean("DeepScanBeforePurge", false);

                    if (MainConsole.Instance != null)
                    {
                        MainConsole.Instance.Commands.AddCommand(
                            "fcache status",
                            "fcache status",
                            "Display cache status",
                            HandleConsoleCommand, false, true);

                        MainConsole.Instance.Commands.AddCommand(
                            "fcache clear",
                            "fcache clear [file] [memory]",
                            "Remove all assets in the file and/or memory cache",
                            HandleConsoleCommand, false, true);

                        MainConsole.Instance.Commands.AddCommand(
                            "fcache assets",
                            "fcache assets",
                            "Attempt a deep scan and cache of all assets in all scenes",
                            HandleConsoleCommand, false, true);

                        MainConsole.Instance.Commands.AddCommand(
                            "fcache expire",
                            "fcache expire <datetime>",
                            "Purge cached assets older then the specified date/time",
                            HandleConsoleCommand, false, true);
                    }
                    registry.RegisterModuleInterface <IImprovedAssetCache> (this);
                }
            }
        }
        public SimianInventoryServiceConnector(string url)
        {
            if (!url.EndsWith("/") && !url.EndsWith("="))
                url = url + '/';
            m_serverUrl = url;

            if (m_ItemCache == null)
                m_ItemCache = new ExpiringCache<UUID, InventoryItemBase>();

        }
        private void CommonInit(IConfigSource source)
        {
            IConfig gridConfig = source.Configs["InventoryService"];
            if (gridConfig != null)
            {
                string serviceUrl = gridConfig.GetString("InventoryServerURI");
                if (!String.IsNullOrEmpty(serviceUrl))
                {
                    if (!serviceUrl.EndsWith("/") && !serviceUrl.EndsWith("="))
                        serviceUrl = serviceUrl + '/';
                    m_serverUrl = serviceUrl;

                    gridConfig = source.Configs["UserAccountService"];
                    if (gridConfig != null)
                    {
                        serviceUrl = gridConfig.GetString("UserAccountServerURI");
                        if (!String.IsNullOrEmpty(serviceUrl))
                        {
                            m_userServerUrl = serviceUrl;
                            m_Enabled = true;
                            if (m_ItemCache == null)
                                m_ItemCache = new ExpiringCache<UUID, InventoryItemBase>();
                        }
                    }
                }
            }

            if (String.IsNullOrEmpty(m_serverUrl))
                m_log.Info("[SIMIAN INVENTORY CONNECTOR]: No InventoryServerURI specified, disabling connector");
            else if (String.IsNullOrEmpty(m_userServerUrl))
                m_log.Info("[SIMIAN INVENTORY CONNECTOR]: No UserAccountServerURI specified, disabling connector");
        }
Beispiel #31
0
 public RegionInfoCache()
 {
     m_UUIDCache = new ExpiringCache<ScopedRegionUUID, GridRegion>();
     m_NameCache = new ExpiringCache<ScopedRegionName, ScopedRegionUUID>();
     m_PositionCache = new ExpiringCache<ScopedRegionPosition, GridRegion>();
 }
        public void Initialise(IConfigSource config)
        {
			if (m_log.IsDebugEnabled) {
				m_log.InfoFormat ("[GroupsMessagingModule]: {0} called", System.Reflection.MethodBase.GetCurrentMethod ().Name);
			}

            IConfig groupsConfig = config.Configs["Groups"];

            if (groupsConfig == null)
                // Do not run this module by default.
                return;

            // if groups aren't enabled, we're not needed.
            // if we're not specified as the connector to use, then we're not wanted
            if ((groupsConfig.GetBoolean("Enabled", false) == false)
                    || (groupsConfig.GetString("MessagingModule", "") != Name))
            {
                m_groupMessagingEnabled = false;
                return;
            }

            m_groupMessagingEnabled = groupsConfig.GetBoolean("MessagingEnabled", true);

            if (!m_groupMessagingEnabled)
                return;

            m_messageOnlineAgentsOnly = groupsConfig.GetBoolean("MessageOnlineUsersOnly", false);

            if (m_messageOnlineAgentsOnly)
                m_usersOnlineCache = new ExpiringCache<UUID, PresenceInfo[]>();

            m_log.InfoFormat("[GroupsMessagingModule]: GroupsMessagingModule enabled with MessageOnlineOnly = {0}",m_messageOnlineAgentsOnly);
        }
Beispiel #33
0
 public UserAccountCache()
 {
     m_UUIDCache = new ExpiringCache <UUID, UserAccount>();
     m_NameCache = new ExpiringCache <string, UUID>();
 }
 public RegionInfoCache()
 {
     m_UUIDCache = new ExpiringCache<ScopedRegionUUID, GridRegion>();
     m_NameCache = new ExpiringCache<ScopedRegionName, ScopedRegionUUID>();
     m_HandleCache = new ExpiringCache<ScopedRegionHandle, ScopedRegionUUID>();
 }
        public void Start(IConfigSource config, IRegistryCore registry)
        {
            m_connector = DataManager.DataManager.RequestPlugin<WebAPIConnector>();
            if (m_connector == null || m_connector.Enabled == false || m_connector.Handler != Name)
            {
                return;
            }

            IConfig webapiConfig = config.Configs["WebAPI"];
            UUID.TryParse(webapiConfig.GetString("AdminID", UUID.Zero.ToString()), out AdminAgentID);

            if (m_connector.Handler != Name)
            {
                MainConsole.Instance.Warn("[WebAPI]: module not loaded");
                return;
            }
            MainConsole.Instance.Info("[WebAPI]: module loaded");

            m_registry = registry;

            IConfig GridInfoConfig = config.Configs["GridInfoService"];
            if (GridInfoConfig != null)
            {
                m_servernick = GridInfoConfig.GetString("gridnick", m_servernick);
            }

            m_GridInfo = new OSDMap();
            if (GridInfoConfig != null && (GridInfoConfig.GetString("gridname", "") != "" && GridInfoConfig.GetString("gridnick", "") != ""))
            {
                foreach (string k in GridInfoConfig.GetKeys())
                {
                    m_GridInfo[k] = GridInfoConfig.GetString(k);
                }
            }

            m_APIAuthentication = webapiConfig.GetString("SupportedAuthentication", "Digest");
            m_EnableCORS = webapiConfig.GetBoolean("CORS", false);
            m_AccessControlAllowOrigin = (new List<string>(webapiConfig.GetString("AccessControlAllowOrigin", "*").Split(' '))).ConvertAll<string>(x=>x.Trim());

            ISimulationBase simBase = registry.RequestModuleInterface<ISimulationBase>();

            m_server = simBase.GetHttpServer(webapiConfig.GetUInt("Port", m_connector.HandlerPort));
            foreach (WebAPIHttpMethod method in Enum.GetValues(typeof(WebAPIHttpMethod)))
            {
                m_server.AddStreamHandler(new WebAPI_StreamHandler(this, method)); // This handler is for WebAPI methods that only read data
            }

            m_server2 = simBase.GetHttpServer(webapiConfig.GetUInt("TextureServerPort", m_connector.TexturePort));
            m_server2.AddHTTPHandler("GridTexture", OnHTTPGetTextureImage);

            m_GridInfo[Name + "TextureServer"] = m_server2.ServerURI;

            m_authNonces = new ExpiringCache<string, string>();

            #region Users

            MainConsole.Instance.Commands.AddCommand("webapi user promote", "Grants the specified user administrative powers within WebAPI.", "webapi user promote", PromoteUser);
            MainConsole.Instance.Commands.AddCommand("webapi user demote", "Revokes administrative powers for WebAPI from the specified user.", "webapi user demote", DemoteUser);

            #endregion

            #region News

            MainConsole.Instance.Commands.AddCommand("webapi news source add", "Sets a group as a news source so in-world group notices can be used as a publishing tool for the website.", "webapi news source add", AddGroupAsNewsSource);
            MainConsole.Instance.Commands.AddCommand("webapi news source remove", "Removes a group as a news source so it's notices will stop showing up on the news page.", "webapi news source remove", RemoveGroupAsNewsSource);

            #endregion

            #region Access Tokens

            MainConsole.Instance.Commands.AddCommand("webapi access token", "Gets the current access token to the API for the specified user", "webapi access token", GetAccessToken);
            MainConsole.Instance.Commands.AddCommand("webapi access token new", "Gets a new access token to the API for the specified user", "webapi access token new", GetNewAccessToken);

            #endregion

            #region ACL

            MainConsole.Instance.Commands.AddCommand("webapi access grant", "Grants access to a specified method for a specified user.", "webapi access grant [method]", GrantAPIAccess);
            MainConsole.Instance.Commands.AddCommand("webapi access revoke", "Revokes access for a specified user.", "webapi access revoke", RevokeAPIAccess);
            MainConsole.Instance.Commands.AddCommand("webapi access reset", "Resets access to defaults for a specified method for a specified user.", "webapi access reset", ResetAPIAccess);
            MainConsole.Instance.Commands.AddCommand("webapi access display", "Displays information about the API usage for the specified user.", "webapi access display", DisplayAPIAccessInfo);

            MainConsole.Instance.Commands.AddCommand("webapi access threat get", "Gets maximum threat level for API access for the specified user.", "webapi access threat get", GetMaxThreatLevel);
            MainConsole.Instance.Commands.AddCommand("webapi access threat set", "Sets maximum threat level for API access for the specified user.", "webapi access threat set", SetMaxThreatLevel);

            #endregion

            #region Log

            MainConsole.Instance.Commands.AddCommand("webapi log clear", "Clears the API access log", "webapi log clear [staleonly]", ClearLog);
            MainConsole.Instance.Commands.AddCommand("webapi log usage", "Get the current usage rate for the specified user on the specified method.", "webapi log usage", GetUsageRate);

            #endregion

            MainConsole.Instance.Commands.AddCommand("webapi list methods", "List API methods", "webapi list methods", ListAPImethods);
        }
        public bool Cross(ScenePresence agent, bool isFlying)
        {
            Scene scene = agent.Scene;
            Vector3 pos = agent.AbsolutePosition;
            Vector3 newpos = new Vector3(pos.X, pos.Y, pos.Z);
            uint neighbourx = scene.RegionInfo.RegionLocX;
            uint neighboury = scene.RegionInfo.RegionLocY;
            const float boundaryDistance = 1.7f;
            Vector3 northCross = new Vector3(0, boundaryDistance, 0);
            Vector3 southCross = new Vector3(0, -1 * boundaryDistance, 0);
            Vector3 eastCross = new Vector3(boundaryDistance, 0, 0);
            Vector3 westCross = new Vector3(-1 * boundaryDistance, 0, 0);

            // distance to edge that will trigger crossing


            // distance into new region to place avatar
            const float enterDistance = 0.5f;

            if (scene.TestBorderCross(pos + westCross, Cardinals.W))
            {
                if (scene.TestBorderCross(pos + northCross, Cardinals.N))
                {
                    Border b = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
                    neighboury += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
                }
                else if (scene.TestBorderCross(pos + southCross, Cardinals.S))
                {
                    Border b = scene.GetCrossedBorder(pos + southCross, Cardinals.S);
                    if (b.TriggerRegionX == 0 && b.TriggerRegionY == 0)
                    {
                        neighboury--;
                        newpos.Y = Constants.RegionSize - enterDistance;
                    }
                    else
                    {
                        agent.IsInTransit = true;

                        neighboury = b.TriggerRegionY;
                        neighbourx = b.TriggerRegionX;

                        Vector3 newposition = pos;
                        newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
                        newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
                        agent.ControllingClient.SendAgentAlertMessage(
                            String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
                        InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
                        return true;
                    }
                }

                Border ba = scene.GetCrossedBorder(pos + westCross, Cardinals.W);
                if (ba.TriggerRegionX == 0 && ba.TriggerRegionY == 0)
                {
                    neighbourx--;
                    newpos.X = Constants.RegionSize - enterDistance;
                }
                else
                {
                    agent.IsInTransit = true;

                    neighboury = ba.TriggerRegionY;
                    neighbourx = ba.TriggerRegionX;


                    Vector3 newposition = pos;
                    newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
                    newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
                    agent.ControllingClient.SendAgentAlertMessage(
                            String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
                    InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);


                    return true;
                }

            }
            else if (scene.TestBorderCross(pos + eastCross, Cardinals.E))
            {
                Border b = scene.GetCrossedBorder(pos + eastCross, Cardinals.E);
                neighbourx += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
                newpos.X = enterDistance;

                if (scene.TestBorderCross(pos + southCross, Cardinals.S))
                {
                    Border ba = scene.GetCrossedBorder(pos + southCross, Cardinals.S);
                    if (ba.TriggerRegionX == 0 && ba.TriggerRegionY == 0)
                    {
                        neighboury--;
                        newpos.Y = Constants.RegionSize - enterDistance;
                    }
                    else
                    {
                        agent.IsInTransit = true;

                        neighboury = ba.TriggerRegionY;
                        neighbourx = ba.TriggerRegionX;
                        Vector3 newposition = pos;
                        newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
                        newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
                        agent.ControllingClient.SendAgentAlertMessage(
                            String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
                        InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
                        return true;
                    }
                }
                else if (scene.TestBorderCross(pos + northCross, Cardinals.N))
                {
                    Border c = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
                    neighboury += (uint)(int)(c.BorderLine.Z / (int)Constants.RegionSize);
                    newpos.Y = enterDistance;
                }


            }
            else if (scene.TestBorderCross(pos + southCross, Cardinals.S))
            {
                Border b = scene.GetCrossedBorder(pos + southCross, Cardinals.S);
                if (b.TriggerRegionX == 0 && b.TriggerRegionY == 0)
                {
                    neighboury--;
                    newpos.Y = Constants.RegionSize - enterDistance;
                }
                else
                {
                    agent.IsInTransit = true;

                    neighboury = b.TriggerRegionY;
                    neighbourx = b.TriggerRegionX;
                    Vector3 newposition = pos;
                    newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
                    newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
                    agent.ControllingClient.SendAgentAlertMessage(
                            String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
                    InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
                    return true;
                }
            }
            else if (scene.TestBorderCross(pos + northCross, Cardinals.N))
            {

                Border b = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
                neighboury += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
                newpos.Y = enterDistance;
            }

            /*

            if (pos.X < boundaryDistance) //West
            {
                neighbourx--;
                newpos.X = Constants.RegionSize - enterDistance;
            }
            else if (pos.X > Constants.RegionSize - boundaryDistance) // East
            {
                neighbourx++;
                newpos.X = enterDistance;
            }

            if (pos.Y < boundaryDistance) // South
            {
                neighboury--;
                newpos.Y = Constants.RegionSize - enterDistance;
            }
            else if (pos.Y > Constants.RegionSize - boundaryDistance) // North
            {
                neighboury++;
                newpos.Y = enterDistance;
            }
            */

            ulong neighbourHandle = Utils.UIntsToLong((uint)(neighbourx * Constants.RegionSize), (uint)(neighboury * Constants.RegionSize));

            int x = (int)(neighbourx * Constants.RegionSize), y = (int)(neighboury * Constants.RegionSize);

            ExpiringCache<ulong, DateTime> r;
            DateTime banUntil;

            if (m_bannedRegions.TryGetValue(agent.ControllingClient.AgentId, out r))
            {
                if (r.TryGetValue(neighbourHandle, out banUntil))
                {
                    if (DateTime.Now < banUntil)
                        return false;
                    r.Remove(neighbourHandle);
                }
            }
            else
            {
                r = null;
            }

            GridRegion neighbourRegion = scene.GridService.GetRegionByPosition(scene.RegionInfo.ScopeID, (int)x, (int)y);

            string reason;
            string version;
            if (!scene.SimulationService.QueryAccess(neighbourRegion, agent.ControllingClient.AgentId, newpos, out version, out reason))
            {
                agent.ControllingClient.SendAlertMessage("Cannot region cross into banned parcel");
                if (r == null)
                {
                    r = new ExpiringCache<ulong, DateTime>();
                    r.Add(neighbourHandle, DateTime.Now + TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));

                    m_bannedRegions.Add(agent.ControllingClient.AgentId, r, TimeSpan.FromSeconds(45));
                }
                else
                {
                    r.Add(neighbourHandle, DateTime.Now + TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));
                }
                return false;
            }

            agent.IsInTransit = true;

            CrossAgentToNewRegionDelegate d = CrossAgentToNewRegionAsync;
            d.BeginInvoke(agent, newpos, neighbourx, neighboury, neighbourRegion, isFlying, version, CrossAgentToNewRegionCompleted, d);

            return true;
        }
Beispiel #37
0
        public void Start(IConfigSource config, IRegistryCore registry)
        {
            m_connector = DataManager.DataManager.RequestPlugin<WebAPIConnector>();
            if (m_connector == null || m_connector.Enabled == false || m_connector.Handler != Name)
            {
                return;
            }

            IConfig handlerConfig = config.Configs["Handlers"];
            UUID.TryParse(handlerConfig.GetString("WebAPIAdminID", UUID.Zero.ToString()), out AdminAgentID);

            if (m_connector.Handler != Name)
            {
                MainConsole.Instance.Warn("[WebAPI]: module not loaded");
                return;
            }
            MainConsole.Instance.Info("[WebAPI]: module loaded");

            m_registry = registry;

            IConfig GridInfoConfig = config.Configs["GridInfoService"];
            if (GridInfoConfig != null)
            {
                m_servernick = GridInfoConfig.GetString("gridnick", m_servernick);
            }

            m_GridInfo = new OSDMap();
            if (GridInfoConfig != null && (GridInfoConfig.GetString("gridname", "") != "" && GridInfoConfig.GetString("gridnick", "") != ""))
            {
                foreach (string k in GridInfoConfig.GetKeys())
                {
                    m_GridInfo[k] = GridInfoConfig.GetString(k);
                }
            }

            ISimulationBase simBase = registry.RequestModuleInterface<ISimulationBase>();

            m_server = simBase.GetHttpServer(handlerConfig.GetUInt(Name + "Port", m_connector.HandlerPort));
            foreach (WebAPIHttpMethod method in Enum.GetValues(typeof(WebAPIHttpMethod)))
            {
                m_server.AddStreamHandler(new WebAPI_StreamHandler(this, method)); // This handler is for WebAPI methods that only read data
            }

            m_server2 = simBase.GetHttpServer(handlerConfig.GetUInt(Name + "TextureServerPort", m_connector.TexturePort));
            m_server2.AddHTTPHandler("GridTexture", OnHTTPGetTextureImage);

            m_GridInfo[Name + "TextureServer"] = m_server2.ServerURI;

            m_authNonces = new ExpiringCache<string, string>();

            MainConsole.Instance.Commands.AddCommand("webapi promote user", "Grants the specified user administrative powers within WebAPI.", "webapi promote user", PromoteUser);
            MainConsole.Instance.Commands.AddCommand("webapi demote user", "Revokes administrative powers for WebAPI from the specified user.", "webapi demote user", DemoteUser);
            MainConsole.Instance.Commands.AddCommand("webapi add group as news source", "Sets a group as a news source so in-world group notices can be used as a publishing tool for the website.", "webapi add group as news source", AddGroupAsNewsSource);
            MainConsole.Instance.Commands.AddCommand("webapi remove group as news source", "Removes a group as a news source so it's notices will stop showing up on the news page.", "webapi remove group as news source", RemoveGroupAsNewsSource);
            MainConsole.Instance.Commands.AddCommand("webapi list methods", "List API methods", "webapi list methods", ListAPImethods);
            MainConsole.Instance.Commands.AddCommand("webapi get access token", "Gets the current access token to the API for the specified user", "webapi get access token", GetAccessToken);
            MainConsole.Instance.Commands.AddCommand("webapi get new access token", "Gets a new access token to the API for the specified user", "webapi get new access token", GetNewAccessToken);
            MainConsole.Instance.Commands.AddCommand("webapi clear log", "Clears the API access log", "webapi clear log [staleonly]", ClearLog);
            MainConsole.Instance.Commands.AddCommand("webapi get usage rate", "Get the current usage rate for the specified user on the specified method.", "webapi get usage rate", GetUsageRate);
            MainConsole.Instance.Commands.AddCommand("webapi grant access", "Grants access to a specified method for a specified user.", "webapi grant access [method]", GrantAPIAccess);
            MainConsole.Instance.Commands.AddCommand("webapi revoke access", "Revokes access for a specified user.", "webapi revoke access", RevokeAPIAccess);
            MainConsole.Instance.Commands.AddCommand("webapi reset access", "Resets access to defaults for a specified method for a specified user.", "webapi reset access", ResetAPIAccess);
        }
        public void Initialise(IConfigSource config)
        {
            IConfig groupsConfig = config.Configs["Groups"];

            if (groupsConfig == null)
            {
                // Do not run this module by default.
                return;
            }
            else
            {
                // if groups aren't enabled, we're not needed.
                // if we're not specified as the connector to use, then we're not wanted
                if ((groupsConfig.GetBoolean("Enabled", false) == false)
                    || (groupsConfig.GetString("ServicesConnectorModule", "Default") != Name))
                {
                    m_connectorEnabled = false;
                    return;
                }

                m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR]: Initializing {0}", this.Name);

                m_groupsServerURI = groupsConfig.GetString("GroupsServerURI", string.Empty);
                if ((m_groupsServerURI == null) ||
                    (m_groupsServerURI == string.Empty))
                {
                    m_log.ErrorFormat("Please specify a valid Simian Server for GroupsServerURI in Aurora.ini, [Groups]");
                    m_connectorEnabled = false;
                    return;
                }


                m_cacheTimeout = groupsConfig.GetInt("GroupsCacheTimeout", 30);
                if (m_cacheTimeout == 0)
                {
                    m_log.WarnFormat("[SIMIAN-GROUPS-CONNECTOR] Groups Cache Disabled.");
                }
                else
                {
                    m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] Groups Cache Timeout set to {0}.", m_cacheTimeout);
                }

                

                m_memoryCache = new ExpiringCache<string,OSDMap>();
                

                // If we got all the config options we need, lets start'er'up
                m_connectorEnabled = true;

                m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", true);

            }
        }
        public void Initialise(IConfigSource config)
        {
            IConfig groupsConfig = config.Configs["Groups"];

            if (groupsConfig == null)
            {
                // Do not run this module by default.
                return;
            }
            else
            {
                // if groups aren't enabled, we're not needed.
                // if we're not specified as the connector to use, then we're not wanted
                if ((groupsConfig.GetBoolean("Enabled", false) == false)
                    || (groupsConfig.GetString("ServicesConnectorModule", "XmlRpcGroupsServicesConnector") != Name))
                {
                    m_connectorEnabled = false;
                    return;
                }

                m_log.DebugFormat("[XMLRPC-GROUPS-CONNECTOR]: Initializing {0}", this.Name);

                m_groupsServerURI = groupsConfig.GetString("GroupsServerURI", string.Empty);
                if (string.IsNullOrEmpty(m_groupsServerURI))
                {
                    m_log.ErrorFormat("Please specify a valid URL for GroupsServerURI in OpenSim.ini, [Groups]");
                    m_connectorEnabled = false;
                    return;
                }

                m_disableKeepAlive = groupsConfig.GetBoolean("XmlRpcDisableKeepAlive", true);

                m_groupReadKey = groupsConfig.GetString("XmlRpcServiceReadKey", string.Empty);
                m_groupWriteKey = groupsConfig.GetString("XmlRpcServiceWriteKey", string.Empty);

                m_cacheTimeout = groupsConfig.GetInt("GroupsCacheTimeout", 30);

                if (m_cacheTimeout == 0)
                {
                    m_log.WarnFormat("[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Disabled.");
                }
                else
                {
                    m_log.InfoFormat("[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Timeout set to {0}.", m_cacheTimeout);
                }

                m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", false);

                // If we got all the config options we need, lets start'er'up
                m_memoryCache = new ExpiringCache<string, XmlRpcResponse>();
                m_connectorEnabled = true;
            }
        }
 public void AddOrUpdate(string path, string language, string languagePath)
 {
     ExpiringCache<string, string> map;
     if (!m_Cache.TryGetValue(path, out map))
         map = new ExpiringCache<string, string>();
     map.AddOrUpdate(language, languagePath, m_CachingTime);
     m_Cache[path] = map;
 }
Beispiel #41
0
        public void Initialise(IConfigSource source)
        {
            IConfig moduleConfig = source.Configs["Modules"];

            if (moduleConfig != null)
            {
                string name = moduleConfig.GetString("AssetCaching", String.Empty);

                if (name == Name)
                {
                    m_MemoryCache = new ExpiringCache <string, AssetBase>();
                    m_Enabled     = true;

                    m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} enabled", this.Name);

                    IConfig assetConfig = source.Configs["AssetCache"];
                    if (assetConfig == null)
                    {
                        m_log.Warn("[FLOTSAM ASSET CACHE]: AssetCache missing from OpenSim.ini, using defaults.");
                        m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Directory", m_DefaultCacheDirectory);
                        return;
                    }

                    m_CacheDirectory = assetConfig.GetString("CacheDirectory", m_DefaultCacheDirectory);
                    m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Directory", m_DefaultCacheDirectory);

                    m_MemoryCacheEnabled = assetConfig.GetBoolean("MemoryCacheEnabled", false);
                    m_MemoryExpiration   = TimeSpan.FromHours(assetConfig.GetDouble("MemoryCacheTimeout", m_DefaultMemoryExpiration));

#if WAIT_ON_INPROGRESS_REQUESTS
                    m_WaitOnInprogressTimeout = assetConfig.GetInt("WaitOnInprogressTimeout", 3000);
#endif

                    m_LogLevel       = assetConfig.GetInt("LogLevel", 0);
                    m_HitRateDisplay = (ulong)assetConfig.GetInt("HitRateDisplay", 1000);

                    m_FileExpiration             = TimeSpan.FromHours(assetConfig.GetDouble("FileCacheTimeout", m_DefaultFileExpiration));
                    m_FileExpirationCleanupTimer = TimeSpan.FromHours(assetConfig.GetDouble("FileCleanupTimer", m_DefaultFileExpiration));
                    if ((m_FileExpiration > TimeSpan.Zero) && (m_FileExpirationCleanupTimer > TimeSpan.Zero))
                    {
                        m_CacheCleanTimer           = new System.Timers.Timer(m_FileExpirationCleanupTimer.TotalMilliseconds);
                        m_CacheCleanTimer.AutoReset = true;
                        m_CacheCleanTimer.Elapsed  += CleanupExpiredFiles;
                        lock (m_CacheCleanTimer)
                            m_CacheCleanTimer.Start();
                    }

                    m_CacheDirectoryTiers = assetConfig.GetInt("CacheDirectoryTiers", 1);
                    if (m_CacheDirectoryTiers < 1)
                    {
                        m_CacheDirectoryTiers = 1;
                    }
                    else if (m_CacheDirectoryTiers > 3)
                    {
                        m_CacheDirectoryTiers = 3;
                    }

                    m_CacheDirectoryTierLen = assetConfig.GetInt("CacheDirectoryTierLength", 3);
                    if (m_CacheDirectoryTierLen < 1)
                    {
                        m_CacheDirectoryTierLen = 1;
                    }
                    else if (m_CacheDirectoryTierLen > 4)
                    {
                        m_CacheDirectoryTierLen = 4;
                    }

                    m_CacheWarnAt = assetConfig.GetInt("CacheWarnAt", 30000);

                    m_DeepScanBeforePurge = assetConfig.GetBoolean("DeepScanBeforePurge", false);

                    MainConsole.Instance.Commands.AddCommand(this.Name, true, "fcache status", "fcache status", "Display cache status", HandleConsoleCommand);
                    MainConsole.Instance.Commands.AddCommand(this.Name, true, "fcache clear", "fcache clear [file] [memory]", "Remove all assets in the file and/or memory cache", HandleConsoleCommand);
                    MainConsole.Instance.Commands.AddCommand(this.Name, true, "fcache assets", "fcache assets", "Attempt a deep scan and cache of all assets in all scenes", HandleConsoleCommand);
                    MainConsole.Instance.Commands.AddCommand(this.Name, true, "fcache expire", "fcache expire <datetime>", "Purge cached assets older then the specified date/time", HandleConsoleCommand);
                }
            }
        }
Beispiel #42
0
 public RegionInfoCache()
 {
     m_UUIDCache     = new ExpiringCache <ScopedRegionUUID, GridRegion>();
     m_NameCache     = new ExpiringCache <ScopedRegionName, ScopedRegionUUID>();
     m_PositionCache = new ExpiringCache <ScopedRegionPosition, GridRegion>();
 }
        public HGInstantMessageService(IConfigSource config, IInstantMessageSimConnector imConnector)
        {
            if (imConnector != null)
                m_IMSimConnector = imConnector;

            if (!m_Initialized)
            {
                m_Initialized = true;

                IConfig serverConfig = config.Configs["HGInstantMessageService"];
                if (serverConfig == null)
                    throw new Exception(String.Format("No section HGInstantMessageService in config file"));

                string gridService = serverConfig.GetString("GridService", String.Empty);
                string presenceService = serverConfig.GetString("PresenceService", String.Empty);
                string userAgentService = serverConfig.GetString("UserAgentService", String.Empty);
                m_InGatekeeper = serverConfig.GetBoolean("InGatekeeper", false);
                m_log.DebugFormat("[HG IM SERVICE]: Starting... InRobust? {0}", m_InGatekeeper);


                if (gridService == string.Empty || presenceService == string.Empty)
                    throw new Exception(String.Format("Incomplete specifications, InstantMessage Service cannot function."));

                Object[] args = new Object[] { config };
                m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
                m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args);
                m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(userAgentService, args);

                m_RegionCache = new ExpiringCache<UUID, GridRegion>();

                IConfig cnf = config.Configs["Messaging"];
                if (cnf == null)
                {
                    return;
                }

                m_RestURL = cnf.GetString("OfflineMessageURL", string.Empty);
                m_ForwardOfflineGroupMessages = cnf.GetBoolean("ForwardOfflineGroupMessages", false);

            }
        }
 public GenericAccountCache()
 {
     m_UUIDCache = new ExpiringCache <UUID, T>();
     m_NameCache = new ExpiringCache <string, UUID>();
 }
        public GridRegion GetDestination(Scene scene, UUID agentID, Vector3 pos, out uint xDest, out uint yDest, out string version, out Vector3 newpos)
        {
            version = String.Empty;
            newpos = new Vector3(pos.X, pos.Y, pos.Z);

//            m_log.DebugFormat(
//                "[ENTITY TRANSFER MODULE]: Crossing agent {0} at pos {1} in {2}", agent.Name, pos, scene.Name);

            uint neighbourx = scene.RegionInfo.RegionLocX;
            uint neighboury = scene.RegionInfo.RegionLocY;
            const float boundaryDistance = 1.7f;
            Vector3 northCross = new Vector3(0, boundaryDistance, 0);
            Vector3 southCross = new Vector3(0, -1 * boundaryDistance, 0);
            Vector3 eastCross = new Vector3(boundaryDistance, 0, 0);
            Vector3 westCross = new Vector3(-1 * boundaryDistance, 0, 0);

            // distance into new region to place avatar
            const float enterDistance = 0.5f;

            if (scene.TestBorderCross(pos + westCross, Cardinals.W))
            {
                if (scene.TestBorderCross(pos + northCross, Cardinals.N))
                {
                    Border b = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
                    neighboury += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
                }
                else if (scene.TestBorderCross(pos + southCross, Cardinals.S))
                {
                    neighboury--;
                    newpos.Y = Constants.RegionSize - enterDistance;
                }

                neighbourx--;
                newpos.X = Constants.RegionSize - enterDistance;
            }
            else if (scene.TestBorderCross(pos + eastCross, Cardinals.E))
            {
                Border b = scene.GetCrossedBorder(pos + eastCross, Cardinals.E);
                neighbourx += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
                newpos.X = enterDistance;

                if (scene.TestBorderCross(pos + southCross, Cardinals.S))
                {
                    neighboury--;
                    newpos.Y = Constants.RegionSize - enterDistance;
                }
                else if (scene.TestBorderCross(pos + northCross, Cardinals.N))
                {
                    Border c = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
                    neighboury += (uint)(int)(c.BorderLine.Z / (int)Constants.RegionSize);
                    newpos.Y = enterDistance;
                }
            }
            else if (scene.TestBorderCross(pos + southCross, Cardinals.S))
            {
                Border b = scene.GetCrossedBorder(pos + southCross, Cardinals.S);
                neighboury--;
                newpos.Y = Constants.RegionSize - enterDistance;
            }
            else if (scene.TestBorderCross(pos + northCross, Cardinals.N))
            {
                Border b = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
                neighboury += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
                newpos.Y = enterDistance;
            }

            /*

            if (pos.X < boundaryDistance) //West
            {
                neighbourx--;
                newpos.X = Constants.RegionSize - enterDistance;
            }
            else if (pos.X > Constants.RegionSize - boundaryDistance) // East
            {
                neighbourx++;
                newpos.X = enterDistance;
            }

            if (pos.Y < boundaryDistance) // South
            {
                neighboury--;
                newpos.Y = Constants.RegionSize - enterDistance;
            }
            else if (pos.Y > Constants.RegionSize - boundaryDistance) // North
            {
                neighboury++;
                newpos.Y = enterDistance;
            }
            */

            xDest = neighbourx;
            yDest = neighboury;

            int x = (int)(neighbourx * Constants.RegionSize), y = (int)(neighboury * Constants.RegionSize);

            ulong neighbourHandle = Utils.UIntsToLong((uint)x, (uint)y);

            ExpiringCache<ulong, DateTime> r;
            DateTime banUntil;

            if (m_bannedRegions.TryGetValue(agentID, out r))
            {
                if (r.TryGetValue(neighbourHandle, out banUntil))
                {
                    if (DateTime.Now < banUntil)
                        return null;
                    r.Remove(neighbourHandle);
                }
            }
            else
            {
                r = null;
            }

            GridRegion neighbourRegion = scene.GridService.GetRegionByPosition(scene.RegionInfo.ScopeID, (int)x, (int)y);

            string reason;
            if (!scene.SimulationService.QueryAccess(neighbourRegion, agentID, newpos, out version, out reason))
            {
                if (r == null)
                {
                    r = new ExpiringCache<ulong, DateTime>();
                    r.Add(neighbourHandle, DateTime.Now + TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));

                    m_bannedRegions.Add(agentID, r, TimeSpan.FromSeconds(45));
                }
                else
                {
                    r.Add(neighbourHandle, DateTime.Now + TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));
                }
                return null;
            }

            return neighbourRegion;
        }
 public UserAccountCache()
 {
     m_UUIDCache = new ExpiringCache<UUID, UserAccount>();
     m_NameCache = new ExpiringCache<string, UUID>(); 
 }
Beispiel #47
0
 private UserAccountCache(IUserAccountService u)
 {
     m_UUIDCache          = new ExpiringCache <UUID, UserAccount>();
     m_UserAccountService = u;
 }
Beispiel #48
0
        public void Equals_NewCachedItem_EqualsSelf()
        {
            var item = new ExpiringCache <int, int> .CachedValue(1, DateTime.Now);

            Expect(item, Is.EqualTo(item));
        }
        public void Initialise(IConfigSource source)
        {
            if (Simian.IsSimianEnabled(source, "UserAccountServices", this.Name))
            {
                IConfig assetConfig = source.Configs["UserAccountService"];
                if (assetConfig == null)
                {
                    m_log.Error("[SIMIAN ACCOUNT CONNECTOR]: UserAccountService missing from OpenSim.ini");
                    throw new Exception("User account connector init error");
                }

                string serviceURI = assetConfig.GetString("UserAccountServerURI");
                if (String.IsNullOrEmpty(serviceURI))
                {
                    m_log.Error("[SIMIAN ACCOUNT CONNECTOR]: No UserAccountServerURI in section UserAccountService, skipping SimianUserAccountServiceConnector");
                    throw new Exception("User account connector init error");
                }

                m_accountCache = new ExpiringCache<UUID, UserAccount>();
                m_serverUrl = serviceURI;
            }
        }
        public void Equals_NewCachedItem_EqualsSelf()
        {
            var item = new ExpiringCache<int, int>.CachedValue(1, DateTime.Now);

            Expect(item, Is.EqualTo(item));
        }