Hi Guys, i tried this: PHP: $this->getServer()->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "rank")), 1200); Which works fine, but when the function "rank" is executed in the CallBackTask, the server times out because the thread has paused - because there was too much processing time. I know why, its because of this: PHP: foreach(Server::getInstance()->getOnlinePlayers() as $donor){ it works sometimes , but when there are a lot of players , it doesnt. Now i know AsyncTask runs a separate thread, so that will prevent it. I looked on the docs and i saw this in the description of AsyncTask: Code: Detailed Description Class used to run async tasks in other threads. WARNING: Do not call PocketMine-MP API methods, or save objects from/on other Threads!! So how will i do this? Does that matter ^^ also, could you please include an example of how to do this? Like: PHP: $this->getServer()->getScheduler()->scheduleRepeatingTask(newAsyncTask(/*whatgoeshere*/)); Thanks
nice idea! Unfortunately what it does involves the PocketMine api... and AsyncTask will only work properly if it doesn't use the api. How would I do this?
its my rank system. It uses file_get_contents() . It works by: 1: On my server app, after the in app purchase is completed: 2: Http:get is sent (with url vaiables) eg: ?rank=<>&usr=<> 3: The "usr" variable is then written to a text file, depending what "rank" is. Eg: Vip.txt,vipplus.txt . 4:Last step: Checking if that player name is in either of the text files. what I have tried: OnJoin Check => laggy (lots of players would join very closely together) the example above was another attempt. Either, I can use a more efficient method (which I cant think of right now) or use an asyncTask. I was thinking about exploding the text files (to an array) and then foreaching them, but that would eventually stop working when more people donate...
if you want to read these text files on AsyncTask, just google the long method that doesnt envolves PocketMine APIs. inside onRun(), you do these stuffs here inside onCompletion(), you gather the result inside onRun() and do make PocketMine API calls.
Rather than search like that I would create a file "[a].txt" where "a" is the first letter of the user. Then I would write in there the user name and the rank. That way instead of having to look at all files to find the rank, you can just jump to the right letter. You could in theory write to a file called "username".txt that would just contain the rank of that user. Under Linux that would work fine. Under Windows that would be problematic once you have lots of users. You should read a little bit about hash tables. This is a classic problem that is resolved with hash tables.
I would store the file data in arrays with the keys and values being the usernames (for faster lookup). Then whenever a check was needed, the file modification times would be checked to make sure that the current arrays were up to date.
no, its one big text file- each username is separated by "<br>" or "\n". there are two files: vip and vipplus
Just to remind you, everyone can decompile your app and HTTP-GET that link with their browsers or cURL too. Hope you remembered to prevent it. Also, why don't you use a MySQL database instead? It may be faster/more convenient.
I have prevented it and would mysql really make that much of a difference? Also: I am a complete noob at setting up mysql... The panel is just confusing xD
mysql make things easier if things you're doing is done remotely. mysql server doesnt have a CP GUI for you to play with. It depends on what MySQL database manager software you are using that makes it "confusing" for you. Try PHPMyAdmin.
pocketmine is more confusing than using PHPMyAdmin for me well technically I use Adminer instead of it because its more lightweight and doesnt need crap loads of file. Its only a one file PHP script that you load into your web server
Command line is the best for me. Anything that requires a mouse or has a GUI (including MCPE) is confusing to me. Only command line is sensible to me xD