private bool CheckNonExistence(NpcPresenceInfo pInfo)
        {
            NpcPresenceInfo result;

            m_Log.Info("Check that entry does not exist by userid 1");
            if (m_PresenceService.ContainsKey(pInfo.Npc.ID))
            {
                return(false);
            }

            m_Log.Info("Check that entry does not exist by userid 2");
            if (m_PresenceService.TryGetValue(pInfo.Npc.ID, out result))
            {
                return(false);
            }

            m_Log.Info("Check that entry does not exist by regionid");
            if (m_PresenceService[pInfo.RegionID].Count != 0)
            {
                return(false);
            }

            m_Log.Info("Check that entry does not exist by firstname and lastname");
            if (m_PresenceService.TryGetValue(pInfo.RegionID, pInfo.Npc.FirstName, pInfo.Npc.LastName, out result))
            {
                return(false);
            }

            return(true);
        }
        public override void Store(NpcPresenceInfo presenceInfo)
        {
            var post = new Dictionary <string, object>
            {
                ["NpcID"]             = presenceInfo.Npc.ID,
                ["FirstName"]         = presenceInfo.Npc.FirstName,
                ["LastName"]          = presenceInfo.Npc.LastName,
                ["Owner"]             = presenceInfo.Owner,
                ["Group"]             = presenceInfo.Group,
                ["Options"]           = presenceInfo.Options,
                ["RegionID"]          = presenceInfo.RegionID,
                ["Position"]          = presenceInfo.Position,
                ["LookAt"]            = presenceInfo.LookAt,
                ["SittingOnObjectID"] = presenceInfo.SittingOnObjectID
            };

            using (var conn = new MySqlConnection(m_ConnectionString))
            {
                conn.Open();
                try
                {
                    conn.ReplaceInto("npcpresence", post);
                }
                catch
                {
                    throw new PresenceUpdateFailedException();
                }
            }
        }
        private bool CheckExistence(NpcPresenceInfo pInfo)
        {
            NpcPresenceInfo        result;
            List <NpcPresenceInfo> reslist;

            m_Log.Info("Check that entry exists by npcid 1");
            if (!m_PresenceService.ContainsKey(pInfo.Npc.ID))
            {
                return(false);
            }

            m_Log.Info("Check that entry exists by npcid 2");
            if (!m_PresenceService.TryGetValue(pInfo.Npc.ID, out result))
            {
                return(false);
            }

            m_Log.Info("Verify equality");
            if (!IsEqual(result, pInfo))
            {
                return(false);
            }

            m_Log.Info("Check that entry exists by regionid");
            reslist = m_PresenceService[pInfo.RegionID];
            if (reslist.Count != 1)
            {
                return(false);
            }

            m_Log.Info("Verify equality");
            if (!IsEqual(reslist[0], pInfo))
            {
                return(false);
            }

            m_Log.Info("Check that entry exists by firstname and lastname");
            if (!m_PresenceService.TryGetValue(pInfo.RegionID, pInfo.Npc.FirstName, pInfo.Npc.LastName, out result))
            {
                return(false);
            }

            m_Log.Info("Verify equality");
            if (!IsEqual(result, pInfo))
            {
                return(false);
            }

            m_Log.Info("Check that entry does not exist by firstname and lastname and other regionid");
            if (m_PresenceService.TryGetValue(UUID.RandomFixedFirst(0xFFFFFFFF), pInfo.Npc.FirstName, pInfo.Npc.LastName, out result))
            {
                return(false);
            }

            return(true);
        }
        private bool IsEqual(NpcPresenceInfo p1, NpcPresenceInfo p2)
        {
            var mismatches = new List <string>();

            if (p1.Npc.ID != p2.Npc.ID || p1.Npc.FirstName != p2.Npc.FirstName || p1.Npc.LastName != p2.Npc.LastName)
            {
                mismatches.Add("Npc");
            }

            bool ownerUriEqual = p1.Owner.HomeURI?.ToString() == p2.Owner.HomeURI?.ToString();

            if (p1.Owner.ID != p2.Owner.ID || !ownerUriEqual)
            {
                mismatches.Add("Owner");
            }

            if (p1.Group.ID != p2.Group.ID || p1.Group.GroupName != p2.Group.GroupName || p1.Group.HomeURI.ToString() != p2.Group.HomeURI.ToString())
            {
                mismatches.Add("Group");
            }

            if (p1.Options != p2.Options)
            {
                mismatches.Add("Options");
            }

            if (p1.RegionID != p2.RegionID)
            {
                mismatches.Add("RegionID");
            }

            if (!p1.Position.ApproxEquals(p2.Position, double.Epsilon))
            {
                mismatches.Add("Position");
            }

            if (!p1.LookAt.ApproxEquals(p2.LookAt, double.Epsilon))
            {
                mismatches.Add("LookAt");
            }

            if (p1.SittingOnObjectID != p2.SittingOnObjectID)
            {
                mismatches.Add("SittingOnObjectID");
            }

            if (mismatches.Count != 0)
            {
                m_Log.InfoFormat("Mismatches: {0}", string.Join(" ", mismatches));
            }

            return(mismatches.Count == 0);
        }
