diff options
Diffstat (limited to 'toxcore/group_chats.c')
-rw-r--r-- | toxcore/group_chats.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index 6dff52ef..17914038 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c | |||
@@ -251,6 +251,22 @@ static int addpeer(Group_Chat *chat, uint8_t *client_id) | |||
251 | } | 251 | } |
252 | 252 | ||
253 | /* | 253 | /* |
254 | * Set a peer from the group chat to deleted. | ||
255 | * | ||
256 | * return 0 if success | ||
257 | * return -1 if error. | ||
258 | */ | ||
259 | static int del_peer_set(Group_Chat *chat, int peernum) | ||
260 | { | ||
261 | if ((uint32_t)peernum >= chat->numpeers) | ||
262 | return -1; | ||
263 | |||
264 | chat->group[peernum].deleted = 1; | ||
265 | chat->group[peernum].deleted_time = unix_time(); | ||
266 | return 0; | ||
267 | } | ||
268 | |||
269 | /* | ||
254 | * Delete a peer from the group chat. | 270 | * Delete a peer from the group chat. |
255 | * | 271 | * |
256 | * return 0 if success | 272 | * return 0 if success |
@@ -488,6 +504,9 @@ static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len) | |||
488 | if (peernum == -1) | 504 | if (peernum == -1) |
489 | return 1; | 505 | return 1; |
490 | 506 | ||
507 | if (chat->group[peernum].deleted) | ||
508 | return 1; | ||
509 | |||
491 | /* Spam prevention (1 message per peer per second limit.) | 510 | /* Spam prevention (1 message per peer per second limit.) |
492 | 511 | ||
493 | if (chat->group[peernum].last_recv == temp_time) | 512 | if (chat->group[peernum].last_recv == temp_time) |
@@ -531,7 +550,7 @@ static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len) | |||
531 | if (contents_len != 0) | 550 | if (contents_len != 0) |
532 | return 1; | 551 | return 1; |
533 | 552 | ||
534 | delpeer(chat, peernum); | 553 | del_peer_set(chat, peernum); |
535 | break; | 554 | break; |
536 | 555 | ||
537 | case GROUP_CHAT_PEER_NICK: | 556 | case GROUP_CHAT_PEER_NICK: |
@@ -758,6 +777,7 @@ static void ping_group(Group_Chat *chat) | |||
758 | } | 777 | } |
759 | } | 778 | } |
760 | 779 | ||
780 | #define DEL_PEER_DELAY 3 | ||
761 | static void del_dead_peers(Group_Chat *chat) | 781 | static void del_dead_peers(Group_Chat *chat) |
762 | { | 782 | { |
763 | uint32_t i; | 783 | uint32_t i; |
@@ -766,6 +786,11 @@ static void del_dead_peers(Group_Chat *chat) | |||
766 | if (is_timeout(chat->group[i].last_recv_msgping, GROUP_PING_INTERVAL * 4)) { | 786 | if (is_timeout(chat->group[i].last_recv_msgping, GROUP_PING_INTERVAL * 4)) { |
767 | delpeer(chat, i); | 787 | delpeer(chat, i); |
768 | } | 788 | } |
789 | |||
790 | if (chat->group[i].deleted) { | ||
791 | if (is_timeout(chat->group[i].deleted_time, DEL_PEER_DELAY)) | ||
792 | delpeer(chat, i); | ||
793 | } | ||
769 | } | 794 | } |
770 | } | 795 | } |
771 | 796 | ||
@@ -773,7 +798,7 @@ static void del_dead_peers(Group_Chat *chat) | |||
773 | static void send_names_new_peer(Group_Chat *chat) | 798 | static void send_names_new_peer(Group_Chat *chat) |
774 | { | 799 | { |
775 | group_send_nick(chat, chat->nick, chat->nick_len); | 800 | group_send_nick(chat, chat->nick, chat->nick_len); |
776 | chat->last_sent_nick = (unix_time() - NICK_SEND_INTERVAL) + 10; | 801 | chat->last_sent_nick = (unix_time() - NICK_SEND_INTERVAL) + 15; |
777 | } | 802 | } |
778 | static void send_names(Group_Chat *chat) | 803 | static void send_names(Group_Chat *chat) |
779 | { | 804 | { |