History

add a Profile class to hold user data from data-server

Stephen Birarda committed 13 years ago

Commit 85edb931 parent 56b71eb9 files · +150 −56Browse files

Showing the changes to interface/src/DataServerClient.cpp (1 of 9 files). Show all

Unified · Split

interface/src/DataServerClient.cpp+46−35
@@ -14,9 +14,11 @@ · 13 unmodified lines
1414 #include <UUID.h>
1515
1616 #include "Application.h"
17+#include "Profile.h"
18+
1719 #include "DataServerClient.h"
1820
19−QString DataServerClient::_clientUsername;
21+
2022 std::map<unsigned char*, int> DataServerClient::_unmatchedPackets;
2123
2224 const char DATA_SERVER_HOSTNAME[] = "127.0.0.1";
@@ -24,33 +26,36 @@ const unsigned short DATA_SERVER_PORT = 3282; · 1 unmodified line
2426 const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT);
2527
2628 void DataServerClient::putValueForKey(const char* key, const char* value) {
27− if (!_clientUsername.isEmpty()) {
28− unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE];
29−
30− // setup the header for this packet
31− int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);
32−
33− // pack the client UUID, null terminated
34− memcpy(putPacket + numPacketBytes, _clientUsername.toLocal8Bit().constData(), _clientUsername.toLocal8Bit().size());
35− numPacketBytes += _clientUsername.toLocal8Bit().size();
36− putPacket[numPacketBytes++] = '\0';
37−
38− // pack the key, null terminated
39− strcpy((char*) putPacket + numPacketBytes, key);
40− numPacketBytes += strlen(key);
41− putPacket[numPacketBytes++] = '\0';
42−
43− // pack the value, null terminated
44− strcpy((char*) putPacket + numPacketBytes, value);
45− numPacketBytes += strlen(value);
46− putPacket[numPacketBytes++] = '\0';
47−
48− // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed
49− _unmatchedPackets.insert(std::pair<unsigned char*, int>(putPacket, numPacketBytes));
50−
51− // send this put request to the data server
52− NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes);
53− }
29+ Profile* userProfile = Application::getInstance()->getProfile();
30+ QString clientString = userProfile->getUUID().isNull() ? userProfile->getUsername() : userProfile->getUUID().toString();
31+
32+ Application::getInstance();
33+
34+ unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE];
35+
36+ // setup the header for this packet
37+ int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);
38+
39+ // pack the client UUID, null terminated
40+ memcpy(putPacket + numPacketBytes, clientString.toLocal8Bit().constData(), clientString.toLocal8Bit().size());
41+ numPacketBytes += clientString.toLocal8Bit().size();
42+ putPacket[numPacketBytes++] = '\0';
43+
44+ // pack the key, null terminated
45+ strcpy((char*) putPacket + numPacketBytes, key);
46+ numPacketBytes += strlen(key);
47+ putPacket[numPacketBytes++] = '\0';
48+
49+ // pack the value, null terminated
50+ strcpy((char*) putPacket + numPacketBytes, value);
51+ numPacketBytes += strlen(value);
52+ putPacket[numPacketBytes++] = '\0';
53+
54+ // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed
55+ _unmatchedPackets.insert(std::pair<unsigned char*, int>(putPacket, numPacketBytes));
56+
57+ // send this put request to the data server
58+ NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes);
5459 }
5560
5661 void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) {
@@ -83,7 +88,9 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use · 26 unmodified lines
8388 NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes);
8489 }
8590
86−
91+void DataServerClient::getClientValueForKey(const char* key) {
92+ getValueForKeyAndUserString(key, Application::getInstance()->getProfile()->getUsername());
93+}
8794
8895 void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {
8996 removeMatchedPacketFromMap(packetData, numPacketBytes);
@@ -102,18 +109,22 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 12 unmodified lines
102109 // for now assume this means that it is for our avatar
103110
104111 char* dataKeyPosition = (char*) packetData + numHeaderBytes + sizeof(userString);
112+ char* dataValuePosition = dataKeyPosition + strlen(dataKeyPosition) + sizeof(char);
113+
114+ QString dataValueString(QByteArray(dataValuePosition,
115+ numPacketBytes - ((unsigned char*) dataValuePosition - packetData)));
105116
106117 if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL) == 0) {
107118 // pull the user's face mesh and set it on the Avatar instance
108− char* faceMeshPosition = dataKeyPosition + strlen(dataKeyPosition) + sizeof(char);
109−
110− QUrl faceMeshURL(QByteArray(faceMeshPosition,
111− numPacketBytes - ((unsigned char*) faceMeshPosition - packetData)));
112119
113− qDebug("Changing user's face model URL to %s\n", faceMeshURL.toString().toLocal8Bit().constData());
120+
121+ qDebug("Changing user's face model URL to %s\n", dataValueString.toLocal8Bit().constData());
114122 QMetaObject::invokeMethod(&Application::getInstance()->getAvatar()->getHead().getBlendFace(),
115123 "setModelURL",
116− Q_ARG(QUrl, faceMeshURL));
124+ Q_ARG(QUrl, QUrl(dataValueString)));
125+ } else if (strcmp(dataKeyPosition, DataServerKey::UUID) == 0) {
126+ // this is the user's UUID - set it on the profile
127+ Application::getInstance()->getProfile()->setUUID(dataValueString);
117128 }
118129 } else {
119130 // user string was UUID, find matching avatar and associate data