aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Avatar/Chat
diff options
context:
space:
mode:
authorDr Scofield2008-10-03 14:53:11 +0000
committerDr Scofield2008-10-03 14:53:11 +0000
commit5c0a0bc2e0951745fd52f5c01f2ee2c0aee49a3a (patch)
tree529c2c8e3ea8f1193f2495f905e542ff1462adb6 /OpenSim/Region/Environment/Modules/Avatar/Chat
parent* minor: remove warnings (the code cleaners strike again) (diff)
downloadopensim-SC_OLD-5c0a0bc2e0951745fd52f5c01f2ee2c0aee49a3a.zip
opensim-SC_OLD-5c0a0bc2e0951745fd52f5c01f2ee2c0aee49a3a.tar.gz
opensim-SC_OLD-5c0a0bc2e0951745fd52f5c01f2ee2c0aee49a3a.tar.bz2
opensim-SC_OLD-5c0a0bc2e0951745fd52f5c01f2ee2c0aee49a3a.tar.xz
This changeset changes the way chat from client is routed:
old way: each region module interested in chat from client had to - subscribe to scene.EventManager.OnNewClient - then in its OnNewClient delegate it would subscribe to client.OnChatFromViewer to capture chat messages coming new way: ChatModule is the only region module that uses the "old way" approach but is now forwarding all client chat via scene.EventManager.OnChatFromClient - each region module interested in chat from client now only subscribes to scene.EventManager.OnChatFromClient this not only simplifies code, but also allows us to substitute ChatModule with derived classes (ConciergeModule is going to be one example). Also, this changeset changes ChatFromViewer to ChatFromClient as it doesn't necessarily have to be a viewer that is a chat source. i've taken great care to only comment out those OnNewClient delegates that were only used for getting at the client chat --- hope it's not breaking anything.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Avatar/Chat')
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs193
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs26
2 files changed, 110 insertions, 109 deletions
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs
index 606ce7e..34a604e 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs
@@ -64,26 +64,25 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
64 { 64 {
65 m_scenes.Add(scene); 65 m_scenes.Add(scene);
66 scene.EventManager.OnNewClient += OnNewClient; 66 scene.EventManager.OnNewClient += OnNewClient;
67 scene.EventManager.OnChatFromWorld += OnSimChat; 67 scene.EventManager.OnChatFromWorld += OnChatFromWorld;
68 scene.EventManager.OnChatBroadcast += OnSimBroadcast; 68 scene.EventManager.OnChatBroadcast += OnChatBroadcast;
69 } 69 }
70 }
70 71
71 // wrap this in a try block so that defaults will work if 72 // wrap this in a try block so that defaults will work if
72 // the config file doesn't specify otherwise. 73 // the config file doesn't specify otherwise.
73 try 74 try
74 { 75 {
75 m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance", m_whisperdistance); 76 m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance", m_whisperdistance);
76 m_saydistance = config.Configs["Chat"].GetInt("say_distance", m_saydistance); 77 m_saydistance = config.Configs["Chat"].GetInt("say_distance", m_saydistance);
77 m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance", m_shoutdistance); 78 m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance", m_shoutdistance);
78 }
79 catch (Exception)
80 {
81 }
82 m_log.InfoFormat("[CHAT] initialized for {0} w:{1} s:{2} S:{3}", scene.RegionInfo.RegionName,
83 m_whisperdistance, m_saydistance, m_shoutdistance);
84 } 79 }
80 catch (Exception)
81 {
82 }
83 m_log.InfoFormat("[CHAT] initialized for {0} w:{1} s:{2} S:{3}", scene.RegionInfo.RegionName,
84 m_whisperdistance, m_saydistance, m_shoutdistance);
85 } 85 }
86
87 public void PostInitialise() 86 public void PostInitialise()
88 { 87 {
89 } 88 }
@@ -104,8 +103,89 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
104 103
105 #endregion 104 #endregion
106 105
107 #region ISimChat Members 106
108 public void OnSimBroadcast(Object sender, OSChatMessage c) 107 public void OnNewClient(IClientAPI client)
108 {
109 try
110 {
111 client.OnChatFromClient += OnChatFromClient;
112 }
113 catch (Exception ex)
114 {
115 m_log.Error("[CHAT]: NewClient exception trap:" + ex.ToString());
116 }
117 }
118
119 public virtual void OnChatFromClient(Object sender, OSChatMessage e)
120 {
121 // redistribute to interested subscribers
122 Scene scene = (Scene)e.Scene;
123 scene.EventManager.TriggerOnChatFromClient(sender, e);
124
125 // early return if not on public or debug channel
126 if (e.Channel != 0 && e.Channel != DEBUG_CHANNEL) return;
127
128 // sanity check:
129 if (e.Sender == null)
130 {
131 m_log.ErrorFormat("[CHAT] OnChatFromClient from {0} has empty Sender field!", sender);
132 return;
133 }
134
135 string message = e.Message;
136 if (e.Channel == DEBUG_CHANNEL) e.Type = ChatTypeEnum.DebugChannel;
137
138 ScenePresence avatar = scene.GetScenePresence(e.Sender.AgentId);
139 Vector3 fromPos = avatar.AbsolutePosition;
140 Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize,
141 scene.RegionInfo.RegionLocY * Constants.RegionSize, 0);
142 string fromName = avatar.Firstname + " " + avatar.Lastname;
143 UUID fromID = e.Sender.AgentId;
144
145 DeliverChatToAvatars(fromPos, regionPos, fromID, fromName, e.Type, ChatSourceType.Agent, message);
146 }
147
148 public void OnChatFromWorld(Object sender, OSChatMessage e)
149 {
150 Scene scene = (Scene) e.Scene;
151
152 // early return if not on public or debug channel
153 if (e.Channel != 0 && e.Channel != DEBUG_CHANNEL) return;
154
155 // Filled in since it's easier than rewriting right now.
156 Vector3 fromPos = e.Position;
157 Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize,
158 scene.RegionInfo.RegionLocY * Constants.RegionSize, 0);
159
160 string fromName = e.From;
161 string message = e.Message;
162 UUID fromID = e.SenderUUID;
163
164 if (e.Channel == DEBUG_CHANNEL)
165 e.Type = ChatTypeEnum.DebugChannel;
166
167 DeliverChatToAvatars(fromPos, regionPos, fromID, fromName, e.Type, ChatSourceType.Object, message);
168 }
169
170 protected void DeliverChatToAvatars(Vector3 pos, Vector3 regionPos, UUID uuid, string name,
171 ChatTypeEnum chatType, ChatSourceType sourceType, string message)
172 {
173 // iterate over message
174 if (message.Length >= 1000) // libomv limit
175 message = message.Substring(0, 1000);
176
177 foreach (Scene s in m_scenes)
178 {
179 s.ForEachScenePresence(delegate(ScenePresence presence)
180 {
181 TrySendChatMessage(presence, pos, regionPos, uuid, name,
182 chatType, message, sourceType);
183 });
184 }
185 }
186
187
188 public void OnChatBroadcast(Object sender, OSChatMessage c)
109 { 189 {
110 // We only want to relay stuff on channel 0 and on the debug channel 190 // We only want to relay stuff on channel 0 and on the debug channel
111 if (c.Channel != 0 && c.Channel != DEBUG_CHANNEL) return; 191 if (c.Channel != 0 && c.Channel != DEBUG_CHANNEL) return;
@@ -153,83 +233,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
153 }); 233 });
154 } 234 }
155 235
156 public void OnSimChat(Object sender, OSChatMessage e)
157 {
158 // early return if not on public or debug channel
159 if (e.Channel != 0 && e.Channel != DEBUG_CHANNEL) return;
160
161 ScenePresence avatar = null;
162 Scene scene = (Scene) e.Scene;
163
164 //TODO: Remove the need for this check
165 if (scene == null)
166 scene = m_scenes[0];
167
168 // Filled in since it's easier than rewriting right now.
169 Vector3 fromPos = e.Position;
170 Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize,
171 scene.RegionInfo.RegionLocY * Constants.RegionSize, 0);
172
173 string fromName = e.From;
174 string message = e.Message;
175 UUID fromID = e.SenderUUID;
176
177 if (message.Length >= 1000) // libomv limit
178 message = message.Substring(0, 1000);
179
180 if (e.Sender != null)
181 {
182 avatar = scene.GetScenePresence(e.Sender.AgentId);
183 }
184
185 if (avatar != null)
186 {
187 fromPos = avatar.AbsolutePosition;
188 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize,
189 scene.RegionInfo.RegionLocY * Constants.RegionSize, 0);
190 fromName = avatar.Firstname + " " + avatar.Lastname;
191 fromID = e.Sender.AgentId;
192 }
193
194 if (e.Channel == DEBUG_CHANNEL)
195 e.Type = ChatTypeEnum.DebugChannel;
196
197 // chat works by redistributing every incoming chat
198 // message to each avatar in the scene
199 foreach (Scene s in m_scenes)
200 {
201 s.ForEachScenePresence(
202 delegate(ScenePresence presence)
203 {
204 if (e.Channel == DEBUG_CHANNEL)
205 {
206 TrySendChatMessage(presence, fromPos, regionPos,
207 fromID, fromName, e.Type,
208 message, ChatSourceType.Object);
209 }
210 else
211 {
212 TrySendChatMessage(presence, fromPos, regionPos,
213 fromID, fromName, e.Type,
214 message, ChatSourceType.Agent);
215 }
216 });
217 }
218 }
219
220 #endregion
221
222 public void OnNewClient(IClientAPI client)
223 {
224 try
225 {
226 client.OnChatFromViewer += OnSimChat;
227 }
228 catch (Exception ex)
229 {
230 m_log.Error("[CHAT]: NewClient exception trap:" + ex.ToString());
231 }
232 }
233 236
234 private void TrySendChatMessage(ScenePresence presence, Vector3 fromPos, Vector3 regionPos, 237 private void TrySendChatMessage(ScenePresence presence, Vector3 fromPos, Vector3 regionPos,
235 UUID fromAgentID, string fromName, ChatTypeEnum type, 238 UUID fromAgentID, string fromName, ChatTypeEnum type,
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs
index eba65a9..5840cb2 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs
@@ -93,6 +93,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
93 m_scenes.Add(scene); 93 m_scenes.Add(scene);
94 scene.EventManager.OnNewClient += OnNewClient; 94 scene.EventManager.OnNewClient += OnNewClient;
95 scene.EventManager.OnChatFromWorld += OnSimChat; 95 scene.EventManager.OnChatFromWorld += OnSimChat;
96 scene.EventManager.OnChatFromClient += OnSimChat;
96 scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; 97 scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
97 scene.EventManager.OnMakeChildAgent += OnMakeChildAgent; 98 scene.EventManager.OnMakeChildAgent += OnMakeChildAgent;
98 } 99 }
@@ -236,7 +237,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
236 237
237 if (avatar != null) 238 if (avatar != null)
238 { 239 {
239 fromName = avatar.Firstname + " " + avatar.Lastname; 240 fromName = avatar.Name;
240 } 241 }
241 242
242 // Try to reconnect to server if not connected 243 // Try to reconnect to server if not connected
@@ -277,21 +278,19 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
277 { 278 {
278 try 279 try
279 { 280 {
280 string clientName = String.Format("{0} {1}", client.FirstName, client.LastName); 281 // client.OnChatFromViewer += OnSimChat;
281
282 client.OnChatFromViewer += OnSimChat;
283 client.OnLogout += OnClientLoggedOut; 282 client.OnLogout += OnClientLoggedOut;
284 client.OnConnectionClosed += OnClientLoggedOut; 283 client.OnConnectionClosed += OnClientLoggedOut;
285 284
286 if (clientName != m_last_new_user) 285 if (client.Name != m_last_new_user)
287 { 286 {
288 if ((m_irc.Enabled) && (m_irc.Connected)) 287 if ((m_irc.Enabled) && (m_irc.Connected))
289 { 288 {
290 m_log.DebugFormat("[IRC] {0} logging on", clientName); 289 m_log.DebugFormat("[IRC] {0} logging on", client.Name);
291 m_irc.PrivMsg(m_irc.Nick, "Sim", 290 m_irc.PrivMsg(m_irc.Nick, "Sim",
292 String.Format("notices {0} logging on", clientName)); 291 String.Format("notices {0} logging on", client.Name));
293 } 292 }
294 m_last_new_user = clientName; 293 m_last_new_user = client.Name;
295 } 294 }
296 } 295 }
297 catch (Exception ex) 296 catch (Exception ex)
@@ -343,21 +342,20 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
343 { 342 {
344 if ((m_irc.Enabled) && (m_irc.Connected)) 343 if ((m_irc.Enabled) && (m_irc.Connected))
345 { 344 {
346 string clientName = String.Format("{0} {1}", client.FirstName, client.LastName);
347 // handles simple case. May not work for hundred connecting in per second. 345 // handles simple case. May not work for hundred connecting in per second.
348 // and the NewClients calles getting interleved 346 // and the NewClients calles getting interleved
349 // but filters out multiple reports 347 // but filters out multiple reports
350 if (clientName != m_last_leaving_user) 348 if (client.Name != m_last_leaving_user)
351 { 349 {
352 Console.WriteLine("Avatar was seen logging out."); 350 Console.WriteLine("Avatar was seen logging out.");
353 //Console.ReadLine(); 351 //Console.ReadLine();
354 Console.WriteLine(); 352 Console.WriteLine();
355 m_last_leaving_user = clientName; 353 m_last_leaving_user = client.Name;
356 m_irc.PrivMsg(m_irc.Nick, "Sim", String.Format("notices {0} logging out", clientName)); 354 m_irc.PrivMsg(m_irc.Nick, "Sim", String.Format("notices {0} logging out", client.Name));
357 m_log.InfoFormat("[IRC]: {0} logging out", clientName); 355 m_log.InfoFormat("[IRC]: {0} logging out", client.Name);
358 } 356 }
359 357
360 if (m_last_new_user == clientName) 358 if (m_last_new_user == client.Name)
361 m_last_new_user = null; 359 m_last_new_user = null;
362 } 360 }
363 } 361 }