diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/Chat')
4 files changed, 315 insertions, 287 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/Chat/ChannelState.cs b/OpenSim/Region/OptionalModules/Avatar/Chat/ChannelState.cs index 66265d8..b5d9fda 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Chat/ChannelState.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Chat/ChannelState.cs | |||
@@ -55,42 +55,42 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
55 | // These are the IRC Connector configurable parameters with hard-wired | 55 | // These are the IRC Connector configurable parameters with hard-wired |
56 | // default values (retained for compatability). | 56 | // default values (retained for compatability). |
57 | 57 | ||
58 | internal string Server = null; | 58 | internal string Server = null; |
59 | internal string Password = null; | 59 | internal string Password = null; |
60 | internal string IrcChannel = null; | 60 | internal string IrcChannel = null; |
61 | internal string BaseNickname = "OSimBot"; | 61 | internal string BaseNickname = "OSimBot"; |
62 | internal uint Port = 6667; | 62 | internal uint Port = 6667; |
63 | internal string User = null; | 63 | internal string User = null; |
64 | 64 | ||
65 | internal bool ClientReporting = true; | 65 | internal bool ClientReporting = true; |
66 | internal bool RelayChat = true; | 66 | internal bool RelayChat = true; |
67 | internal bool RelayPrivateChannels = false; | 67 | internal bool RelayPrivateChannels = false; |
68 | internal int RelayChannel = 1; | 68 | internal int RelayChannel = 1; |
69 | internal List<int> ValidInWorldChannels = new List<int>(); | 69 | internal List<int> ValidInWorldChannels = new List<int>(); |
70 | 70 | ||
71 | // Connector agnostic parameters. These values are NOT shared with the | 71 | // Connector agnostic parameters. These values are NOT shared with the |
72 | // connector and do not differentiate at an IRC level | 72 | // connector and do not differentiate at an IRC level |
73 | 73 | ||
74 | internal string PrivateMessageFormat = "PRIVMSG {0} :<{2}> {1} {3}"; | 74 | internal string PrivateMessageFormat = "PRIVMSG {0} :<{2}> {1} {3}"; |
75 | internal string NoticeMessageFormat = "PRIVMSG {0} :<{2}> {3}"; | 75 | internal string NoticeMessageFormat = "PRIVMSG {0} :<{2}> {3}"; |
76 | internal int RelayChannelOut = -1; | 76 | internal int RelayChannelOut = -1; |
77 | internal bool RandomizeNickname = true; | 77 | internal bool RandomizeNickname = true; |
78 | internal bool CommandsEnabled = false; | 78 | internal bool CommandsEnabled = false; |
79 | internal int CommandChannel = -1; | 79 | internal int CommandChannel = -1; |
80 | internal int ConnectDelay = 10; | 80 | internal int ConnectDelay = 10; |
81 | internal int PingDelay = 15; | 81 | internal int PingDelay = 15; |
82 | internal string DefaultZone = "Sim"; | 82 | internal string DefaultZone = "Sim"; |
83 | 83 | ||
84 | internal string _accessPassword = String.Empty; | 84 | internal string _accessPassword = String.Empty; |
85 | internal Regex AccessPasswordRegex = null; | 85 | internal Regex AccessPasswordRegex = null; |
86 | internal List<string> ExcludeList = new List<string>(); | 86 | internal List<string> ExcludeList = new List<string>(); |
87 | internal string AccessPassword | 87 | internal string AccessPassword |
88 | { | 88 | { |
89 | get { return _accessPassword; } | 89 | get { return _accessPassword; } |
90 | set | 90 | set |
91 | { | 91 | { |
92 | _accessPassword = value; | 92 | _accessPassword = value; |
93 | AccessPasswordRegex = new Regex(String.Format(@"^{0},\s*(?<avatar>[^,]+),\s*(?<message>.+)$", _accessPassword), | 93 | AccessPasswordRegex = new Regex(String.Format(@"^{0},\s*(?<avatar>[^,]+),\s*(?<message>.+)$", _accessPassword), |
94 | RegexOptions.Compiled); | 94 | RegexOptions.Compiled); |
95 | } | 95 | } |
96 | } | 96 | } |
@@ -99,9 +99,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
99 | 99 | ||
100 | // IRC connector reference | 100 | // IRC connector reference |
101 | 101 | ||
102 | internal IRCConnector irc = null; | 102 | internal IRCConnector irc = null; |
103 | 103 | ||
104 | internal int idn = _idk_++; | 104 | internal int idn = _idk_++; |
105 | 105 | ||
106 | // List of regions dependent upon this connection | 106 | // List of regions dependent upon this connection |
107 | 107 | ||
@@ -119,29 +119,29 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
119 | 119 | ||
120 | internal ChannelState(ChannelState model) | 120 | internal ChannelState(ChannelState model) |
121 | { | 121 | { |
122 | Server = model.Server; | 122 | Server = model.Server; |
123 | Password = model.Password; | 123 | Password = model.Password; |
124 | IrcChannel = model.IrcChannel; | 124 | IrcChannel = model.IrcChannel; |
125 | Port = model.Port; | 125 | Port = model.Port; |
126 | BaseNickname = model.BaseNickname; | 126 | BaseNickname = model.BaseNickname; |
127 | RandomizeNickname = model.RandomizeNickname; | 127 | RandomizeNickname = model.RandomizeNickname; |
128 | User = model.User; | 128 | User = model.User; |
129 | CommandsEnabled = model.CommandsEnabled; | 129 | CommandsEnabled = model.CommandsEnabled; |
130 | CommandChannel = model.CommandChannel; | 130 | CommandChannel = model.CommandChannel; |
131 | RelayChat = model.RelayChat; | 131 | RelayChat = model.RelayChat; |
132 | RelayPrivateChannels = model.RelayPrivateChannels; | 132 | RelayPrivateChannels = model.RelayPrivateChannels; |
133 | RelayChannelOut = model.RelayChannelOut; | 133 | RelayChannelOut = model.RelayChannelOut; |
134 | RelayChannel = model.RelayChannel; | 134 | RelayChannel = model.RelayChannel; |
135 | ValidInWorldChannels = model.ValidInWorldChannels; | 135 | ValidInWorldChannels = model.ValidInWorldChannels; |
136 | PrivateMessageFormat = model.PrivateMessageFormat; | 136 | PrivateMessageFormat = model.PrivateMessageFormat; |
137 | NoticeMessageFormat = model.NoticeMessageFormat; | 137 | NoticeMessageFormat = model.NoticeMessageFormat; |
138 | ClientReporting = model.ClientReporting; | 138 | ClientReporting = model.ClientReporting; |
139 | AccessPassword = model.AccessPassword; | 139 | AccessPassword = model.AccessPassword; |
140 | DefaultZone = model.DefaultZone; | 140 | DefaultZone = model.DefaultZone; |
141 | ConnectDelay = model.ConnectDelay; | 141 | ConnectDelay = model.ConnectDelay; |
142 | PingDelay = model.PingDelay; | 142 | PingDelay = model.PingDelay; |
143 | } | 143 | } |
144 | 144 | ||
145 | // Read the configuration file, performing variable substitution and any | 145 | // Read the configuration file, performing variable substitution and any |
146 | // necessary aliasing. See accompanying documentation for how this works. | 146 | // necessary aliasing. See accompanying documentation for how this works. |
147 | // If you don't need variables, then this works exactly as before. | 147 | // If you don't need variables, then this works exactly as before. |
@@ -160,54 +160,54 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
160 | 160 | ||
161 | m_log.DebugFormat("[IRC-Channel-{0}] Initial request by Region {1} to connect to IRC", cs.idn, rs.Region); | 161 | m_log.DebugFormat("[IRC-Channel-{0}] Initial request by Region {1} to connect to IRC", cs.idn, rs.Region); |
162 | 162 | ||
163 | cs.Server = Substitute(rs, config.GetString("server", null)); | 163 | cs.Server = Substitute(rs, config.GetString("server", null)); |
164 | m_log.DebugFormat("[IRC-Channel-{0}] Server : <{1}>", cs.idn, cs.Server); | 164 | m_log.DebugFormat("[IRC-Channel-{0}] Server : <{1}>", cs.idn, cs.Server); |
165 | cs.Password = Substitute(rs, config.GetString("password", null)); | 165 | cs.Password = Substitute(rs, config.GetString("password", null)); |
166 | // probably not a good idea to put a password in the log file | 166 | // probably not a good idea to put a password in the log file |
167 | cs.User = Substitute(rs, config.GetString("user", null)); | 167 | cs.User = Substitute(rs, config.GetString("user", null)); |
168 | cs.IrcChannel = Substitute(rs, config.GetString("channel", null)); | 168 | cs.IrcChannel = Substitute(rs, config.GetString("channel", null)); |
169 | m_log.DebugFormat("[IRC-Channel-{0}] IrcChannel : <{1}>", cs.idn, cs.IrcChannel); | 169 | m_log.DebugFormat("[IRC-Channel-{0}] IrcChannel : <{1}>", cs.idn, cs.IrcChannel); |
170 | cs.Port = Convert.ToUInt32(Substitute(rs, config.GetString("port", Convert.ToString(cs.Port)))); | 170 | cs.Port = Convert.ToUInt32(Substitute(rs, config.GetString("port", Convert.ToString(cs.Port)))); |
171 | m_log.DebugFormat("[IRC-Channel-{0}] Port : <{1}>", cs.idn, cs.Port); | 171 | m_log.DebugFormat("[IRC-Channel-{0}] Port : <{1}>", cs.idn, cs.Port); |
172 | cs.BaseNickname = Substitute(rs, config.GetString("nick", cs.BaseNickname)); | 172 | cs.BaseNickname = Substitute(rs, config.GetString("nick", cs.BaseNickname)); |
173 | m_log.DebugFormat("[IRC-Channel-{0}] BaseNickname : <{1}>", cs.idn, cs.BaseNickname); | 173 | m_log.DebugFormat("[IRC-Channel-{0}] BaseNickname : <{1}>", cs.idn, cs.BaseNickname); |
174 | cs.RandomizeNickname = Convert.ToBoolean(Substitute(rs, config.GetString("randomize_nick", Convert.ToString(cs.RandomizeNickname)))); | 174 | cs.RandomizeNickname = Convert.ToBoolean(Substitute(rs, config.GetString("randomize_nick", Convert.ToString(cs.RandomizeNickname)))); |
175 | m_log.DebugFormat("[IRC-Channel-{0}] RandomizeNickname : <{1}>", cs.idn, cs.RandomizeNickname); | 175 | m_log.DebugFormat("[IRC-Channel-{0}] RandomizeNickname : <{1}>", cs.idn, cs.RandomizeNickname); |
176 | cs.RandomizeNickname = Convert.ToBoolean(Substitute(rs, config.GetString("nicknum", Convert.ToString(cs.RandomizeNickname)))); | 176 | cs.RandomizeNickname = Convert.ToBoolean(Substitute(rs, config.GetString("nicknum", Convert.ToString(cs.RandomizeNickname)))); |
177 | m_log.DebugFormat("[IRC-Channel-{0}] RandomizeNickname : <{1}>", cs.idn, cs.RandomizeNickname); | 177 | m_log.DebugFormat("[IRC-Channel-{0}] RandomizeNickname : <{1}>", cs.idn, cs.RandomizeNickname); |
178 | cs.User = Substitute(rs, config.GetString("username", cs.User)); | 178 | cs.User = Substitute(rs, config.GetString("username", cs.User)); |
179 | m_log.DebugFormat("[IRC-Channel-{0}] User : <{1}>", cs.idn, cs.User); | 179 | m_log.DebugFormat("[IRC-Channel-{0}] User : <{1}>", cs.idn, cs.User); |
180 | cs.CommandsEnabled = Convert.ToBoolean(Substitute(rs, config.GetString("commands_enabled", Convert.ToString(cs.CommandsEnabled)))); | 180 | cs.CommandsEnabled = Convert.ToBoolean(Substitute(rs, config.GetString("commands_enabled", Convert.ToString(cs.CommandsEnabled)))); |
181 | m_log.DebugFormat("[IRC-Channel-{0}] CommandsEnabled : <{1}>", cs.idn, cs.CommandsEnabled); | 181 | m_log.DebugFormat("[IRC-Channel-{0}] CommandsEnabled : <{1}>", cs.idn, cs.CommandsEnabled); |
182 | cs.CommandChannel = Convert.ToInt32(Substitute(rs, config.GetString("commandchannel", Convert.ToString(cs.CommandChannel)))); | 182 | cs.CommandChannel = Convert.ToInt32(Substitute(rs, config.GetString("commandchannel", Convert.ToString(cs.CommandChannel)))); |
183 | m_log.DebugFormat("[IRC-Channel-{0}] CommandChannel : <{1}>", cs.idn, cs.CommandChannel); | 183 | m_log.DebugFormat("[IRC-Channel-{0}] CommandChannel : <{1}>", cs.idn, cs.CommandChannel); |
184 | cs.CommandChannel = Convert.ToInt32(Substitute(rs, config.GetString("command_channel", Convert.ToString(cs.CommandChannel)))); | 184 | cs.CommandChannel = Convert.ToInt32(Substitute(rs, config.GetString("command_channel", Convert.ToString(cs.CommandChannel)))); |
185 | m_log.DebugFormat("[IRC-Channel-{0}] CommandChannel : <{1}>", cs.idn, cs.CommandChannel); | 185 | m_log.DebugFormat("[IRC-Channel-{0}] CommandChannel : <{1}>", cs.idn, cs.CommandChannel); |
186 | cs.RelayChat = Convert.ToBoolean(Substitute(rs, config.GetString("relay_chat", Convert.ToString(cs.RelayChat)))); | 186 | cs.RelayChat = Convert.ToBoolean(Substitute(rs, config.GetString("relay_chat", Convert.ToString(cs.RelayChat)))); |
187 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChat : <{1}>", cs.idn, cs.RelayChat); | 187 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChat : <{1}>", cs.idn, cs.RelayChat); |
188 | cs.RelayPrivateChannels = Convert.ToBoolean(Substitute(rs, config.GetString("relay_private_channels", Convert.ToString(cs.RelayPrivateChannels)))); | 188 | cs.RelayPrivateChannels = Convert.ToBoolean(Substitute(rs, config.GetString("relay_private_channels", Convert.ToString(cs.RelayPrivateChannels)))); |
189 | m_log.DebugFormat("[IRC-Channel-{0}] RelayPrivateChannels : <{1}>", cs.idn, cs.RelayPrivateChannels); | 189 | m_log.DebugFormat("[IRC-Channel-{0}] RelayPrivateChannels : <{1}>", cs.idn, cs.RelayPrivateChannels); |
190 | cs.RelayPrivateChannels = Convert.ToBoolean(Substitute(rs, config.GetString("useworldcomm", Convert.ToString(cs.RelayPrivateChannels)))); | 190 | cs.RelayPrivateChannels = Convert.ToBoolean(Substitute(rs, config.GetString("useworldcomm", Convert.ToString(cs.RelayPrivateChannels)))); |
191 | m_log.DebugFormat("[IRC-Channel-{0}] RelayPrivateChannels : <{1}>", cs.idn, cs.RelayPrivateChannels); | 191 | m_log.DebugFormat("[IRC-Channel-{0}] RelayPrivateChannels : <{1}>", cs.idn, cs.RelayPrivateChannels); |
192 | cs.RelayChannelOut = Convert.ToInt32(Substitute(rs, config.GetString("relay_private_channel_out", Convert.ToString(cs.RelayChannelOut)))); | 192 | cs.RelayChannelOut = Convert.ToInt32(Substitute(rs, config.GetString("relay_private_channel_out", Convert.ToString(cs.RelayChannelOut)))); |
193 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChannelOut : <{1}>", cs.idn, cs.RelayChannelOut); | 193 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChannelOut : <{1}>", cs.idn, cs.RelayChannelOut); |
194 | cs.RelayChannel = Convert.ToInt32(Substitute(rs, config.GetString("relay_private_channel_in", Convert.ToString(cs.RelayChannel)))); | 194 | cs.RelayChannel = Convert.ToInt32(Substitute(rs, config.GetString("relay_private_channel_in", Convert.ToString(cs.RelayChannel)))); |
195 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChannel : <{1}>", cs.idn, cs.RelayChannel); | 195 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChannel : <{1}>", cs.idn, cs.RelayChannel); |
196 | cs.RelayChannel = Convert.ToInt32(Substitute(rs, config.GetString("inchannel", Convert.ToString(cs.RelayChannel)))); | 196 | cs.RelayChannel = Convert.ToInt32(Substitute(rs, config.GetString("inchannel", Convert.ToString(cs.RelayChannel)))); |
197 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChannel : <{1}>", cs.idn, cs.RelayChannel); | 197 | m_log.DebugFormat("[IRC-Channel-{0}] RelayChannel : <{1}>", cs.idn, cs.RelayChannel); |
198 | cs.PrivateMessageFormat = Substitute(rs, config.GetString("msgformat", cs.PrivateMessageFormat)); | 198 | cs.PrivateMessageFormat = Substitute(rs, config.GetString("msgformat", cs.PrivateMessageFormat)); |
199 | m_log.DebugFormat("[IRC-Channel-{0}] PrivateMessageFormat : <{1}>", cs.idn, cs.PrivateMessageFormat); | 199 | m_log.DebugFormat("[IRC-Channel-{0}] PrivateMessageFormat : <{1}>", cs.idn, cs.PrivateMessageFormat); |
200 | cs.NoticeMessageFormat = Substitute(rs, config.GetString("noticeformat", cs.NoticeMessageFormat)); | 200 | cs.NoticeMessageFormat = Substitute(rs, config.GetString("noticeformat", cs.NoticeMessageFormat)); |
201 | m_log.DebugFormat("[IRC-Channel-{0}] NoticeMessageFormat : <{1}>", cs.idn, cs.NoticeMessageFormat); | 201 | m_log.DebugFormat("[IRC-Channel-{0}] NoticeMessageFormat : <{1}>", cs.idn, cs.NoticeMessageFormat); |
202 | cs.ClientReporting = Convert.ToInt32(Substitute(rs, config.GetString("verbosity", cs.ClientReporting?"1":"0"))) > 0; | 202 | cs.ClientReporting = Convert.ToInt32(Substitute(rs, config.GetString("verbosity", cs.ClientReporting ? "1" : "0"))) > 0; |
203 | m_log.DebugFormat("[IRC-Channel-{0}] ClientReporting : <{1}>", cs.idn, cs.ClientReporting); | 203 | m_log.DebugFormat("[IRC-Channel-{0}] ClientReporting : <{1}>", cs.idn, cs.ClientReporting); |
204 | cs.ClientReporting = Convert.ToBoolean(Substitute(rs, config.GetString("report_clients", Convert.ToString(cs.ClientReporting)))); | 204 | cs.ClientReporting = Convert.ToBoolean(Substitute(rs, config.GetString("report_clients", Convert.ToString(cs.ClientReporting)))); |
205 | m_log.DebugFormat("[IRC-Channel-{0}] ClientReporting : <{1}>", cs.idn, cs.ClientReporting); | 205 | m_log.DebugFormat("[IRC-Channel-{0}] ClientReporting : <{1}>", cs.idn, cs.ClientReporting); |
206 | cs.DefaultZone = Substitute(rs, config.GetString("fallback_region", cs.DefaultZone)); | 206 | cs.DefaultZone = Substitute(rs, config.GetString("fallback_region", cs.DefaultZone)); |
207 | m_log.DebugFormat("[IRC-Channel-{0}] DefaultZone : <{1}>", cs.idn, cs.DefaultZone); | 207 | m_log.DebugFormat("[IRC-Channel-{0}] DefaultZone : <{1}>", cs.idn, cs.DefaultZone); |
208 | cs.ConnectDelay = Convert.ToInt32(Substitute(rs, config.GetString("connect_delay", Convert.ToString(cs.ConnectDelay)))); | 208 | cs.ConnectDelay = Convert.ToInt32(Substitute(rs, config.GetString("connect_delay", Convert.ToString(cs.ConnectDelay)))); |
209 | m_log.DebugFormat("[IRC-Channel-{0}] ConnectDelay : <{1}>", cs.idn, cs.ConnectDelay); | 209 | m_log.DebugFormat("[IRC-Channel-{0}] ConnectDelay : <{1}>", cs.idn, cs.ConnectDelay); |
210 | cs.PingDelay = Convert.ToInt32(Substitute(rs, config.GetString("ping_delay", Convert.ToString(cs.PingDelay)))); | 210 | cs.PingDelay = Convert.ToInt32(Substitute(rs, config.GetString("ping_delay", Convert.ToString(cs.PingDelay)))); |
211 | m_log.DebugFormat("[IRC-Channel-{0}] PingDelay : <{1}>", cs.idn, cs.PingDelay); | 211 | m_log.DebugFormat("[IRC-Channel-{0}] PingDelay : <{1}>", cs.idn, cs.PingDelay); |
212 | cs.AccessPassword = Substitute(rs, config.GetString("access_password", cs.AccessPassword)); | 212 | cs.AccessPassword = Substitute(rs, config.GetString("access_password", cs.AccessPassword)); |
213 | m_log.DebugFormat("[IRC-Channel-{0}] AccessPassword : <{1}>", cs.idn, cs.AccessPassword); | 213 | m_log.DebugFormat("[IRC-Channel-{0}] AccessPassword : <{1}>", cs.idn, cs.AccessPassword); |
@@ -217,7 +217,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
217 | { | 217 | { |
218 | cs.ExcludeList.Add(name.Trim().ToLower()); | 218 | cs.ExcludeList.Add(name.Trim().ToLower()); |
219 | } | 219 | } |
220 | 220 | ||
221 | // Fail if fundamental information is still missing | 221 | // Fail if fundamental information is still missing |
222 | 222 | ||
223 | if (cs.Server == null) | 223 | if (cs.Server == null) |
@@ -306,8 +306,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
306 | 306 | ||
307 | IRCBridgeModule.m_channels.Add(cs); | 307 | IRCBridgeModule.m_channels.Add(cs); |
308 | 308 | ||
309 | m_log.InfoFormat("[IRC-Channel-{0}] New channel initialized for {1}, nick: {2}, commands {3}, private channels {4}", | 309 | m_log.InfoFormat("[IRC-Channel-{0}] New channel initialized for {1}, nick: {2}, commands {3}, private channels {4}", |
310 | cs.idn, rs.Region, cs.DefaultZone, | 310 | cs.idn, rs.Region, cs.DefaultZone, |
311 | cs.CommandsEnabled ? "enabled" : "not enabled", | 311 | cs.CommandsEnabled ? "enabled" : "not enabled", |
312 | cs.RelayPrivateChannels ? "relayed" : "not relayed"); | 312 | cs.RelayPrivateChannels ? "relayed" : "not relayed"); |
313 | } | 313 | } |
@@ -417,7 +417,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
417 | private bool IsAConnectionMatchFor(ChannelState cs) | 417 | private bool IsAConnectionMatchFor(ChannelState cs) |
418 | { | 418 | { |
419 | return ( | 419 | return ( |
420 | Server == cs.Server && | 420 | Server == cs.Server && |
421 | IrcChannel == cs.IrcChannel && | 421 | IrcChannel == cs.IrcChannel && |
422 | Port == cs.Port && | 422 | Port == cs.Port && |
423 | BaseNickname == cs.BaseNickname && | 423 | BaseNickname == cs.BaseNickname && |
@@ -461,7 +461,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
461 | 461 | ||
462 | string result = instr; | 462 | string result = instr; |
463 | 463 | ||
464 | if (result == null || result.Length == 0) | 464 | if (string.IsNullOrEmpty(result)) |
465 | return result; | 465 | return result; |
466 | 466 | ||
467 | // Repeatedly scan the string until all possible | 467 | // Repeatedly scan the string until all possible |
@@ -473,27 +473,27 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
473 | { | 473 | { |
474 | 474 | ||
475 | string vvar = arg.Match(result).ToString(); | 475 | string vvar = arg.Match(result).ToString(); |
476 | string var = vvar.Substring(1,vvar.Length-2).Trim(); | 476 | string var = vvar.Substring(1, vvar.Length - 2).Trim(); |
477 | 477 | ||
478 | switch (var.ToLower()) | 478 | switch (var.ToLower()) |
479 | { | 479 | { |
480 | case "%region" : | 480 | case "%region": |
481 | result = result.Replace(vvar, rs.Region); | 481 | result = result.Replace(vvar, rs.Region); |
482 | break; | 482 | break; |
483 | case "%host" : | 483 | case "%host": |
484 | result = result.Replace(vvar, rs.Host); | 484 | result = result.Replace(vvar, rs.Host); |
485 | break; | 485 | break; |
486 | case "%locx" : | 486 | case "%locx": |
487 | result = result.Replace(vvar, rs.LocX); | 487 | result = result.Replace(vvar, rs.LocX); |
488 | break; | 488 | break; |
489 | case "%locy" : | 489 | case "%locy": |
490 | result = result.Replace(vvar, rs.LocY); | 490 | result = result.Replace(vvar, rs.LocY); |
491 | break; | 491 | break; |
492 | case "%k" : | 492 | case "%k": |
493 | result = result.Replace(vvar, rs.IDK); | 493 | result = result.Replace(vvar, rs.IDK); |
494 | break; | 494 | break; |
495 | default : | 495 | default: |
496 | result = result.Replace(vvar, rs.config.GetString(var,var)); | 496 | result = result.Replace(vvar, rs.config.GetString(var, var)); |
497 | break; | 497 | break; |
498 | } | 498 | } |
499 | // m_log.DebugFormat("[IRC-Channel] Parse[2]: {0}", result); | 499 | // m_log.DebugFormat("[IRC-Channel] Parse[2]: {0}", result); |
diff --git a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs index 2e1d03d..351dbfe 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs | |||
@@ -46,18 +46,18 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
46 | { | 46 | { |
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
48 | 48 | ||
49 | internal static bool m_pluginEnabled = false; | 49 | internal static bool Enabled = false; |
50 | internal static IConfig m_config = null; | 50 | internal static IConfig m_config = null; |
51 | 51 | ||
52 | internal static List<ChannelState> m_channels = new List<ChannelState>(); | 52 | internal static List<ChannelState> m_channels = new List<ChannelState>(); |
53 | internal static List<RegionState> m_regions = new List<RegionState>(); | 53 | internal static List<RegionState> m_regions = new List<RegionState>(); |
54 | 54 | ||
55 | internal static string m_password = String.Empty; | 55 | internal static string m_password = String.Empty; |
56 | internal RegionState m_region = null; | 56 | internal RegionState m_region = null; |
57 | 57 | ||
58 | #region INonSharedRegionModule Members | 58 | #region INonSharedRegionModule Members |
59 | 59 | ||
60 | public Type ReplaceableInterface | 60 | public Type ReplaceableInterface |
61 | { | 61 | { |
62 | get { return null; } | 62 | get { return null; } |
63 | } | 63 | } |
@@ -72,13 +72,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
72 | m_config = config.Configs["IRC"]; | 72 | m_config = config.Configs["IRC"]; |
73 | if (m_config == null) | 73 | if (m_config == null) |
74 | { | 74 | { |
75 | // m_log.InfoFormat("[IRC-Bridge] module not configured"); | 75 | // m_log.InfoFormat("[IRC-Bridge] module not configured"); |
76 | return; | 76 | return; |
77 | } | 77 | } |
78 | 78 | ||
79 | if (!m_config.GetBoolean("enabled", false)) | 79 | if (!m_config.GetBoolean("enabled", false)) |
80 | { | 80 | { |
81 | // m_log.InfoFormat("[IRC-Bridge] module disabled in configuration"); | 81 | // m_log.InfoFormat("[IRC-Bridge] module disabled in configuration"); |
82 | return; | 82 | return; |
83 | } | 83 | } |
84 | 84 | ||
@@ -87,19 +87,22 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
87 | m_password = config.Configs["RemoteAdmin"].GetString("access_password", m_password); | 87 | m_password = config.Configs["RemoteAdmin"].GetString("access_password", m_password); |
88 | } | 88 | } |
89 | 89 | ||
90 | m_pluginEnabled = true; | 90 | Enabled = true; |
91 | m_log.InfoFormat("[IRC-Bridge]: Module enabled"); | 91 | |
92 | m_log.InfoFormat("[IRC-Bridge]: Module is enabled"); | ||
92 | } | 93 | } |
93 | 94 | ||
94 | public void AddRegion(Scene scene) | 95 | public void AddRegion(Scene scene) |
95 | { | 96 | { |
96 | if (m_pluginEnabled) | 97 | if (Enabled) |
97 | { | 98 | { |
98 | try | 99 | try |
99 | { | 100 | { |
100 | m_log.InfoFormat("[IRC-Bridge] Connecting region {0}", scene.RegionInfo.RegionName); | 101 | m_log.InfoFormat("[IRC-Bridge] Connecting region {0}", scene.RegionInfo.RegionName); |
102 | |||
101 | if (!String.IsNullOrEmpty(m_password)) | 103 | if (!String.IsNullOrEmpty(m_password)) |
102 | MainServer.Instance.AddXmlRPCHandler("irc_admin", XmlRpcAdminMethod, false); | 104 | MainServer.Instance.AddXmlRPCHandler("irc_admin", XmlRpcAdminMethod, false); |
105 | |||
103 | m_region = new RegionState(scene, m_config); | 106 | m_region = new RegionState(scene, m_config); |
104 | lock (m_regions) m_regions.Add(m_region); | 107 | lock (m_regions) m_regions.Add(m_region); |
105 | m_region.Open(); | 108 | m_region.Open(); |
@@ -123,7 +126,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
123 | 126 | ||
124 | public void RemoveRegion(Scene scene) | 127 | public void RemoveRegion(Scene scene) |
125 | { | 128 | { |
126 | if (!m_pluginEnabled) | 129 | if (!Enabled) |
127 | return; | 130 | return; |
128 | 131 | ||
129 | if (m_region == null) | 132 | if (m_region == null) |
@@ -150,12 +153,12 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
150 | m_log.Debug("[IRC-Bridge]: XML RPC Admin Entry"); | 153 | m_log.Debug("[IRC-Bridge]: XML RPC Admin Entry"); |
151 | 154 | ||
152 | XmlRpcResponse response = new XmlRpcResponse(); | 155 | XmlRpcResponse response = new XmlRpcResponse(); |
153 | Hashtable responseData = new Hashtable(); | 156 | Hashtable responseData = new Hashtable(); |
154 | 157 | ||
155 | try | 158 | try |
156 | { | 159 | { |
157 | Hashtable requestData = (Hashtable)request.Params[0]; | 160 | Hashtable requestData = (Hashtable)request.Params[0]; |
158 | bool found = false; | 161 | bool found = false; |
159 | string region = String.Empty; | 162 | string region = String.Empty; |
160 | 163 | ||
161 | if (m_password != String.Empty) | 164 | if (m_password != String.Empty) |
@@ -169,18 +172,18 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
169 | if (!requestData.ContainsKey("region")) | 172 | if (!requestData.ContainsKey("region")) |
170 | throw new Exception("No region name specified"); | 173 | throw new Exception("No region name specified"); |
171 | region = (string)requestData["region"]; | 174 | region = (string)requestData["region"]; |
172 | 175 | ||
173 | foreach (RegionState rs in m_regions) | 176 | foreach (RegionState rs in m_regions) |
174 | { | 177 | { |
175 | if (rs.Region == region) | 178 | if (rs.Region == region) |
176 | { | 179 | { |
177 | responseData["server"] = rs.cs.Server; | 180 | responseData["server"] = rs.cs.Server; |
178 | responseData["port"] = (int)rs.cs.Port; | 181 | responseData["port"] = (int)rs.cs.Port; |
179 | responseData["user"] = rs.cs.User; | 182 | responseData["user"] = rs.cs.User; |
180 | responseData["channel"] = rs.cs.IrcChannel; | 183 | responseData["channel"] = rs.cs.IrcChannel; |
181 | responseData["enabled"] = rs.cs.irc.Enabled; | 184 | responseData["enabled"] = rs.cs.irc.Enabled; |
182 | responseData["connected"] = rs.cs.irc.Connected; | 185 | responseData["connected"] = rs.cs.irc.Connected; |
183 | responseData["nickname"] = rs.cs.irc.Nick; | 186 | responseData["nickname"] = rs.cs.irc.Nick; |
184 | found = true; | 187 | found = true; |
185 | break; | 188 | break; |
186 | } | 189 | } |
@@ -195,7 +198,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
195 | m_log.ErrorFormat("[IRC-Bridge] XML RPC Admin request failed : {0}", e.Message); | 198 | m_log.ErrorFormat("[IRC-Bridge] XML RPC Admin request failed : {0}", e.Message); |
196 | 199 | ||
197 | responseData["success"] = "false"; | 200 | responseData["success"] = "false"; |
198 | responseData["error"] = e.Message; | 201 | responseData["error"] = e.Message; |
199 | } | 202 | } |
200 | finally | 203 | finally |
201 | { | 204 | { |
diff --git a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs index a014798..6985371 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs | |||
@@ -52,17 +52,19 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
52 | 52 | ||
53 | // Local constants | 53 | // Local constants |
54 | 54 | ||
55 | // This computation is not the real region center if the region is larger than 256. | ||
56 | // This computation isn't fixed because there is not a handle back to the region. | ||
55 | private static readonly Vector3 CenterOfRegion = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20); | 57 | private static readonly Vector3 CenterOfRegion = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20); |
56 | private static readonly char[] CS_SPACE = { ' ' }; | 58 | private static readonly char[] CS_SPACE = { ' ' }; |
57 | 59 | ||
58 | private const int WD_INTERVAL = 1000; // base watchdog interval | 60 | private const int WD_INTERVAL = 1000; // base watchdog interval |
59 | private static int PING_PERIOD = 15; // WD intervals per PING | 61 | private static int PING_PERIOD = 15; // WD intervals per PING |
60 | private static int ICCD_PERIOD = 10; // WD intervals between Connects | 62 | private static int ICCD_PERIOD = 10; // WD intervals between Connects |
61 | private static int L_TIMEOUT = 25; // Login time out interval | 63 | private static int L_TIMEOUT = 25; // Login time out interval |
62 | 64 | ||
63 | private static int _idk_ = 0; // core connector identifier | 65 | private static int _idk_ = 0; // core connector identifier |
64 | private static int _pdk_ = 0; // ping interval counter | 66 | private static int _pdk_ = 0; // ping interval counter |
65 | private static int _icc_ = ICCD_PERIOD; // IRC connect counter | 67 | private static int _icc_ = ICCD_PERIOD; // IRC connect counter |
66 | 68 | ||
67 | // List of configured connectors | 69 | // List of configured connectors |
68 | 70 | ||
@@ -107,13 +109,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
107 | 109 | ||
108 | internal int m_resetk = 0; | 110 | internal int m_resetk = 0; |
109 | 111 | ||
110 | // Working threads | ||
111 | |||
112 | private Thread m_listener = null; | ||
113 | |||
114 | private Object msyncConnect = new Object(); | 112 | private Object msyncConnect = new Object(); |
115 | 113 | ||
116 | internal bool m_randomizeNick = true; // add random suffix | 114 | internal bool m_randomizeNick = true; // add random suffix |
117 | internal string m_baseNick = null; // base name for randomizing | 115 | internal string m_baseNick = null; // base name for randomizing |
118 | internal string m_nick = null; // effective nickname | 116 | internal string m_nick = null; // effective nickname |
119 | 117 | ||
@@ -122,7 +120,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
122 | get { return m_nick; } | 120 | get { return m_nick; } |
123 | set { m_nick = value; } | 121 | set { m_nick = value; } |
124 | } | 122 | } |
125 | 123 | ||
126 | private bool m_enabled = false; // connector enablement | 124 | private bool m_enabled = false; // connector enablement |
127 | public bool Enabled | 125 | public bool Enabled |
128 | { | 126 | { |
@@ -130,8 +128,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
130 | } | 128 | } |
131 | 129 | ||
132 | private bool m_connected = false; // connection status | 130 | private bool m_connected = false; // connection status |
133 | private bool m_pending = false; // login disposition | 131 | private bool m_pending = false; // login disposition |
134 | private int m_timeout = L_TIMEOUT; // login timeout counter | 132 | private int m_timeout = L_TIMEOUT; // login timeout counter |
135 | public bool Connected | 133 | public bool Connected |
136 | { | 134 | { |
137 | get { return m_connected; } | 135 | get { return m_connected; } |
@@ -143,9 +141,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
143 | get { return m_ircChannel; } | 141 | get { return m_ircChannel; } |
144 | set { m_ircChannel = value; } | 142 | set { m_ircChannel = value; } |
145 | } | 143 | } |
146 | 144 | ||
147 | private uint m_port = 6667; // session port | 145 | private uint m_port = 6667; // session port |
148 | public uint Port | 146 | public uint Port |
149 | { | 147 | { |
150 | get { return m_port; } | 148 | get { return m_port; } |
151 | set { m_port = value; } | 149 | set { m_port = value; } |
@@ -172,10 +170,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
172 | 170 | ||
173 | // Network interface | 171 | // Network interface |
174 | 172 | ||
175 | private TcpClient m_tcp; | 173 | private TcpClient m_tcp; |
176 | private NetworkStream m_stream = null; | 174 | private NetworkStream m_stream = null; |
177 | private StreamReader m_reader; | 175 | private StreamReader m_reader; |
178 | private StreamWriter m_writer; | 176 | private StreamWriter m_writer; |
179 | 177 | ||
180 | // Channel characteristic info (if available) | 178 | // Channel characteristic info (if available) |
181 | 179 | ||
@@ -193,26 +191,26 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
193 | 191 | ||
194 | // Prepare network interface | 192 | // Prepare network interface |
195 | 193 | ||
196 | m_tcp = null; | 194 | m_tcp = null; |
197 | m_writer = null; | 195 | m_writer = null; |
198 | m_reader = null; | 196 | m_reader = null; |
199 | 197 | ||
200 | // Setup IRC session parameters | 198 | // Setup IRC session parameters |
201 | 199 | ||
202 | m_server = cs.Server; | 200 | m_server = cs.Server; |
203 | m_password = cs.Password; | 201 | m_password = cs.Password; |
204 | m_baseNick = cs.BaseNickname; | 202 | m_baseNick = cs.BaseNickname; |
205 | m_randomizeNick = cs.RandomizeNickname; | 203 | m_randomizeNick = cs.RandomizeNickname; |
206 | m_ircChannel = cs.IrcChannel; | 204 | m_ircChannel = cs.IrcChannel; |
207 | m_port = cs.Port; | 205 | m_port = cs.Port; |
208 | m_user = cs.User; | 206 | m_user = cs.User; |
209 | 207 | ||
210 | if (m_watchdog == null) | 208 | if (m_watchdog == null) |
211 | { | 209 | { |
212 | // Non-differentiating | 210 | // Non-differentiating |
213 | 211 | ||
214 | ICCD_PERIOD = cs.ConnectDelay; | 212 | ICCD_PERIOD = cs.ConnectDelay; |
215 | PING_PERIOD = cs.PingDelay; | 213 | PING_PERIOD = cs.PingDelay; |
216 | 214 | ||
217 | // Smaller values are not reasonable | 215 | // Smaller values are not reasonable |
218 | 216 | ||
@@ -235,7 +233,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
235 | 233 | ||
236 | if (m_randomizeNick) | 234 | if (m_randomizeNick) |
237 | m_nick = m_baseNick + Util.RandomClass.Next(1, 99); | 235 | m_nick = m_baseNick + Util.RandomClass.Next(1, 99); |
238 | else | 236 | else |
239 | m_nick = m_baseNick; | 237 | m_nick = m_baseNick; |
240 | 238 | ||
241 | m_log.InfoFormat("[IRC-Connector-{0}]: Initialization complete", idn); | 239 | m_log.InfoFormat("[IRC-Connector-{0}]: Initialization complete", idn); |
@@ -295,18 +293,22 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
295 | m_nick, m_ircChannel, m_server)); | 293 | m_nick, m_ircChannel, m_server)); |
296 | m_writer.Flush(); | 294 | m_writer.Flush(); |
297 | } | 295 | } |
298 | catch (Exception) {} | 296 | catch (Exception) { } |
299 | 297 | ||
300 | 298 | ||
301 | m_connected = false; | 299 | m_connected = false; |
302 | 300 | ||
303 | try { m_writer.Close(); } catch (Exception) {} | 301 | try { m_writer.Close(); } |
304 | try { m_reader.Close(); } catch (Exception) {} | 302 | catch (Exception) { } |
305 | try { m_stream.Close(); } catch (Exception) {} | 303 | try { m_reader.Close(); } |
306 | try { m_tcp.Close(); } catch (Exception) {} | 304 | catch (Exception) { } |
305 | try { m_stream.Close(); } | ||
306 | catch (Exception) { } | ||
307 | try { m_tcp.Close(); } | ||
308 | catch (Exception) { } | ||
307 | 309 | ||
308 | } | 310 | } |
309 | 311 | ||
310 | lock (m_connectors) | 312 | lock (m_connectors) |
311 | m_connectors.Remove(this); | 313 | m_connectors.Remove(this); |
312 | 314 | ||
@@ -347,20 +349,17 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
347 | if (m_connected) return; | 349 | if (m_connected) return; |
348 | 350 | ||
349 | m_connected = true; | 351 | m_connected = true; |
350 | m_pending = true; | 352 | m_pending = true; |
351 | m_timeout = L_TIMEOUT; | 353 | m_timeout = L_TIMEOUT; |
352 | 354 | ||
353 | m_tcp = new TcpClient(m_server, (int)m_port); | 355 | m_tcp = new TcpClient(m_server, (int)m_port); |
354 | m_stream = m_tcp.GetStream(); | 356 | m_stream = m_tcp.GetStream(); |
355 | m_reader = new StreamReader(m_stream); | 357 | m_reader = new StreamReader(m_stream); |
356 | m_writer = new StreamWriter(m_stream); | 358 | m_writer = new StreamWriter(m_stream); |
357 | 359 | ||
358 | m_log.InfoFormat("[IRC-Connector-{0}]: Connected to {1}:{2}", idn, m_server, m_port); | 360 | m_log.InfoFormat("[IRC-Connector-{0}]: Connected to {1}:{2}", idn, m_server, m_port); |
359 | 361 | ||
360 | m_listener = new Thread(new ThreadStart(ListenerRun)); | 362 | WorkManager.StartThread(ListenerRun, "IRCConnectionListenerThread", ThreadPriority.Normal, true, false); |
361 | m_listener.Name = "IRCConnectorListenerThread"; | ||
362 | m_listener.IsBackground = true; | ||
363 | m_listener.Start(); | ||
364 | 363 | ||
365 | // This is the message order recommended by RFC 2812 | 364 | // This is the message order recommended by RFC 2812 |
366 | if (m_password != null) | 365 | if (m_password != null) |
@@ -418,12 +417,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
418 | // the socket and it will disappear of its own accord, once this | 417 | // the socket and it will disappear of its own accord, once this |
419 | // processing is completed. | 418 | // processing is completed. |
420 | 419 | ||
421 | try { m_writer.Close(); } catch (Exception) {} | 420 | try { m_writer.Close(); } |
422 | try { m_reader.Close(); } catch (Exception) {} | 421 | catch (Exception) { } |
423 | try { m_tcp.Close(); } catch (Exception) {} | 422 | try { m_reader.Close(); } |
423 | catch (Exception) { } | ||
424 | try { m_tcp.Close(); } | ||
425 | catch (Exception) { } | ||
424 | 426 | ||
425 | m_connected = false; | 427 | m_connected = false; |
426 | m_pending = false; | 428 | m_pending = false; |
427 | m_resetk++; | 429 | m_resetk++; |
428 | 430 | ||
429 | } | 431 | } |
@@ -495,27 +497,26 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
495 | { | 497 | { |
496 | 498 | ||
497 | string inputLine; | 499 | string inputLine; |
498 | int resetk = m_resetk; | 500 | int resetk = m_resetk; |
499 | 501 | ||
500 | try | 502 | try |
501 | { | 503 | { |
502 | while (m_enabled && m_connected) | 504 | while (m_enabled && m_connected) |
503 | { | 505 | { |
504 | |||
505 | if ((inputLine = m_reader.ReadLine()) == null) | 506 | if ((inputLine = m_reader.ReadLine()) == null) |
506 | throw new Exception("Listener input socket closed"); | 507 | throw new Exception("Listener input socket closed"); |
507 | 508 | ||
509 | Watchdog.UpdateThread(); | ||
510 | |||
508 | // m_log.Info("[IRCConnector]: " + inputLine); | 511 | // m_log.Info("[IRCConnector]: " + inputLine); |
509 | 512 | ||
510 | if (inputLine.Contains("PRIVMSG")) | 513 | if (inputLine.Contains("PRIVMSG")) |
511 | { | 514 | { |
512 | |||
513 | Dictionary<string, string> data = ExtractMsg(inputLine); | 515 | Dictionary<string, string> data = ExtractMsg(inputLine); |
514 | 516 | ||
515 | // Any chat ??? | 517 | // Any chat ??? |
516 | if (data != null) | 518 | if (data != null) |
517 | { | 519 | { |
518 | |||
519 | OSChatMessage c = new OSChatMessage(); | 520 | OSChatMessage c = new OSChatMessage(); |
520 | c.Message = data["msg"]; | 521 | c.Message = data["msg"]; |
521 | c.Type = ChatTypeEnum.Region; | 522 | c.Type = ChatTypeEnum.Region; |
@@ -531,9 +532,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
531 | c.Message = String.Format("/me {0}", c.Message.Substring(8, c.Message.Length - 9)); | 532 | c.Message = String.Format("/me {0}", c.Message.Substring(8, c.Message.Length - 9)); |
532 | 533 | ||
533 | ChannelState.OSChat(this, c, false); | 534 | ChannelState.OSChat(this, c, false); |
534 | |||
535 | } | 535 | } |
536 | |||
537 | } | 536 | } |
538 | else | 537 | else |
539 | { | 538 | { |
@@ -553,9 +552,11 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
553 | 552 | ||
554 | if (m_enabled && (m_resetk == resetk)) | 553 | if (m_enabled && (m_resetk == resetk)) |
555 | Reconnect(); | 554 | Reconnect(); |
555 | |||
556 | Watchdog.RemoveThread(); | ||
556 | } | 557 | } |
557 | 558 | ||
558 | private Regex RE = new Regex(@":(?<nick>[\w-]*)!(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)", | 559 | private Regex RE = new Regex(@":(?<nick>[\w-]*)!(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)", |
559 | RegexOptions.Multiline); | 560 | RegexOptions.Multiline); |
560 | 561 | ||
561 | private Dictionary<string, string> ExtractMsg(string input) | 562 | private Dictionary<string, string> ExtractMsg(string input) |
@@ -617,8 +618,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
617 | string[] commArgs; | 618 | string[] commArgs; |
618 | string c_server = m_server; | 619 | string c_server = m_server; |
619 | 620 | ||
620 | string pfx = String.Empty; | 621 | string pfx = String.Empty; |
621 | string cmd = String.Empty; | 622 | string cmd = String.Empty; |
622 | string parms = String.Empty; | 623 | string parms = String.Empty; |
623 | 624 | ||
624 | // ":" indicates that a prefix is present | 625 | // ":" indicates that a prefix is present |
@@ -627,15 +628,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
627 | // ":" indicates that the remainder of the | 628 | // ":" indicates that the remainder of the |
628 | // line is a single parameter value. | 629 | // line is a single parameter value. |
629 | 630 | ||
630 | commArgs = command.Split(CS_SPACE,2); | 631 | commArgs = command.Split(CS_SPACE, 2); |
631 | 632 | ||
632 | if (commArgs[0].StartsWith(":")) | 633 | if (commArgs[0].StartsWith(":")) |
633 | { | 634 | { |
634 | pfx = commArgs[0].Substring(1); | 635 | pfx = commArgs[0].Substring(1); |
635 | commArgs = commArgs[1].Split(CS_SPACE,2); | 636 | commArgs = commArgs[1].Split(CS_SPACE, 2); |
636 | } | 637 | } |
637 | 638 | ||
638 | cmd = commArgs[0]; | 639 | cmd = commArgs[0]; |
639 | parms = commArgs[1]; | 640 | parms = commArgs[1]; |
640 | 641 | ||
641 | // m_log.DebugFormat("[IRC-Connector-{0}] prefix = <{1}> cmd = <{2}>", idn, pfx, cmd); | 642 | // m_log.DebugFormat("[IRC-Connector-{0}] prefix = <{1}> cmd = <{2}>", idn, pfx, cmd); |
@@ -646,44 +647,44 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
646 | // Messages 001-004 are always sent | 647 | // Messages 001-004 are always sent |
647 | // following signon. | 648 | // following signon. |
648 | 649 | ||
649 | case "001" : // Welcome ... | 650 | case "001": // Welcome ... |
650 | case "002" : // Server information | 651 | case "002": // Server information |
651 | case "003" : // Welcome ... | 652 | case "003": // Welcome ... |
652 | break; | 653 | break; |
653 | case "004" : // Server information | 654 | case "004": // Server information |
654 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); | 655 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); |
655 | commArgs = parms.Split(CS_SPACE); | 656 | commArgs = parms.Split(CS_SPACE); |
656 | c_server = commArgs[1]; | 657 | c_server = commArgs[1]; |
657 | m_server = c_server; | 658 | m_server = c_server; |
658 | version = commArgs[2]; | 659 | version = commArgs[2]; |
659 | usermod = commArgs[3]; | 660 | usermod = commArgs[3]; |
660 | chanmod = commArgs[4]; | 661 | chanmod = commArgs[4]; |
661 | break; | 662 | break; |
662 | case "005" : // Server information | 663 | case "005": // Server information |
663 | break; | 664 | break; |
664 | case "042" : | 665 | case "042": |
665 | case "250" : | 666 | case "250": |
666 | case "251" : | 667 | case "251": |
667 | case "252" : | 668 | case "252": |
668 | case "254" : | 669 | case "254": |
669 | case "255" : | 670 | case "255": |
670 | case "265" : | 671 | case "265": |
671 | case "266" : | 672 | case "266": |
672 | case "332" : // Subject | 673 | case "332": // Subject |
673 | case "333" : // Subject owner (?) | 674 | case "333": // Subject owner (?) |
674 | case "353" : // Name list | 675 | case "353": // Name list |
675 | case "366" : // End-of-Name list marker | 676 | case "366": // End-of-Name list marker |
676 | case "372" : // MOTD body | 677 | case "372": // MOTD body |
677 | case "375" : // MOTD start | 678 | case "375": // MOTD start |
678 | // m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); | 679 | // m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); |
679 | break; | 680 | break; |
680 | case "376" : // MOTD end | 681 | case "376": // MOTD end |
681 | // m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); | 682 | // m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); |
682 | motd = true; | 683 | motd = true; |
683 | break; | 684 | break; |
684 | case "451" : // Not registered | 685 | case "451": // Not registered |
685 | break; | 686 | break; |
686 | case "433" : // Nickname in use | 687 | case "433": // Nickname in use |
687 | // Gen a new name | 688 | // Gen a new name |
688 | m_nick = m_baseNick + Util.RandomClass.Next(1, 99); | 689 | m_nick = m_baseNick + Util.RandomClass.Next(1, 99); |
689 | m_log.ErrorFormat("[IRC-Connector-{0}]: [{1}] IRC SERVER reports NicknameInUse, trying {2}", idn, cmd, m_nick); | 690 | m_log.ErrorFormat("[IRC-Connector-{0}]: [{1}] IRC SERVER reports NicknameInUse, trying {2}", idn, cmd, m_nick); |
@@ -695,29 +696,29 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
695 | m_writer.WriteLine(String.Format("JOIN {0}", m_ircChannel)); | 696 | m_writer.WriteLine(String.Format("JOIN {0}", m_ircChannel)); |
696 | m_writer.Flush(); | 697 | m_writer.Flush(); |
697 | break; | 698 | break; |
698 | case "479" : // Bad channel name, etc. This will never work, so disable the connection | 699 | case "479": // Bad channel name, etc. This will never work, so disable the connection |
699 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); | 700 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE, 2)[1]); |
700 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] Connector disabled", idn, cmd); | 701 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] Connector disabled", idn, cmd); |
701 | m_enabled = false; | 702 | m_enabled = false; |
702 | m_connected = false; | 703 | m_connected = false; |
703 | m_pending = false; | 704 | m_pending = false; |
704 | break; | 705 | break; |
705 | case "NOTICE" : | 706 | case "NOTICE": |
706 | // m_log.WarnFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); | 707 | // m_log.WarnFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); |
707 | break; | 708 | break; |
708 | case "ERROR" : | 709 | case "ERROR": |
709 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); | 710 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE, 2)[1]); |
710 | if (parms.Contains("reconnect too fast")) | 711 | if (parms.Contains("reconnect too fast")) |
711 | ICCD_PERIOD++; | 712 | ICCD_PERIOD++; |
712 | m_pending = false; | 713 | m_pending = false; |
713 | Reconnect(); | 714 | Reconnect(); |
714 | break; | 715 | break; |
715 | case "PING" : | 716 | case "PING": |
716 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); | 717 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); |
717 | m_writer.WriteLine(String.Format("PONG {0}", parms)); | 718 | m_writer.WriteLine(String.Format("PONG {0}", parms)); |
718 | m_writer.Flush(); | 719 | m_writer.Flush(); |
719 | break; | 720 | break; |
720 | case "PONG" : | 721 | case "PONG": |
721 | break; | 722 | break; |
722 | case "JOIN": | 723 | case "JOIN": |
723 | if (m_pending) | 724 | if (m_pending) |
@@ -748,19 +749,19 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
748 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); | 749 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); |
749 | eventIrcQuit(pfx, cmd, parms); | 750 | eventIrcQuit(pfx, cmd, parms); |
750 | break; | 751 | break; |
751 | default : | 752 | default: |
752 | m_log.DebugFormat("[IRC-Connector-{0}] Command '{1}' ignored, parms = {2}", idn, cmd, parms); | 753 | m_log.DebugFormat("[IRC-Connector-{0}] Command '{1}' ignored, parms = {2}", idn, cmd, parms); |
753 | break; | 754 | break; |
754 | } | 755 | } |
755 | 756 | ||
756 | // m_log.DebugFormat("[IRC-Connector-{0}] prefix = <{1}> cmd = <{2}> complete", idn, pfx, cmd); | 757 | // m_log.DebugFormat("[IRC-Connector-{0}] prefix = <{1}> cmd = <{2}> complete", idn, pfx, cmd); |
757 | 758 | ||
758 | } | 759 | } |
759 | 760 | ||
760 | public void eventIrcJoin(string prefix, string command, string parms) | 761 | public void eventIrcJoin(string prefix, string command, string parms) |
761 | { | 762 | { |
762 | string[] args = parms.Split(CS_SPACE,2); | 763 | string[] args = parms.Split(CS_SPACE, 2); |
763 | string IrcUser = prefix.Split('!')[0]; | 764 | string IrcUser = prefix.Split('!')[0]; |
764 | string IrcChannel = args[0]; | 765 | string IrcChannel = args[0]; |
765 | 766 | ||
766 | if (IrcChannel.StartsWith(":")) | 767 | if (IrcChannel.StartsWith(":")) |
@@ -772,8 +773,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
772 | 773 | ||
773 | public void eventIrcPart(string prefix, string command, string parms) | 774 | public void eventIrcPart(string prefix, string command, string parms) |
774 | { | 775 | { |
775 | string[] args = parms.Split(CS_SPACE,2); | 776 | string[] args = parms.Split(CS_SPACE, 2); |
776 | string IrcUser = prefix.Split('!')[0]; | 777 | string IrcUser = prefix.Split('!')[0]; |
777 | string IrcChannel = args[0]; | 778 | string IrcChannel = args[0]; |
778 | 779 | ||
779 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCPart {1}:{2}", idn, m_server, m_ircChannel); | 780 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCPart {1}:{2}", idn, m_server, m_ircChannel); |
@@ -782,7 +783,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
782 | 783 | ||
783 | public void eventIrcMode(string prefix, string command, string parms) | 784 | public void eventIrcMode(string prefix, string command, string parms) |
784 | { | 785 | { |
785 | string[] args = parms.Split(CS_SPACE,2); | 786 | string[] args = parms.Split(CS_SPACE, 2); |
786 | string UserMode = args[1]; | 787 | string UserMode = args[1]; |
787 | 788 | ||
788 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCMode {1}:{2}", idn, m_server, m_ircChannel); | 789 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCMode {1}:{2}", idn, m_server, m_ircChannel); |
@@ -794,7 +795,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
794 | 795 | ||
795 | public void eventIrcNickChange(string prefix, string command, string parms) | 796 | public void eventIrcNickChange(string prefix, string command, string parms) |
796 | { | 797 | { |
797 | string[] args = parms.Split(CS_SPACE,2); | 798 | string[] args = parms.Split(CS_SPACE, 2); |
798 | string UserOldNick = prefix.Split('!')[0]; | 799 | string UserOldNick = prefix.Split('!')[0]; |
799 | string UserNewNick = args[0].Remove(0, 1); | 800 | string UserNewNick = args[0].Remove(0, 1); |
800 | 801 | ||
@@ -804,11 +805,11 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
804 | 805 | ||
805 | public void eventIrcKick(string prefix, string command, string parms) | 806 | public void eventIrcKick(string prefix, string command, string parms) |
806 | { | 807 | { |
807 | string[] args = parms.Split(CS_SPACE,3); | 808 | string[] args = parms.Split(CS_SPACE, 3); |
808 | string UserKicker = prefix.Split('!')[0]; | 809 | string UserKicker = prefix.Split('!')[0]; |
809 | string IrcChannel = args[0]; | 810 | string IrcChannel = args[0]; |
810 | string UserKicked = args[1]; | 811 | string UserKicked = args[1]; |
811 | string KickMessage = args[2]; | 812 | string KickMessage = args[2]; |
812 | 813 | ||
813 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCKick {1}:{2}", idn, m_server, m_ircChannel); | 814 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCKick {1}:{2}", idn, m_server, m_ircChannel); |
814 | BroadcastSim(UserKicker, "/me kicks kicks {0} off {1} saying \"{2}\"", UserKicked, IrcChannel, KickMessage); | 815 | BroadcastSim(UserKicker, "/me kicks kicks {0} off {1} saying \"{2}\"", UserKicked, IrcChannel, KickMessage); |
@@ -822,7 +823,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
822 | 823 | ||
823 | public void eventIrcQuit(string prefix, string command, string parms) | 824 | public void eventIrcQuit(string prefix, string command, string parms) |
824 | { | 825 | { |
825 | string IrcUser = prefix.Split('!')[0]; | 826 | string IrcUser = prefix.Split('!')[0]; |
826 | string QuitMessage = parms; | 827 | string QuitMessage = parms; |
827 | 828 | ||
828 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCQuit {1}:{2}", idn, m_server, m_ircChannel); | 829 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCQuit {1}:{2}", idn, m_server, m_ircChannel); |
@@ -842,65 +843,65 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
842 | 843 | ||
843 | // m_log.InfoFormat("[IRC-Watchdog] Status scan, pdk = {0}, icc = {1}", _pdk_, _icc_); | 844 | // m_log.InfoFormat("[IRC-Watchdog] Status scan, pdk = {0}, icc = {1}", _pdk_, _icc_); |
844 | 845 | ||
845 | _pdk_ = (_pdk_+1)%PING_PERIOD; // cycle the ping trigger | 846 | _pdk_ = (_pdk_ + 1) % PING_PERIOD; // cycle the ping trigger |
846 | _icc_++; // increment the inter-consecutive-connect-delay counter | 847 | _icc_++; // increment the inter-consecutive-connect-delay counter |
847 | 848 | ||
848 | lock (m_connectors) | 849 | lock (m_connectors) |
849 | foreach (IRCConnector connector in m_connectors) | 850 | foreach (IRCConnector connector in m_connectors) |
850 | { | 851 | { |
851 | 852 | ||
852 | // m_log.InfoFormat("[IRC-Watchdog] Scanning {0}", connector); | 853 | // m_log.InfoFormat("[IRC-Watchdog] Scanning {0}", connector); |
853 | 854 | ||
854 | if (connector.Enabled) | 855 | if (connector.Enabled) |
855 | { | ||
856 | if (!connector.Connected) | ||
857 | { | 856 | { |
858 | try | 857 | if (!connector.Connected) |
859 | { | 858 | { |
860 | // m_log.DebugFormat("[IRC-Watchdog] Connecting {1}:{2}", connector.idn, connector.m_server, connector.m_ircChannel); | 859 | try |
861 | connector.Connect(); | 860 | { |
861 | // m_log.DebugFormat("[IRC-Watchdog] Connecting {1}:{2}", connector.idn, connector.m_server, connector.m_ircChannel); | ||
862 | connector.Connect(); | ||
863 | } | ||
864 | catch (Exception e) | ||
865 | { | ||
866 | m_log.ErrorFormat("[IRC-Watchdog] Exception on connector {0}: {1} ", connector.idn, e.Message); | ||
867 | } | ||
862 | } | 868 | } |
863 | catch (Exception e) | 869 | else |
864 | { | 870 | { |
865 | m_log.ErrorFormat("[IRC-Watchdog] Exception on connector {0}: {1} ", connector.idn, e.Message); | ||
866 | } | ||
867 | } | ||
868 | else | ||
869 | { | ||
870 | 871 | ||
871 | if (connector.m_pending) | 872 | if (connector.m_pending) |
872 | { | ||
873 | if (connector.m_timeout == 0) | ||
874 | { | 873 | { |
875 | m_log.ErrorFormat("[IRC-Watchdog] Login timed-out for connector {0}, reconnecting", connector.idn); | 874 | if (connector.m_timeout == 0) |
876 | connector.Reconnect(); | 875 | { |
876 | m_log.ErrorFormat("[IRC-Watchdog] Login timed-out for connector {0}, reconnecting", connector.idn); | ||
877 | connector.Reconnect(); | ||
878 | } | ||
879 | else | ||
880 | connector.m_timeout--; | ||
877 | } | 881 | } |
878 | else | ||
879 | connector.m_timeout--; | ||
880 | } | ||
881 | 882 | ||
882 | // Being marked connected is not enough to ping. Socket establishment can sometimes take a long | 883 | // Being marked connected is not enough to ping. Socket establishment can sometimes take a long |
883 | // time, in which case the watch dog might try to ping the server before the socket has been | 884 | // time, in which case the watch dog might try to ping the server before the socket has been |
884 | // set up, with nasty side-effects. | 885 | // set up, with nasty side-effects. |
885 | 886 | ||
886 | else if (_pdk_ == 0) | 887 | else if (_pdk_ == 0) |
887 | { | ||
888 | try | ||
889 | { | ||
890 | connector.m_writer.WriteLine(String.Format("PING :{0}", connector.m_server)); | ||
891 | connector.m_writer.Flush(); | ||
892 | } | ||
893 | catch (Exception e) | ||
894 | { | 888 | { |
895 | m_log.ErrorFormat("[IRC-PingRun] Exception on connector {0}: {1} ", connector.idn, e.Message); | 889 | try |
896 | m_log.Debug(e); | 890 | { |
897 | connector.Reconnect(); | 891 | connector.m_writer.WriteLine(String.Format("PING :{0}", connector.m_server)); |
892 | connector.m_writer.Flush(); | ||
893 | } | ||
894 | catch (Exception e) | ||
895 | { | ||
896 | m_log.ErrorFormat("[IRC-PingRun] Exception on connector {0}: {1} ", connector.idn, e.Message); | ||
897 | m_log.Debug(e); | ||
898 | connector.Reconnect(); | ||
899 | } | ||
898 | } | 900 | } |
899 | } | ||
900 | 901 | ||
902 | } | ||
901 | } | 903 | } |
902 | } | 904 | } |
903 | } | ||
904 | 905 | ||
905 | // m_log.InfoFormat("[IRC-Watchdog] Status scan completed"); | 906 | // m_log.InfoFormat("[IRC-Watchdog] Status scan completed"); |
906 | 907 | ||
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()); |