mIRC Homepage
Posted By: Wims unable to connect: silent retry - 25/09/21 08:25 PM
When you lose internet connection, mIRC will retry connecting N times, and when you don't get internet connection for a while, mIRC will basically flood the status window with the reconnecting messages, which is cluttering.
Not only that but even the maximum number of retry may left you disconnected, despite having internet connection at the time you go back to mIRC.
Instead, I would like mIRC to silently retry indefinitely, and only start displaying message back to the status window when it gets a reply from the server.
This would avoid clutter and ensure that you're connected when internet comes back.
Posted By: Talon Re: unable to connect: silent retry - 28/09/21 11:01 AM
Windows 7 and later do a form of "internet connection" verification by means of a service called NSCI. Basically in the background on a polling frequency it attempts to resolve a ipv4 and ipv6 domain, and if that passes, it attempts to make a http request to a known file and it's contents to return if you truely are connected to the internet.

More information can be found here: https://blog.superuser.com/2011/05/16/windows-7-network-awareness/

It's slightly changed over time albeit the registry keys seem to still be the same. Since you're after "silent" I do believe you cannot halt a /dns (on ^*:DNS) event so to avoid that spam, we'll just utilize the http request method and script our own version of internet connection testing.

I'd reccomend going to Alt+o -> Connect -> Options and clicking the "Retry..." button to change your retry limits to something smaller to mitigate the amount of status window spam from failed attempts, and also this will allow ON *:CONNECTFAIL to trigger faster instead of having to burn through a ton of retry attempts to fire.

Here is a quick-n-dirty solution that achieves the effect you're after, it could use some refinement but serves as a nice example. Some examples would be determining $1- from CONNECTFAIL to avoid triggering this on cases like connection refused, prolly only wanna trigger this on connection messages like "Unable to resolve server". Again, it's quick and dirty, just a means of showing how you might go about implementing this yourself.

Code
on *:CONNECTFAIL: { InternetTest }
alias ITest.RegRead { .comopen wsh WScript.shell | noop $com(wsh,regread,1,bstr,HKLM\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\ $+ $1) $com(wsh,&r).result | .comclose wsh | return $bvar(&r,1-).text }
alias InternetTest { noop $urlget($+(http://,$ITest.RegRead(ActiveWebProbeHost),/,$ITest.RegRead(ActiveWebProbePath)),bgk,&ConnectionTest,IsInternetConnected $ITest.RegRead(ActiveWebProbeContent)) }
alias IsInternetConnected {
  var %id = $($+($,$0),2) , %pass = 0
  if ($urlget(%id).state == ok) && ($bvar($urlget(%id).target,1-).text === $($+($,1-,$calc($0 -1)),2)) { inc %pass }
  if (!%pass) { .timerITest 1 $ITest.RegRead(PassivePollPeriod) InternetTest }
  else { scon -at2 server }
}


I'm on Windows 10, so just in-case you aren't or this does not work for you, slight modification to remove the registry key/value pairs I query just-in-case some windows update changes these values (You never know, it's changed a few times since Win7) here's the appropriate data from my registry on Windows 10 to replace the $Itest.RegRead() calls and hard-code these values into the script.

replace: $+(http://,$ITest.RegRead(ActiveWebProbeHost),/,$ITest.RegRead(ActiveWebProbePath))
with: http://www.msftconnecttest.com/connecttest.txt

Replace: $ITest.RegRead(ActiveWebProbeContent)
with: Microsoft Connect Test

Replace: $ITest.RegRead(PassivePollPeriod)
with: 15

The above script triggers a timer when mIRC fires the CONNECTFAIL event to wait the PollPeriod and attempt a http request, and verifies a proper return to determine if you are truely connected or not. If the urlget fails or the return is invalid, it re-initializes the timer to wait again the PollPeriod and attempt to verify internet access again. If this check passes, both return ok and the data matches, it will attempt to re-connect any non-connected status windows via /scon -at2 (a means all, t2 means not connected)
© mIRC Discussion Forums