Showing the changes to interface/src/DataServerClient.cpp (1 of 5 files). Show all
Unified · Split
| @@ -13,7 +13,7 @@ · 12 unmodified lines | ||
| 13 | 13 | |
| 14 | 14 | #include "DataServerClient.h" |
| 15 | 15 | |
| 16 | −QUuid DataServerClient::_clientUUID; | |
| 16 | +QString DataServerClient::_clientUsername; | |
| 17 | 17 | std::vector<unsigned char*> DataServerClient::_unconfirmedPackets; |
| 18 | 18 | |
| 19 | 19 | const char DATA_SERVER_HOSTNAME[] = "127.0.0.1"; |
| @@ -21,16 +21,15 @@ const unsigned short DATA_SERVER_PORT = 3282; · 1 unmodified line | ||
| 21 | 21 | const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT); |
| 22 | 22 | |
| 23 | 23 | void DataServerClient::putValueForKey(const char* key, const char* value) { |
| 24 | − if (!_clientUUID.isNull()) { | |
| 24 | + if (!_clientUsername.isEmpty()) { | |
| 25 | 25 | unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; |
| 26 | 26 | |
| 27 | 27 | // setup the header for this packet |
| 28 | 28 | int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); |
| 29 | 29 | |
| 30 | 30 | // pack the client UUID |
| 31 | − QString uuidString = uuidStringWithoutCurlyBraces(_clientUUID); | |
| 32 | − memcpy(putPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); | |
| 33 | − numPacketBytes += uuidString.toLocal8Bit().size(); | |
| 31 | + memcpy(putPacket + numPacketBytes, _clientUsername.toLocal8Bit().constData(), _clientUsername.toLocal8Bit().size()); | |
| 32 | + numPacketBytes += _clientUsername.toLocal8Bit().size(); | |
| 34 | 33 | |
| 35 | 34 | // pack the key, null terminated |
| 36 | 35 | strcpy((char*) putPacket + numPacketBytes, key); |
| @@ -52,26 +51,30 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { · 15 unmodified lines | ||
| 52 | 51 | |
| 53 | 52 | void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) { |
| 54 | 53 | if (!uuid.isNull()) { |
| 55 | − unsigned char getPacket[MAX_PACKET_SIZE]; | |
| 56 | − | |
| 57 | − // setup the header for this packet | |
| 58 | − int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); | |
| 59 | − | |
| 60 | − // pack the UUID we're asking for data for | |
| 61 | 54 | QString uuidString = uuidStringWithoutCurlyBraces(uuid); |
| 62 | − memcpy(getPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); | |
| 63 | − numPacketBytes += uuidString.toLocal8Bit().size(); | |
| 64 | − | |
| 65 | − // pack the key, null terminated | |
| 66 | − strcpy((char*) getPacket + numPacketBytes, key); | |
| 67 | − numPacketBytes += strlen(key); | |
| 68 | − getPacket[numPacketBytes++] = '\0'; | |
| 69 | − | |
| 70 | − // send the get to the data server | |
| 71 | − NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); | |
| 55 | + getValueforKeyAndUserString(key, uuidString); | |
| 72 | 56 | } |
| 73 | 57 | } |
| 74 | 58 | |
| 59 | +void DataServerClient::getValueforKeyAndUserString(const char* key, QString& userString) { | |
| 60 | + unsigned char getPacket[MAX_PACKET_SIZE]; | |
| 61 | + | |
| 62 | + // setup the header for this packet | |
| 63 | + int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); | |
| 64 | + | |
| 65 | + // pack the user string (could be username or UUID string) | |
| 66 | + memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size()); | |
| 67 | + numPacketBytes += userString.toLocal8Bit().size(); | |
| 68 | + | |
| 69 | + // pack the key, null terminated | |
| 70 | + strcpy((char*) getPacket + numPacketBytes, key); | |
| 71 | + numPacketBytes += strlen(key); | |
| 72 | + getPacket[numPacketBytes++] = '\0'; | |
| 73 | + | |
| 74 | + // send the get to the data server | |
| 75 | + NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); | |
| 76 | +} | |
| 77 | + | |
| 75 | 78 | void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { |
| 76 | 79 | |
| 77 | 80 | for (std::vector<unsigned char*>::iterator unconfirmedPacket = _unconfirmedPackets.begin(); |