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) {
//qDebug() << "Particle::fromEditPacket() length=" << length;
Particle Particle::fromEditPacket(unsigned char* data, int length, int& processedBytes, ParticleTree* tree, bool& valid) {
Particle newParticle; // id and _lastUpdated will get set here...
unsigned char* dataAt = data;
processedBytes = 0;
@ -304,9 +301,6 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe
int octets = numberOfThreeBitSectionsInCode(data);
int lengthOfOctcode = bytesRequiredForCodeLength(octets);
//qDebug() << "Particle::fromEditPacket() lengthOfOctcode=" << lengthOfOctcode;
//printOctalCode(data);
// we don't actually do anything with this octcode...
dataAt += lengthOfOctcode;
processedBytes += lengthOfOctcode;
@ -323,8 +317,6 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe
// special case for handling "new" particles
if (isNewParticle) {
//qDebug() << "editID == NEW_PARTICLE";
// 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
uint32_t creatorTokenID;
@ -332,11 +324,8 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe
dataAt += sizeof(creatorTokenID);
processedBytes += sizeof(creatorTokenID);
//qDebug() << "creatorTokenID:" << creatorTokenID;
newParticle.setCreatorTokenID(creatorTokenID);
newParticle._newlyCreated = true;
newParticle.setAge(0); // this guy is new!
} else {
@ -346,15 +335,19 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe
// copy existing properties before over-writing with new properties
if (existingParticle) {
newParticle = *existingParticle;
//qDebug() << "newParticle = *existingParticle... calling debugDump()...";
//existingParticle->debugDump();
} else {
// 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._newlyCreated = false;
}
// if we got this far, then our result will be valid
valid = true;
// 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);
/// 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 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
switch (packetType) {
case PACKET_TYPE_PARTICLE_ADD_OR_EDIT: {
//qDebug() << " got PACKET_TYPE_PARTICLE_ADD_OR_EDIT... ";
Particle newParticle = Particle::fromEditPacket(editData, maxLength, processedBytes, this);
storeParticle(newParticle, senderNode);
if (newParticle.isNewlyCreated()) {
notifyNewlyCreatedParticle(newParticle, senderNode);
bool isValid;
Particle newParticle = Particle::fromEditPacket(editData, maxLength, processedBytes, this, isValid);
if (isValid) {
storeParticle(newParticle, senderNode);
if (newParticle.isNewlyCreated()) {
notifyNewlyCreatedParticle(newParticle, senderNode);
}
}
//qDebug() << " DONE... PACKET_TYPE_PARTICLE_ADD_OR_EDIT... ";
} break;
// TODO: wire in support here for server to get PACKET_TYPE_PARTICLE_ERASE messages