From 8719f466456ef6000e25cf2c26644762b404980c Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 8 Aug 2013 15:00:30 -0400 Subject: added actions/alternate messages --- core/Messenger.c | 28 ++++++++++++++++++++++++++++ core/Messenger.h | 10 ++++++++++ 2 files changed, 38 insertions(+) (limited to 'core') diff --git a/core/Messenger.c b/core/Messenger.c index ede8f718..bf87a3e4 100644 --- a/core/Messenger.c +++ b/core/Messenger.c @@ -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)) diff --git a/core/Messenger.h b/core/Messenger.h index 3a9a56df..40d02f46 100644 --- a/core/Messenger.h +++ b/core/Messenger.h @@ -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 */ -- cgit v1.2.3