mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-06 08:05:18 -04:00
added load/save of default nickname, plus some debugging
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4737 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
9b79d70fa8
commit
cc57ab2462
11 changed files with 211 additions and 51 deletions
|
@ -34,18 +34,16 @@
|
|||
#include "pqi/p3historymgr.h"
|
||||
|
||||
#include "services/p3chatservice.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
|
||||
/****
|
||||
* #define CHAT_DEBUG 1
|
||||
****/
|
||||
|
||||
/************ NOTE *********************************
|
||||
* This Service is so simple that there is no
|
||||
* mutex protection required!
|
||||
*
|
||||
*/
|
||||
static const int CONNECTION_CHALLENGE_MAX_COUNT = 15 ; // sends a connexion challenge every 15 messages
|
||||
static const int LOBBY_CACHE_CLEANING_PERIOD = 10 ; // sends a connexion challenge every 15 messages
|
||||
static const time_t MAX_KEEP_MSG_RECORD = 240 ; // keep msg record for 240 secs max.
|
||||
|
||||
static const int CONNECTION_CHALLENGE_MAX_COUNT = 10 ; // sends a connexion challenge every 10 messages
|
||||
|
||||
p3ChatService::p3ChatService(p3LinkMgr *lm, p3HistoryMgr *historyMgr)
|
||||
:p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mChatMtx("p3ChatService"), mLinkMgr(lm) , mHistoryMgr(historyMgr)
|
||||
|
@ -63,6 +61,15 @@ int p3ChatService::tick()
|
|||
receiveChatQueue();
|
||||
}
|
||||
|
||||
static time_t last_clean_time = 0 ;
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
if(last_clean_time + LOBBY_CACHE_CLEANING_PERIOD < now)
|
||||
{
|
||||
cleanLobbyCaches() ;
|
||||
last_clean_time = now ;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1168,6 +1175,16 @@ bool p3ChatService::loadList(std::list<RsItem*>& load)
|
|||
continue;
|
||||
}
|
||||
|
||||
RsConfigKeyValueSet *vitem = NULL ;
|
||||
|
||||
if(NULL != (vitem = dynamic_cast<RsConfigKeyValueSet*>(*it)))
|
||||
for(std::list<RsTlvKeyValue>::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit)
|
||||
if(kit->key == "DEFAULT_NICK_NAME")
|
||||
{
|
||||
std::cerr << "Loaded config default nick name for chat: " << kit->value << std::endl ;
|
||||
_default_nick_name = kit->value ;
|
||||
}
|
||||
|
||||
// delete unknown items
|
||||
delete *it;
|
||||
}
|
||||
|
@ -1217,6 +1234,14 @@ bool p3ChatService::saveList(bool& cleanup, std::list<RsItem*>& list)
|
|||
list.push_back(ci);
|
||||
}
|
||||
|
||||
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||
RsTlvKeyValue kv;
|
||||
kv.key = "DEFAULT_NICK_NAME" ;
|
||||
kv.value = _default_nick_name ;
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
list.push_back(vitem) ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1230,6 +1255,7 @@ RsSerialiser *p3ChatService::setupSerialiser()
|
|||
{
|
||||
RsSerialiser *rss = new RsSerialiser ;
|
||||
rss->addSerialType(new RsChatSerialiser) ;
|
||||
rss->addSerialType(new RsGeneralConfigSerialiser());
|
||||
|
||||
return rss ;
|
||||
}
|
||||
|
@ -1412,7 +1438,7 @@ void p3ChatService::handleConnectionChallenge(RsChatLobbyConnectChallengeItem *i
|
|||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
for(std::map<ChatLobbyId,ChatLobbyEntry>::const_iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end() && !found;++it)
|
||||
for(std::map<ChatLobbyId,ChatLobbyEntry>::iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end() && !found;++it)
|
||||
for(std::map<ChatLobbyMsgId,time_t>::const_iterator it2(it->second.msg_cache.begin());it2!=it->second.msg_cache.end() && !found;++it2)
|
||||
{
|
||||
uint64_t code = makeConnexionChallengeCode(it->first,it2->first) ;
|
||||
|
@ -1425,11 +1451,14 @@ void p3ChatService::handleConnectionChallenge(RsChatLobbyConnectChallengeItem *i
|
|||
|
||||
lobby_id = it->first ;
|
||||
found = true ;
|
||||
|
||||
// also add the peer to the list of participating friends
|
||||
it->second.participating_friends.insert(item->PeerId()) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(found)
|
||||
if(found) // send invitation. As the peer already has the lobby, the invitation will most likely be accepted.
|
||||
invitePeerToLobby(lobby_id, item->PeerId()) ;
|
||||
else
|
||||
std::cerr << " Challenge denied: no existing cached msg has matching Id." << std::endl;
|
||||
|
@ -1520,10 +1549,6 @@ void p3ChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, const std::st
|
|||
item->PeerId(peer_id) ;
|
||||
|
||||
sendItem(item) ;
|
||||
|
||||
// Adds the invitation into the invitation cache.
|
||||
//
|
||||
it->second.invitations_sent[peer_id] = time(NULL) ;
|
||||
}
|
||||
void p3ChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item)
|
||||
{
|
||||
|
@ -1692,6 +1717,17 @@ void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id)
|
|||
|
||||
// send a lobby leaving packet. To be implemented.
|
||||
}
|
||||
bool p3ChatService::setDefaultNickNameForChatLobby(const std::string& nick)
|
||||
{
|
||||
_default_nick_name = nick;
|
||||
IndicateConfigChanged() ;
|
||||
return true ;
|
||||
}
|
||||
bool p3ChatService::getDefaultNickNameForChatLobby(std::string& nick)
|
||||
{
|
||||
nick = _default_nick_name ;
|
||||
return true ;
|
||||
}
|
||||
bool p3ChatService::getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick)
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
@ -1726,3 +1762,27 @@ bool p3ChatService::setNickNameForChatLobby(const ChatLobbyId& lobby_id,const st
|
|||
return true ;
|
||||
}
|
||||
|
||||
void p3ChatService::cleanLobbyCaches()
|
||||
{
|
||||
std::cerr << "Cleaning chat lobby caches." << std::endl;
|
||||
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
for(std::map<ChatLobbyId,ChatLobbyEntry>::iterator it = _chat_lobbys.begin();it!=_chat_lobbys.end();++it)
|
||||
for(std::map<ChatLobbyMsgId,time_t>::iterator it2(it->second.msg_cache.begin());it2!=it->second.msg_cache.end();)
|
||||
if(it2->second + MAX_KEEP_MSG_RECORD < now)
|
||||
{
|
||||
std::cerr << " removing old msg 0x" << std::hex << it2->first << ", time=" << std::dec << it2->second << std::endl;
|
||||
|
||||
std::map<ChatLobbyMsgId,time_t>::iterator tmp(it2) ;
|
||||
++tmp ;
|
||||
it->second.msg_cache.erase(it2) ;
|
||||
it2 = tmp ;
|
||||
}
|
||||
else
|
||||
++it2 ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -160,9 +160,11 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
|||
void denyLobbyInvite(const ChatLobbyId& id) ;
|
||||
void getPendingChatLobbyInvites(std::list<ChatLobbyInvite>& invites) ;
|
||||
void invitePeerToLobby(const ChatLobbyId&, const std::string&) ;
|
||||
bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) ;
|
||||
void unsubscribeChatLobby(const ChatLobbyId& lobby_id) ;
|
||||
bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) ;
|
||||
bool getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick) ;
|
||||
bool setDefaultNickNameForChatLobby(const std::string& nick) ;
|
||||
bool getDefaultNickNameForChatLobby(std::string& nick) ;
|
||||
ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends) ;
|
||||
|
||||
protected:
|
||||
|
@ -217,6 +219,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
|||
void checkAndRedirectMsgToLobby(RsChatMsgItem*) ;
|
||||
void handleConnectionChallenge(RsChatLobbyConnectChallengeItem *item) ;
|
||||
void sendConnectionChallenge(ChatLobbyId id) ;
|
||||
void cleanLobbyCaches() ;
|
||||
|
||||
static std::string makeVirtualPeerId(ChatLobbyId) ;
|
||||
static uint64_t makeConnexionChallengeCode(ChatLobbyId lobby_id,ChatLobbyMsgId msg_id) ;
|
||||
|
@ -243,11 +246,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
|||
{
|
||||
public:
|
||||
std::map<ChatLobbyMsgId,time_t> msg_cache ;
|
||||
std::map<std::string,time_t> invitations_sent ;
|
||||
std::string virtual_peer_id ;
|
||||
|
||||
static const time_t MAX_KEEP_MSG_RECORD = 240 ; // keep msg record for 240 secs max.
|
||||
void cleanCache() ;
|
||||
int connexion_challenge_count ;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue