FILE | GENERAL PREFERENCES | GENERAL | Notify me if unable to connect
By far, the most frequent error you will recieve when that option is turned on, is error 10060 (Connection Timed Out).

Now, in my opinion this is by far the most common time someone will want to re-attempt a connection. (Perhaps on failed DNS lookup, if your nameserver is down, and you are waiting for it to go back up - RARE).
Now, currently, your suggestion is to:
Make a subroutine to set a flag when connected.
Make a subroutine to set a flag when disconnected appropriately.
Make a timer to call a script.
Have the script called by the timer check the state of the flag and the connection status, and make a re-attempt if appropriate.
Here are a couple of downsides to that:
- COM calls to script file. Everytime you call your script file, there is a very minor lag during this process.
- Since you don't know when you are disconnected, you must make periodic checks to see if you are connected. From previous point, this translated to periodic lag suffering.
- Since you don't know when you are disconnected, it would be very hard to time your script to make an attempt immediately when the connection fails. Instead, you have to wait until the next time the timer checks your connection status. You could set the timer to be the same as the 'Connection Time Out' grace period, but see second point, above.
Some thoughts...
- I don't know if "OnWorldDisconnect" is called when the connection attempt times out (above). I doubt it.
- If "OnWorldDisconnect" is called, there is no means that I know of to check the error code (reason) for the disconnection. (No argument is passed).
Now, I know the lag times I am talking about are so minute they may seem insignificant, but when you have a huge world file with several plugins, efficiency becomes a concern. Inefficient code adds up, and the cummulative effect can be significant. So, it's wise to be as efficient as possible wherever one can. :)
It seems natural that the user would want to make a reconnection attempt immediately, when presented with the error window above (Connection Timed Out). Or, if they want to be polite about it, start a timer to make a re-attempt later, starting from the time that message is presented.
There's the rub. There is no automated way to run script when that error window is presented, and that's my submission, that you automatically call a certain subroutine, if it exists, in the root world file, or in any of it's plugins. To be more flexible, you might change it to something like this:
OnWorldConnectionError(ErrorCode)
OnPluginConnectionError(ErrorCode)
...and then, in my case, I would check to see if the argument was code 10060.
As I said earlier, I thought it would probably be relatively simple for you to add this feature, by simply making the call immediately prior or following your source code that presents that window above. :)
I feel this would be far more efficient than the method you recommend.
(For other people reading: There is already an option to "Reconnect on Disconnect", but the automated procedure will not function if there was a connection error). |