本文整理汇总了C++中UserPtr::getCID方法的典型用法代码示例。如果您正苦于以下问题:C++ UserPtr::getCID方法的具体用法?C++ UserPtr::getCID怎么用?C++ UserPtr::getCID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserPtr
的用法示例。
在下文中一共展示了UserPtr::getCID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getPath
string LogManager::getPath(const UserPtr& aUser, ParamMap& params, bool addCache /*false*/) {
if (aUser->isNMDC() || !SETTING(PM_LOG_GROUP_CID)) {
return getPath(PM, params);
}
//is it cached?
auto p = pmPaths.find(aUser->getCID());
if (p != pmPaths.end()) {
//can we still use the same dir?
if (Util::getFilePath(getPath(PM, params)) == Util::getFilePath(p->second))
return p->second;
}
//check the directory
string fileName = getSetting(PM, FILE);
ensureParam("%[userCID]", fileName);
string path = SETTING(LOG_DIRECTORY) + Util::formatParams(fileName, params);
auto files = File::findFiles(Util::getFilePath(path), "*" + aUser->getCID().toBase32() + "*", File::TYPE_FILE);
if (!files.empty()) {
path = files.front();
}
if (addCache)
pmPaths.emplace(aUser->getCID(), path);
return path;
}
示例2: serializeUser
json Serializer::serializeUser(const UserPtr& aUser) noexcept {
return{
{ "cid", aUser->getCID().toBase32() },
{ "nicks", Util::listToString(ClientManager::getInstance()->getNicks(aUser->getCID())) },
{ "hubs", Util::listToString(ClientManager::getInstance()->getHubNames(aUser->getCID())) },
{ "flags", getUserFlags(aUser) }
};
}
示例3: isOp
bool ClientManager::isOp(const UserPtr& user, const string& aHubUrl) const {
Lock l(cs);
OnlinePairC p = onlineUsers.equal_range(user->getCID());
for(auto i = p.first; i != p.second; ++i) {
if(i->second->getClient().getHubUrl() == aHubUrl) {
return i->second->getIdentity().isOp();
}
}
return false;
}
示例4: l
vector<Identity> ClientManager::getIdentities(const UserPtr &u) const {
Lock l(cs);
auto op = onlineUsers.equal_range(u->getCID());
auto ret = vector<Identity>();
for(auto i = op.first; i != op.second; ++i) {
ret.push_back(i->second->getIdentity());
}
return ret;
}
示例5: on
void UserApi::on(ClientManagerListener::UserDisconnected, const UserPtr& aUser, bool aWentOffline) noexcept {
if (aUser->getCID() == CID())
return;
maybeSend("user_disconnected", [&] {
return json({
{ "user", Serializer::serializeUser(aUser) },
{ "went_offline", aWentOffline },
});
});
}
示例6: onRES
void SearchManager::onRES(const AdcCommand& cmd, const UserPtr& from, const string& remoteIp) {
int freeSlots = -1;
int64_t size = -1;
string file;
string tth;
string token;
for(StringIterC i = cmd.getParameters().begin(); i != cmd.getParameters().end(); ++i) {
const string& str = *i;
if(str.compare(0, 2, "FN") == 0) {
file = Util::toNmdcFile(str.substr(2));
} else if(str.compare(0, 2, "SL") == 0) {
freeSlots = Util::toInt(str.substr(2));
} else if(str.compare(0, 2, "SI") == 0) {
size = Util::toInt64(str.substr(2));
} else if(str.compare(0, 2, "TR") == 0) {
tth = str.substr(2);
} else if(str.compare(0, 2, "TO") == 0) {
token = str.substr(2);
}
}
if(!file.empty() && freeSlots != -1 && size != -1) {
/// @todo get the hub this was sent from, to be passed as a hint? (eg by using the token?)
StringList names = ClientManager::getInstance()->getHubNames(from->getCID(), Util::emptyString);
string hubName = names.empty() ? _("Offline") : Util::toString(names);
StringList hubs = ClientManager::getInstance()->getHubs(from->getCID(), Util::emptyString);
string hub = hubs.empty() ? _("Offline") : Util::toString(hubs);
SearchResult::Types type = (file[file.length() - 1] == '\\' ? SearchResult::TYPE_DIRECTORY : SearchResult::TYPE_FILE);
if(type == SearchResult::TYPE_FILE && tth.empty())
return;
/// @todo Something about the slots
SearchResultPtr sr(new SearchResult(from, type, 0, freeSlots, size,
file, hubName, hub, remoteIp, TTHValue(tth), token));
fire(SearchManagerListener::SR(), sr);
}
}
示例7: connect
void UserConnection::connect(const Socket::AddressInfo& aServer, const string& aPort, const string& localPort, BufferedSocket::NatRoles natRole, const UserPtr& aUser /*nullptr*/) {
dcassert(!socket);
socket = BufferedSocket::getSocket(0);
socket->addListener(this);
string expKP;
if (aUser) {
expKP = ClientManager::getInstance()->getField(aUser->getCID(), hubUrl, "KP");
setUser(aUser);
}
socket->connect(aServer, aPort, localPort, natRole, secure, SETTING(ALLOW_UNTRUSTED_CLIENTS), true, expKP);
}
示例8:
void UsersFrame::UserInfo::update(const UserPtr& u, bool visible) {
auto fu = FavoriteManager::getInstance()->getFavoriteUser(u);
if(fu) {
isFavorite = true;
grantSlot = fu->isSet(FavoriteUser::FLAG_GRANTSLOT);
columns[COLUMN_NICK] = Text::toT(fu->getNick());
if(!visible) {
return;
}
columns[COLUMN_DESCRIPTION] = Text::toT(fu->getDescription());
if(u->isOnline()) {
columns[COLUMN_SEEN] = T_("Online");
columns[COLUMN_HUB] = WinUtil::getHubNames(u->getCID()).first;
} else {
columns[COLUMN_SEEN] = fu->getLastSeen() > 0 ? Text::toT(Util::formatTime("%Y-%m-%d %H:%M", fu->getLastSeen())) : T_("Offline");
columns[COLUMN_HUB] = Text::toT(fu->getUrl());
}
} else {
isFavorite = false;
grantSlot = false;
columns[COLUMN_NICK] = WinUtil::getNicks(u->getCID());
if(!visible) {
return;
}
if(u->isOnline()) {
columns[COLUMN_SEEN] = T_("Online");
columns[COLUMN_HUB] = WinUtil::getHubNames(u->getCID()).first;
} else {
columns[COLUMN_SEEN] = T_("Offline");
}
}
columns[COLUMN_CID] = Text::toT(u->getCID().toBase32());
}
示例9: onRES
void SearchManager::onRES(const AdcCommand& cmd, const UserPtr& from, const string& remoteIp) {
int freeSlots = -1;
int64_t size = -1;
string file;
string tth;
string token;
for(auto& str: cmd.getParameters()) {
if(str.compare(0, 2, "FN") == 0) {
file = Util::toNmdcFile(str.substr(2));
} else if(str.compare(0, 2, "SL") == 0) {
freeSlots = Util::toInt(str.substr(2));
} else if(str.compare(0, 2, "SI") == 0) {
size = Util::toInt64(str.substr(2));
} else if(str.compare(0, 2, "TR") == 0) {
tth = str.substr(2);
} else if(str.compare(0, 2, "TO") == 0) {
token = str.substr(2);
}
}
if(file.empty() || freeSlots == -1 || size == -1) { return; }
auto type = (*(file.end() - 1) == '\\' ? SearchResult::TYPE_DIRECTORY : SearchResult::TYPE_FILE);
if(type == SearchResult::TYPE_FILE && tth.empty()) { return; }
string hubUrl;
// token format: [per-hub unique id] "/" [per-search actual token] (see AdcHub::search)
auto slash = token.find('/');
if(slash == string::npos) { return; }
{
auto uniqueId = Util::toUInt32(token.substr(0, slash));
auto lock = ClientManager::getInstance()->lock();
auto& clients = ClientManager::getInstance()->getClients();
auto i = boost::find_if(clients, [uniqueId](const Client* client) { return client->getUniqueId() == uniqueId; });
if(i == clients.end()) { return; }
hubUrl = (*i)->getHubUrl();
}
token.erase(0, slash + 1);
StringList names = ClientManager::getInstance()->getHubNames(from->getCID());
string hubName = names.empty() ? _("Offline") : Util::toString(names);
/// @todo Something about the slots
fire(SearchManagerListener::SR(), SearchResultPtr(new SearchResult(HintedUser(from, hubUrl),
type, 0, freeSlots, size, file, hubName, remoteIp, TTHValue(tth), token)));
}
示例10: updateDupeType
DupeType ChatLink::updateDupeType(const UserPtr& aUser) {
if (type == TYPE_RELEASE) {
if (ShareManager::getInstance()->isDirShared(url)) {
dupe = DUPE_SHARE;
} else {
auto qd = QueueManager::getInstance()->isDirQueued(url);
if (qd == 1) {
dupe = DUPE_QUEUE;
} else if (qd == 2) {
dupe = DUPE_FINISHED;
}
}
} else if (type == TYPE_MAGNET) {
Magnet m = Magnet(url);
dupe = m.getDupeType();
if (dupe == DUPE_NONE && ShareManager::getInstance()->isTempShared(aUser ? aUser->getCID().toBase32() : Util::emptyString, m.getTTH())) {
dupe = DUPE_SHARE;
}
}
return dupe;
}
示例11: getParams
void DownloadQueue::getParams(DownloadQueue::VarMap ¶ms, const QueueItem *item){
QString nick = "";
QMap<QString, QString> source;
int online = 0;
if (!item)
return;
params["FNAME"] = _q(item->getTargetFileName());
params["PATH"] = _q(Util::getFilePath(item->getTarget()));
params["TARGET"] = _q(item->getTarget());
params["USERS"] = QString("");
QStringList user_list;
QueueItem::SourceConstIter it = item->getSources().begin();
for (; it != item->getSources().end(); ++it){
HintedUser usr = it->getUser();
const dcpp::CID &cid = usr.user->getCID();
if (usr.user->isOnline())
++online;
nick = WulforUtil::getInstance()->getNicks(cid, _q(usr.hint));
if (!nick.isEmpty()){
source[nick] = _q(cid.toBase32());
user_list.push_back(nick);
}
}
if (!user_list.isEmpty())
params["USERS"] = user_list.join(", ");
else
params["USERS"] = tr("No users...");
Q_D(DownloadQueue);
d->sources[_q(item->getTarget())] = source;
if (item->isWaiting())
params["STATUS"] = tr("%1 of %2 user(s) online").arg(online).arg(item->getSources().size());
else
params["STATUS"] = tr("Running...");
params["ESIZE"] = (qlonglong)item->getSize();
params["DOWN"] = (qlonglong)item->getDownloadedBytes();
params["PRIO"] = static_cast<int>(item->getPriority());
source.clear();
params["ERRORS"] = QString("");
it = item->getBadSources().begin();
for (; it != item->getBadSources().end(); ++it){
QString errors = params["ERRORS"].toString();
UserPtr usr = it->getUser();
nick = WulforUtil::getInstance()->getNicks(usr->getCID());
source[nick] = _q(usr->getCID().toBase32());
if (!it->isSet(QueueItem::Source::FLAG_REMOVED)){
if (!errors.isEmpty())
errors += ", ";
errors += nick + " (";
if (it->isSet(QueueItem::Source::FLAG_FILE_NOT_AVAILABLE))
errors += tr("File not available");
else if (it->isSet(QueueItem::Source::FLAG_PASSIVE))
errors += tr("Passive user");
else if (it->isSet(QueueItem::Source::FLAG_CRC_FAILED))
errors += tr("Checksum mismatch");
else if (it->isSet(QueueItem::Source::FLAG_BAD_TREE))
errors += tr("Full tree does not match TTH root");
else if (it->isSet(QueueItem::Source::FLAG_SLOW_SOURCE))
errors += tr("Source too slow");
else if (it->isSet(QueueItem::Source::FLAG_NO_TTHF))
errors += tr("Remote client does not fully support TTH - cannot download");
params["ERRORS"] = errors + ")";
}
}
if (params["ERRORS"].toString().isEmpty())
params["ERRORS"] = tr("No errors");
d->badSources[_q(item->getTarget())] = source;
params["ADDED"] = _q(Util::formatTime("%Y-%m-%d %H:%M", item->getAdded()));
params["TTH"] = _q(item->getTTH().toBase32());
}
示例12: removePmCache
void LogManager::removePmCache(const UserPtr& aUser) {
pmPaths.erase(aUser->getCID());
}
示例13: onPSR
void SearchManager::onPSR(const AdcCommand& cmd, UserPtr from, const string& remoteIp) {
uint16_t udpPort = 0;
uint32_t partialCount = 0;
string tth;
string hubIpPort;
string nick;
PartsInfo partialInfo;
for(StringIterC i = cmd.getParameters().begin(); i != cmd.getParameters().end(); ++i) {
const string& str = *i;
if(str.compare(0, 2, "U4") == 0) {
udpPort = static_cast<uint16_t>(Util::toInt(str.substr(2)));
} else if(str.compare(0, 2, "NI") == 0) {
nick = str.substr(2);
} else if(str.compare(0, 2, "HI") == 0) {
hubIpPort = str.substr(2);
} else if(str.compare(0, 2, "TR") == 0) {
tth = str.substr(2);
} else if(str.compare(0, 2, "PC") == 0) {
partialCount = Util::toUInt32(str.substr(2))*2;
} else if(str.compare(0, 2, "PI") == 0) {
StringTokenizer<string> tok(str.substr(2), ',');
for(StringIter i = tok.getTokens().begin(); i != tok.getTokens().end(); ++i) {
partialInfo.push_back((uint16_t)Util::toInt(*i));
}
}
}
string url = ClientManager::getInstance()->findHub(hubIpPort);
if(!from || from == ClientManager::getInstance()->getMe()) {
// for NMDC support
if(nick.empty() || hubIpPort.empty()) {
return;
}
from = ClientManager::getInstance()->findUser(nick, url);
if(!from) {
// Could happen if hub has multiple URLs / IPs
from = ClientManager::getInstance()->findLegacyUser(nick);
if(!from) {
dcdebug("Search result from unknown user");
return;
}
}
}
//ClientManager::getInstance()->setIPUser(from, remoteIp, udpPort);
if(partialInfo.size() != partialCount) {
// what to do now ? just ignore partial search result :-/
return;
}
PartsInfo outPartialInfo;
QueueItem::PartialSource ps(from->isNMDC() ? ClientManager::getInstance()->getClient(url)->getMyIdentity().getNick() : Util::emptyString, hubIpPort, remoteIp, udpPort);
ps.setPartialInfo(partialInfo);
QueueManager::getInstance()->handlePartialResult(from, url, TTHValue(tth), ps, outPartialInfo);
if((udpPort > 0) && !outPartialInfo.empty()) {
try {
AdcCommand cmd = SearchManager::getInstance()->toPSR(false, ps.getMyNick(), hubIpPort, tth, outPartialInfo);
ClientManager::getInstance()->send(cmd, from->getCID());
} catch(...) {
dcdebug("Partial search caught error\n");
}
}
}
示例14: onData
void SearchManager::onData(const uint8_t* buf, size_t aLen, const string& remoteIp) {
string x((char*)buf, aLen);
if(x.compare(0, 4, "$SR ") == 0) {
string::size_type i, j;
// Directories: $SR <nick><0x20><directory><0x20><free slots>/<total slots><0x05><Hubname><0x20>(<Hubip:port>)
// Files: $SR <nick><0x20><filename><0x05><filesize><0x20><free slots>/<total slots><0x05><Hubname><0x20>(<Hubip:port>)
i = 4;
if( (j = x.find(' ', i)) == string::npos) {
return;
}
string nick = x.substr(i, j-i);
i = j + 1;
// A file has 2 0x05, a directory only one
size_t cnt = count(x.begin() + j, x.end(), 0x05);
SearchResult::Types type = SearchResult::TYPE_FILE;
string file;
int64_t size = 0;
if(cnt == 1) {
// We have a directory...find the first space beyond the first 0x05 from the back
// (dirs might contain spaces as well...clever protocol, eh?)
type = SearchResult::TYPE_DIRECTORY;
// Get past the hubname that might contain spaces
if((j = x.rfind(0x05)) == string::npos) {
return;
}
// Find the end of the directory info
if((j = x.rfind(' ', j-1)) == string::npos) {
return;
}
if(j < i + 1) {
return;
}
file = x.substr(i, j-i) + '\\';
} else if(cnt == 2) {
if( (j = x.find((char)5, i)) == string::npos) {
return;
}
file = x.substr(i, j-i);
i = j + 1;
if( (j = x.find(' ', i)) == string::npos) {
return;
}
size = Util::toInt64(x.substr(i, j-i));
}
i = j + 1;
if( (j = x.find('/', i)) == string::npos) {
return;
}
int freeSlots = Util::toInt(x.substr(i, j-i));
i = j + 1;
if( (j = x.find((char)5, i)) == string::npos) {
return;
}
int slots = Util::toInt(x.substr(i, j-i));
i = j + 1;
if( (j = x.rfind(" (")) == string::npos) {
return;
}
string hubName = x.substr(i, j-i);
i = j + 2;
if( (j = x.rfind(')')) == string::npos) {
return;
}
string hubIpPort = x.substr(i, j-i);
string url = ClientManager::getInstance()->findHub(hubIpPort);
string encoding = ClientManager::getInstance()->findHubEncoding(url);
nick = Text::toUtf8(nick, encoding);
file = Text::toUtf8(file, encoding);
hubName = Text::toUtf8(hubName, encoding);
UserPtr user = ClientManager::getInstance()->findUser(nick, url);
if(!user) {
// Could happen if hub has multiple URLs / IPs
user = ClientManager::getInstance()->findLegacyUser(nick);
if(!user)
return;
}
string tth;
if(hubName.compare(0, 4, "TTH:") == 0) {
tth = hubName.substr(4);
StringList names = ClientManager::getInstance()->getHubNames(user->getCID(), Util::emptyString);
hubName = names.empty() ? _("Offline") : Util::toString(names);
}
if(tth.empty() && type == SearchResult::TYPE_FILE) {
return;
}
SearchResultPtr sr(new SearchResult(user, type, slots, freeSlots, size,
file, hubName, url, remoteIp, TTHValue(tth), Util::emptyString));
fire(SearchManagerListener::SR(), sr);
//.........这里部分代码省略.........
示例15: onFlagsUpdated
void HubInfo::onFlagsUpdated(const UserPtr& aUser) noexcept {
auto ou = ClientManager::getInstance()->findOnlineUser(aUser->getCID(), client->getHubUrl(), false);
if (ou) {
onUserUpdated(ou, { PROP_FLAGS });
}
}