opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 1 /*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27  
28 using System;
29 using System.Collections.Generic;
30 using Nini.Config;
31 using OpenSim.Framework;
32 using OpenSim.Region.Framework.Interfaces;
33 using OpenSim.Region.Framework.Scenes;
34 using OpenMetaverse;
35  
36 using Mono.Addins;
37  
38 namespace OpenSim.Region.CoreModules.Avatar.Combat.CombatModule
39 {
40 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "CombatModule")]
41 public class CombatModule : ISharedRegionModule
42 {
43 //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44  
45 /// <summary>
46 /// Region UUIDS indexed by AgentID
47 /// </summary>
48 //private Dictionary<UUID, UUID> m_rootAgents = new Dictionary<UUID, UUID>();
49  
50 /// <summary>
51 /// Scenes by Region Handle
52 /// </summary>
53 private Dictionary<ulong, Scene> m_scenel = new Dictionary<ulong, Scene>();
54  
55 /// <summary>
56 /// Startup
57 /// </summary>
58 /// <param name="scene"></param>
59 /// <param name="config"></param>
60 public void Initialise(IConfigSource config)
61 {
62 }
63  
64 public void AddRegion(Scene scene)
65 {
66 lock (m_scenel)
67 {
68 if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
69 {
70 m_scenel[scene.RegionInfo.RegionHandle] = scene;
71 }
72 else
73 {
74 m_scenel.Add(scene.RegionInfo.RegionHandle, scene);
75 }
76 }
77  
78 scene.EventManager.OnAvatarKilled += KillAvatar;
79 scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
80 }
81  
82 public void RemoveRegion(Scene scene)
83 {
84 if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
85 m_scenel.Remove(scene.RegionInfo.RegionHandle);
86  
87 scene.EventManager.OnAvatarKilled -= KillAvatar;
88 scene.EventManager.OnAvatarEnteringNewParcel -= AvatarEnteringParcel;
89 }
90  
91 public void RegionLoaded(Scene scene)
92 {
93 }
94  
95 public void PostInitialise()
96 {
97 }
98  
99 public void Close()
100 {
101 }
102  
103 public string Name
104 {
105 get { return "CombatModule"; }
106 }
107  
108 public Type ReplaceableInterface
109 {
110 get { return null; }
111 }
112  
113  
114 private void KillAvatar(uint killerObjectLocalID, ScenePresence deadAvatar)
115 {
116 string deadAvatarMessage;
117 ScenePresence killingAvatar = null;
118 // string killingAvatarMessage;
119  
120 // check to see if it is an NPC and just remove it
121 INPCModule NPCmodule = deadAvatar.Scene.RequestModuleInterface<INPCModule>();
122 if (NPCmodule != null && NPCmodule.DeleteNPC(deadAvatar.UUID, deadAvatar.Scene))
123 {
124 return;
125 }
126  
127 if (killerObjectLocalID == 0)
128 deadAvatarMessage = "You committed suicide!";
129 else
130 {
131 // Try to get the avatar responsible for the killing
132 killingAvatar = deadAvatar.Scene.GetScenePresence(killerObjectLocalID);
133 if (killingAvatar == null)
134 {
135 // Try to get the object which was responsible for the killing
136 SceneObjectPart part = deadAvatar.Scene.GetSceneObjectPart(killerObjectLocalID);
137 if (part == null)
138 {
139 // Cause of death: Unknown
140 deadAvatarMessage = "You died!";
141 }
142 else
143 {
144 // Try to find the avatar wielding the killing object
145 killingAvatar = deadAvatar.Scene.GetScenePresence(part.OwnerID);
146 if (killingAvatar == null)
147 {
148 IUserManagement userManager = deadAvatar.Scene.RequestModuleInterface<IUserManagement>();
149 string userName = "Unkown User";
150 if (userManager != null)
151 userName = userManager.GetUserName(part.OwnerID);
152 deadAvatarMessage = String.Format("You impaled yourself on {0} owned by {1}!", part.Name, userName);
153 }
154 else
155 {
156 // killingAvatarMessage = String.Format("You fragged {0}!", deadAvatar.Name);
157 deadAvatarMessage = String.Format("You got killed by {0}!", killingAvatar.Name);
158 }
159 }
160 }
161 else
162 {
163 // killingAvatarMessage = String.Format("You fragged {0}!", deadAvatar.Name);
164 deadAvatarMessage = String.Format("You got killed by {0}!", killingAvatar.Name);
165 }
166 }
167 try
168 {
169 deadAvatar.ControllingClient.SendAgentAlertMessage(deadAvatarMessage, true);
170 if (killingAvatar != null)
171 killingAvatar.ControllingClient.SendAlertMessage("You fragged " + deadAvatar.Firstname + " " + deadAvatar.Lastname);
172 }
173 catch (InvalidOperationException)
174 { }
175  
176 deadAvatar.setHealthWithUpdate(100.0f);
177 deadAvatar.Scene.TeleportClientHome(deadAvatar.UUID, deadAvatar.ControllingClient);
178 }
179  
180 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID)
181 {
182 try
183 {
184 ILandObject obj = avatar.Scene.LandChannel.GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
185 if ((obj.LandData.Flags & (uint)ParcelFlags.AllowDamage) != 0
186 || avatar.Scene.RegionInfo.RegionSettings.AllowDamage)
187 {
188 avatar.Invulnerable = false;
189 }
190 else
191 {
192 avatar.Invulnerable = true;
193 if (avatar.Health < 100.0f)
194 {
195 avatar.setHealthWithUpdate(100.0f);
196 }
197 }
198 }
199 catch (Exception)
200 {
201 }
202 }
203 }
204 }