Patch level : 4.0.0

Files correlati     : setup.exe
Ricompilazione Demo : [ ]
Commento            :
Corretta ricerca server remoti


git-svn-id: svn://10.65.10.50/trunk@15620 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2007-09-14 15:43:08 +00:00
parent 144a07f646
commit 22af546170
2 changed files with 132 additions and 136 deletions

View File

@ -28,6 +28,7 @@
///////////////////////////////////////////////////////////
// Utilities
///////////////////////////////////////////////////////////
wxString GetDefaultDestination()
{
wxString strDest;
@ -56,79 +57,6 @@ wxString GetDefaultDestination()
return strDest;
}
class CampoDirCopier : public wxDirTraverser
{
wxString m_strSrc, m_strDst;
protected:
virtual wxDirTraverseResult OnDir(const wxString& dirname);
virtual wxDirTraverseResult OnFile(const wxString& filename);
public:
void RenameDLL(const wxString& strDLL, bool bOpenGL) const;
bool Copy(const wxString& src, const wxString& dst, bool bOpenGL);
};
wxDirTraverseResult CampoDirCopier::OnDir(const wxString& dirname)
{
return wxDIR_CONTINUE;
}
wxDirTraverseResult CampoDirCopier::OnFile(const wxString& filename)
{
wxFileName strSource(filename);
strSource.MakeRelativeTo(m_strSrc);
wxString str = m_strDst;
str += strSource.GetPathSeparator();
str += strSource.GetFullPath();
wxFileName strDest(str);
if (!strDest.DirExists())
strDest.Mkdir();
::wxCopyFile(filename, str);
return wxDIR_CONTINUE;
}
void CampoDirCopier::RenameDLL(const wxString& strDLL, bool bOpenGL) const
{
wxFileName file1(m_strDst, strDLL);
file1.SetExt(bOpenGL ? wxT("dll") : wxT("old"));
if (file1.FileExists())
{
wxFileName file2(file1);
file2.SetExt(bOpenGL ? wxT("old") : wxT("dll"));
wxRename(file1.GetFullPath(), file2.GetFullPath());
}
}
bool CampoDirCopier::Copy(const wxString& src, const wxString& dst, bool bOpenGL)
{
wxBusyCursor hourglass;
m_strSrc = src;
m_strDst = dst;
if (!wxDirExists(m_strDst)) // Utile precauzione
wxMkdir(m_strDst);
wxDir dir(m_strSrc);
dir.Traverse(*this);
RenameDLL(wxT("OpenGL32.dll"), bOpenGL);
RenameDLL(wxT("glu32.dll"), bOpenGL);
return true;
}
#ifdef WIN32
#endif
///////////////////////////////////////////////////////////
// CampoWizardPage
///////////////////////////////////////////////////////////
@ -158,10 +86,11 @@ class CampoWizard : public wxWizard
protected:
DECLARE_EVENT_TABLE();
int Pages() const { return m_nPages; }
CampoWizardPage* Page(int p) const { return m_pPage[p]; }
void OnNext(wxCommandEvent& e);
int Pages() const { return m_nPages; }
CampoWizardPage& Page(int p) const { wxASSERT(p >= 0 && p < m_nPages); return *m_pPage[p]; }
public:
bool Run();
wxString Get(wxWindowID id) const;
@ -631,16 +560,25 @@ void CampoWizardPage4::OnEUPick(wxCommandEvent& e)
void CampoWizardPage4::OnSRPick(wxCommandEvent& e)
{
wxString strSrvName;
int year = 0;
unsigned short serno = ServerLogin(year, strSrvName);
if (!strSrvName.IsEmpty())
Set(404, strSrvName);
static bool bSemaforo = false;
if (!bSemaforo)
{
bSemaforo = true;
wxBusyCursor hourglass;
wxString strSrvName;
int year = 0;
unsigned short serno = ServerLogin(year, strSrvName);
if (!strSrvName.IsEmpty())
Set(404, strSrvName);
bSemaforo = false;
}
}
bool CampoWizardPage4::ForwardValidate()
{
//per poter proseguire deve aver trovato una chiave o un server!
GetWizard().SetSrvAuth(Get(404));
int nDongleType = DongleTest();
if (nDongleType == 0)
return ErrorBox("Per proseguire e' NECESSARIO installare una chiave locale o collegarsi ad una chiave di rete!");
@ -1559,7 +1497,7 @@ void CampoWizard::OnNext(wxCommandEvent& e)
}
bool CampoWizard::Run()
{ return RunWizard(Page(0)); }
{ return RunWizard(m_pPage[0]); }
wxString CampoWizard::Get(wxWindowID id) const
{
@ -1778,6 +1716,18 @@ CampoWizard::CampoWizard(wxWindow* pParent)
wxWizardPageSimple::Chain(m_pPage[p-1], m_pPage[p]);
GetPageAreaSizer()->Add(m_pPage[0]);
wxWindow* pNext = FindWindowById(wxID_FORWARD);
if (pNext != NULL)
pNext->SetLabel("Continua");
wxWindow* pPrev = FindWindowById(wxID_BACKWARD);
if (pPrev != NULL)
pPrev->SetLabel("C'ho ripensato");
wxWindow* pCancel = FindWindowById(wxID_CANCEL);
if (pCancel != NULL)
pCancel->SetLabel("Mittico! Ma vaff...");
}

View File

