mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added exchange and auto-update of public chat lobby lists.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4758 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e9d6940b09
commit
434ba06c82
@ -207,23 +207,24 @@ class NotifyBase
|
||||
virtual bool askForPassword(const std::string& /* key_details */, bool /* prev_is_bad */, std::string& /* password */ ) { return false ;}
|
||||
};
|
||||
|
||||
const int NOTIFY_LIST_NEIGHBOURS = 1;
|
||||
const int NOTIFY_LIST_FRIENDS = 2;
|
||||
const int NOTIFY_LIST_SEARCHLIST = 4;
|
||||
const int NOTIFY_LIST_MESSAGELIST = 5;
|
||||
const int NOTIFY_LIST_CHANNELLIST = 6;
|
||||
const int NOTIFY_LIST_TRANSFERLIST = 7;
|
||||
const int NOTIFY_LIST_CONFIG = 8;
|
||||
const int NOTIFY_LIST_DIRLIST_LOCAL = 9;
|
||||
const int NOTIFY_LIST_DIRLIST_FRIENDS = 10;
|
||||
const int NOTIFY_LIST_FORUMLIST_LOCKED = 11; // use connect with Qt::QueuedConnection
|
||||
const int NOTIFY_LIST_MESSAGE_TAGS = 12;
|
||||
const int NOTIFY_LIST_PUBLIC_CHAT = 13;
|
||||
const int NOTIFY_LIST_PRIVATE_INCOMING_CHAT = 14;
|
||||
const int NOTIFY_LIST_PRIVATE_OUTGOING_CHAT = 15;
|
||||
const int NOTIFY_LIST_GROUPLIST = 16;
|
||||
const int NOTIFY_LIST_CHANNELLIST_LOCKED = 17; // use connect with Qt::QueuedConnection
|
||||
const int NOTIFY_LIST_CHAT_LOBBY_INVITATION = 18;
|
||||
const int NOTIFY_LIST_NEIGHBOURS = 1;
|
||||
const int NOTIFY_LIST_FRIENDS = 2;
|
||||
const int NOTIFY_LIST_SEARCHLIST = 4;
|
||||
const int NOTIFY_LIST_MESSAGELIST = 5;
|
||||
const int NOTIFY_LIST_CHANNELLIST = 6;
|
||||
const int NOTIFY_LIST_TRANSFERLIST = 7;
|
||||
const int NOTIFY_LIST_CONFIG = 8;
|
||||
const int NOTIFY_LIST_DIRLIST_LOCAL = 9;
|
||||
const int NOTIFY_LIST_DIRLIST_FRIENDS = 10;
|
||||
const int NOTIFY_LIST_FORUMLIST_LOCKED = 11; // use connect with Qt::QueuedConnection
|
||||
const int NOTIFY_LIST_MESSAGE_TAGS = 12;
|
||||
const int NOTIFY_LIST_PUBLIC_CHAT = 13;
|
||||
const int NOTIFY_LIST_PRIVATE_INCOMING_CHAT = 14;
|
||||
const int NOTIFY_LIST_PRIVATE_OUTGOING_CHAT = 15;
|
||||
const int NOTIFY_LIST_GROUPLIST = 16;
|
||||
const int NOTIFY_LIST_CHANNELLIST_LOCKED = 17; // use connect with Qt::QueuedConnection
|
||||
const int NOTIFY_LIST_CHAT_LOBBY_INVITATION = 18;
|
||||
const int NOTIFY_LIST_PUBLIC_CHAT_LOBBY_LIST = 19;
|
||||
|
||||
const int NOTIFY_TYPE_SAME = 0x01;
|
||||
const int NOTIFY_TYPE_MOD = 0x02; /* general purpose, check all */
|
||||
|
@ -159,13 +159,20 @@ class ChatLobbyInvite
|
||||
class PublicChatLobbyRecord
|
||||
{
|
||||
public:
|
||||
PublicChatLobbyRecord() { total_number_of_peers = 0 ; }
|
||||
|
||||
ChatLobbyId lobby_id ; // unique id of the lobby
|
||||
std::string lobby_name ; // name to use for this lobby
|
||||
std::set<std::string> participating_friends ; // list of direct friend who participate. Used to broadcast sent messages.
|
||||
|
||||
uint32_t total_number_of_peers ; // total number of particpating peers. Might not be
|
||||
};
|
||||
class ChatLobbyInfo: public PublicChatLobbyRecord
|
||||
class ChatLobbyInfo
|
||||
{
|
||||
public:
|
||||
ChatLobbyId lobby_id ; // unique id of the lobby
|
||||
std::string lobby_name ; // name to use for this lobby
|
||||
std::set<std::string> participating_friends ; // list of direct friend who participate. Used to broadcast sent messages.
|
||||
std::string nick_name ; // nickname to use for this lobby
|
||||
|
||||
uint32_t lobby_privacy_level ; // see RS_CHAT_LOBBY_
|
||||
|
@ -41,12 +41,12 @@
|
||||
****/
|
||||
#define CHAT_DEBUG 1
|
||||
|
||||
static const int CONNECTION_CHALLENGE_MAX_COUNT = 15 ; // sends a connexion challenge every 15 messages
|
||||
static const int CONNECTION_CHALLENGE_MIN_DELAY = 15 ; // sends a connexion at most every 15 seconds
|
||||
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 time_t MAX_KEEP_INACTIVE_LOBBY = 3600 ; // keep inactive lobbies for 1h max.
|
||||
|
||||
static const int CONNECTION_CHALLENGE_MAX_COUNT = 15 ; // sends a connexion challenge every 15 messages
|
||||
static const int CONNECTION_CHALLENGE_MIN_DELAY = 15 ; // sends a connexion at most every 15 seconds
|
||||
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 time_t MAX_KEEP_INACTIVE_LOBBY = 3600 ; // keep inactive lobbies for 1h max.
|
||||
static const time_t MIN_DELAY_BETWEEN_PUBLIC_LOBBY_REQ = 30 ; // don't ask for lobby list more than once every 30 secs.
|
||||
|
||||
p3ChatService::p3ChatService(p3LinkMgr *lm, p3HistoryMgr *historyMgr)
|
||||
:p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mChatMtx("p3ChatService"), mLinkMgr(lm) , mHistoryMgr(historyMgr)
|
||||
@ -620,15 +620,53 @@ void p3ChatService::receiveChatQueue()
|
||||
}
|
||||
}
|
||||
|
||||
void p3ChatService::handleRecvChatLobbyListRequest(RsChatLobbyListRequestItem *item)
|
||||
void p3ChatService::handleRecvChatLobbyListRequest(RsChatLobbyListRequestItem *clr)
|
||||
{
|
||||
// todo !!
|
||||
std::cerr << "Called to unimplemented method: p3ChatService::handleRecvChatLobbyListRequest(RsChatLobbyListRequestItem *item)" << std::endl;
|
||||
// make a lobby list item
|
||||
//
|
||||
RsChatLobbyListItem *item = new RsChatLobbyListItem;
|
||||
|
||||
std::cerr << "Peer " << clr->PeerId() << " requested the list of public chat lobbies." << std::endl;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
for(std::map<ChatLobbyId,ChatLobbyEntry>::const_iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end();++it)
|
||||
if(it->second.lobby_privacy_level == RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC)
|
||||
{
|
||||
std::cerr << " Adding lobby " << std::hex << it->first << std::dec << " \"" << it->second.lobby_name << "\" count=" << it->second.nick_names.size() << std::endl;
|
||||
|
||||
item->lobby_ids.push_back(it->first) ;
|
||||
item->lobby_names.push_back(it->second.lobby_name) ;
|
||||
item->lobby_counts.push_back(it->second.nick_names.size()) ;
|
||||
}
|
||||
else
|
||||
std::cerr << " Not adding private lobby " << std::hex << it->first << std::dec << std::endl ;
|
||||
}
|
||||
|
||||
item->PeerId(clr->PeerId()) ;
|
||||
|
||||
std::cerr << " Sending list to " << clr->PeerId() << std::endl;
|
||||
sendItem(item);
|
||||
}
|
||||
|
||||
void p3ChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item)
|
||||
{
|
||||
// todo !!
|
||||
std::cerr << "Called to unimplemented method: p3ChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item)" << std::endl;
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
for(uint32_t i=0;i<item->lobby_ids.size();++i)
|
||||
{
|
||||
PublicChatLobbyRecord& rec(_public_lobbies[item->lobby_ids[i]]) ;
|
||||
|
||||
rec.lobby_id = item->lobby_ids[i] ;
|
||||
rec.lobby_name = item->lobby_names[i] ;
|
||||
rec.participating_friends.insert(item->PeerId()) ;
|
||||
rec.total_number_of_peers = item->lobby_counts[i] ;
|
||||
}
|
||||
}
|
||||
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_PUBLIC_CHAT_LOBBY_LIST,0) ;
|
||||
}
|
||||
|
||||
void p3ChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *item)
|
||||
@ -789,12 +827,32 @@ void p3ChatService::handleRecvChatStatusItem(RsChatStatusItem *cs)
|
||||
|
||||
void p3ChatService::getListOfNearbyChatLobbies(std::vector<PublicChatLobbyRecord>& public_lobbies)
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
public_lobbies.clear() ;
|
||||
public_lobbies.clear() ;
|
||||
|
||||
for(std::map<ChatLobbyId,PublicChatLobbyRecord>::const_iterator it(_public_lobbies.begin());it!=_public_lobbies.end();++it)
|
||||
public_lobbies.push_back(it->second) ;
|
||||
for(std::map<ChatLobbyId,PublicChatLobbyRecord>::const_iterator it(_public_lobbies.begin());it!=_public_lobbies.end();++it)
|
||||
public_lobbies.push_back(it->second) ;
|
||||
}
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
if(now > MIN_DELAY_BETWEEN_PUBLIC_LOBBY_REQ + last_public_lobby_info_request_time)
|
||||
{
|
||||
std::list<std::string> ids ;
|
||||
mLinkMgr->getOnlineList(ids);
|
||||
|
||||
for(std::list<std::string>::const_iterator it(ids.begin());it!=ids.end();++it)
|
||||
{
|
||||
std::cerr << " asking list of public lobbies to " << *it << std::endl;
|
||||
RsChatLobbyListRequestItem *item = new RsChatLobbyListRequestItem ;
|
||||
item->PeerId(*it) ;
|
||||
|
||||
sendItem(item);
|
||||
}
|
||||
last_public_lobby_info_request_time = now ;
|
||||
}
|
||||
}
|
||||
|
||||
int p3ChatService::getPublicChatQueueCount()
|
||||
|
@ -278,6 +278,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
||||
std::map<std::string,ChatLobbyId> _lobby_ids ;
|
||||
std::string _default_nick_name ;
|
||||
time_t last_lobby_challenge_time ; // prevents bruteforce attack
|
||||
time_t last_public_lobby_info_request_time ; // allows to ask for updates
|
||||
};
|
||||
|
||||
class p3ChatService::StateStringInfo
|
||||
|
@ -298,6 +298,11 @@ void FriendsDialog::updateStatusTyping()
|
||||
}
|
||||
}
|
||||
|
||||
void FriendsDialog::updatePublicLobbyList()
|
||||
{
|
||||
std::cerr << "Updating public lobby list !!" << std::endl;
|
||||
}
|
||||
|
||||
void FriendsDialog::displayChatLobbyEvent(qulonglong lobby_id,int event_type,const QString& nickname,const QString& str)
|
||||
{
|
||||
std::cerr << "Received displayChatLobbyEvent()!" << std::endl;
|
||||
|
@ -57,6 +57,7 @@ public slots:
|
||||
void insertChat();
|
||||
void setChatInfo(QString info, QColor color=QApplication::palette().color(QPalette::WindowText));
|
||||
void displayChatLobbyEvent(qulonglong,int,const QString&,const QString&) ;
|
||||
void updatePublicLobbyList() ;
|
||||
void resetStatusBar() ;
|
||||
void readChatLobbyInvites() ;
|
||||
|
||||
|
@ -380,6 +380,10 @@ void NotifyQt::notifyListChange(int list, int type)
|
||||
#endif
|
||||
emit privateChatChanged(list, type);
|
||||
break;
|
||||
case NOTIFY_LIST_PUBLIC_CHAT_LOBBY_LIST:
|
||||
std::cerr << "received notify public chat lobby list" << std::endl;
|
||||
emit publicLobbyListChanged();
|
||||
|
||||
case NOTIFY_LIST_GROUPLIST:
|
||||
#ifdef NOTIFY_DEBUG
|
||||
std::cerr << "received groups changed" << std::endl ;
|
||||
|
@ -68,6 +68,7 @@ class NotifyQt: public QObject, public NotifyBase
|
||||
void filesPostModChanged(bool) const ;
|
||||
void transfersChanged() const ;
|
||||
void friendsChanged() const ;
|
||||
void publicLobbyListChanged() const ;
|
||||
void chatLobbyEvent(qulonglong,int,const QString&,const QString&) ;
|
||||
void neighboursChanged() const ;
|
||||
void messagesChanged() const ;
|
||||
|
@ -282,6 +282,7 @@ int main(int argc, char *argv[])
|
||||
QObject::connect(notify,SIGNAL(messagesTagsChanged()) ,w->messagesDialog ,SLOT(messagesTagsChanged() )) ;
|
||||
QObject::connect(notify,SIGNAL(messagesChanged()) ,w ,SLOT(updateMessages() )) ;
|
||||
QObject::connect(notify,SIGNAL(chatLobbyInviteReceived()) ,w->friendsDialog ,SLOT(readChatLobbyInvites() )) ;
|
||||
QObject::connect(notify,SIGNAL(publicLobbyListChanged()) ,w->friendsDialog ,SLOT(updatePublicLobbyList() )) ;
|
||||
QObject::connect(notify,SIGNAL(chatLobbyEvent(qulonglong,int,const QString&,const QString&)),w->friendsDialog,SLOT(displayChatLobbyEvent(qulonglong,int,const QString&,const QString&))) ;
|
||||
QObject::connect(notify,SIGNAL(forumsChanged()) ,w ,SLOT(updateForums() ), Qt::QueuedConnection);
|
||||
QObject::connect(notify,SIGNAL(channelsChanged(int)) ,w ,SLOT(updateChannels(int) ), Qt::QueuedConnection);
|
||||
|
Loading…
Reference in New Issue
Block a user