I am currently thinking about how I would generate an ID or integer (unique) for every faction I create. I am trying to avoid the autoincrement field in SQLite, but can't seem to think of a better way. Any ideas?
increment, or a random and very long string to avoid collisions you can have meta.json {nextcount:10} and increment that slowly, if you want to increment without autoincrement
You could alternatively just use a hash of a combination of - say - faction name + faction owner or something.
hope no one tried an timing attack to generate two or more guilds on the same time to break the system i dont think using only time is good enough
yea, only using microtime is probably bad. but there is a soloution: sleep 1ms! (or more simply: only process one creation per tick)
If only microtime is uesd, it is very unreliable, especially if the server becomes very popular and you have multiple servers accepting faction creation simultaneously (where not even CPU performance assumption is reliable). In addition, microtime is not an integer, and if you multiply it with 1e+9, you have to truncate the top part of the timestamp, which makes it just a random integer (but less random than random_int()) Generally, a random 64-bit integer is reliable enough. So, you will get struck by a lightning before you get 20 million factions created. How do you increment it "slowly"? This sounds worse than using auto_increment. Auto-increment is not really that bad. If you don't want to populate the whole row before getting the ID, you may consider using two separate tables (one table with auto_increment, another table with factionId as the foreign key to the auto_increment row). Adding a current timestamp salt is more reliable if you don't want a duplicate ID when the owner recreates the faction after deletion.
How do you generate a random 64-bit integer in PHP? I googled and saw some people combining a few calls to mt_rand.
Use random_bytes(8), added in PHP 7. Or simply use random_int(), since PocketMine supposedly only runs in 64-bit environments.