mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 13:30:06 +00:00
Try to transmit FF packets in one go, instead of sending the id first.
This commit is contained in:
parent
9e9161083d
commit
3c43dd0193
@ -123,23 +123,25 @@ void CNSocket::sendPacket(void* buf, uint32_t type, size_t size) {
|
|||||||
if (!alive)
|
if (!alive)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int tmpSize = size + sizeof(uint32_t);
|
size_t bodysize = size + sizeof(uint32_t);
|
||||||
uint8_t* tmpBuf = (uint8_t*)xmalloc(tmpSize);
|
uint8_t* fullpkt = (uint8_t*)xmalloc(bodysize+4);
|
||||||
|
uint8_t* body = fullpkt+4;
|
||||||
|
memcpy(fullpkt, (void*)&bodysize, 4);
|
||||||
|
|
||||||
// copy packet type to the front of the buffer & then the actual buffer
|
// copy packet type to the front of the buffer & then the actual buffer
|
||||||
memcpy(tmpBuf, (void*)&type, sizeof(uint32_t));
|
memcpy(body, (void*)&type, sizeof(uint32_t));
|
||||||
memcpy(tmpBuf+sizeof(uint32_t), buf, size);
|
memcpy(body+sizeof(uint32_t), buf, size);
|
||||||
|
|
||||||
// encrypt the packet
|
// encrypt the packet
|
||||||
switch (activeKey) {
|
switch (activeKey) {
|
||||||
case SOCKETKEY_E:
|
case SOCKETKEY_E:
|
||||||
CNSocketEncryption::encryptData((uint8_t*)tmpBuf, (uint8_t*)(&EKey), tmpSize);
|
CNSocketEncryption::encryptData((uint8_t*)body, (uint8_t*)(&EKey), bodysize);
|
||||||
break;
|
break;
|
||||||
case SOCKETKEY_FE:
|
case SOCKETKEY_FE:
|
||||||
CNSocketEncryption::encryptData((uint8_t*)tmpBuf, (uint8_t*)(&FEKey), tmpSize);
|
CNSocketEncryption::encryptData((uint8_t*)body, (uint8_t*)(&FEKey), bodysize);
|
||||||
break;
|
break;
|
||||||
default: {
|
default: {
|
||||||
free(tmpBuf);
|
free(fullpkt);
|
||||||
DEBUGLOG(
|
DEBUGLOG(
|
||||||
std::cout << "[WARN]: UNSET KEYTYPE FOR SOCKET!! ABORTING SEND" << std::endl;
|
std::cout << "[WARN]: UNSET KEYTYPE FOR SOCKET!! ABORTING SEND" << std::endl;
|
||||||
)
|
)
|
||||||
@ -147,15 +149,11 @@ void CNSocket::sendPacket(void* buf, uint32_t type, size_t size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// send packet size
|
|
||||||
if (!sendData((uint8_t*)&tmpSize, sizeof(uint32_t)))
|
|
||||||
kill();
|
|
||||||
|
|
||||||
// send packet data!
|
// send packet data!
|
||||||
if (alive && !sendData(tmpBuf, tmpSize))
|
if (alive && !sendData(fullpkt, bodysize+4))
|
||||||
kill();
|
kill();
|
||||||
|
|
||||||
free(tmpBuf); // free tmp buffer
|
free(fullpkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CNSocket::setActiveKey(ACTIVEKEY key) {
|
void CNSocket::setActiveKey(ACTIVEKEY key) {
|
||||||
|
Loading…
Reference in New Issue
Block a user