1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
/*
* 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.
*/
#include "stdinc.h"
#include "DCPlusPlus.h"
#include "User.h"
#include "Client.h"
#include "StringTokenizer.h"
#include "FavoriteUser.h"
OnlineUser::OnlineUser(const User::Ptr& ptr, Client& client_, uint32_t sid_) : identity(ptr, sid_), client(client_) {
}
void Identity::getParams(StringMap& sm, const string& prefix, bool compatibility) const {
{
Lock l(cs);
for(InfMap::const_iterator i = info.begin(); i != info.end(); ++i) {
sm[prefix + string((char*)(&i->first), 2)] = i->second;
}
}
if(user) {
sm[prefix + "SID"] = getSIDString();
sm[prefix + "CID"] = user->getCID().toBase32();
sm[prefix + "TAG"] = getTag();
sm[prefix + "SSshort"] = Util::formatBytes(get("SS"));
if(compatibility) {
if(prefix == "my") {
sm["mynick"] = getNick();
sm["mycid"] = user->getCID().toBase32();
} else {
sm["nick"] = getNick();
sm["cid"] = user->getCID().toBase32();
sm["ip"] = get("I4");
sm["tag"] = getTag();
sm["description"] = get("DE");
sm["email"] = get("EM");
sm["share"] = get("SS");
sm["shareshort"] = Util::formatBytes(get("SS"));
}
}
}
}
string Identity::getTag() const {
if(!get("TA").empty())
return get("TA");
if(get("VE").empty() || get("HN").empty() || get("HR").empty() ||get("HO").empty() || get("SL").empty())
return Util::emptyString;
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);
return i == info.end() ? Util::emptyString : i->second;
}
void Identity::set(const char* name, const string& val) {
Lock l(cs);
if(val.empty())
info.erase(*(short*)name);
else
info[*(short*)name] = val;
}
bool Identity::supports(const string& name) const {
const string& su = get("SU");
StringTokenizer<string> st(su, ',');
for(StringIter i = st.getTokens().begin(); i != st.getTokens().end(); ++i) {
if(*i == name)
return true;
}
return false;
}
void FavoriteUser::update(const OnlineUser& info) {
setNick(info.getIdentity().getNick());
setUrl(info.getClient().getHubUrl());
}
|