From ee4985c935396f5b70530d2ea0abbfd0fee15c67 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 27 Dec 2013 20:21:44 +0000 Subject: [PATCH] patch "Fix_ChatLobbyAutoSubscribe_6951.diff" from Phenom. Fixes request for existing lobbies when no lobby ihas been found yet. Code beautification git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6971 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/services/p3chatservice.cc | 32 ++++++++++++--------- libretroshare/src/services/p3chatservice.h | 6 ++-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 727a2b2de..4db2882f7 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -63,7 +63,7 @@ static const time_t MAX_KEEP_PUBLIC_LOBBY_RECORD = 60 ; // keep inactiv static const time_t MIN_DELAY_BETWEEN_PUBLIC_LOBBY_REQ = 20 ; // don't ask for lobby list more than once every 30 secs. static const time_t LOBBY_LIST_AUTO_UPDATE_TIME = 121 ; // regularly ask for available lobbies every 5 minutes, to allow auto-subscribe to work -static const time_t DISTANT_CHAT_CLEANING_PERIOD = 60 ; // don't ask for lobby list more than once every 30 secs. +static const time_t DISTANT_CHAT_CLEANING_PERIOD = 60 ; // clean distant chat caches every 60 secs (remove old invites) static const time_t DISTANT_CHAT_KEEP_ALIVE_PERIOD = 10 ; // sens keep alive distant chat packets every 10 secs. static const uint32_t DISTANT_CHAT_AES_KEY_SIZE = 16 ; // size of AES encryption key for distant chat. static const uint32_t DISTANT_CHAT_HASH_SIZE = 20 ; // This is sha1 size in bytes. @@ -125,8 +125,12 @@ int p3ChatService::tick() std::vector visible_lobbies_tmp ; getListOfNearbyChatLobbies(visible_lobbies_tmp) ; + if (visible_lobbies_tmp.size()==0){ + last_req_chat_lobby_list = now-LOBBY_LIST_AUTO_UPDATE_TIME+MIN_DELAY_BETWEEN_PUBLIC_LOBBY_REQ; + } else { last_req_chat_lobby_list = now ; } + } // Flush items that could not be sent, probably because of a Mutex protected zone. // @@ -435,11 +439,11 @@ void p3ChatService::locked_printDebugInfo() const std::cerr << " \"" << std::hex << it->first << "\" flags = " << it->second << std::dec << std::endl; } -bool p3ChatService::isLobbyId(const std::string& id,ChatLobbyId& lobby_id) +bool p3ChatService::isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - std::map::const_iterator it(_lobby_ids.find(id)) ; + std::map::const_iterator it(_lobby_ids.find(virtual_peer_id)) ; if(it != _lobby_ids.end()) { @@ -2017,10 +2021,10 @@ bool p3ChatService::loadList(std::list& load) _default_nick_name = kit->value ; } - RsChatLobbyConfigItem *cas = NULL ; + RsChatLobbyConfigItem *clci = NULL ; - if(NULL != (cas = dynamic_cast(*it))) - _known_lobbies_flags[cas->lobby_Id] = ChatLobbyFlags(cas->flags) ; + if(NULL != (clci = dynamic_cast(*it))) + _known_lobbies_flags[clci->lobby_Id] = ChatLobbyFlags(clci->flags) ; // delete unknown items delete *it; @@ -2088,6 +2092,8 @@ bool p3ChatService::saveList(bool& cleanup, std::list& list) list.push_back(ei) ; } + /* Save Default Nick Name */ + RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ; RsTlvKeyValue kv; kv.key = "DEFAULT_NICK_NAME" ; @@ -2099,11 +2105,11 @@ bool p3ChatService::saveList(bool& cleanup, std::list& list) /* Save Lobby Auto Subscribe */ for(std::map::const_iterator it=_known_lobbies_flags.begin();it!=_known_lobbies_flags.end();++it) { - RsChatLobbyConfigItem *cas = new RsChatLobbyConfigItem ; - cas->lobby_Id=it->first; - cas->flags=it->second.toUInt32(); + RsChatLobbyConfigItem *clci = new RsChatLobbyConfigItem ; + clci->lobby_Id=it->first; + clci->flags=it->second.toUInt32(); - list.push_back(cas) ; + list.push_back(clci) ; } @@ -2515,16 +2521,16 @@ uint64_t p3ChatService::makeConnexionChallengeCode(const std::string& peer_id,Ch return result ; } -void p3ChatService::getChatLobbyList(std::list& linfos) +void p3ChatService::getChatLobbyList(std::list& cl_infos) { // fill up a dummy list for now. RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - linfos.clear() ; + cl_infos.clear() ; for(std::map::const_iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end();++it) - linfos.push_back(it->second) ; + cl_infos.push_back(it->second) ; } void p3ChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, const std::string& peer_id,bool connexion_challenge) { diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index 65716a87a..6d3c096ef 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -163,9 +163,9 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi */ bool clearPrivateChatQueue(bool incoming, const std::string &id); - bool getVirtualPeerId(const ChatLobbyId&, std::string& virtual_peer_id) ; - bool isLobbyId(const std::string&, ChatLobbyId&) ; - void getChatLobbyList(std::list >&) ; + bool getVirtualPeerId(const ChatLobbyId& lobby_id, std::string& virtual_peer_id) ; + bool isLobbyId(const std::string& virtual_peer_id, ChatLobbyId& lobby_id) ; + void getChatLobbyList(std::list >& cl_infos) ; bool acceptLobbyInvite(const ChatLobbyId& id) ; void denyLobbyInvite(const ChatLobbyId& id) ; void getPendingChatLobbyInvites(std::list& invites) ;