diff options
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 55 |
1 files changed, 51 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 | ||
168 | static 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 | |||
178 | static 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 | |||
168 | static int handle_status(void *object, int i, uint8_t status); | 185 | static int handle_status(void *object, int i, uint8_t status); |
169 | static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len); | 186 | static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len); |
170 | static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length); | 187 | static 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; |