예제 #5
0
        private void OnSceneRemoved(SceneInterface scene)
        {
            scene.LoginControl.OnLoginsEnabled -= LoginControl_OnLoginsEnabled;
            m_KnownScenes.Remove(scene.ID);
            var removeList = new Dictionary <UUID, NpcAgent>();

            foreach (NpcAgent agent in m_NpcAgents.Values)
            {
                if (agent.CurrentScene == scene)
                {
                    try
                    {
                        agent.DetachAllAttachments();
                    }
                    catch
                    {
                        m_Log.WarnFormat("Failed to detach attachments of NPC {0} {1} ({2})", agent.NamedOwner.FirstName, agent.NamedOwner.LastName, agent.NamedOwner.ID);
                    }
                    removeList.Add(agent.ID, agent);
                }
            }

            foreach (KeyValuePair <UUID, NpcAgent> kvp in removeList)
            {
                /* we have to call the next two removes explicitly. We only want to act upon non-persisted data */
                m_NonpersistentInventoryService.Remove(kvp.Key);
                m_NonpersistentProfileService?.Remove(kvp.Key);
                NpcAgent npc          = kvp.Value;
                IObject  obj          = npc.SittingOnObject;
                var      presenceInfo = new NpcPresenceInfo
                {
                    Npc               = npc.NamedOwner,
                    Owner             = npc.NpcOwner,
                    Position          = npc.Position,
                    LookAt            = npc.LookAt,
                    Group             = npc.Group,
                    RegionID          = npc.SceneID,
                    SittingOnObjectID = obj != null ? obj.ID : UUID.Zero
                };
                kvp.Value.DisableListen();

                if (m_NpcAgents.Remove(kvp.Key))
                {
                    /* we do not distinguish persistent/non-persistent here since NpcAgent has a property for referencing it */
                    npc.NpcPresenceService.Store(presenceInfo);
                }
            }
        }
        public bool Run()
        {
            var pInfo = new NpcPresenceInfo
            {
                Npc               = new UGUIWithName(UUID.Random, "Npc", "Test"),
                Owner             = new UGUIWithName(UUID.Random, "Test", "User", new Uri("http://example.com/")),
                Group             = new UGI(UUID.Random, "NpcGroup", new Uri("http://example.com/")),
                RegionID          = UUID.Random,
                Position          = new Vector3(128, 128, 23),
                LookAt            = new Vector3(1, -1, 0.5),
                SittingOnObjectID = UUID.Random
            };

            m_Log.Info("---- Check precondition ----");
            if (!CheckNonExistence(pInfo))
            {
                return(false);
            }

            m_Log.Info("---- Presence Login ----");
            m_PresenceService.Store(pInfo);

            m_Log.Info("---- Verify existence ----");
            if (!CheckExistence(pInfo))
            {
                return(false);
            }

            UUID newRegionID = UUID.Random;

            /* ensure that we get a different id */
            while (newRegionID == pInfo.RegionID)
            {
                newRegionID = UUID.Random;
            }

            m_Log.Info("---- Verify entry to be removed ----");
            m_PresenceService.Remove(pInfo.Npc.ID);
            if (!CheckNonExistence(pInfo))
            {
                return(false);
            }

            return(true);
        }
 public override bool TryGetValue(UUID npcid, out NpcPresenceInfo presence)
 {
     presence = default(NpcPresenceInfo);
     using (var conn = new MySqlConnection(m_ConnectionString))
     {
         conn.Open();
         using (var cmd = new MySqlCommand("SELECT * FROM npcpresence WHERE NpcID = @npcid LIMIT 1", conn))
         {
             cmd.Parameters.AddParameter("@npcid", npcid);
             using (MySqlDataReader reader = cmd.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     presence = ReaderToPresenceInfo(reader);
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
예제 #8
0
        public override void Store(NpcPresenceInfo presenceInfo)
        {
            var post = new Dictionary <string, object>
            {
                ["NpcID"]             = presenceInfo.Npc.ID,
                ["FirstName"]         = presenceInfo.Npc.FirstName,
                ["LastName"]          = presenceInfo.Npc.LastName,
                ["Owner"]             = presenceInfo.Owner,
                ["Group"]             = presenceInfo.Group,
                ["Options"]           = presenceInfo.Options,
                ["RegionID"]          = presenceInfo.RegionID,
                ["Position"]          = presenceInfo.Position,
                ["LookAt"]            = presenceInfo.LookAt,
                ["SittingOnObjectID"] = presenceInfo.SittingOnObjectID
            };

            using (var conn = new NpgsqlConnection(m_ConnectionString))
            {
                conn.Open();
                conn.ReplaceInto("npcpresence", post, new string[] { "NpcID" }, m_EnableOnConflict);
            }
        }
예제 #9
0
 public override void Store(NpcPresenceInfo presenceInfo)
 {
     /* nothing to do */
 }
예제 #10
0
 public override bool TryGetValue(UUID regionID, string firstname, string lastname, out NpcPresenceInfo info)
 {
     info = default(NpcPresenceInfo);
     return(false);
 }
예제 #11
0
 public override bool TryGetValue(UUID npcid, out NpcPresenceInfo presence)
 {
     presence = default(NpcPresenceInfo);
     return(false);
 }
예제 #12
0
        public NpcAgent CreateNpc(UUID sceneid, UGUI owner, UGI group, string firstName, string lastName, Vector3 position, Notecard nc, NpcOptions options = NpcOptions.None)
        {
            SceneInterface   scene;
            AgentServiceList agentServiceList = m_NonpersistentAgentServices;

            if ((options & NpcOptions.Persistent) != NpcOptions.None)
            {
                if (m_NpcPresenceService == null)
                {
                    throw new InvalidOperationException("Persistence of NPCs not configured");
                }
                agentServiceList = m_PersistentAgentServices;
            }

            NpcPresenceServiceInterface presenceService  = agentServiceList.Get <NpcPresenceServiceInterface>();
            InventoryServiceInterface   inventoryService = agentServiceList.Get <InventoryServiceInterface>();

            var npcId = new UGUIWithName
            {
                ID        = UUID.Random,
                FirstName = firstName,
                LastName  = lastName
            };

            if (m_KnownScenes.TryGetValue(sceneid, out scene))
            {
                var agent = new NpcAgent(npcId, agentServiceList, sceneid)
                {
                    NpcOwner = owner,
                    Group    = group
                };
                try
                {
                    m_NpcAgents.Add(agent.ID, agent);
                    var npcInfo = new NpcPresenceInfo
                    {
                        RegionID = sceneid,
                        Npc      = agent.NamedOwner,
                        Owner    = agent.NpcOwner,
                        Group    = agent.Group,
                    };
                    inventoryService.CheckInventory(npcInfo.Npc.ID);
                    presenceService.Store(npcInfo);
                    agent.CurrentScene = scene;
                    agent.Position     = position;
                    scene.Add(agent);
                }
                catch
                {
                    if (m_NpcPresenceService != null)
                    {
                        presenceService.Remove(agent.ID);
                    }
                    inventoryService.Remove(agent.ID);
                    m_NpcAgents.Remove(agent.ID);
                    throw;
                }
                agent.EnableListen();

                scene.SendAgentObjectToAllAgents(agent);
                agent.SendAnimations();

                ThreadPool.QueueUserWorkItem(LoadAppearanceFromNotecardJob, new RebakeJob {
                    Notecard = nc, Agent = agent
                });
                return(agent);
            }

            throw new KeyNotFoundException("Scene not found");
        }
 public override bool TryGetValue(UUID regionID, string firstname, string lastname, out NpcPresenceInfo presence)
 {
     presence = default(NpcPresenceInfo);
     using (var conn = new MySqlConnection(m_ConnectionString))
     {
         conn.Open();
         using (var cmd = new MySqlCommand("SELECT * FROM npcpresence WHERE RegionID = @regionID AND FirstName = @first AND LastName = @last LIMIT 1", conn))
         {
             cmd.Parameters.AddParameter("@regionID", regionID);
             cmd.Parameters.AddParameter("@first", firstname);
             cmd.Parameters.AddParameter("@last", lastname);
             using (MySqlDataReader reader = cmd.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     presence = ReaderToPresenceInfo(reader);
                     return(true);
                 }
             }
         }
     }
     return(false);
 }