dev-lancer / mc-pack
The library is designed to integrate the minecraft server with the website.
Installs: 1 029
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.4
- ext-json: *
- dev-lancer/minecraft-motd-parser: ^1.0
- dev-lancer/minecraft-rcon: ^1.0
- dev-lancer/minecraft-status: ^3.0
- phpseclib/phpseclib: ^2.0
- symfony/config: ^5.4
- symfony/polyfill-php83: ^1.30
- symfony/property-access: ^5.4
- symfony/serializer: ^5.4
- xpaw/php-minecraft-query: ^4.0
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-10-26 19:48:36 UTC
README
Installation
This library can installed by issuing the following command:
composer require dev-lancer/mc-pack
Query
This method uses GameSpy4 protocol, and requires enabling query
listener in your server.properties
like this:
enable-query=true
query.port=25565
Rcon
This method allows you to send commands, it is used in item shop, and requires enabling rcon
listener in your server.properties
like this:
enable-rcon=true
rcon.port=25575
rcon.password=pass
Example
Query & Rcon
It enables downloading basic server information and sending commands.
<?php require 'vendor/autoload.php'; use DevLancer\MCPack\ConsoleRcon; use DevLancer\MinecraftStatus\Query; $info = new Query("some.minecraftserver.com", 25565); $info->connect(); $console = new ConsoleRcon("some.minecraftserver.com", 25575, "pass", 3); $console->connect(); $players = $info->getCountPlayers(); echo $players . "/" . $info->getMaxPlayers(); $console->sendCommand("bc MCPack");
Look here for Query
Look here for RCON
ServerManager with SSH
It enables downloading basic server information, sending commands and server management.
<?php require 'vendor/autoload.php'; use DevLancer\MCPack\ConsoleRcon; use DevLancer\MCPack\Manager\ServerManager; use DevLancer\MCPack\Sftp\Sftp; $host = "some.minecraftserver.com"; $sftp = new Sftp($host); $sftp->login("username", "password"); $server = new ServerManager($sftp, 25565); $path = "path/to/minecraft/server.jar"; if(!$server->isRunning()) { if ($server->run(["-Xmx1G"], $path)) echo "server started"; }
Server logs
This class allows downloading logs from the server.
<?php require 'vendor/autoload.php'; use DevLancer\MCPack\Logs; use DevLancer\MCPack\Sftp\Sftp; $host = "some.minecraftserver.com"; $sftp = new Sftp($host); $sftp->login("username", "password"); $path = "path/to/minecraft/logs/latest.log"; $logs = new Logs($sftp, $path); echo implode("<br />", $logs->getLogs(true));
Properties
<?php require 'vendor/autoload.php'; use DevLancer\MCPack\Manager\PropertiesManager; use DevLancer\MCPack\Sftp\Sftp; $sftp = new Sftp("some.minecraftserver.com"); $sftp->login("username", "password"); $manager = new PropertiesManager("path/to/minecraft/server.properties", $sftp); $properties = $manager->getProperties(); $properties->setRconPassword("new-password"); $manager->saveProperties($properties);
Motd
<?php require 'vendor/autoload.php'; use DevLancer\MCPack\Motd; use DevLancer\MinecraftStatus\Ping; $host = "some.minecraftserver.com"; $info = new Ping($host, 25565); $info->connect(); $motd = new Motd($info); $motd->sendRequest(); echo $motd->getResponse(Motd::RESPONSE_HTML);
Look here