Showing the changes to interface/src/DataServerClient.cpp (1 of 4 files). Show all
Unified · Split
| @@ -26,11 +26,7 @@ const unsigned short DATA_SERVER_PORT = 3282; · 25 unmodified lines | ||
| 26 | 26 | const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT); |
| 27 | 27 | |
| 28 | 28 | void DataServerClient::putValueForKey(const char* key, const char* value) { |
| 29 | − Profile* userProfile = Application::getInstance()->getProfile(); | |
| 30 | − QString clientString = userProfile->getUUID().isNull() | |
| 31 | − ? userProfile->getUsername() | |
| 32 | − : uuidStringWithoutCurlyBraces(userProfile->getUUID().toString()); | |
| 33 | − | |
| 29 | + QString clientString = Application::getInstance()->getProfile()->getUserString(); | |
| 34 | 30 | if (!clientString.isEmpty()) { |
| 35 | 31 | |
| 36 | 32 | unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; |
| @@ -62,40 +58,45 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { · 25 unmodified lines | ||
| 62 | 58 | } |
| 63 | 59 | |
| 64 | 60 | void DataServerClient::getValueForKeyAndUUID(const char* key, const QUuid &uuid) { |
| 61 | + getValuesForKeysAndUUID(QStringList(QString(key)), uuid); | |
| 62 | +} | |
| 63 | + | |
| 64 | +void DataServerClient::getValuesForKeysAndUUID(const QStringList& keys, const QUuid& uuid) { | |
| 65 | 65 | if (!uuid.isNull()) { |
| 66 | − getValueForKeyAndUserString(key, uuidStringWithoutCurlyBraces(uuid)); | |
| 66 | + getValuesForKeysAndUserString(keys, uuidStringWithoutCurlyBraces(uuid)); | |
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | −void DataServerClient::getValueForKeyAndUserString(const char* key, const QString& userString) { | |
| 71 | − unsigned char* getPacket = new unsigned char[MAX_PACKET_SIZE]; | |
| 72 | − | |
| 73 | − // setup the header for this packet | |
| 74 | − int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); | |
| 75 | − | |
| 76 | − // pack the user string (could be username or UUID string), null-terminate | |
| 77 | − memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size()); | |
| 78 | − numPacketBytes += userString.toLocal8Bit().size(); | |
| 79 | − getPacket[numPacketBytes++] = '\0'; | |
| 80 | − | |
| 81 | − // pack the key, null terminated | |
| 82 | − strcpy((char*) getPacket + numPacketBytes, key); | |
| 83 | − int numKeyBytes = strlen(key); | |
| 84 | − | |
| 85 | − if (numKeyBytes > 0) { | |
| 86 | − numPacketBytes += numKeyBytes; | |
| 70 | +void DataServerClient::getValuesForKeysAndUserString(const QStringList& keys, const QString& userString) { | |
| 71 | + if (!userString.isEmpty()) { | |
| 72 | + unsigned char* getPacket = new unsigned char[MAX_PACKET_SIZE]; | |
| 73 | + | |
| 74 | + // setup the header for this packet | |
| 75 | + int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); | |
| 76 | + | |
| 77 | + // pack the user string (could be username or UUID string), null-terminate | |
| 78 | + memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size()); | |
| 79 | + numPacketBytes += userString.toLocal8Bit().size(); | |
| 87 | 80 | getPacket[numPacketBytes++] = '\0'; |
| 81 | + | |
| 82 | + for (int i = 0; i < keys.size(); ++i) { | |
| 83 | + // pack the keys, null terminated | |
| 84 | + strcpy((char*) getPacket + numPacketBytes, keys[i].toLocal8Bit().constData()); | |
| 85 | + | |
| 86 | + numPacketBytes += keys[i].size(); | |
| 87 | + getPacket[numPacketBytes++] = '\0'; | |
| 88 | + } | |
| 89 | + | |
| 90 | + // add the getPacket to our vector of uncofirmed packets, will be deleted once we get a response from the nameserver | |
| 91 | + _unmatchedPackets.insert(std::pair<unsigned char*, int>(getPacket, numPacketBytes)); | |
| 92 | + | |
| 93 | + // send the get to the data server | |
| 94 | + NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); | |
| 88 | 95 | } |
| 89 | − | |
| 90 | − // add the getPacket to our vector of uncofirmed packets, will be deleted once we get a response from the nameserver | |
| 91 | − _unmatchedPackets.insert(std::pair<unsigned char*, int>(getPacket, numPacketBytes)); | |
| 92 | − | |
| 93 | − // send the get to the data server | |
| 94 | − NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); | |
| 95 | 96 | } |
| 96 | 97 | |
| 97 | 98 | void DataServerClient::getClientValueForKey(const char* key) { |
| 98 | − getValueForKeyAndUserString(key, Application::getInstance()->getProfile()->getUsername()); | |
| 99 | + getValuesForKeysAndUserString(QStringList(QString(key)), Application::getInstance()->getProfile()->getUserString()); | |
| 99 | 100 | } |
| 100 | 101 | |
| 101 | 102 | void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { |