shore up receipt of face mesh URL from data-server

This commit is contained in:
Stephen Birarda 2013-10-07 17:06:33 -07:00
parent b33843fddc
commit 4b62026c25
3 changed files with 62 additions and 10 deletions

View file

@ -3613,6 +3613,12 @@ void* Application::networkReceive(void* args) {
case PACKET_TYPE_AVATAR_FACE_VIDEO: case PACKET_TYPE_AVATAR_FACE_VIDEO:
processAvatarFaceVideoMessage(app->_incomingPacket, bytesReceived); processAvatarFaceVideoMessage(app->_incomingPacket, bytesReceived);
break; break;
case PACKET_TYPE_DATA_SERVER_GET:
case PACKET_TYPE_DATA_SERVER_PUT:
case PACKET_TYPE_DATA_SERVER_SEND:
case PACKET_TYPE_DATA_SERVER_CONFIRM:
DataServerClient::processMessageFromDataServer(app->_incomingPacket, bytesReceived);
break;
default: default:
NodeList::getInstance()->processNodeData(&senderAddress, app->_incomingPacket, bytesReceived); NodeList::getInstance()->processNodeData(&senderAddress, app->_incomingPacket, bytesReceived);
break; break;

View file

@ -6,15 +6,18 @@
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. // Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
// //
#include <QtCore/QUrl>
#include <NodeList.h> #include <NodeList.h>
#include <PacketHeaders.h> #include <PacketHeaders.h>
#include <UDPSocket.h> #include <UDPSocket.h>
#include <UUID.h> #include <UUID.h>
#include "Application.h"
#include "DataServerClient.h" #include "DataServerClient.h"
QString DataServerClient::_clientUsername; QString DataServerClient::_clientUsername;
std::vector<unsigned char*> DataServerClient::_unconfirmedPackets; std::vector<unsigned char*> DataServerClient::_unmatchedPackets;
const char DATA_SERVER_HOSTNAME[] = "127.0.0.1"; const char DATA_SERVER_HOSTNAME[] = "127.0.0.1";
const unsigned short DATA_SERVER_PORT = 3282; const unsigned short DATA_SERVER_PORT = 3282;
@ -27,9 +30,10 @@ void DataServerClient::putValueForKey(const char* key, const char* value) {
// setup the header for this packet // setup the header for this packet
int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);
// pack the client UUID // pack the client UUID, null terminated
memcpy(putPacket + numPacketBytes, _clientUsername.toLocal8Bit().constData(), _clientUsername.toLocal8Bit().size()); memcpy(putPacket + numPacketBytes, _clientUsername.toLocal8Bit().constData(), _clientUsername.toLocal8Bit().size());
numPacketBytes += _clientUsername.toLocal8Bit().size(); numPacketBytes += _clientUsername.toLocal8Bit().size();
putPacket[numPacketBytes++] = '\0';
// pack the key, null terminated // pack the key, null terminated
strcpy((char*) putPacket + numPacketBytes, key); strcpy((char*) putPacket + numPacketBytes, key);
@ -42,7 +46,7 @@ void DataServerClient::putValueForKey(const char* key, const char* value) {
putPacket[numPacketBytes++] = '\0'; putPacket[numPacketBytes++] = '\0';
// add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed
_unconfirmedPackets.push_back(putPacket); _unmatchedPackets.push_back(putPacket);
// send this put request to the data server // send this put request to the data server
NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes);
@ -62,9 +66,10 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use
// setup the header for this packet // setup the header for this packet
int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET);
// pack the user string (could be username or UUID string) // pack the user string (could be username or UUID string), null-terminate
memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size()); memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size());
numPacketBytes += userString.toLocal8Bit().size(); numPacketBytes += userString.toLocal8Bit().size();
getPacket[numPacketBytes++] = '\0';
// pack the key, null terminated // pack the key, null terminated
strcpy((char*) getPacket + numPacketBytes, key); strcpy((char*) getPacket + numPacketBytes, key);
@ -77,14 +82,14 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use
void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {
for (std::vector<unsigned char*>::iterator unconfirmedPacket = _unconfirmedPackets.begin(); for (std::vector<unsigned char*>::iterator unconfirmedPacket = _unmatchedPackets.begin();
unconfirmedPacket != _unconfirmedPackets.end(); unconfirmedPacket != _unmatchedPackets.end();
++unconfirmedPacket) { ++unconfirmedPacket) {
if (memcmp(*unconfirmedPacket + sizeof(PACKET_TYPE), if (memcmp(*unconfirmedPacket + sizeof(PACKET_TYPE),
packetData + sizeof(PACKET_TYPE), packetData + sizeof(PACKET_TYPE),
numPacketBytes - sizeof(PACKET_TYPE)) == 0) { numPacketBytes - sizeof(PACKET_TYPE)) == 0) {
// this is a match - remove the confirmed packet from the vector so it isn't sent back out // this is a match - remove the confirmed packet from the vector so it isn't sent back out
_unconfirmedPackets.erase(unconfirmedPacket); _unmatchedPackets.erase(unconfirmedPacket);
// we've matched the packet - bail out // we've matched the packet - bail out
break; break;
@ -95,6 +100,46 @@ void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, i
} }
} }
void DataServerClient::processGetFromDataServer(unsigned char* packetData, int numPacketBytes) { void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) {
// pull the user string from the packet so we know who to associate this with
int numHeaderBytes = numBytesForPacketHeader(packetData);
QString userString(QByteArray((char*) packetData + numHeaderBytes, strlen((char*) packetData + numHeaderBytes)));
QUuid userUUID(userString);
if (userUUID.isNull()) {
// the user string was a username
// for now assume this means that it is for our avatar
char* dataKeyPosition = (char*) packetData + numHeaderBytes + sizeof(userString);
if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL) == 0) {
// pull the user's face mesh and set it on the Avatar instance
char* faceMeshPosition = dataKeyPosition + strlen(dataKeyPosition) + sizeof(char);
QUrl faceMeshURL(QByteArray(faceMeshPosition,
numPacketBytes - ((unsigned char*) faceMeshPosition - packetData)));
qDebug("Changing user's face model URL to %s\n", faceMeshURL.toString().toLocal8Bit().constData());
QMetaObject::invokeMethod(&Application::getInstance()->getAvatar()->getHead().getBlendFace(),
"setModelURL",
Q_ARG(QUrl, faceMeshURL));
}
} else {
// user string was UUID, find matching avatar and associate data
}
}
void DataServerClient::processMessageFromDataServer(unsigned char* packetData, int numPacketBytes) {
switch (packetData[0]) {
case PACKET_TYPE_DATA_SERVER_SEND:
processSendFromDataServer(packetData, numPacketBytes);
break;
case PACKET_TYPE_DATA_SERVER_CONFIRM:
processConfirmFromDataServer(packetData, numPacketBytes);
break;
default:
break;
}
} }

View file

@ -20,13 +20,14 @@ public:
static void getValueForKeyAndUserString(const char* key, QString& userString); static void getValueForKeyAndUserString(const char* key, QString& userString);
static void getClientValueForKey(const char* key) { getValueForKeyAndUserString(key, _clientUsername); } static void getClientValueForKey(const char* key) { getValueForKeyAndUserString(key, _clientUsername); }
static void processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes); static void processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes);
static void processGetFromDataServer(unsigned char* packetData, int numPacketBytes); static void processSendFromDataServer(unsigned char* packetData, int numPacketBytes);
static void processMessageFromDataServer(unsigned char* packetData, int numPacketBytes);
static void setClientUsername(const QString& clientUsername) { _clientUsername = clientUsername; } static void setClientUsername(const QString& clientUsername) { _clientUsername = clientUsername; }
static QString& setClientUsername() { return _clientUsername; } static QString& setClientUsername() { return _clientUsername; }
private: private:
static QString _clientUsername; static QString _clientUsername;
static std::vector<unsigned char*> _unconfirmedPackets; static std::vector<unsigned char*> _unmatchedPackets;
}; };
namespace DataServerKey { namespace DataServerKey {