diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/Messenger.c | 28 | ||||
-rw-r--r-- | core/Messenger.h | 10 |
2 files changed, 38 insertions, 0 deletions
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 | |||
245 | return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1 + sizeof(theid)); | 245 | return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1 + sizeof(theid)); |
246 | } | 246 | } |
247 | 247 | ||
248 | /* send an action to an online friend | ||
249 | return 1 if packet was successfully put into the send queue | ||
250 | return 0 if it was not */ | ||
251 | int m_sendaction(int friendnumber, uint8_t *action, uint32_t length) | ||
252 | { | ||
253 | if (friendnumber < 0 || friendnumber >= numfriends) | ||
254 | return 0; | ||
255 | if (length >= MAX_DATA_SIZE || friendlist[friendnumber].status != FRIEND_ONLINE) | ||
256 | return 0; | ||
257 | uint8_t temp[MAX_DATA_SIZE]; | ||
258 | temp[0] = PACKET_ID_ACTION; | ||
259 | memcpy(temp + 1, action, length); | ||
260 | return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1); | ||
261 | } | ||
262 | |||
248 | /* send a name packet to friendnumber | 263 | /* send a name packet to friendnumber |
249 | length is the length with the NULL terminator*/ | 264 | length is the length with the NULL terminator*/ |
250 | static int m_sendname(int friendnumber, uint8_t * name, uint16_t length) | 265 | 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)) | |||
445 | friend_message_isset = 1; | 460 | friend_message_isset = 1; |
446 | } | 461 | } |
447 | 462 | ||
463 | static void (*friend_action)(int, uint8_t *, uint16_t); | ||
464 | static uint8_t friend_action_isset = 0; | ||
465 | void m_callback_action(void (*function)(int, uint8_t *, uint16_t)) | ||
466 | { | ||
467 | friend_action = function; | ||
468 | friend_action_isset = 1; | ||
469 | } | ||
470 | |||
448 | static void (*friend_namechange)(int, uint8_t *, uint16_t); | 471 | static void (*friend_namechange)(int, uint8_t *, uint16_t); |
449 | static uint8_t friend_namechange_isset = 0; | 472 | static uint8_t friend_namechange_isset = 0; |
450 | void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t)) | 473 | void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t)) |
@@ -589,6 +612,11 @@ static void doFriends(void) | |||
589 | (*friend_message)(i, temp + 5, len - 5); | 612 | (*friend_message)(i, temp + 5, len - 5); |
590 | break; | 613 | break; |
591 | } | 614 | } |
615 | case PACKET_ID_ACTION: { | ||
616 | if (friend_action_isset) | ||
617 | (*friend_action)(i, temp + 1, len - 1); | ||
618 | break; | ||
619 | } | ||
592 | case PACKET_ID_RECEIPT: { | 620 | case PACKET_ID_RECEIPT: { |
593 | uint32_t msgid; | 621 | uint32_t msgid; |
594 | if (len < 1 + sizeof(msgid)) | 622 | 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" { | |||
43 | #define PACKET_ID_USERSTATUS 50 | 43 | #define PACKET_ID_USERSTATUS 50 |
44 | #define PACKET_ID_RECEIPT 65 | 44 | #define PACKET_ID_RECEIPT 65 |
45 | #define PACKET_ID_MESSAGE 64 | 45 | #define PACKET_ID_MESSAGE 64 |
46 | #define PACKET_ID_ACTION 63 | ||
46 | 47 | ||
47 | /* status definitions */ | 48 | /* status definitions */ |
48 | #define FRIEND_ONLINE 4 | 49 | #define FRIEND_ONLINE 4 |
@@ -122,6 +123,11 @@ int m_friendstatus(int friendnumber); | |||
122 | uint32_t m_sendmessage(int friendnumber, uint8_t *message, uint32_t length); | 123 | uint32_t m_sendmessage(int friendnumber, uint8_t *message, uint32_t length); |
123 | uint32_t m_sendmessage_withid(int friendnumber, uint32_t theid, uint8_t *message, uint32_t length); | 124 | uint32_t m_sendmessage_withid(int friendnumber, uint32_t theid, uint8_t *message, uint32_t length); |
124 | 125 | ||
126 | /* send an action to an online friend | ||
127 | returns 1 if packet was successfully put into the send queue | ||
128 | return 0 if it was not */ | ||
129 | int m_sendaction(int friendnumber, uint8_t *action, uint32_t length); | ||
130 | |||
125 | /* Set our nickname | 131 | /* Set our nickname |
126 | name must be a string of maximum MAX_NAME_LENGTH length. | 132 | name must be a string of maximum MAX_NAME_LENGTH length. |
127 | length must be at least 1 byte | 133 | length must be at least 1 byte |
@@ -178,6 +184,10 @@ void m_callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t)); | |||
178 | function format is: function(int friendnumber, uint8_t * message, uint32_t length) */ | 184 | function format is: function(int friendnumber, uint8_t * message, uint32_t length) */ |
179 | void m_callback_friendmessage(void (*function)(int, uint8_t *, uint16_t)); | 185 | void m_callback_friendmessage(void (*function)(int, uint8_t *, uint16_t)); |
180 | 186 | ||
187 | /* set the function that will be executed when an action from a friend is received. | ||
188 | function format is: function(int friendnumber, uint8_t * action, uint32_t length) */ | ||
189 | void m_callback_action(void (*function)(int, uint8_t *, uint16_t)); | ||
190 | |||
181 | /* set the callback for name changes | 191 | /* set the callback for name changes |
182 | function(int friendnumber, uint8_t *newname, uint16_t length) | 192 | function(int friendnumber, uint8_t *newname, uint16_t length) |
183 | you are not responsible for freeing newname */ | 193 | you are not responsible for freeing newname */ |