From: <arn...@us...> - 2006-10-18 19:44:19
|
Revision: 681 http://svn.sourceforge.net/dcplusplus/?rev=681&view=rev Author: arnetheduck Date: 2006-10-18 12:43:41 -0700 (Wed, 18 Oct 2006) Log Message: ----------- cleanup, patches Modified Paths: -------------- dcplusplus/trunk/DCPlusPlus.vcproj dcplusplus/trunk/changelog.txt dcplusplus/trunk/client/AdcHub.cpp dcplusplus/trunk/client/AdcHub.h dcplusplus/trunk/client/Client.cpp dcplusplus/trunk/client/Client.h dcplusplus/trunk/client/DCPlusPlus.h dcplusplus/trunk/client/NmdcHub.cpp dcplusplus/trunk/client/NmdcHub.h dcplusplus/trunk/client/stdinc.h dcplusplus/trunk/client.vcproj dcplusplus/trunk/windows/HubFrame.cpp dcplusplus/trunk/windows/HubFrame.h Removed Paths: ------------- dcplusplus/trunk/client/config.h Modified: dcplusplus/trunk/DCPlusPlus.vcproj =================================================================== --- dcplusplus/trunk/DCPlusPlus.vcproj 2006-10-18 06:53:29 UTC (rev 680) +++ dcplusplus/trunk/DCPlusPlus.vcproj 2006-10-18 19:43:41 UTC (rev 681) @@ -47,7 +47,6 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories=""$(SolutionDir)stlport";"$(SolutionDir)wtl";"$(SolutionDir)yassl\include"" - PreprocessorDefinitions="HAVE_STLPORT" StringPooling="true" MinimalRebuild="true" ExceptionHandling="1" @@ -157,7 +156,6 @@ OmitFramePointers="true" EnableFiberSafeOptimizations="true" AdditionalIncludeDirectories=""$(SolutionDir)stlport";"$(SolutionDir)wtl";"$(SolutionDir)yassl\include"" - PreprocessorDefinitions="HAVE_STLPORT" StringPooling="true" MinimalRebuild="true" ExceptionHandling="1" Modified: dcplusplus/trunk/changelog.txt =================================================================== --- dcplusplus/trunk/changelog.txt 2006-10-18 06:53:29 UTC (rev 680) +++ dcplusplus/trunk/changelog.txt 2006-10-18 19:43:41 UTC (rev 681) @@ -5,6 +5,9 @@ * Confirm hub removal is now default * SFV checking is now default * Fixed TLS port not being greyed out +* Automatic hub reconnection is only done if at least one successful connection has been made +* [bug 1080] Better nick tab completion (thanks cologic) +* [bug 1081] Added user IP in hub frame (thanks cologic) -- 0.698 2006-10-10 -- * [bug 1065] Code cleanup (thanks steven sheehy) Modified: dcplusplus/trunk/client/AdcHub.cpp =================================================================== --- dcplusplus/trunk/client/AdcHub.cpp 2006-10-18 06:53:29 UTC (rev 680) +++ dcplusplus/trunk/client/AdcHub.cpp 2006-10-18 19:43:41 UTC (rev 681) @@ -39,7 +39,7 @@ const string AdcHub::TCP4_FEATURE("TCP4"); const string AdcHub::UDP4_FEATURE("UDP4"); -AdcHub::AdcHub(const string& aHubURL, bool secure) : Client(aHubURL, '\n', secure), state(STATE_PROTOCOL), sid(0), reconnect(true) { +AdcHub::AdcHub(const string& aHubURL, bool secure) : Client(aHubURL, '\n', secure), sid(0) { TimerManager::getInstance()->addListener(this); } @@ -48,6 +48,7 @@ clearUsers(); } + OnlineUser& AdcHub::getUser(const uint32_t aSID, const CID& aCID) { OnlineUser* ou = findUser(aSID); if(ou) { @@ -146,6 +147,7 @@ if(u->getUser() == getMyIdentity().getUser()) { state = STATE_NORMAL; + setAutoReconnect(true); setMyIdentity(u->getIdentity()); updateCounts(false); } @@ -219,7 +221,13 @@ } void AdcHub::handle(AdcCommand::QUI, AdcCommand& c) throw() { - putUser(AdcCommand::toSID(c.getParam(0))); + uint32_t s = AdcCommand::toSID(c.getParam(0)); + putUser(s); + + // No use to hammer if we're banned + if(s == sid && c.hasFlag("TL", 1)) { + setAutoReconnect(false); + } } void AdcHub::handle(AdcCommand::CTM, AdcCommand& c) throw() { @@ -574,16 +582,24 @@ return tmp; } +void AdcHub::send(const AdcCommand& cmd) { + if(cmd.getType() == AdcCommand::TYPE_UDP) + sendUDP(cmd); + send(cmd.toString(sid)); +} + void AdcHub::on(Connected) throw() { - dcassert(state == STATE_PROTOCOL); + Client::on(Connected()); + lastInfoMap.clear(); - reconnect = true; + sid = 0; + send(AdcCommand(AdcCommand::CMD_SUP, AdcCommand::TYPE_HUB).addParam("ADBAS0")); - - fire(ClientListener::Connected(), this); } void AdcHub::on(Line, const string& aLine) throw() { + Client::on(Line(), aLine); + if(BOOLSETTING(ADC_DEBUG)) { fire(ClientListener::StatusMessage(), this, "<ADC>" + aLine + "</ADC>"); } @@ -592,23 +608,12 @@ void AdcHub::on(Failed, const string& aLine) throw() { clearUsers(); - socket->removeListener(this); - state = STATE_PROTOCOL; - fire(ClientListener::Failed(), this, aLine); + Client::on(Failed(), aLine); } -void AdcHub::send(const AdcCommand& cmd) { - dcassert(socket); - if(!socket) - return; - if(cmd.getType() == AdcCommand::TYPE_UDP) - sendUDP(cmd); - send(cmd.toString(sid)); -} - void AdcHub::on(Second, uint32_t aTick) throw() { - if(getAutoReconnect() && state == STATE_PROTOCOL && (getReconnecting() || ((getLastActivity() + getReconnDelay() * 1000) < aTick)) ) { - // Try to reconnect... - connect(); + Client::on(Second(), aTick); + if(state == STATE_NORMAL && (aTick > (getLastActivity() + 120*1000)) ) { + send("\n", 1); } } Modified: dcplusplus/trunk/client/AdcHub.h =================================================================== --- dcplusplus/trunk/client/AdcHub.h 2006-10-18 06:53:29 UTC (rev 680) +++ dcplusplus/trunk/client/AdcHub.h 2006-10-18 19:43:41 UTC (rev 681) @@ -56,13 +56,6 @@ friend class ClientManager; friend class CommandHandler<AdcHub>; - enum States { - STATE_PROTOCOL, - STATE_IDENTIFY, - STATE_VERIFY, - STATE_NORMAL - } state; - AdcHub(const string& aHubURL, bool secure); AdcHub(const AdcHub&); @@ -79,9 +72,7 @@ mutable CriticalSection cs; string salt; - uint32_t sid; - bool reconnect; static const string CLIENT_PROTOCOL; static const string SECURE_CLIENT_PROTOCOL; @@ -110,9 +101,7 @@ void handle(AdcCommand::CMD, AdcCommand& c) throw(); void handle(AdcCommand::RES, AdcCommand& c) throw(); - template<typename T> void handle(T, AdcCommand&) { - //Speaker<AdcHubListener>::fire(t, this, c); - } + template<typename T> void handle(T, AdcCommand&) { } void sendUDP(const AdcCommand& cmd) throw(); @@ -122,6 +111,7 @@ virtual void on(Failed, const string& aLine) throw(); virtual void on(Second, uint32_t aTick) throw(); + }; #endif // !defined(ADC_HUB_H) Modified: dcplusplus/trunk/client/Client.cpp =================================================================== --- dcplusplus/trunk/client/Client.cpp 2006-10-18 06:53:29 UTC (rev 680) +++ dcplusplus/trunk/client/Client.cpp 2006-10-18 19:43:41 UTC (rev 681) @@ -31,7 +31,7 @@ Client::Client(const string& hubURL, char separator_, bool secure_) : myIdentity(ClientManager::getInstance()->getMe(), 0), - reconnDelay(120), lastActivity(GET_TICK()), registered(false), autoReconnect(true), reconnecting(false), socket(0), + reconnDelay(120), lastActivity(GET_TICK()), registered(false), autoReconnect(false), state(STATE_DISCONNECTED), socket(0), hubUrl(hubURL), port(0), separator(separator_), secure(secure_), countType(COUNT_UNCOUNTED) { @@ -50,7 +50,7 @@ void Client::reconnect() { disconnect(true); setAutoReconnect(true); - setReconnecting(true); + setReconnDelay(0); } void Client::shutdown() { @@ -88,7 +88,6 @@ BufferedSocket::putSocket(socket); setAutoReconnect(true); - setReconnecting(false); setReconnDelay(120 + Util::rand(0, 60)); reloadSettings(true); setRegistered(false); @@ -107,18 +106,25 @@ fire(ClientListener::Failed(), this, e.getError()); } updateActivity(); + state = STATE_CONNECTING; } void Client::on(Connected) throw() { updateActivity(); ip = socket->getIp(); fire(ClientListener::Connected(), this); + state = STATE_PROTOCOL; } +void Client::on(Failed, const string& aLine) throw() { + state = STATE_DISCONNECTED; + socket->removeListener(this); + fire(ClientListener::Failed(), this, aLine); +} + void Client::disconnect(bool graceLess) { - if(!socket) - return; - socket->disconnect(graceLess); + if(socket) + socket->disconnect(graceLess); } void Client::updateCounts(bool aRemove) { @@ -166,5 +172,13 @@ return lip; } -void Client::on(Second, uint32_t) throw() { +void Client::on(Line, const string& /*aLine*/) throw() { + updateActivity(); } + +void Client::on(Second, uint32_t aTick) throw() { + if(state == STATE_DISCONNECTED && getAutoReconnect() && (aTick > (getLastActivity() + getReconnDelay() * 1000)) ) { + // Try to reconnect... + connect(); + } +} Modified: dcplusplus/trunk/client/Client.h =================================================================== --- dcplusplus/trunk/client/Client.h 2006-10-18 06:53:29 UTC (rev 680) +++ dcplusplus/trunk/client/Client.h 2006-10-18 19:43:41 UTC (rev 681) @@ -153,7 +153,6 @@ GETSET(uint32_t, lastActivity, LastActivity); GETSET(bool, registered, Registered); GETSET(bool, autoReconnect, AutoReconnect); - GETSET(bool, reconnecting, Reconnecting); GETSET(string, currentNick, CurrentNick); GETSET(string, currentDescription, CurrentDescription); @@ -169,6 +168,15 @@ bool operator !=(const Counts& rhs) { return normal != rhs.normal || registered != rhs.registered || op != rhs.op; } }; + enum States { + STATE_CONNECTING, ///< Waiting for socket to connect + STATE_PROTOCOL, ///< Protocol setup + STATE_IDENTIFY, ///< Nick setup + STATE_VERIFY, ///< Checking password + STATE_NORMAL, ///< Running + STATE_DISCONNECTED, ///< Nothing in particular + } state; + BufferedSocket* socket; static Counts counts; @@ -184,6 +192,11 @@ // TimerManagerListener virtual void on(Second, uint32_t aTick) throw(); + // BufferedSocketListener + virtual void on(Connecting) throw() { fire(ClientListener::Connecting(), this); } + virtual void on(Connected) throw(); + virtual void on(Line, const string& aLine) throw(); + virtual void on(Failed, const string&) throw(); private: @@ -204,12 +217,6 @@ char separator; bool secure; CountType countType; - - // BufferedSocketListener - virtual void on(Connecting) throw() { fire(ClientListener::Connecting(), this); } - virtual void on(Connected) throw(); - - }; #endif // !defined(CLIENT_H) Modified: dcplusplus/trunk/client/DCPlusPlus.h =================================================================== --- dcplusplus/trunk/client/DCPlusPlus.h 2006-10-18 06:53:29 UTC (rev 680) +++ dcplusplus/trunk/client/DCPlusPlus.h 2006-10-18 19:43:41 UTC (rev 681) @@ -100,6 +100,37 @@ typedef vector<WStringPair> WStringPairList; typedef WStringPairList::iterator WStringPairIter; +#if defined(_MSC_VER) +#define _LL(x) x##ll +#define _ULL(x) x##ull +#define I64_FMT "%I64d" +#define U64_FMT "%I64d" + +#elif defined(SIZEOF_LONG) && SIZEOF_LONG == 8 +#define _LL(x) x##l +#define _ULL(x) x##ul +#define I64_FMT "%ld" +#define U64_FMT "%ld" +#else +#define _LL(x) x##ll +#define _ULL(x) x##ull +#define I64_FMT "%lld" +#define U64_FMT "%lld" +#endif + +#ifdef _WIN32 + +# define PATH_SEPARATOR '\\' +# define PATH_SEPARATOR_STR "\\" + +#else + +# define PATH_SEPARATOR '/' +# define PATH_SEPARATOR_STR "/" + +#endif + + typedef HASH_MAP<wstring, wstring> WStringMap; typedef WStringMap::iterator WStringMapIter; Modified: dcplusplus/trunk/client/NmdcHub.cpp =================================================================== --- dcplusplus/trunk/client/NmdcHub.cpp 2006-10-18 06:53:29 UTC (rev 680) +++ dcplusplus/trunk/client/NmdcHub.cpp 2006-10-18 19:43:41 UTC (rev 681) @@ -32,7 +32,7 @@ #include "UserCommand.h" #include "StringTokenizer.h" -NmdcHub::NmdcHub(const string& aHubURL) : Client(aHubURL, '|', false), supportFlags(0), state(STATE_CONNECT), +NmdcHub::NmdcHub(const string& aHubURL) : Client(aHubURL, '|', false), supportFlags(0), lastUpdate(0) { } @@ -41,19 +41,9 @@ clearUsers(); } -void NmdcHub::connect() { - supportFlags = 0; - lastMyInfoA.clear(); - lastMyInfoB.clear(); - lastUpdate = 0; - state = STATE_LOCK; +#define checkstate() if(state != STATE_NORMAL) return - Client::connect(); -} - -#define checkstate() if(state != STATE_CONNECTED) return - void NmdcHub::connect(const OnlineUser& aUser) { checkstate(); dcdebug("NmdcHub::connect %s\n", aUser.getIdentity().getNick().c_str()); @@ -178,14 +168,12 @@ } void NmdcHub::onLine(const string& aLine) throw() { - updateActivity(); - if(aLine.length() == 0) return; if(aLine[0] != '$') { // Check if we're being banned... - if(state != STATE_CONNECTED) { + if(state != STATE_NORMAL) { if(Util::findSubString(aLine, "banned") != string::npos) { setAutoReconnect(false); } @@ -236,7 +224,7 @@ } if(cmd == "$Search") { - if(state != STATE_CONNECTED) { + if(state != STATE_NORMAL) { return; } string::size_type i = 0; @@ -411,7 +399,7 @@ putUser(nick); } } else if(cmd == "$ConnectToMe") { - if(state != STATE_CONNECTED) { + if(state != STATE_NORMAL) { return; } string::size_type i = param.find(' '); @@ -431,7 +419,7 @@ string port = param.substr(j+1); ConnectionManager::getInstance()->nmdcConnect(server, (unsigned short)Util::toInt(port), getMyNick(), getHubUrl()); } else if(cmd == "$RevConnectToMe") { - if(state != STATE_CONNECTED) { + if(state != STATE_NORMAL) { return; } @@ -515,10 +503,10 @@ fire(ClientListener::UserCommand(), this, type, ctx, name, command); } } else if(cmd == "$Lock") { - if(state != STATE_LOCK) { + if(state != STATE_PROTOCOL) { return; } - state = STATE_HELLO; + state = STATE_IDENTIFY; // Param must not be fromAcp'd... param = aLine.substr(6); @@ -568,8 +556,8 @@ u.getUser()->setFlag(User::PASSIVE); } - if(state == STATE_HELLO && u.getUser() == getMyIdentity().getUser()) { - state = STATE_CONNECTED; + if(state == STATE_IDENTIFY && u.getUser() == getMyIdentity().getUser()) { + state = STATE_NORMAL; updateCounts(false); version(); @@ -626,7 +614,7 @@ v.push_back(&getUser(*it)); } - if(!(getSupportFlags() & SUPPORTS_NOGETINFO)) { + if(!(supportFlags & SUPPORTS_NOGETINFO)) { string tmp; // Let's assume 10 characters per nick... tmp.reserve(v.size() * (11 + 10 + getMyNick().length())); @@ -901,24 +889,29 @@ } } -// TimerManagerListener -void NmdcHub::on(Second, uint32_t aTick) throw() { - if(state == STATE_CONNECTED && (getLastActivity() + getReconnDelay() * 1000) < aTick) { - // Try to send something for the fun of it... - dcdebug("Testing writing...\n"); - send("|", 1); - } else if(getAutoReconnect() && state == STATE_CONNECT && (getReconnecting() || ((getLastActivity() + getReconnDelay() * 1000) < aTick))) { - // Try to reconnect... - connect(); - } +void NmdcHub::on(Connected) throw() { + Client::on(Connected()); - Client::on(Second(), aTick); + supportFlags = 0; + lastMyInfoA.clear(); + lastMyInfoB.clear(); + lastUpdate = 0; } -// BufferedSocketListener -void NmdcHub::on(BufferedSocketListener::Failed, const string& aLine) throw() { +void NmdcHub::on(Line, const string& aLine) throw() { + Client::on(Line(), aLine); + onLine(aLine); +} + +void NmdcHub::on(Failed, const string& aLine) throw() { clearUsers(); - socket->removeListener(this); - state = STATE_CONNECT; - fire(ClientListener::Failed(), this, aLine); + Client::on(Failed(), aLine); } + +void NmdcHub::on(Second, uint32_t aTick) throw() { + Client::on(Second(), aTick); + + if(state == STATE_NORMAL && (aTick > (getLastActivity() + 120*1000)) ) { + send("|", 1); + } +} Modified: dcplusplus/trunk/client/NmdcHub.h =================================================================== --- dcplusplus/trunk/client/NmdcHub.h 2006-10-18 06:53:29 UTC (rev 680) +++ dcplusplus/trunk/client/NmdcHub.h 2006-10-18 19:43:41 UTC (rev 681) @@ -37,8 +37,8 @@ { public: using Client::send; + using Client::connect; - virtual void connect(); virtual void connect(const OnlineUser& aUser); virtual void hubMessage(const string& aMessage); @@ -57,8 +57,6 @@ virtual void send(const AdcCommand&) { dcassert(0); } static string validateMessage(string tmp, bool reverse); - - GETSET(int, supportFlags, SupportFlags); private: friend class ClientManager; enum SupportFlags { @@ -67,13 +65,6 @@ SUPPORTS_USERIP2 = 0x04 }; - enum States { - STATE_CONNECT, - STATE_LOCK, - STATE_HELLO, - STATE_CONNECTED - } state; - mutable CriticalSection cs; typedef HASH_MAP_X(string, OnlineUser*, noCaseStringHash, noCaseStringEq, noCaseStringLess) NickMap; @@ -81,6 +72,7 @@ NickMap users; + int supportFlags; uint32_t lastUpdate; string lastMyInfoA, lastMyInfoB; @@ -123,7 +115,8 @@ // TimerManagerListener virtual void on(Second, uint32_t aTick) throw(); - virtual void on(Line, const string& l) throw() { onLine(l); } + virtual void on(Connected) throw(); + virtual void on(Line, const string& l) throw(); virtual void on(Failed, const string&) throw(); }; Deleted: dcplusplus/trunk/client/config.h =================================================================== --- dcplusplus/trunk/client/config.h 2006-10-18 06:53:29 UTC (rev 680) +++ dcplusplus/trunk/client/config.h 2006-10-18 19:43:41 UTC (rev 681) @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2001-2006 Jacek Sieka, arnetheduck on gmail point com - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#if !defined(CONFIG_H) -#define CONFIG_H - -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 - -#ifdef HAVE_CONFIG_H -#include "autoconf.h" -#endif - -// Remove this line if hashes are not available in your stl -#define HAVE_HASH 1 - -// This enables stlport's debug mode (and slows it down to a crawl...) -//#define _STLP_DEBUG 1 -//#define _STLP_USE_NEWALLOC 1 - -// --- Shouldn't have to change anything under here... - -#ifndef _REENTRANT -# define _REENTRANT 1 -#endif - -#ifdef HAVE_STLPORT -# define _STLP_DONT_USE_SHORT_STRING_OPTIM 1 // Lots of memory issues with this undefined...wonder what's up with that.. -# define _STLP_USE_PTR_SPECIALIZATIONS 1 -# define _STLP_NO_ANACHRONISMS 1 -# define _STLP_NO_CUSTOM_IO 1 -# define _STLP_NO_IOSTREAMS 1 -# ifndef _DEBUG -# define _STLP_DONT_USE_EXCEPTIONS 1 -# endif -#endif - -#ifdef _MSC_VER -# pragma warning(disable: 4711) // function 'xxx' selected for automatic inline expansion -# pragma warning(disable: 4786) // identifier was truncated to '255' characters in the debug information -# pragma warning(disable: 4290) // C++ Exception Specification ignored -# pragma warning(disable: 4127) // constant expression -# pragma warning(disable: 4710) // function not inlined -# pragma warning(disable: 4503) // decorated name length exceeded, name was truncated -# pragma warning(disable: 4428) // universal-character-name encountered in source - -# if _MSC_VER == 1200 || _MSC_VER == 1300 || _MSC_VER == 1310 || _MSC_VER == 1400 - -typedef signed __int8 int8_t; -typedef signed __int16 int16_t; -typedef signed __int32 int32_t; -typedef signed __int64 int64_t; - -typedef unsigned __int8 uint8_t; -typedef unsigned __int16 uint16_t; -typedef unsigned __int32 uint32_t; -typedef unsigned __int64 uint64_t; - -# endif - -#endif - -#if defined(_MSC_VER) -#define _LL(x) x##ll -#define _ULL(x) x##ull -#define I64_FMT "%I64d" -#define U64_FMT "%I64d" - -#elif defined(SIZEOF_LONG) && SIZEOF_LONG == 8 -#define _LL(x) x##l -#define _ULL(x) x##ul -#define I64_FMT "%ld" -#define U64_FMT "%ld" -#else -#define _LL(x) x##ll -#define _ULL(x) x##ull -#define I64_FMT "%lld" -#define U64_FMT "%lld" -#endif - -#ifdef _WIN32 - -# define PATH_SEPARATOR '\\' -# define PATH_SEPARATOR_STR "\\" - -#else - -# define PATH_SEPARATOR '/' -# define PATH_SEPARATOR_STR "/" - -#endif - -#ifdef _MSC_VER - -# ifndef CDECL -# define CDECL _cdecl -# endif - -#else // _MSC_VER - -# ifndef CDECL -# define CDECL -# endif - -#endif // _MSC_VER - -#define BZ_NO_STDIO - -#ifdef _WIN32 -# define _WIN32_WINNT 0x0501 -# define _WIN32_IE 0x0500 -#endif - -#endif // !defined(CONFIG_H) Modified: dcplusplus/trunk/client/stdinc.h =================================================================== --- dcplusplus/trunk/client/stdinc.h 2006-10-18 06:53:29 UTC (rev 680) +++ dcplusplus/trunk/client/stdinc.h 2006-10-18 19:43:41 UTC (rev 681) @@ -19,9 +19,71 @@ #if !defined(STDINC_H) #define STDINC_H -#include "config.h" +// This enables stlport's debug mode (and slows it down to a crawl...) +//#define _STLP_DEBUG 1 +//#define _STLP_USE_NEWALLOC 1 +// --- Shouldn't have to change anything under here... + +#ifndef _REENTRANT +# define _REENTRANT 1 +#endif + +#ifndef BZ_NO_STDIO +#define BZ_NO_STDIO 1 +#endif + +#ifdef HAVE_STLPORT +# define _STLP_DONT_USE_SHORT_STRING_OPTIM 1 // Lots of memory issues with this undefined...wonder what's up with that.. +# define _STLP_USE_PTR_SPECIALIZATIONS 1 +# define _STLP_NO_ANACHRONISMS 1 +# define _STLP_NO_CUSTOM_IO 1 +# define _STLP_NO_IOSTREAMS 1 +# ifndef _DEBUG +# define _STLP_DONT_USE_EXCEPTIONS 1 +# endif +#endif + +#ifdef _MSC_VER + +//disable the deprecated warnings for the CRT functions. +#define _CRT_SECURE_NO_DEPRECATE 1 +#define _ATL_SECURE_NO_DEPRECATE 1 +#define _CRT_NON_CONFORMING_SWPRINTFS 1 + +# pragma warning(disable: 4711) // function 'xxx' selected for automatic inline expansion +# pragma warning(disable: 4786) // identifier was truncated to '255' characters in the debug information +# pragma warning(disable: 4290) // C++ Exception Specification ignored +# pragma warning(disable: 4127) // constant expression +# pragma warning(disable: 4710) // function not inlined +# pragma warning(disable: 4503) // decorated name length exceeded, name was truncated +# pragma warning(disable: 4428) // universal-character-name encountered in source + +typedef signed __int8 int8_t; +typedef signed __int16 int16_t; +typedef signed __int32 int32_t; +typedef signed __int64 int64_t; + +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; + +# ifndef CDECL +# define CDECL _cdecl +# endif + +#else // _MSC_VER + +# ifndef CDECL +# define CDECL +# endif + +#endif // _MSC_VER + #ifdef _WIN32 +# define _WIN32_WINNT 0x0501 +# define _WIN32_IE 0x0500 #define STRICT #define WIN32_LEAN_AND_MEAN @@ -32,13 +94,6 @@ #define _ATL_NO_HOSTING #define _ATL_NO_OLD_NAMES -#if _MSC_VER == 1400 -//disable the deperecated warnings for the crt functions. -#define _CRT_SECURE_NO_DEPRECATE 1 -#define _ATL_SECURE_NO_DEPRECATE 1 -#define _CRT_NON_CONFORMING_SWPRINTFS 1 -#endif - #include <Winsock2.h> #include <windows.h> @@ -68,45 +123,27 @@ #include <functional> // Use maps if hash_maps aren't available -#ifdef HAVE_HASH -# ifdef _STLPORT_VERSION -# define HASH_SET_X(key, hfunc, eq, order) hash_set<key, hfunc, eq > -# define HASH_MAP_X(key, type, hfunc, eq, order) hash_map<key, type, hfunc, eq > -// STLPort 5.0.2 hash_multimap buggy -# define HASH_MULTIMAP_X(key, type, hfunc, eq, order) multimap<key, type, order > -# elif defined(__GLIBCPP__) || defined(__GLIBCXX__) // Using GNU C++ library? -# define HASH_SET_X(key, hfunc, eq, order) hash_set<key, hfunc, eq > -# define HASH_MAP_X(key, type, hfunc, eq, order) hash_map<key, type, hfunc, eq > -# define HASH_MULTIMAP_X(key, type, hfunc, eq, order) hash_multimap<key, type, hfunc, eq > -# elif defined(_MSC_VER) // Assume the msvc 7.x stl -# define HASH_SET_X(key, hfunc, eq, order) hash_set<key, hfunc > -# define HASH_MAP_X(key, type, hfunc, eq, order) hash_map<key, type, hfunc > -# define HASH_MULTIMAP_X(key, type, hfunc, eq, order) hash_multimap<key, type, hfunc > -# else -# error Unknown STL, hashes need to be configured -# endif - +#ifdef _STLPORT_VERSION # define HASH_SET hash_set # define HASH_MAP hash_map +// STLPort 5.0.2 hash_multimap buggy # define HASH_MULTIMAP multimap +# define HASH_SET_X(key, hfunc, eq, order) hash_set<key, hfunc, eq > +# define HASH_MAP_X(key, type, hfunc, eq, order) hash_map<key, type, hfunc, eq > +# define HASH_MULTIMAP_X(key, type, hfunc, eq, order) multimap<key, type, order > -#else // HAVE_HASH - -# define HASH_SET_X(key, hfunc, eq, order) -# define HASH_SET set -# define HASH_MAP map -# define HASH_MAP_X(key, type, hfunc, eq, order) map<key, type, order > -# define HASH_MULTIMAP multimap -# define HASH_MULTIMAP_X(key, type, hfunc, eq, order) multimap<key, type, order > - -#endif // HAVE_HASH - -#ifdef _STLPORT_VERSION -using namespace std; #include <hash_map> #include <hash_set> +using namespace std; #elif defined(__GLIBCPP__) || defined(__GLIBCXX__) // Using GNU C++ library? +# define HASH_SET hash_set +# define HASH_MAP hash_map +# define HASH_MULTIMAP hash_multimap +# define HASH_SET_X(key, hfunc, eq, order) hash_set<key, hfunc, eq > +# define HASH_MAP_X(key, type, hfunc, eq, order) hash_map<key, type, hfunc, eq > +# define HASH_MULTIMAP_X(key, type, hfunc, eq, order) hash_multimap<key, type, hfunc, eq > + #include <ext/hash_map> #include <ext/hash_set> #include <ext/functional> @@ -117,20 +154,33 @@ namespace __gnu_cxx { template<> struct hash<std::string> { size_t operator()(const std::string& x) const - { return hash<const char*>()(x.c_str()); } + { return hash<const char*>()(x.c_str()); } }; template<> struct hash<long long int> { size_t operator()(long long int x) const { return x; } }; } -#else // __GLIBCPP__ +#elif defined(_MSC_VER) // Assume the msvc stl +# define HASH_SET hash_set +# define HASH_MAP hash_map +# define HASH_MULTIMAP hash_multimap +# define HASH_SET_X(key, hfunc, eq, order) hash_set<key, hfunc > +# define HASH_MAP_X(key, type, hfunc, eq, order) hash_map<key, type, hfunc > +# define HASH_MULTIMAP_X(key, type, hfunc, eq, order) hash_multimap<key, type, hfunc > + #include <hash_map> #include <hash_set> - using namespace std; using namespace stdext; -#endif // __GLIBCPP__ +#else +# define HASH_SET set +# define HASH_MAP map +# define HASH_SET_X(key, hfunc, eq, order) +# define HASH_MAP_X(key, type, hfunc, eq, order) map<key, type, order > +# define HASH_MULTIMAP multimap +# define HASH_MULTIMAP_X(key, type, hfunc, eq, order) multimap<key, type, order > +#endif #endif // !defined(STDINC_H) Modified: dcplusplus/trunk/client.vcproj =================================================================== --- dcplusplus/trunk/client.vcproj 2006-10-18 06:53:29 UTC (rev 680) +++ dcplusplus/trunk/client.vcproj 2006-10-18 19:43:41 UTC (rev 681) @@ -43,7 +43,6 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories=""$(SolutionDir)stlport";"$(SolutionDir)wtl";"$(SolutionDir)yassl\include"" - PreprocessorDefinitions="HAVE_STLPORT" StringPooling="true" MinimalRebuild="true" ExceptionHandling="1" @@ -130,7 +129,6 @@ OmitFramePointers="true" EnableFiberSafeOptimizations="true" AdditionalIncludeDirectories=""$(SolutionDir)stlport";"$(SolutionDir)wtl";"$(SolutionDir)yassl\include"" - PreprocessorDefinitions="HAVE_STLPORT" StringPooling="true" MinimalRebuild="true" ExceptionHandling="1" Modified: dcplusplus/trunk/windows/HubFrame.cpp =================================================================== --- dcplusplus/trunk/windows/HubFrame.cpp 2006-10-18 06:53:29 UTC (rev 680) +++ dcplusplus/trunk/windows/HubFrame.cpp 2006-10-18 19:43:41 UTC (rev 681) @@ -37,10 +37,10 @@ HubFrame::FrameMap HubFrame::frames; -int HubFrame::columnSizes[] = { 100, 75, 75, 100, 75, 100, 125 }; -int HubFrame::columnIndexes[] = { COLUMN_NICK, COLUMN_SHARED, COLUMN_DESCRIPTION, COLUMN_TAG, COLUMN_CONNECTION, COLUMN_EMAIL, COLUMN_CID }; +int HubFrame::columnSizes[] = { 100, 75, 75, 100, 75, 100, 100, 125 }; +int HubFrame::columnIndexes[] = { COLUMN_NICK, COLUMN_SHARED, COLUMN_DESCRIPTION, COLUMN_TAG, COLUMN_CONNECTION, COLUMN_IP, COLUMN_EMAIL, COLUMN_CID }; static ResourceManager::Strings columnNames[] = { ResourceManager::NICK, ResourceManager::SHARED, -ResourceManager::DESCRIPTION, ResourceManager::TAG, ResourceManager::CONNECTION, ResourceManager::EMAIL, ResourceManager::CID }; +ResourceManager::DESCRIPTION, ResourceManager::TAG, ResourceManager::CONNECTION, ResourceManager::IP_BARE, ResourceManager::EMAIL, ResourceManager::CID }; LRESULT HubFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) { @@ -463,6 +463,11 @@ columns[COLUMN_DESCRIPTION] = Text::toT(identity.getDescription()); columns[COLUMN_TAG] = Text::toT(identity.getTag()); columns[COLUMN_CONNECTION] = Text::toT(identity.getConnection()); + string ip = identity.getIp(); + string country = ip.empty()?Util::emptyString:Util::getIpCountry(ip); + if (!country.empty()) + ip = country + " (" + ip + ")"; + columns[COLUMN_IP] = Text::toT(ip); columns[COLUMN_EMAIL] = Text::toT(identity.getEmail()); columns[COLUMN_CID] = Text::toT(identity.getUser()->getCID().toBase32()); @@ -899,6 +904,45 @@ } } +string HubFrame::stripNick(const string& nick) const { + if (nick.substr(0, 1) != "[") return nick; + string::size_type x = nick.find(']'); + string ret; + // Avoid full deleting of [IMCOOL][CUSIHAVENOTHINGELSETHANBRACKETS]-type nicks + if ((x != string::npos) && (nick.substr(x+1).length() > 0)) { + ret = nick.substr(x+1); + } else { + ret = nick; + } + return ret; +} + +//Has fun side-effects. Otherwise needs reference arguments or multiple-return-values. +tstring HubFrame::scanNickPrefix(const tstring& prefixT) { + string prefix = Text::fromT(prefixT), maxPrefix; + tabCompleteNicks.clear(); + for (UserMap::const_iterator i = userMap.begin(); i != userMap.end(); ++i) { + string prevNick, nick = i->second->getIdentity().getNick(), wholeNick = nick; + + do { + string::size_type lp = prefix.size(), ln = nick.size(); + if ((ln >= lp) && (!Util::strnicmp(nick, prefix, lp))) { + if (maxPrefix == Util::emptyString) maxPrefix = nick; //ugly hack + tabCompleteNicks.push_back(nick); + tabCompleteNicks.push_back(wholeNick); + maxPrefix = maxPrefix.substr(0, mismatch(maxPrefix.begin(), + maxPrefix.begin()+min(maxPrefix.size(), nick.size()), + nick.begin(), compareCharsNoCase).first - maxPrefix.begin()); + } + + prevNick = nick; + nick = stripNick(nick); + } while (prevNick != nick); + } + + return Text::toT(maxPrefix); +} + void HubFrame::onTab() { if(ctrlMessage.GetWindowTextLength() == 0) { handleTab(WinUtil::isShift()); @@ -936,49 +980,34 @@ else textStart++; - int start = ctrlUsers.GetNextItem(-1, LVNI_FOCUSED) + 1; - int i = start; - int j = ctrlUsers.GetItemCount(); + if (inTabComplete) { + // Already pressed tab once. Output nick candidate list. + tstring nicks; + for (StringList::const_iterator i = tabCompleteNicks.begin(); i < tabCompleteNicks.end(); i+=2) + nicks.append(Text::toT(*i + " ")); + addClientLine(nicks); + inTabComplete = false; + } else { + // First tab. Maximally extend proposed nick. + tstring nick = scanNickPrefix(complete); + if (tabCompleteNicks.empty()) return; - bool firstPass = i < j; - if(!firstPass) - i = 0; - while(firstPass || (!firstPass && i < start)) { - UserInfo* ui = ctrlUsers.getItemData(i); - const tstring& nick = ui->columns[COLUMN_NICK]; - bool found = (Util::strnicmp(nick, complete, complete.length()) == 0); - tstring::size_type x = 0; - if(!found) { - // Check if there's one or more [ISP] tags to ignore... - tstring::size_type y = 0; - while(nick[y] == _T('[')) { - x = nick.find(_T(']'), y); - if(x != string::npos) { - if(Util::strnicmp(nick.c_str() + x + 1, complete.c_str(), complete.length()) == 0) { - found = true; - break; - } - } else { - break; - } - y = x + 1; // assuming that nick[y] == '\0' is legal - } - } - if(found) { - if((start - 1) != -1) { - ctrlUsers.SetItemState(start - 1, 0, LVNI_SELECTED | LVNI_FOCUSED); - } + // Maybe it found a unique match. If userlist showing, highlight. + if (showUsers && tabCompleteNicks.size() == 2) { + int i = ctrlUsers.findItem(Text::toT(tabCompleteNicks[1])); ctrlUsers.SetItemState(i, LVNI_FOCUSED | LVNI_SELECTED, LVNI_FOCUSED | LVNI_SELECTED); ctrlUsers.EnsureVisible(i, FALSE); - ctrlMessage.SetSel(textStart, ctrlMessage.GetWindowTextLength(), TRUE); + } + + ctrlMessage.SetSel(textStart, ctrlMessage.GetWindowTextLength(), TRUE); + // no shift, use partial nick when appropriate + if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { ctrlMessage.ReplaceSel(nick.c_str()); - return; + } else { + ctrlMessage.ReplaceSel(Text::toT(stripNick(Text::fromT(nick))).c_str()); } - i++; - if(i == j) { - firstPass = false; - i = 0; - } + + inTabComplete = true; } } } @@ -990,7 +1019,7 @@ LRESULT HubFrame::onChar(UINT uMsg, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled) { if(!complete.empty() && wParam != VK_TAB && uMsg == WM_KEYDOWN) - complete.clear(); + complete.clear(), inTabComplete = false; if (uMsg != WM_KEYDOWN) { switch(wParam) { Modified: dcplusplus/trunk/windows/HubFrame.h =================================================================== --- dcplusplus/trunk/windows/HubFrame.h 2006-10-18 06:53:29 UTC (rev 680) +++ dcplusplus/trunk/windows/HubFrame.h 2006-10-18 19:43:41 UTC (rev 681) @@ -178,6 +178,7 @@ COLUMN_DESCRIPTION, COLUMN_TAG, COLUMN_CONNECTION, + COLUMN_IP, COLUMN_EMAIL, COLUMN_CID, COLUMN_LAST @@ -250,7 +251,7 @@ HubFrame(const tstring& aServer) : waitingForPW(false), extraSort(false), server(aServer), closed(false), showUsers(BOOLSETTING(GET_USER_INFO)), updateUsers(false), resort(false), - curCommandPosition(0), timeStamps(BOOLSETTING(TIME_STAMPS)), + curCommandPosition(0), timeStamps(BOOLSETTING(TIME_STAMPS)), inTabComplete(false), ctrlMessageContainer(WC_EDIT, this, EDIT_MESSAGE_MAP), showUsersContainer(WC_BUTTON, this, EDIT_MESSAGE_MAP), clientContainer(WC_EDIT, this, EDIT_MESSAGE_MAP), @@ -283,6 +284,8 @@ bool showJoins; bool favShowJoins; tstring complete; + StringList tabCompleteNicks; + bool inTabComplete; bool waitingForPW; bool extraSort; @@ -356,6 +359,13 @@ static int columnIndexes[COLUMN_LAST]; static int columnSizes[COLUMN_LAST]; + static bool compareCharsNoCase(string::value_type a, string::value_type b) { + return Text::toLower(a) == Text::toLower(b); + } + + string stripNick(const string& nick) const; + tstring scanNickPrefix(const tstring& prefix); + bool updateUser(const UserTask& u); void removeUser(const User::Ptr& aUser); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |