From 7fb42dcb8a089549e01d636040215e9a797c58ce Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 10 Jun 2013 13:48:34 -0700 Subject: [PATCH] fix bug with sent and received agent interest packets --- domain-server/src/main.cpp | 6 ++++-- interface/src/Application.cpp | 2 +- libraries/shared/src/AgentList.cpp | 16 +++++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 6988137455..b1e2117db3 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -102,7 +102,8 @@ int main(int argc, const char * argv[]) std::map newestSoloAgents; agentType = packetData[1]; - int numBytesSocket = unpackSocket(packetData + 2, (sockaddr*) &agentLocalAddress); + int numBytesSocket = unpackSocket(packetData + sizeof(PACKET_HEADER) + sizeof(AGENT_TYPE), + (sockaddr*) &agentLocalAddress); // check the agent public address // if it matches our local address we're on the same box @@ -127,7 +128,8 @@ int main(int argc, const char * argv[]) currentBufferPos = broadcastPacket + sizeof(PACKET_HEADER); startPointer = currentBufferPos; - char* agentTypesOfInterest = (char*) currentBufferPos + sizeof(AGENT_TYPE) + numBytesSocket + sizeof(unsigned char); + unsigned char* agentTypesOfInterest = packetData + sizeof(PACKET_HEADER) + sizeof(AGENT_TYPE) + + numBytesSocket + sizeof(unsigned char); int numInterestTypes = *(agentTypesOfInterest - 1); if (numInterestTypes > 0) { diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index fe65c56424..df9321a977 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -209,7 +209,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : #endif // tell the AgentList instance who to tell the domain server we care about - const unsigned char agentTypesOfInterest[] = {AGENT_TYPE_AUDIO_MIXER, AGENT_TYPE_AVATAR_MIXER, AGENT_TYPE_VOXEL_SERVER}; + const char agentTypesOfInterest[] = {AGENT_TYPE_AUDIO_MIXER, AGENT_TYPE_AVATAR_MIXER, AGENT_TYPE_VOXEL_SERVER}; AgentList::getInstance()->setAgentTypesOfInterest(agentTypesOfInterest, sizeof(agentTypesOfInterest)); // start the agentList threads diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 1da6b90c2d..42a735a1e3 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -215,23 +215,29 @@ void AgentList::sendDomainServerCheckIn() { numBytesAgentsOfInterest + sizeof(unsigned char); checkInPacket = new unsigned char[numPacketBytes]; + unsigned char* packetPosition = checkInPacket; - checkInPacket[0] = (memchr(SOLO_AGENT_TYPES, _ownerType, sizeof(SOLO_AGENT_TYPES))) + *(packetPosition++) = (memchr(SOLO_AGENT_TYPES, _ownerType, sizeof(SOLO_AGENT_TYPES))) ? PACKET_HEADER_DOMAIN_REPORT_FOR_DUTY : PACKET_HEADER_DOMAIN_LIST_REQUEST; - checkInPacket[1] = _ownerType; + *(packetPosition++) = _ownerType; - packSocket(checkInPacket + sizeof(PACKET_HEADER) + sizeof(AGENT_TYPE), getLocalAddress(), htons(_socketListenPort)); + packetPosition += packSocket(checkInPacket + sizeof(PACKET_HEADER) + sizeof(AGENT_TYPE), + getLocalAddress(), + htons(_socketListenPort)); // add the number of bytes for agent types of interest - checkInPacket[numPacketBytes] = numBytesAgentsOfInterest; + *(packetPosition++) = numBytesAgentsOfInterest; // copy over the bytes for agent types of interest, if required if (numBytesAgentsOfInterest > 0) { - memcpy(checkInPacket + numPacketBytes + sizeof(unsigned char), + memcpy(packetPosition, _agentTypesOfInterest, numBytesAgentsOfInterest); + packetPosition += numBytesAgentsOfInterest; } + + *packetPosition = '\0'; } _agentSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, checkInPacket, strlen((char*) checkInPacket));