clockwerk-opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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 OpenSimulator 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 | using System; |
||
28 | using System.Collections.Generic; |
||
29 | using System.Reflection; |
||
30 | using log4net; |
||
31 | using Mono.Addins; |
||
32 | using Nini.Config; |
||
33 | using OpenMetaverse; |
||
34 | using OpenSim.Framework; |
||
35 | using OpenSim.Framework.Client; |
||
36 | using OpenSim.Region.Framework.Interfaces; |
||
37 | using OpenSim.Region.Framework.Scenes; |
||
38 | |||
39 | namespace OpenSim.Region.CoreModules.Avatar.InstantMessage |
||
40 | { |
||
41 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "InstantMessageModule")] |
||
42 | public class InstantMessageModule : ISharedRegionModule |
||
43 | { |
||
44 | private static readonly ILog m_log = LogManager.GetLogger( |
||
45 | MethodBase.GetCurrentMethod().DeclaringType); |
||
46 | |||
47 | /// <value> |
||
48 | /// Is this module enabled? |
||
49 | /// </value> |
||
50 | private bool m_enabled = false; |
||
51 | |||
52 | private readonly List<Scene> m_scenes = new List<Scene>(); |
||
53 | |||
54 | #region Region Module interface |
||
55 | |||
56 | private IMessageTransferModule m_TransferModule = null; |
||
57 | |||
58 | public void Initialise(IConfigSource config) |
||
59 | { |
||
60 | if (config.Configs["Messaging"] != null) |
||
61 | { |
||
62 | if (config.Configs["Messaging"].GetString( |
||
63 | "InstantMessageModule", "InstantMessageModule") != |
||
64 | "InstantMessageModule") |
||
65 | return; |
||
66 | } |
||
67 | |||
68 | m_enabled = true; |
||
69 | } |
||
70 | |||
71 | public void AddRegion(Scene scene) |
||
72 | { |
||
73 | if (!m_enabled) |
||
74 | return; |
||
75 | |||
76 | lock (m_scenes) |
||
77 | { |
||
78 | if (!m_scenes.Contains(scene)) |
||
79 | { |
||
80 | m_scenes.Add(scene); |
||
81 | scene.EventManager.OnClientConnect += OnClientConnect; |
||
82 | scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage; |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | |||
87 | public void RegionLoaded(Scene scene) |
||
88 | { |
||
89 | if (!m_enabled) |
||
90 | return; |
||
91 | |||
92 | if (m_TransferModule == null) |
||
93 | { |
||
94 | m_TransferModule = |
||
95 | scene.RequestModuleInterface<IMessageTransferModule>(); |
||
96 | |||
97 | if (m_TransferModule == null) |
||
98 | { |
||
99 | m_log.Error("[INSTANT MESSAGE]: No message transfer module, IM will not work!"); |
||
100 | scene.EventManager.OnClientConnect -= OnClientConnect; |
||
101 | scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage; |
||
102 | |||
103 | m_scenes.Clear(); |
||
104 | m_enabled = false; |
||
105 | } |
||
106 | } |
||
107 | } |
||
108 | |||
109 | public void RemoveRegion(Scene scene) |
||
110 | { |
||
111 | if (!m_enabled) |
||
112 | return; |
||
113 | |||
114 | lock (m_scenes) |
||
115 | { |
||
116 | m_scenes.Remove(scene); |
||
117 | } |
||
118 | } |
||
119 | |||
120 | void OnClientConnect(IClientCore client) |
||
121 | { |
||
122 | IClientIM clientIM; |
||
123 | if (client.TryGet(out clientIM)) |
||
124 | { |
||
125 | clientIM.OnInstantMessage += OnInstantMessage; |
||
126 | } |
||
127 | } |
||
128 | |||
129 | public void PostInitialise() |
||
130 | { |
||
131 | } |
||
132 | |||
133 | public void Close() |
||
134 | { |
||
135 | } |
||
136 | |||
137 | public string Name |
||
138 | { |
||
139 | get { return "InstantMessageModule"; } |
||
140 | } |
||
141 | |||
142 | public Type ReplaceableInterface |
||
143 | { |
||
144 | get { return null; } |
||
145 | } |
||
146 | |||
147 | #endregion |
||
148 | |||
149 | public void OnInstantMessage(IClientAPI client, GridInstantMessage im) |
||
150 | { |
||
151 | byte dialog = im.dialog; |
||
152 | |||
153 | if (dialog != (byte)InstantMessageDialog.MessageFromAgent |
||
154 | && dialog != (byte)InstantMessageDialog.StartTyping |
||
155 | && dialog != (byte)InstantMessageDialog.StopTyping |
||
156 | && dialog != (byte)InstantMessageDialog.BusyAutoResponse |
||
157 | && dialog != (byte)InstantMessageDialog.MessageFromObject) |
||
158 | { |
||
159 | return; |
||
160 | } |
||
161 | |||
162 | if (m_TransferModule != null) |
||
163 | { |
||
164 | if (client != null) |
||
165 | im.fromAgentName = client.FirstName + " " + client.LastName; |
||
166 | m_TransferModule.SendInstantMessage(im, |
||
167 | delegate(bool success) |
||
168 | { |
||
169 | if (dialog == (uint)InstantMessageDialog.StartTyping || |
||
170 | dialog == (uint)InstantMessageDialog.StopTyping || |
||
171 | dialog == (uint)InstantMessageDialog.MessageFromObject) |
||
172 | { |
||
173 | return; |
||
174 | } |
||
175 | |||
176 | if ((client != null) && !success) |
||
177 | { |
||
178 | client.SendInstantMessage( |
||
179 | new GridInstantMessage( |
||
180 | null, new UUID(im.fromAgentID), "System", |
||
181 | new UUID(im.toAgentID), |
||
182 | (byte)InstantMessageDialog.BusyAutoResponse, |
||
183 | "Unable to send instant message. "+ |
||
184 | "User is not logged in.", false, |
||
185 | new Vector3())); |
||
186 | } |
||
187 | } |
||
188 | ); |
||
189 | } |
||
190 | } |
||
191 | |||
192 | /// <summary> |
||
193 | /// |
||
194 | /// </summary> |
||
195 | /// <param name="msg"></param> |
||
196 | private void OnGridInstantMessage(GridInstantMessage msg) |
||
197 | { |
||
198 | // Just call the Text IM handler above |
||
199 | // This event won't be raised unless we have that agent, |
||
200 | // so we can depend on the above not trying to send |
||
201 | // via grid again |
||
202 | // |
||
203 | OnInstantMessage(null, msg); |
||
204 | } |
||
205 | } |
||
206 | } |