diff options
author | Dr Scofield | 2008-10-20 17:31:54 +0000 |
---|---|---|
committer | Dr Scofield | 2008-10-20 17:31:54 +0000 |
commit | 72a388a7b6dfba8f93ffc5c5c45db4c44bb46480 (patch) | |
tree | db9ab06f6820806d8c2b3fc32029383971e955b7 /OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs | |
parent | Mantis #2438 (diff) | |
download | opensim-SC_OLD-72a388a7b6dfba8f93ffc5c5c45db4c44bb46480.zip opensim-SC_OLD-72a388a7b6dfba8f93ffc5c5c45db4c44bb46480.tar.gz opensim-SC_OLD-72a388a7b6dfba8f93ffc5c5c45db4c44bb46480.tar.bz2 opensim-SC_OLD-72a388a7b6dfba8f93ffc5c5c45db4c44bb46480.tar.xz |
cleaning up IRCBridgeModule to allow for configuration from in-world,
chat relaying via private channels, and old IRCBridgeModule
behaviour. also cleaning up IRCBridgeModule's OpenSim.ini
configuration variable names (still supporting "old" variable
names). refactored IRCChatModule into IRCConnector and incorporating
watchdog from IRCBridgeModule into IRCConnector.
enabling ChatModule to be used as a super-class and utilizing it in
ConciergeModule.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs | 198 |
1 files changed, 122 insertions, 76 deletions
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs index 34a604e..5ee07ff 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs | |||
@@ -48,6 +48,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat | |||
48 | 48 | ||
49 | private const int DEBUG_CHANNEL = 2147483647; | 49 | private const int DEBUG_CHANNEL = 2147483647; |
50 | 50 | ||
51 | private bool m_enabled = true; | ||
51 | private int m_saydistance = 30; | 52 | private int m_saydistance = 30; |
52 | private int m_shoutdistance = 100; | 53 | private int m_shoutdistance = 100; |
53 | private int m_whisperdistance = 10; | 54 | private int m_whisperdistance = 10; |
@@ -56,23 +57,15 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat | |||
56 | internal object m_syncInit = new object(); | 57 | internal object m_syncInit = new object(); |
57 | 58 | ||
58 | #region IRegionModule Members | 59 | #region IRegionModule Members |
59 | public void Initialise(Scene scene, IConfigSource config) | 60 | public virtual void Initialise(Scene scene, IConfigSource config) |
60 | { | 61 | { |
61 | lock (m_syncInit) | ||
62 | { | ||
63 | if (!m_scenes.Contains(scene)) | ||
64 | { | ||
65 | m_scenes.Add(scene); | ||
66 | scene.EventManager.OnNewClient += OnNewClient; | ||
67 | scene.EventManager.OnChatFromWorld += OnChatFromWorld; | ||
68 | scene.EventManager.OnChatBroadcast += OnChatBroadcast; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | // wrap this in a try block so that defaults will work if | 62 | // wrap this in a try block so that defaults will work if |
73 | // the config file doesn't specify otherwise. | 63 | // the config file doesn't specify otherwise. |
74 | try | 64 | try |
75 | { | 65 | { |
66 | m_enabled = config.Configs["Chat"].GetBoolean("enabled", m_enabled); | ||
67 | if (!m_enabled) return; | ||
68 | |||
76 | m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance", m_whisperdistance); | 69 | m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance", m_whisperdistance); |
77 | m_saydistance = config.Configs["Chat"].GetInt("say_distance", m_saydistance); | 70 | m_saydistance = config.Configs["Chat"].GetInt("say_distance", m_saydistance); |
78 | m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance", m_shoutdistance); | 71 | m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance", m_shoutdistance); |
@@ -80,23 +73,35 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat | |||
80 | catch (Exception) | 73 | catch (Exception) |
81 | { | 74 | { |
82 | } | 75 | } |
76 | |||
77 | lock (m_syncInit) | ||
78 | { | ||
79 | if (!m_scenes.Contains(scene)) | ||
80 | { | ||
81 | m_scenes.Add(scene); | ||
82 | scene.EventManager.OnNewClient += OnNewClient; | ||
83 | scene.EventManager.OnChatFromWorld += OnChatFromWorld; | ||
84 | scene.EventManager.OnChatBroadcast += OnChatBroadcast; | ||
85 | } | ||
86 | } | ||
87 | |||
83 | m_log.InfoFormat("[CHAT] initialized for {0} w:{1} s:{2} S:{3}", scene.RegionInfo.RegionName, | 88 | m_log.InfoFormat("[CHAT] initialized for {0} w:{1} s:{2} S:{3}", scene.RegionInfo.RegionName, |
84 | m_whisperdistance, m_saydistance, m_shoutdistance); | 89 | m_whisperdistance, m_saydistance, m_shoutdistance); |
85 | } | 90 | } |
86 | public void PostInitialise() | 91 | public virtual void PostInitialise() |
87 | { | 92 | { |
88 | } | 93 | } |
89 | 94 | ||
90 | public void Close() | 95 | public virtual void Close() |
91 | { | 96 | { |
92 | } | 97 | } |
93 | 98 | ||
94 | public string Name | 99 | public virtual string Name |
95 | { | 100 | { |
96 | get { return "ChatModule"; } | 101 | get { return "ChatModule"; } |
97 | } | 102 | } |
98 | 103 | ||
99 | public bool IsSharedModule | 104 | public virtual bool IsSharedModule |
100 | { | 105 | { |
101 | get { return true; } | 106 | get { return true; } |
102 | } | 107 | } |
@@ -104,16 +109,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat | |||
104 | #endregion | 109 | #endregion |
105 | 110 | ||
106 | 111 | ||
107 | public void OnNewClient(IClientAPI client) | 112 | public virtual void OnNewClient(IClientAPI client) |
108 | { | 113 | { |
109 | try | 114 | client.OnChatFromClient += OnChatFromClient; |
110 | { | ||
111 | client.OnChatFromClient += OnChatFromClient; | ||
112 | } | ||
113 | catch (Exception ex) | ||
114 | { | ||
115 | m_log.Error("[CHAT]: NewClient exception trap:" + ex.ToString()); | ||
116 | } | ||
117 | } | 115 | } |
118 | 116 | ||
119 | public virtual void OnChatFromClient(Object sender, OSChatMessage e) | 117 | public virtual void OnChatFromClient(Object sender, OSChatMessage e) |
@@ -132,45 +130,76 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat | |||
132 | return; | 130 | return; |
133 | } | 131 | } |
134 | 132 | ||
135 | string message = e.Message; | 133 | // string message = e.Message; |
136 | if (e.Channel == DEBUG_CHANNEL) e.Type = ChatTypeEnum.DebugChannel; | 134 | // if (e.Channel == DEBUG_CHANNEL) e.Type = ChatTypeEnum.DebugChannel; |
137 | 135 | ||
138 | ScenePresence avatar = scene.GetScenePresence(e.Sender.AgentId); | 136 | // ScenePresence avatar = scene.GetScenePresence(e.Sender.AgentId); |
139 | Vector3 fromPos = avatar.AbsolutePosition; | 137 | // Vector3 fromPos = avatar.AbsolutePosition; |
140 | Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, | 138 | // Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, |
141 | scene.RegionInfo.RegionLocY * Constants.RegionSize, 0); | 139 | // scene.RegionInfo.RegionLocY * Constants.RegionSize, 0); |
142 | string fromName = avatar.Firstname + " " + avatar.Lastname; | 140 | // string fromName = avatar.Firstname + " " + avatar.Lastname; |
143 | UUID fromID = e.Sender.AgentId; | 141 | // UUID fromID = e.Sender.AgentId; |
144 | 142 | ||
145 | DeliverChatToAvatars(fromPos, regionPos, fromID, fromName, e.Type, ChatSourceType.Agent, message); | 143 | // DeliverChatToAvatars(fromPos, regionPos, fromID, fromName, e.Type, ChatSourceType.Agent, message); |
144 | DeliverChatToAvatars(ChatSourceType.Agent, e); | ||
146 | } | 145 | } |
147 | 146 | ||
148 | public void OnChatFromWorld(Object sender, OSChatMessage e) | 147 | public virtual void OnChatFromWorld(Object sender, OSChatMessage e) |
149 | { | 148 | { |
150 | Scene scene = (Scene) e.Scene; | ||
151 | |||
152 | // early return if not on public or debug channel | 149 | // early return if not on public or debug channel |
153 | if (e.Channel != 0 && e.Channel != DEBUG_CHANNEL) return; | 150 | if (e.Channel != 0 && e.Channel != DEBUG_CHANNEL) return; |
154 | 151 | ||
155 | // Filled in since it's easier than rewriting right now. | 152 | // // Filled in since it's easier than rewriting right now. |
156 | Vector3 fromPos = e.Position; | 153 | // Vector3 fromPos = e.Position; |
157 | Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, | 154 | // Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, |
158 | scene.RegionInfo.RegionLocY * Constants.RegionSize, 0); | 155 | // scene.RegionInfo.RegionLocY * Constants.RegionSize, 0); |
159 | 156 | ||
160 | string fromName = e.From; | 157 | // string fromName = e.From; |
161 | string message = e.Message; | 158 | // string message = e.Message; |
162 | UUID fromID = e.SenderUUID; | 159 | // UUID fromID = e.SenderUUID; |
163 | 160 | ||
164 | if (e.Channel == DEBUG_CHANNEL) | 161 | // if (e.Channel == DEBUG_CHANNEL) |
165 | e.Type = ChatTypeEnum.DebugChannel; | 162 | // e.Type = ChatTypeEnum.DebugChannel; |
166 | 163 | ||
167 | DeliverChatToAvatars(fromPos, regionPos, fromID, fromName, e.Type, ChatSourceType.Object, message); | 164 | // DeliverChatToAvatars(fromPos, regionPos, fromID, fromName, e.Type, ChatSourceType.Object, message); |
165 | DeliverChatToAvatars(ChatSourceType.Object, e); | ||
168 | } | 166 | } |
169 | 167 | ||
170 | protected void DeliverChatToAvatars(Vector3 pos, Vector3 regionPos, UUID uuid, string name, | 168 | protected virtual void DeliverChatToAvatars(ChatSourceType sourceType, OSChatMessage c) |
171 | ChatTypeEnum chatType, ChatSourceType sourceType, string message) | ||
172 | { | 169 | { |
173 | // iterate over message | 170 | string fromName = c.From; |
171 | UUID fromID = UUID.Zero; | ||
172 | string message = c.Message; | ||
173 | IScene scene = c.Scene; | ||
174 | Vector3 fromPos = c.Position; | ||
175 | Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, | ||
176 | scene.RegionInfo.RegionLocY * Constants.RegionSize, 0); | ||
177 | |||
178 | if (c.Channel == DEBUG_CHANNEL) c.Type = ChatTypeEnum.DebugChannel; | ||
179 | |||
180 | switch (sourceType) | ||
181 | { | ||
182 | case ChatSourceType.Agent: | ||
183 | if (!(scene is Scene)) | ||
184 | { | ||
185 | m_log.WarnFormat("[CHAT] scene {0} is not a Scene object, cannot obtain scene presence for {1}", | ||
186 | scene.RegionInfo.RegionName, c.Sender.AgentId); | ||
187 | return; | ||
188 | } | ||
189 | ScenePresence avatar = (scene as Scene).GetScenePresence(c.Sender.AgentId); | ||
190 | fromPos = avatar.AbsolutePosition; | ||
191 | fromName = avatar.Firstname + " " + avatar.Lastname; | ||
192 | fromID = c.Sender.AgentId; | ||
193 | |||
194 | break; | ||
195 | |||
196 | case ChatSourceType.Object: | ||
197 | fromID = c.SenderUUID; | ||
198 | |||
199 | break; | ||
200 | } | ||
201 | |||
202 | // TODO: iterate over message | ||
174 | if (message.Length >= 1000) // libomv limit | 203 | if (message.Length >= 1000) // libomv limit |
175 | message = message.Substring(0, 1000); | 204 | message = message.Substring(0, 1000); |
176 | 205 | ||
@@ -178,20 +207,42 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat | |||
178 | { | 207 | { |
179 | s.ForEachScenePresence(delegate(ScenePresence presence) | 208 | s.ForEachScenePresence(delegate(ScenePresence presence) |
180 | { | 209 | { |
181 | TrySendChatMessage(presence, pos, regionPos, uuid, name, | 210 | TrySendChatMessage(presence, fromPos, regionPos, fromID, fromName, |
182 | chatType, message, sourceType); | 211 | c.Type, message, sourceType); |
183 | }); | 212 | }); |
184 | } | 213 | } |
185 | } | 214 | } |
186 | 215 | ||
187 | 216 | // protected virtual void DeliverChatToAvatars(Vector3 pos, Vector3 regionPos, UUID uuid, string name, | |
188 | public void OnChatBroadcast(Object sender, OSChatMessage c) | 217 | // ChatTypeEnum chatType, ChatSourceType sourceType, string message) |
218 | // { | ||
219 | // // iterate over message | ||
220 | // if (message.Length >= 1000) // libomv limit | ||
221 | // message = message.Substring(0, 1000); | ||
222 | |||
223 | // foreach (Scene s in m_scenes) | ||
224 | // { | ||
225 | // s.ForEachScenePresence(delegate(ScenePresence presence) | ||
226 | // { | ||
227 | // TrySendChatMessage(presence, pos, regionPos, uuid, name, | ||
228 | // chatType, message, sourceType); | ||
229 | // }); | ||
230 | // } | ||
231 | // } | ||
232 | |||
233 | |||
234 | public virtual void OnChatBroadcast(Object sender, OSChatMessage c) | ||
189 | { | 235 | { |
190 | // We only want to relay stuff on channel 0 and on the debug channel | 236 | // unless the chat to be broadcast is of type Region, we |
191 | if (c.Channel != 0 && c.Channel != DEBUG_CHANNEL) return; | 237 | // drop it if its channel is neither 0 nor DEBUG_CHANNEL |
238 | if (c.Channel != 0 && c.Channel != DEBUG_CHANNEL && c.Type != ChatTypeEnum.Region) return; | ||
192 | 239 | ||
240 | ChatTypeEnum cType = c.Type; | ||
193 | if (c.Channel == DEBUG_CHANNEL) | 241 | if (c.Channel == DEBUG_CHANNEL) |
194 | c.Type = ChatTypeEnum.DebugChannel; | 242 | cType = ChatTypeEnum.DebugChannel; |
243 | |||
244 | if (cType == ChatTypeEnum.Region) | ||
245 | cType = ChatTypeEnum.Say; | ||
195 | 246 | ||
196 | if (c.Message.Length > 1100) | 247 | if (c.Message.Length > 1100) |
197 | c.Message = c.Message.Substring(0, 1000); | 248 | c.Message = c.Message.Substring(0, 1000); |
@@ -199,6 +250,15 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat | |||
199 | // broadcast chat works by redistributing every incoming chat | 250 | // broadcast chat works by redistributing every incoming chat |
200 | // message to each avatar in the scene. | 251 | // message to each avatar in the scene. |
201 | Vector3 pos = new Vector3(128, 128, 30); | 252 | Vector3 pos = new Vector3(128, 128, 30); |
253 | |||
254 | UUID fromID = UUID.Zero; | ||
255 | ChatSourceType sourceType = ChatSourceType.Object; | ||
256 | if (null != c.Sender) | ||
257 | { | ||
258 | fromID = c.Sender.AgentId; | ||
259 | sourceType = ChatSourceType.Agent; | ||
260 | } | ||
261 | |||
202 | ((Scene)c.Scene).ForEachScenePresence( | 262 | ((Scene)c.Scene).ForEachScenePresence( |
203 | delegate(ScenePresence presence) | 263 | delegate(ScenePresence presence) |
204 | { | 264 | { |
@@ -214,29 +274,15 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat | |||
214 | (((SceneObjectPart)c.SenderObject).OwnerID != client.AgentId)) | 274 | (((SceneObjectPart)c.SenderObject).OwnerID != client.AgentId)) |
215 | return; | 275 | return; |
216 | 276 | ||
217 | if (null == c.SenderObject) | 277 | client.SendChatMessage(c.Message, (byte)cType, pos, c.From, fromID, |
218 | { | 278 | (byte)sourceType, (byte)ChatAudibleLevel.Fully); |
219 | // chat from agent (avatar) | ||
220 | client.SendChatMessage(c.Message, (byte)c.Type, | ||
221 | pos, c.From, UUID.Zero, | ||
222 | (byte)ChatSourceType.Agent, | ||
223 | (byte)ChatAudibleLevel.Fully); | ||
224 | } | ||
225 | else | ||
226 | { | ||
227 | // chat from object | ||
228 | client.SendChatMessage(c.Message, (byte)c.Type, | ||
229 | pos, c.From, UUID.Zero, | ||
230 | (byte)ChatSourceType.Object, | ||
231 | (byte)ChatAudibleLevel.Fully); | ||
232 | } | ||
233 | }); | 279 | }); |
234 | } | 280 | } |
235 | 281 | ||
236 | 282 | ||
237 | private void TrySendChatMessage(ScenePresence presence, Vector3 fromPos, Vector3 regionPos, | 283 | protected virtual void TrySendChatMessage(ScenePresence presence, Vector3 fromPos, Vector3 regionPos, |
238 | UUID fromAgentID, string fromName, ChatTypeEnum type, | 284 | UUID fromAgentID, string fromName, ChatTypeEnum type, |
239 | string message, ChatSourceType src) | 285 | string message, ChatSourceType src) |
240 | { | 286 | { |
241 | // don't send stuff to child agents | 287 | // don't send stuff to child agents |
242 | if (presence.IsChildAgent) return; | 288 | if (presence.IsChildAgent) return; |