Magikcraft / product-board

Release Notes for Magikcraft - what's new and noteworthy. Also: open issues or feature requests here.
https://www.magikcraft.io
1 stars 0 forks source link

Problem with spell syncing #44

Closed jwulf closed 6 years ago

jwulf commented 6 years ago

Observed while Xx_MEDIARITE_xX was doing a video. Reproduced on my machine.

To reproduce:

  1. Start with the fly spell in your spellbook.
  2. Rename your spell fly to ultrafly and save
  3. Create a new spell and paste the fly spell in
  4. Click Save in spellbook
  5. Observe message: “Go to Minecraft and type /cast fly
  6. Go to Minecraft
  7. Type in /cast fly
  8. Observe output: You do not have the spell fly
  9. Go to the spellbook, rename that spell to f
  10. Click Save in spellbook
  11. Observe message: “Go to Minecraft and type /cast f
  12. Go to Minecraft
  13. Type in /cast f
  14. Observe message Volare!
  15. Observe levitation effect

Part 2

  1. Go to Minecraft
  2. Type in /cast ultrafly
  3. Observe message Volare!
  4. Observe no levitation effect.
triyuga commented 6 years ago

Was able to replicate locally. It is due to some faulty handling in the endpoint filewriter cache around deleting and updating files.

This bug would have sometimes manifested as an intermittent file syncing bug!

Anyways, I have deleted the filewriter, and replaced it with a simple method on the main User class:

https://github.com/jwulf/play.magikcraft.io-endpoint/commit/4c53112f32b86fb4b5ceedd3efb0f446d26a9fe9

    writeFilesToFileSystem() {
        // Add or update files.
        this.files.forEach(file => {
            const prevFile = this.prevFiles.find(f => `${f.name}.${f.ext}` === `${file.name}.${file.ext}`);
            const isNew = (!prevFile);
            const hasChanged = (prevFile && file.changed !== prevFile.changed);

            if (isNew) {
                // write new file
                fs.writeFileSync(`${SPELLPATH}/${this.minecraftUsername}/${file.name}.js`, this.transpileFileContent(file));
                debug(`Added file: ${this.minecraftUsername}/${file.name}.js`);
            } else if (hasChanged) {
                // delete old version of file.
                fs.removeSync(`${SPELLPATH}/${this.minecraftUsername}/${file.name}.js`);
                // write new version of file
                fs.writeFileSync(`${SPELLPATH}/${this.minecraftUsername}/${file.name}.js`, this.transpileFileContent(file));
                debug(`Updated file: ${this.minecraftUsername}/${file.name}.js`);
            }
        });

        // delete files that no longer exist.
        this.prevFiles.forEach(file => {
            const stillExists = this.files.find(f => `${f.name}.${f.ext}` === `${file.name}.${file.ext}`);
            if (!stillExists) {
                fs.removeSync(`${SPELLPATH}/${this.minecraftUsername}/${file.name}.js`);
                debug(`Deleted file: ${this.minecraftUsername}/${file.name}.js`);
            }
        });
    }

Deploying now!

triyuga commented 6 years ago

This is now fixed on the develop server.

I have observed some additional strange behavior... ATTN: @jwulf After deleting a spell, I can still cast it! After deleting I check the endpoint file system and the spell is gone, as expected. The logs even say so:

screen shot 2017-11-27 at 1 54 46 am

However, I can still cast the spell!

It seems that the spell engine, inside the plugin, has some kind of cache...

Anyways, should not cause too much trouble to users, as if I recreate the spell, the "cached" version gets overwritten.