ChunkCache question
#1
Hi,

in the past few weeks I was thinking a lot about orebfuscation and stuff and then I took a look into the original code of the orebfuscator. It turns out, that the plugin generates the obfuscated ores only ones the player loaded a chunk. It overrides the internal chunkcache. Until a player actually does something (e.g. breaks a block) it is not regenerated. That doesn't seem possible in MCServer because there is no part of the API that says chunkcache. Would it be possible to write an interface for that?
Here is the link: http://forums.bukkit.org/threads/sec-ore...-10.38385/
is this possible?
Reply
Thanks given by:
#2
There is no explicit chunk cache in MCS, because the entire cWorld is in fact a chunk cache.

If I were to write a plugin like this, I'd go about it this way:
- Install a post-generator hook that saves the entire chunk somewhere, and then processes it so that all the invisible blocks are ores.
- Install a player-digging hook that checks if the visibility has changed, and if so, restores the needed blocks from the "backup".
- In order to speed things up, I'd keep backups of the four chunks closest to the player loaded, so that the restoration process takes as little time as possible.

This will not be perfect, however, because the obfuscation cannot really process blocks on the chunk's edge - there is no neighbor data while generating. This could be worked around, if needed.
Reply
Thanks given by:
#3
Okay, you need to explain this a little bit more in detail:
- Are all these hooks available or do I have to create one of them
- Where should I save the data to? in a file or in a variable
- What kind of IDE do you prefer for lua?
Reply
Thanks given by:
#4
The hooks are already available: HOOK_CHUNK_GENERATED, HOOK_PLAYER_BREAKING_BLOCK.
There will be way too many files - one file for each chunk, and you need to take care of all of them, so that you can restore the world back once players start digging. I recommend saving each chunk as a .schematic file in a folder; make one folder per 32x32 chunks (so the path will be something like "SavedChunks/r.-1.0/ch.-2.5.schematic" for chunk [-2, 5])
I use ZeroBrane Studio - I wrote a plugin so that it can debug MCServer plugins directly while the server is running, and the entire thing is awesome. Set it up according to this guide: http://mc-server.xoft.cz/LuaAPI/SettingUpZeroBrane.html
Reply
Thanks given by:
#5
Why shouldn't I use HOOK_CHUNK_AVAILABLE? If I do so, the plugin can be also used on an existing server.
Also, is there a nice way of writing into a .schematic? What dataformat does it have?
Reply
Thanks given by:
#6
You can use that hook, but you need to remember if the chunk has already been modified or not, otherwise you'll save the obfuscated chunk and re-obfuscate it, thus losing all its data.
Reply
Thanks given by:
#7
Do you have an example of how I can convert multiple chunks into a cBlockArea object? And how can I calculate the global coordinate of a block using the chunks coords and the relx, rely of the block inside?
Reply
Thanks given by:
#8
Why would you need multiple chunks? Store just one - after all, only one chunk comes through the generator / loader hook at a time. Use the incoming cChunkDesc, it has a ReadBlockArea function that can read a cBlockArea from that description, and cBlockArea has a direct function to write the contents to a .schematic file.

The Rel coords are just that - relative to the chunk. So AbsoluteX = ChunkX * 16 + RelX etc. Going the other way round is a bit more difficult, you need to use math.floor() for the division, otherwise the calculation is wrong for the negative coords.
Reply
Thanks given by:
#9
Okay. This is exactly what I did. But at what time should I initialize the obfuscator? It keeps hanging up if I do it inside of the hook.
Reply
Thanks given by:
#10
What's "initialize the obfuscator"?
You should initialize the plugin normally - when it's loaded and its Initialize function called. And then you should obfuscate the chunk directly in cChunkDesc while processing the HOOK_CHUNK_GENERATED hook. You might need to optimize the obfuscating code, otherwise it might get slow and seem to have hanged.
Reply
Thanks given by:




Users browsing this thread: 7 Guest(s)