History

Merge

stojce committed 12 years ago

Commit a401d821 parent 50ad5a4183 files · +30506 −2547Browse files

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

Unified · Split

interface/src/DataServerClient.cpp+34−35
@@ -34,33 +34,33 @@ const HifiSockAddr& DataServerClient::dataServerSockAddr() { · 33 unmodified lines
3434 void DataServerClient::putValueForKey(const QString& key, const char* value) {
3535 QString clientString = Application::getInstance()->getProfile()->getUserString();
3636 if (!clientString.isEmpty()) {
37−
37+
3838 unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE];
39−
39+
4040 // setup the header for this packet
4141 int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);
42−
42+
4343 // pack the client UUID, null terminated
4444 memcpy(putPacket + numPacketBytes, clientString.toLocal8Bit().constData(), clientString.toLocal8Bit().size());
4545 numPacketBytes += clientString.toLocal8Bit().size();
4646 putPacket[numPacketBytes++] = '\0';
47−
47+
4848 // pack a 1 to designate that we are putting a single value
4949 putPacket[numPacketBytes++] = 1;
50−
50+
5151 // pack the key, null terminated
5252 strcpy((char*) putPacket + numPacketBytes, key.toLocal8Bit().constData());
5353 numPacketBytes += key.size();
5454 putPacket[numPacketBytes++] = '\0';
55−
55+
5656 // pack the value, null terminated
5757 strcpy((char*) putPacket + numPacketBytes, value);
5858 numPacketBytes += strlen(value);
5959 putPacket[numPacketBytes++] = '\0';
60−
60+
6161 // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed
6262 // _unmatchedPackets.insert(std::pair<unsigned char*, int>(putPacket, numPacketBytes));
63−
63+
6464 // send this put request to the data server
6565 NodeList::getInstance()->getNodeSocket().writeDatagram((char*) putPacket, numPacketBytes,
6666 dataServerSockAddr().getAddress(),
@@ -81,27 +81,27 @@ void DataServerClient::getValuesForKeysAndUUID(const QStringList& keys, const QU · 14 unmodified lines
8181 void DataServerClient::getValuesForKeysAndUserString(const QStringList& keys, const QString& userString) {
8282 if (!userString.isEmpty() && keys.size() <= UCHAR_MAX) {
8383 unsigned char* getPacket = new unsigned char[MAX_PACKET_SIZE];
84−
84+
8585 // setup the header for this packet
8686 int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET);
87−
87+
8888 // pack the user string (could be username or UUID string), null-terminate
8989 memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size());
9090 numPacketBytes += userString.toLocal8Bit().size();
9191 getPacket[numPacketBytes++] = '\0';
92−
92+
9393 // pack one byte to designate the number of keys
9494 getPacket[numPacketBytes++] = keys.size();
95−
95+
9696 QString keyString = keys.join(MULTI_KEY_VALUE_SEPARATOR);
97−
97+
9898 // pack the key string, null terminated
9999 strcpy((char*) getPacket + numPacketBytes, keyString.toLocal8Bit().constData());
100100 numPacketBytes += keyString.size() + sizeof('\0');
101−
101+
102102 // add the getPacket to our vector of uncofirmed packets, will be deleted once we get a response from the nameserver
103103 // _unmatchedPackets.insert(std::pair<unsigned char*, int>(getPacket, numPacketBytes));
104−
104+
105105 // send the get to the data server
106106 NodeList::getInstance()->getNodeSocket().writeDatagram((char*) getPacket, numPacketBytes,
107107 dataServerSockAddr().getAddress(),
@@ -120,25 +120,25 @@ void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, i · 12 unmodified lines
120120 void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) {
121121 // pull the user string from the packet so we know who to associate this with
122122 int numHeaderBytes = numBytesForPacketHeader(packetData);
123−
123+
124124 char* userStringPosition = (char*) packetData + numHeaderBytes;
125−
125+
126126 QString userString(QByteArray(userStringPosition, strlen(userStringPosition)));
127−
127+
128128 QUuid userUUID(userString);
129−
129+
130130 char* keysPosition = (char*) packetData + numHeaderBytes + strlen(userStringPosition)
131131 + sizeof('\0') + sizeof(unsigned char);
132132 char* valuesPosition = keysPosition + strlen(keysPosition) + sizeof('\0');
133−
133+
134134 QStringList keyList = QString(keysPosition).split(MULTI_KEY_VALUE_SEPARATOR);
135135 QStringList valueList = QString(valuesPosition).split(MULTI_KEY_VALUE_SEPARATOR);
136−
136+
137137 // user string was UUID, find matching avatar and associate data
138138 for (int i = 0; i < keyList.size(); i++) {
139139 if (valueList[i] != " ") {
140140 if (keyList[i] == DataServerKey::FaceMeshURL) {
141−
141+
142142 if (userUUID.isNull() || userUUID == Application::getInstance()->getProfile()->getUUID()) {
143143 qDebug("Changing user's face model URL to %s", valueList[i].toLocal8Bit().constData());
144144 Application::getInstance()->getProfile()->setFaceModelURL(QUrl(valueList[i]));
@@ -148,7 +148,7 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 3 unmodified lines
148148 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
149149 if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
150150 Avatar* avatar = (Avatar *) node->getLinkedData();
151−
151+
152152 if (avatar->getUUID() == userUUID) {
153153 QMetaObject::invokeMethod(&avatar->getHead().getFaceModel(),
154154 "setURL", Q_ARG(QUrl, QUrl(valueList[i])));
@@ -157,7 +157,7 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 2 unmodified lines
157157 }
158158 }
159159 } else if (keyList[i] == DataServerKey::SkeletonURL) {
160−
160+
161161 if (userUUID.isNull() || userUUID == Application::getInstance()->getProfile()->getUUID()) {
162162 qDebug("Changing user's skeleton URL to %s", valueList[i].toLocal8Bit().constData());
163163 Application::getInstance()->getProfile()->setSkeletonModelURL(QUrl(valueList[i]));
@@ -166,7 +166,7 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 2 unmodified lines
166166 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
167167 if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
168168 Avatar* avatar = (Avatar *) node->getLinkedData();
169−
169+
170170 if (avatar->getUUID() == userUUID) {
171171 QMetaObject::invokeMethod(&avatar->getSkeletonModel(), "setURL",
172172 Q_ARG(QUrl, QUrl(valueList[i])));
@@ -177,42 +177,41 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 4 unmodified lines
177177 } else if (keyList[i] == DataServerKey::Domain && keyList[i + 1] == DataServerKey::Position &&
178178 keyList[i + 2] == DataServerKey::Orientation && valueList[i] != " " &&
179179 valueList[i + 1] != " " && valueList[i + 2] != " ") {
180−
180+
181181 QStringList coordinateItems = valueList[i + 1].split(',');
182182 QStringList orientationItems = valueList[i + 2].split(',');
183−
183+
184184 if (coordinateItems.size() == 3 && orientationItems.size() == 3) {
185−
185+
186186 // send a node kill request, indicating to other clients that they should play the "disappeared" effect
187187 NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1);
188−
188+
189189 qDebug() << "Changing domain to" << valueList[i].toLocal8Bit().constData() <<
190190 ", position to" << valueList[i + 1].toLocal8Bit().constData() <<
191191 ", and orientation to" << valueList[i + 2].toLocal8Bit().constData() <<
192192 "to go to" << userString;
193193
194194 NodeList::getInstance()->setDomainHostname(valueList[i]);
195−
196195 // orient the user to face the target
197196 glm::quat newOrientation = glm::quat(glm::radians(glm::vec3(orientationItems[0].toFloat(),
198197 orientationItems[1].toFloat(), orientationItems[2].toFloat()))) *
199198 glm::angleAxis(180.0f, 0.0f, 1.0f, 0.0f);
200199 Application::getInstance()->getAvatar()->setOrientation(newOrientation);
201−
200+
202201 // move the user a couple units away
203202 const float DISTANCE_TO_USER = 2.0f;
204203 glm::vec3 newPosition = glm::vec3(coordinateItems[0].toFloat(), coordinateItems[1].toFloat(),
205204 coordinateItems[2].toFloat()) - newOrientation * IDENTITY_FRONT * DISTANCE_TO_USER;
206205 Application::getInstance()->getAvatar()->setPosition(newPosition);
207206 }
208−
207+
209208 } else if (keyList[i] == DataServerKey::UUID) {
210209 // this is the user's UUID - set it on the profile
211210 Application::getInstance()->getProfile()->setUUID(valueList[i]);
212211 }
213212 }
214213 }
215−
214+
216215 // remove the matched packet from our map so it isn't re-sent to the data-server
217216 // removeMatchedPacketFromMap(packetData, numPacketBytes);
218217 }
@@ -237,12 +236,12 @@ void DataServerClient::removeMatchedPacketFromMap(unsigned char* packetData, int · 18 unmodified lines
237236 if (memcmp(mapIterator->first + sizeof(PACKET_TYPE),
238237 packetData + sizeof(PACKET_TYPE),
239238 numPacketBytes - sizeof(PACKET_TYPE)) == 0) {
240−
239+
241240 // this is a match - remove the confirmed packet from the vector and delete associated member
242241 // so it isn't sent back out
243242 delete[] mapIterator->first;
244243 _unmatchedPackets.erase(mapIterator);
245−
244+
246245 // we've matched the packet - bail out
247246 break;
248247 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t