mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge pull request #50 from stal888/master
Move packet IDs to Messenger.h.
This commit is contained in:
commit
dd623d120e
|
@ -223,7 +223,7 @@ int m_sendmessage(int friendnumber, uint8_t * message, uint32_t length)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
uint8_t temp[MAX_DATA_SIZE];
|
uint8_t temp[MAX_DATA_SIZE];
|
||||||
temp[0] = 64;
|
temp[0] = PACKET_ID_MESSAGE;
|
||||||
memcpy(temp + 1, message, length);
|
memcpy(temp + 1, message, length);
|
||||||
return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1);
|
return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1);
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ static int m_sendname(int friendnumber, uint8_t * name)
|
||||||
{
|
{
|
||||||
uint8_t temp[MAX_NAME_LENGTH + 1];
|
uint8_t temp[MAX_NAME_LENGTH + 1];
|
||||||
memcpy(temp + 1, name, MAX_NAME_LENGTH);
|
memcpy(temp + 1, name, MAX_NAME_LENGTH);
|
||||||
temp[0] = 48;
|
temp[0] = PACKET_ID_NICKNAME;
|
||||||
return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, MAX_NAME_LENGTH + 1);
|
return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, MAX_NAME_LENGTH + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,7 +334,7 @@ static int send_userstatus(int friendnumber, uint8_t * status, uint16_t length)
|
||||||
{
|
{
|
||||||
uint8_t *thepacket = malloc(length + 1);
|
uint8_t *thepacket = malloc(length + 1);
|
||||||
memcpy(thepacket + 1, status, length);
|
memcpy(thepacket + 1, status, length);
|
||||||
thepacket[0] = 49;
|
thepacket[0] = PACKET_ID_USERSTATUS;
|
||||||
int written = write_cryptpacket(friendlist[friendnumber].crypt_connection_id, thepacket, length + 1);
|
int written = write_cryptpacket(friendlist[friendnumber].crypt_connection_id, thepacket, length + 1);
|
||||||
free(thepacket);
|
free(thepacket);
|
||||||
return written;
|
return written;
|
||||||
|
@ -456,14 +456,14 @@ static void doFriends()
|
||||||
if(len > 0)
|
if(len > 0)
|
||||||
{
|
{
|
||||||
switch(temp[0]) {
|
switch(temp[0]) {
|
||||||
case 48: {
|
case PACKET_ID_NICKNAME: {
|
||||||
if (len != MAX_NAME_LENGTH + 1) break;
|
if (len != MAX_NAME_LENGTH + 1) break;
|
||||||
friend_namechange(i, temp + 1, MAX_NAME_LENGTH); // todo: use the actual length
|
friend_namechange(i, temp + 1, MAX_NAME_LENGTH); // todo: use the actual length
|
||||||
memcpy(friendlist[i].name, temp + 1, MAX_NAME_LENGTH);
|
memcpy(friendlist[i].name, temp + 1, MAX_NAME_LENGTH);
|
||||||
friendlist[i].name[MAX_NAME_LENGTH - 1] = 0;//make sure the NULL terminator is present.
|
friendlist[i].name[MAX_NAME_LENGTH - 1] = 0;//make sure the NULL terminator is present.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 49: {
|
case PACKET_ID_USERSTATUS: {
|
||||||
uint8_t *status = calloc(MIN(len - 1, MAX_USERSTATUS_LENGTH), 1);
|
uint8_t *status = calloc(MIN(len - 1, MAX_USERSTATUS_LENGTH), 1);
|
||||||
memcpy(status, temp + 1, MIN(len - 1, MAX_USERSTATUS_LENGTH));
|
memcpy(status, temp + 1, MIN(len - 1, MAX_USERSTATUS_LENGTH));
|
||||||
friend_statuschange(i, status, MIN(len - 1, MAX_USERSTATUS_LENGTH));
|
friend_statuschange(i, status, MIN(len - 1, MAX_USERSTATUS_LENGTH));
|
||||||
|
@ -471,7 +471,7 @@ static void doFriends()
|
||||||
free(status);
|
free(status);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 64: {
|
case PACKET_ID_MESSAGE: {
|
||||||
(*friend_message)(i, temp + 1, len - 1);
|
(*friend_message)(i, temp + 1, len - 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,11 @@
|
||||||
|
|
||||||
#define MAX_NAME_LENGTH 128
|
#define MAX_NAME_LENGTH 128
|
||||||
#define MAX_USERSTATUS_LENGTH 128
|
#define MAX_USERSTATUS_LENGTH 128
|
||||||
|
|
||||||
|
#define PACKET_ID_NICKNAME 48
|
||||||
|
#define PACKET_ID_USERSTATUS 49
|
||||||
|
#define PACKET_ID_MESSAGE 64
|
||||||
|
|
||||||
// don't assume MAX_USERSTATUS_LENGTH will stay at 128, it may be increased
|
// don't assume MAX_USERSTATUS_LENGTH will stay at 128, it may be increased
|
||||||
// to an absurdly large number later
|
// to an absurdly large number later
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user