mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Functions to get name of peer in group chat added.
Group message callback modified.
This commit is contained in:
parent
0b7479e758
commit
dd12d464de
|
@ -588,10 +588,12 @@ void print_invite(Tox *m, int friendnumber, uint8_t *group_public_key, void *use
|
|||
new_lines(msg);
|
||||
}
|
||||
|
||||
void print_groupmessage(Tox *m, int groupnumber, uint8_t *message, uint16_t length, void *userdata)
|
||||
void print_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message, uint16_t length, void *userdata)
|
||||
{
|
||||
char msg[256 + length];
|
||||
sprintf(msg, "[g] %u: %s", groupnumber, message);
|
||||
uint8_t name[TOX_MAX_NAME_LENGTH];
|
||||
tox_group_peername(m, groupnumber, peernumber, name);
|
||||
sprintf(msg, "[g] %u: <%s>: %s", groupnumber, name, message);
|
||||
new_lines(msg);
|
||||
}
|
||||
|
||||
|
|
|
@ -686,9 +686,9 @@ void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int, u
|
|||
|
||||
/* Set the callback for group messages.
|
||||
*
|
||||
* Function(Messenger *m, int groupnumber, uint8_t * message, uint16_t length, void *userdata)
|
||||
* Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
|
||||
*/
|
||||
void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *),
|
||||
void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, int, uint8_t *, uint16_t, void *),
|
||||
void *userdata)
|
||||
{
|
||||
m->group_message = function;
|
||||
|
@ -705,7 +705,7 @@ static void group_message_function(Group_Chat *chat, int peer_number, uint8_t *m
|
|||
}
|
||||
|
||||
if (m->group_message)
|
||||
(*m->group_message)(m, i, message, length, m->group_invite_userdata);
|
||||
(*m->group_message)(m, i, peer_number, message, length, m->group_invite_userdata);
|
||||
}
|
||||
|
||||
/* Creates a new groupchat and puts it in the chats array.
|
||||
|
@ -786,6 +786,24 @@ int del_groupchat(Messenger *m, int groupnumber)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Copy the name of peernumber who is in groupnumber to name.
|
||||
* name must be at least MAX_NICK_BYTES long.
|
||||
*
|
||||
* return length of name if success
|
||||
* return -1 if failure
|
||||
*/
|
||||
int m_group_peername(Messenger *m, int groupnumber, int peernumber, uint8_t *name)
|
||||
{
|
||||
if ((unsigned int)groupnumber >= m->numchats)
|
||||
return -1;
|
||||
|
||||
if (m->chats == NULL)
|
||||
return -1;
|
||||
|
||||
if (m->chats[groupnumber] == NULL)
|
||||
return -1;
|
||||
return group_peername(m->chats[groupnumber], peernumber, name);
|
||||
}
|
||||
/* return 1 if that friend was invited to the group
|
||||
* return 0 if the friend was not or error.
|
||||
*/
|
||||
|
|
|
@ -159,7 +159,7 @@ typedef struct Messenger {
|
|||
void *friend_connectionstatuschange_userdata;
|
||||
void (*group_invite)(struct Messenger *m, int, uint8_t *, void *);
|
||||
void *group_invite_userdata;
|
||||
void (*group_message)(struct Messenger *m, int, uint8_t *, uint16_t, void *);
|
||||
void (*group_message)(struct Messenger *m, int, int, uint8_t *, uint16_t, void *);
|
||||
void *group_message_userdata;
|
||||
|
||||
} Messenger;
|
||||
|
@ -382,9 +382,9 @@ void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int, u
|
|||
|
||||
/* Set the callback for group messages.
|
||||
*
|
||||
* Function(Messenger *m, int groupnumber, uint8_t * message, uint16_t length, void *userdata)
|
||||
* Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
|
||||
*/
|
||||
void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *),
|
||||
void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, int, uint8_t *, uint16_t, void *),
|
||||
void *userdata);
|
||||
|
||||
/* Creates a new groupchat and puts it in the chats array.
|
||||
|
@ -401,6 +401,14 @@ int add_groupchat(Messenger *m);
|
|||
*/
|
||||
int del_groupchat(Messenger *m, int groupnumber);
|
||||
|
||||
/* Copy the name of peernumber who is in groupnumber to name.
|
||||
* name must be at least MAX_NICK_BYTES long.
|
||||
*
|
||||
* return length of name if success
|
||||
* return -1 if failure
|
||||
*/
|
||||
int m_group_peername(Messenger *m, int groupnumber, int peernumber, uint8_t *name);
|
||||
|
||||
/* invite friendnumber to groupnumber
|
||||
* return 0 on success
|
||||
* return -1 on failure
|
||||
|
|
|
@ -278,6 +278,26 @@ static int delpeer(Group_Chat *chat, uint8_t *client_id)
|
|||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Copy the name of peernum to name.
|
||||
* name must be at least MAX_NICK_BYTES long.
|
||||
*
|
||||
* return length of name if success
|
||||
* return -1 if failure
|
||||
*/
|
||||
int group_peername(Group_Chat *chat, int peernum, uint8_t *name)
|
||||
{
|
||||
if ((uint32_t)peernum >= chat->numpeers)
|
||||
return -1;
|
||||
if (chat->group[peernum].nick_len == 0) {
|
||||
memcpy(name, "NSA Agent", 10); /* Kindly remind the user that someone with no name might be a NSA agent.*/
|
||||
return 10;
|
||||
}
|
||||
memcpy(name, chat->group[peernum].nick, chat->group[peernum].nick_len);
|
||||
return chat->group[peernum].nick_len;
|
||||
}
|
||||
|
||||
|
||||
/* min time between pings sent to one peer in seconds */
|
||||
#define PING_TIMEOUT 5
|
||||
static int send_getnodes(Group_Chat *chat, IP_Port ip_port, int peernum)
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MAX_NICK_BYTES 128
|
||||
|
||||
typedef struct {
|
||||
uint8_t client_id[crypto_box_PUBLICKEYBYTES];
|
||||
uint64_t pingid;
|
||||
|
@ -39,6 +41,9 @@ typedef struct {
|
|||
uint64_t last_recv;
|
||||
uint64_t last_recv_msgping;
|
||||
uint32_t last_message_number;
|
||||
|
||||
uint8_t nick[MAX_NICK_BYTES];
|
||||
uint16_t nick_len;
|
||||
} Group_Peer;
|
||||
|
||||
typedef struct {
|
||||
|
@ -65,6 +70,14 @@ typedef struct Group_Chat {
|
|||
|
||||
} Group_Chat;
|
||||
|
||||
/* Copy the name of peernum to name.
|
||||
* name must be at least MAX_NICK_BYTES long.
|
||||
*
|
||||
* return length of name if success
|
||||
* return -1 if failure
|
||||
*/
|
||||
int group_peername(Group_Chat *chat, int peernum, uint8_t *name);
|
||||
|
||||
/*
|
||||
* Set callback function for chat messages.
|
||||
*
|
||||
|
|
|
@ -379,9 +379,9 @@ void tox_callback_group_invite(void *tox, void (*function)(Messenger *tox, int,
|
|||
}
|
||||
/* Set the callback for group messages.
|
||||
*
|
||||
* Function(Tox *tox, int groupnumber, uint8_t * message, uint16_t length, void *userdata)
|
||||
* Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
|
||||
*/
|
||||
void tox_callback_group_message(void *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *),
|
||||
void tox_callback_group_message(void *tox, void (*function)(Messenger *tox, int, int, uint8_t *, uint16_t, void *),
|
||||
void *userdata)
|
||||
{
|
||||
Messenger *m = tox;
|
||||
|
@ -407,6 +407,18 @@ int tox_del_groupchat(void *tox, int groupnumber)
|
|||
Messenger *m = tox;
|
||||
return del_groupchat(m, groupnumber);
|
||||
}
|
||||
|
||||
/* Copy the name of peernumber who is in groupnumber to name.
|
||||
* name must be at least MAX_NICK_BYTES long.
|
||||
*
|
||||
* return length of name if success
|
||||
* return -1 if failure
|
||||
*/
|
||||
int tox_group_peername(void *tox, int groupnumber, int peernumber, uint8_t *name)
|
||||
{
|
||||
Messenger *m = tox;
|
||||
return m_group_peername(m, groupnumber, peernumber, name);
|
||||
}
|
||||
/* invite friendnumber to groupnumber
|
||||
* return 0 on success
|
||||
* return -1 on failure
|
||||
|
|
|
@ -357,9 +357,9 @@ void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int, uint8_t
|
|||
|
||||
/* Set the callback for group messages.
|
||||
*
|
||||
* Function(Tox *tox, int groupnumber, uint8_t * message, uint16_t length, void *userdata)
|
||||
* Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
|
||||
*/
|
||||
void tox_callback_group_message(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *),
|
||||
void tox_callback_group_message(Tox *tox, void (*function)(Tox *tox, int, int, uint8_t *, uint16_t, void *),
|
||||
void *userdata);
|
||||
|
||||
/* Creates a new groupchat and puts it in the chats array.
|
||||
|
@ -376,6 +376,14 @@ int tox_add_groupchat(Tox *tox);
|
|||
*/
|
||||
int tox_del_groupchat(Tox *tox, int groupnumber);
|
||||
|
||||
/* Copy the name of peernumber who is in groupnumber to name.
|
||||
* name must be at least TOX_MAX_NAME_LENGTH long.
|
||||
*
|
||||
* return length of name if success
|
||||
* return -1 if failure
|
||||
*/
|
||||
int tox_group_peername(Tox *tox, int groupnumber, int peernumber, uint8_t *name);
|
||||
|
||||
/* invite friendnumber to groupnumber
|
||||
* return 0 on success
|
||||
* return -1 on failure
|
||||
|
|
Loading…
Reference in New Issue
Block a user