From: <arn...@us...> - 2007-11-16 23:11:12
|
Revision: 911 http://dcplusplus.svn.sourceforge.net/dcplusplus/?rev=911&view=rev Author: arnetheduck Date: 2007-11-16 15:11:07 -0800 (Fri, 16 Nov 2007) Log Message: ----------- More 0.14 support Modified Paths: -------------- dcplusplus/trunk/dcpp/AdcHub.cpp dcplusplus/trunk/dcpp/ConnectionManager.cpp dcplusplus/trunk/dcpp/User.cpp dcplusplus/trunk/dcpp/User.h Modified: dcplusplus/trunk/dcpp/AdcHub.cpp =================================================================== --- dcplusplus/trunk/dcpp/AdcHub.cpp 2007-11-16 17:34:06 UTC (rev 910) +++ dcplusplus/trunk/dcpp/AdcHub.cpp 2007-11-16 23:11:07 UTC (rev 911) @@ -527,6 +527,24 @@ } } +static void addParam(StringMap& lastInfoMap, AdcCommand& c, const string& var, const string& value) { + StringMapIter i = lastInfoMap.find(var); + + if(i != lastInfoMap.end()) { + if(i->second != value) { + if(value.empty()) { + lastInfoMap.erase(i); + } else { + i->second = value; + } + c.addParam(var, value); + } + } else if(!value.empty()) { + lastInfoMap.insert(make_pair(var, value)); + c.addParam(var, value); + } +} + void AdcHub::info(bool /*alwaysSend*/) { if(state != STATE_IDENTIFY && state != STATE_NORMAL) return; @@ -534,51 +552,30 @@ reloadSettings(false); AdcCommand c(AdcCommand::CMD_INF, AdcCommand::TYPE_BROADCAST); - string tmp; - StringMapIter i; -#define ADDPARAM(var, content) \ - tmp = content; \ - if((i = lastInfoMap.find(var)) != lastInfoMap.end()) { \ - if(i->second != tmp) { \ - if(tmp.empty()) \ - lastInfoMap.erase(i); \ - else \ - i->second = tmp; \ - c.addParam(var, tmp); \ - } \ - } else if(!tmp.empty()) { \ - c.addParam(var, tmp); \ - lastInfoMap[var] = tmp; \ - } + updateCounts(false); - updateCounts(false); \ + addParam(lastInfoMap, c, "ID", ClientManager::getInstance()->getMyCID().toBase32()); + addParam(lastInfoMap, c, "PD", ClientManager::getInstance()->getMyPID().toBase32()); + addParam(lastInfoMap, c, "NI", getCurrentNick()); + addParam(lastInfoMap, c, "DE", getCurrentDescription()); + addParam(lastInfoMap, c, "SL", Util::toString(SETTING(SLOTS))); + addParam(lastInfoMap, c, "SS", ShareManager::getInstance()->getShareSizeString()); + addParam(lastInfoMap, c, "SF", Util::toString(ShareManager::getInstance()->getSharedFiles())); + addParam(lastInfoMap, c, "EM", SETTING(EMAIL)); + addParam(lastInfoMap, c, "HN", Util::toString(counts.normal)); + addParam(lastInfoMap, c, "HR", Util::toString(counts.registered)); + addParam(lastInfoMap, c, "HO", Util::toString(counts.op)); + addParam(lastInfoMap, c, "VE", "++ " VERSIONSTRING); + addParam(lastInfoMap, c, "US", Util::toString((long)(Util::toDouble(SETTING(UPLOAD_SPEED))*1024*1024))); + addParam(lastInfoMap, c, "AW", Util::getAway() ? "1" : Util::emptyString); - ADDPARAM("ID", ClientManager::getInstance()->getMyCID().toBase32()); - ADDPARAM("PD", ClientManager::getInstance()->getMyPID().toBase32()); - ADDPARAM("NI", getCurrentNick()); - ADDPARAM("DE", getCurrentDescription()); - ADDPARAM("SL", Util::toString(SETTING(SLOTS))); - ADDPARAM("SS", ShareManager::getInstance()->getShareSizeString()); - ADDPARAM("SF", Util::toString(ShareManager::getInstance()->getSharedFiles())); - ADDPARAM("EM", SETTING(EMAIL)); - ADDPARAM("HN", Util::toString(counts.normal)); - ADDPARAM("HR", Util::toString(counts.registered)); - ADDPARAM("HO", Util::toString(counts.op)); - ADDPARAM("VE", "++ " VERSIONSTRING); - ADDPARAM("US", Util::toString((long)(Util::toDouble(SETTING(UPLOAD_SPEED))*1024*1024))); - if(SETTING(MAX_DOWNLOAD_SPEED) > 0) { - ADDPARAM("DS", Util::toString((SETTING(MAX_DOWNLOAD_SPEED)*1024*8))); + addParam(lastInfoMap, c, "DS", Util::toString((SETTING(MAX_DOWNLOAD_SPEED)*1024*8))); } else { - ADDPARAM("DS", Util::emptyString); + addParam(lastInfoMap, c, "DS", Util::emptyString); } - if(Util::getAway()){ - ADDPARAM("AW", '1'); - } else { - ADDPARAM("AW", Util::emptyString); - } string su; if(CryptoManager::getInstance()->TLSOk()) { @@ -587,25 +584,23 @@ if(ClientManager::getInstance()->isActive()) { if(BOOLSETTING(NO_IP_OVERRIDE) && !SETTING(EXTERNAL_IP).empty()) { - ADDPARAM("I4", Socket::resolve(SETTING(EXTERNAL_IP))); + addParam(lastInfoMap, c, "I4", Socket::resolve(SETTING(EXTERNAL_IP))); } else { - ADDPARAM("I4", "0.0.0.0"); + addParam(lastInfoMap, c, "I4", "0.0.0.0"); } - ADDPARAM("U4", Util::toString(SearchManager::getInstance()->getPort())); + addParam(lastInfoMap, c, "U4", Util::toString(SearchManager::getInstance()->getPort())); su += TCP4_FEATURE + ","; su += UDP4_FEATURE + ","; } else { - ADDPARAM("I4", ""); - ADDPARAM("U4", ""); + addParam(lastInfoMap, c, "I4", ""); + addParam(lastInfoMap, c, "U4", ""); } if(!su.empty()) { su.erase(su.size() - 1); } - ADDPARAM("SU", su); + addParam(lastInfoMap, c, "SU", su); -#undef ADDPARAM - if(c.getParameters().size() > 0) { send(c); } Modified: dcplusplus/trunk/dcpp/ConnectionManager.cpp =================================================================== --- dcplusplus/trunk/dcpp/ConnectionManager.cpp 2007-11-16 17:34:06 UTC (rev 910) +++ dcplusplus/trunk/dcpp/ConnectionManager.cpp 2007-11-16 23:11:07 UTC (rev 911) @@ -736,8 +736,6 @@ conn->setFlag(UserConnection::FLAG_SUPPORTS_TTHL); } else if(*i == UserConnection::FEATURE_TTHF) { conn->setFlag(UserConnection::FLAG_SUPPORTS_TTHF); - if(conn->getUser()) - conn->getUser()->setFlag(User::TTH_GET); } } } Modified: dcplusplus/trunk/dcpp/User.cpp =================================================================== --- dcplusplus/trunk/dcpp/User.cpp 2007-11-16 17:34:06 UTC (rev 910) +++ dcplusplus/trunk/dcpp/User.cpp 2007-11-16 23:11:07 UTC (rev 911) @@ -61,6 +61,11 @@ } } +bool Identity::isClientType(ClientType ct) const { + int type = Util::toInt(get("CT")); + return (type & ct) == ct; +} + string Identity::getTag() const { if(!get("TA").empty()) return get("TA"); @@ -69,6 +74,7 @@ return "<" + get("VE") + ",M:" + string(isTcpActive() ? "A" : "P") + ",H:" + get("HN") + "/" + get("HR") + "/" + get("HO") + ",S:" + get("SL") + ">"; } + string Identity::get(const char* name) const { Lock l(cs); InfMap::const_iterator i = info.find(*(short*)name); Modified: dcplusplus/trunk/dcpp/User.h =================================================================== --- dcplusplus/trunk/dcpp/User.h 2007-11-16 17:34:06 UTC (rev 910) +++ dcplusplus/trunk/dcpp/User.h 2007-11-16 23:11:07 UTC (rev 911) @@ -39,7 +39,6 @@ PASSIVE_BIT, NMDC_BIT, BOT_BIT, - TTH_GET_BIT, TLS_BIT, OLD_CLIENT_BIT }; @@ -51,7 +50,6 @@ PASSIVE = 1<<PASSIVE_BIT, NMDC = 1<<NMDC_BIT, BOT = 1<<BOT_BIT, - TTH_GET = 1<<TTH_GET_BIT, //< User supports getting files by tth -> don't have path in queue... TLS = 1<<TLS_BIT, //< Client supports TLS OLD_CLIENT = 1<<OLD_CLIENT_BIT //< Can't download - old client }; @@ -80,7 +78,7 @@ /** One of possibly many identities of a user, mainly for UI purposes */ class Identity : public Flags { public: - enum { + enum IdentityFlagBits { GOT_INF_BIT, NMDC_PASSIVE_BIT }; @@ -88,7 +86,14 @@ GOT_INF = 1 << GOT_INF_BIT, NMDC_PASSIVE = 1 << NMDC_PASSIVE_BIT }; - + enum ClientType { + CT_BOT = 1, + CT_REGGED = 2, + CT_OP = 4, + CT_OWNER = 8, + CT_HUB = 16 + }; + Identity() : sid(0) { } Identity(const UserPtr& ptr, uint32_t aSID) : user(ptr), sid(aSID) { } Identity(const Identity& rhs) : Flags(rhs), user(rhs.user), sid(rhs.sid), info(rhs.info) { } @@ -111,24 +116,26 @@ void setHidden(bool hidden) { set("HI", hidden ? "1" : Util::emptyString); } string getTag() const; bool supports(const string& name) const; - bool isHub() const { return !get("HU").empty(); } - bool isOp() const { return !get("OP").empty(); } - bool isRegistered() const { return !get("RG").empty(); } + bool isHub() const { return isClientType(CT_HUB) || !get("HU").empty(); } + bool isOp() const { return isClientType(CT_OP) || !get("OP").empty(); } + bool isRegistered() const { return isClientType(CT_REGGED) || !get("RG").empty(); } bool isHidden() const { return !get("HI").empty(); } - bool isBot() const { return !get("BO").empty(); } + bool isBot() const { return isClientType(CT_BOT) || !get("BO").empty(); } bool isAway() const { return !get("AW").empty(); } bool isTcpActive() const { return !getIp().empty() || (user->isSet(User::NMDC) && !user->isSet(User::PASSIVE)); } bool isUdpActive() const { return !getIp().empty() && !getUdpPort().empty(); } string get(const char* name) const; void set(const char* name, const string& val); string getSIDString() const { return string((const char*)&sid, 4); } + + bool isClientType(ClientType ct) const; void getParams(StringMap& map, const string& prefix, bool compatibility) const; UserPtr& getUser() { return user; } GETSET(UserPtr, user, User); GETSET(uint32_t, sid, SID); private: - typedef map<short, string> InfMap; + typedef std::tr1::unordered_map<short, string> InfMap; typedef InfMap::iterator InfIter; InfMap info; /** @todo there are probably more threading issues here ...*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |