From 5ac6376f7cc0248cce8219519b2a7175d9eb1a8a Mon Sep 17 00:00:00 2001 From: upstream svn Date: Tue, 24 Feb 2009 00:26:56 +0100 Subject: [PATCH] Upstream tarball 9450 --- .svn-revision | 2 +- src/BaseClient.cpp | 66 +++++++++++++++++++------------------------------ src/CaptchaGenerator.h | 6 ++--- src/ClientTCPSocket.cpp | 2 +- src/updownclient.h | 63 ++++++++++++++++++++++------------------------ 5 files changed, 61 insertions(+), 78 deletions(-) diff --git a/.svn-revision b/.svn-revision index 38022909..da6b0d9a 100644 --- a/.svn-revision +++ b/.svn-revision @@ -1 +1 @@ -9449 +9450 diff --git a/src/BaseClient.cpp b/src/BaseClient.cpp index a191c9f8..db924c16 100644 --- a/src/BaseClient.cpp +++ b/src/BaseClient.cpp @@ -2618,10 +2618,9 @@ void CUpDownClient::ProcessCaptchaReqRes(uint8 nStatus) wxASSERT( nStatus < 3 ); m_nChatCaptchaState = CA_NONE; theApp->amuledlg->m_chatwnd->ShowCaptchaResult(id, nStatus == 0); - } - else { + } else { m_nChatCaptchaState = CA_NONE; - AddDebugLogLineN(logClient, CFormat(wxT("Received captcha result from client, but don't accepting it at this time (%s)")) % GetFullIP()); + AddDebugLogLineN(logClient, CFormat(wxT("Received captcha result from client, but not accepting it at this time (%s)")) % GetFullIP()); } } @@ -2634,19 +2633,15 @@ void CUpDownClient::ProcessChatMessage(wxString message) // advanced spamfilter check if (thePrefs::IsChatCaptchaEnabled() && !IsFriend()) { - // captcha checks outrank any further checks - if the captcha has been solved, we assume its no spam - // first check if we need to sent a captcha request to this client - if (GetMessagesSent() == 0 && GetMessagesReceived() == 0 && GetChatCaptchaState() != CA_CAPTCHASOLVED) - { + // captcha checks outrank any further checks - if the captcha has been solved, we assume it's not spam + // first check if we need to send a captcha request to this client + if (GetMessagesSent() == 0 && GetMessagesReceived() == 0 && GetChatCaptchaState() != CA_CAPTCHASOLVED) { // we have never sent a message to this client, and no message from him has ever passed our filters - if (GetChatCaptchaState() != CA_CHALLENGESENT) - { + if (GetChatCaptchaState() != CA_CHALLENGESENT) { // we also aren't currently expecting a captcha response - if (m_fSupportsCaptcha) - { - // and he supports captcha, so send him on and store the message (without showing for now) - if (m_cCaptchasSent < 3) // no more than 3 tries - { + if (m_fSupportsCaptcha) { + // and he supports captcha, so send him one and store the message (without showing for now) + if (m_cCaptchasSent < 3) { // no more than 3 tries m_strCaptchaPendingMsg = message; wxMemoryOutputStream memstr; memstr.PutC(0); // no tags, for future use @@ -2660,33 +2655,27 @@ void CUpDownClient::ProcessChatMessage(wxString message) theStats::AddUpOverheadOther(packet->GetPacketSize()); AddLogLineN(CFormat(wxT("sent Captcha %s (%d)")) % m_strCaptchaChallenge % packet->GetPacketSize()); SafeSendPacket(packet); - } - else{ - wxASSERT( false ); + } else { + wxFAIL; } } - } - else - { - // client doesn't supports captchas, but we require them, tell him that its not going to work out - // with an answer message (will not be shown and doesn't counts as sent message) - if (m_cCaptchasSent < 1) // dont sent this notifier more than once - { + } else { + // client doesn't support captchas, but we require them, tell him that it's not going to work out + // with an answer message (will not be shown and doesn't count as sent message) + if (m_cCaptchasSent < 1) { // don't send this notifier more than once m_cCaptchasSent++; // always sent in english SendChatMessage(wxT("In order to avoid spam messages, this user requires you to solve a captcha before you can send a message to him. However your client does not supports captchas, so you will not be able to chat with this user.")); AddDebugLogLineN(logClient, CFormat(wxT("Received message from client not supporting captchas, filtered and sent notifier (%s)")) % GetClientFullInfo()); } else { - AddDebugLogLineN(logClient, CFormat(wxT("Received message from client not supporting captchs, filtered, didn't sent notifier (%s)")) % GetClientFullInfo()); + AddDebugLogLineN(logClient, CFormat(wxT("Received message from client not supporting captchas, filtered, didn't send notifier (%s)")) % GetClientFullInfo()); } } return; - } - else //(GetChatCaptchaState() == CA_CHALLENGESENT) - { - // this message must be the answer to the captcha request we send him, lets verify + } else { // (GetChatCaptchaState() == CA_CHALLENGESENT) + // this message must be the answer to the captcha request we sent him, let's verify wxASSERT( !m_strCaptchaChallenge.IsEmpty() ); - if (m_strCaptchaChallenge.CmpNoCase(message.Trim().Right(std::min(message.Length(), m_strCaptchaChallenge.Length()))) == 0){ + if (m_strCaptchaChallenge.CmpNoCase(message.Trim().Right(std::min(message.Length(), m_strCaptchaChallenge.Length()))) == 0) { // allright AddDebugLogLineN(logClient, CFormat(wxT("Captcha solved, showing withheld message (%s)")) % GetClientFullInfo()); m_nChatCaptchaState = CA_CAPTCHASOLVED; // this state isn't persitent, but the messagecounter will be used to determine later if the captcha has been solved @@ -2699,14 +2688,13 @@ void CUpDownClient::ProcessChatMessage(wxString message) packet->CopyToDataBuffer(0, &statusResponse, 1); theStats::AddUpOverheadOther(packet->GetPacketSize()); SafeSendPacket(packet); - } - else{ // wrong, cleanup and ignore + } else { // wrong, cleanup and ignore AddDebugLogLineN(logClient, CFormat(wxT("Captcha answer failed (%s)")) % GetClientFullInfo()); m_nChatCaptchaState = CA_NONE; m_strCaptchaChallenge = wxEmptyString; m_strCaptchaPendingMsg = wxEmptyString; CPacket* packet = new CPacket(OP_CHATCAPTCHARES, 1, OP_EMULEPROT, false); - byte statusResponse = (m_cCaptchasSent < 3)? 1 : 2; // status response + byte statusResponse = (m_cCaptchasSent < 3) ? 1 : 2; // status response packet->CopyToDataBuffer(0, &statusResponse, 1); theStats::AddUpOverheadOther(packet->GetPacketSize()); SafeSendPacket(packet); @@ -2716,14 +2704,12 @@ void CUpDownClient::ProcessChatMessage(wxString message) } } - if (thePrefs::IsAdvancedSpamfilterEnabled() && !IsFriend()) // friends are never spammer... (but what if two spammers are friends :P ) - { + if (thePrefs::IsAdvancedSpamfilterEnabled() && !IsFriend()) { // friends are never spammer... (but what if two spammers are friends :P ) bool bIsSpam = false; if (m_fIsSpammer) { bIsSpam = true; } else { - - // first fixed criteria: If a client sends me an URL in his first message before I response to him + // first fixed criteria: If a client sends me an URL in his first message before I respond to him // there is a 99,9% chance that it is some poor guy advising his leech mod, or selling you .. well you know :P if (GetMessagesSent() == 0) { static wxArrayString urlindicators(wxStringTokenize(wxT("http:|www.|.de |.net |.com |.org |.to |.tk |.cc |.fr |ftp:|ed2k:|https:|ftp.|.info|.biz|.uk|.eu|.es|.tv|.cn|.tw|.ws|.nu|.jp"), wxT("|"))); @@ -2733,7 +2719,7 @@ void CUpDownClient::ProcessChatMessage(wxString message) break; } } - // second fixed criteria: he sent me 4 or more messages and I didn't answered him once + // second fixed criteria: he sent me 4 or more messages and I didn't answer him once if (GetMessagesReceived() > 3) { bIsSpam = true; } @@ -2752,9 +2738,9 @@ void CUpDownClient::ProcessChatMessage(wxString message) if(thePrefs::ShowMessagesInLog()) { logMsg += wxT(": ") + message; } - AddLogLineM( true, logMsg); + AddLogLineM(true, logMsg); IncMessagesReceived(); - + Notify_ChatProcessMsg(GUI_ID(GetIP(), GetUserPort()), GetUserName() + wxT("|") + message); } diff --git a/src/CaptchaGenerator.h b/src/CaptchaGenerator.h index ad6309cf..cef547c8 100644 --- a/src/CaptchaGenerator.h +++ b/src/CaptchaGenerator.h @@ -37,9 +37,9 @@ class CCaptchaGenerator public: CCaptchaGenerator(uint32 nLetterCount = 4); - void ReGenerateCaptcha(uint32 nLetterCount = 4); - wxString GetCaptchaText() const {return m_strCaptchaText;} - bool WriteCaptchaImage(wxMemoryOutputStream& file); + void ReGenerateCaptcha(uint32 nLetterCount = 4); + wxString GetCaptchaText() const { return m_strCaptchaText; } + bool WriteCaptchaImage(wxMemoryOutputStream& file); private: diff --git a/src/ClientTCPSocket.cpp b/src/ClientTCPSocket.cpp index a90bcfc9..977141e3 100644 --- a/src/ClientTCPSocket.cpp +++ b/src/ClientTCPSocket.cpp @@ -798,7 +798,7 @@ bool CClientTCPSocket::ProcessPacket(const byte* buffer, uint32 size, uint8 opco throw wxString(wxT("invalid message packet")); } - // limit mesage length + // limit message length static const uint16 MAX_CLIENT_MSG_LEN = 450; if (length > MAX_CLIENT_MSG_LEN) { diff --git a/src/updownclient.h b/src/updownclient.h index c4468e0f..5ae6d850 100644 --- a/src/updownclient.h +++ b/src/updownclient.h @@ -260,8 +260,8 @@ public: bool GetFriendSlot() const { return m_bFriendSlot; } void SetFriendSlot(bool bNV) { m_bFriendSlot = bNV; } void SetCommentDirty(bool bDirty = true) { m_bCommentDirty = bDirty; } - uint8 GetSourceExchange1Version() const { return m_bySourceExchange1Ver; } - bool SupportsSourceExchange2() const { return m_fSupportsSourceEx2; } + uint8 GetSourceExchange1Version() const { return m_bySourceExchange1Ver; } + bool SupportsSourceExchange2() const { return m_fSupportsSourceEx2; } bool SafeSendPacket(CPacket* packet); @@ -320,12 +320,9 @@ public: return m_score; } uint16 m_waitingPosition; - uint16 GetWaitingPosition() const { return m_waitingPosition; } + uint16 GetWaitingPosition() const { return m_waitingPosition; } #endif - double GetRating() const - { - return (double)GetScore(false, IsDownloading(), true); - } + double GetRating() const { return (double)GetScore(false, IsDownloading(), true); } void AddReqBlock(Requested_Block_Struct* reqblock); void CreateNextBlockPackage(); @@ -420,19 +417,19 @@ public: //chat uint8 GetChatState() { return m_byChatstate; } void SetChatState(uint8 nNewS) { m_byChatstate = nNewS; } - EChatCaptchaState GetChatCaptchaState() const { return (EChatCaptchaState)m_nChatCaptchaState; } - void SetChatCaptchaState(EChatCaptchaState nNewS) { m_nChatCaptchaState = nNewS; } - void ProcessCaptchaRequest(CMemFile* data); - void ProcessCaptchaReqRes(uint8 nStatus); - void ProcessChatMessage(wxString message); + EChatCaptchaState GetChatCaptchaState() const { return (EChatCaptchaState)m_nChatCaptchaState; } + void SetChatCaptchaState(EChatCaptchaState nNewS) { m_nChatCaptchaState = nNewS; } + void ProcessCaptchaRequest(CMemFile* data); + void ProcessCaptchaReqRes(uint8 nStatus); + void ProcessChatMessage(wxString message); // message filtering - uint8 GetMessagesReceived() const { return m_cMessagesReceived; } - void IncMessagesReceived() { m_cMessagesReceived < 255 ? ++m_cMessagesReceived : 255; } - uint8 GetMessagesSent() const { return m_cMessagesSent; } - void IncMessagesSent() { m_cMessagesSent < 255 ? ++m_cMessagesSent : 255; } - bool IsSpammer() const { return m_fIsSpammer; } - void SetSpammer(bool bVal); - bool IsMessageFiltered(const wxString& message); + uint8 GetMessagesReceived() const { return m_cMessagesReceived; } + void IncMessagesReceived() { m_cMessagesReceived < 255 ? ++m_cMessagesReceived : 255; } + uint8 GetMessagesSent() const { return m_cMessagesSent; } + void IncMessagesSent() { m_cMessagesSent < 255 ? ++m_cMessagesSent : 255; } + bool IsSpammer() const { return m_fIsSpammer; } + void SetSpammer(bool bVal); + bool IsMessageFiltered(const wxString& message); //File Comment const wxString& GetFileComment() const { return m_strComment; } @@ -536,7 +533,7 @@ public: * * @return True if sent, false if connecting */ - bool SendChatMessage(const wxString& message); + bool SendChatMessage(const wxString& message); uint32 GetPayloadInBuffer() const { return m_addedPayloadQueueSession - GetQueueSessionPayloadUp(); } uint32 GetQueueSessionPayloadUp() const { return m_nCurQueueSessionPayloadUp; } @@ -567,7 +564,7 @@ public: uint8 GetKadVersion() { return m_byKadVersion; } void ProcessFirewallCheckUDPRequest(CMemFile *data); // Kad added by me - bool SendBuddyPing(); + bool SendBuddyPing(); /* Returns the client hash type (SO_EMULE, mldonkey, etc) */ int GetHashType() const; @@ -633,10 +630,10 @@ public: bool SupportsLargeFiles() const { return m_fSupportsLargeFiles; } - #ifdef __DEBUG__ +#ifdef __DEBUG__ /* Kry - Debug. See connection_reason definition comment below */ void SetConnectionReason(const wxString& reason) { connection_reason = reason; } - #endif +#endif // Encryption / Obfuscation / ConnectOptions bool SupportsCryptLayer() const { return m_fSupportsCryptLayer; } @@ -825,7 +822,7 @@ private: // if this flag is not set, we just know that we don't know // for sure if it is enabled m_fSupportsPreview : 1, - m_fIsSpammer : 1, + m_fIsSpammer : 1, m_fSentCancelTransfer: 1, // we have sent an OP_CANCELTRANSFER in the current connection m_fSharedDirectories : 1, // client supports OP_ASKSHAREDIRS opcodes m_fSupportsAICH : 3, @@ -837,7 +834,7 @@ private: m_fSupportsCryptLayer: 1, m_fRequiresCryptLayer: 1, m_fSupportsSourceEx2 : 1, - m_fSupportsCaptcha : 1, + m_fSupportsCaptcha : 1, m_fDirectUDPCallback : 1; unsigned int @@ -895,22 +892,22 @@ private: wxString m_lastOSInfo; /* For buddies timeout */ - uint32 m_nCreationTime; + uint32 m_nCreationTime; /* Calculation of last average speed */ - uint32 m_lastaverage; - uint32 m_last_block_start; + uint32 m_lastaverage; + uint32 m_last_block_start; /* Save the encryption status for display when disconnected */ - bool m_hasbeenobfuscatinglately; + bool m_hasbeenobfuscatinglately; /* Kry - Debug thing. Clients created just to check their data have this string set to the reason we want to check them. - Obviously, once checked, we disconect them. Take that, sucker. + Obviously, once checked, we disconnect them. Take that, sucker. This debug code is just for me I'm afraid. */ - #ifdef __DEBUG__ - wxString connection_reason; - #endif +#ifdef __DEBUG__ + wxString connection_reason; +#endif }; -- 2.11.4.GIT