Would like advice on networking please

Discussion in 'Spigot Plugin Development' started by Rixterz, Jun 7, 2016.

  1. Hi

    Firstly I'd like to say I had my thread locked on Bukkit Forums by a very nasty moderator who said Bukkit does not support Bungeecord. I'm not asking for you to support anything, and in fact my plugins run fine on my servers. So...

    I have a few servers all connected with Bungeecord. I would like to remake my old RankManager plugin, which gives players a prefix such as [VIP]. However, the old version worked by reading from the player's file and getting their "rank" property. My concern was that if two plugins attempted to read from the file at the same time, one would result in an error due to the file being in use. So I'm going to move over to a database instead, and using a queueing system, where one server is used as the file server, and reads from the files and relays information from them to the servers requiring the information. For example, if I join the server "game1", it will send a request to the file server. It will then read my rank, and pass it back to game1 so it can give me my prefix.

    So in terms of advice, I would like to know:

    1) Is this the best approach? There will hopefully be multiple hundreds/thousands of players online in the future
    2) Would it be best to get the servers to communicate through Bungeecord or should I write my own TCP code?
    3) How would I wait for the server's response? That would ideally implement a timeout feature as well

    Thanks for your time

    -Rix
     
  2. 1) Redis & MySQL. Ask BungeeCord everytime, which'll read from a MySQL/MariaDB/etc database. https://github.com/xetorthio/jedis
    2) Bungee. If you have more instances, connect them to a cluster pc with redis.
    3) Just make sure the database is up. Timeout? Give all players a bonus due the inconvinience.
     
  3. Sorry about the Bukkit staff, 100% stupid and toxic.

    To answer your question, I think MySQL sounds like the best way to go, but if you can figure out how to setup ranks with bungee that would be a more reliable setup (I think).
     
    • Like Like x 1
    • Agree Agree x 1
  4. MiniDigger

    Supporter

    you can only send plugin messages through bungee when players are connected.
    if you want to send a message from server1 to server2, then you need at least one player on both servers. so this would not work like you imagined it.
    If you want a dedicated file server, making it a minecraft server is overkill. just write a small java program and let it communicate with your game servers using netty or something like that.

    But I generally don't think that you should be running a dedicated server for such things. Thats why we have database servers. just setup a database that all servers can access and then the servers can query the prefixes from there. But you feel like that one database server would not handle the load, make a cluster of multiple database servers.
     
  5. With 3), i meant for example on the playerjoinevent:
    Code (Text):

    String prefix = ...?
    e.setJoinMessage(prefix + e.getPlayer().getName());
    Would I need to use synclock or something?
     
  6. My concern though would be if there were read/writes all the time; if there's latency issues then a plugin may read old data because the write hasn't gone through yet
     
  7. MiniDigger

    Supporter

    well, you will get the prefix async to the main thread and attach it later.
    if you want to show join messages with the prefix, don't send a join message in the event handler but send it when you received the prefix from the db server.
     
  8. Serializator

    Supporter

    I don't think that Netty is even necessary, it is possible to use Redis PUB/SUB for the server to server communication.

    And to address the issue with waiting for a response, the best is probably to use a callback of some sort, you could do it by starting an asynchronous task and getting back on the main thread by starting a synchronous task, but this will become quite ugly to read depending on how many times you have to do it.
     
  9. MySQL looks ridiculously complicated. Running a service on my machine, servers and all sorts... no thanks.

    Would a .mdb or .accdb do fine?
     
  10. Serializator

    Supporter

    You will have to put in some effort if you want those people to play your server and your server to be able to handle that kind of stress.
    SQL isn't that hard to learn, once you understand the syntax it will probably depend on your logical thinking capacity.
    My personal recommendation is the W3Schools tutorial, it explains SQL in a simplistic way and you can learn it at your own pace.