Merge pull request #774 from PhenomRetroShare/Fix_LobbyTopic

Fix Lobby Topic not send on invite.
This commit is contained in:
csoler 2017-05-10 20:00:42 +02:00 committed by GitHub
commit 3cc79fb242
6 changed files with 108 additions and 29 deletions

View File

@ -428,14 +428,14 @@ bool DistributedChatService::handleRecvItem(RsChatItem *item)
{
switch(item->PacketSubType())
{
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT: handleRecvChatLobbyEventItem (dynamic_cast<RsChatLobbyEventItem *>(item)) ; break ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: handleRecvLobbyInvite (dynamic_cast<RsChatLobbyInviteItem *>(item)) ; break ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE: handleConnectionChallenge (dynamic_cast<RsChatLobbyConnectChallengeItem *>(item)) ; break ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE: handleFriendUnsubscribeLobby (dynamic_cast<RsChatLobbyUnsubscribeItem *>(item)) ; break ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST: handleRecvChatLobbyListRequest (dynamic_cast<RsChatLobbyListRequestItem *>(item)) ; break ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: handleRecvChatLobbyList (dynamic_cast<RsChatLobbyListItem *>(item)) ; break ;
default:
return false ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT: handleRecvChatLobbyEventItem (dynamic_cast<RsChatLobbyEventItem *>(item)) ; break ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE_DEPRECATED: handleRecvLobbyInvite_Deprecated (dynamic_cast<RsChatLobbyInviteItem_Deprecated*>(item)) ; break ; // to be removed (deprecated since May 2017)
case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: handleRecvLobbyInvite (dynamic_cast<RsChatLobbyInviteItem *>(item)) ; break ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE: handleConnectionChallenge (dynamic_cast<RsChatLobbyConnectChallengeItem *>(item)) ; break ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE: handleFriendUnsubscribeLobby (dynamic_cast<RsChatLobbyUnsubscribeItem *>(item)) ; break ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST: handleRecvChatLobbyListRequest (dynamic_cast<RsChatLobbyListRequestItem *>(item)) ; break ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: handleRecvChatLobbyList (dynamic_cast<RsChatLobbyListItem *>(item)) ; break ;
default: return false ;
}
return true ;
}
@ -1233,14 +1233,45 @@ void DistributedChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, cons
RsChatLobbyInviteItem *item = new RsChatLobbyInviteItem ;
item->lobby_id = lobby_id ;
item->lobby_name = it->second.lobby_name ;
item->lobby_topic = it->second.lobby_topic ;
item->lobby_flags = connexion_challenge?RS_CHAT_LOBBY_FLAGS_CHALLENGE:(it->second.lobby_flags) ;
item->lobby_id = lobby_id ;
item->lobby_name = it->second.lobby_name ;
item->lobby_topic = it->second.lobby_topic ;
item->lobby_flags = connexion_challenge?RS_CHAT_LOBBY_FLAGS_CHALLENGE:(it->second.lobby_flags) ;
item->PeerId(peer_id) ;
sendChatItem(item) ;
//FOR BACKWARD COMPATIBILITY
{// to be removed (deprecated since May 2017)
RsChatLobbyInviteItem_Deprecated *item = new RsChatLobbyInviteItem_Deprecated ;
item->lobby_id = lobby_id ;
item->lobby_name = it->second.lobby_name ;
item->lobby_topic = it->second.lobby_topic ;
item->lobby_flags = connexion_challenge?RS_CHAT_LOBBY_FLAGS_CHALLENGE:(it->second.lobby_flags) ;
item->PeerId(peer_id) ;
sendChatItem(item) ;
}
}
// to be removed (deprecated since May 2017)
void DistributedChatService::handleRecvLobbyInvite_Deprecated(RsChatLobbyInviteItem_Deprecated *item)
{
#ifdef DEBUG_CHAT_LOBBIES
std::cerr << "Received deprecated invite to lobby from " << item->PeerId() << " to lobby " << std::hex << item->lobby_id << std::dec << ", named " << item->lobby_name << item->lobby_topic << std::endl;
#endif
RsChatLobbyInviteItem* newItem = new RsChatLobbyInviteItem();
newItem->lobby_id = item->lobby_id ;
newItem->lobby_name = item->lobby_name ;
newItem->lobby_topic = item->lobby_topic ;
newItem->lobby_flags = item->lobby_flags ;
newItem->PeerId( item->PeerId() );
handleRecvLobbyInvite(newItem);
}
void DistributedChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item)
{
#ifdef DEBUG_CHAT_LOBBIES
@ -1259,10 +1290,10 @@ void DistributedChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item)
{
#ifdef DEBUG_CHAT_LOBBIES
std::cerr << " Lobby already exists. " << std::endl;
std::cerr << " privacy levels: " << item->lobby_flags << " vs. " << it->second.lobby_flags ;
std::cerr << " privacy levels: " << item->lobby_flags << " vs. " << it->second.lobby_flags ;
#endif
if((!IS_CONNEXION_CHALLENGE(item->lobby_flags)) && EXTRACT_PRIVACY_FLAGS(item->lobby_flags) != EXTRACT_PRIVACY_FLAGS(it->second.lobby_flags))
if ((!IS_CONNEXION_CHALLENGE(item->lobby_flags)) && EXTRACT_PRIVACY_FLAGS(item->lobby_flags) != EXTRACT_PRIVACY_FLAGS(it->second.lobby_flags))
{
std::cerr << " : Don't match. Cancelling." << std::endl;
return ;
@ -1274,10 +1305,22 @@ void DistributedChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item)
std::cerr << " Adding new friend " << item->PeerId() << " to lobby." << std::endl;
#endif
// to be removed (deprecated since May 2017)
{ //Update Topics if have received deprecated before (withou topic)
if(it->second.lobby_topic.empty() && !item->lobby_topic.empty())
it->second.lobby_topic = item->lobby_topic;
}
it->second.participating_friends.insert(item->PeerId()) ;
return ;
}
// to be removed (deprecated since May 2017)
{//check if invitation is already received by deprecated version
std::map<ChatLobbyId,ChatLobbyInvite>::const_iterator it(_lobby_invites_queue.find( item->lobby_id)) ;
if(it != _lobby_invites_queue.end())
return ;
}
// Don't record the invitation if it's a challenge response item or a lobby we don't have.
//
if(IS_CONNEXION_CHALLENGE(item->lobby_flags))
@ -1290,7 +1333,7 @@ void DistributedChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item)
invite.peer_id = item->PeerId() ;
invite.lobby_name = item->lobby_name ;
invite.lobby_topic = item->lobby_topic ;
invite.lobby_flags = item->lobby_flags ;
invite.lobby_flags = item->lobby_flags ;
_lobby_invites_queue[item->lobby_id] = invite ;
}

