diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.c | 13 | ||||
-rw-r--r-- | toxcore/friend_requests.c | 10 | ||||
-rw-r--r-- | toxcore/friend_requests.h | 10 | ||||
-rw-r--r-- | toxcore/group_chats.c | 10 |
4 files changed, 41 insertions, 2 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 1a7fc230..5e9758dd 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1454,6 +1454,17 @@ int m_msi_packet(Messenger *m, int friendnumber, uint8_t *data, uint16_t length) | |||
1454 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length); | 1454 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length); |
1455 | } | 1455 | } |
1456 | 1456 | ||
1457 | /* Function to filter out some friend requests*/ | ||
1458 | static int friend_already_added(uint8_t * client_id, void * data) | ||
1459 | { | ||
1460 | Messenger *m = data; | ||
1461 | |||
1462 | if (getfriend_id(m, client_id) == -1) | ||
1463 | return 0; | ||
1464 | |||
1465 | return -1; | ||
1466 | } | ||
1467 | |||
1457 | /* Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds. */ | 1468 | /* Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds. */ |
1458 | static void LANdiscovery(Messenger *m) | 1469 | static void LANdiscovery(Messenger *m) |
1459 | { | 1470 | { |
@@ -1503,6 +1514,8 @@ Messenger *new_messenger(uint8_t ipv6enabled) | |||
1503 | friendreq_init(&(m->fr), m->net_crypto); | 1514 | friendreq_init(&(m->fr), m->net_crypto); |
1504 | LANdiscovery_init(m->dht); | 1515 | LANdiscovery_init(m->dht); |
1505 | set_nospam(&(m->fr), random_int()); | 1516 | set_nospam(&(m->fr), random_int()); |
1517 | set_filter_function(&(m->fr), &friend_already_added, m); | ||
1518 | |||
1506 | networking_registerhandler(m->net, NET_PACKET_GROUP_CHATS, &handle_group, m); | 1519 | networking_registerhandler(m->net, NET_PACKET_GROUP_CHATS, &handle_group, m); |
1507 | 1520 | ||
1508 | return m; | 1521 | return m; |
diff --git a/toxcore/friend_requests.c b/toxcore/friend_requests.c index 67977c23..589bd315 100644 --- a/toxcore/friend_requests.c +++ b/toxcore/friend_requests.c | |||
@@ -96,6 +96,12 @@ void callback_friendrequest(Friend_Requests *fr, void (*function)(uint8_t *, uin | |||
96 | fr->handle_friendrequest_isset = 1; | 96 | fr->handle_friendrequest_isset = 1; |
97 | fr->handle_friendrequest_userdata = userdata; | 97 | fr->handle_friendrequest_userdata = userdata; |
98 | } | 98 | } |
99 | /* Set the function used to check if a friend request should be displayed to the user or not. */ | ||
100 | void set_filter_function(Friend_Requests *fr, int (*function)(uint8_t *, void *), void *userdata) | ||
101 | { | ||
102 | fr->filter_function = function; | ||
103 | fr->filter_function_userdata = userdata; | ||
104 | } | ||
99 | 105 | ||
100 | /* Add to list of received friend requests. */ | 106 | /* Add to list of received friend requests. */ |
101 | static void addto_receivedlist(Friend_Requests *fr, uint8_t *client_id) | 107 | static void addto_receivedlist(Friend_Requests *fr, uint8_t *client_id) |
@@ -141,6 +147,10 @@ static int friendreq_handlepacket(void *object, IP_Port source, uint8_t *source_ | |||
141 | if (memcmp(packet, &fr->nospam, sizeof(fr->nospam)) != 0) | 147 | if (memcmp(packet, &fr->nospam, sizeof(fr->nospam)) != 0) |
142 | return 1; | 148 | return 1; |
143 | 149 | ||
150 | if (fr->filter_function) | ||
151 | if ((*fr->filter_function)(source_pubkey, fr->filter_function_userdata) != 0) | ||
152 | return 1; | ||
153 | |||
144 | addto_receivedlist(fr, source_pubkey); | 154 | addto_receivedlist(fr, source_pubkey); |
145 | (*fr->handle_friendrequest)(source_pubkey, packet + 4, length - 4, fr->handle_friendrequest_userdata); | 155 | (*fr->handle_friendrequest)(source_pubkey, packet + 4, length - 4, fr->handle_friendrequest_userdata); |
146 | return 0; | 156 | return 0; |
diff --git a/toxcore/friend_requests.h b/toxcore/friend_requests.h index b5c46056..c655669d 100644 --- a/toxcore/friend_requests.h +++ b/toxcore/friend_requests.h | |||
@@ -34,6 +34,8 @@ typedef struct { | |||
34 | uint8_t handle_friendrequest_isset; | 34 | uint8_t handle_friendrequest_isset; |
35 | void *handle_friendrequest_userdata; | 35 | void *handle_friendrequest_userdata; |
36 | 36 | ||
37 | int (*filter_function)(uint8_t *, void *); | ||
38 | void *filter_function_userdata; | ||
37 | /* NOTE: The following is just a temporary fix for the multiple friend requests received at the same time problem. | 39 | /* NOTE: The following is just a temporary fix for the multiple friend requests received at the same time problem. |
38 | * TODO: Make this better (This will most likely tie in with the way we will handle spam.) | 40 | * TODO: Make this better (This will most likely tie in with the way we will handle spam.) |
39 | */ | 41 | */ |
@@ -53,11 +55,17 @@ void set_nospam(Friend_Requests *fr, uint32_t num); | |||
53 | uint32_t get_nospam(Friend_Requests *fr); | 55 | uint32_t get_nospam(Friend_Requests *fr); |
54 | 56 | ||
55 | /* Set the function that will be executed when a friend request for us is received. | 57 | /* Set the function that will be executed when a friend request for us is received. |
56 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) | 58 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length, void * userdata) |
57 | */ | 59 | */ |
58 | void callback_friendrequest(Friend_Requests *fr, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), | 60 | void callback_friendrequest(Friend_Requests *fr, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), |
59 | void *userdata); | 61 | void *userdata); |
60 | 62 | ||
63 | /* Set the function used to check if a friend request should be displayed to the user or not. | ||
64 | * Function format is int function(uint8_t * public_key, void * userdata) | ||
65 | * It must return 0 if the request is ok (anything else if it is bad.) | ||
66 | */ | ||
67 | void set_filter_function(Friend_Requests *fr, int (*function)(uint8_t *, void *), void *userdata); | ||
68 | |||
61 | /* Sets up friendreq packet handlers. */ | 69 | /* Sets up friendreq packet handlers. */ |
62 | void friendreq_init(Friend_Requests *fr, Net_Crypto *c); | 70 | void friendreq_init(Friend_Requests *fr, Net_Crypto *c); |
63 | 71 | ||
diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index 1637f181..90e8752b 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c | |||
@@ -235,6 +235,14 @@ static int delpeer(Group_Chat *chat, int peernum) | |||
235 | if ((uint32_t)peernum >= chat->numpeers) | 235 | if ((uint32_t)peernum >= chat->numpeers) |
236 | return -1; | 236 | return -1; |
237 | 237 | ||
238 | uint32_t i; | ||
239 | for (i = 0; i < GROUP_CLOSE_CONNECTIONS; ++i) { /* If peer is in close list, time it out forcefully. */ | ||
240 | if (id_equal(chat->close[i].client_id, chat->group[peernum].client_id)) { | ||
241 | chat->close[i].last_recv = 0; | ||
242 | break; | ||
243 | } | ||
244 | } | ||
245 | |||
238 | Group_Peer *temp; | 246 | Group_Peer *temp; |
239 | --chat->numpeers; | 247 | --chat->numpeers; |
240 | 248 | ||
@@ -725,7 +733,7 @@ static void send_names(Group_Chat *chat) | |||
725 | if (is_timeout(chat->last_sent_nick, 180)) | 733 | if (is_timeout(chat->last_sent_nick, 180)) |
726 | if (group_send_nick(chat, chat->nick, chat->nick_len) > 0) { | 734 | if (group_send_nick(chat, chat->nick, chat->nick_len) > 0) { |
727 | if (!chat->last_sent_nick) | 735 | if (!chat->last_sent_nick) |
728 | chat->last_sent_nick = (unix_time() - NICK_SEND_INTERVAL) + 30; | 736 | chat->last_sent_nick = (unix_time() - NICK_SEND_INTERVAL) + 10; |
729 | else | 737 | else |
730 | chat->last_sent_nick = unix_time(); | 738 | chat->last_sent_nick = unix_time(); |
731 | } | 739 | } |