private void TestAddRemoveNPCs(int numberOfNpcs) { ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); // 8 is the index of the first baked texture in AvatarAppearance UUID originalFace8TextureId = TestHelpers.ParseTail(0x10); Primitive.TextureEntry originalTe = new Primitive.TextureEntry(UUID.Zero); Primitive.TextureEntryFace originalTef = originalTe.CreateFace(8); originalTef.TextureID = originalFace8TextureId; // We also need to add the texture to the asset service, otherwise the AvatarFactoryModule will tell // ScenePresence.SendInitialData() to reset our entire appearance. scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId)); afm.SetAppearance(sp, originalTe, null, new WearableCacheItem[0]); INPCModule npcModule = scene.RequestModuleInterface <INPCModule>(); List <UUID> npcs = new List <UUID>(); long startGcMemory = GC.GetTotalMemory(true); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < numberOfNpcs; i++) { npcs.Add( npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, scene, sp.Appearance)); } for (int i = 0; i < numberOfNpcs; i++) { Assert.That(npcs[i], Is.Not.Null); ScenePresence npc = scene.GetScenePresence(npcs[i]); Assert.That(npc, Is.Not.Null); } for (int i = 0; i < numberOfNpcs; i++) { Assert.That(npcModule.DeleteNPC(npcs[i], scene), Is.True); ScenePresence npc = scene.GetScenePresence(npcs[i]); Assert.That(npc, Is.Null); } sw.Stop(); long endGcMemory = GC.GetTotalMemory(true); Console.WriteLine("Took {0} ms", sw.ElapsedMilliseconds); Console.WriteLine( "End {0} MB, Start {1} MB, Diff {2} MB", endGcMemory / 1024 / 1024, startGcMemory / 1024 / 1024, (endGcMemory - startGcMemory) / 1024 / 1024); }
public void GridKickUser(UUID agentID, string reason) { int godlevel = 240; // grid god default ScenePresence sp = m_scene.GetScenePresence(agentID); if (sp == null || sp.IsChildAgent) { IMessageTransferModule transferModule = m_scene.RequestModuleInterface <IMessageTransferModule>(); if (transferModule != null) { m_log.DebugFormat("[GODS]: Sending nonlocal kill for agent {0}", agentID); transferModule.SendInstantMessage(new GridInstantMessage( m_scene, Constants.servicesGodAgentID, "GRID", agentID, (byte)250, false, reason, UUID.Zero, true, new Vector3(), new byte[] { 0 }, true), delegate(bool success) { }); } return; } if (sp.IsDeleted) { return; } if (godlevel <= sp.GodController.GodLevel) // no god wars { if (m_dialogModule != null) { m_dialogModule.SendAlertToUser(sp.UUID, "GRID kick detected and ignored, kick reason: " + reason); } return; } if (sp.IsNPC) { INPCModule npcmodule = sp.Scene.RequestModuleInterface <INPCModule>(); if (npcmodule != null) { npcmodule.DeleteNPC(sp.UUID, sp.Scene); return; } } sp.ControllingClient.Kick(reason); sp.Scene.CloseAgent(sp.UUID, true); }
private void KickPresence(ScenePresence sp, string reason) { if (sp.IsDeleted || sp.IsChildAgent) { return; } if (sp.IsNPC) { INPCModule npcmodule = sp.Scene.RequestModuleInterface <INPCModule>(); if (npcmodule != null) { npcmodule.DeleteNPC(sp.UUID, sp.Scene); return; } } sp.ControllingClient.Kick(reason); sp.Scene.CloseAgent(sp.UUID, true); }
public void deleteAllNPC() { m_npcs = new List <NPCData>(); try { INPCModule module = m_scene.RequestModuleInterface <INPCModule>(); if (module != null) { m_scene.ForEachRootScenePresence( delegate(ScenePresence ssp) { if (ssp.IsNPC) { NPCData data = new NPCData(); data.FirstName = ssp.Firstname; data.LastName = ssp.Lastname; data.Position = ssp.AbsolutePosition; data.AgentID = ssp.UUID; data.Owner = module.GetOwner(ssp.UUID); data.GroupTitle = ssp.Grouptitle; data.GroupUUID = UUID.Zero; data.SenseAsAgent = !ssp.IsNPC; data.Appearance = ssp.Appearance; m_npcs.Add(data); module.DeleteNPC(ssp.UUID, m_scene); m_log.Info("Remove NPC " + ssp.Firstname + " " + ssp.Lastname); } } ); } else { m_log.Error("WARNING: CANT FOUND A NPC MODULE!"); } } catch (Exception _error) { m_log.Error("FATAL ERROR: " + _error.Message); } }
private void KillAvatar(uint killerObjectLocalID, ScenePresence deadAvatar) { string deadAvatarMessage; ScenePresence killingAvatar = null; // string killingAvatarMessage; // check to see if it is an NPC and just remove it INPCModule NPCmodule = deadAvatar.Scene.RequestModuleInterface <INPCModule>(); if (NPCmodule != null && NPCmodule.DeleteNPC(deadAvatar.UUID, deadAvatar.Scene)) { return; } if (killerObjectLocalID == 0) { deadAvatarMessage = "You committed suicide!"; } else { // Try to get the avatar responsible for the killing killingAvatar = deadAvatar.Scene.GetScenePresence(killerObjectLocalID); if (killingAvatar == null) { // Try to get the object which was responsible for the killing SceneObjectPart part = deadAvatar.Scene.GetSceneObjectPart(killerObjectLocalID); if (part == null) { // Cause of death: Unknown deadAvatarMessage = "You died!"; } else { // Try to find the avatar wielding the killing object killingAvatar = deadAvatar.Scene.GetScenePresence(part.OwnerID); if (killingAvatar == null) { IUserManagement userManager = deadAvatar.Scene.RequestModuleInterface <IUserManagement>(); string userName = "******"; if (userManager != null) { userName = userManager.GetUserName(part.OwnerID); } deadAvatarMessage = String.Format("You impaled yourself on {0} owned by {1}!", part.Name, userName); } else { // killingAvatarMessage = String.Format("You fragged {0}!", deadAvatar.Name); deadAvatarMessage = String.Format("You got killed by {0}!", killingAvatar.Name); } } } else { // killingAvatarMessage = String.Format("You fragged {0}!", deadAvatar.Name); deadAvatarMessage = String.Format("You got killed by {0}!", killingAvatar.Name); } } try { deadAvatar.ControllingClient.SendAgentAlertMessage(deadAvatarMessage, true); if (killingAvatar != null) { killingAvatar.ControllingClient.SendAlertMessage("You fragged " + deadAvatar.Firstname + " " + deadAvatar.Lastname); } } catch (InvalidOperationException) { } deadAvatar.setHealthWithUpdate(100.0f); deadAvatar.Scene.TeleportClientHome(deadAvatar.UUID, deadAvatar.ControllingClient); }