mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Improvements to chat lobbies:
- added generic methods and items for bouncing generic objects through lobbies - added handling of peer typing status - proper handling of peer join/leave lobby - added sub item ids to lobby messages to allow proper message splitting - made 2 different message splitting methods for normal chat vs. lobbies. In v0.6, we'll have to handle all messages the same way. - added parent id to RsChatLobbyMsgItem, to allow threaded chat. - added possibility to make a lobby public/private (not yet fully working) - added items for requesting/exchanging list of public lobbies at friends' (not yet fully working) - major cleaning of p3chatservice.cc Next move: - gui for listing friend public lobbies, joining them, etc. - load/save of persistent lobbies. - autoremove of inactive lobbies Warning: lobby message items of this version are incompatible with previous versions. It won't crash, but messages will not pass through. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4755 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e430612714
commit
e9d6940b09
@ -186,6 +186,7 @@ class NotifyBase
|
||||
virtual void notifyListChange(int list, int type) { (void) list; (void) type; return; }
|
||||
virtual void notifyErrorMsg(int list, int sev, std::string msg) { (void) list; (void) sev; (void) msg; return; }
|
||||
virtual void notifyChatStatus(const std::string& /* peer_id */, const std::string& /* status_string */ ,bool /* is_private */) {}
|
||||
virtual void notifyChatLobbyEvent(uint64_t /* lobby id */,uint32_t /* event type */,const std::string& /* nickname */,const std::string& /* any string */) {}
|
||||
virtual void notifyCustomState(const std::string& /* peer_id */, const std::string& /* status_string */) {}
|
||||
virtual void notifyHashingInfo(uint32_t type, const std::string& fileinfo) { (void) type; (void)fileinfo; }
|
||||
virtual void notifyTurtleSearchResult(uint32_t /* search_id */ ,const std::list<TurtleFileInfo>& files) { (void)files; }
|
||||
|
@ -55,6 +55,11 @@
|
||||
#define RS_MSG_FORWARDED 0x0100 /* Message is forwarded */
|
||||
#define RS_MSG_STAR 0x0200 /* Message is marked with a star */
|
||||
|
||||
#define RS_CHAT_LOBBY_EVENT_PEER_LEFT 0x01
|
||||
#define RS_CHAT_LOBBY_EVENT_PEER_STATUS 0x02
|
||||
#define RS_CHAT_LOBBY_EVENT_PEER_JOINED 0x03
|
||||
#define RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME 0x04
|
||||
|
||||
#define RS_MSGTAGTYPE_IMPORTANT 1
|
||||
#define RS_MSGTAGTYPE_WORK 2
|
||||
#define RS_MSGTAGTYPE_PERSONAL 3
|
||||
@ -62,6 +67,9 @@
|
||||
#define RS_MSGTAGTYPE_LATER 5
|
||||
#define RS_MSGTAGTYPE_USER 100
|
||||
|
||||
#define RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC 1 /* lobby is visible by friends. Friends can connect.*/
|
||||
#define RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE 2 /* lobby invisible by friends. Peers on invitation only .*/
|
||||
|
||||
typedef uint64_t ChatLobbyId ;
|
||||
typedef uint64_t ChatLobbyMsgId ;
|
||||
typedef std::string ChatLobbyNickName ;
|
||||
@ -148,15 +156,21 @@ class ChatLobbyInvite
|
||||
std::string peer_id ;
|
||||
std::string lobby_name ;
|
||||
};
|
||||
class ChatLobbyInfo
|
||||
class PublicChatLobbyRecord
|
||||
{
|
||||
public:
|
||||
ChatLobbyId lobby_id ; // unique id of the lobby
|
||||
std::string nick_name ; // nickname to use for this 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.
|
||||
};
|
||||
class ChatLobbyInfo: public PublicChatLobbyRecord
|
||||
{
|
||||
public:
|
||||
std::string nick_name ; // nickname to use for this lobby
|
||||
|
||||
uint32_t lobby_privacy_level ; // see RS_CHAT_LOBBY_
|
||||
std::set<std::string> nick_names ; // list of non direct friend who participate. Used to display only.
|
||||
time_t last_activity ; // last recorded activity. Useful for removing dead lobbies.
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const MessageInfo &info);
|
||||
@ -240,7 +254,7 @@ virtual bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::stri
|
||||
virtual bool getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick) = 0 ;
|
||||
virtual bool setDefaultNickNameForChatLobby(const std::string& nick) = 0;
|
||||
virtual bool getDefaultNickNameForChatLobby(std::string& nick) = 0 ;
|
||||
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends) = 0 ;
|
||||
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends,uint32_t lobby_privacy_type) = 0 ;
|
||||
|
||||
/****************************************/
|
||||
|
||||
|
@ -299,9 +299,9 @@ bool p3Msgs::getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& ni
|
||||
return mChatSrv->getNickNameForChatLobby(lobby_id,nick_name) ;
|
||||
}
|
||||
|
||||
ChatLobbyId p3Msgs::createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends)
|
||||
ChatLobbyId p3Msgs::createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends,uint32_t privacy_type)
|
||||
{
|
||||
return mChatSrv->createChatLobby(lobby_name,invited_friends) ;
|
||||
return mChatSrv->createChatLobby(lobby_name,invited_friends,privacy_type) ;
|
||||
}
|
||||
|
||||
bool p3Msgs::acceptLobbyInvite(const ChatLobbyId& id)
|
||||
|
@ -180,7 +180,7 @@ class p3Msgs: public RsMsgs
|
||||
virtual bool getNickNameForChatLobby(const ChatLobbyId&,std::string& nick) ;
|
||||
virtual bool setDefaultNickNameForChatLobby(const std::string&) ;
|
||||
virtual bool getDefaultNickNameForChatLobby(std::string& nick) ;
|
||||
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends) ;
|
||||
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends,uint32_t privacy_type) ;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -57,6 +57,33 @@ std::ostream& RsChatMsgItem::print(std::ostream &out, uint16_t indent)
|
||||
printRsItemEnd(out, "RsChatMsgItem", indent);
|
||||
return out;
|
||||
}
|
||||
std::ostream& RsChatLobbyListItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsChatLobbyListItem", indent);
|
||||
|
||||
for(uint32_t i=0;i<lobby_ids.size();++i)
|
||||
{
|
||||
printIndent(out, indent+2);
|
||||
out << "lobby 0x" << std::hex << lobby_ids[i] << std::dec << " (name=\"" << lobby_names[i] << "\", count=" << lobby_counts[i] << std::endl ;
|
||||
}
|
||||
|
||||
printRsItemEnd(out, "RsChatLobbyListItem", indent);
|
||||
return out;
|
||||
}
|
||||
std::ostream& RsChatLobbyListRequestItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsChatLobbyListRequestItem", indent);
|
||||
printRsItemEnd(out, "RsChatLobbyListRequestItem", indent);
|
||||
return out;
|
||||
}
|
||||
std::ostream& RsChatLobbyBouncingObject::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printIndent(out, indent); out << "Lobby ID: " << std::hex << lobby_id << std::endl;
|
||||
printIndent(out, indent); out << "Msg ID: " << std::hex << msg_id << std::dec << std::endl;
|
||||
printIndent(out, indent); out << "Nick: " << nick << std::dec << std::endl;
|
||||
|
||||
return out;
|
||||
}
|
||||
std::ostream& RsChatLobbyUnsubscribeItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsChatLobbyUnsubscribeItem", indent);
|
||||
@ -65,6 +92,15 @@ std::ostream& RsChatLobbyUnsubscribeItem::print(std::ostream &out, uint16_t inde
|
||||
printRsItemEnd(out, "RsChatLobbyUnsubscribeItem", indent);
|
||||
return out;
|
||||
}
|
||||
std::ostream& RsChatLobbyEventItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsChatLobbyEventItem", indent);
|
||||
RsChatLobbyBouncingObject::print(out,indent) ;
|
||||
printIndent(out, indent); out << "Event type : " << event_type << std::endl;
|
||||
printIndent(out, indent); out << "String param: " << string1 << std::endl;
|
||||
printRsItemEnd(out, "RsChatLobbyEventItem", indent);
|
||||
return out;
|
||||
}
|
||||
std::ostream& RsChatLobbyConnectChallengeItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsChatLobbyConnectChallengeItem", indent);
|
||||
@ -76,13 +112,7 @@ std::ostream& RsChatLobbyConnectChallengeItem::print(std::ostream &out, uint16_t
|
||||
std::ostream& RsChatLobbyMsgItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
RsChatMsgItem::print(out,indent) ;
|
||||
|
||||
printIndent(out, indent);
|
||||
out << "Lobby ID: " << std::hex << lobby_id << std::endl;
|
||||
printIndent(out, indent);
|
||||
out << "Msg ID: " << std::hex << msg_id << std::dec << std::endl;
|
||||
printIndent(out, indent);
|
||||
out << "Nick: " << nick << std::dec << std::endl;
|
||||
RsChatLobbyBouncingObject::print(out,indent) ;
|
||||
|
||||
printRsItemEnd(out, "RsChatLobbyMsgItem", indent);
|
||||
return out;
|
||||
@ -192,6 +222,9 @@ RsItem *RsChatSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: return new RsChatLobbyInviteItem(data,*pktsize) ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE: return new RsChatLobbyConnectChallengeItem(data,*pktsize) ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE: return new RsChatLobbyUnsubscribeItem(data,*pktsize) ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_EVENT: return new RsChatLobbyEventItem(data,*pktsize) ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST: return new RsChatLobbyListRequestItem(data,*pktsize) ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: return new RsChatLobbyListItem(data,*pktsize) ;
|
||||
default:
|
||||
std::cerr << "Unknown packet type in chat!" << std::endl ;
|
||||
return NULL ;
|
||||
@ -223,12 +256,50 @@ uint32_t RsChatLobbyConnectChallengeItem::serial_size()
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsChatLobbyBouncingObject::serial_size()
|
||||
{
|
||||
uint32_t s = 0 ; // no header!
|
||||
s += 8 ; // lobby_id
|
||||
s += 8 ; // msg_id
|
||||
s += GetTlvStringSize(nick) ; // nick
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsChatLobbyEventItem::serial_size()
|
||||
{
|
||||
uint32_t s = 8 ; // header
|
||||
s += RsChatLobbyBouncingObject::serial_size() ;
|
||||
s += 1 ; // event_type
|
||||
s += GetTlvStringSize(string1) ; // string1
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsChatLobbyListRequestItem::serial_size()
|
||||
{
|
||||
uint32_t s = 8 ; // header
|
||||
return s ;
|
||||
}
|
||||
uint32_t RsChatLobbyListItem::serial_size()
|
||||
{
|
||||
uint32_t s = 8 ; // header
|
||||
s += 4 ; // number of elements in the vectors
|
||||
s += lobby_ids.size() * 8 ; // lobby_ids
|
||||
|
||||
for(uint32_t i=0;i<lobby_names.size();++i)
|
||||
s += GetTlvStringSize(lobby_names[i]) ; // lobby_names
|
||||
|
||||
s += lobby_counts.size() * 4 ; // lobby_counts
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsChatLobbyMsgItem::serial_size()
|
||||
{
|
||||
uint32_t s = RsChatMsgItem::serial_size() ; // parent
|
||||
s += 8; // lobby_id
|
||||
s += 8; // msg_id
|
||||
s += GetTlvStringSize(nick) ; // nick
|
||||
s += RsChatLobbyBouncingObject::serial_size() ;
|
||||
s += 1; // subpacket id
|
||||
s += 8; // parent_msg_id
|
||||
|
||||
return s;
|
||||
}
|
||||
@ -330,6 +401,17 @@ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize)
|
||||
return ok ;
|
||||
}
|
||||
|
||||
bool RsChatLobbyBouncingObject::serialise(void *data,uint32_t tlvsize,uint32_t& offset)
|
||||
{
|
||||
bool ok = true ;
|
||||
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, lobby_id);
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, msg_id);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, nick);
|
||||
|
||||
return ok ;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsChatLobbyMsgItem::serialise(void *data, uint32_t& pktsize)
|
||||
{
|
||||
@ -340,16 +422,94 @@ bool RsChatLobbyMsgItem::serialise(void *data, uint32_t& pktsize)
|
||||
|
||||
bool ok = true;
|
||||
ok &= RsChatMsgItem::serialise(data,pktsize) ; // first, serialize parent
|
||||
|
||||
uint32_t offset = pktsize;
|
||||
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header!
|
||||
|
||||
pktsize = tlvsize;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, lobby_id);
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, msg_id);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, nick);
|
||||
ok &= RsChatLobbyBouncingObject::serialise(data,tlvsize,offset) ;
|
||||
ok &= setRawUInt8(data, tlvsize, &offset, subpacket_id);
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, parent_msg_id);
|
||||
|
||||
/* add mandatory parts first */
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ;
|
||||
#endif
|
||||
return ok ;
|
||||
}
|
||||
|
||||
bool RsChatLobbyListRequestItem::serialise(void *data, uint32_t& pktsize)
|
||||
{
|
||||
uint32_t tlvsize = serial_size() ;
|
||||
bool ok = true ;
|
||||
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header!
|
||||
|
||||
if (pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
pktsize = tlvsize ;
|
||||
return ok ;
|
||||
}
|
||||
|
||||
bool RsChatLobbyListItem::serialise(void *data, uint32_t& pktsize)
|
||||
{
|
||||
uint32_t tlvsize = serial_size() ;
|
||||
bool ok = true ;
|
||||
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header!
|
||||
|
||||
if (pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
if(lobby_ids.size() != lobby_counts.size() || lobby_ids.size() != lobby_names.size())
|
||||
{
|
||||
std::cerr << "Consistency error in RsChatLobbyListItem!! Sizes don't match!" << std::endl;
|
||||
return false ;
|
||||
}
|
||||
pktsize = tlvsize ;
|
||||
|
||||
uint32_t offset = 8 ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, lobby_ids.size());
|
||||
|
||||
for(uint32_t i=0;i<lobby_ids.size();++i)
|
||||
{
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, lobby_ids[i]);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, lobby_names[i]);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, lobby_counts[i]);
|
||||
}
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
return ok ;
|
||||
}
|
||||
bool RsChatLobbyEventItem::serialise(void *data, uint32_t& pktsize)
|
||||
{
|
||||
uint32_t tlvsize = serial_size() ;
|
||||
bool ok = true ;
|
||||
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header!
|
||||
|
||||
if (pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
uint32_t offset = 8 ;
|
||||
|
||||
ok &= RsChatLobbyBouncingObject::serialise(data,tlvsize,offset) ; // first, serialize parent
|
||||
ok &= setRawUInt8(data, tlvsize, &offset, event_type);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, string1);
|
||||
|
||||
pktsize = tlvsize ;
|
||||
|
||||
/* add mandatory parts first */
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
@ -589,7 +749,7 @@ RsChatMsgItem::RsChatMsgItem(void *data,uint32_t /*size*/,uint8_t subtype)
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Building new chat msg item." << std::endl ;
|
||||
#endif
|
||||
if (offset != rssize)
|
||||
if (getRsItemSubType(getRsItemId(data)) == subtype && offset != rssize)
|
||||
std::cerr << "Size error while deserializing." << std::endl ;
|
||||
if (!ok)
|
||||
std::cerr << "Unknown error while deserializing." << std::endl ;
|
||||
@ -603,13 +763,84 @@ RsChatLobbyMsgItem::RsChatLobbyMsgItem(void *data,uint32_t /*size*/)
|
||||
|
||||
uint32_t offset = RsChatMsgItem::serial_size() ;
|
||||
|
||||
ok &= RsChatLobbyBouncingObject::deserialise(data,rssize,offset) ;
|
||||
ok &= getRawUInt8(data, rssize, &offset, &subpacket_id);
|
||||
ok &= getRawUInt64(data, rssize, &offset, &parent_msg_id);
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Building new chat lobby msg item." << std::endl ;
|
||||
#endif
|
||||
if (offset != rssize)
|
||||
std::cerr << "Size error while deserializing." << std::endl ;
|
||||
if (!ok)
|
||||
std::cerr << "Unknown error while deserializing." << std::endl ;
|
||||
}
|
||||
RsChatLobbyListRequestItem::RsChatLobbyListRequestItem(void *data,uint32_t)
|
||||
: RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST)
|
||||
{
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
uint32_t offset = 8; // skip the header
|
||||
|
||||
if (offset != rssize)
|
||||
std::cerr << "Size error while deserializing." << std::endl ;
|
||||
if (!ok)
|
||||
std::cerr << "Unknown error while deserializing." << std::endl ;
|
||||
}
|
||||
|
||||
RsChatLobbyListItem::RsChatLobbyListItem(void *data,uint32_t)
|
||||
: RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST)
|
||||
{
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
uint32_t offset = 8; // skip the header
|
||||
|
||||
uint32_t n=0 ;
|
||||
ok &= getRawUInt32(data, rssize, &offset, &n);
|
||||
|
||||
lobby_ids.resize(n) ;
|
||||
lobby_names.resize(n) ;
|
||||
lobby_counts.resize(n) ;
|
||||
|
||||
for(uint32_t i=0;i<n;++i)
|
||||
{
|
||||
ok &= getRawUInt64(data, rssize, &offset, &lobby_ids[i]);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, lobby_names[i]);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &lobby_counts[i]);
|
||||
}
|
||||
|
||||
if (offset != rssize)
|
||||
std::cerr << "Size error while deserializing." << std::endl ;
|
||||
if (!ok)
|
||||
std::cerr << "Unknown error while deserializing." << std::endl ;
|
||||
}
|
||||
|
||||
bool RsChatLobbyBouncingObject::deserialise(void *data,uint32_t rssize,uint32_t& offset)
|
||||
{
|
||||
bool ok = true ;
|
||||
/* get mandatory parts first */
|
||||
ok &= getRawUInt64(data, rssize, &offset, &lobby_id);
|
||||
ok &= getRawUInt64(data, rssize, &offset, &msg_id);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, nick);
|
||||
|
||||
return ok ;
|
||||
}
|
||||
|
||||
RsChatLobbyEventItem::RsChatLobbyEventItem(void *data,uint32_t /*size*/)
|
||||
: RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_EVENT)
|
||||
{
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
|
||||
uint32_t offset = 8 ;
|
||||
|
||||
ok &= RsChatLobbyBouncingObject::deserialise(data,rssize,offset) ;
|
||||
|
||||
ok &= getRawUInt8(data, rssize, &offset, &event_type);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, string1);
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Building new chat msg item." << std::endl ;
|
||||
std::cerr << "Building new chat lobby status item." << std::endl ;
|
||||
#endif
|
||||
if (offset != rssize)
|
||||
std::cerr << "Size error while deserializing." << std::endl ;
|
||||
@ -742,7 +973,7 @@ RsChatStatusItem::RsChatStatusItem(void *data,uint32_t /*size*/)
|
||||
}
|
||||
|
||||
RsChatAvatarItem::RsChatAvatarItem(void *data,uint32_t /*size*/)
|
||||
: RsChatItem(RS_PKT_SUBTYPE_CHAT_STATUS)
|
||||
: RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR)
|
||||
{
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
@ -48,14 +48,18 @@ const uint32_t RS_CHAT_FLAG_LOBBY = 0x0200;
|
||||
|
||||
const uint32_t RS_CHATMSG_CONFIGFLAG_INCOMING = 0x0001;
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_AVATAR = 0x03 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_STATUS = 0x04 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG = 0x05 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_MSG = 0x06 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE = 0x07 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_ACCEPT = 0x08 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE = 0x09 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE= 0x0A ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_AVATAR = 0x03 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_STATUS = 0x04 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG = 0x05 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_MSG_DEPRECATED= 0x06 ; // don't use !
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE = 0x07 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_ACCEPT = 0x08 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE = 0x09 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE = 0x0A ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_EVENT = 0x0B ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_MSG = 0x0C ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST = 0x0D ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_LIST = 0x0E ;
|
||||
|
||||
// for defining tags themselves and msg tags
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_TAG_TYPE = 0x03;
|
||||
@ -99,8 +103,6 @@ class RsChatMsgItem: public RsChatItem
|
||||
virtual void clear() {}
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
virtual RsChatMsgItem *duplicate() const { return new RsChatMsgItem(*this) ; }
|
||||
|
||||
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
|
||||
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
|
||||
|
||||
@ -111,7 +113,25 @@ class RsChatMsgItem: public RsChatItem
|
||||
uint32_t recvTime;
|
||||
};
|
||||
|
||||
class RsChatLobbyMsgItem: public RsChatMsgItem
|
||||
// This class contains the info to bounce an object throughout a lobby, while
|
||||
// maintaining cache info to avoid duplicates.
|
||||
//
|
||||
class RsChatLobbyBouncingObject
|
||||
{
|
||||
public:
|
||||
ChatLobbyId lobby_id ;
|
||||
ChatLobbyMsgId msg_id ;
|
||||
ChatLobbyNickName nick ; // Nickname of sender
|
||||
|
||||
virtual RsChatLobbyBouncingObject *duplicate() const = 0 ;
|
||||
virtual uint32_t serial_size() ;
|
||||
virtual bool serialise(void *data,uint32_t tlvsize,uint32_t& offset) ;
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
bool deserialise(void *data,uint32_t rssize,uint32_t& offset) ;
|
||||
};
|
||||
|
||||
class RsChatLobbyMsgItem: public RsChatMsgItem, public RsChatLobbyBouncingObject
|
||||
{
|
||||
public:
|
||||
RsChatLobbyMsgItem() :RsChatMsgItem(RS_PKT_SUBTYPE_CHAT_LOBBY_MSG) {}
|
||||
@ -120,14 +140,61 @@ class RsChatLobbyMsgItem: public RsChatMsgItem
|
||||
|
||||
virtual ~RsChatLobbyMsgItem() {}
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
virtual RsChatMsgItem *duplicate() const { return new RsChatLobbyMsgItem(*this) ; }
|
||||
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyMsgItem(*this) ; }
|
||||
|
||||
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
|
||||
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
|
||||
|
||||
ChatLobbyId lobby_id ;
|
||||
ChatLobbyMsgId msg_id ;
|
||||
ChatLobbyNickName nick ;
|
||||
uint8_t subpacket_id ; // this is for proper handling of split packets.
|
||||
ChatLobbyMsgId parent_msg_id ; // Used for threaded chat.
|
||||
};
|
||||
|
||||
class RsChatLobbyEventItem: public RsChatItem, public RsChatLobbyBouncingObject
|
||||
{
|
||||
public:
|
||||
RsChatLobbyEventItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_EVENT) {}
|
||||
RsChatLobbyEventItem(void *data,uint32_t size) ; // deserialization /// TODO!!!
|
||||
|
||||
virtual ~RsChatLobbyEventItem() {}
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; }
|
||||
//
|
||||
virtual bool serialise(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
|
||||
// members.
|
||||
//
|
||||
uint8_t event_type ; // used for defining the type of event.
|
||||
std::string string1; // used for any string
|
||||
};
|
||||
|
||||
class RsChatLobbyListRequestItem: public RsChatItem
|
||||
{
|
||||
public:
|
||||
RsChatLobbyListRequestItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST) {}
|
||||
RsChatLobbyListRequestItem(void *data,uint32_t size) ;
|
||||
virtual ~RsChatLobbyListRequestItem() {}
|
||||
|
||||
virtual bool serialise(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
};
|
||||
class RsChatLobbyListItem: public RsChatItem
|
||||
{
|
||||
public:
|
||||
RsChatLobbyListItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST) {}
|
||||
RsChatLobbyListItem(void *data,uint32_t size) ;
|
||||
virtual ~RsChatLobbyListItem() {}
|
||||
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
virtual bool serialise(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
|
||||
std::vector<ChatLobbyId> lobby_ids ;
|
||||
std::vector<std::string> lobby_names ;
|
||||
std::vector<uint32_t> lobby_counts ;
|
||||
};
|
||||
|
||||
class RsChatLobbyUnsubscribeItem: public RsChatItem
|
||||
|
@ -39,10 +39,13 @@
|
||||
/****
|
||||
* #define CHAT_DEBUG 1
|
||||
****/
|
||||
#define CHAT_DEBUG 1
|
||||
|
||||
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 = 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.
|
||||
|
||||
|
||||
p3ChatService::p3ChatService(p3LinkMgr *lm, p3HistoryMgr *historyMgr)
|
||||
@ -196,20 +199,26 @@ void p3ChatService::sendGroupChatStatusString(const std::string& status_string)
|
||||
|
||||
void p3ChatService::sendStatusString( const std::string& id , const std::string& status_string)
|
||||
{
|
||||
RsChatStatusItem *cs = new RsChatStatusItem ;
|
||||
ChatLobbyId lobby_id ;
|
||||
if(isLobbyId(id,lobby_id))
|
||||
sendLobbyStatusString(lobby_id,status_string) ;
|
||||
else
|
||||
{
|
||||
RsChatStatusItem *cs = new RsChatStatusItem ;
|
||||
|
||||
cs->status_string = status_string ;
|
||||
cs->flags = RS_CHAT_FLAG_PRIVATE ;
|
||||
cs->PeerId(id);
|
||||
cs->status_string = status_string ;
|
||||
cs->flags = RS_CHAT_FLAG_PRIVATE ;
|
||||
cs->PeerId(id);
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "sending chat status packet:" << std::endl ;
|
||||
cs->print(std::cerr) ;
|
||||
std::cerr << "sending chat status packet:" << std::endl ;
|
||||
cs->print(std::cerr) ;
|
||||
#endif
|
||||
sendItem(cs);
|
||||
sendItem(cs);
|
||||
}
|
||||
}
|
||||
|
||||
void p3ChatService::checkSizeAndSendMessage(RsChatMsgItem *msg)
|
||||
void p3ChatService::checkSizeAndSendMessage_deprecated(RsChatMsgItem *msg)
|
||||
{
|
||||
// We check the message item, and possibly split it into multiple messages, if the message is too big.
|
||||
|
||||
@ -219,7 +228,7 @@ void p3ChatService::checkSizeAndSendMessage(RsChatMsgItem *msg)
|
||||
{
|
||||
// chop off the first 15000 wchars
|
||||
|
||||
RsChatMsgItem *item = msg->duplicate() ;
|
||||
RsChatMsgItem *item = new RsChatMsgItem(*msg) ;
|
||||
|
||||
item->message = item->message.substr(0,MAX_STRING_SIZE) ;
|
||||
msg->message = msg->message.substr(MAX_STRING_SIZE,msg->message.size()-MAX_STRING_SIZE) ;
|
||||
@ -236,6 +245,40 @@ void p3ChatService::checkSizeAndSendMessage(RsChatMsgItem *msg)
|
||||
}
|
||||
sendItem(msg) ;
|
||||
}
|
||||
// This function should be used for all types of chat messages. But this requires a non backward compatible change in
|
||||
// chat protocol. To be done for version 0.6
|
||||
//
|
||||
void p3ChatService::checkSizeAndSendMessage(RsChatLobbyMsgItem *msg)
|
||||
{
|
||||
// We check the message item, and possibly split it into multiple messages, if the message is too big.
|
||||
|
||||
static const uint32_t MAX_STRING_SIZE = 15000 ;
|
||||
int n=0 ;
|
||||
|
||||
while(msg->message.size() > MAX_STRING_SIZE)
|
||||
{
|
||||
// chop off the first 15000 wchars
|
||||
|
||||
RsChatLobbyMsgItem *item = new RsChatLobbyMsgItem(*msg) ;
|
||||
|
||||
item->message = item->message.substr(0,MAX_STRING_SIZE) ;
|
||||
msg->message = msg->message.substr(MAX_STRING_SIZE,msg->message.size()-MAX_STRING_SIZE) ;
|
||||
|
||||
// Clear out any one time flags that should not be copied into multiple objects. This is
|
||||
// a precaution, in case the receivign peer does not yet handle split messages transparently.
|
||||
//
|
||||
item->chatFlags &= (RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_PUBLIC | RS_CHAT_FLAG_LOBBY) ;
|
||||
|
||||
// Indicate that the message is to be continued.
|
||||
//
|
||||
item->chatFlags |= RS_CHAT_FLAG_PARTIAL_MESSAGE ;
|
||||
item->subpacket_id = n++ ;
|
||||
|
||||
sendItem(item) ;
|
||||
}
|
||||
msg->subpacket_id = n ;
|
||||
sendItem(msg) ;
|
||||
}
|
||||
|
||||
bool p3ChatService::getVirtualPeerId(const ChatLobbyId& id,std::string& vpid)
|
||||
{
|
||||
@ -264,6 +307,7 @@ bool p3ChatService::getVirtualPeerId(const ChatLobbyId& id,std::string& vpid)
|
||||
void p3ChatService::locked_printDebugInfo() const
|
||||
{
|
||||
std::cerr << "Recorded lobbies: " << std::endl;
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
for( std::map<ChatLobbyId,ChatLobbyEntry>::const_iterator it(_chat_lobbys.begin()) ;it!=_chat_lobbys.end();++it)
|
||||
{
|
||||
@ -272,10 +316,11 @@ void p3ChatService::locked_printDebugInfo() const
|
||||
std::cerr << " nick name\t\t: " << it->second.nick_name << std::endl;
|
||||
std::cerr << " Lobby peer id\t: " << it->second.virtual_peer_id << std::endl;
|
||||
std::cerr << " Challenge count\t: " << it->second.connexion_challenge_count << std::endl;
|
||||
std::cerr << " Last activity\t: " << now - it->second.last_activity << " seconds ago." << std::endl;
|
||||
std::cerr << " Cached messages\t: " << it->second.msg_cache.size() << std::endl;
|
||||
|
||||
for(std::map<ChatLobbyMsgId,time_t>::const_iterator it2(it->second.msg_cache.begin());it2!=it->second.msg_cache.end();++it2)
|
||||
std::cerr << " " << std::hex << it2->first << std::dec << " time=" << it2->second << std::endl;
|
||||
std::cerr << " " << std::hex << it2->first << std::dec << " time=" << now - it2->second << " secs ago" << std::endl;
|
||||
|
||||
std::cerr << " Participating friends: " << std::endl;
|
||||
|
||||
@ -293,6 +338,15 @@ void p3ChatService::locked_printDebugInfo() const
|
||||
|
||||
for( std::map<std::string,ChatLobbyId>::const_iterator it(_lobby_ids.begin()) ;it!=_lobby_ids.end();++it)
|
||||
std::cerr << " \"" << it->first << "\" id = " << std::hex << it->second << std::dec << std::endl;
|
||||
|
||||
std::cerr << "Visible public lobbies: " << std::endl;
|
||||
|
||||
for( std::map<ChatLobbyId,PublicChatLobbyRecord>::const_iterator it(_public_lobbies.begin()) ;it!=_public_lobbies.end();++it)
|
||||
{
|
||||
std::cerr << " " << std::hex << it->first << " name = " << std::dec << it->second.lobby_name << std::endl;
|
||||
for(std::set<std::string>::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
|
||||
std::cerr << " With friend: " << *it2 << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
bool p3ChatService::isLobbyId(const std::string& id,ChatLobbyId& lobby_id)
|
||||
@ -377,7 +431,7 @@ bool p3ChatService::sendPrivateChat(const std::string &id, const std::wstrin
|
||||
|
||||
mHistoryMgr->addMessage(false, id, mLinkMgr->getOwnId(), ci);
|
||||
|
||||
checkSizeAndSendMessage(ci);
|
||||
checkSizeAndSendMessage_deprecated(ci);
|
||||
|
||||
// Check if custom state string has changed, in which case it should be sent to the peer.
|
||||
bool should_send_state_string = false ;
|
||||
@ -412,13 +466,13 @@ bool p3ChatService::sendPrivateChat(const std::string &id, const std::wstrin
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3ChatService::checkAndRebuildPartialMessage(RsChatMsgItem *ci)
|
||||
bool p3ChatService::locked_checkAndRebuildPartialMessage_deprecated(RsChatMsgItem *ci)
|
||||
{
|
||||
// Check is the item is ending an incomplete item.
|
||||
//
|
||||
std::map<std::string,RsChatMsgItem*>::iterator it = _pendingPartialMessages.find(ci->PeerId()) ;
|
||||
|
||||
bool ci_is_partial = ci->chatFlags & RS_CHAT_FLAG_PARTIAL_MESSAGE ;
|
||||
bool ci_is_incomplete = ci->chatFlags & RS_CHAT_FLAG_PARTIAL_MESSAGE ;
|
||||
|
||||
if(it != _pendingPartialMessages.end())
|
||||
{
|
||||
@ -432,11 +486,11 @@ bool p3ChatService::checkAndRebuildPartialMessage(RsChatMsgItem *ci)
|
||||
|
||||
delete it->second ;
|
||||
|
||||
if(!ci_is_partial)
|
||||
if(!ci_is_incomplete)
|
||||
_pendingPartialMessages.erase(it) ;
|
||||
}
|
||||
|
||||
if(ci_is_partial)
|
||||
if(ci_is_incomplete)
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Message is partial, storing for later." << std::endl;
|
||||
@ -454,13 +508,82 @@ bool p3ChatService::checkAndRebuildPartialMessage(RsChatMsgItem *ci)
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
bool p3ChatService::locked_checkAndRebuildPartialMessage(RsChatLobbyMsgItem *ci)
|
||||
{
|
||||
// Check is the item is ending an incomplete item.
|
||||
//
|
||||
std::map<ChatLobbyMsgId,std::vector<RsChatLobbyMsgItem*> >::iterator it = _pendingPartialLobbyMessages.find(ci->msg_id) ;
|
||||
|
||||
std::cerr << "Checking chat message for completeness:" << std::endl;
|
||||
bool ci_is_incomplete = ci->chatFlags & RS_CHAT_FLAG_PARTIAL_MESSAGE ;
|
||||
|
||||
if(it != _pendingPartialLobbyMessages.end())
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << " Pending message found. Happending it." << std::endl;
|
||||
#endif
|
||||
// Yes, there is. Add the item to the list of stored sub-items
|
||||
|
||||
if(ci->subpacket_id >= it->second.size() )
|
||||
it->second.resize(ci->subpacket_id+1,NULL) ;
|
||||
|
||||
it->second[ci->subpacket_id] = ci ;
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << " Checking for completeness." << std::endl;
|
||||
#endif
|
||||
// Now check wether we have a complete item or not.
|
||||
//
|
||||
bool complete = true ;
|
||||
for(uint32_t i=0;i<it->second.size() && complete;++i)
|
||||
complete = complete && (it->second[i] != NULL) ;
|
||||
|
||||
complete = complete && !(it->second.back()->chatFlags & RS_CHAT_FLAG_PARTIAL_MESSAGE) ;
|
||||
|
||||
if(complete)
|
||||
{
|
||||
std::cerr << " Message is complete ! Re-forming it and returning true." << std::endl;
|
||||
std::wstring msg ;
|
||||
uint32_t flags = 0 ;
|
||||
|
||||
for(uint32_t i=0;i<it->second.size();++i)
|
||||
{
|
||||
msg += it->second[i]->message ;
|
||||
flags |= it->second[i]->chatFlags ;
|
||||
|
||||
if(i != ci->subpacket_id) // don't delete ci itself !!
|
||||
delete it->second[i] ;
|
||||
}
|
||||
_pendingPartialLobbyMessages.erase(it) ;
|
||||
|
||||
ci->chatFlags = flags ;
|
||||
ci->message = msg ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << " Not complete: returning" << std::endl ;
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
else if(ci_is_incomplete || ci->subpacket_id > 0) // the message id might not yet be recorded
|
||||
{
|
||||
std::cerr << " Message is partial, but not recorded. Adding it. " << std::endl;
|
||||
|
||||
_pendingPartialLobbyMessages[ci->msg_id].resize(ci->subpacket_id+1,NULL) ;
|
||||
_pendingPartialLobbyMessages[ci->msg_id][ci->subpacket_id] = ci ;
|
||||
|
||||
return false ;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << " Message is not partial. Returning it as is." << std::endl;
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
|
||||
void p3ChatService::receiveChatQueue()
|
||||
{
|
||||
bool publicChanged = false;
|
||||
bool privateChanged = false;
|
||||
|
||||
time_t now = time(NULL);
|
||||
RsItem *item ;
|
||||
|
||||
while(NULL != (item=recvItem()))
|
||||
@ -468,171 +591,165 @@ void p3ChatService::receiveChatQueue()
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::receiveChatQueue() Item:" << (void*)item << std::endl ;
|
||||
#endif
|
||||
RsChatMsgItem *ci = dynamic_cast<RsChatMsgItem*>(item) ;
|
||||
|
||||
if(ci != NULL) // real chat message
|
||||
// RsChatMsgItems needs dynamic_cast, since they have derived siblings.
|
||||
//
|
||||
RsChatMsgItem *ci = dynamic_cast<RsChatMsgItem*>(item) ;
|
||||
if(ci != NULL)
|
||||
{
|
||||
// check if it's a lobby msg, in which case we replace the peer id by the lobby's virtual peer id.
|
||||
//
|
||||
RsChatLobbyMsgItem *cli = dynamic_cast<RsChatLobbyMsgItem*>(ci) ;
|
||||
if(! handleRecvChatMsgItem(ci))
|
||||
delete ci ;
|
||||
|
||||
if(cli != NULL)
|
||||
{
|
||||
if(!recvLobbyChat(cli,cli->PeerId())) // forwards the message to friends, keeps track of subscribers, etc.
|
||||
{
|
||||
delete ci ;
|
||||
continue ;
|
||||
}
|
||||
}
|
||||
else if(!checkAndRebuildPartialMessage(ci)) // Don't delete ! This function is not handled propoerly for chat lobby msgs, so
|
||||
continue ; // we don't use it in this case.
|
||||
continue ; // don't delete! It's handled by handleRecvChatMsgItem in some specific cases only.
|
||||
}
|
||||
|
||||
switch(item->PacketSubType())
|
||||
{
|
||||
case RS_PKT_SUBTYPE_CHAT_STATUS: handleRecvChatStatusItem (dynamic_cast<RsChatStatusItem *>(item)) ; break ;
|
||||
case RS_PKT_SUBTYPE_CHAT_AVATAR: handleRecvChatAvatarItem (dynamic_cast<RsChatAvatarItem *>(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_EVENT: handleRecvChatLobbyEventItem (dynamic_cast<RsChatLobbyEventItem *>(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:
|
||||
std::cerr << "Unhandled item subtype " << item->PacketSubType() << " in p3ChatService: " << std::endl;
|
||||
}
|
||||
delete item ;
|
||||
}
|
||||
}
|
||||
|
||||
void p3ChatService::handleRecvChatLobbyListRequest(RsChatLobbyListRequestItem *item)
|
||||
{
|
||||
// todo !!
|
||||
std::cerr << "Called to unimplemented method: p3ChatService::handleRecvChatLobbyListRequest(RsChatLobbyListRequestItem *item)" << std::endl;
|
||||
}
|
||||
void p3ChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item)
|
||||
{
|
||||
// todo !!
|
||||
std::cerr << "Called to unimplemented method: p3ChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item)" << std::endl;
|
||||
}
|
||||
|
||||
void p3ChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *item)
|
||||
{
|
||||
std::cerr << "Received ChatLobbyEvent item of type " << item->event_type << ", and string=" << item->string1 << std::endl;
|
||||
|
||||
if(! bounceLobbyObject(item,item->PeerId()))
|
||||
return ;
|
||||
|
||||
rsicontrol->getNotify().notifyChatLobbyEvent(item->lobby_id,item->event_type,item->nick,item->string1) ;
|
||||
}
|
||||
|
||||
void p3ChatService::handleRecvChatAvatarItem(RsChatAvatarItem *ca)
|
||||
{
|
||||
receiveAvatarJpegData(ca) ;
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::receiveChatQueue() Item:";
|
||||
std::cerr << std::endl;
|
||||
ci->print(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "Got msg. Flags = " << ci->chatFlags << std::endl ;
|
||||
std::cerr << "Received avatar data for peer " << ca->PeerId() << ". Notifying." << std::endl ;
|
||||
#endif
|
||||
rsicontrol->getNotify().notifyPeerHasNewAvatar(ca->PeerId()) ;
|
||||
}
|
||||
|
||||
bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *ci)
|
||||
{
|
||||
bool publicChanged = false;
|
||||
bool privateChanged = false;
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
// check if it's a lobby msg, in which case we replace the peer id by the lobby's virtual peer id.
|
||||
//
|
||||
RsChatLobbyMsgItem *cli = dynamic_cast<RsChatLobbyMsgItem*>(ci) ;
|
||||
|
||||
if(cli != NULL)
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
if(!locked_checkAndRebuildPartialMessage(cli))
|
||||
return true ;
|
||||
}
|
||||
|
||||
if(!bounceLobbyObject(cli,cli->PeerId())) // forwards the message to friends, keeps track of subscribers, etc.
|
||||
return false;
|
||||
|
||||
// setup the peer id to the virtual peer id of the lobby.
|
||||
//
|
||||
std::string virtual_peer_id ;
|
||||
getVirtualPeerId(cli->lobby_id,virtual_peer_id) ;
|
||||
cli->PeerId(virtual_peer_id) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
if(!locked_checkAndRebuildPartialMessage_deprecated(ci)) // Don't delete ! This function is not handled propoerly for chat lobby msgs, so
|
||||
return true ; // we don't use it in this case.
|
||||
}
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::receiveChatQueue() Item:";
|
||||
std::cerr << std::endl;
|
||||
ci->print(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "Got msg. Flags = " << ci->chatFlags << std::endl ;
|
||||
#endif
|
||||
|
||||
if(ci->chatFlags & RS_CHAT_FLAG_REQUESTS_AVATAR) // no msg here. Just an avatar request.
|
||||
{
|
||||
sendAvatarJpegData(ci->PeerId()) ;
|
||||
delete item ;
|
||||
continue ;
|
||||
if(ci->chatFlags & RS_CHAT_FLAG_REQUESTS_AVATAR) // no msg here. Just an avatar request.
|
||||
{
|
||||
sendAvatarJpegData(ci->PeerId()) ;
|
||||
return false ;
|
||||
}
|
||||
else // normal msg. Return it normally.
|
||||
{
|
||||
// Check if new avatar is available at peer's. If so, send a request to get the avatar.
|
||||
if(ci->chatFlags & RS_CHAT_FLAG_AVATAR_AVAILABLE)
|
||||
{
|
||||
std::cerr << "New avatar is available for peer " << ci->PeerId() << ", sending request" << std::endl ;
|
||||
sendAvatarRequest(ci->PeerId()) ;
|
||||
ci->chatFlags &= ~RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
||||
}
|
||||
|
||||
std::map<std::string,AvatarInfo *>::const_iterator it = _avatars.find(ci->PeerId()) ;
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3chatservice:: avatar requested from above. " << std::endl ;
|
||||
#endif
|
||||
// has avatar. Return it strait away.
|
||||
//
|
||||
if(it!=_avatars.end() && it->second->_peer_is_new)
|
||||
{
|
||||
std::cerr << "Avatar is new for peer. ending info above" << std::endl ;
|
||||
ci->chatFlags |= RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
||||
}
|
||||
|
||||
if ((ci->chatFlags & RS_CHAT_FLAG_PRIVATE) == 0) {
|
||||
/* notify public chat message */
|
||||
std::string message;
|
||||
message.assign(ci->message.begin(), ci->message.end());
|
||||
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_CHAT_NEW, ci->PeerId(), message, "");
|
||||
}
|
||||
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
ci->recvTime = now;
|
||||
|
||||
if (ci->chatFlags & RS_CHAT_FLAG_PRIVATE) {
|
||||
std::cerr << "Adding msg 0x" << std::hex << (void*)ci << std::dec << " to private chat incoming list." << std::endl;
|
||||
privateChanged = true;
|
||||
privateIncomingList.push_back(ci); // don't delete the item !!
|
||||
} else {
|
||||
std::cerr << "Adding msg 0x" << std::hex << (void*)ci << std::dec << " to public chat incoming list." << std::endl;
|
||||
publicChanged = true;
|
||||
publicList.push_back(ci); // don't delete the item !!
|
||||
|
||||
if (ci->PeerId() != mLinkMgr->getOwnId()) {
|
||||
/* not from loop back */
|
||||
mHistoryMgr->addMessage(true, "", ci->PeerId(), ci);
|
||||
}
|
||||
}
|
||||
else // normal msg. Return it normally.
|
||||
{
|
||||
// Check if new avatar is available at peer's. If so, send a request to get the avatar.
|
||||
if(ci->chatFlags & RS_CHAT_FLAG_AVATAR_AVAILABLE)
|
||||
{
|
||||
std::cerr << "New avatar is available for peer " << ci->PeerId() << ", sending request" << std::endl ;
|
||||
sendAvatarRequest(ci->PeerId()) ;
|
||||
ci->chatFlags &= ~RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
||||
}
|
||||
|
||||
std::map<std::string,AvatarInfo *>::const_iterator it = _avatars.find(ci->PeerId()) ;
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3chatservice:: avatar requested from above. " << std::endl ;
|
||||
#endif
|
||||
// has avatar. Return it strait away.
|
||||
//
|
||||
if(it!=_avatars.end() && it->second->_peer_is_new)
|
||||
{
|
||||
std::cerr << "Avatar is new for peer. ending info above" << std::endl ;
|
||||
ci->chatFlags |= RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
||||
}
|
||||
|
||||
if ((ci->chatFlags & RS_CHAT_FLAG_PRIVATE) == 0) {
|
||||
/* notify public chat message */
|
||||
std::string message;
|
||||
message.assign(ci->message.begin(), ci->message.end());
|
||||
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_CHAT_NEW, ci->PeerId(), message, "");
|
||||
}
|
||||
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
ci->recvTime = now;
|
||||
|
||||
if (ci->chatFlags & RS_CHAT_FLAG_PRIVATE) {
|
||||
std::cerr << "Adding msg 0x" << std::hex << (void*)ci << std::dec << " to private chat incoming list." << std::endl;
|
||||
privateChanged = true;
|
||||
privateIncomingList.push_back(ci); // don't delete the item !!
|
||||
} else {
|
||||
std::cerr << "Adding msg 0x" << std::hex << (void*)ci << std::dec << " to public chat incoming list." << std::endl;
|
||||
publicChanged = true;
|
||||
publicList.push_back(ci); // don't delete the item !!
|
||||
|
||||
if (ci->PeerId() != mLinkMgr->getOwnId()) {
|
||||
/* not from loop back */
|
||||
mHistoryMgr->addMessage(true, "", ci->PeerId(), ci);
|
||||
}
|
||||
}
|
||||
} /* UNLOCK */
|
||||
}
|
||||
continue ;
|
||||
}
|
||||
|
||||
RsChatStatusItem *cs = dynamic_cast<RsChatStatusItem*>(item) ;
|
||||
|
||||
if(cs != NULL)
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Received status string \"" << cs->status_string << "\"" << std::endl ;
|
||||
#endif
|
||||
|
||||
if(cs->flags & RS_CHAT_FLAG_REQUEST_CUSTOM_STATE){ // no state here just a request.
|
||||
sendCustomState(cs->PeerId()) ;
|
||||
|
||||
}
|
||||
else // Check if new custom string is available at peer's. If so, send a request to get the custom string.
|
||||
if(cs->flags & RS_CHAT_FLAG_CUSTOM_STATE)
|
||||
{
|
||||
receiveStateString(cs->PeerId(),cs->status_string) ; // store it
|
||||
rsicontrol->getNotify().notifyCustomState(cs->PeerId(), cs->status_string) ;
|
||||
}else
|
||||
if(cs->flags & RS_CHAT_FLAG_CUSTOM_STATE_AVAILABLE){
|
||||
|
||||
std::cerr << "New custom state is available for peer " << cs->PeerId() << ", sending request" << std::endl ;
|
||||
sendCustomStateRequest(cs->PeerId()) ;
|
||||
}else
|
||||
if(cs->flags & RS_CHAT_FLAG_PRIVATE)
|
||||
rsicontrol->getNotify().notifyChatStatus(cs->PeerId(),cs->status_string,true) ;
|
||||
else
|
||||
if(cs->flags & RS_CHAT_FLAG_PUBLIC)
|
||||
rsicontrol->getNotify().notifyChatStatus(cs->PeerId(),cs->status_string,false) ;
|
||||
|
||||
delete item;
|
||||
continue ;
|
||||
}
|
||||
|
||||
RsChatAvatarItem *ca = dynamic_cast<RsChatAvatarItem*>(item) ;
|
||||
|
||||
if(ca != NULL)
|
||||
{
|
||||
receiveAvatarJpegData(ca) ;
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Received avatar data for peer " << ca->PeerId() << ". Notifying." << std::endl ;
|
||||
#endif
|
||||
rsicontrol->getNotify().notifyPeerHasNewAvatar(ca->PeerId()) ;
|
||||
|
||||
delete item ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
RsChatLobbyInviteItem *cl = dynamic_cast<RsChatLobbyInviteItem*>(item) ;
|
||||
|
||||
if(cl != NULL)
|
||||
{
|
||||
handleRecvLobbyInvite(cl) ;
|
||||
delete item ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
RsChatLobbyConnectChallengeItem *cn = dynamic_cast<RsChatLobbyConnectChallengeItem*>(item) ;
|
||||
|
||||
if(cn != NULL)
|
||||
{
|
||||
handleConnectionChallenge(cn) ;
|
||||
delete item ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
RsChatLobbyUnsubscribeItem *cu = dynamic_cast<RsChatLobbyUnsubscribeItem*>(item) ;
|
||||
|
||||
if(cu != NULL)
|
||||
{
|
||||
handleFriendUnsubscribeLobby(cu) ;
|
||||
delete item ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
|
||||
std::cerr << "Received ChatItem of unhandled type: " << std::endl;
|
||||
item->print(std::cerr,0) ;
|
||||
} /* UNLOCK */
|
||||
}
|
||||
|
||||
if (publicChanged) {
|
||||
@ -643,6 +760,41 @@ void p3ChatService::receiveChatQueue()
|
||||
|
||||
IndicateConfigChanged(); // only private chat messages are saved
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
void p3ChatService::handleRecvChatStatusItem(RsChatStatusItem *cs)
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Received status string \"" << cs->status_string << "\"" << std::endl ;
|
||||
#endif
|
||||
|
||||
if(cs->flags & RS_CHAT_FLAG_REQUEST_CUSTOM_STATE) // no state here just a request.
|
||||
sendCustomState(cs->PeerId()) ;
|
||||
else if(cs->flags & RS_CHAT_FLAG_CUSTOM_STATE) // Check if new custom string is available at peer's.
|
||||
{ // If so, send a request to get the custom string.
|
||||
receiveStateString(cs->PeerId(),cs->status_string) ; // store it
|
||||
rsicontrol->getNotify().notifyCustomState(cs->PeerId(), cs->status_string) ;
|
||||
}
|
||||
else if(cs->flags & RS_CHAT_FLAG_CUSTOM_STATE_AVAILABLE)
|
||||
{
|
||||
std::cerr << "New custom state is available for peer " << cs->PeerId() << ", sending request" << std::endl ;
|
||||
sendCustomStateRequest(cs->PeerId()) ;
|
||||
}
|
||||
else if(cs->flags & RS_CHAT_FLAG_PRIVATE)
|
||||
rsicontrol->getNotify().notifyChatStatus(cs->PeerId(),cs->status_string,true) ;
|
||||
else if(cs->flags & RS_CHAT_FLAG_PUBLIC)
|
||||
rsicontrol->getNotify().notifyChatStatus(cs->PeerId(),cs->status_string,false) ;
|
||||
}
|
||||
|
||||
void p3ChatService::getListOfNearbyChatLobbies(std::vector<PublicChatLobbyRecord>& public_lobbies)
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
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) ;
|
||||
}
|
||||
|
||||
int p3ChatService::getPublicChatQueueCount()
|
||||
@ -1269,7 +1421,7 @@ void p3ChatService::statusChange(const std::list<pqipeer> &plist)
|
||||
if (c->PeerId() == it->id) {
|
||||
mHistoryMgr->addMessage(false, c->PeerId(), ownId, c);
|
||||
|
||||
checkSizeAndSendMessage(c); // delete item
|
||||
checkSizeAndSendMessage_deprecated(c); // delete item
|
||||
|
||||
changed = true;
|
||||
|
||||
@ -1295,13 +1447,12 @@ void p3ChatService::statusChange(const std::list<pqipeer> &plist)
|
||||
//********************** Chat Lobby Stuff ***********************//
|
||||
|
||||
// returns:
|
||||
// true: the message is not a duplicate and should be shown
|
||||
// false: the message is a duplicate or there is an error, and should be destroyed.
|
||||
// true: the object is not a duplicate and should be used
|
||||
// false: the object is a duplicate or there is an error, and it should be destroyed.
|
||||
//
|
||||
bool p3ChatService::recvLobbyChat(RsChatLobbyMsgItem *item,const std::string& peer_id)
|
||||
bool p3ChatService::bounceLobbyObject(RsChatLobbyBouncingObject *item,const std::string& peer_id)
|
||||
{
|
||||
bool send_challenge = false ;
|
||||
std::string lobby_virtual_peer_id ;
|
||||
ChatLobbyId send_challenge_lobby ;
|
||||
|
||||
{
|
||||
@ -1309,7 +1460,7 @@ bool p3ChatService::recvLobbyChat(RsChatLobbyMsgItem *item,const std::string& pe
|
||||
|
||||
locked_printDebugInfo() ; // debug
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Handling ChatLobbyMsg " << std::hex << item->msg_id << ", lobby id " << item->lobby_id << ", from peer id " << item->PeerId() << std::endl;
|
||||
std::cerr << "Handling ChatLobbyMsg " << std::hex << item->msg_id << ", lobby id " << item->lobby_id << ", from peer id " << peer_id << std::endl;
|
||||
#endif
|
||||
|
||||
// send upward for display
|
||||
@ -1325,13 +1476,12 @@ bool p3ChatService::recvLobbyChat(RsChatLobbyMsgItem *item,const std::string& pe
|
||||
|
||||
// Adds the peer id to the list of friend participants, even if it's not original msg source
|
||||
|
||||
lobby.participating_friends.insert(peer_id) ;
|
||||
if(peer_id != mLinkMgr->getOwnId())
|
||||
lobby.participating_friends.insert(peer_id) ;
|
||||
|
||||
if(item->nick != "Lobby management") // not nice ! We need a lobby management flag.
|
||||
lobby.nick_names.insert(item->nick) ;
|
||||
|
||||
lobby_virtual_peer_id = lobby.virtual_peer_id ;
|
||||
|
||||
// Checks wether the msg is already recorded or not
|
||||
|
||||
std::map<ChatLobbyMsgId,time_t>::const_iterator it2(lobby.msg_cache.find(item->msg_id)) ;
|
||||
@ -1345,45 +1495,80 @@ bool p3ChatService::recvLobbyChat(RsChatLobbyMsgItem *item,const std::string& pe
|
||||
std::cerr << " Msg already not received already. Adding in cache, and forwarding!" << std::endl ;
|
||||
#endif
|
||||
|
||||
lobby.msg_cache[item->msg_id] = time(NULL) ;
|
||||
time_t now = time(NULL) ;
|
||||
lobby.msg_cache[item->msg_id] = now ;
|
||||
lobby.last_activity = now ;
|
||||
|
||||
bool is_message = (NULL != dynamic_cast<RsChatLobbyMsgItem*>(item)) ;
|
||||
|
||||
// Forward to allparticipating friends, except this peer.
|
||||
|
||||
for(std::set<std::string>::const_iterator it(lobby.participating_friends.begin());it!=lobby.participating_friends.end();++it)
|
||||
if((*it)!=peer_id && mLinkMgr->isOnline(*it))
|
||||
{
|
||||
RsChatLobbyMsgItem *item2 = new RsChatLobbyMsgItem(*item) ; // copy almost everything
|
||||
RsChatLobbyBouncingObject *obj2 = item->duplicate() ; // makes a copy
|
||||
RsChatItem *item2 = dynamic_cast<RsChatItem*>(obj2) ;
|
||||
|
||||
assert(item2 != NULL) ;
|
||||
|
||||
item2->PeerId(*it) ; // replaces the virtual peer id with the actual destination.
|
||||
|
||||
sendItem(item2);
|
||||
if(is_message)
|
||||
checkSizeAndSendMessage(static_cast<RsChatLobbyMsgItem*>(item2)) ;
|
||||
else
|
||||
sendItem(item2);
|
||||
}
|
||||
|
||||
if(++lobby.connexion_challenge_count > CONNECTION_CHALLENGE_MAX_COUNT)
|
||||
if(++lobby.connexion_challenge_count > CONNECTION_CHALLENGE_MAX_COUNT && now > lobby.last_connexion_challenge_time + CONNECTION_CHALLENGE_MIN_DELAY)
|
||||
{
|
||||
lobby.connexion_challenge_count = 0 ;
|
||||
send_challenge_lobby = item->lobby_id ;
|
||||
send_challenge = true ;
|
||||
lobby.last_connexion_challenge_time = now ;
|
||||
}
|
||||
}
|
||||
|
||||
if(send_challenge)
|
||||
sendConnectionChallenge(send_challenge_lobby) ;
|
||||
|
||||
item->PeerId(lobby_virtual_peer_id) ; // updates the peer id for proper display
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lobby_id,bool management)
|
||||
void p3ChatService::sendLobbyStatusString(const ChatLobbyId& lobby_id,const std::string& status_string)
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
sendLobbyStatusItem(lobby_id,RS_CHAT_LOBBY_EVENT_PEER_STATUS,status_string) ;
|
||||
}
|
||||
void p3ChatService::sendLobbyStatusPeerLiving(const ChatLobbyId& lobby_id)
|
||||
{
|
||||
std::string nick ;
|
||||
getNickNameForChatLobby(lobby_id,nick) ;
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Sending chat lobby message to lobby " << std::hex << lobby_id << std::dec << std::endl;
|
||||
std::cerr << "msg:" << std::endl;
|
||||
std::wcerr << msg << std::endl;
|
||||
#endif
|
||||
sendLobbyStatusItem(lobby_id,RS_CHAT_LOBBY_EVENT_PEER_LEFT,nick) ;
|
||||
}
|
||||
void p3ChatService::sendLobbyStatusNewPeer(const ChatLobbyId& lobby_id)
|
||||
{
|
||||
std::string nick ;
|
||||
getNickNameForChatLobby(lobby_id,nick) ;
|
||||
|
||||
sendLobbyStatusItem(lobby_id,RS_CHAT_LOBBY_EVENT_PEER_JOINED,nick) ;
|
||||
}
|
||||
void p3ChatService::sendLobbyStatusItem(const ChatLobbyId& lobby_id,int type,const std::string& status_string)
|
||||
{
|
||||
RsChatLobbyEventItem item ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
locked_initLobbyBouncableObject(lobby_id,item) ;
|
||||
|
||||
item.event_type = type ;
|
||||
item.string1 = status_string ;
|
||||
}
|
||||
std::string ownId = mLinkMgr->getOwnId();
|
||||
bounceLobbyObject(&item,ownId) ;
|
||||
}
|
||||
|
||||
void p3ChatService::locked_initLobbyBouncableObject(const ChatLobbyId& lobby_id,RsChatLobbyBouncingObject& item)
|
||||
{
|
||||
// get a pointer to the info for that chat lobby.
|
||||
//
|
||||
std::map<ChatLobbyId,ChatLobbyEntry>::iterator it(_chat_lobbys.find(lobby_id)) ;
|
||||
@ -1391,43 +1576,47 @@ bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lo
|
||||
if(it == _chat_lobbys.end())
|
||||
{
|
||||
std::cerr << "Chatlobby for id " << std::hex << lobby_id << " has no record. This is a serious error!!" << std::dec << std::endl;
|
||||
return false ;
|
||||
return ;
|
||||
}
|
||||
ChatLobbyEntry& lobby(it->second) ;
|
||||
|
||||
RsChatLobbyMsgItem item ;
|
||||
|
||||
// chat lobby stuff
|
||||
//
|
||||
do { item.msg_id = RSRandom::random_u64(); } while( lobby.msg_cache.find(item.msg_id) != lobby.msg_cache.end() ) ;
|
||||
|
||||
lobby.msg_cache[item.msg_id] = time(NULL) ; // put the msg in cache!
|
||||
do
|
||||
{
|
||||
item.msg_id = RSRandom::random_u64();
|
||||
}
|
||||
while( lobby.msg_cache.find(item.msg_id) != lobby.msg_cache.end() ) ;
|
||||
|
||||
item.lobby_id = lobby_id ;
|
||||
item.nick = lobby.nick_name ;
|
||||
}
|
||||
|
||||
if(management)
|
||||
item.nick = "Lobby management" ;
|
||||
else
|
||||
item.nick = lobby.nick_name ;
|
||||
bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lobby_id)
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Sending chat lobby message to lobby " << std::hex << lobby_id << std::dec << std::endl;
|
||||
std::cerr << "msg:" << std::endl;
|
||||
std::wcerr << msg << std::endl;
|
||||
#endif
|
||||
|
||||
// chat msg stuff
|
||||
//
|
||||
item.chatFlags = RS_CHAT_FLAG_LOBBY | RS_CHAT_FLAG_PRIVATE;
|
||||
item.sendTime = time(NULL);
|
||||
item.recvTime = item.sendTime;
|
||||
item.message = msg;
|
||||
RsChatLobbyMsgItem item ;
|
||||
|
||||
for(std::set<std::string>::const_iterator it(lobby.participating_friends.begin());it!=lobby.participating_friends.end();++it)
|
||||
if(mLinkMgr->isOnline(*it))
|
||||
{
|
||||
RsChatLobbyMsgItem *sitem = new RsChatLobbyMsgItem(item) ; // copies almost everything
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
// gives a random msg id, setup the nickname
|
||||
locked_initLobbyBouncableObject(lobby_id,item) ;
|
||||
|
||||
sitem->PeerId(*it) ;
|
||||
// chat msg stuff
|
||||
//
|
||||
item.chatFlags = RS_CHAT_FLAG_LOBBY | RS_CHAT_FLAG_PRIVATE;
|
||||
item.sendTime = time(NULL);
|
||||
item.recvTime = item.sendTime;
|
||||
item.message = msg;
|
||||
}
|
||||
|
||||
sendItem(sitem);
|
||||
}
|
||||
bounceLobbyObject(&item,rsPeers->getOwnId()) ;
|
||||
|
||||
locked_printDebugInfo() ; // debug
|
||||
return true ;
|
||||
}
|
||||
|
||||
@ -1641,11 +1830,13 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id)
|
||||
|
||||
ChatLobbyEntry entry ;
|
||||
entry.participating_friends.insert(it->second.peer_id) ;
|
||||
entry.nick_name = _default_nick_name ; // to be changed. For debug only!!
|
||||
entry.nick_name = _default_nick_name ;
|
||||
entry.lobby_id = lobby_id ;
|
||||
entry.lobby_name = it->second.lobby_name ;
|
||||
entry.virtual_peer_id = makeVirtualPeerId(lobby_id) ;
|
||||
entry.connexion_challenge_count = 0 ;
|
||||
entry.last_activity = time(NULL) ;
|
||||
entry.last_connexion_challenge_time = time(NULL) ;
|
||||
|
||||
_lobby_ids[entry.virtual_peer_id] = lobby_id ;
|
||||
_chat_lobbys[lobby_id] = entry ;
|
||||
@ -1657,7 +1848,6 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id)
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << " Pushing new msg item to incoming msgs." << std::endl;
|
||||
#endif
|
||||
|
||||
RsChatLobbyMsgItem *item = new RsChatLobbyMsgItem;
|
||||
item->lobby_id = entry.lobby_id ;
|
||||
item->msg_id = 0 ;
|
||||
@ -1675,11 +1865,8 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id)
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_PRIVATE_INCOMING_CHAT, NOTIFY_TYPE_ADD);
|
||||
|
||||
// send AKN item
|
||||
std::wstring wmsg(_default_nick_name.length(), L' '); // Make room for characters
|
||||
// Copy string to wstring.
|
||||
std::copy(_default_nick_name.begin(), _default_nick_name.end(), wmsg.begin());
|
||||
sendLobbyStatusNewPeer(lobby_id) ;
|
||||
|
||||
sendLobbyChat(wmsg + L" joined the lobby",lobby_id,true) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
@ -1710,7 +1897,7 @@ void p3ChatService::denyLobbyInvite(const ChatLobbyId& lobby_id)
|
||||
_lobby_invites_queue.erase(it) ;
|
||||
}
|
||||
|
||||
ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends)
|
||||
ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends,uint32_t privacy_level)
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Creating a new Chat lobby !!" << std::endl;
|
||||
@ -1728,12 +1915,15 @@ ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const s
|
||||
#endif
|
||||
|
||||
ChatLobbyEntry entry ;
|
||||
entry.lobby_privacy_level = privacy_level ;
|
||||
entry.participating_friends.clear() ;
|
||||
entry.nick_name = _default_nick_name ; // to be changed. For debug only!!
|
||||
entry.lobby_id = lobby_id ;
|
||||
entry.lobby_name = lobby_name ;
|
||||
entry.virtual_peer_id = makeVirtualPeerId(lobby_id) ;
|
||||
entry.connexion_challenge_count = 0 ;
|
||||
entry.last_activity = time(NULL) ;
|
||||
entry.last_connexion_challenge_time = time(NULL) ;
|
||||
|
||||
_lobby_ids[entry.virtual_peer_id] = lobby_id ;
|
||||
_chat_lobbys[lobby_id] = entry ;
|
||||
@ -1751,12 +1941,12 @@ void p3ChatService::handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem *ite
|
||||
std::map<ChatLobbyId,ChatLobbyEntry>::iterator it = _chat_lobbys.find(item->lobby_id) ;
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Received unsubscribed to lobby " << item->lobby_id << ", from friend " << item->PeerId() << std::endl;
|
||||
std::cerr << "Received unsubscribed to lobby " << std::hex << item->lobby_id << std::dec << ", from friend " << item->PeerId() << std::endl;
|
||||
#endif
|
||||
|
||||
if(it == _chat_lobbys.end())
|
||||
{
|
||||
std::cerr << "Chat lobby " << item->lobby_id << " does not exist ! Can't unsubscribe!" << std::endl;
|
||||
std::cerr << "Chat lobby " << std::hex << item->lobby_id << std::dec << " does not exist ! Can't unsubscribe friend!" << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
@ -1764,7 +1954,7 @@ void p3ChatService::handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem *ite
|
||||
if(*it2 == item->PeerId())
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << " removing peer id " << item->PeerId() << " from participant list of lobby " << item->lobby_id << std::endl;
|
||||
std::cerr << " removing peer id " << item->PeerId() << " from participant list of lobby " << std::hex << item->lobby_id << std::dec << std::endl;
|
||||
#endif
|
||||
it->second.participating_friends.erase(it2) ;
|
||||
break ;
|
||||
@ -1774,11 +1964,7 @@ void p3ChatService::handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem *ite
|
||||
void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id)
|
||||
{
|
||||
// send AKN item
|
||||
std::string nick ;
|
||||
getNickNameForChatLobby(id,nick) ;
|
||||
std::wstring wmsg(nick.length(), L' '); // Make room for characters
|
||||
std::copy(nick.begin(), nick.end(), wmsg.begin());
|
||||
sendLobbyChat(wmsg + L" has left the lobby",id,true) ;
|
||||
sendLobbyStatusPeerLiving(id) ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
@ -1800,6 +1986,8 @@ void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id)
|
||||
item->lobby_id = id ;
|
||||
item->PeerId(*it2) ;
|
||||
|
||||
std::cerr << "Sending unsubscribe item to friend " << *it2 << std::endl;
|
||||
|
||||
sendItem(item) ;
|
||||
}
|
||||
|
||||
@ -1890,6 +2078,9 @@ void p3ChatService::cleanLobbyCaches()
|
||||
}
|
||||
else
|
||||
++it2 ;
|
||||
|
||||
// also clean inactive lobbies.
|
||||
// [...]
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "serialiser/rsmsgitems.h"
|
||||
#include "services/p3service.h"
|
||||
@ -165,7 +166,9 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
||||
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) ;
|
||||
void sendLobbyStatusString(const ChatLobbyId& id,const std::string& status_string) ;
|
||||
ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends,uint32_t privacy_type) ;
|
||||
void getListOfNearbyChatLobbies(std::vector<PublicChatLobbyRecord>& public_lobbies) ;
|
||||
|
||||
protected:
|
||||
/************* from p3Config *******************/
|
||||
@ -200,6 +203,14 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
||||
void receiveAvatarJpegData(RsChatAvatarItem *ci) ; // new method
|
||||
void receiveStateString(const std::string& id,const std::string& s) ;
|
||||
|
||||
/// methods for handling various Chat items.
|
||||
bool handleRecvChatMsgItem(RsChatMsgItem *item) ; // returns false if the item should be deleted.
|
||||
void handleRecvChatStatusItem(RsChatStatusItem *item) ;
|
||||
void handleRecvChatAvatarItem(RsChatAvatarItem *item) ;
|
||||
void handleRecvChatLobbyListRequest(RsChatLobbyListRequestItem *item) ;
|
||||
void handleRecvChatLobbyList(RsChatLobbyListItem *item) ;
|
||||
void handleRecvChatLobbyEventItem(RsChatLobbyEventItem *item) ;
|
||||
|
||||
/// Sends a request for an avatar to the peer of given id
|
||||
void sendAvatarRequest(const std::string& peer_id) ;
|
||||
|
||||
@ -207,20 +218,29 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
||||
void sendCustomStateRequest(const std::string& peer_id);
|
||||
|
||||
/// called as a proxy to sendItem(). Possibly splits item into multiple items of size lower than the maximum item size.
|
||||
void checkSizeAndSendMessage(RsChatMsgItem *item) ;
|
||||
void checkSizeAndSendMessage(RsChatLobbyMsgItem *item) ;
|
||||
void checkSizeAndSendMessage_deprecated(RsChatMsgItem *item) ; // keep for compatibility for a few weeks.
|
||||
|
||||
/// Called when a RsChatMsgItem is received. The item may be collapsed with any waiting partial chat item from the same peer.
|
||||
bool checkAndRebuildPartialMessage(RsChatMsgItem*) ;
|
||||
bool locked_checkAndRebuildPartialMessage(RsChatLobbyMsgItem*) ;
|
||||
bool locked_checkAndRebuildPartialMessage_deprecated(RsChatMsgItem*) ;
|
||||
|
||||
/// receive and handle chat lobby item
|
||||
bool recvLobbyChat(RsChatLobbyMsgItem*,const std::string& src_peer_id) ;
|
||||
bool sendLobbyChat(const std::wstring&, const ChatLobbyId&,bool management = false) ;
|
||||
bool sendLobbyChat(const std::wstring&, const ChatLobbyId&) ;
|
||||
void handleRecvLobbyInvite(RsChatLobbyInviteItem*) ;
|
||||
void checkAndRedirectMsgToLobby(RsChatMsgItem*) ;
|
||||
void handleConnectionChallenge(RsChatLobbyConnectChallengeItem *item) ;
|
||||
void sendConnectionChallenge(ChatLobbyId id) ;
|
||||
void handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem*) ;
|
||||
void cleanLobbyCaches() ;
|
||||
bool bounceLobbyObject(RsChatLobbyBouncingObject *obj, const std::string& peer_id) ;
|
||||
|
||||
void sendLobbyStatusItem(const ChatLobbyId&, int type, const std::string& status_string) ;
|
||||
void sendLobbyStatusPeerLiving(const ChatLobbyId& lobby_id) ;
|
||||
void sendLobbyStatusNewPeer(const ChatLobbyId& lobby_id) ;
|
||||
|
||||
void locked_initLobbyBouncableObject(const ChatLobbyId& id,RsChatLobbyBouncingObject&) ;
|
||||
|
||||
static std::string makeVirtualPeerId(ChatLobbyId) ;
|
||||
static uint64_t makeConnexionChallengeCode(ChatLobbyId lobby_id,ChatLobbyMsgId msg_id) ;
|
||||
@ -238,8 +258,8 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
||||
|
||||
AvatarInfo *_own_avatar ;
|
||||
std::map<std::string,AvatarInfo *> _avatars ;
|
||||
std::map<std::string,RsChatMsgItem *> _pendingPartialMessages ;
|
||||
|
||||
std::map<std::string,RsChatMsgItem *> _pendingPartialMessages ;
|
||||
std::map<ChatLobbyMsgId,std::vector<RsChatLobbyMsgItem*> > _pendingPartialLobbyMessages ; // should be used for all chat msgs after version updgrade
|
||||
std::string _custom_status_string ;
|
||||
std::map<std::string,StateStringInfo> _state_strings ;
|
||||
|
||||
@ -249,10 +269,12 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
||||
std::map<ChatLobbyMsgId,time_t> msg_cache ;
|
||||
std::string virtual_peer_id ;
|
||||
int connexion_challenge_count ;
|
||||
time_t last_connexion_challenge_time ;
|
||||
};
|
||||
|
||||
std::map<ChatLobbyId,ChatLobbyEntry> _chat_lobbys ;
|
||||
std::map<ChatLobbyId,ChatLobbyInvite> _lobby_invites_queue ;
|
||||
std::map<ChatLobbyId,PublicChatLobbyRecord> _public_lobbies ;
|
||||
std::map<std::string,ChatLobbyId> _lobby_ids ;
|
||||
std::string _default_nick_name ;
|
||||
time_t last_lobby_challenge_time ; // prevents bruteforce attack
|
||||
|
@ -42,6 +42,27 @@ RsSerialType* init_item(RsChatMsgItem& cmi)
|
||||
|
||||
return new RsChatSerialiser();
|
||||
}
|
||||
RsSerialType* init_item(RsChatLobbyListRequestItem& cmi)
|
||||
{
|
||||
return new RsChatSerialiser();
|
||||
}
|
||||
RsSerialType* init_item(RsChatLobbyListItem& cmi)
|
||||
{
|
||||
int n = rand()%20 ;
|
||||
|
||||
cmi.lobby_ids.resize(n) ;
|
||||
cmi.lobby_names.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]);
|
||||
cmi.lobby_counts[i] = RSRandom::random_u32() ;
|
||||
}
|
||||
|
||||
return new RsChatSerialiser();
|
||||
}
|
||||
RsSerialType* init_item(RsChatLobbyMsgItem& cmi)
|
||||
{
|
||||
RsSerialType *serial = init_item( *dynamic_cast<RsChatMsgItem*>(&cmi)) ;
|
||||
@ -49,9 +70,18 @@ RsSerialType* init_item(RsChatLobbyMsgItem& cmi)
|
||||
cmi.msg_id = RSRandom::random_u64() ;
|
||||
cmi.lobby_id = RSRandom::random_u64() ;
|
||||
cmi.nick = "My nickname" ;
|
||||
cmi.subpacket_id = rand()%256 ;
|
||||
cmi.parent_msg_id = RSRandom::random_u64() ;
|
||||
|
||||
return serial ;
|
||||
}
|
||||
RsSerialType *init_item(RsChatLobbyEventItem& cmi)
|
||||
{
|
||||
cmi.event_type = rand()%256 ;
|
||||
randString(20, cmi.string1);
|
||||
|
||||
return new RsChatSerialiser();
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsChatLobbyInviteItem& cmi)
|
||||
{
|
||||
@ -151,6 +181,24 @@ RsSerialType* init_item(RsMsgParentId& ms)
|
||||
return new RsMsgSerialiser();
|
||||
}
|
||||
|
||||
bool operator ==(const RsChatLobbyListItem& cmiLeft,const RsChatLobbyListItem& cmiRight)
|
||||
{
|
||||
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_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_counts[i] != cmiRight.lobby_counts[i]) return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
bool operator ==(const RsChatLobbyListRequestItem& cmiLeft,const RsChatLobbyListRequestItem& cmiRight)
|
||||
{
|
||||
return true ;
|
||||
}
|
||||
bool operator ==(const RsChatMsgItem& cmiLeft,const RsChatMsgItem& cmiRight)
|
||||
{
|
||||
|
||||
@ -192,7 +240,16 @@ bool operator ==(const RsChatLobbyMsgItem& csiLeft, const RsChatLobbyMsgItem& cs
|
||||
|
||||
return true;
|
||||
}
|
||||
bool operator ==(const RsChatLobbyEventItem& csiLeft, const RsChatLobbyEventItem& csiRight)
|
||||
{
|
||||
if(csiLeft.lobby_id != csiRight.lobby_id) return false ;
|
||||
if(csiLeft.msg_id != csiRight.msg_id) return false ;
|
||||
if(csiLeft.nick != csiRight.nick) return false ;
|
||||
if(csiLeft.event_type != csiRight.event_type) return false ;
|
||||
if(csiLeft.string1 != csiRight.string1) return false ;
|
||||
|
||||
return true;
|
||||
}
|
||||
bool operator ==(const RsChatLobbyInviteItem& csiLeft, const RsChatLobbyInviteItem& csiRight)
|
||||
{
|
||||
if(csiLeft.lobby_id != csiRight.lobby_id) return false ;
|
||||
@ -279,6 +336,9 @@ int main()
|
||||
test_RsItem<RsChatMsgItem >(); REPORT("Serialise/Deserialise RsChatMsgItem");
|
||||
test_RsItem<RsChatLobbyMsgItem >(); REPORT("Serialise/Deserialise RsChatLobbyMsgItem");
|
||||
test_RsItem<RsChatLobbyInviteItem >(); REPORT("Serialise/Deserialise RsChatLobbyInviteItem");
|
||||
test_RsItem<RsChatLobbyEventItem >(); REPORT("Serialise/Deserialise RsChatLobbyEventItem");
|
||||
test_RsItem<RsChatLobbyListRequestItem >(); REPORT("Serialise/Deserialise RsChatLobbyListRequestItem");
|
||||
test_RsItem<RsChatLobbyListItem >(); REPORT("Serialise/Deserialise RsChatLobbyListItem");
|
||||
test_RsItem<RsChatStatusItem >(); REPORT("Serialise/Deserialise RsChatStatusItem");
|
||||
test_RsItem<RsChatAvatarItem >(); REPORT("Serialise/Deserialise RsChatAvatarItem");
|
||||
test_RsItem<RsMsgItem >(); REPORT("Serialise/Deserialise RsMsgItem");
|
||||
|
@ -38,6 +38,7 @@
|
||||
|
||||
#include "channels/CreateChannel.h"
|
||||
#include "chat/PopupChatDialog.h"
|
||||
#include "chat/ChatLobbyDialog.h"
|
||||
#include "common/Emoticons.h"
|
||||
#include "common/vmessagebox.h"
|
||||
#include "connect/ConfCertDialog.h"
|
||||
@ -297,6 +298,16 @@ void FriendsDialog::updateStatusTyping()
|
||||
}
|
||||
}
|
||||
|
||||
void FriendsDialog::displayChatLobbyEvent(qulonglong lobby_id,int event_type,const QString& nickname,const QString& str)
|
||||
{
|
||||
std::cerr << "Received displayChatLobbyEvent()!" << std::endl;
|
||||
|
||||
std::string vpid ;
|
||||
if(rsMsgs->getVirtualPeerId(lobby_id,vpid))
|
||||
if( ChatLobbyDialog *cld = dynamic_cast<ChatLobbyDialog*>(PopupChatDialog::getExistingInstance(vpid)))
|
||||
cld->displayLobbyEvent(event_type,nickname,str) ;
|
||||
}
|
||||
|
||||
// Called by libretroshare through notifyQt to display the peer's status
|
||||
//
|
||||
void FriendsDialog::updateStatusString(const QString& peer_id, const QString& status_string)
|
||||
@ -317,7 +328,7 @@ void FriendsDialog::readChatLobbyInvites()
|
||||
rsMsgs->getPendingChatLobbyInvites(invites) ;
|
||||
|
||||
for(std::list<ChatLobbyInvite>::const_iterator it(invites.begin());it!=invites.end();++it)
|
||||
if(QMessageBox::Ok == QMessageBox::question(NULL,tr("Invitation to chat lobby"),QString::fromStdString((*it).peer_id)+QString(" invites you to chat lobby named ")+QString::fromUtf8((*it).lobby_name.c_str()),QMessageBox::Ok,QMessageBox::Ignore))
|
||||
if(QMessageBox::Ok == QMessageBox::question(NULL,tr("Invitation to chat lobby"),QString::fromUtf8(rsPeers->getPeerName((*it).peer_id).c_str())+QString(" invites you to chat lobby named ")+QString::fromUtf8((*it).lobby_name.c_str()),QMessageBox::Ok,QMessageBox::Ignore))
|
||||
{
|
||||
std::cerr << "Accepting invite to lobby " << (*it).lobby_name << std::endl;
|
||||
|
||||
|
@ -56,6 +56,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 resetStatusBar() ;
|
||||
void readChatLobbyInvites() ;
|
||||
|
||||
|
@ -68,6 +68,11 @@ ChatLobbyDialog::~ChatLobbyDialog()
|
||||
{
|
||||
// announce leaving of lobby
|
||||
|
||||
// check that the lobby still exists.
|
||||
ChatLobbyId lid ;
|
||||
if(!rsMsgs->isLobbyId(getPeerId(),lid))
|
||||
return ;
|
||||
|
||||
if(QMessageBox::Yes == QMessageBox::question(NULL,tr("Unsubscribe to lobby?"),tr("Do you want to unsubscribe to this chat lobby?"),QMessageBox::Yes | QMessageBox::No))
|
||||
rsMsgs->unsubscribeChatLobby(lobby_id) ;
|
||||
}
|
||||
@ -77,11 +82,6 @@ void ChatLobbyDialog::setNickName(const QString& nick)
|
||||
rsMsgs->setNickNameForChatLobby(lobby_id,nick.toUtf8().constData()) ;
|
||||
}
|
||||
|
||||
void ChatLobbyDialog::updateStatus(const QString &peer_id, int status)
|
||||
{
|
||||
// For now. We need something more efficient to tell when the lobby is disconnected.
|
||||
}
|
||||
|
||||
void ChatLobbyDialog::addIncomingChatMsg(const ChatInfo& info)
|
||||
{
|
||||
QDateTime sendTime = QDateTime::fromTime_t(info.sendTime);
|
||||
@ -118,3 +118,25 @@ void ChatLobbyDialog::updateFriendsList()
|
||||
friendsListWidget->addItem(QString::fromUtf8((*it2).c_str())) ;
|
||||
}
|
||||
|
||||
void ChatLobbyDialog::displayLobbyEvent(int event_type,const QString& nickname,const QString& str)
|
||||
{
|
||||
switch(event_type)
|
||||
{
|
||||
case RS_CHAT_LOBBY_EVENT_PEER_LEFT: addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), str + tr(" has left the lobby."), TYPE_NORMAL);
|
||||
break ;
|
||||
case RS_CHAT_LOBBY_EVENT_PEER_JOINED:
|
||||
addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), str + tr(" joined the lobby."), TYPE_NORMAL);
|
||||
break ;
|
||||
case RS_CHAT_LOBBY_EVENT_PEER_STATUS:
|
||||
updateStatusString(nickname,str) ;
|
||||
break ;
|
||||
default:
|
||||
std::cerr << "ChatLobbyDialog::displayLobbyEvent() Unhandled lobby event type " << event_type << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
QString ChatLobbyDialog::makeStatusString(const QString& peer_id, const QString& status_string) const
|
||||
{
|
||||
return QString::fromUtf8(peer_id.toStdString().c_str()) + " " + tr(status_string.toAscii());
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,9 @@ class ChatLobbyDialog: public PopupChatDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
void displayLobbyEvent(int event_type,const QString& nickname,const QString& str) ;
|
||||
|
||||
protected:
|
||||
/** Default constructor */
|
||||
ChatLobbyDialog(const std::string& id,const ChatLobbyId& lid, const QString &name, QWidget *parent = 0, Qt::WFlags flags = 0);
|
||||
@ -55,8 +58,8 @@ class ChatLobbyDialog: public PopupChatDialog
|
||||
|
||||
// The following methods are differentfrom those of the parent:
|
||||
//
|
||||
virtual void updateStatus(const QString &peer_id, int status) ; // needs grouped status. Not yet implemented.
|
||||
virtual void addIncomingChatMsg(const ChatInfo& info) ; //
|
||||
virtual QString makeStatusString(const QString& peer_id,const QString& status_string) const ;
|
||||
|
||||
protected slots:
|
||||
void setNickName(const QString&) ;
|
||||
|
@ -101,7 +101,10 @@ void CreateLobbyDialog::createLobby()
|
||||
std::string lobby_name = ui->lobbyName_LE->text().toUtf8().constData() ;
|
||||
|
||||
// add to group
|
||||
ChatLobbyId id = rsMsgs->createChatLobby(lobby_name, mShareList);
|
||||
|
||||
int lobby_privacy_type = (ui->security_CB->currentIndex() == 0)?RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC:RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE ;
|
||||
|
||||
ChatLobbyId id = rsMsgs->createChatLobby(lobby_name, mShareList, lobby_privacy_type);
|
||||
|
||||
std::cerr << "gui: Created chat lobby " << std::hex << id << std::endl ;
|
||||
|
||||
|
@ -133,6 +133,16 @@ p, li { white-space: pre-wrap; }
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Security policy:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
@ -143,6 +153,20 @@ p, li { white-space: pre-wrap; }
|
||||
<item>
|
||||
<widget class="QLineEdit" name="nickName_LE"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="security_CB">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Public (Visible by friends)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Private (Works on invitation only)</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -473,11 +473,15 @@ void PopupChatDialog::updateStatusTyping()
|
||||
}
|
||||
}
|
||||
|
||||
QString PopupChatDialog::makeStatusString(const QString& peer_id,const QString& status_string) const
|
||||
{
|
||||
return QString::fromUtf8(rsPeers->getPeerName(peer_id.toStdString()).c_str()) + " " + tr(status_string.toAscii());
|
||||
}
|
||||
// Called by libretroshare through notifyQt to display the peer's status
|
||||
//
|
||||
void PopupChatDialog::updateStatusString(const QString& peer_id, const QString& status_string)
|
||||
{
|
||||
QString status = QString::fromUtf8(rsPeers->getPeerName(peer_id.toStdString()).c_str()) + " " + tr(status_string.toAscii());
|
||||
QString status = makeStatusString(peer_id,status_string) ;
|
||||
ui.statusLabel->setText(status); // displays info for 5 secs.
|
||||
ui.typingpixmapLabel->setPixmap(QPixmap(":images/typing.png") );
|
||||
|
||||
|
@ -76,7 +76,11 @@ protected:
|
||||
|
||||
void insertChatMsgs();
|
||||
void addChatMsg(bool incoming, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &message, enumChatType chatType);
|
||||
virtual void addIncomingChatMsg(const ChatInfo& info) ; // derived in ChatLobbyDialog.
|
||||
|
||||
// derived in ChatLobbyDialog.
|
||||
//
|
||||
virtual void addIncomingChatMsg(const ChatInfo& info) ;
|
||||
virtual QString makeStatusString(const QString& peer_id,const QString& status_string) const ;
|
||||
|
||||
private slots:
|
||||
void pasteLink() ;
|
||||
|
@ -228,6 +228,14 @@ void NotifyQt::notifyCustomState(const std::string& peer_id, const std::string&
|
||||
emit peerHasNewCustomStateString(QString::fromStdString(peer_id), QString::fromUtf8(status_string.c_str())) ;
|
||||
}
|
||||
|
||||
void NotifyQt::notifyChatLobbyEvent(uint64_t lobby_id,uint32_t event_type,const std::string& nickname,const std::string& str)
|
||||
{
|
||||
#ifdef NOTIFY_DEBUG
|
||||
std::cerr << "notifyQt: Received chat lobby event message: lobby #" << std::hex << lobby_id << std::dec << ", event=" << event_type << ", str=\"" << str << "\"" << std::endl ;
|
||||
#endif
|
||||
emit chatLobbyEvent(lobby_id,event_type,QString::fromUtf8(nickname.c_str()),QString::fromUtf8(str.c_str())) ;
|
||||
}
|
||||
|
||||
void NotifyQt::notifyChatStatus(const std::string& peer_id,const std::string& status_string,bool is_private)
|
||||
{
|
||||
#ifdef NOTIFY_DEBUG
|
||||
|
@ -41,6 +41,7 @@ class NotifyQt: public QObject, public NotifyBase
|
||||
virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& found_files);
|
||||
virtual void notifyPeerHasNewAvatar(std::string peer_id) ;
|
||||
virtual void notifyOwnAvatarChanged() ;
|
||||
virtual void notifyChatLobbyEvent(uint64_t /* lobby id */,uint32_t /* event type */,const std::string& /*nickname*/,const std::string& /* any string */) ;
|
||||
virtual void notifyOwnStatusMessageChanged() ;
|
||||
virtual void notifyDiskFull(uint32_t loc,uint32_t size_in_mb) ;
|
||||
/* peer has changed the state */
|
||||
@ -67,6 +68,7 @@ class NotifyQt: public QObject, public NotifyBase
|
||||
void filesPostModChanged(bool) const ;
|
||||
void transfersChanged() const ;
|
||||
void friendsChanged() const ;
|
||||
void chatLobbyEvent(qulonglong,int,const QString&,const QString&) ;
|
||||
void neighboursChanged() const ;
|
||||
void messagesChanged() const ;
|
||||
void messagesTagsChanged() 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(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);
|
||||
QObject::connect(notify,SIGNAL(downloadCompleteCountChanged(int)) ,w ,SLOT(updateTransfers(int) ));
|
||||
|
Loading…
Reference in New Issue
Block a user