View File

@ -39,6 +39,7 @@ class RsChatLobbyListRequestItem ;
class RsChatLobbyListItem ;
class RsChatLobbyEventItem ;
class RsChatLobbyBouncingObject ;
class RsChatLobbyInviteItem_Deprecated ; // to be removed (deprecated since May 2017)
class RsChatLobbyInviteItem ;
class RsChatLobbyMsgItem ;
class RsChatLobbyConnectChallengeItem ;
@ -111,6 +112,7 @@ class DistributedChatService
/// receive and handle chat lobby item
bool recvLobbyChat(RsChatLobbyMsgItem*,const RsPeerId& src_peer_id) ;
void handleRecvLobbyInvite_Deprecated(RsChatLobbyInviteItem_Deprecated*) ; // to be removed (deprecated since May 2017)
void handleRecvLobbyInvite(RsChatLobbyInviteItem*) ;
void checkAndRedirectMsgToLobby(RsChatMsgItem*) ;
void handleConnectionChallenge(RsChatLobbyConnectChallengeItem *item) ;

View File

@ -44,18 +44,19 @@ RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) c
switch(item_sub_id)
{
case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem() ;
case RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG: return new RsPrivateChatMsgConfigItem() ;
case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem() ;
case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG: return new RsChatLobbyMsgItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: return new RsChatLobbyInviteItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE: return new RsChatLobbyConnectChallengeItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE: return new RsChatLobbyUnsubscribeItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT:return new RsChatLobbyEventItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST:return new RsChatLobbyListRequestItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: return new RsChatLobbyListItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG: return new RsChatLobbyConfigItem() ;
case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem() ;
case RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG: return new RsPrivateChatMsgConfigItem() ;
case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem() ;
case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG: return new RsChatLobbyMsgItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE_DEPRECATED: return new RsChatLobbyInviteItem_Deprecated() ; // to be removed (deprecated since May 2017)
case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: return new RsChatLobbyInviteItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE: return new RsChatLobbyConnectChallengeItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE: return new RsChatLobbyUnsubscribeItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT: return new RsChatLobbyEventItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST: return new RsChatLobbyListRequestItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: return new RsChatLobbyListItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG: return new RsChatLobbyConfigItem() ;
default:
std::cerr << "Unknown packet type in chat!" << std::endl ;
return NULL ;
@ -135,10 +136,19 @@ void RsChatLobbyConnectChallengeItem::serial_process(RsGenericSerializer::Serial
RsTypeSerializer::serial_process<uint64_t>(j,ctx,challenge_code,"challenge_code") ;
}
// to be removed (deprecated since May 2017)
void RsChatLobbyInviteItem_Deprecated::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t>(j,ctx, lobby_id, "lobby_id") ;
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,lobby_name, "lobby_name") ;
RsTypeSerializer::serial_process (j,ctx, lobby_flags,"lobby_flags") ;
}
void RsChatLobbyInviteItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t>(j,ctx, lobby_id, "lobby_id") ;
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,lobby_name, "lobby_name") ;
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,lobby_topic,"lobby_topic") ;
RsTypeSerializer::serial_process (j,ctx, lobby_flags,"lobby_flags") ;
}

