summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-10-02 17:33:54 -0400
committerirungentoo <irungentoo@gmail.com>2014-10-02 17:33:54 -0400
commitdf212234382b3f7f4695311cccc2f27d2bb4d805 (patch)
tree31adc5ee21e0708ceb5126b5fe58e074bf61ea99
parent92f804d0f5545a405b5d0816510cbf8058f7f605 (diff)
People in groups can now be added/removed from friends list without issues.
-rw-r--r--toxcore/Messenger.c55
-rw-r--r--toxcore/Messenger.h2
2 files changed, 53 insertions, 4 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index d99b0027..db5a3141 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -165,6 +165,23 @@ void getaddress(const Messenger *m, uint8_t *address)
165 memcpy(address + crypto_box_PUBLICKEYBYTES + sizeof(nospam), &checksum, sizeof(checksum)); 165 memcpy(address + crypto_box_PUBLICKEYBYTES + sizeof(nospam), &checksum, sizeof(checksum));
166} 166}
167 167
168static int send_online_packet(Messenger *m, int32_t friendnumber)
169{
170 if (friend_not_valid(m, friendnumber))
171 return 0;
172
173 uint8_t packet = PACKET_ID_ONLINE;
174 return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
175 m->friendlist[friendnumber].friendcon_id), &packet, sizeof(packet), 0) != -1;
176}
177
178static int send_offine_packet(Messenger *m, int friendcon_id)
179{
180 uint8_t packet = PACKET_ID_OFFLINE;
181 return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), &packet,
182 sizeof(packet), 0) != -1;
183}
184
168static int handle_status(void *object, int i, uint8_t status); 185static int handle_status(void *object, int i, uint8_t status);
169static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len); 186static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len);
170static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length); 187static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length);
@@ -261,10 +278,13 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u
261 friend_connection_callbacks(m->fr_c, friendcon_id, MESSENGER_CALLBACK_INDEX, &handle_status, &handle_packet, 278 friend_connection_callbacks(m->fr_c, friendcon_id, MESSENGER_CALLBACK_INDEX, &handle_status, &handle_packet,
262 &handle_custom_lossy_packet, m, i); 279 &handle_custom_lossy_packet, m, i);
263 280
264
265 if (m->numfriends == i) 281 if (m->numfriends == i)
266 ++m->numfriends; 282 ++m->numfriends;
267 283
284 if (friend_con_connected(m->fr_c, friendcon_id) == FRIENDCONN_STATUS_CONNECTED) {
285 send_online_packet(m, i);
286 }
287
268 return i; 288 return i;
269 } 289 }
270 } 290 }
@@ -318,6 +338,10 @@ int32_t m_addfriend_norequest(Messenger *m, const uint8_t *client_id)
318 if (m->numfriends == i) 338 if (m->numfriends == i)
319 ++m->numfriends; 339 ++m->numfriends;
320 340
341 if (friend_con_connected(m->fr_c, friendcon_id) == FRIENDCONN_STATUS_CONNECTED) {
342 send_online_packet(m, i);
343 }
344
321 return i; 345 return i;
322 } 346 }
323 } 347 }
@@ -343,6 +367,11 @@ int m_delfriend(Messenger *m, int32_t friendnumber)
343 remove_request_received(&(m->fr), m->friendlist[friendnumber].client_id); 367 remove_request_received(&(m->fr), m->friendlist[friendnumber].client_id);
344 friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, 0, 0, 0, 0, 0); 368 friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, 0, 0, 0, 0, 0);
345 kill_friend_connection(m->fr_c, m->friendlist[friendnumber].friendcon_id); 369 kill_friend_connection(m->fr_c, m->friendlist[friendnumber].friendcon_id);
370
371 if (friend_con_connected(m->fr_c, m->friendlist[friendnumber].friendcon_id) == FRIENDCONN_STATUS_CONNECTED) {
372 send_offine_packet(m, m->friendlist[friendnumber].friendcon_id);
373 }
374
346 memset(&(m->friendlist[friendnumber]), 0, sizeof(Friend)); 375 memset(&(m->friendlist[friendnumber]), 0, sizeof(Friend));
347 uint32_t i; 376 uint32_t i;
348 377
@@ -1654,7 +1683,7 @@ static int handle_status(void *object, int i, uint8_t status)
1654 Messenger *m = object; 1683 Messenger *m = object;
1655 1684
1656 if (status) { /* Went online. */ 1685 if (status) { /* Went online. */
1657 set_friend_status(m, i, FRIEND_ONLINE); 1686 send_online_packet(m, i);
1658 m->friendlist[i].name_sent = 0; 1687 m->friendlist[i].name_sent = 0;
1659 m->friendlist[i].userstatus_sent = 0; 1688 m->friendlist[i].userstatus_sent = 0;
1660 m->friendlist[i].statusmessage_sent = 0; 1689 m->friendlist[i].statusmessage_sent = 0;
@@ -1955,10 +1984,28 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
1955 uint8_t *data = temp + 1; 1984 uint8_t *data = temp + 1;
1956 uint32_t data_length = len - 1; 1985 uint32_t data_length = len - 1;
1957 1986
1958 if (m->friendlist[i].status != FRIEND_ONLINE) 1987 if (m->friendlist[i].status != FRIEND_ONLINE) {
1959 return -1; 1988 if (packet_id == PACKET_ID_ONLINE && len == 1) {
1989 set_friend_status(m, i, FRIEND_ONLINE);
1990 send_online_packet(m, i);
1991 } else if (packet_id == PACKET_ID_NICKNAME || packet_id == PACKET_ID_STATUSMESSAGE
1992 || packet_id == PACKET_ID_USERSTATUS) {
1993 /* Some backward compatibility, TODO: remove. */
1994 set_friend_status(m, i, FRIEND_ONLINE);
1995 send_online_packet(m, i);
1996 } else {
1997 return -1;
1998 }
1999 }
1960 2000
1961 switch (packet_id) { 2001 switch (packet_id) {
2002 case PACKET_ID_OFFLINE: {
2003 if (data_length != 0)
2004 break;
2005
2006 set_friend_status(m, i, FRIEND_CONFIRMED);
2007 }
2008
1962 case PACKET_ID_NICKNAME: { 2009 case PACKET_ID_NICKNAME: {
1963 if (data_length > MAX_NAME_LENGTH || data_length == 0) 2010 if (data_length > MAX_NAME_LENGTH || data_length == 0)
1964 break; 2011 break;
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 6b7b5000..372c9785 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -41,6 +41,8 @@
41 41
42/* NOTE: Packet ids below 17 must never be used. */ 42/* NOTE: Packet ids below 17 must never be used. */
43#define PACKET_ID_SHARE_RELAYS 17 43#define PACKET_ID_SHARE_RELAYS 17
44#define PACKET_ID_ONLINE 24
45#define PACKET_ID_OFFLINE 25
44#define PACKET_ID_NICKNAME 48 46#define PACKET_ID_NICKNAME 48
45#define PACKET_ID_STATUSMESSAGE 49 47#define PACKET_ID_STATUSMESSAGE 49
46#define PACKET_ID_USERSTATUS 50 48#define PACKET_ID_USERSTATUS 50