@ -1,5 +1,4 @@
#include "wxinc.h"
#include <wx/socket.h>
#include "setupkey.h"
@ -10,7 +9,6 @@ extern "C"
#include "../xvaga/skeylink.h"
}
///////////////////////////////
// Utilities //
///////////////////////////////
@ -144,16 +142,82 @@ unsigned short EutronLogin(int& year)
return serno;
}
//////////////////////////////////
// Gestione Server di chiavi //
//////////////////////////////////
class TBordello
{
WX_DECLARE_STRING_HASH_MAP(wxSocketClient*, TBrothel);
TBrothel m_map;
public:
wxSocketClient& Zoccola(wxIPV4address& ip);
wxSocketClient* QuellaBuona();
void Chiudi();
virtual ~TBordello();
} m_bordello;
wxSocketClient& TBordello::Zoccola(wxIPV4address& ip)
{
const wxString strIP = ip.IPAddress();
if (m_map[strIP] == NULL)
{
m_map[strIP] = new wxSocketClient;
m_map[strIP]->SetTimeout(2);
}
return *m_map[strIP];
}
wxSocketClient* TBordello::QuellaBuona()
{
wxSocketClient* good = NULL;
for(TBrothel::iterator it = m_map.begin(); it != m_map.end(); ++it )
{
wxSocketClient* sc = (wxSocketClient*)it->second;
if (sc != NULL)
{
sc->WaitOnConnect(0, 1);
if (sc->IsConnected())
{
good = sc;
break;
}
}
}
return good;
}
void TBordello::Chiudi()
{
for(TBrothel::iterator it = m_map.begin(); it != m_map.end(); ++it )
{
wxSocketClient* sc = (wxSocketClient*)it->second;
if (sc != NULL)
sc->Close();
}
}
TBordello::~TBordello()
{
/* Non funziona per oggetti statici
for(TBrothel::iterator it = m_map.begin(); it != m_map.end(); ++it )
{
wxSocketClient* sc = (wxSocketClient*)it->second;
sc->Destroy();
}
*/
m_map.clear();
}
//////////////////////////////////
// Gestione Server di chiavi //
//////////////////////////////////
static unsigned short InquireSocketNumber(wxSocketClient& sc, const wxString& strCommand)
{
sc.Write(strCommand, (wxUint32)strCommand.Len());
long number[2] = { 0L, 0L };
sc.Read(number, sizeof(number));
return (unsigned short)number[1];
sc.Discard();
sc.Write(strCommand, (wxUint32)strCommand.Len());
long number[2] = { 0L, 0L };
sc.Read(number, sizeof(number));
return (unsigned short)number[1];
}
static unsigned short InquireServer(const wxString& strSrvName, int& year, const bool bMsg)
@ -169,13 +233,12 @@ static unsigned short InquireServer(const wxString& strSrvName, int& year, const
return serno;
}
wxSocketClient* sc = new wxSocketClient;
sc->SetTimeout(2);
if (sc->Connect(ip)) //il computer remoto risponde ma il server no (non c'e' o e' spento)
wxSocketClient& sc = m_bordello.Zoccola(ip);
if (sc.IsConnected() || sc.Connect(ip)) //il computer remoto risponde
{
serno = InquireSocketNumber(*sc, "DongleNumber()");
year = InquireSocketNumber(*sc, "DongleYear()");
sc->Discard();
// ma il server e' davvero acceso o spento ?
serno = InquireSocketNumber(sc, "DongleNumber()");
year = InquireSocketNumber(sc, "DongleYear()");
}
else
{
@ -187,7 +250,6 @@ static unsigned short InquireServer(const wxString& strSrvName, int& year, const
}
}
sc->Destroy();
return serno;
}
@ -208,51 +270,35 @@ unsigned short ServerLogin(int& year, wxString& strSrvName)
if (strMyIP.Len() > 7)
{
const unsigned short MaxSck = 256;
// for (int j = 3; j < 256 && serno == 0xFFFF; j += MaxSck)
for (int i = 0; i < MaxSck; i++)
{
wxSocketClient* sc[MaxSck];
memset(sc, 0, sizeof(sc));
wxIPV4address ipRemote[MaxSck];
for (int i = 0; i < MaxSck; i++)
//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; //ip del computer remoto
if (strSrvIP != strMyIP)
{
const int n = i; //+j;
if (n < 256)
wxIPV4address ipRemote;
if (ipRemote.Hostname(strSrvIP) && ipRemote.Service("1883"))
{
//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] = new wxSocketClient;
sc[i]->SetTimeout(2);
sc[i]->Connect(ipRemote[i], false);
}
wxSocketClient& sc = m_bordello.Zoccola(ipRemote);
if (!sc.IsConnected())
sc.Connect(ipRemote, ipLocal, false);
}
}
wxMilliSleep(100);
for (int i = 0; i < MaxSck; i++) if (sc[i])
{
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()");
sc[i]->Discard();
if (year > 0)
break;
}
sc[i]->Close();
} //for (inti =0...
for (int i = 0; i < MaxSck; i++) if (sc[i])
sc[i]->Destroy();
} //for(int j=0...
}
wxSleep(2);
wxSocketClient* sc = m_bordello.QuellaBuona();
if (sc != NULL)
{
wxIPV4address ipRemote;
sc->GetPeer(ipRemote);
strSrvName = ipRemote.Hostname();
}
} //if(strMyIP.Len()...
} //if(strSrvName.Is...
else
if (!strSrvName.IsEmpty())
serno = InquireServer(strSrvName, year, true);
return serno;