aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs157
1 files changed, 157 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs
new file mode 100644
index 0000000..1b82837
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs
@@ -0,0 +1,157 @@
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
28using System.Collections.Generic;
29using libsecondlife;
30using Nini.Config;
31using OpenSim.Framework;
32using OpenSim.Region.Environment.Interfaces;
33using OpenSim.Region.Environment.Scenes;
34
35namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
36{
37 public class InstantMessageModule : IRegionModule
38 {
39 private readonly List<Scene> m_scenes = new List<Scene>();
40
41 public void Initialise(Scene scene, IConfigSource config)
42 {
43 lock (m_scenes)
44 {
45 if (m_scenes.Count == 0)
46 {
47 //scene.AddXmlRPCHandler("avatar_location_update", processPresenceUpdate);
48 }
49
50 if (!m_scenes.Contains(scene))
51 {
52 m_scenes.Add(scene);
53 scene.EventManager.OnNewClient += OnNewClient;
54 scene.EventManager.OnGridInstantMessageToIMModule += OnGridInstantMessage;
55 }
56 }
57 }
58
59 private void OnNewClient(IClientAPI client)
60 {
61 client.OnInstantMessage += OnInstantMessage;
62 }
63
64 private void OnInstantMessage(IClientAPI client,LLUUID fromAgentID,
65 LLUUID fromAgentSession, LLUUID toAgentID,
66 LLUUID imSessionID, uint timestamp, string fromAgentName,
67 string message, byte dialog, bool fromGroup, byte offline,
68 uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
69 byte[] binaryBucket)
70 {
71 bool dialogHandledElsewhere
72 = ((dialog == 38) || (dialog == 39) || (dialog == 40)
73 || dialog == (byte)InstantMessageDialog.InventoryOffered
74 || dialog == (byte)InstantMessageDialog.InventoryAccepted
75 || dialog == (byte)InstantMessageDialog.InventoryDeclined);
76
77 // IM dialogs need to be pre-processed and have their sessionID filled by the server
78 // so the sim can match the transaction on the return packet.
79
80 // Don't send a Friend Dialog IM with a LLUUID.Zero session.
81 if (!(dialogHandledElsewhere && imSessionID == LLUUID.Zero))
82 {
83 // Try root avatar only first
84 foreach (Scene scene in m_scenes)
85 {
86 if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence)
87 {
88 // Local message
89 ScenePresence user = (ScenePresence)scene.Entities[toAgentID];
90 if (!user.IsChildAgent)
91 {
92 user.ControllingClient.SendInstantMessage(fromAgentID, fromAgentSession, message,
93 toAgentID, imSessionID, fromAgentName, dialog,
94 timestamp);
95 // Message sent
96 return;
97 }
98 }
99 }
100
101 // try child avatar second
102 foreach (Scene scene in m_scenes)
103 {
104 if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence)
105 {
106 // Local message
107 ScenePresence user = (ScenePresence)scene.Entities[toAgentID];
108
109 user.ControllingClient.SendInstantMessage(fromAgentID, fromAgentSession, message,
110 toAgentID, imSessionID, fromAgentName, dialog,
111 timestamp);
112 // Message sent
113 return;
114
115 }
116 }
117
118 }
119
120
121 // Still here, try send via Grid
122 // TODO
123 }
124
125 // Trusty OSG1 called method. This method also gets called from the FriendsModule
126 // Turns out the sim has to send an instant message to the user to get it to show an accepted friend.
127
128 private void OnGridInstantMessage(GridInstantMessage msg)
129 {
130 // Trigger the above event handler
131 OnInstantMessage(null,new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession),
132 new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName,
133 msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID,
134 new LLVector3(msg.Position.x,msg.Position.y,msg.Position.z), new LLUUID(msg.RegionID),
135 msg.binaryBucket);
136
137 }
138
139 public void PostInitialise()
140 {
141 }
142
143 public void Close()
144 {
145 }
146
147 public string Name
148 {
149 get { return "InstantMessageModule"; }
150 }
151
152 public bool IsSharedModule
153 {
154 get { return true; }
155 }
156 }
157} \ No newline at end of file