zD12 / pircbotx

Automatically exported from code.google.com/p/pircbotx
0 stars 0 forks source link

Add the ability to specify multiple ports to connect to a server, and try them all if necessary #157

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Right now it is possible to only specify one port in a configuration. Some IRC 
servers support multiple ports (i.e. Quakenet) thus PircBotX should be able to 
try them all in case the first one fails, ...

I had done it in Modular-PircBot, but now that PircBotX is using an 
unmodifiable Configuration that supports only one port, it is a lot harder to 
do so.
(See: 
https://github.com/Bhasmithal/Modular-PircBot/blob/master/modular-pircbot/src/ma
in/java/org/jibble/pircbot/ModularPircBot.java#L115)

I guess accepting a list of integers instead of just one integer would be 
sufficient ;)

Original issue reported on code.google.com by ec...@google.com on 13 Dec 2013 at 8:01

GoogleCodeExporter commented 9 years ago
The link above is not working anymore, but basically the configuration should 
accept of list of ports instead of a single one, and the connect() should 
handle it nicely.

Suggestion: be able to retrieve the connected port in ServerInfo or another 
helpful class.

Original comment by emmanuel...@gmail.com on 17 Dec 2013 at 12:08

GoogleCodeExporter commented 9 years ago
I've considered doing this, but ultimately it seemed very complex to implement 
in the core Configuration class that was clear without over complicating things

Basically I'd be creating a list of servers and having PircBotX loop through 
them. That's simple, but where do I stop? First I have addServer(port). Then it 
just keeps getting more complex when you ask yourself "What could you want to 
change on the next server connect?"

 - addServer(hostname, port)
 - addServer(sslSocketFactory, hostname, port)
 - addServer(sslSocketFactory, hostname, port, password)
 - addServer(sslSocketFactory, hostname, port, password, nick)
 - addServer(sslSocketFActory, hostname, port, password, nick, ...)

It will just keep on going. There's a use case for almost every option in 
Configuration to change on the next connect. There's also retrying and 
timeouts; should I go on to the next server on reconnect? What about 
exceptions? 

I really recommend "template" configurations. This allows you to configure 
PircBotX how you want without any pre-determined list of options you can 
change. 

Original comment by Lord.Qua...@gmail.com on 17 Dec 2013 at 2:24

GoogleCodeExporter commented 9 years ago
Thanks for your answer!

I don't really agree that there are a lot of cases when trying with different 
ports. There is no reason why the user should be able to addServer() to a 
configuration.

I was thinking more about having the following methods:
setServer(String host, List<Integer> ports);
setServer(String host, List<Integer> ports, String password);
setServerPorts(List<Integer> ports);

[same for buildForServer() methods]

Why? Because some IRC networks support several ports that do not depend on any 
other server configuration. Typically, if I try to connect to Quakenet, I'd 
like to try the 6667-6669 ports without having to copy my Configuration each 
time. Trying to connect on these ports should not require any other 
Configuration change besides the port.

Obviously, trying to connect to a different hostname would be a different 
story. If you want to support it, you might consider adding an addServer() 
method that takes a ServerParameters object as parameter (for example).

Original comment by emmanuel...@gmail.com on 17 Dec 2013 at 9:19

GoogleCodeExporter commented 9 years ago
This has been implemented in Revision 2431658b032d. Configuration has a list of 
hostnames and ports that you add with addServer("irc.freenode.net", 6667) 

Original comment by Lord.Qua...@gmail.com on 21 Nov 2014 at 10:16