diff options
author | Coren[m] <Break@Ocean> | 2013-09-13 09:06:52 +0200 |
---|---|---|
committer | Coren[m] <Break@Ocean> | 2013-09-13 09:06:52 +0200 |
commit | e67a11dd04edce395c2d0ac403241ed08a875737 (patch) | |
tree | 4a0c069cfe501c6395ee25a4050fd6068acd2f29 | |
parent | ec3734fc5d0f0d81a5220cf16ad6ef8eb5f06c7c (diff) | |
parent | f8b979a92a8c316c49bed28e158a468a2f74346c (diff) |
Merge remote-tracking branch 'upstream/master' into Integration
-rw-r--r-- | other/DHT_bootstrap.c | 8 | ||||
-rw-r--r-- | testing/nTox.c | 45 | ||||
-rw-r--r-- | toxcore/LAN_discovery.h | 2 | ||||
-rw-r--r-- | toxcore/Messenger.c | 124 | ||||
-rw-r--r-- | toxcore/Messenger.h | 56 | ||||
-rw-r--r-- | toxcore/group_chats.h | 1 | ||||
-rw-r--r-- | toxcore/tox.c | 75 | ||||
-rw-r--r-- | toxcore/tox.h | 53 |
8 files changed, 353 insertions, 11 deletions
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index e6e8d59f..246ae818 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #include "../toxcore/DHT.h" | 33 | #include "../toxcore/DHT.h" |
34 | #include "../toxcore/LAN_discovery.h" | ||
34 | #include "../toxcore/friend_requests.h" | 35 | #include "../toxcore/friend_requests.h" |
35 | #include "../testing/misc_tools.c" | 36 | #include "../testing/misc_tools.c" |
36 | 37 | ||
@@ -140,6 +141,9 @@ int main(int argc, char *argv[]) | |||
140 | 141 | ||
141 | int is_waiting_for_dht_connection = 1; | 142 | int is_waiting_for_dht_connection = 1; |
142 | 143 | ||
144 | uint64_t last_LANdiscovery = 0; | ||
145 | LANdiscovery_init(dht); | ||
146 | |||
143 | while (1) { | 147 | while (1) { |
144 | if (is_waiting_for_dht_connection && DHT_isconnected(dht)) { | 148 | if (is_waiting_for_dht_connection && DHT_isconnected(dht)) { |
145 | printf("Connected to other bootstrap server successfully.\n"); | 149 | printf("Connected to other bootstrap server successfully.\n"); |
@@ -147,6 +151,10 @@ int main(int argc, char *argv[]) | |||
147 | } | 151 | } |
148 | 152 | ||
149 | do_DHT(dht); | 153 | do_DHT(dht); |
154 | if (last_LANdiscovery + (is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL) < unix_time()) { | ||
155 | send_LANdiscovery(htons(PORT), dht->c); | ||
156 | last_LANdiscovery = unix_time(); | ||
157 | } | ||
150 | 158 | ||
151 | networking_poll(dht->c->lossless_udp->net); | 159 | networking_poll(dht->c->lossless_udp->net); |
152 | 160 | ||
diff --git a/testing/nTox.c b/testing/nTox.c index 1e83f507..70dc5c77 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -348,13 +348,34 @@ void line_eval(Tox *m, char *line) | |||
348 | do_refresh(); | 348 | do_refresh(); |
349 | } else if (inpt_command == 'h') { //help | 349 | } else if (inpt_command == 'h') { //help |
350 | new_lines(help); | 350 | new_lines(help); |
351 | } else if (inpt_command == 'i') { //info | 351 | } else if (inpt_command == 'x') { //info |
352 | char idstring[200]; | 352 | char idstring[200]; |
353 | get_id(m, idstring); | 353 | get_id(m, idstring); |
354 | new_lines(idstring); | 354 | new_lines(idstring); |
355 | } | 355 | } else if (inpt_command == 'g') { //create new group chat |
356 | char msg[256]; | ||
357 | sprintf(msg, "[g] Created new group chat with number: %u", tox_add_groupchat(m)); | ||
358 | new_lines(msg); | ||
359 | } else if (inpt_command == 'i') { //invite friendnum to groupnum | ||
360 | char *posi[1]; | ||
361 | int friendnumber = strtoul(line + prompt_offset, posi, 0); | ||
362 | int groupnumber = strtoul(*posi + 1, NULL, 0); | ||
363 | char msg[256]; | ||
364 | sprintf(msg, "[g] Invited friend number %u to group number %u, returned: %u (0 means success)", friendnumber, | ||
365 | groupnumber, tox_invite_friend(m, friendnumber, groupnumber)); | ||
366 | new_lines(msg); | ||
367 | } else if (inpt_command == 'z') { //send message to groupnum | ||
368 | char *posi[1]; | ||
369 | int groupnumber = strtoul(line + prompt_offset, posi, 0); | ||
370 | |||
371 | if (**posi != 0) { | ||
372 | char msg[256 + 1024]; | ||
373 | sprintf(msg, "[g] sent message: %s to group num: %u returned: %u (0 means success)", *posi + 1, groupnumber, | ||
374 | tox_group_message_send(m, groupnumber, (uint8_t *)*posi + 1, strlen(*posi + 1) + 1)); | ||
375 | new_lines(msg); | ||
376 | } | ||
356 | 377 | ||
357 | else if (inpt_command == 'q') { //exit | 378 | } else if (inpt_command == 'q') { //exit |
358 | endwin(); | 379 | endwin(); |
359 | exit(EXIT_SUCCESS); | 380 | exit(EXIT_SUCCESS); |
360 | } else { | 381 | } else { |
@@ -535,6 +556,22 @@ void print_help(void) | |||
535 | puts("\t-f\t-\tSpecify a keyfile to read (or write to) from."); | 556 | puts("\t-f\t-\tSpecify a keyfile to read (or write to) from."); |
536 | } | 557 | } |
537 | 558 | ||
559 | void print_invite(Tox *m, int friendnumber, uint8_t *group_public_key, void *userdata) | ||
560 | { | ||
561 | char msg[256]; | ||
562 | sprintf(msg, "[i] recieved group chat invite from: %u, auto accepting and joining. group number: %u", friendnumber, | ||
563 | tox_join_groupchat(m, friendnumber, group_public_key)); | ||
564 | new_lines(msg); | ||
565 | } | ||
566 | |||
567 | void print_groupmessage(Tox *m, int groupnumber, uint8_t *message, uint16_t length, void *userdata) | ||
568 | { | ||
569 | char msg[256 + length]; | ||
570 | sprintf(msg, "[g] %u: %s", groupnumber, message); | ||
571 | new_lines(msg); | ||
572 | } | ||
573 | |||
574 | |||
538 | int main(int argc, char *argv[]) | 575 | int main(int argc, char *argv[]) |
539 | { | 576 | { |
540 | if (argc < 4) { | 577 | if (argc < 4) { |
@@ -579,6 +616,8 @@ int main(int argc, char *argv[]) | |||
579 | tox_callback_friendmessage(m, print_message, NULL); | 616 | tox_callback_friendmessage(m, print_message, NULL); |
580 | tox_callback_namechange(m, print_nickchange, NULL); | 617 | tox_callback_namechange(m, print_nickchange, NULL); |
581 | tox_callback_statusmessage(m, print_statuschange, NULL); | 618 | tox_callback_statusmessage(m, print_statuschange, NULL); |
619 | tox_callback_group_invite(m, print_invite, NULL); | ||
620 | tox_callback_group_message(m, print_groupmessage, NULL); | ||
582 | 621 | ||
583 | initscr(); | 622 | initscr(); |
584 | noecho(); | 623 | noecho(); |
diff --git a/toxcore/LAN_discovery.h b/toxcore/LAN_discovery.h index a0789956..3e9d9de5 100644 --- a/toxcore/LAN_discovery.h +++ b/toxcore/LAN_discovery.h | |||
@@ -35,7 +35,7 @@ | |||
35 | #include <linux/netdevice.h> | 35 | #include <linux/netdevice.h> |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | /* standard interval in seconds between LAN discovery packet sending. */ | 38 | /* Interval in seconds between LAN discovery packet sending. */ |
39 | #define LAN_DISCOVERY_INTERVAL 60 | 39 | #define LAN_DISCOVERY_INTERVAL 60 |
40 | 40 | ||
41 | /* Send a LAN discovery pcaket to the broadcast address with port port. */ | 41 | /* Send a LAN discovery pcaket to the broadcast address with port port. */ |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index d228fcc2..8d0b149f 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -674,6 +674,40 @@ static int group_num(Messenger *m, uint8_t *group_public_key) | |||
674 | return -1; | 674 | return -1; |
675 | } | 675 | } |
676 | 676 | ||
677 | /* Set the callback for group invites. | ||
678 | * | ||
679 | * Function(Messenger *m, int friendnumber, uint8_t *group_public_key, void *userdata) | ||
680 | */ | ||
681 | void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, void *), void *userdata) | ||
682 | { | ||
683 | m->group_invite = function; | ||
684 | m->group_invite_userdata = userdata; | ||
685 | } | ||
686 | |||
687 | /* Set the callback for group messages. | ||
688 | * | ||
689 | * Function(Messenger *m, int groupnumber, uint8_t * message, uint16_t length, void *userdata) | ||
690 | */ | ||
691 | void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), | ||
692 | void *userdata) | ||
693 | { | ||
694 | m->group_message = function; | ||
695 | m->group_message_userdata = userdata; | ||
696 | } | ||
697 | static void group_message_function(Group_Chat *chat, int peer_number, uint8_t *message, uint16_t length, void *userdata) | ||
698 | { | ||
699 | Messenger *m = userdata; | ||
700 | uint32_t i; | ||
701 | |||
702 | for (i = 0; i < m->numchats; ++i) { //TODO: remove this | ||
703 | if (m->chats[i] == chat) | ||
704 | break; | ||
705 | } | ||
706 | |||
707 | if (m->group_message) | ||
708 | (*m->group_message)(m, i, message, length, m->group_invite_userdata); | ||
709 | } | ||
710 | |||
677 | /* Creates a new groupchat and puts it in the chats array. | 711 | /* Creates a new groupchat and puts it in the chats array. |
678 | * | 712 | * |
679 | * return group number on success. | 713 | * return group number on success. |
@@ -690,6 +724,7 @@ int add_groupchat(Messenger *m) | |||
690 | if (newchat == NULL) | 724 | if (newchat == NULL) |
691 | return -1; | 725 | return -1; |
692 | 726 | ||
727 | callback_groupmessage(newchat, &group_message_function, m); | ||
693 | m->chats[i] = newchat; | 728 | m->chats[i] = newchat; |
694 | return i; | 729 | return i; |
695 | } | 730 | } |
@@ -706,6 +741,8 @@ int add_groupchat(Messenger *m) | |||
706 | if (temp[m->numchats] == NULL) | 741 | if (temp[m->numchats] == NULL) |
707 | return -1; | 742 | return -1; |
708 | 743 | ||
744 | m->chats = temp; | ||
745 | callback_groupmessage(temp[m->numchats], &group_message_function, m); | ||
709 | ++m->numchats; | 746 | ++m->numchats; |
710 | return (m->numchats - 1); | 747 | return (m->numchats - 1); |
711 | } | 748 | } |
@@ -715,7 +752,7 @@ int add_groupchat(Messenger *m) | |||
715 | * return 0 on success. | 752 | * return 0 on success. |
716 | * return -1 if failure. | 753 | * return -1 if failure. |
717 | */ | 754 | */ |
718 | static int del_groupchat(Messenger *m, int groupnumber) | 755 | int del_groupchat(Messenger *m, int groupnumber) |
719 | { | 756 | { |
720 | if ((unsigned int)groupnumber >= m->numchats) | 757 | if ((unsigned int)groupnumber >= m->numchats) |
721 | return -1; | 758 | return -1; |
@@ -749,9 +786,42 @@ static int del_groupchat(Messenger *m, int groupnumber) | |||
749 | return 0; | 786 | return 0; |
750 | } | 787 | } |
751 | 788 | ||
789 | /* return 1 if that friend was invited to the group | ||
790 | * return 0 if the friend was not or error. | ||
791 | */ | ||
792 | static uint8_t group_invited(Messenger *m, int friendnumber, int groupnumber) | ||
793 | { | ||
794 | //TODO: this function; | ||
795 | return 1; | ||
796 | } | ||
797 | |||
798 | /* invite friendnumber to groupnumber | ||
799 | * return 0 on success | ||
800 | * return -1 on failure | ||
801 | */ | ||
802 | int invite_friend(Messenger *m, int friendnumber, int groupnumber) | ||
803 | { | ||
804 | if (friend_not_valid(m, friendnumber) || (unsigned int)groupnumber >= m->numchats) | ||
805 | return -1; | ||
806 | |||
807 | if (m->chats == NULL) | ||
808 | return -1; | ||
809 | |||
810 | if (m->friendlist[friendnumber].status == NOFRIEND || m->chats[groupnumber] == NULL) | ||
811 | return -1; | ||
812 | |||
813 | //TODO: store invited friends. | ||
814 | if (write_cryptpacket_id(m, friendnumber, PACKET_ID_INVITE_GROUPCHAT, m->chats[groupnumber]->self_public_key, | ||
815 | crypto_box_PUBLICKEYBYTES) == 0) | ||
816 | return -1; | ||
817 | |||
818 | return 0; | ||
819 | } | ||
820 | |||
821 | |||
752 | /* Join a group (you need to have been invited first.) | 822 | /* Join a group (you need to have been invited first.) |
753 | * | 823 | * |
754 | * returns 0 on success | 824 | * returns group number on success |
755 | * returns -1 on failure. | 825 | * returns -1 on failure. |
756 | */ | 826 | */ |
757 | int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_key) | 827 | int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_key) |
@@ -771,12 +841,34 @@ int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_ | |||
771 | if (write_cryptpacket_id(m, friendnumber, PACKET_ID_JOIN_GROUPCHAT, data, sizeof(data))) { | 841 | if (write_cryptpacket_id(m, friendnumber, PACKET_ID_JOIN_GROUPCHAT, data, sizeof(data))) { |
772 | chat_bootstrap_nonlazy(m->chats[groupnum], get_friend_ipport(m, friendnumber), | 842 | chat_bootstrap_nonlazy(m->chats[groupnum], get_friend_ipport(m, friendnumber), |
773 | friend_group_public_key); //TODO: check if ip returned is zero? | 843 | friend_group_public_key); //TODO: check if ip returned is zero? |
774 | return 0; | 844 | return groupnum; |
775 | } | 845 | } |
776 | 846 | ||
777 | return -1; | 847 | return -1; |
778 | } | 848 | } |
779 | 849 | ||
850 | /* send a group message | ||
851 | * return 0 on success | ||
852 | * return -1 on failure | ||
853 | */ | ||
854 | |||
855 | int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length) | ||
856 | { | ||
857 | if ((unsigned int)groupnumber >= m->numchats) | ||
858 | return -1; | ||
859 | |||
860 | if (m->chats == NULL) | ||
861 | return -1; | ||
862 | |||
863 | if (m->chats[groupnumber] == NULL) | ||
864 | return -1; | ||
865 | |||
866 | if (group_sendmessage(m->chats[groupnumber], message, length) > 0) | ||
867 | return 0; | ||
868 | |||
869 | return -1; | ||
870 | } | ||
871 | |||
780 | static int handle_group(void *object, IP_Port source, uint8_t *packet, uint32_t length) | 872 | static int handle_group(void *object, IP_Port source, uint8_t *packet, uint32_t length) |
781 | { | 873 | { |
782 | Messenger *m = object; | 874 | Messenger *m = object; |
@@ -810,9 +902,6 @@ static void do_allgroupchats(Messenger *m) | |||
810 | 902 | ||
811 | /*********************************/ | 903 | /*********************************/ |
812 | 904 | ||
813 | /* Interval in seconds between LAN discovery packet sending. */ | ||
814 | #define LAN_DISCOVERY_INTERVAL 60 | ||
815 | |||
816 | /* Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds. */ | 905 | /* Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds. */ |
817 | static void LANdiscovery(Messenger *m) | 906 | static void LANdiscovery(Messenger *m) |
818 | { | 907 | { |
@@ -1065,6 +1154,29 @@ void doFriends(Messenger *m) | |||
1065 | 1154 | ||
1066 | break; | 1155 | break; |
1067 | } | 1156 | } |
1157 | |||
1158 | case PACKET_ID_INVITE_GROUPCHAT: { | ||
1159 | if (data_length != crypto_box_PUBLICKEYBYTES) | ||
1160 | break; | ||
1161 | |||
1162 | if (m->group_invite) | ||
1163 | (*m->group_invite)(m, i, data, m->group_invite_userdata); | ||
1164 | } | ||
1165 | |||
1166 | case PACKET_ID_JOIN_GROUPCHAT: { | ||
1167 | if (data_length != crypto_box_PUBLICKEYBYTES * 2) | ||
1168 | break; | ||
1169 | |||
1170 | int groupnum = group_num(m, data); | ||
1171 | |||
1172 | if (groupnum == -1) | ||
1173 | break; | ||
1174 | |||
1175 | if (!group_invited(m, i, groupnum)) | ||
1176 | break; | ||
1177 | |||
1178 | group_newpeer(m->chats[groupnum], data + crypto_box_PUBLICKEYBYTES); | ||
1179 | } | ||
1068 | } | 1180 | } |
1069 | } else { | 1181 | } else { |
1070 | if (is_cryptoconnected(m->net_crypto, | 1182 | if (is_cryptoconnected(m->net_crypto, |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index b7032bbd..bfcc69df 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -157,7 +157,10 @@ typedef struct Messenger { | |||
157 | void *friend_statuschange_userdata; | 157 | void *friend_statuschange_userdata; |
158 | void (*friend_connectionstatuschange)(struct Messenger *m, int, uint8_t, void *); | 158 | void (*friend_connectionstatuschange)(struct Messenger *m, int, uint8_t, void *); |
159 | void *friend_connectionstatuschange_userdata; | 159 | void *friend_connectionstatuschange_userdata; |
160 | 160 | void (*group_invite)(struct Messenger *m, int, uint8_t *, void *); | |
161 | void *group_invite_userdata; | ||
162 | void (*group_message)(struct Messenger *m, int, uint8_t *, uint16_t, void *); | ||
163 | void *group_message_userdata; | ||
161 | 164 | ||
162 | } Messenger; | 165 | } Messenger; |
163 | 166 | ||
@@ -369,6 +372,57 @@ void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, u | |||
369 | */ | 372 | */ |
370 | void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int, uint8_t, void *), void *userdata); | 373 | void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int, uint8_t, void *), void *userdata); |
371 | 374 | ||
375 | /**********GROUP CHATS************/ | ||
376 | |||
377 | /* Set the callback for group invites. | ||
378 | * | ||
379 | * Function(Messenger *m, int friendnumber, uint8_t *group_public_key, void *userdata) | ||
380 | */ | ||
381 | void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, void *), void *userdata); | ||
382 | |||
383 | /* Set the callback for group messages. | ||
384 | * | ||
385 | * Function(Messenger *m, int groupnumber, uint8_t * message, uint16_t length, void *userdata) | ||
386 | */ | ||
387 | void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), | ||
388 | void *userdata); | ||
389 | |||
390 | /* Creates a new groupchat and puts it in the chats array. | ||
391 | * | ||
392 | * return group number on success. | ||
393 | * return -1 on failure. | ||
394 | */ | ||
395 | int add_groupchat(Messenger *m); | ||
396 | |||
397 | /* Delete a groupchat from the chats array. | ||
398 | * | ||
399 | * return 0 on success. | ||
400 | * return -1 if failure. | ||
401 | */ | ||
402 | int del_groupchat(Messenger *m, int groupnumber); | ||
403 | |||
404 | /* invite friendnumber to groupnumber | ||
405 | * return 0 on success | ||
406 | * return -1 on failure | ||
407 | */ | ||
408 | int invite_friend(Messenger *m, int friendnumber, int groupnumber); | ||
409 | |||
410 | /* Join a group (you need to have been invited first.) | ||
411 | * | ||
412 | * returns group number on success | ||
413 | * returns -1 on failure. | ||
414 | */ | ||
415 | int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_key); | ||
416 | |||
417 | /* send a group message | ||
418 | * return 0 on success | ||
419 | * return -1 on failure | ||
420 | */ | ||
421 | |||
422 | int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length); | ||
423 | |||
424 | /*********************************/ | ||
425 | |||
372 | /* Run this at startup. | 426 | /* Run this at startup. |
373 | * return allocated instance of Messenger on success. | 427 | * return allocated instance of Messenger on success. |
374 | * return 0 if there are problems. | 428 | * return 0 if there are problems. |
diff --git a/toxcore/group_chats.h b/toxcore/group_chats.h index 535b46db..78a5488c 100644 --- a/toxcore/group_chats.h +++ b/toxcore/group_chats.h | |||
@@ -77,6 +77,7 @@ void callback_groupmessage(Group_Chat *chat, void (*function)(Group_Chat *chat, | |||
77 | /* | 77 | /* |
78 | * Send a message to the group. | 78 | * Send a message to the group. |
79 | * | 79 | * |
80 | * returns the number of peers it has sent it to. | ||
80 | */ | 81 | */ |
81 | uint32_t group_sendmessage(Group_Chat *chat, uint8_t *message, uint32_t length); | 82 | uint32_t group_sendmessage(Group_Chat *chat, uint8_t *message, uint32_t length); |
82 | 83 | ||
diff --git a/toxcore/tox.c b/toxcore/tox.c index 3eb80d22..68b1e6e9 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -366,6 +366,81 @@ void tox_callback_connectionstatus(void *tox, void (*function)(Messenger *tox, i | |||
366 | m_callback_connectionstatus(m, function, userdata); | 366 | m_callback_connectionstatus(m, function, userdata); |
367 | } | 367 | } |
368 | 368 | ||
369 | /**********GROUP CHAT FUNCTIONS: WARNING WILL BREAK A LOT************/ | ||
370 | |||
371 | /* Set the callback for group invites. | ||
372 | * | ||
373 | * Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata) | ||
374 | */ | ||
375 | void tox_callback_group_invite(void *tox, void (*function)(Messenger *tox, int, uint8_t *, void *), void *userdata) | ||
376 | { | ||
377 | Messenger *m = tox; | ||
378 | m_callback_group_invite(m, function, userdata); | ||
379 | } | ||
380 | /* Set the callback for group messages. | ||
381 | * | ||
382 | * Function(Tox *tox, int groupnumber, uint8_t * message, uint16_t length, void *userdata) | ||
383 | */ | ||
384 | void tox_callback_group_message(void *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), | ||
385 | void *userdata) | ||
386 | { | ||
387 | Messenger *m = tox; | ||
388 | m_callback_group_message(m, function, userdata); | ||
389 | } | ||
390 | /* Creates a new groupchat and puts it in the chats array. | ||
391 | * | ||
392 | * return group number on success. | ||
393 | * return -1 on failure. | ||
394 | */ | ||
395 | int tox_add_groupchat(void *tox) | ||
396 | { | ||
397 | Messenger *m = tox; | ||
398 | return add_groupchat(m); | ||
399 | } | ||
400 | /* Delete a groupchat from the chats array. | ||
401 | * | ||
402 | * return 0 on success. | ||
403 | * return -1 if failure. | ||
404 | */ | ||
405 | int tox_del_groupchat(void *tox, int groupnumber) | ||
406 | { | ||
407 | Messenger *m = tox; | ||
408 | return del_groupchat(m, groupnumber); | ||
409 | } | ||
410 | /* invite friendnumber to groupnumber | ||
411 | * return 0 on success | ||
412 | * return -1 on failure | ||
413 | */ | ||
414 | int tox_invite_friend(void *tox, int friendnumber, int groupnumber) | ||
415 | { | ||
416 | Messenger *m = tox; | ||
417 | return invite_friend(m, friendnumber, groupnumber); | ||
418 | } | ||
419 | /* Join a group (you need to have been invited first.) | ||
420 | * | ||
421 | * returns group number on success | ||
422 | * returns -1 on failure. | ||
423 | */ | ||
424 | int tox_join_groupchat(void *tox, int friendnumber, uint8_t *friend_group_public_key) | ||
425 | { | ||
426 | Messenger *m = tox; | ||
427 | return join_groupchat(m, friendnumber, friend_group_public_key); | ||
428 | } | ||
429 | |||
430 | /* send a group message | ||
431 | * return 0 on success | ||
432 | * return -1 on failure | ||
433 | */ | ||
434 | int tox_group_message_send(void *tox, int groupnumber, uint8_t *message, uint32_t length) | ||
435 | { | ||
436 | Messenger *m = tox; | ||
437 | return group_message_send(m, groupnumber, message, length); | ||
438 | } | ||
439 | |||
440 | |||
441 | |||
442 | /******************END OF GROUP CHAT FUNCTIONS************************/ | ||
443 | |||
369 | /* Use these functions to bootstrap the client. | 444 | /* Use these functions to bootstrap the client. |
370 | * Sends a get nodes request to the given node with ip port and public_key. | 445 | * Sends a get nodes request to the given node with ip port and public_key. |
371 | */ | 446 | */ |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 4c597250..c52a644f 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -342,6 +342,59 @@ void tox_callback_read_receipt(Tox *tox, void (*function)(Tox *tox, int, uint32_ | |||
342 | */ | 342 | */ |
343 | void tox_callback_connectionstatus(Tox *tox, void (*function)(Tox *tox, int, uint8_t, void *), void *userdata); | 343 | void tox_callback_connectionstatus(Tox *tox, void (*function)(Tox *tox, int, uint8_t, void *), void *userdata); |
344 | 344 | ||
345 | /**********GROUP CHAT FUNCTIONS: WARNING WILL BREAK A LOT************/ | ||
346 | |||
347 | /* Set the callback for group invites. | ||
348 | * | ||
349 | * Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata) | ||
350 | */ | ||
351 | void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, void *), void *userdata); | ||
352 | |||
353 | /* Set the callback for group messages. | ||
354 | * | ||
355 | * Function(Tox *tox, int groupnumber, uint8_t * message, uint16_t length, void *userdata) | ||
356 | */ | ||
357 | void tox_callback_group_message(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *), | ||
358 | void *userdata); | ||
359 | |||
360 | /* Creates a new groupchat and puts it in the chats array. | ||
361 | * | ||
362 | * return group number on success. | ||
363 | * return -1 on failure. | ||
364 | */ | ||
365 | int tox_add_groupchat(Tox *tox); | ||
366 | |||
367 | /* Delete a groupchat from the chats array. | ||
368 | * | ||
369 | * return 0 on success. | ||
370 | * return -1 if failure. | ||
371 | */ | ||
372 | int tox_del_groupchat(Tox *tox, int groupnumber); | ||
373 | |||
374 | /* invite friendnumber to groupnumber | ||
375 | * return 0 on success | ||
376 | * return -1 on failure | ||
377 | */ | ||
378 | int tox_invite_friend(Tox *tox, int friendnumber, int groupnumber); | ||
379 | |||
380 | /* Join a group (you need to have been invited first.) | ||
381 | * | ||
382 | * returns group number on success | ||
383 | * returns -1 on failure. | ||
384 | */ | ||
385 | int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_key); | ||
386 | |||
387 | |||
388 | /* send a group message | ||
389 | * return 0 on success | ||
390 | * return -1 on failure | ||
391 | */ | ||
392 | int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length); | ||
393 | |||
394 | |||
395 | |||
396 | /******************END OF GROUP CHAT FUNCTIONS************************/ | ||
397 | |||
345 | /* | 398 | /* |
346 | * Use these two functions to bootstrap the client. | 399 | * Use these two functions to bootstrap the client. |
347 | */ | 400 | */ |