Skip to content

Commit

Permalink
.: Fixed: minimize to tray after display scaling change
Browse files Browse the repository at this point in the history
.: Fixed: checks for null pointers in Kademlia code
.: Fixed: after initial bootstrap KAD contacts list stopped updating (regression)
.: Changed: expanded tooltip to 128 characters
.: Changed: reuse source exchange socket for downloading (thanks to Enig123)
.: Changed: minor dialogs optimizations
.: Removed: unused HyperTextCtrl.* files
  • Loading branch information
irwir committed Jul 29, 2017
1 parent 91d04f3 commit 5a130f9
Show file tree
Hide file tree
Showing 132 changed files with 1,102 additions and 3,254 deletions.
2 changes: 1 addition & 1 deletion 3DPreviewControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void C3DPreviewControl::SetSliderPos(int iPos)
{
if ( iPos <= 5 && iPos >= -5)
{
m_iSliderPos = iPos;
m_iSliderPos = iPos;
}
if ( GetSafeHwnd() )
{
Expand Down
4 changes: 2 additions & 2 deletions AddSourceDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ void CAddSourceDlg::OnBnClickedButton1()
return;
}

uint32 ip;
if ((ip = inet_addr(CT2CA(sip))) == INADDR_NONE && _tcscmp(sip, _T("255.255.255.255")) != 0)
uint32 ip = inet_addr(CT2CA(sip));
if (ip == INADDR_NONE && _tcscmp(sip, _T("255.255.255.255")) != 0)
ip = 0;
if (IsGoodIPPort(ip, port))
{
Expand Down
10 changes: 5 additions & 5 deletions AddSourceDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ class CAddSourceDlg : public CResizableDialog

DECLARE_MESSAGE_MAP()
afx_msg void OnBnClickedRadio1();
afx_msg void OnBnClickedRadio2();
afx_msg void OnBnClickedRadio3();
// afx_msg void OnBnClickedRadio2();
// afx_msg void OnBnClickedRadio3();
afx_msg void OnBnClickedRadio4();
afx_msg void OnBnClickedRadio5();
afx_msg void OnBnClickedRadio6();
afx_msg void OnBnClickedRadio7();
// afx_msg void OnBnClickedRadio5();
// afx_msg void OnBnClickedRadio6();
// afx_msg void OnBnClickedRadio7();
afx_msg void OnBnClickedButton1();
afx_msg void OnBnClickedOk();
};
5 changes: 3 additions & 2 deletions ArchivePreviewDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,9 @@ int CArchivePreviewDlg::ShowRarResults(int succ, archiveScannerThreadParams_s* t
temp+=_T('M');
}

if (!temp.IsEmpty()) temp+=_T(", ");
temp.AppendFormat(_T("L%i"),block->METHOD-0x30);
if (!temp.IsEmpty())
temp+=_T(", ");
temp.AppendFormat(_T("L%u"),block->METHOD-0x30u);

m_ContentList.SetItemText(iItem,uSubId++,temp);

Expand Down
23 changes: 12 additions & 11 deletions ArchiveRecovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ bool CArchiveRecovery::recoverZip(CFile *zipInput, CFile *zipOutput, archiveScan
writeUInt32(zipOutput, (uint32)(endOffset - startOffset));
writeUInt32(zipOutput, (uint32)startOffset);
writeUInt16(zipOutput, (uint16)strlen(ZIP_COMMENT));
zipOutput->Write(ZIP_COMMENT, strlen(ZIP_COMMENT));
zipOutput->Write(ZIP_COMMENT, (UINT)strlen(ZIP_COMMENT));

centralDirectoryEntries->RemoveAll();
}
Expand Down Expand Up @@ -1582,9 +1582,8 @@ void CArchiveRecovery::ISOReadDirectory(archiveScannerThreadParams_s* aitp, UINT
// read directory entries
int iSecsOfDirectoy = -1;

if (!aitp || !aitp->ai ||
!IsFilled(startSec * aitp->ai->isoInfos.secSize, (startSec * aitp->ai->isoInfos.secSize) + aitp->ai->isoInfos.secSize,
aitp->filled))
if (!aitp || !aitp->ai
|| !IsFilled(startSec * aitp->ai->isoInfos.secSize, (startSec * aitp->ai->isoInfos.secSize) + aitp->ai->isoInfos.secSize, aitp->filled))
return;

isoInput->Seek(startSec * (LONGLONG)aitp->ai->isoInfos.secSize, FILE_BEGIN);
Expand All @@ -1601,18 +1600,20 @@ void CArchiveRecovery::ISOReadDirectory(archiveScannerThreadParams_s* aitp, UINT
// do we continue at next sector?
if (iSecsOfDirectoy-- > 1) {
startSec++;
if (!IsFilled( startSec * aitp->ai->isoInfos.secSize, (startSec * aitp->ai->isoInfos.secSize) + aitp->ai->isoInfos.secSize,
aitp->filled))
break;
if (!IsFilled( startSec * aitp->ai->isoInfos.secSize, (startSec * aitp->ai->isoInfos.secSize) + aitp->ai->isoInfos.secSize, aitp->filled))
break;

isoInput->Seek(startSec * (LONGLONG)aitp->ai->isoInfos.secSize, FILE_BEGIN);
continue;
} else
break; // folder end
}
break; // folder end
}

file->name = (TCHAR*)calloc(file->nameLen+2, sizeof(TCHAR));

if (!file->name) {
delete file;
return;
}
blocksize += isoInput->Read(file->name, file->nameLen);

if (!(file->nameLen & 1))
Expand Down Expand Up @@ -1769,7 +1770,7 @@ bool CArchiveRecovery::recoverISO(CFile *isoInput, CFile *isoOutput, archiveScan

// read root directory of iso and recursive
ISO_FileFolderEntry rootdir;
memcpy(&rootdir, svd.descr_type!=0xff?svd.rootdir:pvd.rootdir, 33);
memcpy(&rootdir.lenRecord, svd.descr_type!=0xff ? svd.rootdir : pvd.rootdir, 33);

ISOReadDirectory(aitp, LODWORD(rootdir.sector1OfExtension), isoInput, _T("") );
}
Expand Down
4 changes: 2 additions & 2 deletions AsyncProxySocketLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ class CAsyncProxySocketLayer : public CAsyncSocketExLayer
u_long m_nProxyPeerIP; //IP of the server you are connected to, retrieve via GetPeerName
typedef struct
{
int nProxyType;
CStringA strProxyHost;
int nProxyPort;
CStringA strProxyUser;
CStringA strProxyPass;
int nProxyType;
int nProxyPort;
BOOL bUseLogon;
} t_proxydata; //This structure will be used to hold the proxy details
t_proxydata m_ProxyData;//Structure to hold the data set by SetProxy
Expand Down
9 changes: 3 additions & 6 deletions BaseClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,12 @@ bool CUpDownClient::ProcessHelloTypePacket(CSafeMemFile* data)
free(m_pszUsername);
m_pszUsername = _tcsdup(temptag.GetStr());
if (bDbgInfo) {
if (m_pszUsername) {//filter username for bad chars
TCHAR* psz = m_pszUsername;
while (*psz != _T('\0')) {
if (m_pszUsername) { //filter username for bad chars
for (TCHAR* psz = m_pszUsername; *psz != _T('\0'); ++psz)
if (*psz == _T('\n') || *psz == _T('\r'))
*psz = _T(' ');
psz++;
}
m_strHelloInfo.AppendFormat(_T("\n Name='%s'"), m_pszUsername);
}
m_strHelloInfo.AppendFormat(_T("\n Name='%s'"), m_pszUsername);
}
}
else if (bDbgInfo)
Expand Down
7 changes: 2 additions & 5 deletions CatDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,9 @@ void CCatDialog::OnBnClickedOk()
OnOK();
}

