Getting game state of another server

Discussion in 'Spigot Plugin Development' started by su1414, Aug 12, 2018.

  1. I'm making a minigame with BungeeCord mode where one server is one arena. I need to check if game is running or restarting etc. I'm doing this using Plugin Messaging Channel, but there's one problem. It doesn't work when there's no players on the server, so I can't check if game is ready to play or is it still restarting. How should I check that? I thought about two ways. First - sockets. I know it is possible to ping a server and get MOTD and that could be an option, but I guess it's complicated and may cause errors. Second one is database. I would save the game state to database when it's changed and then I could get the state from lobby whenever I want to. I don't know if it's a good idea, but for sure easier than sockets. What do you think about that? Are there any better ways to do that?
     
  2. ummmmm……. one server per arena???
     
  3. That's not the point here. Even if it is multiple arena per server I still can't get the game state when no one is on the server.
     
    • Like Like x 1
  4. You could always use MySQL and store the 'Server Name' and it's 'Game state' if you really need it that badly, it would be pretty easy to update the MySQL table and input the server and it's game state, just simply grab all servers connected to the bungee-server and input them in a table and put it's default game state as whatever you'd like then when the arena is available you can update the servers game state to "OPEN" or whatever you'd like to say (just as an example)
     
  5. Ye, I know how would it be done, but I'm just asking if it is a good idea (it may cause lags etc) and if there is any better option to do that
     
  6. You could be stupid like me and host a webserver on each server so that it is overly complex to set up and has exteremely difficult to debug issues.

    Most likely you want to pick one which is the easiest to write the system for. There is an issue you want to solve if you want to have some sort of state ("running" "restarting"):
    • State Desync: State on main server becomes desynchronized because a server went down or failed to perform the state update
    Sockets
    • You can think the socket packets as events, so state stays consistent
    • State Desync: Timer task on main server can handle desync when the game should have already ended
    Database
    • Requires constant checking from the database to keep state consistent
    • Game State changes will require timestamps in the database to know if desync has occurred
    • State Desync: If a timestamp was too long ago and the game should have ended, handle desync.
     
    • Useful Useful x 1
  7. It shouldn't cause any lag (assuming that you know how to properly handle connections)
     
    • Agree Agree x 1
  8. So I'll probably use a database with addition of timestamps. Thank you very much for help!
     
  9. I built my network with MongoDB to support multiple games per server.
    I created a custom 'onGameCreate' event where it add its to the database, each time a player joins or the state changes, I update the field.
    Once the game is finished, I remove it from the database and wait for another one to start up.