aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs193
1 files changed, 98 insertions, 95 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,