LRESULT CCatDialog::OnSelChange(WPARAM wParam, LPARAM lParam)
LRESULT CCatDialog::OnSelChange(WPARAM wParam, LPARAM /*lParam*/)
{
if (wParam == CLR_DEFAULT)
newcolor = (DWORD)-1;
else
newcolor = m_ctlColor.GetColor();
newcolor = (wParam == CLR_DEFAULT) ? (DWORD)-1 : m_ctlColor.GetColor();
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion CatDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CCatDialog : public CDialog
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

DECLARE_MESSAGE_MAP()
afx_msg LRESULT OnSelChange(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnSelChange(WPARAM wParam, LPARAM /*lParam*/);
afx_msg void OnBnClickedBrowse();
afx_msg void OnBnClickedOk();
afx_msg void OnDDBnClicked();
Expand Down
103 changes: 41 additions & 62 deletions ClientList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,17 @@ static char THIS_FILE[] = __FILE__;
#endif


CClientList::CClientList(){
m_dwLastBannCleanUp = 0;
m_dwLastTrackedCleanUp = 0;
m_dwLastClientCleanUp = 0;
m_nBuddyStatus = Disconnected;
CClientList::CClientList()
: m_nBuddyStatus(Disconnected), m_pBuddy(NULL)
{
m_dwLastBannCleanUp = m_dwLastTrackedCleanUp = m_dwLastClientCleanUp = ::GetTickCount();
m_bannedList.InitHashTable(331);
m_trackedClientsList.InitHashTable(2011);
m_globDeadSourceList.Init(true);
m_pBuddy = NULL;
}

CClientList::~CClientList(){
CClientList::~CClientList()
{
RemoveAllTrackedClients();
}

Expand All @@ -70,7 +69,7 @@ void CClientList::GetStatistics(uint32 &ruTotalClients, int stats[NUM_CLIENTLIST
CMap<uint32, uint32, uint32, uint32>& clientVersionAMule)
{
ruTotalClients = list.GetCount();
memset(stats, 0, sizeof(stats[0]) * NUM_CLIENTLIST_STATS);
memset(stats, 0, NUM_CLIENTLIST_STATS*sizeof stats[0]);

for (POSITION pos = list.GetHeadPosition(); pos != NULL; )
{
Expand Down Expand Up @@ -138,14 +137,10 @@ void CClientList::GetStatistics(uint32 &ruTotalClients, int stats[NUM_CLIENTLIST
if (cur_client->GetDownloadState()==DS_ERROR)
stats[6]++; // Error

switch (cur_client->GetUserPort())
{
case 4662:
stats[8]++; // Default Port
break;
default:
stats[9]++; // Other Port
}
if (cur_client->GetUserPort() == 4662)
++stats[8]; // Default Port
else
++stats[9]; // Other Port

// Network client stats
if (cur_client->GetServerIP() && cur_client->GetServerPort())
Expand Down Expand Up @@ -335,7 +330,7 @@ CUpDownClient* CClientList::FindClientByServerID(uint32 uServerIP, uint32 uED2KU
uint32 uHybridUserID = ntohl(uED2KUserID);
for (POSITION pos = list.GetHeadPosition(); pos != NULL;)
{
CUpDownClient* cur_client = list.GetNext(pos);
CUpDownClient* cur_client = list.GetNext(pos);
if (cur_client->GetServerIP() == uServerIP && cur_client->GetUserIDHybrid() == uHybridUserID)
return cur_client;
}
Expand All @@ -354,11 +349,7 @@ void CClientList::AddBannedClient(uint32 dwIP)
bool CClientList::IsBannedClient(uint32 dwIP) const
{
uint32 dwBantime;
if (m_bannedList.Lookup(dwIP, dwBantime)){
if (dwBantime + CLIENTBANTIME > ::GetTickCount())
return true;
}
return false;
return m_bannedList.Lookup(dwIP, dwBantime) && (dwBantime + CLIENTBANTIME > ::GetTickCount());
}

void CClientList::RemoveBannedClient(uint32 dwIP)
Expand Down Expand Up @@ -546,7 +537,7 @@ void CClientList::Process()
else {
if (thePrefs.GetDebugClientKadUDPLevel() > 0)
DebugSend("KADEMLIA_FIREWALLED_ACK_RES", cur_client->GetIP(), cur_client->GetKadPort());
Kademlia::CKademlia::GetUDPListener()->SendNullPacket(KADEMLIA_FIREWALLED_ACK_RES, ntohl(cur_client->GetIP()), cur_client->GetKadPort(), 0, NULL);
Kademlia::CKademlia::GetUDPListener()->SendNullPacket(KADEMLIA_FIREWALLED_ACK_RES, ntohl(cur_client->GetIP()), cur_client->GetKadPort(), Kademlia::CKadUDPKey(0), NULL);
}
//We are done with this client. Set Kad status to KS_NONE and it will be removed in the next cycle.
if (cur_client != NULL)
Expand Down Expand Up @@ -698,15 +689,13 @@ void CClientList::Process()
void CClientList::Debug_SocketDeleted(CClientReqSocket* deleted) const
{
for (POSITION pos = list.GetHeadPosition(); pos != NULL;){
CUpDownClient* cur_client = list.GetNext(pos);
if (!AfxIsValidAddress(cur_client, sizeof(CUpDownClient))) {
CUpDownClient* cur_client = list.GetNext(pos);
if (!AfxIsValidAddress(cur_client, sizeof CUpDownClient))
AfxDebugBreak();
}
if (thePrefs.m_iDbgHeap >= 2)
ASSERT_VALID(cur_client);
if (cur_client->socket == deleted){
if (cur_client->socket == deleted)
AfxDebugBreak();
}
}
}
#endif
Expand Down Expand Up @@ -785,11 +774,11 @@ bool CClientList::IncomingBuddy(Kademlia::CContact* contact, Kademlia::CUInt128*
//Although the odds of this happening is very small, it could still happen.
if (FindClientByIP(nContactIP, contact->GetTCPPort()))
return false;
else if (IsKadFirewallCheckIP(nContactIP)){ // doing a kad firewall check with this IP, abort
if (IsKadFirewallCheckIP(nContactIP)) { // doing a kad firewall check with this IP, abort
DEBUG_ONLY( DebugLogWarning(_T("KAD tcp Firewallcheck / Buddy request collosion for IP %s"), (LPCTSTR)ipstr(nContactIP)) );
return false;
}
else if (theApp.serverconnect->GetLocalIP() == nContactIP && thePrefs.GetPort() == contact->GetTCPPort())
if (theApp.serverconnect->GetLocalIP() == nContactIP && thePrefs.GetPort() == contact->GetTCPPort())
return false; // don't connect ourself

//Add client to the lists to be processed.
Expand Down Expand Up @@ -819,15 +808,10 @@ void CClientList::RemoveFromKadList(CUpDownClient* torem){
}
}

void CClientList::AddToKadList(CUpDownClient* toadd){
if(!toadd)
return;
POSITION pos = m_KadList.Find(toadd);
if(pos)
{
return;
}
m_KadList.AddTail(toadd);
void CClientList::AddToKadList(CUpDownClient* toadd)
{
if (toadd && !m_KadList.Find(toadd))
m_KadList.AddTail(toadd);
}

bool CClientList::DoRequestFirewallCheckUDP(const Kademlia::CContact& contact){
Expand Down Expand Up @@ -920,22 +904,20 @@ void CClientList::ProcessA4AFClients() const {
}
// <-- ZZ:DownloadManager

void CClientList::AddKadFirewallRequest(uint32 dwIP){
IPANDTICS add = {dwIP, ::GetTickCount()};
listFirewallCheckRequests.AddHead(add);
while (!listFirewallCheckRequests.IsEmpty()){
if (::GetTickCount() - listFirewallCheckRequests.GetTail().dwInserted > SEC2MS(180))
listFirewallCheckRequests.RemoveTail();
else
break;
}
void CClientList::AddKadFirewallRequest(uint32 dwIP)
{
DWORD tick = ::GetTickCount();
listFirewallCheckRequests.AddHead(IPANDTICS{dwIP, tick});
while (!listFirewallCheckRequests.IsEmpty() && tick > listFirewallCheckRequests.GetTail().dwInserted+SEC2MS(180))
listFirewallCheckRequests.RemoveTail();
}

bool CClientList::IsKadFirewallCheckIP(uint32 dwIP) const{
const DWORD tick = ::GetTickCount() - SEC2MS(180);
bool CClientList::IsKadFirewallCheckIP(uint32 dwIP) const
{
const DWORD tick = ::GetTickCount();
for (POSITION pos = listFirewallCheckRequests.GetHeadPosition(); pos != NULL;) {
const IPANDTICS& iptick = listFirewallCheckRequests.GetNext(pos);
if (iptick.dwIP == dwIP && tick < iptick.dwInserted)
if (iptick.dwIP == dwIP && tick < iptick.dwInserted+SEC2MS(180))
return true;
}
return false;
Expand Down Expand Up @@ -979,23 +961,20 @@ void CClientList::RemoveConnectingClient(CUpDownClient* pToRemove){
}
}

void CClientList::AddTrackCallbackRequests(uint32 dwIP){
IPANDTICS add = {dwIP, ::GetTickCount()};
listDirectCallbackRequests.AddHead(add);
while (!listDirectCallbackRequests.IsEmpty()){
if (add.dwInserted > listDirectCallbackRequests.GetTail().dwInserted + MIN2MS(3))
listDirectCallbackRequests.RemoveTail();
else
break;
}
void CClientList::AddTrackCallbackRequests(uint32 dwIP)
{
DWORD tick = ::GetTickCount();
listDirectCallbackRequests.AddHead(IPANDTICS{dwIP, tick});
while (!listDirectCallbackRequests.IsEmpty() && tick > listDirectCallbackRequests.GetTail().dwInserted+SEC2MS(180))
listDirectCallbackRequests.RemoveTail();
}

bool CClientList::AllowCalbackRequest(uint32 dwIP) const
{
const DWORD tick = ::GetTickCount() - MIN2MS(3);
const DWORD tick = ::GetTickCount();
for (POSITION pos = listDirectCallbackRequests.GetHeadPosition(); pos != NULL;) {
const IPANDTICS& iptick = listDirectCallbackRequests.GetNext(pos);
if (iptick.dwIP == dwIP && tick < iptick.dwInserted)
if (iptick.dwIP == dwIP && tick < iptick.dwInserted+SEC2MS(180))
return false;
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions ClientList.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class CClientList
// Clients
void AddClient(CUpDownClient* toadd,bool bSkipDupTest = false);
void RemoveClient(CUpDownClient* toremove, LPCTSTR pszReason = NULL);
void GetStatistics(uint32& totalclient, int stats[NUM_CLIENTLIST_STATS],
void GetStatistics(uint32& ruTotalClients, int stats[NUM_CLIENTLIST_STATS],
CMap<uint32, uint32, uint32, uint32>& clientVersionEDonkey,
CMap<uint32, uint32, uint32, uint32>& clientVersionEDonkeyHybrid,
CMap<uint32, uint32, uint32, uint32>& clientVersionEMule,
Expand All @@ -86,7 +86,7 @@ class CClientList
CUpDownClient* FindClientByUserHash(const uchar* clienthash, uint32 dwIP = 0, uint16 nTCPPort = 0) const;
CUpDownClient* FindClientByIP(uint32 clientip) const;
CUpDownClient* FindClientByIP_UDP(uint32 clientip, UINT nUDPport) const;
CUpDownClient* FindClientByServerID(uint32 uServerIP, uint32 uUserID) const;
CUpDownClient* FindClientByServerID(uint32 uServerIP, uint32 uED2KUserID) const;
CUpDownClient* FindClientByUserID_KadPort(uint32 clientID,uint16 kadPort) const;
CUpDownClient* FindClientByIP_KadPort(uint32 ip, uint16 port) const;

Expand Down
Loading

0 comments on commit 5a130f9

Please sign in to comment.