public LSL_String llRequestAgentData(string id, int data) { m_host.AddScriptLPS(1); UUID uuid = (UUID)id; PresenceInfo pinfo = null; UserAccount account; UserInfoCacheEntry ce; if (!m_userInfoCache.TryGetValue(uuid, out ce)) { account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); if (account == null) { m_userInfoCache[uuid] = null; // Cache negative return UUID.Zero.ToString(); } PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); if (pinfos != null && pinfos.Length > 0) { foreach (PresenceInfo p in pinfos) { if (p.RegionID != UUID.Zero) { pinfo = p; } } } ce = new UserInfoCacheEntry(); ce.time = Util.EnvironmentTickCount(); ce.account = account; ce.pinfo = pinfo; } else { if (ce == null) return UUID.Zero.ToString(); account = ce.account; pinfo = ce.pinfo; } if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000) { PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); if (pinfos != null && pinfos.Length > 0) { foreach (PresenceInfo p in pinfos) { if (p.RegionID != UUID.Zero) { pinfo = p; } } } else pinfo = null; ce.time = Util.EnvironmentTickCount(); ce.pinfo = pinfo; } string reply = String.Empty; switch (data) { case 1: // DATA_ONLINE (0|1) if (pinfo != null && pinfo.RegionID != UUID.Zero) reply = "1"; else reply = "0"; break; case 2: // DATA_NAME (First Last) reply = account.FirstName + " " + account.LastName; break; case 3: // DATA_BORN (YYYY-MM-DD) DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0); born = born.AddSeconds(account.Created); reply = born.ToString("yyyy-MM-dd"); break; case 4: // DATA_RATING (0,0,0,0,0,0) reply = "0,0,0,0,0,0"; break; case 7: // DATA_USERLEVEL (integer) reply = account.UserLevel.ToString(); break; case 8: // DATA_PAYINFO (0|1|2|3) reply = "0"; break; default: return UUID.Zero.ToString(); // Raise no event } UUID rq = UUID.Random(); UUID tid = AsyncCommands. DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString()); AsyncCommands. DataserverPlugin.DataserverReply(rq.ToString(), reply); ScriptSleep(100); return tid.ToString(); }
public LSL_String llRequestAgentData(string id, int data) { m_host.AddScriptLPS(1); UUID uuid = (UUID)id; UserInfoCacheEntry ce = null; PresenceInfo pinfo = null; UserAccount account; try { ce = m_userInfoCache.GetOrAddIfNotExists(uuid, delegate() { account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); if (account == null) { return null; // Cache negative } PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); if (pinfos != null && pinfos.Length > 0) { foreach (PresenceInfo p in pinfos) { if (p.RegionID != UUID.Zero) { pinfo = p; } } } ce = new UserInfoCacheEntry(); ce.time = Environment.TickCount; ce.account = account; ce.pinfo = pinfo; return ce; }); } catch { ce = null; } if (ce == null) return UUID.Zero.ToString(); account = ce.account; if ((Environment.TickCount - ce.time) >= LlRequestAgentDataCacheTimeoutMs) { PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); if (pinfos != null && pinfos.Length > 0) { foreach (PresenceInfo p in pinfos) { if (p.RegionID != UUID.Zero) { pinfo = p; } } } else { pinfo = null; } ce.time = Environment.TickCount; ce.pinfo = pinfo; } else { pinfo = ce.pinfo; } string reply = String.Empty; switch (data) { case ScriptBaseClass.DATA_ONLINE: if (pinfo != null && pinfo.RegionID != UUID.Zero) reply = "1"; else reply = "0"; break; case ScriptBaseClass.DATA_NAME: // (First Last) reply = account.FirstName + " " + account.LastName; break; case ScriptBaseClass.DATA_BORN: // (YYYY-MM-DD) DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0); born = born.AddSeconds(account.Created); reply = born.ToString("yyyy-MM-dd"); break; case ScriptBaseClass.DATA_RATING: // (0,0,0,0,0,0) reply = "0,0,0,0,0,0"; break; case 7: // DATA_USERLEVEL (integer). This is not available in LL and so has no constant. reply = account.UserLevel.ToString(); break; case ScriptBaseClass.DATA_PAYINFO: // (0|1|2|3) reply = "0"; break; default: return UUID.Zero.ToString(); // Raise no event } UUID rq = UUID.Random(); UUID tid = AsyncCommands. DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString()); AsyncCommands. DataserverPlugin.DataserverReply(rq.ToString(), reply); ScriptSleep(100); return tid.ToString(); }