diff options
Diffstat (limited to '')
4 files changed, 81 insertions, 25 deletions
diff --git a/OpenSim/Region/Environment/Interfaces/ISimChat.cs b/OpenSim/Region/Environment/Interfaces/ISimChat.cs index 4ec55ff..583d8b2 100644 --- a/OpenSim/Region/Environment/Interfaces/ISimChat.cs +++ b/OpenSim/Region/Environment/Interfaces/ISimChat.cs | |||
@@ -32,6 +32,6 @@ namespace OpenSim.Region.Environment.Interfaces | |||
32 | { | 32 | { |
33 | public interface ISimChat | 33 | public interface ISimChat |
34 | { | 34 | { |
35 | void SimChat(byte[] message, byte type, int channel, LLVector3 fromPos, string fromName, LLUUID fromAgentID); | 35 | void SimChat(System.Object sender, OpenSim.Framework.Interfaces.ChatFromViewerArgs e); |
36 | } | 36 | } |
37 | } | 37 | } |
diff --git a/OpenSim/Region/Environment/Modules/ChatModule.cs b/OpenSim/Region/Environment/Modules/ChatModule.cs index 7db4f4b..594d5b4 100644 --- a/OpenSim/Region/Environment/Modules/ChatModule.cs +++ b/OpenSim/Region/Environment/Modules/ChatModule.cs | |||
@@ -33,15 +33,16 @@ using System.Threading; | |||
33 | using libsecondlife; | 33 | using libsecondlife; |
34 | using OpenSim.Framework.Interfaces; | 34 | using OpenSim.Framework.Interfaces; |
35 | using OpenSim.Framework.Utilities; | 35 | using OpenSim.Framework.Utilities; |
36 | using OpenSim.Framework.Console; | ||
36 | using OpenSim.Region.Environment.Interfaces; | 37 | using OpenSim.Region.Environment.Interfaces; |
37 | using OpenSim.Region.Environment.Scenes; | 38 | using OpenSim.Region.Environment.Scenes; |
38 | using Nini.Config; | ||
39 | 39 | ||
40 | namespace OpenSim.Region.Environment.Modules | 40 | namespace OpenSim.Region.Environment.Modules |
41 | { | 41 | { |
42 | public class ChatModule : IRegionModule, ISimChat | 42 | public class ChatModule : IRegionModule, ISimChat |
43 | { | 43 | { |
44 | private Scene m_scene; | 44 | private Scene m_scene; |
45 | private LogBase m_log; | ||
45 | 46 | ||
46 | private string m_server = null; | 47 | private string m_server = null; |
47 | private int m_port = 6668; | 48 | private int m_port = 6668; |
@@ -65,10 +66,12 @@ namespace OpenSim.Region.Environment.Modules | |||
65 | m_nick = "OSimBot" + Util.RandomClass.Next(1, 99); | 66 | m_nick = "OSimBot" + Util.RandomClass.Next(1, 99); |
66 | m_irc = null; | 67 | m_irc = null; |
67 | m_ircWriter = null; | 68 | m_ircWriter = null; |
68 | m_ircReader = null; | 69 | m_ircReader = null; |
70 | |||
71 | m_log = OpenSim.Framework.Console.MainLog.Instance; | ||
69 | } | 72 | } |
70 | 73 | ||
71 | public void Initialise(Scene scene, IConfigSource config) | 74 | public void Initialise(Scene scene, Nini.Config.IConfigSource config) |
72 | { | 75 | { |
73 | try { | 76 | try { |
74 | m_server = config.Configs["IRC"].GetString("server"); | 77 | m_server = config.Configs["IRC"].GetString("server"); |
@@ -175,41 +178,80 @@ namespace OpenSim.Region.Environment.Modules | |||
175 | } | 178 | } |
176 | } | 179 | } |
177 | 180 | ||
178 | public void SimChat(byte[] message, byte type, int channel, LLVector3 fromPos, string fromName, | 181 | public void SimChat(Object sender, ChatFromViewerArgs e) |
179 | LLUUID fromAgentID) | ||
180 | { | 182 | { |
181 | ScenePresence avatar = null; | 183 | ScenePresence avatar = null; |
182 | avatar = m_scene.GetScenePresence(fromAgentID); | 184 | |
185 | //TODO: Move ForEachScenePresence and others into IScene. | ||
186 | Scene scene = (Scene)e.Scene; | ||
187 | |||
188 | //TODO: Remove the need for this check | ||
189 | if (scene == null) | ||
190 | scene = m_scene; | ||
191 | |||
192 | // Filled in since it's easier than rewriting right now. | ||
193 | LLVector3 fromPos = e.Position; | ||
194 | string fromName = e.From; | ||
195 | string message = e.Message; | ||
196 | byte type = (byte)e.Type; | ||
197 | LLUUID fromAgentID = LLUUID.Zero; | ||
198 | |||
199 | if (e.Sender != null) | ||
200 | avatar = scene.GetScenePresence(e.Sender.AgentId); | ||
201 | |||
183 | if (avatar != null) | 202 | if (avatar != null) |
184 | { | 203 | { |
185 | fromPos = avatar.AbsolutePosition; | 204 | fromPos = avatar.AbsolutePosition; |
186 | fromName = avatar.Firstname + " " + avatar.Lastname; | 205 | fromName = avatar.Firstname + " " + avatar.Lastname; |
206 | fromAgentID = e.Sender.AgentId; | ||
187 | avatar = null; | 207 | avatar = null; |
188 | } | 208 | } |
209 | |||
210 | string typeName; | ||
211 | switch (e.Type) | ||
212 | { | ||
213 | case ChatTypeEnum.Broadcast: | ||
214 | typeName = "broadcasts"; | ||
215 | break; | ||
216 | case ChatTypeEnum.Say: | ||
217 | typeName = "says"; | ||
218 | break; | ||
219 | case ChatTypeEnum.Shout: | ||
220 | typeName = "shouts"; | ||
221 | break; | ||
222 | case ChatTypeEnum.Whisper: | ||
223 | typeName = "whispers"; | ||
224 | break; | ||
225 | default: | ||
226 | typeName = "unknown"; | ||
227 | break; | ||
228 | } | ||
229 | |||
230 | m_log.Verbose("CHAT", fromName + " (" + e.Channel + ") " + typeName + ": " + e.Message); | ||
189 | 231 | ||
190 | if (connected) | 232 | if (connected) |
191 | { | 233 | { |
192 | m_ircWriter.WriteLine("PRIVMSG " + m_channel + " :" + "<" + fromName + ">: " + | 234 | m_ircWriter.WriteLine("PRIVMSG " + m_channel + " :" + "<" + fromName + ">: " + |
193 | Util.FieldToString(message)); | 235 | e.Message); |
194 | m_ircWriter.Flush(); | 236 | m_ircWriter.Flush(); |
195 | } | 237 | } |
196 | 238 | ||
197 | if (channel == 0) | 239 | if (e.Channel == 0) |
198 | { | 240 | { |
199 | m_scene.ForEachScenePresence(delegate(ScenePresence presence) | 241 | scene.ForEachScenePresence(delegate(ScenePresence presence) |
200 | { | 242 | { |
201 | int dis = -1000; | 243 | int dis = -1000; |
202 | 244 | ||
203 | //err ??? the following code seems to be request a scenePresence when it already has a ref to it | 245 | //err ??? the following code seems to be request a scenePresence when it already has a ref to it |
204 | avatar = m_scene.GetScenePresence(presence.ControllingClient.AgentId); | 246 | avatar = scene.GetScenePresence(presence.ControllingClient.AgentId); |
205 | if (avatar != null) | 247 | if (avatar != null) |
206 | { | 248 | { |
207 | dis = (int) avatar.AbsolutePosition.GetDistanceTo(fromPos); | 249 | dis = (int) avatar.AbsolutePosition.GetDistanceTo(fromPos); |
208 | } | 250 | } |
209 | 251 | ||
210 | switch (type) | 252 | switch (e.Type) |
211 | { | 253 | { |
212 | case 0: // Whisper | 254 | case ChatTypeEnum.Whisper: |
213 | if ((dis < 10) && (dis > -10)) | 255 | if ((dis < 10) && (dis > -10)) |
214 | { | 256 | { |
215 | //should change so the message is sent through the avatar rather than direct to the ClientView | 257 | //should change so the message is sent through the avatar rather than direct to the ClientView |
@@ -220,7 +262,7 @@ namespace OpenSim.Region.Environment.Modules | |||
220 | fromAgentID); | 262 | fromAgentID); |
221 | } | 263 | } |
222 | break; | 264 | break; |
223 | case 1: // Say | 265 | case ChatTypeEnum.Say: |
224 | if ((dis < 30) && (dis > -30)) | 266 | if ((dis < 30) && (dis > -30)) |
225 | { | 267 | { |
226 | //Console.WriteLine("sending chat"); | 268 | //Console.WriteLine("sending chat"); |
@@ -231,7 +273,7 @@ namespace OpenSim.Region.Environment.Modules | |||
231 | fromAgentID); | 273 | fromAgentID); |
232 | } | 274 | } |
233 | break; | 275 | break; |
234 | case 2: // Shout | 276 | case ChatTypeEnum.Shout: |
235 | if ((dis < 100) && (dis > -100)) | 277 | if ((dis < 100) && (dis > -100)) |
236 | { | 278 | { |
237 | presence.ControllingClient.SendChatMessage(message, | 279 | presence.ControllingClient.SendChatMessage(message, |
@@ -242,7 +284,7 @@ namespace OpenSim.Region.Environment.Modules | |||
242 | } | 284 | } |
243 | break; | 285 | break; |
244 | 286 | ||
245 | case 0xff: // Broadcast | 287 | case ChatTypeEnum.Broadcast: |
246 | presence.ControllingClient.SendChatMessage(message, type, | 288 | presence.ControllingClient.SendChatMessage(message, type, |
247 | fromPos, | 289 | fromPos, |
248 | fromName, | 290 | fromName, |
diff --git a/OpenSim/Region/Environment/Modules/WorldCommModule.cs b/OpenSim/Region/Environment/Modules/WorldCommModule.cs index 765f1b4..cf5bba3 100644 --- a/OpenSim/Region/Environment/Modules/WorldCommModule.cs +++ b/OpenSim/Region/Environment/Modules/WorldCommModule.cs | |||
@@ -119,13 +119,12 @@ namespace OpenSim.Region.Environment.Modules | |||
119 | client.OnChatFromViewer += DeliverClientMessage; | 119 | client.OnChatFromViewer += DeliverClientMessage; |
120 | } | 120 | } |
121 | 121 | ||
122 | private void DeliverClientMessage(byte[] message, byte type, int channel, LLVector3 fromPos, string fromName, | 122 | private void DeliverClientMessage(Object sender, ChatFromViewerArgs e) |
123 | LLUUID fromAgentID) | ||
124 | { | 123 | { |
125 | ASCIIEncoding ae = new ASCIIEncoding(); | 124 | DeliverMessage(e.Sender.AgentId.ToString(), |
126 | 125 | (int)e.Type, e.Channel, | |
127 | DeliverMessage(fromAgentID.ToString(), type, channel, fromName, ae.GetString(message)); | 126 | e.Sender.FirstName + " " + e.Sender.LastName, |
128 | 127 | e.Message); | |
129 | } | 128 | } |
130 | 129 | ||
131 | public int Listen(uint localID, LLUUID itemID, LLUUID hostID, int channel, string name, string id, string msg) | 130 | public int Listen(uint localID, LLUUID itemID, LLUUID hostID, int channel, string name, string id, string msg) |
diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs index df8b190..71f8037 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs | |||
@@ -70,7 +70,22 @@ namespace OpenSim.Region.Environment.Scenes | |||
70 | { | 70 | { |
71 | if (m_simChatModule != null) | 71 | if (m_simChatModule != null) |
72 | { | 72 | { |
73 | m_simChatModule.SimChat(message, type, channel, fromPos, fromName, fromAgentID); | 73 | ChatFromViewerArgs args = new ChatFromViewerArgs(); |
74 | |||
75 | args.Message = OpenSim.Framework.Utilities.Util.FieldToString(message); | ||
76 | args.Channel = channel; | ||
77 | args.Type = (ChatTypeEnum)type; | ||
78 | args.Position = fromPos; | ||
79 | |||
80 | ScenePresence user = this.GetScenePresence(fromAgentID); | ||
81 | if (user != null) | ||
82 | args.Sender = user.ControllingClient; | ||
83 | else | ||
84 | args.Sender = null; | ||
85 | |||
86 | args.From = fromName; | ||
87 | |||
88 | m_simChatModule.SimChat(this, args); | ||
74 | } | 89 | } |
75 | } | 90 | } |
76 | 91 | ||