diff options
Diffstat (limited to 'toxcore/group_chats.h')
-rw-r--r-- | toxcore/group_chats.h | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/toxcore/group_chats.h b/toxcore/group_chats.h new file mode 100644 index 00000000..7af13d8d --- /dev/null +++ b/toxcore/group_chats.h | |||
@@ -0,0 +1,123 @@ | |||
1 | /* group_chats.h | ||
2 | * | ||
3 | * An implementation of massive text only group chats. | ||
4 | * | ||
5 | * | ||
6 | * Copyright (C) 2013 Tox project All Rights Reserved. | ||
7 | * | ||
8 | * This file is part of Tox. | ||
9 | * | ||
10 | * Tox is free software: you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation, either version 3 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * Tox is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | #ifndef GROUP_CHATS_H | ||
26 | #define GROUP_CHATS_H | ||
27 | |||
28 | #include "net_crypto.h" | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" { | ||
32 | #endif | ||
33 | |||
34 | typedef struct { | ||
35 | uint8_t client_id[crypto_box_PUBLICKEYBYTES]; | ||
36 | uint64_t pingid; | ||
37 | uint64_t last_pinged; | ||
38 | |||
39 | uint64_t last_recv; | ||
40 | uint64_t last_recv_msgping; | ||
41 | uint32_t last_message_number; | ||
42 | } Group_Peer; | ||
43 | |||
44 | typedef struct { | ||
45 | uint8_t client_id[crypto_box_PUBLICKEYBYTES]; | ||
46 | IP_Port ip_port; | ||
47 | uint64_t last_recv; | ||
48 | |||
49 | } Group_Close; | ||
50 | |||
51 | #define GROUP_CLOSE_CONNECTIONS 6 | ||
52 | |||
53 | typedef struct Group_Chat { | ||
54 | Networking_Core *net; | ||
55 | uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; | ||
56 | uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; | ||
57 | |||
58 | Group_Peer *group; | ||
59 | Group_Close close[GROUP_CLOSE_CONNECTIONS]; | ||
60 | uint32_t numpeers; | ||
61 | |||
62 | uint32_t message_number; | ||
63 | void (*group_message)(struct Group_Chat *m, int, uint8_t *, uint16_t, void *); | ||
64 | void *group_message_userdata; | ||
65 | |||
66 | } Group_Chat; | ||
67 | |||
68 | /* | ||
69 | * Set callback function for chat messages. | ||
70 | * | ||
71 | * format of function is: function(Group_Chat *chat, peer number, message, message length, userdata) | ||
72 | */ | ||
73 | |||
74 | void callback_groupmessage(Group_Chat *chat, void (*function)(Group_Chat *chat, int, uint8_t *, uint16_t, void *), | ||
75 | void *userdata); | ||
76 | |||
77 | /* | ||
78 | * Send a message to the group. | ||
79 | * | ||
80 | */ | ||
81 | uint32_t group_sendmessage(Group_Chat *chat, uint8_t *message, uint32_t length); | ||
82 | |||
83 | |||
84 | /* | ||
85 | * Tell everyone about a new peer (a person we are inviting for example.) | ||
86 | * | ||
87 | */ | ||
88 | uint32_t group_newpeer(Group_Chat *chat, uint8_t *client_id); | ||
89 | |||
90 | |||
91 | /* Create a new group chat. | ||
92 | * | ||
93 | * Returns a new group chat instance if success. | ||
94 | * | ||
95 | * Returns a NULL pointer if fail. | ||
96 | */ | ||
97 | Group_Chat *new_groupchat(Networking_Core *net); | ||
98 | |||
99 | |||
100 | /* Kill a group chat | ||
101 | * | ||
102 | * Frees the memory and everything. | ||
103 | */ | ||
104 | void kill_groupchat(Group_Chat *chat); | ||
105 | |||
106 | /* | ||
107 | * This is the main loop. | ||
108 | */ | ||
109 | void do_groupchat(Group_Chat *chat); | ||
110 | |||
111 | /* if we receive a group chat packet we call this function so it can be handled. | ||
112 | return 0 if packet is handled correctly. | ||
113 | return 1 if it didn't handle the packet or if the packet was shit. */ | ||
114 | int handle_groupchatpacket(Group_Chat *chat, IP_Port source, uint8_t *packet, uint32_t length); | ||
115 | |||
116 | |||
117 | void chat_bootstrap(Group_Chat *chat, IP_Port ip_port, uint8_t *client_id); | ||
118 | |||
119 | #ifdef __cplusplus | ||
120 | } | ||
121 | #endif | ||
122 | |||
123 | #endif | ||