aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs')
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs98
1 files changed, 61 insertions, 37 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs b/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs
index 53b103e..5505001 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Chat/RegionState.cs
@@ -41,49 +41,73 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
41 41
42 internal class RegionState 42 internal class RegionState
43 { 43 {
44
45 private static readonly ILog m_log = 44 private static readonly ILog m_log =
46 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 45 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 46
47 // This computation is not the real region center if the region is larger than 256.
48 // This computation isn't fixed because there is not a handle back to the region.
48 private static readonly OpenMetaverse.Vector3 CenterOfRegion = new OpenMetaverse.Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20); 49 private static readonly OpenMetaverse.Vector3 CenterOfRegion = new OpenMetaverse.Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20);
49 private const int DEBUG_CHANNEL = 2147483647; 50 private const int DEBUG_CHANNEL = 2147483647;
50 51
51 private static int _idk_ = 0; 52 private static int _idk_ = 0;
52 53
53 // Runtime variables; these values are assigned when the 54 // Runtime variables; these values are assigned when the
54 // IrcState is created and remain constant thereafter. 55 // IrcState is created and remain constant thereafter.
55 56
56 internal string Region = String.Empty; 57 internal string Region = String.Empty;
57 internal string Host = String.Empty; 58 internal string Host = String.Empty;
58 internal string LocX = String.Empty; 59 internal string LocX = String.Empty;
59 internal string LocY = String.Empty; 60 internal string LocY = String.Empty;
60 internal string IDK = String.Empty; 61 internal string IDK = String.Empty;
61 62
62 // System values - used only be the IRC classes themselves 63 // System values - used only be the IRC classes themselves
63 64
64 internal ChannelState cs = null; // associated IRC configuration 65 internal ChannelState cs = null; // associated IRC configuration
65 internal Scene scene = null; // associated scene 66 internal Scene scene = null; // associated scene
66 internal IConfig config = null; // configuration file reference 67 internal IConfig config = null; // configuration file reference
67 internal bool enabled = true; 68 internal bool enabled = true;
68 69
70 //AgentAlert
71 internal bool showAlert = false;
72 internal string alertMessage = String.Empty;
73 internal IDialogModule dialogModule = null;
74
69 // This list is used to keep track of who is here, and by 75 // This list is used to keep track of who is here, and by
70 // implication, who is not. 76 // implication, who is not.
71 77
72 internal List<IClientAPI> clients = new List<IClientAPI>(); 78 internal List<IClientAPI> clients = new List<IClientAPI>();
73 79
74 // Setup runtime variable values 80 // Setup runtime variable values
75 81
76 public RegionState(Scene p_scene, IConfig p_config) 82 public RegionState(Scene p_scene, IConfig p_config)
77 { 83 {
78 84 scene = p_scene;
79 scene = p_scene;
80 config = p_config; 85 config = p_config;
81 86
82 Region = scene.RegionInfo.RegionName; 87 Region = scene.RegionInfo.RegionName;
83 Host = scene.RegionInfo.ExternalHostName; 88 Host = scene.RegionInfo.ExternalHostName;
84 LocX = Convert.ToString(scene.RegionInfo.RegionLocX); 89 LocX = Convert.ToString(scene.RegionInfo.RegionLocX);
85 LocY = Convert.ToString(scene.RegionInfo.RegionLocY); 90 LocY = Convert.ToString(scene.RegionInfo.RegionLocY);
86 IDK = Convert.ToString(_idk_++); 91 IDK = Convert.ToString(_idk_++);
92
93 showAlert = config.GetBoolean("alert_show", false);
94 string alertServerInfo = String.Empty;
95
96 if (showAlert)
97 {
98 bool showAlertServerInfo = config.GetBoolean("alert_show_serverinfo", true);
99
100 if (showAlertServerInfo)
101 alertServerInfo = String.Format("\nServer: {0}\nPort: {1}\nChannel: {2}\n\n",
102 config.GetString("server", ""), config.GetString("port", ""), config.GetString("channel", ""));
103
104 string alertPreMessage = config.GetString("alert_msg_pre", "This region is linked to Irc.");
105 string alertPostMessage = config.GetString("alert_msg_post", "Everything you say in public chat can be listened.");
106
107 alertMessage = String.Format("{0}\n{1}{2}", alertPreMessage, alertServerInfo, alertPostMessage);
108
109 dialogModule = scene.RequestModuleInterface<IDialogModule>();
110 }
87 111
88 // OpenChannel conditionally establishes a connection to the 112 // OpenChannel conditionally establishes a connection to the
89 // IRC server. The request will either succeed, or it will 113 // IRC server. The request will either succeed, or it will
@@ -93,9 +117,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
93 117
94 // Connect channel to world events 118 // Connect channel to world events
95 119
96 scene.EventManager.OnChatFromWorld += OnSimChat; 120 scene.EventManager.OnChatFromWorld += OnSimChat;
97 scene.EventManager.OnChatFromClient += OnSimChat; 121 scene.EventManager.OnChatFromClient += OnSimChat;
98 scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; 122 scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
99 scene.EventManager.OnMakeChildAgent += OnMakeChildAgent; 123 scene.EventManager.OnMakeChildAgent += OnMakeChildAgent;
100 124
101 m_log.InfoFormat("[IRC-Region {0}] Initialization complete", Region); 125 m_log.InfoFormat("[IRC-Region {0}] Initialization complete", Region);
@@ -106,8 +130,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
106 130
107 ~RegionState() 131 ~RegionState()
108 { 132 {
109 if (cs != null) 133 if (cs != null)
110 cs.RemoveRegion(this); 134 cs.RemoveRegion(this);
111 } 135 }
112 136
113 // Called by PostInitialize after all regions have been created 137 // Called by PostInitialize after all regions have been created
@@ -138,7 +162,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
138 { 162 {
139 if (clients.Contains(client)) 163 if (clients.Contains(client))
140 { 164 {
141 if (enabled && (cs.irc.Enabled) && (cs.irc.Connected) && (cs.ClientReporting)) 165 if (enabled && (cs.irc.Enabled) && (cs.irc.Connected) && (cs.ClientReporting))
142 { 166 {
143 m_log.InfoFormat("[IRC-Region {0}]: {1} has left", Region, client.Name); 167 m_log.InfoFormat("[IRC-Region {0}]: {1} has left", Region, client.Name);
144 //Check if this person is excluded from IRC 168 //Check if this person is excluded from IRC
@@ -147,7 +171,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
147 cs.irc.PrivMsg(cs.NoticeMessageFormat, cs.irc.Nick, Region, String.Format("{0} has left", client.Name)); 171 cs.irc.PrivMsg(cs.NoticeMessageFormat, cs.irc.Nick, Region, String.Format("{0} has left", client.Name));
148 } 172 }
149 } 173 }
150 client.OnLogout -= OnClientLoggedOut; 174 client.OnLogout -= OnClientLoggedOut;
151 client.OnConnectionClosed -= OnClientLoggedOut; 175 client.OnConnectionClosed -= OnClientLoggedOut;
152 clients.Remove(client); 176 clients.Remove(client);
153 } 177 }
@@ -171,13 +195,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
171 { 195 {
172 if (clients.Contains(client)) 196 if (clients.Contains(client))
173 { 197 {
174 if (enabled && (cs.irc.Enabled) && (cs.irc.Connected) && (cs.ClientReporting)) 198 if (enabled && (cs.irc.Enabled) && (cs.irc.Connected) && (cs.ClientReporting))
175 { 199 {
176 string clientName = String.Format("{0} {1}", presence.Firstname, presence.Lastname); 200 string clientName = String.Format("{0} {1}", presence.Firstname, presence.Lastname);
177 m_log.DebugFormat("[IRC-Region {0}] {1} has left", Region, clientName); 201 m_log.DebugFormat("[IRC-Region {0}] {1} has left", Region, clientName);
178 cs.irc.PrivMsg(cs.NoticeMessageFormat, cs.irc.Nick, Region, String.Format("{0} has left", clientName)); 202 cs.irc.PrivMsg(cs.NoticeMessageFormat, cs.irc.Nick, Region, String.Format("{0} has left", clientName));
179 } 203 }
180 client.OnLogout -= OnClientLoggedOut; 204 client.OnLogout -= OnClientLoggedOut;
181 client.OnConnectionClosed -= OnClientLoggedOut; 205 client.OnConnectionClosed -= OnClientLoggedOut;
182 clients.Remove(client); 206 clients.Remove(client);
183 } 207 }
@@ -195,14 +219,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
195 219
196 private void OnMakeRootAgent(ScenePresence presence) 220 private void OnMakeRootAgent(ScenePresence presence)
197 { 221 {
198
199 IClientAPI client = presence.ControllingClient; 222 IClientAPI client = presence.ControllingClient;
200 223
201 try 224 try
202 { 225 {
203 if (!clients.Contains(client)) 226 if (!clients.Contains(client))
204 { 227 {
205 client.OnLogout += OnClientLoggedOut; 228 client.OnLogout += OnClientLoggedOut;
206 client.OnConnectionClosed += OnClientLoggedOut; 229 client.OnConnectionClosed += OnClientLoggedOut;
207 clients.Add(client); 230 clients.Add(client);
208 if (enabled && (cs.irc.Enabled) && (cs.irc.Connected) && (cs.ClientReporting)) 231 if (enabled && (cs.irc.Enabled) && (cs.irc.Connected) && (cs.ClientReporting))
@@ -216,17 +239,18 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
216 } 239 }
217 } 240 }
218 } 241 }
242
243 if (dialogModule != null && showAlert)
244 dialogModule.SendAlertToUser(client, alertMessage, true);
219 } 245 }
220 catch (Exception ex) 246 catch (Exception ex)
221 { 247 {
222 m_log.ErrorFormat("[IRC-Region {0}]: MakeRootAgent exception: {1}", Region, ex.Message); 248 m_log.ErrorFormat("[IRC-Region {0}]: MakeRootAgent exception: {1}", Region, ex.Message);
223 m_log.Debug(ex); 249 m_log.Debug(ex);
224 } 250 }
225
226 } 251 }
227 252
228 // This handler detects chat events int he virtual world. 253 // This handler detects chat events int he virtual world.
229
230 public void OnSimChat(Object sender, OSChatMessage msg) 254 public void OnSimChat(Object sender, OSChatMessage msg)
231 { 255 {
232 256
@@ -317,14 +341,14 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
317 // that evident. 341 // that evident.
318 342
319 default: 343 default:
320 m_log.DebugFormat("[IRC-Region {0}] Forwarding unrecognized command to IRC : {1}", 344 m_log.DebugFormat("[IRC-Region {0}] Forwarding unrecognized command to IRC : {1}",
321 Region, msg.Message); 345 Region, msg.Message);
322 cs.irc.Send(msg.Message); 346 cs.irc.Send(msg.Message);
323 break; 347 break;
324 } 348 }
325 } 349 }
326 catch (Exception ex) 350 catch (Exception ex)
327 { 351 {
328 m_log.WarnFormat("[IRC-Region {0}] error processing in-world command channel input: {1}", 352 m_log.WarnFormat("[IRC-Region {0}] error processing in-world command channel input: {1}",
329 Region, ex.Message); 353 Region, ex.Message);
330 m_log.Debug(ex); 354 m_log.Debug(ex);
@@ -366,7 +390,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
366 390
367 m_log.DebugFormat("[IRC-Region {0}] heard on channel {1} : {2}", Region, msg.Channel, msg.Message); 391 m_log.DebugFormat("[IRC-Region {0}] heard on channel {1} : {2}", Region, msg.Channel, msg.Message);
368 392
369 if (null != avatar && cs.RelayChat && (msg.Channel == 0 || msg.Channel == DEBUG_CHANNEL)) 393 if (null != avatar && cs.RelayChat && (msg.Channel == 0 || msg.Channel == DEBUG_CHANNEL))
370 { 394 {
371 string txt = msg.Message; 395 string txt = msg.Message;
372 if (txt.StartsWith("/me ")) 396 if (txt.StartsWith("/me "))
@@ -376,13 +400,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
376 return; 400 return;
377 } 401 }
378 402
379 if (null == avatar && cs.RelayPrivateChannels && null != cs.AccessPassword && 403 if (null == avatar && cs.RelayPrivateChannels && null != cs.AccessPassword &&
380 msg.Channel == cs.RelayChannelOut) 404 msg.Channel == cs.RelayChannelOut)
381 { 405 {
382 Match m = cs.AccessPasswordRegex.Match(msg.Message); 406 Match m = cs.AccessPasswordRegex.Match(msg.Message);
383 if (null != m) 407 if (null != m)
384 { 408 {
385 m_log.DebugFormat("[IRC] relaying message from {0}: {1}", m.Groups["avatar"].ToString(), 409 m_log.DebugFormat("[IRC] relaying message from {0}: {1}", m.Groups["avatar"].ToString(),
386 m.Groups["message"].ToString()); 410 m.Groups["message"].ToString());
387 cs.irc.PrivMsg(cs.PrivateMessageFormat, m.Groups["avatar"].ToString(), 411 cs.irc.PrivMsg(cs.PrivateMessageFormat, m.Groups["avatar"].ToString(),
388 scene.RegionInfo.RegionName, m.Groups["message"].ToString()); 412 scene.RegionInfo.RegionName, m.Groups["message"].ToString());