handle preventing edits to non-existant particles

This commit is contained in:
ZappoMan 2014-01-24 15:30:40 -08:00
parent 2720b98d57
commit 67ef3282cb
3 changed files with 18 additions and 24 deletions

View file

@ -292,10 +292,7 @@ int Particle::readParticleDataFromBuffer(const unsigned char* data, int bytesLef
} }
Particle Particle::fromEditPacket(unsigned char* data, int length, int& processedBytes, ParticleTree* tree) { Particle Particle::fromEditPacket(unsigned char* data, int length, int& processedBytes, ParticleTree* tree, bool& valid) {
//qDebug() << "Particle::fromEditPacket() length=" << length;
Particle newParticle; // id and _lastUpdated will get set here... Particle newParticle; // id and _lastUpdated will get set here...
unsigned char* dataAt = data; unsigned char* dataAt = data;
processedBytes = 0; processedBytes = 0;
@ -304,9 +301,6 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe
int octets = numberOfThreeBitSectionsInCode(data); int octets = numberOfThreeBitSectionsInCode(data);
int lengthOfOctcode = bytesRequiredForCodeLength(octets); int lengthOfOctcode = bytesRequiredForCodeLength(octets);
//qDebug() << "Particle::fromEditPacket() lengthOfOctcode=" << lengthOfOctcode;
//printOctalCode(data);
// we don't actually do anything with this octcode... // we don't actually do anything with this octcode...
dataAt += lengthOfOctcode; dataAt += lengthOfOctcode;
processedBytes += lengthOfOctcode; processedBytes += lengthOfOctcode;
@ -323,8 +317,6 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe
// special case for handling "new" particles // special case for handling "new" particles
if (isNewParticle) { if (isNewParticle) {
//qDebug() << "editID == NEW_PARTICLE";
// If this is a NEW_PARTICLE, then we assume that there's an additional uint32_t creatorToken, that // If this is a NEW_PARTICLE, then we assume that there's an additional uint32_t creatorToken, that
// we want to send back to the creator as an map to the actual id // we want to send back to the creator as an map to the actual id
uint32_t creatorTokenID; uint32_t creatorTokenID;
@ -332,11 +324,8 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe
dataAt += sizeof(creatorTokenID); dataAt += sizeof(creatorTokenID);
processedBytes += sizeof(creatorTokenID); processedBytes += sizeof(creatorTokenID);
//qDebug() << "creatorTokenID:" << creatorTokenID;
newParticle.setCreatorTokenID(creatorTokenID); newParticle.setCreatorTokenID(creatorTokenID);
newParticle._newlyCreated = true; newParticle._newlyCreated = true;
newParticle.setAge(0); // this guy is new! newParticle.setAge(0); // this guy is new!
} else { } else {
@ -346,15 +335,19 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe
// copy existing properties before over-writing with new properties // copy existing properties before over-writing with new properties
if (existingParticle) { if (existingParticle) {
newParticle = *existingParticle; newParticle = *existingParticle;
//qDebug() << "newParticle = *existingParticle... calling debugDump()..."; } else {
//existingParticle->debugDump(); // the user attempted to edit a particle that doesn't exist
qDebug() << "user attempted to edit a particle that doesn't exist...";
valid = false;
return newParticle;
} }
newParticle._id = editID; newParticle._id = editID;
newParticle._newlyCreated = false; newParticle._newlyCreated = false;
} }
// if we got this far, then our result will be valid
valid = true;
// lastEdited // lastEdited
memcpy(&newParticle._lastEdited, dataAt, sizeof(newParticle._lastEdited)); memcpy(&newParticle._lastEdited, dataAt, sizeof(newParticle._lastEdited));

View file

@ -168,7 +168,7 @@ public:
bool inHand = NOT_IN_HAND, QString updateScript = DEFAULT_SCRIPT, uint32_t id = NEW_PARTICLE); bool inHand = NOT_IN_HAND, QString updateScript = DEFAULT_SCRIPT, uint32_t id = NEW_PARTICLE);
/// creates an NEW particle from an PACKET_TYPE_PARTICLE_ADD_OR_EDIT edit data buffer /// creates an NEW particle from an PACKET_TYPE_PARTICLE_ADD_OR_EDIT edit data buffer
static Particle fromEditPacket(unsigned char* data, int length, int& processedBytes, ParticleTree* tree); static Particle fromEditPacket(unsigned char* data, int length, int& processedBytes, ParticleTree* tree, bool& valid);
virtual ~Particle(); virtual ~Particle();
virtual void init(glm::vec3 position, float radius, rgbColor color, glm::vec3 velocity, virtual void init(glm::vec3 position, float radius, rgbColor color, glm::vec3 velocity,

View file

@ -250,13 +250,14 @@ int ParticleTree::processEditPacketData(PACKET_TYPE packetType, unsigned char* p
// we handle these types of "edit" packets // we handle these types of "edit" packets
switch (packetType) { switch (packetType) {
case PACKET_TYPE_PARTICLE_ADD_OR_EDIT: { case PACKET_TYPE_PARTICLE_ADD_OR_EDIT: {
//qDebug() << " got PACKET_TYPE_PARTICLE_ADD_OR_EDIT... "; bool isValid;
Particle newParticle = Particle::fromEditPacket(editData, maxLength, processedBytes, this); Particle newParticle = Particle::fromEditPacket(editData, maxLength, processedBytes, this, isValid);
storeParticle(newParticle, senderNode); if (isValid) {
if (newParticle.isNewlyCreated()) { storeParticle(newParticle, senderNode);
notifyNewlyCreatedParticle(newParticle, senderNode); if (newParticle.isNewlyCreated()) {
notifyNewlyCreatedParticle(newParticle, senderNode);
}
} }
//qDebug() << " DONE... PACKET_TYPE_PARTICLE_ADD_OR_EDIT... ";
} break; } break;
// TODO: wire in support here for server to get PACKET_TYPE_PARTICLE_ERASE messages // TODO: wire in support here for server to get PACKET_TYPE_PARTICLE_ERASE messages