mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
added actions/alternate messages
This commit is contained in:
parent
1fb2085c67
commit
8719f46645
|
@ -245,6 +245,21 @@ uint32_t m_sendmessage_withid(int friendnumber, uint32_t theid, uint8_t *message
|
|||
return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1 + sizeof(theid));
|
||||
}
|
||||
|
||||
/* send an action to an online friend
|
||||
return 1 if packet was successfully put into the send queue
|
||||
return 0 if it was not */
|
||||
int m_sendaction(int friendnumber, uint8_t *action, uint32_t length)
|
||||
{
|
||||
if (friendnumber < 0 || friendnumber >= numfriends)
|
||||
return 0;
|
||||
if (length >= MAX_DATA_SIZE || friendlist[friendnumber].status != FRIEND_ONLINE)
|
||||
return 0;
|
||||
uint8_t temp[MAX_DATA_SIZE];
|
||||
temp[0] = PACKET_ID_ACTION;
|
||||
memcpy(temp + 1, action, length);
|
||||
return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1);
|
||||
}
|
||||
|
||||
/* send a name packet to friendnumber
|
||||
length is the length with the NULL terminator*/
|
||||
static int m_sendname(int friendnumber, uint8_t * name, uint16_t length)
|
||||
|
@ -445,6 +460,14 @@ void m_callback_friendmessage(void (*function)(int, uint8_t *, uint16_t))
|
|||
friend_message_isset = 1;
|
||||
}
|
||||
|
||||
static void (*friend_action)(int, uint8_t *, uint16_t);
|
||||
static uint8_t friend_action_isset = 0;
|
||||
void m_callback_action(void (*function)(int, uint8_t *, uint16_t))
|
||||
{
|
||||
friend_action = function;
|
||||
friend_action_isset = 1;
|
||||
}
|
||||
|
||||
static void (*friend_namechange)(int, uint8_t *, uint16_t);
|
||||
static uint8_t friend_namechange_isset = 0;
|
||||
void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t))
|
||||
|
@ -589,6 +612,11 @@ static void doFriends(void)
|
|||
(*friend_message)(i, temp + 5, len - 5);
|
||||
break;
|
||||
}
|
||||
case PACKET_ID_ACTION: {
|
||||
if (friend_action_isset)
|
||||
(*friend_action)(i, temp + 1, len - 1);
|
||||
break;
|
||||
}
|
||||
case PACKET_ID_RECEIPT: {
|
||||
uint32_t msgid;
|
||||
if (len < 1 + sizeof(msgid))
|
||||
|
|
|
@ -43,6 +43,7 @@ extern "C" {
|
|||
#define PACKET_ID_USERSTATUS 50
|
||||
#define PACKET_ID_RECEIPT 65
|
||||
#define PACKET_ID_MESSAGE 64
|
||||
#define PACKET_ID_ACTION 63
|
||||
|
||||
/* status definitions */
|
||||
#define FRIEND_ONLINE 4
|
||||
|
@ -122,6 +123,11 @@ int m_friendstatus(int friendnumber);
|
|||
uint32_t m_sendmessage(int friendnumber, uint8_t *message, uint32_t length);
|
||||
uint32_t m_sendmessage_withid(int friendnumber, uint32_t theid, uint8_t *message, uint32_t length);
|
||||
|
||||
/* send an action to an online friend
|
||||
returns 1 if packet was successfully put into the send queue
|
||||
return 0 if it was not */
|
||||
int m_sendaction(int friendnumber, uint8_t *action, uint32_t length);
|
||||
|
||||
/* Set our nickname
|
||||
name must be a string of maximum MAX_NAME_LENGTH length.
|
||||
length must be at least 1 byte
|
||||
|
@ -178,6 +184,10 @@ void m_callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t));
|
|||
function format is: function(int friendnumber, uint8_t * message, uint32_t length) */
|
||||
void m_callback_friendmessage(void (*function)(int, uint8_t *, uint16_t));
|
||||
|
||||
/* set the function that will be executed when an action from a friend is received.
|
||||
function format is: function(int friendnumber, uint8_t * action, uint32_t length) */
|
||||
void m_callback_action(void (*function)(int, uint8_t *, uint16_t));
|
||||
|
||||
/* set the callback for name changes
|
||||
function(int friendnumber, uint8_t *newname, uint16_t length)
|
||||
you are not responsible for freeing newname */
|
||||
|
|
Loading…
Reference in New Issue
Block a user