Giter Site home page Giter Site logo

thebluekinglp / minecraft-auth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eluinhost/minecraft-auth

0.0 1.0 0.0 244 KB

PHP Library for running a 'fake' Minecraft server that checks auth and kicks on connect

License: GNU General Public License v3.0

PHP 100.00%

minecraft-auth's Introduction

minecraft-auth

SensioLabsInsight

PHP Library for running a 'fake' Minecraft server that checks authentications are correct with the session servers and kicks the player afterwards. Has a callback to change the disconnect message. I use if for verification codes to link minecraft accounts without needing them to input their password.

Install

Install via composer by adding "publicuhc/minecraft-auth": "dev-master" to your composer require.

Dependencies: Will be handled by composer on install, requires the PHP mcrypt extension to run. (You can install this on linux with apt-get install php5-mcrypt or similar)

Example Usage

use PublicUHC\MinecraftAuth\AuthServer\AuthServer;

$server = new AuthServer(25565, '0.0.0.0');

$server->on('login_success', function($username, $uuid, DisconnectPacket $packet){
    echo "USERNAME: $username, UUID: $uuid\n";
    $packet->setReason("USERNAME: $username, UUID: $uuid");
});

$server->on('status_request', function(StatusResponsePacket $packet) {
    $packet->setDescription('test server')
        ->setMaxPlayers(10)
        ->setOnlineCount(1000)
        ->setVersion('1.8+')
        ->setProtocol(47);
});

$server->start();

Explanation

new AuthServer(25565, '0.0.0.0');

Creates a new auth server to bind on the port 25565 and on all interfaces (0.0.0.0). If second parameter is ommited it will bind to 127.0.0.1 for localhost connections.

$server->on('login_success', function($username, $uuid, DisconnectPacket $packet){
    echo "USERNAME: $username, UUID: $uuid\n";
    $packet->setReason("USERNAME: $username, UUID: $uuid");
});

This is the login_success event. It is called whenever a successful connection has been made. Username is the username of the client connecting, UUID is the minecraft UUID (without -s). $packet is a DisconnectPacket object that will be sent to the client after the event. Use setReason (to set an array/string reason that will be json encoded before sending) or setReasonJSON (to set a pre-encoded json string).

$server->on('status_request', function(StatusResponsePacket $packet) {
    $packet->setDescription('test')
        ->setMaxPlayers(10)
        ->setOnlineCount(1000)
        ->setVersion('1.8+')
        ->setProtocol(47);
        ->setOnlinePlayers([
            [
                'name' => 'Eluinhost',
                'id'   => '000000000000-0000-0000-0000-00000000'
            ]
        ]);
});

This is the status_request event. It is called whenever a client requests data for the server list.

->setDescription(string); - Sets the description that shows up in the server list
->setMaxPlayers(int) - the number after the / on the list
->setOnlineCount(int) - the number before the / on the list
->setVersion(string) - If the client is connecting on a different protocol this version number will show instead of min/max players
->setProtocol(47) - The protocol version to set to, we only accept 47 so either set this to 47 or leave it out ->setOnlinePlayers(array) - An array of player names to show when hovering over the online count. For array format check the PHPDoc comment
->setFavicon(string) - The image in text format (i.e. data:image/png;base64,DATAHERE)

All of the method can be ignored. If they are not set the following will be set instead:

->setDescription(string); - Default: §4▁§e▂§4▃§e▄§4▅§e▆§4▇§e█ §4§l PHPAuthServer §e█§4▇§e▆§4▅§e▄§4▃§e▂§4▁ §c▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
->setMaxPlayers(int) - Default: -1
->setOnlineCount(int) - Default: -1
->setVersion(string) - Default: 1.8+ ->setProtocol(47) - Default: 47 ->setOnlinePlayers(array) - Default: []
->setFavicon(string) - Default: null (no favicon)

Due to the single thread nature of PHP all events will be blocking other code. If you run any long running processes in here it will stop processing other connections until it is complete. Either keep computation low or fork processes to run long running code.

`$server->start()`

Starts the server, nothing after this method will be called as it blocking, make sure to run everything you need before this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.