mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Added message ids to action messages
This commit is contained in:
parent
77ec510858
commit
571412f911
|
@ -332,12 +332,36 @@ uint32_t m_sendmessage_withid(Messenger *m, int friendnumber, uint32_t theid, ui
|
||||||
|
|
||||||
/* Send an action to an online friend.
|
/* Send an action to an online friend.
|
||||||
*
|
*
|
||||||
* return 1 if packet was successfully put into the send queue.
|
* return the message id if packet was successfully put into the send queue.
|
||||||
* return 0 if it was not.
|
* return 0 if it was not.
|
||||||
*/
|
*/
|
||||||
int m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t length)
|
uint32_t m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t length)
|
||||||
{
|
{
|
||||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_ACTION, action, length);
|
if (friend_not_valid(m, friendnumber))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
uint32_t msgid = ++m->friendlist[friendnumber].message_id;
|
||||||
|
|
||||||
|
if (msgid == 0)
|
||||||
|
msgid = 1; // Otherwise, false error
|
||||||
|
|
||||||
|
if (m_sendaction_withid(m, friendnumber, msgid, action, length)) {
|
||||||
|
return msgid;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t m_sendaction_withid(Messenger *m, int friendnumber, uint32_t theid, uint8_t *action, uint32_t length)
|
||||||
|
{
|
||||||
|
if (length >= (MAX_DATA_SIZE - sizeof(theid)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
uint8_t temp[MAX_DATA_SIZE];
|
||||||
|
theid = htonl(theid);
|
||||||
|
memcpy(temp, &theid, sizeof(theid));
|
||||||
|
memcpy(temp + sizeof(theid), action, length);
|
||||||
|
return write_cryptpacket_id(m, friendnumber, PACKET_ID_ACTION, temp, length + sizeof(theid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send a name packet to friendnumber.
|
/* Send a name packet to friendnumber.
|
||||||
|
@ -1470,13 +1494,22 @@ void doFriends(Messenger *m)
|
||||||
}
|
}
|
||||||
|
|
||||||
case PACKET_ID_ACTION: {
|
case PACKET_ID_ACTION: {
|
||||||
if (data_length == 0)
|
uint8_t *message_id = data;
|
||||||
|
uint8_t message_id_length = 4;
|
||||||
|
|
||||||
|
if (data_length <= message_id_length)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
data[data_length - 1] = 0;/* Make sure the NULL terminator is present. */
|
uint8_t *action = data + message_id_length;
|
||||||
|
uint16_t action_length = data_length - message_id_length;
|
||||||
|
|
||||||
|
action[action_length - 1] = 0;/* Make sure the NULL terminator is present. */
|
||||||
|
|
||||||
|
if (m->friendlist[i].receives_read_receipts) {
|
||||||
|
write_cryptpacket_id(m, i, PACKET_ID_RECEIPT, message_id, message_id_length);
|
||||||
|
}
|
||||||
if (m->friend_action)
|
if (m->friend_action)
|
||||||
(*m->friend_action)(m, i, data, data_length, m->friend_action_userdata);
|
(*m->friend_action)(m, i, action, action_length, m->friend_action_userdata);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,7 +267,7 @@ int m_friend_exists(Messenger *m, int friendnumber);
|
||||||
* return the message id if packet was successfully put into the send queue.
|
* return the message id if packet was successfully put into the send queue.
|
||||||
* return 0 if it was not.
|
* return 0 if it was not.
|
||||||
*
|
*
|
||||||
* You will want to retain the return value, it will be passed to your read receipt callback
|
* You will want to retain the return value, it will be passed to your read_receipt callback
|
||||||
* if one is received.
|
* if one is received.
|
||||||
* m_sendmessage_withid will send a message with the id of your choosing,
|
* m_sendmessage_withid will send a message with the id of your choosing,
|
||||||
* however we can generate an id for you by calling plain m_sendmessage.
|
* however we can generate an id for you by calling plain m_sendmessage.
|
||||||
|
@ -277,10 +277,16 @@ uint32_t m_sendmessage_withid(Messenger *m, int friendnumber, uint32_t theid, ui
|
||||||
|
|
||||||
/* Send an action to an online friend.
|
/* Send an action to an online friend.
|
||||||
*
|
*
|
||||||
* return 1 if packet was successfully put into the send queue.
|
* return the message id if packet was successfully put into the send queue.
|
||||||
* return 0 if it was not.
|
* return 0 if it was not.
|
||||||
|
*
|
||||||
|
* You will want to retain the return value, it will be passed to your read_receipt callback
|
||||||
|
* if one is received.
|
||||||
|
* m_sendaction_withid will send an action message with the id of your choosing,
|
||||||
|
* however we can generate an id for you by calling plain m_sendaction.
|
||||||
*/
|
*/
|
||||||
int m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t length);
|
uint32_t m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t length);
|
||||||
|
uint32_t m_sendaction_withid(Messenger *m, int friendnumber, uint32_t theid, uint8_t *action, uint32_t length);
|
||||||
|
|
||||||
/* Set the name and name_length of a friend.
|
/* Set the name and name_length of a friend.
|
||||||
* name must be a string of maximum MAX_NAME_LENGTH length.
|
* name must be a string of maximum MAX_NAME_LENGTH length.
|
||||||
|
|
|
@ -132,7 +132,7 @@ int tox_friend_exists(Tox *tox, int friendnumber)
|
||||||
* return the message id if packet was successfully put into the send queue.
|
* return the message id if packet was successfully put into the send queue.
|
||||||
* return 0 if it was not.
|
* return 0 if it was not.
|
||||||
*
|
*
|
||||||
* You will want to retain the return value, it will be passed to your read receipt callback
|
* You will want to retain the return value, it will be passed to your read_receipt callback
|
||||||
* if one is received.
|
* if one is received.
|
||||||
* m_sendmessage_withid will send a message with the id of your choosing,
|
* m_sendmessage_withid will send a message with the id of your choosing,
|
||||||
* however we can generate an id for you by calling plain m_sendmessage.
|
* however we can generate an id for you by calling plain m_sendmessage.
|
||||||
|
@ -150,15 +150,27 @@ uint32_t tox_sendmessage_withid(Tox *tox, int friendnumber, uint32_t theid, uint
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send an action to an online friend.
|
/* Send an action to an online friend.
|
||||||
* return 1 if packet was successfully put into the send queue.
|
*
|
||||||
|
* return the message id if packet was successfully put into the send queue.
|
||||||
* return 0 if it was not.
|
* return 0 if it was not.
|
||||||
|
*
|
||||||
|
* You will want to retain the return value, it will be passed to your read_receipt callback
|
||||||
|
* if one is received.
|
||||||
|
* m_sendaction_withid will send an action message with the id of your choosing,
|
||||||
|
* however we can generate an id for you by calling plain m_sendaction.
|
||||||
*/
|
*/
|
||||||
int tox_sendaction(Tox *tox, int friendnumber, uint8_t *action, uint32_t length)
|
uint32_t tox_sendaction(Tox *tox, int friendnumber, uint8_t *action, uint32_t length)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_sendaction(m, friendnumber, action, length);
|
return m_sendaction(m, friendnumber, action, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t tox_sendaction_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *action, uint32_t length)
|
||||||
|
{
|
||||||
|
Messenger *m = tox;
|
||||||
|
return m_sendaction_withid(m, friendnumber, theid, action, length);
|
||||||
|
}
|
||||||
|
|
||||||
/* Set friendnumber's nickname.
|
/* Set friendnumber's nickname.
|
||||||
* name must be a string of maximum MAX_NAME_LENGTH length.
|
* name must be a string of maximum MAX_NAME_LENGTH length.
|
||||||
* length must be at least 1 byte.
|
* length must be at least 1 byte.
|
||||||
|
|
|
@ -209,7 +209,7 @@ int tox_friend_exists(Tox *tox, int friendnumber);
|
||||||
* return the message id if packet was successfully put into the send queue.
|
* return the message id if packet was successfully put into the send queue.
|
||||||
* return 0 if it was not.
|
* return 0 if it was not.
|
||||||
*
|
*
|
||||||
* You will want to retain the return value, it will be passed to your read receipt callback
|
* You will want to retain the return value, it will be passed to your read_receipt callback
|
||||||
* if one is received.
|
* if one is received.
|
||||||
* m_sendmessage_withid will send a message with the id of your choosing,
|
* m_sendmessage_withid will send a message with the id of your choosing,
|
||||||
* however we can generate an id for you by calling plain m_sendmessage.
|
* however we can generate an id for you by calling plain m_sendmessage.
|
||||||
|
@ -219,10 +219,16 @@ uint32_t tox_sendmessage_withid(Tox *tox, int friendnumber, uint32_t theid, uint
|
||||||
|
|
||||||
/* Send an action to an online friend.
|
/* Send an action to an online friend.
|
||||||
*
|
*
|
||||||
* return 1 if packet was successfully put into the send queue.
|
* return the message id if packet was successfully put into the send queue.
|
||||||
* return 0 if it was not.
|
* return 0 if it was not.
|
||||||
|
*
|
||||||
|
* You will want to retain the return value, it will be passed to your read_receipt callback
|
||||||
|
* if one is received.
|
||||||
|
* m_sendaction_withid will send an action message with the id of your choosing,
|
||||||
|
* however we can generate an id for you by calling plain m_sendaction.
|
||||||
*/
|
*/
|
||||||
int tox_sendaction(Tox *tox, int friendnumber, uint8_t *action, uint32_t length);
|
uint32_t tox_sendaction(Tox *tox, int friendnumber, uint8_t *action, uint32_t length);
|
||||||
|
uint32_t tox_sendaction_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *action, uint32_t length);
|
||||||
|
|
||||||
/* Set friendnumber's nickname.
|
/* Set friendnumber's nickname.
|
||||||
* name must be a string of maximum MAX_NAME_LENGTH length.
|
* name must be a string of maximum MAX_NAME_LENGTH length.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user