diff --git a/setup/Setup.cpp b/setup/Setup.cpp index 5e5faeff9..55b4d8589 100755 --- a/setup/Setup.cpp +++ b/setup/Setup.cpp @@ -1232,6 +1232,12 @@ void CampoWizardPage8::OnSrvClick(wxCommandEvent& e) bool CampoWizardPage8::TransferDataToWindow() { + const wxString strSrvAuth = GetWizard().GetSrvAuth(); + if (!strSrvAuth.IsEmpty()) + { + Set(808, strSrvAuth); + FindWindowById(808)->Disable(); + } return true; } diff --git a/setup/setupkey.cpp b/setup/setupkey.cpp index 9b0330000..9122b23a6 100755 --- a/setup/setupkey.cpp +++ b/setup/setupkey.cpp @@ -162,23 +162,29 @@ static unsigned short InquireServer(const wxString& strSrvName, int& year, const wxSocketClient sc; sc.SetTimeout(2); + sc.SetFlags(sc.GetFlags() | wxSOCKET_REUSEADDR); if (!sc.Connect(ip)) //il computer remoto risponde ma il server no (non c'e' o e' spento) { if (bMsg) - ErrorBox("Il server specificato non e' raggiungibile!"); + { + wxString strMsg; + strMsg << "Il server " << strSrvName << " non e' raggiungibile!"; + ErrorBox(strMsg); + } return 0xFFFF; } unsigned short serno = InquireSocketNumber(sc, "DongleNumber()"); year = InquireSocketNumber(sc, "DongleYear()"); + sc.Destroy(); return serno; } unsigned short ServerLogin(int& year, wxString& strSrvName) { unsigned short serno = 0xFFFF; - + //se non specificato un nome/indirizzo di server, lo cerca tra i miei "cpu fratelli" in rete if (strSrvName.IsEmpty()) { @@ -191,39 +197,48 @@ unsigned short ServerLogin(int& year, wxString& strSrvName) if (strMyIP.Len() > 7) { - wxSocketClient sc[256]; - for (int i = 0; i < 256; i++) + const unsigned short MaxSck = 6; + for (int j = 3; j < 256 && serno == 0xFFFF; j += MaxSck) { - //deve sostituire l'ultima cifra dell'IP con tutti i numeri che vanno da 0 a 255 alla ricerca del server - wxString strSrvIP = strMyIP.BeforeLast('.'); - strSrvIP << "." << i; - wxIPV4address ipRemote; - if (ipRemote.Hostname(strSrvIP) && ipRemote.Service("1883")) + wxSocketClient sc[MaxSck]; + wxIPV4address ipRemote[MaxSck]; + for (int i = 0; i < MaxSck; i++) { - sc[i].SetTimeout(2); - sc[i].Connect(ipRemote, false); + const int n = i+j; + if (n < 256) + { + //deve sostituire l'ultima cifra dell'IP con tutti i numeri che vanno da 0 a 255 alla ricerca del server + wxString strSrvIP = strMyIP.BeforeLast('.'); + strSrvIP << "." << n; //ip del computer remoto + if (strSrvIP == strMyIP) + continue; + if (ipRemote[i].Hostname(strSrvIP) && ipRemote[i].Service("1883")) + { + sc[i].SetTimeout(2); + sc[i].SetFlags(sc[i].GetFlags() | wxSOCKET_REUSEADDR); + sc[i].Connect(ipRemote[i], false); + } + } } - } - wxSleep(2); - for (int i = 0; i < 256; i++) - { - sc[i].WaitOnConnect(0, 10); - if (sc[i].IsConnected()) + wxMilliSleep(100); + for (int i = 0; i < MaxSck; i++) { - wxIPV4address ipRemote; - sc[i].GetPeer(ipRemote); - strSrvName = ipRemote.Hostname(); - serno = InquireSocketNumber(sc[i], "DongleNumber()"); - year = InquireSocketNumber(sc[i], "DongleYear()"); - if (year > 0) - break; - } - } - - for (int i = 0; i < 256; i++) - sc[i].Destroy(); - } - } + sc[i].WaitOnConnect(0, 1); + if (sc[i].IsConnected()) + { + sc[i].GetPeer(ipRemote[i]); + strSrvName = ipRemote[i].Hostname(); + serno = InquireSocketNumber(sc[i], "DongleNumber()"); + year = InquireSocketNumber(sc[i], "DongleYear()"); + if (year > 0) + break; + } + } //for (inti =0... + for (int i = 0; i < MaxSck; i++) + sc[i].Destroy(); + } //for(int j=0... + } //if(strMyIP.Len()... + } //if(strSrvName.Is... else serno = InquireServer(strSrvName, year, true);