Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Plugin making help

Comments in 'Plugin Development' started by Mclover152, May 17, 2014.

  1. Mclover152
    Offline

    Mclover152 Active Member

    Joined:
    Apr 26, 2014
    Posts:
    64
    Minecraft User:
    mclover152
    I have a question. If I want to determine an IP address of a user and tell the console to Run the SendTo function: $ip, what is $ip equal to. So how do i know a users IP address in a function or variable?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $player->getAddress() (new API)
  3. Mclover152
    Offline

    Mclover152 Active Member

    Joined:
    Apr 26, 2014
    Posts:
    64
    Minecraft User:
    mclover152
    But whats the function for a command where you want to get a players ip? Example:
    /getip <username>
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    $name = ...;
    $player ServerAPI::request()->api->player->get($name);
    $address $player->ip;
  5. Mclover152
    Offline

    Mclover152 Active Member

    Joined:
    Apr 26, 2014
    Posts:
    64
    Minecraft User:
    mclover152
    What do i put in replace for new API?
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    $name = ...;
    $player Server::getInstance()->getPlayer($name);
    $ip $player->getAddress();
  7. Mclover152
    Offline

    Mclover152 Active Member

    Joined:
    Apr 26, 2014
    Posts:
    64
    Minecraft User:
    mclover152
    So if i wanted to set the command IPCHECK to the function IPCHECK i would put that code as the function for the function IPCHECK?
  8. Mclover152
    Offline

    Mclover152 Active Member

    Joined:
    Apr 26, 2014
    Posts:
    64
    Minecraft User:
    mclover152
    I put in the code you said and when i do /IPCHECK mclover152, it just displays a line in chat with nothing. Console view:
    [Server] 02:50:30 [INFO]
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If you don't know how to return chats in commands, look at the tutorials.
  10. Mclover152
    Offline

    Mclover152 Active Member

    Joined:
    Apr 26, 2014
    Posts:
    64
    Minecraft User:
    mclover152
    Ok its working, the problem was i wasn't doing the cmd in game. I have 1 question. When I did /IPCHECK it said 192.168.1.(private). How do i make it say my real ip. If im correct, 192.168.1.(private) is my device gateway. How do i make it display my router ip?
  11. Mclover152
    Offline

    Mclover152 Active Member

    Joined:
    Apr 26, 2014
    Posts:
    64
    Minecraft User:
    mclover152
    Oh and when i say router ip, i dont mean 192.168.1.1. I mean the ip that would be my server IP address if portforwarded. (not my server ip, that was an example)
  12. Tuff
    Offline

    Tuff Active Member

    Joined:
    Jan 25, 2014
    Posts:
    203
    Minecraft User:
    Roboroug2
    You mean external ip?
    You are correct in your assumption that 192.168.0.(private) is your internal ip.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Wait... Do you want to check your server's external IP or a player's IP?
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Utils::getIP()

    or Utils::getIP(true) if you want to reload
  15. Mclover152
    Offline

    Mclover152 Active Member

    Joined:
    Apr 26, 2014
    Posts:
    64
    Minecraft User:
    mclover152
    No my server ip was an example. When i run cmd, it says 192.168.1.(im not displaying this part of the ip) i want it to say my real ip which is 76.14.128.(dont want to display this either).
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It only shows that when you connect via "External server". If you connect by tapping the blue button, the IP is 192.168.xx, and if you ban IP it is also this IP banned not your external IP.
  17. Mclover152
    Offline

    Mclover152 Active Member

    Joined:
    Apr 26, 2014
    Posts:
    64
    Minecraft User:
    mclover152
    Ok, can I make it display my real IP address which is 76.14.128.(i really dont wanna tell everyone my full ip)?
  18. Tuff
    Offline

    Tuff Active Member

    Joined:
    Jan 25, 2014
    Posts:
    203
    Minecraft User:
    Roboroug2
    This querys a website to get your external ip, and spits it out in a variable.

    PHP:
    $externalContent file_get_contents('http://checkip.dyndns.com/');
    preg_match('/\b(?:\d{1,3}\.){3}\d{1,3}\b/'$externalContent$m);
    $externalIp $m[0];
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    As I said, Utils::getIP() already does that
    https://github.com/PocketMine/PocketMine-MP/blob/master/src/utils/Utils.php line 69
  20. Tuff
    Offline

    Tuff Active Member

    Joined:
    Jan 25, 2014
    Posts:
    203
    Minecraft User:
    Roboroug2

Share This Page

Advertisement