mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Fix Lobby auto-subscribe.
Save GxsId for each. Disallow to auto-subscribe to signed lobby with unsigned id.
This commit is contained in:
parent
0d681b149f
commit
cbbc3920fa
@ -23,8 +23,9 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sstream>
|
#include <iomanip>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <sstream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "util/rsprint.h"
|
#include "util/rsprint.h"
|
||||||
@ -536,6 +537,7 @@ void DistributedChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item)
|
|||||||
std::cerr << " lobby is flagged as autosubscribed. Adding it to subscribe list." << std::endl;
|
std::cerr << " lobby is flagged as autosubscribed. Adding it to subscribe list." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
ChatLobbyId clid = item->lobbies[i].id;
|
ChatLobbyId clid = item->lobbies[i].id;
|
||||||
|
if(_chat_lobbys.find(clid) == _chat_lobbys.end())
|
||||||
chatLobbyToSubscribe.push_back(clid);
|
chatLobbyToSubscribe.push_back(clid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,7 +558,35 @@ void DistributedChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item)
|
|||||||
|
|
||||||
std::list<ChatLobbyId>::iterator it;
|
std::list<ChatLobbyId>::iterator it;
|
||||||
for (it = chatLobbyToSubscribe.begin(); it != chatLobbyToSubscribe.end(); ++it)
|
for (it = chatLobbyToSubscribe.begin(); it != chatLobbyToSubscribe.end(); ++it)
|
||||||
joinVisibleChatLobby(*it,_default_identity);
|
{
|
||||||
|
RsGxsId gxsId = _lobby_default_identity[*it];
|
||||||
|
if (gxsId.isNull())
|
||||||
|
gxsId = _default_identity;
|
||||||
|
|
||||||
|
//Check if gxsId can connect to this lobby
|
||||||
|
ChatLobbyFlags flags(0);
|
||||||
|
std::map<ChatLobbyId,VisibleChatLobbyRecord>::const_iterator vlIt = _visible_lobbies.find(*it) ;
|
||||||
|
if(vlIt != _visible_lobbies.end())
|
||||||
|
flags = vlIt->second.lobby_flags;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::map<ChatLobbyId,ChatLobbyEntry>::const_iterator clIt = _chat_lobbys.find(*it) ;
|
||||||
|
|
||||||
|
if(clIt != _chat_lobbys.end())
|
||||||
|
flags = clIt->second.lobby_flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsIdentityDetails idd ;
|
||||||
|
if(IS_PGP_SIGNED_LOBBY(flags)
|
||||||
|
&& (!rsIdentity->getIdDetails(gxsId,idd)
|
||||||
|
|| !(idd.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED)) )
|
||||||
|
{
|
||||||
|
std::cerr << "(EE) Attempt to auto-subscribe to signed lobby with non signed Id. Remove it." << std::endl;
|
||||||
|
setLobbyAutoSubscribe(*it, false);
|
||||||
|
} else {
|
||||||
|
joinVisibleChatLobby(*it,gxsId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for(std::list<ChatLobbyId>::const_iterator it = invitationNeeded.begin();it!=invitationNeeded.end();++it)
|
for(std::list<ChatLobbyId>::const_iterator it = invitationNeeded.begin();it!=invitationNeeded.end();++it)
|
||||||
invitePeerToLobby(*it,item->PeerId(),false) ;
|
invitePeerToLobby(*it,item->PeerId(),false) ;
|
||||||
@ -1765,10 +1795,15 @@ bool DistributedChatService::setIdentityForChatLobby(const ChatLobbyId& lobby_id
|
|||||||
|
|
||||||
void DistributedChatService::setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe)
|
void DistributedChatService::setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe)
|
||||||
{
|
{
|
||||||
if(autoSubscribe)
|
if(autoSubscribe){
|
||||||
_known_lobbies_flags[lobby_id] |= RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE;
|
_known_lobbies_flags[lobby_id] |= RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE;
|
||||||
else
|
RsGxsId gxsId;
|
||||||
|
if (getIdentityForChatLobby(lobby_id, gxsId))
|
||||||
|
_lobby_default_identity[lobby_id] = gxsId;
|
||||||
|
} else {
|
||||||
_known_lobbies_flags[lobby_id] &= ~RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE ;
|
_known_lobbies_flags[lobby_id] &= ~RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE ;
|
||||||
|
_lobby_default_identity.erase(lobby_id);
|
||||||
|
}
|
||||||
|
|
||||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
|
RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
|
||||||
triggerConfigSave();
|
triggerConfigSave();
|
||||||
@ -1899,23 +1934,46 @@ void DistributedChatService::addToSaveList(std::list<RsItem*>& list) const
|
|||||||
|
|
||||||
list.push_back(clci) ;
|
list.push_back(clci) ;
|
||||||
}
|
}
|
||||||
/* Save Default Nick Name */
|
|
||||||
|
|
||||||
|
/* Save Default Nick Name */
|
||||||
|
{
|
||||||
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||||
RsTlvKeyValue kv;
|
RsTlvKeyValue kv;
|
||||||
kv.key = "DEFAULT_IDENTITY";
|
kv.key = "DEFAULT_IDENTITY";
|
||||||
kv.value = _default_identity.toStdString();
|
kv.value = _default_identity.toStdString();
|
||||||
vitem->tlvkvs.pairs.push_back(kv);
|
vitem->tlvkvs.pairs.push_back(kv);
|
||||||
|
|
||||||
list.push_back(vitem);
|
list.push_back(vitem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Save Default Nick Name by Lobby*/
|
||||||
|
for(std::map<ChatLobbyId,RsGxsId>::const_iterator it=_lobby_default_identity.begin(); it!=_lobby_default_identity.end(); ++it)
|
||||||
|
{
|
||||||
|
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||||
|
ChatLobbyId cli = it->first;
|
||||||
|
RsGxsId gxsId = it->second;
|
||||||
|
|
||||||
|
std::stringstream stream;
|
||||||
|
stream << std::setfill ('0') << std::setw(sizeof(ChatLobbyId)*2)
|
||||||
|
<< std::hex << cli;
|
||||||
|
std::string strCli( stream.str() );
|
||||||
|
|
||||||
|
RsTlvKeyValue kv;
|
||||||
|
kv.key = "LOBBY_DEFAULT_IDENTITY:"+strCli;
|
||||||
|
kv.value = gxsId.toStdString();
|
||||||
|
vitem->tlvkvs.pairs.push_back(kv);
|
||||||
|
list.push_back(vitem);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool DistributedChatService::processLoadListItem(const RsItem *item)
|
bool DistributedChatService::processLoadListItem(const RsItem *item)
|
||||||
{
|
{
|
||||||
const RsConfigKeyValueSet *vitem = NULL;
|
const RsConfigKeyValueSet *vitem = NULL;
|
||||||
|
const std::string strldID = "LOBBY_DEFAULT_IDENTITY:";
|
||||||
|
|
||||||
if(NULL != (vitem = dynamic_cast<const RsConfigKeyValueSet*>(item)))
|
if(NULL != (vitem = dynamic_cast<const RsConfigKeyValueSet*>(item)))
|
||||||
for(std::list<RsTlvKeyValue>::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit)
|
for(std::list<RsTlvKeyValue>::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit)
|
||||||
|
{
|
||||||
if( kit->key == "DEFAULT_IDENTITY" )
|
if( kit->key == "DEFAULT_IDENTITY" )
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_CHAT_LOBBIES
|
#ifdef DEBUG_CHAT_LOBBIES
|
||||||
@ -1931,6 +1989,31 @@ bool DistributedChatService::processLoadListItem(const RsItem *item)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( kit->key.compare(0, strldID.length(), strldID) == 0)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_CHAT_LOBBIES
|
||||||
|
std::cerr << "Loaded config lobby default nick name: " << kit->key << " " << kit->value << std::endl ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::string strCli = kit->key.substr(strldID.length());
|
||||||
|
std::stringstream stream;
|
||||||
|
stream << std::hex << strCli;
|
||||||
|
ChatLobbyId cli = 0;
|
||||||
|
stream >> cli;
|
||||||
|
|
||||||
|
if (!kit->value.empty() && (cli != 0))
|
||||||
|
{
|
||||||
|
RsGxsId gxsId(kit->value);
|
||||||
|
if (gxsId.isNull())
|
||||||
|
std::cerr << "ERROR: lobby default identity is malformed." << std::endl;
|
||||||
|
else
|
||||||
|
_lobby_default_identity[cli] = gxsId ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const RsChatLobbyConfigItem *clci = NULL ;
|
const RsChatLobbyConfigItem *clci = NULL ;
|
||||||
|
|
||||||
if(NULL != (clci = dynamic_cast<const RsChatLobbyConfigItem*>(item)))
|
if(NULL != (clci = dynamic_cast<const RsChatLobbyConfigItem*>(item)))
|
||||||
|
@ -159,6 +159,7 @@ class DistributedChatService
|
|||||||
time_t last_visible_lobby_info_request_time ; // allows to ask for updates
|
time_t last_visible_lobby_info_request_time ; // allows to ask for updates
|
||||||
bool _should_reset_lobby_counts ;
|
bool _should_reset_lobby_counts ;
|
||||||
RsGxsId _default_identity;
|
RsGxsId _default_identity;
|
||||||
|
std::map<ChatLobbyId,RsGxsId> _lobby_default_identity;
|
||||||
|
|
||||||
uint32_t mServType ;
|
uint32_t mServType ;
|
||||||
RsMutex mDistributedChatMtx ;
|
RsMutex mDistributedChatMtx ;
|
||||||
|
@ -820,7 +820,8 @@ void ChatLobbyWidget::autoSubscribeLobby(QTreeWidgetItem *item)
|
|||||||
ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
|
ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
|
||||||
bool isAutoSubscribe = rsMsgs->getLobbyAutoSubscribe(id);
|
bool isAutoSubscribe = rsMsgs->getLobbyAutoSubscribe(id);
|
||||||
rsMsgs->setLobbyAutoSubscribe(id, !isAutoSubscribe);
|
rsMsgs->setLobbyAutoSubscribe(id, !isAutoSubscribe);
|
||||||
if (!isAutoSubscribe) subscribeChatLobbyAtItem(item);
|
if (!isAutoSubscribe && !item->data(COLUMN_DATA, ROLE_SUBSCRIBED).toBool())
|
||||||
|
subscribeChatLobbyAtItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatLobbyWidget::showBlankPage(ChatLobbyId id)
|
void ChatLobbyWidget::showBlankPage(ChatLobbyId id)
|
||||||
|
Loading…
Reference in New Issue
Block a user