Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Mysql query

Comments in 'Plugin Development' started by Creeperface, Feb 20, 2016.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    when i write something into MySQL it is easy do it async but how to do this when i want to get something from mysql?

    e.g. on PreLoginEvent i must check player's rank and if server is full and player hasn't any rank, kick player from server. but how?
    PEMapModder likes this.
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    SELECT whatever FROM table WHERE name="whatevername"
    For example. You should tell us your table construction
    Last edited: Feb 20, 2016
  3. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    no i mean how to do this async
    PEMapModder likes this.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Threading isn't hard. How to handle threading properly is the thing that requires more cerebrum activity. The server full problem is an example.

    In the LegionPE-Theta-Base plugin, I store the rank of each user in a database. If the player was not registered, or if the player is a VIP, he can bypass the server full limit. (Look at LoginQuery.php and BaseListener.php in specific)
    So, how to do this? I must not cancel the event. Otherwise, the player will be kicked all the time. In iMCPE plugin, @iJoshuaHD made it such that player data are cached, so the first time player joins at server full he gets kicked, but the async query is dispatched, and the result is cached, so the second time he rejoins, the plugin knows that he is VIP from the cache, and lets him join.
    But this is still not the best solution.
    So, why not just let the player join anyway? Several ticks later, the AsyncTask got a result, and if the plugin realizes that the player is in fact normal and the server player count exceeds maximum, kick the player.
    Indeed, the player joined for a few ticks. But that is the method of the lowest cost I can think of.
    matthww likes this.
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
  6. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    im saving mysql instance in static variable but when i try to query async task lags.. :/
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Static = thread-local.
    A static property cannot be shared among different threads.
    You should create a MySQLi instance for each thread. Look at HereAuth for example how.
    Creeperface and matthww like this.
  8. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    yes i looked but in steadfast isn't method saveToThreadStore(). and can i use static methods?
  9. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    I use that, and due to the tiny delay, It looks to the client as if the event was cancelled. Also because it takes time to join the server, the player would most likely be kicked before there is a chance for it to spawn.
  10. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    And can i use static methods?
  11. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    I think i can
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Static methods aren't a problem; they are just like namespace functions. However pthreads understands static class properties as thread local, so it won't work.
  13. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    but if there are more players on the server so tasks don't run :/
  14. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    or don't complete and players can not login
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    These two are not relevant. No matter what your server max player limit is, you still have to run the same amount of queries because the same amount of join attempts will be there. As long as your queries do not hang the async workers for too long (like shorter than the average period between two player joins), it is not really a problem.

    My suggestion was, just let players join. Only kick them after you have confirmed that they don't have the permission to stay. It is not hard at all if you do things properly.
  16. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    thx i solved it :D task sometimes creates an infinite loop so worker can not run other tasks. and why i have only 2 workers if i set worker amount to 4? and i have 4 core CPU
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Did you explicitly set to 4?

Share This Page

Advertisement