mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 11:42:55 +02:00
voxel-server packet version handling
This commit is contained in:
parent
5062ae8965
commit
693463ae5b
4 changed files with 15 additions and 12 deletions
|
@ -97,7 +97,7 @@ void NodeList::processNodeData(sockaddr *senderAddress, unsigned char *packetDat
|
||||||
case PACKET_TYPE_PING: {
|
case PACKET_TYPE_PING: {
|
||||||
char pingPacket[dataBytes];
|
char pingPacket[dataBytes];
|
||||||
memcpy(pingPacket, packetData, dataBytes);
|
memcpy(pingPacket, packetData, dataBytes);
|
||||||
pingPacket[0] = PACKET_TYPE_PING_REPLY;
|
populateTypeAndVersion((unsigned char*) pingPacket, PACKET_TYPE_PING_REPLY);
|
||||||
_nodeSocket.send(senderAddress, pingPacket, dataBytes);
|
_nodeSocket.send(senderAddress, pingPacket, dataBytes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,10 @@ const PACKET_TYPE PACKET_TYPE_DOMAIN_LIST_REQUEST = 'L';
|
||||||
const PACKET_TYPE PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY = 'C';
|
const PACKET_TYPE PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY = 'C';
|
||||||
|
|
||||||
typedef char PACKET_VERSION;
|
typedef char PACKET_VERSION;
|
||||||
PACKET_VERSION versionForPacketType(PACKET_TYPE header);
|
|
||||||
int populateTypeAndVersion(unsigned char* destination, PACKET_TYPE header);
|
PACKET_VERSION versionForPacketType(PACKET_TYPE type);
|
||||||
|
|
||||||
|
int populateTypeAndVersion(unsigned char* destination, PACKET_TYPE type);
|
||||||
|
|
||||||
const int MAX_PACKET_HEADER_BYTES = sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION);
|
const int MAX_PACKET_HEADER_BYTES = sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION);
|
||||||
|
|
||||||
|
|
|
@ -535,7 +535,7 @@ void VoxelTree::readCodeColorBufferToTreeRecursion(VoxelNode* node, void* extraD
|
||||||
|
|
||||||
void VoxelTree::processRemoveVoxelBitstream(unsigned char * bitstream, int bufferSizeBytes) {
|
void VoxelTree::processRemoveVoxelBitstream(unsigned char * bitstream, int bufferSizeBytes) {
|
||||||
//unsigned short int itemNumber = (*((unsigned short int*)&bitstream[sizeof(PACKET_HEADER)]));
|
//unsigned short int itemNumber = (*((unsigned short int*)&bitstream[sizeof(PACKET_HEADER)]));
|
||||||
int atByte = sizeof(short int) + sizeof(PACKET_TYPE);
|
int atByte = sizeof(short int) + sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION);
|
||||||
unsigned char* voxelCode = (unsigned char*)&bitstream[atByte];
|
unsigned char* voxelCode = (unsigned char*)&bitstream[atByte];
|
||||||
while (atByte < bufferSizeBytes) {
|
while (atByte < bufferSizeBytes) {
|
||||||
int codeLength = numberOfThreeBitSectionsInCode(voxelCode);
|
int codeLength = numberOfThreeBitSectionsInCode(voxelCode);
|
||||||
|
|
|
@ -636,19 +636,20 @@ int main(int argc, const char * argv[]) {
|
||||||
// check to see if we need to persist our voxel state
|
// check to see if we need to persist our voxel state
|
||||||
persistVoxelsWhenDirty();
|
persistVoxelsWhenDirty();
|
||||||
|
|
||||||
if (nodeList->getNodeSocket()->receive(&nodePublicAddress, packetData, &receivedBytes)) {
|
if (nodeList->getNodeSocket()->receive(&nodePublicAddress, packetData, &receivedBytes) &&
|
||||||
|
versionForPacketType(packetData[0]) == packetData[1]) {
|
||||||
if (packetData[0] == PACKET_TYPE_SET_VOXEL || packetData[0] == PACKET_TYPE_SET_VOXEL_DESTRUCTIVE) {
|
if (packetData[0] == PACKET_TYPE_SET_VOXEL || packetData[0] == PACKET_TYPE_SET_VOXEL_DESTRUCTIVE) {
|
||||||
bool destructive = (packetData[0] == PACKET_TYPE_SET_VOXEL_DESTRUCTIVE);
|
bool destructive = (packetData[0] == PACKET_TYPE_SET_VOXEL_DESTRUCTIVE);
|
||||||
PerformanceWarning warn(::shouldShowAnimationDebug,
|
PerformanceWarning warn(::shouldShowAnimationDebug,
|
||||||
destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL",
|
destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL",
|
||||||
::shouldShowAnimationDebug);
|
::shouldShowAnimationDebug);
|
||||||
unsigned short int itemNumber = (*((unsigned short int*)&packetData[1]));
|
unsigned short int itemNumber = (*((unsigned short int*)&packetData[2]));
|
||||||
if (::shouldShowAnimationDebug) {
|
if (::shouldShowAnimationDebug) {
|
||||||
printf("got %s - command from client receivedBytes=%ld itemNumber=%d\n",
|
printf("got %s - command from client receivedBytes=%ld itemNumber=%d\n",
|
||||||
destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL",
|
destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL",
|
||||||
receivedBytes,itemNumber);
|
receivedBytes,itemNumber);
|
||||||
}
|
}
|
||||||
int atByte = sizeof(PACKET_TYPE) + sizeof(itemNumber);
|
int atByte = sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION) + sizeof(itemNumber);
|
||||||
unsigned char* voxelData = (unsigned char*)&packetData[atByte];
|
unsigned char* voxelData = (unsigned char*)&packetData[atByte];
|
||||||
while (atByte < receivedBytes) {
|
while (atByte < receivedBytes) {
|
||||||
unsigned char octets = (unsigned char)*voxelData;
|
unsigned char octets = (unsigned char)*voxelData;
|
||||||
|
@ -702,7 +703,7 @@ int main(int argc, const char * argv[]) {
|
||||||
|
|
||||||
// the Z command is a special command that allows the sender to send the voxel server high level semantic
|
// the Z command is a special command that allows the sender to send the voxel server high level semantic
|
||||||
// requests, like erase all, or add sphere scene
|
// requests, like erase all, or add sphere scene
|
||||||
char* command = (char*) &packetData[1]; // start of the command
|
char* command = (char*) &packetData[2]; // start of the command
|
||||||
int commandLength = strlen(command); // commands are null terminated strings
|
int commandLength = strlen(command); // commands are null terminated strings
|
||||||
int totalLength = sizeof(PACKET_TYPE_Z_COMMAND) + commandLength + 1; // 1 for null termination
|
int totalLength = sizeof(PACKET_TYPE_Z_COMMAND) + commandLength + 1; // 1 for null termination
|
||||||
printf("got Z message len(%ld)= %s\n", receivedBytes, command);
|
printf("got Z message len(%ld)= %s\n", receivedBytes, command);
|
||||||
|
@ -735,11 +736,11 @@ int main(int argc, const char * argv[]) {
|
||||||
// need to make sure we have it in our nodeList.
|
// need to make sure we have it in our nodeList.
|
||||||
if (packetData[0] == PACKET_TYPE_HEAD_DATA) {
|
if (packetData[0] == PACKET_TYPE_HEAD_DATA) {
|
||||||
uint16_t nodeID = 0;
|
uint16_t nodeID = 0;
|
||||||
unpackNodeId(packetData + sizeof(PACKET_TYPE_HEAD_DATA), &nodeID);
|
unpackNodeId(packetData + sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION), &nodeID);
|
||||||
Node* node = nodeList->addOrUpdateNode(&nodePublicAddress,
|
Node* node = nodeList->addOrUpdateNode(&nodePublicAddress,
|
||||||
&nodePublicAddress,
|
&nodePublicAddress,
|
||||||
NODE_TYPE_AGENT,
|
NODE_TYPE_AGENT,
|
||||||
nodeID);
|
nodeID);
|
||||||
|
|
||||||
nodeList->updateNodeWithData(node, packetData, receivedBytes);
|
nodeList->updateNodeWithData(node, packetData, receivedBytes);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue