included setting to allow or disallow access to key channels without

This commit is contained in:
Nícolas Lazarte Kaqui 2011-10-11 12:11:12 -03:00
parent c869a07bd6
commit 9a1a7f4626
2 changed files with 36 additions and 10 deletions

View file

@ -43,10 +43,14 @@ namespace SparkleLib {
{
string uri = SparkleConfig.DefaultConfig.GetFolderOptionalAttribute (
folder_name, "announcements_url");
// Key to turn the channel access more safely.
string key = SparkleConfig.DefaultConfig.GetFolderOptionalAttribute (
folder_name, "key");
// Identifier to define access in IRC channel when no key is defined
string dangerous_access = SparkleConfig.DefaultConfig.GetFolderOptionalAttribute (
folder_name, "dangerous_access");
if (uri == null) {
// This is SparkleShare's centralized notification service.
@ -57,6 +61,13 @@ namespace SparkleLib {
uri = "irc://204.62.14.135/";
}
// This action ensures that the Sparkleshare function normally when the key is not defined.
// It is recommended that the user asked a question to see whether or not to allow access
// to the channel without a key.
if (dangerous_access == null) {
dangerous_access = "yes";
}
Uri announce_uri = new Uri (uri);
// We use only one listener per server to keep
@ -78,10 +89,10 @@ namespace SparkleLib {
listeners.Add (new SparkleListenerTcp (announce_uri, folder_identifier));
break;
case "irc":
listeners.Add (new SparkleListenerIrc (announce_uri, folder_identifier, key));
listeners.Add (new SparkleListenerIrc (announce_uri, folder_identifier, key, dangerous_access));
break;
default:
listeners.Add (new SparkleListenerIrc (announce_uri, folder_identifier, key));
listeners.Add (new SparkleListenerIrc (announce_uri, folder_identifier, key, dangerous_access));
break;
}

View file

@ -30,9 +30,10 @@ namespace SparkleLib {
private IrcClient client;
private string nick;
private string key;
private string dangerous_access;
public SparkleListenerIrc (Uri server, string folder_identifier, string key) :
public SparkleListenerIrc (Uri server, string folder_identifier, string key, string dangerous_access) :
base (server, folder_identifier)
{
// Try to get a uniqueish nickname
@ -42,8 +43,12 @@ namespace SparkleLib {
// with a number, so prefix an alphabetic character
this.nick = "s" + this.nick.Substring (0, 7);
// Key to access the channel
this.key = key;
// Allow access to the channel
this.dangerous_access = dangerous_access;
base.channels.Add ("#" + folder_identifier);
this.client = new IrcClient () {
@ -112,11 +117,16 @@ namespace SparkleLib {
foreach (string channel in base.channels) {
SparkleHelpers.DebugInfo ("ListenerIrc", "Joining channel " + channel);
if (key != null) {
SparkleHelpers.DebugInfo ("ListenerIrc", "Ussing key");
SparkleHelpers.DebugInfo ("ListenerIrc", "Key set to access the channel");
this.client.RfcJoin (channel, key);
this.client.RfcMode (channel, "+k " + key);
} else {
this.client.RfcJoin (channel);
if (dangerous_access == "yes") {
SparkleHelpers.DebugInfo ("ListenerIrc", "Accessing a dangerous channel change the setting to not access");
this.client.RfcJoin (channel);
} else {
SparkleHelpers.DebugInfo ("ListenerIrc", "Dangerous channel change the setting to access");
}
}
this.client.RfcMode (channel, "+s");
}
@ -146,14 +156,19 @@ namespace SparkleLib {
if (IsConnected) {
SparkleHelpers.DebugInfo ("ListenerIrc", "Joining channel " + channel);
if (key != null) {
SparkleHelpers.DebugInfo ("ListenerIrc", "Ussing key");
SparkleHelpers.DebugInfo ("ListenerIrc", "Key set to access the channel");
this.client.RfcJoin (channel, key);
this.client.RfcMode (channel, "+k " + key);
} else {
this.client.RfcJoin (channel);
if (dangerous_access == "yes") {
SparkleHelpers.DebugInfo ("ListenerIrc", "Accessing a dangerous channel change the setting to not access");
this.client.RfcJoin (channel);
} else {
SparkleHelpers.DebugInfo ("ListenerIrc", "Dangerous channel change the setting to access");
}
}
this.client.RfcMode (channel, "+s");
}
this.client.RfcMode (channel, "+s");
}
}