Solved Query

Discussion in 'Help' started by Fritures, Jun 15, 2019.

  1. Fritures

    Fritures Spider Jockey

    Messages:
    47
    Hello, so can you help me i want to use query with socket in nodejs but i don't know how to make a socket in nodejs
     
  2. Destroyer57

    Destroyer57 Zombie

    Messages:
    259
    I do this

    var net = require("net");
    function createSocket(socket){
    var s = socket || new net.Socket(); s.write("hello!");
    }
    exports.createSocket = createSocket;
     
  3. Fritures

    Fritures Spider Jockey

    Messages:
    47
    Okay but in socket i put the server ip 192.168.1.1:19132 ?
     
  4. Destroyer57

    Destroyer57 Zombie

    Messages:
    259
    Yes
     
  5. Fritures

    Fritures Spider Jockey

    Messages:
    47
    And for get, for example server's plugin, how i do ?
     
  6. Destroyer57

    Destroyer57 Zombie

    Messages:
    259
    Idk how to query plugins sorry
     
  7. Fritures

    Fritures Spider Jockey

    Messages:
    47
    Oh
     
  8. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,161
    GitHub:
    Thunder33345
    just use mcpe ping who wanna be bother re implementing query
    you dont seem to even know the basics, i dont recommend you trying to reinvent it

    https://runkit.com/thunder33345/mcpe-ping-demo
    Code:
    var mcpePing = require("mcpe-ping-fixed")
    mcpePing('play.lbsg.net','19132', function(err, res) {
        if(err) {
            console.log(err) 
        }else{
            console.log(res)
        }
    })
    
    hint: learn about node package manager in order to get mcpe ping
     
  9. TheDeibo

    TheDeibo HBIDamian Staff Member Poggit Reviewer

    Messages:
    348
    GitHub:
    thedeibo
    I know this isn't directly socket, but use services that are already out there?
    https://api.mcsrvstat.us/2/play.lbsg.net:19132

    Pros:
    - It's very easy to use
    - It's set up for you
    - Works without requiring node. :3

    Con:
    - It doesn't do BDS (Bedrock Dedicated Server) yet.
     
  10. Fritures

    Fritures Spider Jockey

    Messages:
    47
    Okay it's really clean but i had just a few question, ...
    First question ; what's "dedicaced servers"
    Second question ; you don't learn an other method with node ? Because i want to make a discord's bot, and if a user send "$mcsrvinfo play.lbsg.net:19132" my bot can go with the socket to get the infos of this server.
    Just with solo a node socket method and don't use api or in last resort.
     
  11. TheDeibo

    TheDeibo HBIDamian Staff Member Poggit Reviewer

    Messages:
    348
    GitHub:
    thedeibo
    "Bedrock Dedicated Server" is this https://minecraft.gamepedia.com/Bedrock_Dedicated_Server
    (Tl;dr: it's Minecraft's official vanilla server software for Bedrock edition)

    I did put together the code using the api if you want it. It works for me on my discord bot. :D

    here is a pretty rubbish code that works that I put together. :3
    Code:
    const request = require('request')
        , url = 'https://api.mcsrvstat.us/2/' + escape(args.join(" "))
    request(url, (error, response, body) => {
        if (!error && response.statusCode === 200) {
            const mcpeResponse = JSON.parse(body);
            if (mcpeResponse.debug.query == true) {
                const embed = new Discord.RichEmbed()
                    .setTitle("MCPE Server Query")
                    .setColor("RANDOM")
                    .addField("IP:", mcpeResponse.ip, true)
                    .addField("Port:", mcpeResponse.port, true)
                    .addField("Online:", mcpeResponse.online, true)
                    .addField("MOTD:", mcpeResponse.motd.clean, false)
                    .addField("Players:", mcpeResponse.players.online + "/" + mcpeResponse.players.max, true)
                    .addField("Version", mcpeResponse.version, true)
                    .addField("Software:", mcpeResponse.software, true)
                    .setTimestamp()
                    .setFooter('ZOINKS! - api.mcsrvstat.us', 'https://i.imgur.com/16KKVW8.png')
                message.channel.send(embed);
            } else {
                message.channel.send("Error: Server not found. \nPlease make sure the server is turned on, and query is enabled!");
            }
        } else {
            console.log("Got an error: ", error, ", status code: ", response.statusCode)
        }
    })
    
     
  12. Fritures

    Fritures Spider Jockey

    Messages:
    47
    Thanks i going to use that
     
  13. TheDeibo

    TheDeibo HBIDamian Staff Member Poggit Reviewer

    Messages:
    348
    GitHub:
    thedeibo
    It actually works for Java edition too. It’s not limited to MCPE
     

Share This Page

  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.