Sending messages when a player is not on a server?

Discussion in 'BungeeCord Plugin Development' started by ewized, Sep 2, 2013.

  1. I'm trying to add BunggeSupport for my eSuite plugin and I can figure a way to send it to the server even when on one is on it I don't know if there is a way or not. Or If i should check if the server is empty before sending it well here is my code.

    Send Code
    Code (Text):
        public void sendChatBungeeCord(Player player, String msg){
            try {
                ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
                DataOutputStream msgout = new DataOutputStream(msgbytes);
                msgout.writeUTF(msg);
                msgout.writeShort(msg.length());
                ByteArrayOutputStream b = new ByteArrayOutputStream();
                DataOutputStream out = new DataOutputStream(b);
     
                out.writeUTF("Forward");
                out.writeUTF("ALL");
                out.writeUTF("eChat");
                out.writeShort(msgbytes.toByteArray().length);
                out.write(msgbytes.toByteArray());
                Bukkit.getOnlinePlayers()[0].sendPluginMessage(CommandBook.inst(), "BungeeCord", b.toByteArray());
              } catch (Exception ex) {
                ex.printStackTrace();
              }
        }
    Receive Code
    Code (Text):
        @Override
        public void onPluginMessageReceived(String channel, Player player, byte[] message){
            if (!channel.equals("BungeeCord")) {
                return;
            }
     
            try {
                DataInputStream in = new DataInputStream(new ByteArrayInputStream(message));
                String subchannel = in.readUTF();
                short len = in.readShort();
                byte[] msgbytes = new byte[len];
                in.readFully(msgbytes);
                DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(msgbytes));
                if (subchannel.equals("eChat")) {
                    String msg = msgin.readUTF();
     
                    for (Player p : Bukkit.getOnlinePlayers()) {
                        p.sendMessage(msg);
                    }
                    Bukkit.getConsoleSender().sendMessage(ChatColor.stripColor(msg));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
     
        }
     
  2. I've heard there's no way to use Bungee plugin message if there's no players on the server, I've tried with forward to use it for custom events... but if the receiver have 0 players that doesn't work :'(.

    Use sockets and Thread :/
     
  3. I really dint want to mess with sockets, Guess I'll just have to check if the server has no players don't send it.
     
  4. There is a message to send to the bungee server that will return the number of players online, other than that, you could ping it, and get the online players.
     
  5. If the server have no players it does not receive the message, so this check is useless :p
     
  6. Ill see what I can figure out but what about a BungeeCore Plugin does any of that API will return a player amount if one are online?
     
  7. So what would be a good way if (for example) I want to have a list of all players and do not want to poll these information every time?
     
  8. Either store it in MySQL or do what hcherndon said to do.
     
  9. Okay but I want to store player-related information and make them available for plugins on all servers. Is there no way to get data stored globally so that different servers can access them?
     
  10. MySql again :D
     
  11. I don't think sql is a good idea when talking about things you need very often and very fast.

    Will there be any system that can cover global shared data or do we have to implement our own communication layer?
     
  12. Depending of what kinds of datas you want to share, some can be stored in a BungeeCord plugin, but the communication between the plugins need a shared database or usage of packets...

    For some datas you need to access very often the best is to stored that in objets, but that's data AND server dependant, the best way is to use SQL to store shared datas with all servers and load them when the player join only, after you use a simple HashMap with "PlayerName, CustomPlayerClass" and all the datas you need to load.
     
    • Like Like x 1
  13. As long as your Mysql database is local it will definitely be fast enough. Think about logblock it's making hundreds of calls a second to a Mysql dB without any issues

    Edit:Autocorrect -_-
     
    #13 bloodsplat, Sep 4, 2013
    Last edited: Sep 5, 2013
  14. I want to see that :D.

    I'm making a serveur with BungeeCord:
    1 Hub + X generated worlds with 1 server/world, those world have random specs (icedworld, superzombies etc..)
    For the moment all this servers are on the same Host (I5 2,88ghz / 16G ram) and the Mysql Database is on the server too, they use it to share informations when the player leave/join the world.

    Soon i'll run with some player to test the best efficient way to share those datas (local hashmap or sql request), I Know sql is fast but I'll test all my task/methode with the usual subtraction (start system current nano - end system current nano) tu be sure.

    With 2 players its ok... with 100 I'll dont know ^^

    PS: You mean logblock or logbook ?
    Cause LogBlock use AsyncThread to excute the longs operations, so you cant have any lag with that.
     
  15. MySQL isn't fast enough? That's funny.

    Every tick, (50 milliseconds), you could send a query to a database, get the result set within 500 nanoseconds, or .5 milliseconds.

    And even if it isn't localhost, if it is on the same subnet, it shouldn't take but 5 milliseconds. Which, hopefully you will have servers on the same subnet as your bungee instance.

    Pinging a minecraft server would take about 50 milliseconds.

    And how does it cause lag, I do some SQL in my main thread and it doesn't even touch performance. It would actually cause more CPU usage to put it into a separate thread.

    And if you think an AsyncTask can't cause lag, your life is a lie... Believe me.


    And bloodsplat MySQL can handle 100,000 Queries/s easy, and with it's native InnoDB it is said it can handle over 700,000. :p Food for thought.
     
  16. Thanks for this information so the OP have to use Mysql ^^