View File

@ -77,7 +77,8 @@ const uint8_t RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY = 0x16 ;
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG = 0x17 ;
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT = 0x18 ;
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_LIST = 0x19 ;
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE = 0x1A ;
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE_DEPRECATED = 0x1A ; // to be removed (deprecated since May 2017)
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE = 0x1B ;
typedef uint64_t ChatLobbyId ;
typedef uint64_t ChatLobbyMsgId ;
@ -238,6 +239,21 @@ class RsChatLobbyConnectChallengeItem: public RsChatItem
uint64_t challenge_code ;
};
// to be removed (deprecated since May 2017)
class RsChatLobbyInviteItem_Deprecated: public RsChatItem
{
public:
RsChatLobbyInviteItem_Deprecated() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE_DEPRECATED) {}
virtual ~RsChatLobbyInviteItem_Deprecated() {}
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
ChatLobbyId lobby_id ;
std::string lobby_name ;
std::string lobby_topic ;
ChatLobbyFlags lobby_flags ;
};
class RsChatLobbyInviteItem: public RsChatItem
{
public:
@ -249,7 +265,7 @@ class RsChatLobbyInviteItem: public RsChatItem
ChatLobbyId lobby_id ;
std::string lobby_name ;
std::string lobby_topic ;
ChatLobbyFlags lobby_flags ;
ChatLobbyFlags lobby_flags ;
};
/*!

View File

@ -52,12 +52,14 @@ RsSerialType* init_item(RsChatLobbyListItem& cmi)
cmi.lobby_ids.resize(n) ;
cmi.lobby_names.resize(n) ;
cmi.lobby_topics.resize(n) ;
cmi.lobby_counts.resize(n) ;
for(int i=0;i<n;++i)
{
cmi.lobby_ids[i] = RSRandom::random_u64() ;
randString(5+(rand()%10), cmi.lobby_names[i]);
randString(5+(rand()%10), cmi.lobby_topics[i]);
cmi.lobby_counts[i] = RSRandom::random_u32() ;
}
@ -87,6 +89,7 @@ RsSerialType* init_item(RsChatLobbyInviteItem& cmi)
{
cmi.lobby_id = RSRandom::random_u64() ;
cmi.lobby_name = "Name of the lobby" ;
cmi.lobby_topic = "Topic of the lobby" ;
return new RsChatSerialiser();
}
@ -185,12 +188,14 @@ bool operator ==(const RsChatLobbyListItem& cmiLeft,const RsChatLobbyListItem&
{
if(cmiLeft.lobby_ids.size() != cmiRight.lobby_ids.size()) return false;
if(cmiLeft.lobby_names.size() != cmiRight.lobby_names.size()) return false;
if(cmiLeft.lobby_topics.size() != cmiRight.lobby_topics.size()) return false;
if(cmiLeft.lobby_counts.size() != cmiRight.lobby_counts.size()) return false;
for(uint32_t i=0;i<cmiLeft.lobby_ids.size();++i)
{
if(cmiLeft.lobby_ids[i] != cmiRight.lobby_ids[i]) return false ;
if(cmiLeft.lobby_names[i] != cmiRight.lobby_names[i]) return false ;
if(cmiLeft.lobby_topics[i] != cmiRight.lobby_topics[i]) return false ;
if(cmiLeft.lobby_counts[i] != cmiRight.lobby_counts[i]) return false ;
}
return true ;
@ -254,6 +259,7 @@ bool operator ==(const RsChatLobbyInviteItem& csiLeft, const RsChatLobbyInviteIt
{
if(csiLeft.lobby_id != csiRight.lobby_id) return false ;
if(csiLeft.lobby_name != csiRight.lobby_name) return false ;
if(csiLeft.lobby_topic != csiRight.lobby_topic) return false ;
return true;
}

View File

@ -88,6 +88,7 @@ RsSerialType* init_item(RsChatLobbyInviteItem& cmi)
{
cmi.lobby_id = RSRandom::random_u64() ;
cmi.lobby_name = "Name of the lobby" ;
cmi.lobby_topic = "Topic of the lobby" ;
return new RsChatSerialiser();
}
@ -254,6 +255,7 @@ bool operator ==(const RsChatLobbyInviteItem& csiLeft, const RsChatLobbyInviteIt
{
if(csiLeft.lobby_id != csiRight.lobby_id) return false ;
if(csiLeft.lobby_name != csiRight.lobby_name) return false ;
if(csiLeft.lobby_topic != csiRight.lobby_topic) return false ;
return true;
}