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
34void DataServerClient::putValueForKey(const QString& key, const char* value) {34void DataServerClient::putValueForKey(const QString& key, const char* value) {
35 QString clientString = Application::getInstance()->getProfile()->getUserString();35 QString clientString = Application::getInstance()->getProfile()->getUserString();
36 if (!clientString.isEmpty()) {36 if (!clientString.isEmpty()) {
37 37
38 unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE];38 unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE];
39 39
40 // setup the header for this packet40 // setup the header for this packet
41 int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);41 int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);
42 42
43 // pack the client UUID, null terminated43 // pack the client UUID, null terminated
44 memcpy(putPacket + numPacketBytes, clientString.toLocal8Bit().constData(), clientString.toLocal8Bit().size());44 memcpy(putPacket + numPacketBytes, clientString.toLocal8Bit().constData(), clientString.toLocal8Bit().size());
45 numPacketBytes += clientString.toLocal8Bit().size();45 numPacketBytes += clientString.toLocal8Bit().size();
46 putPacket[numPacketBytes++] = '\0';46 putPacket[numPacketBytes++] = '\0';
47 47
48 // pack a 1 to designate that we are putting a single value48 // pack a 1 to designate that we are putting a single value
49 putPacket[numPacketBytes++] = 1;49 putPacket[numPacketBytes++] = 1;
50 50
51 // pack the key, null terminated51 // pack the key, null terminated
52 strcpy((char*) putPacket + numPacketBytes, key.toLocal8Bit().constData());52 strcpy((char*) putPacket + numPacketBytes, key.toLocal8Bit().constData());
53 numPacketBytes += key.size();53 numPacketBytes += key.size();
54 putPacket[numPacketBytes++] = '\0';54 putPacket[numPacketBytes++] = '\0';
55 55
56 // pack the value, null terminated56 // pack the value, null terminated
57 strcpy((char*) putPacket + numPacketBytes, value);57 strcpy((char*) putPacket + numPacketBytes, value);
58 numPacketBytes += strlen(value);58 numPacketBytes += strlen(value);
59 putPacket[numPacketBytes++] = '\0';59 putPacket[numPacketBytes++] = '\0';
60 60
61 // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed61 // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed
62 // _unmatchedPackets.insert(std::pair<unsigned char*, int>(putPacket, numPacketBytes));62 // _unmatchedPackets.insert(std::pair<unsigned char*, int>(putPacket, numPacketBytes));
63 63
64 // send this put request to the data server64 // send this put request to the data server
65 NodeList::getInstance()->getNodeSocket().writeDatagram((char*) putPacket, numPacketBytes,65 NodeList::getInstance()->getNodeSocket().writeDatagram((char*) putPacket, numPacketBytes,
66 dataServerSockAddr().getAddress(),66 dataServerSockAddr().getAddress(),
@@ -81,27 +81,27 @@ void DataServerClient::getValuesForKeysAndUUID(const QStringList& keys, const QU · 14 unmodified lines
81void DataServerClient::getValuesForKeysAndUserString(const QStringList& keys, const QString& userString) {81void DataServerClient::getValuesForKeysAndUserString(const QStringList& keys, const QString& userString) {
82 if (!userString.isEmpty() && keys.size() <= UCHAR_MAX) {82 if (!userString.isEmpty() && keys.size() <= UCHAR_MAX) {
83 unsigned char* getPacket = new unsigned char[MAX_PACKET_SIZE];83 unsigned char* getPacket = new unsigned char[MAX_PACKET_SIZE];
84 84
85 // setup the header for this packet85 // setup the header for this packet
86 int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET);86 int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET);
87 87
88 // pack the user string (could be username or UUID string), null-terminate88 // pack the user string (could be username or UUID string), null-terminate
89 memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size());89 memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size());
90 numPacketBytes += userString.toLocal8Bit().size();90 numPacketBytes += userString.toLocal8Bit().size();
91 getPacket[numPacketBytes++] = '\0';91 getPacket[numPacketBytes++] = '\0';
92 92
93 // pack one byte to designate the number of keys93 // pack one byte to designate the number of keys
94 getPacket[numPacketBytes++] = keys.size();94 getPacket[numPacketBytes++] = keys.size();
95 95
96 QString keyString = keys.join(MULTI_KEY_VALUE_SEPARATOR);96 QString keyString = keys.join(MULTI_KEY_VALUE_SEPARATOR);
97 97
98 // pack the key string, null terminated98 // pack the key string, null terminated
99 strcpy((char*) getPacket + numPacketBytes, keyString.toLocal8Bit().constData());99 strcpy((char*) getPacket + numPacketBytes, keyString.toLocal8Bit().constData());
100 numPacketBytes += keyString.size() + sizeof('\0');100 numPacketBytes += keyString.size() + sizeof('\0');
101 101
102 // add the getPacket to our vector of uncofirmed packets, will be deleted once we get a response from the nameserver102 // add the getPacket to our vector of uncofirmed packets, will be deleted once we get a response from the nameserver
103 // _unmatchedPackets.insert(std::pair<unsigned char*, int>(getPacket, numPacketBytes));103 // _unmatchedPackets.insert(std::pair<unsigned char*, int>(getPacket, numPacketBytes));
104 104
105 // send the get to the data server105 // send the get to the data server
106 NodeList::getInstance()->getNodeSocket().writeDatagram((char*) getPacket, numPacketBytes,106 NodeList::getInstance()->getNodeSocket().writeDatagram((char*) getPacket, numPacketBytes,
107 dataServerSockAddr().getAddress(),107 dataServerSockAddr().getAddress(),
@@ -120,25 +120,25 @@ void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, i · 12 unmodified lines
120void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) {120void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) {
121 // pull the user string from the packet so we know who to associate this with121 // pull the user string from the packet so we know who to associate this with
122 int numHeaderBytes = numBytesForPacketHeader(packetData);122 int numHeaderBytes = numBytesForPacketHeader(packetData);
123 123
124 char* userStringPosition = (char*) packetData + numHeaderBytes;124 char* userStringPosition = (char*) packetData + numHeaderBytes;
125 125
126 QString userString(QByteArray(userStringPosition, strlen(userStringPosition)));126 QString userString(QByteArray(userStringPosition, strlen(userStringPosition)));
127 127
128 QUuid userUUID(userString);128 QUuid userUUID(userString);
129 129
130 char* keysPosition = (char*) packetData + numHeaderBytes + strlen(userStringPosition)130 char* keysPosition = (char*) packetData + numHeaderBytes + strlen(userStringPosition)
131 + sizeof('\0') + sizeof(unsigned char);131 + sizeof('\0') + sizeof(unsigned char);
132 char* valuesPosition = keysPosition + strlen(keysPosition) + sizeof('\0');132 char* valuesPosition = keysPosition + strlen(keysPosition) + sizeof('\0');
133 133
134 QStringList keyList = QString(keysPosition).split(MULTI_KEY_VALUE_SEPARATOR);134 QStringList keyList = QString(keysPosition).split(MULTI_KEY_VALUE_SEPARATOR);
135 QStringList valueList = QString(valuesPosition).split(MULTI_KEY_VALUE_SEPARATOR);135 QStringList valueList = QString(valuesPosition).split(MULTI_KEY_VALUE_SEPARATOR);
136 136
137 // user string was UUID, find matching avatar and associate data137 // user string was UUID, find matching avatar and associate data
138 for (int i = 0; i < keyList.size(); i++) {138 for (int i = 0; i < keyList.size(); i++) {
139 if (valueList[i] != " ") {139 if (valueList[i] != " ") {
140 if (keyList[i] == DataServerKey::FaceMeshURL) {140 if (keyList[i] == DataServerKey::FaceMeshURL) {
141 141
142 if (userUUID.isNull() || userUUID == Application::getInstance()->getProfile()->getUUID()) {142 if (userUUID.isNull() || userUUID == Application::getInstance()->getProfile()->getUUID()) {
143 qDebug("Changing user's face model URL to %s", valueList[i].toLocal8Bit().constData());143 qDebug("Changing user's face model URL to %s", valueList[i].toLocal8Bit().constData());
144 Application::getInstance()->getProfile()->setFaceModelURL(QUrl(valueList[i]));144 Application::getInstance()->getProfile()->setFaceModelURL(QUrl(valueList[i]));
@@ -148,7 +148,7 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 3 unmodified lines
148 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {148 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
149 if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {149 if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
150 Avatar* avatar = (Avatar *) node->getLinkedData();150 Avatar* avatar = (Avatar *) node->getLinkedData();
151 151
152 if (avatar->getUUID() == userUUID) {152 if (avatar->getUUID() == userUUID) {
153 QMetaObject::invokeMethod(&avatar->getHead().getFaceModel(),153 QMetaObject::invokeMethod(&avatar->getHead().getFaceModel(),
154 "setURL", Q_ARG(QUrl, QUrl(valueList[i])));154 "setURL", Q_ARG(QUrl, QUrl(valueList[i])));
@@ -157,7 +157,7 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 2 unmodified lines
157 }157 }
158 }158 }
159 } else if (keyList[i] == DataServerKey::SkeletonURL) {159 } else if (keyList[i] == DataServerKey::SkeletonURL) {
160 160
161 if (userUUID.isNull() || userUUID == Application::getInstance()->getProfile()->getUUID()) {161 if (userUUID.isNull() || userUUID == Application::getInstance()->getProfile()->getUUID()) {
162 qDebug("Changing user's skeleton URL to %s", valueList[i].toLocal8Bit().constData());162 qDebug("Changing user's skeleton URL to %s", valueList[i].toLocal8Bit().constData());
163 Application::getInstance()->getProfile()->setSkeletonModelURL(QUrl(valueList[i]));163 Application::getInstance()->getProfile()->setSkeletonModelURL(QUrl(valueList[i]));
@@ -166,7 +166,7 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 2 unmodified lines
166 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {166 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
167 if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {167 if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
168 Avatar* avatar = (Avatar *) node->getLinkedData();168 Avatar* avatar = (Avatar *) node->getLinkedData();
169 169
170 if (avatar->getUUID() == userUUID) {170 if (avatar->getUUID() == userUUID) {
171 QMetaObject::invokeMethod(&avatar->getSkeletonModel(), "setURL",171 QMetaObject::invokeMethod(&avatar->getSkeletonModel(), "setURL",
172 Q_ARG(QUrl, QUrl(valueList[i])));172 Q_ARG(QUrl, QUrl(valueList[i])));
@@ -177,42 +177,41 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 4 unmodified lines
177 } else if (keyList[i] == DataServerKey::Domain && keyList[i + 1] == DataServerKey::Position &&177 } else if (keyList[i] == DataServerKey::Domain && keyList[i + 1] == DataServerKey::Position &&
178 keyList[i + 2] == DataServerKey::Orientation && valueList[i] != " " &&178 keyList[i + 2] == DataServerKey::Orientation && valueList[i] != " " &&
179 valueList[i + 1] != " " && valueList[i + 2] != " ") {179 valueList[i + 1] != " " && valueList[i + 2] != " ") {
180 180
181 QStringList coordinateItems = valueList[i + 1].split(',');181 QStringList coordinateItems = valueList[i + 1].split(',');
182 QStringList orientationItems = valueList[i + 2].split(',');182 QStringList orientationItems = valueList[i + 2].split(',');
183 183
184 if (coordinateItems.size() == 3 && orientationItems.size() == 3) {184 if (coordinateItems.size() == 3 && orientationItems.size() == 3) {
185 185
186 // send a node kill request, indicating to other clients that they should play the "disappeared" effect186 // send a node kill request, indicating to other clients that they should play the "disappeared" effect
187 NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1);187 NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1);
188 188
189 qDebug() << "Changing domain to" << valueList[i].toLocal8Bit().constData() <<189 qDebug() << "Changing domain to" << valueList[i].toLocal8Bit().constData() <<
190 ", position to" << valueList[i + 1].toLocal8Bit().constData() <<190 ", position to" << valueList[i + 1].toLocal8Bit().constData() <<
191 ", and orientation to" << valueList[i + 2].toLocal8Bit().constData() <<191 ", and orientation to" << valueList[i + 2].toLocal8Bit().constData() <<
192 "to go to" << userString;192 "to go to" << userString;
193 193
194 NodeList::getInstance()->setDomainHostname(valueList[i]);194 NodeList::getInstance()->setDomainHostname(valueList[i]);
195
196 // orient the user to face the target195 // orient the user to face the target
197 glm::quat newOrientation = glm::quat(glm::radians(glm::vec3(orientationItems[0].toFloat(),196 glm::quat newOrientation = glm::quat(glm::radians(glm::vec3(orientationItems[0].toFloat(),
198 orientationItems[1].toFloat(), orientationItems[2].toFloat()))) *197 orientationItems[1].toFloat(), orientationItems[2].toFloat()))) *
199 glm::angleAxis(180.0f, 0.0f, 1.0f, 0.0f);198 glm::angleAxis(180.0f, 0.0f, 1.0f, 0.0f);
200 Application::getInstance()->getAvatar()->setOrientation(newOrientation);199 Application::getInstance()->getAvatar()->setOrientation(newOrientation);
201 200
202 // move the user a couple units away201 // move the user a couple units away
203 const float DISTANCE_TO_USER = 2.0f;202 const float DISTANCE_TO_USER = 2.0f;
204 glm::vec3 newPosition = glm::vec3(coordinateItems[0].toFloat(), coordinateItems[1].toFloat(),203 glm::vec3 newPosition = glm::vec3(coordinateItems[0].toFloat(), coordinateItems[1].toFloat(),
205 coordinateItems[2].toFloat()) - newOrientation * IDENTITY_FRONT * DISTANCE_TO_USER;204 coordinateItems[2].toFloat()) - newOrientation * IDENTITY_FRONT * DISTANCE_TO_USER;
206 Application::getInstance()->getAvatar()->setPosition(newPosition);205 Application::getInstance()->getAvatar()->setPosition(newPosition);
207 }206 }
208 207
209 } else if (keyList[i] == DataServerKey::UUID) {208 } else if (keyList[i] == DataServerKey::UUID) {
210 // this is the user's UUID - set it on the profile209 // this is the user's UUID - set it on the profile
211 Application::getInstance()->getProfile()->setUUID(valueList[i]);210 Application::getInstance()->getProfile()->setUUID(valueList[i]);
212 }211 }
213 }212 }
214 }213 }
215 214
216 // remove the matched packet from our map so it isn't re-sent to the data-server215 // remove the matched packet from our map so it isn't re-sent to the data-server
217 // removeMatchedPacketFromMap(packetData, numPacketBytes);216 // removeMatchedPacketFromMap(packetData, numPacketBytes);
218}217}
@@ -237,12 +236,12 @@ void DataServerClient::removeMatchedPacketFromMap(unsigned char* packetData, int · 18 unmodified lines
237 if (memcmp(mapIterator->first + sizeof(PACKET_TYPE),236 if (memcmp(mapIterator->first + sizeof(PACKET_TYPE),
238 packetData + sizeof(PACKET_TYPE),237 packetData + sizeof(PACKET_TYPE),
239 numPacketBytes - sizeof(PACKET_TYPE)) == 0) {238 numPacketBytes - sizeof(PACKET_TYPE)) == 0) {
240 239
241 // this is a match - remove the confirmed packet from the vector and delete associated member240 // this is a match - remove the confirmed packet from the vector and delete associated member
242 // so it isn't sent back out241 // so it isn't sent back out
243 delete[] mapIterator->first;242 delete[] mapIterator->first;
244 _unmatchedPackets.erase(mapIterator);243 _unmatchedPackets.erase(mapIterator);
245 244
246 // we've matched the packet - bail out245 // we've matched the packet - bail out
247 break;246 break;
248 }247 }

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