aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/ChatModule.cs
diff options
context:
space:
mode:
authorAdam Frisby2007-10-19 22:02:07 +0000
committerAdam Frisby2007-10-19 22:02:07 +0000
commit1313544ac7761ec7d84c14009fc95d5d7316004d (patch)
tree39a7bd27f07bb96859f5d09436d7e81e99f951a9 /OpenSim/Region/Environment/Modules/ChatModule.cs
parentenable IRC bridge via runtime configuration (diff)
downloadopensim-SC_OLD-1313544ac7761ec7d84c14009fc95d5d7316004d.zip
opensim-SC_OLD-1313544ac7761ec7d84c14009fc95d5d7316004d.tar.gz
opensim-SC_OLD-1313544ac7761ec7d84c14009fc95d5d7316004d.tar.bz2
opensim-SC_OLD-1313544ac7761ec7d84c14009fc95d5d7316004d.tar.xz
* Major structural change: Begun converting Events to use (caller, args) syntax to conform with .NET guidelines.
* OnChatFromViewer has been converted as an example. * Bug: SimpleApp's NPC client does not implement a Scene property and will likely crash with a NullReferenceException when it attempts to chat.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/ChatModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/ChatModule.cs76
1 files changed, 59 insertions, 17 deletions
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;
33using libsecondlife; 33using libsecondlife;
34using OpenSim.Framework.Interfaces; 34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Utilities; 35using OpenSim.Framework.Utilities;
36using OpenSim.Framework.Console;
36using OpenSim.Region.Environment.Interfaces; 37using OpenSim.Region.Environment.Interfaces;
37using OpenSim.Region.Environment.Scenes; 38using OpenSim.Region.Environment.Scenes;
38using Nini.Config;
39 39
40namespace OpenSim.Region.Environment.Modules 40namespace 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,