From ffbfc146899e00585eb8dad481323dae1511b484 Mon Sep 17 00:00:00 2001
From: Tom
Date: Fri, 28 Jan 2011 09:55:46 -0800
Subject: Make llRequestAgentData shout an error instead of crashing the script
 when an invalid UUID is passed to it.

---
 .../Shared/Api/Implementation/LSL_Api.cs           | 164 +++++++++++----------
 1 file changed, 86 insertions(+), 78 deletions(-)

(limited to 'OpenSim/Region/ScriptEngine/Shared')

diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index f5b7f5f..59e905e 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -4309,107 +4309,115 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
         {
             m_host.AddScriptLPS(1);
 
-            UUID uuid = (UUID)id;
-            PresenceInfo pinfo = null;
-            UserAccount account;
-
-            UserInfoCacheEntry ce;
-            if (!m_userInfoCache.TryGetValue(uuid, out ce))
+            UUID uuid;
+            if (UUID.TryParse(id, out uuid))
             {
-                account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
-                if (account == null)
+                PresenceInfo pinfo = null;
+                UserAccount account;
+
+                UserInfoCacheEntry ce;
+                if (!m_userInfoCache.TryGetValue(uuid, out ce))
                 {
-                    m_userInfoCache[uuid] = null; // Cache negative
-                    return UUID.Zero.ToString();
-                }
+                    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)
+                    PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
+                    if (pinfos != null && pinfos.Length > 0)
                     {
-                        if (p.RegionID != UUID.Zero)
+                        foreach (PresenceInfo p in pinfos)
                         {
-                            pinfo = p;
+                            if (p.RegionID != UUID.Zero)
+                            {
+                                pinfo = p;
+                            }
                         }
                     }
-                }
 
-                ce = new UserInfoCacheEntry();
-                ce.time = Util.EnvironmentTickCount();
-                ce.account = account;
-                ce.pinfo = pinfo;
-                m_userInfoCache[uuid] = ce;
-            }
-            else
-            {
-                if (ce == null)
-                    return UUID.Zero.ToString();
+                    ce = new UserInfoCacheEntry();
+                    ce.time = Util.EnvironmentTickCount();
+                    ce.account = account;
+                    ce.pinfo = pinfo;
+                    m_userInfoCache[uuid] = ce;
+                }
+                else
+                {
+                    if (ce == null)
+                        return UUID.Zero.ToString();
 
-                account = ce.account;
-                pinfo = ce.pinfo;
-            }
+                    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)
+                if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000)
                 {
-                    foreach (PresenceInfo p in pinfos)
+                    PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
+                    if (pinfos != null && pinfos.Length > 0)
                     {
-                        if (p.RegionID != UUID.Zero)
+                        foreach (PresenceInfo p in pinfos)
                         {
-                            pinfo = p;
+                            if (p.RegionID != UUID.Zero)
+                            {
+                                pinfo = p;
+                            }
                         }
                     }
-                }
-                else
-                    pinfo = null;
+                    else
+                        pinfo = null;
 
-                ce.time = Util.EnvironmentTickCount();
-                ce.pinfo = pinfo;
-            }
+                    ce.time = Util.EnvironmentTickCount();
+                    ce.pinfo = pinfo;
+                }
 
-            string reply = String.Empty;
+                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 8: // DATA_PAYINFO (0|1|2|3)
-                reply = "0";
-                break;
-            default:
-                return UUID.Zero.ToString(); // Raise no event
-            }
+                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 8: // DATA_PAYINFO (0|1|2|3)
+                        reply = "0";
+                        break;
+                    default:
+                        return UUID.Zero.ToString(); // Raise no event
+                }
 
-            UUID rq = UUID.Random();
+                UUID rq = UUID.Random();
 
-            UUID tid = AsyncCommands.
-                DataserverPlugin.RegisterRequest(m_localID,
-                                             m_itemID, rq.ToString());
+                UUID tid = AsyncCommands.
+                    DataserverPlugin.RegisterRequest(m_localID,
+                                                 m_itemID, rq.ToString());
 
-            AsyncCommands.
-            DataserverPlugin.DataserverReply(rq.ToString(), reply);
+                AsyncCommands.
+                DataserverPlugin.DataserverReply(rq.ToString(), reply);
 
-            ScriptSleep(100);
-            return tid.ToString();
+                ScriptSleep(100);
+                return tid.ToString();
+            }
+            else
+            {
+                ShoutError("Invalid UUID passed to llRequestAgentData.");
+            }
+            return "";
         }
 
         public LSL_String llRequestInventoryData(string name)
-- 
cgit v1.1