summaryrefslogtreecommitdiff
path: root/core/Messenger.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-08 12:40:15 -0700
committerirungentoo <irungentoo@gmail.com>2013-08-08 12:40:15 -0700
commit5024bab9309b75994663b506a6b7aff2130d611d (patch)
tree8f01fd35da9cbbd583cad65e709f4ab7a80e7334 /core/Messenger.c
parent4d09e907e00657b693fb8db03594b967e6c1405c (diff)
parent982c86df1f0556a767ef16cfd27cf4552d487225 (diff)
Merge pull request #400 from JFreegman/master
Added actions/alternative type of messages
Diffstat (limited to 'core/Messenger.c')
-rw-r--r--core/Messenger.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/core/Messenger.c b/core/Messenger.c
index 90dfe48d..af4fd797 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -247,6 +247,21 @@ uint32_t m_sendmessage_withid(int friendnumber, uint32_t theid, uint8_t *message
247 return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1 + sizeof(theid)); 247 return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1 + sizeof(theid));
248} 248}
249 249
250/* send an action to an online friend
251 return 1 if packet was successfully put into the send queue
252 return 0 if it was not */
253int m_sendaction(int friendnumber, uint8_t *action, uint32_t length)
254{
255 if (friendnumber < 0 || friendnumber >= numfriends)
256 return 0;
257 if (length >= MAX_DATA_SIZE || friendlist[friendnumber].status != FRIEND_ONLINE)
258 return 0;
259 uint8_t temp[MAX_DATA_SIZE];
260 temp[0] = PACKET_ID_ACTION;
261 memcpy(temp + 1, action, length);
262 return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1);
263}
264
250/* send a name packet to friendnumber 265/* send a name packet to friendnumber
251 length is the length with the NULL terminator*/ 266 length is the length with the NULL terminator*/
252static int m_sendname(int friendnumber, uint8_t * name, uint16_t length) 267static int m_sendname(int friendnumber, uint8_t * name, uint16_t length)
@@ -447,6 +462,14 @@ void m_callback_friendmessage(void (*function)(int, uint8_t *, uint16_t))
447 friend_message_isset = 1; 462 friend_message_isset = 1;
448} 463}
449 464
465static void (*friend_action)(int, uint8_t *, uint16_t);
466static uint8_t friend_action_isset = 0;
467void m_callback_action(void (*function)(int, uint8_t *, uint16_t))
468{
469 friend_action = function;
470 friend_action_isset = 1;
471}
472
450static void (*friend_namechange)(int, uint8_t *, uint16_t); 473static void (*friend_namechange)(int, uint8_t *, uint16_t);
451static uint8_t friend_namechange_isset = 0; 474static uint8_t friend_namechange_isset = 0;
452void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t)) 475void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t))
@@ -606,6 +629,11 @@ static void doFriends(void)
606 (*friend_message)(i, temp + 5, len - 5); 629 (*friend_message)(i, temp + 5, len - 5);
607 break; 630 break;
608 } 631 }
632 case PACKET_ID_ACTION: {
633 if (friend_action_isset)
634 (*friend_action)(i, temp + 1, len - 1);
635 break;
636 }
609 case PACKET_ID_RECEIPT: { 637 case PACKET_ID_RECEIPT: {
610 uint32_t msgid; 638 uint32_t msgid;
611 if (len < 1 + sizeof(msgid)) 639 if (len < 1 + sizeof(msgid))