1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How can i send a message for all players in multiple server?

Discussion in 'Development' started by LewBr, Feb 1, 2018.

  1. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    How can i send message broadcast to all network that i have?
    Like i want to do /say and get all my registered servers to make a signal and send the message for all the players on the network?

    (Please don't say me to use Hormones, because has too many bugs and too many things, and i just want to broadcast..)
     
  2. kenygamer

    kenygamer Banned Banned

    Messages:
    106
    GitHub:
    kenygamer
    You could create an API, and your servers would periodically fetch data from it.
     
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Use hormones' issue tracker :p

    Anyway, have your worked with sockets or databases?
     
  4. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    With databases i am working too much, but sockets never, can you tell me more about that all?
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I'd rather you use a database so you get how it all works. You can proceed to sockets then if you think there's a significant delay in messages. But then again, hormones already does that.
    What kind of database do you use the most?
     
    LewBr likes this.
  6. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    I use mysqli database, but can you tell me how to connect the servers and send a message to a player in $player->sendMessage but on sockets? and witch is faster to do, database or sockets? I think sockets is more easier to do then database
     
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Sockets isn't easy and databases make use of sockets. It will be faster with sockets, no doubt. You'll need to learn about Threads and Workers before proceeding.

    You have to dedicate a Worker thread on server startup that will check for incoming messages the whole time the server is running -- this is the only hard part.

    Another way would be creating custom packets and handling the packet on both servers. That way you are making use of an already open socket and won't need to worry about threading, opening sockets, closing sockets etc (I doubt whether this one is possible).
     
    Jack Noordhuis likes this.
  8. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Omg, that's so crazy it's too much complex for me, someone should create something like Bukkit that connects all servers easier and run all functions of the software like send message and etc..

    Anywars, but what about that code, what they do?
    This connect each server together
    PHP:
    if(!($sock socket_create(AF_INETSOCK_STREAM0)))
    {
        
    $errorcode socket_last_error();
        
    $errormsg socket_strerror($errorcode);
       
        die(
    "Couldn't create socket: [$errorcode$errormsg \n");
    }
     
    echo 
    "Socket created \n";
     
    if(!
    socket_connect($sock '0.0.0.0' 19132))
    {
        
    $errorcode socket_last_error();
        
    $errormsg socket_strerror($errorcode);
       
        die(
    "Could not connect: [$errorcode$errormsg \n");
    }
     
    echo 
    "Connection established \n";
     
    but what about that?
    PHP:
    $message "YourMessage";

    //Send the message to the server
    if( ! socket_send $sock $message strlen($message) , 0))
    {
        
    $errorcode socket_last_error();
        
    $errormsg socket_strerror($errorcode);
       
        die(
    "Could not send data: [$errorcode$errormsgPHP_EOL);
    }

    echo 
    "Message send successfully" PHP_EOL;
    Is not there an easier way of all that? ;-; I just want to send a message broadcast for all players in all the network, whitout too much like Hormones..
     
  9. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Hormones is an abuse. You shouldn't be using databases for message queues/buffers. I initially made it as a proof of concept, but it ended up getting too popular because of how easy it is to install (MySQL setup is trivial; a custom central gateway isn't).
     
    Last edited: Feb 6, 2018
    Lewis Brindley and LewBr like this.
  10. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Yeah i have thinking to do that all the time, but how did you say "THIS IS HIGHLY UN-RECOMMENDED!!! PLEASE TAKE THIS WARNING AND DON'T DO THIS. MAY CAUSE EXTREME PERFORMANCE ISSUES, AND I'M NOT TO BE HELD RELIABLE.".
     
  11. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Because constantly polling a database for changes isn't what they were designed for.
     
  12. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    What about that? https://www.spigotmc.org/threads/tutorial-handling-data-through-multiple-servers.959/
    Can i do on pocketmine?
     
  13. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Which method are you referring to?
    We will most likely never officially add this to PocketMine. First of all, we don't have an official bungee cord service. Second, how bungee cord works is quite incompatible with how our API is heading towards (where everything is very synchronous, including plugin data).
    This will however be inefficient if you have an enormous network, e.g. one with 100 servers.

    I personally find it better to have a middleman server instead of directly connecting different servers, because then you only need to set one address in the config of each server. As I said, if you have 100 servers, every time you change a certain server's IP or port, you need to edit your config 100 times. If you use a middleman (kind of like the MySQL in Hormones), you just need to update it once, and it can be done automatically. You can also setup more specific synchronization behaviour instead of just randomly passing messages at an inconsistent pace. (This is something Hormones cannot do either)
     
    Lewis Brindley likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.