Skip to content

Commit

Permalink
Add unlimited amount of Commands
Browse files Browse the repository at this point in the history
  • Loading branch information
xXSchrandXx committed Dec 7, 2021
1 parent 9519a23 commit b0aaa03
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 305 deletions.
15 changes: 11 additions & 4 deletions files/lib/acp/form/MinecraftConsoleForm.class.php
Expand Up @@ -94,8 +94,9 @@ public function readFormParameters()
{
if (isset($_POST['command'])) {
$tmpResponse = [];
$command = $_POST['command'];
try {
$tmpResponse = $this->connection->call($_POST['command']);
$tmpResponse = $this->connection->call($command);
} catch (MinecraftException $e) {
$this->errorType = 'cantConnect';
if (\ENABLE_DEBUG_MODE) {
Expand All @@ -106,9 +107,15 @@ public function readFormParameters()
$this->errorType = 'cantConnect';
} else {
if ($tmpResponse['Response'] == 0) {
$this->response = $tmpResponse['S1'];
if (!empty($tmpResponse['S2'])) {
$this->response = $this->response . '\n' . $tmpResponse['S2'];
foreach ($tmpResponse as $key => $value) {
if ($key == 'Response' || $key == 'Lenght') {
continue;
}
if ($this->response == null) {
$this->response = $value;
} else {
$this->response .= '\n' . $value;
}
}
} else {
$this->errorType = 'cantRead';
Expand Down
91 changes: 0 additions & 91 deletions files/lib/system/minecraft/AbstractMinecraftRCONHandler.class.php

This file was deleted.

56 changes: 39 additions & 17 deletions files/lib/system/minecraft/IMinecraftHandler.class.php
Expand Up @@ -2,6 +2,8 @@

namespace wcf\system\minecraft;

use wcf\system\exception\MinecraftException;

/**
* MinecraftHandler interface
*
Expand All @@ -13,10 +15,9 @@ interface IMinecraftHandler
{
/**
* Construct for Minecraft class and tries to connect.
*
* @param string $hostname the hostname/ip of your Minecraft server
* @param int $port the server rcon port of your Minecraft server (standard = 25575)
* @param string $password Password of server rcon
* @param string $hostname the hostname/ip of your Minecraft server
* @param int $port the server rcon port of your Minecraft server (standard = 25575)
* @param string $password Password of server rcon
*/
public function __construct($hostname, $port, $password);

Expand All @@ -27,40 +28,61 @@ public function __destruct();

/**
* Connect to Minecraft server rcon and tries to login.
* @throws MinecraftException
*/
public function connect();

/**
* Authenticates with the Minecraft Server instance using given ServerRCON login credentials.
* @throws MinecraftException
*/
public function login();

/**
* Method to execute server rcon commands
*
* @param string $command Command to execute on server
* @return array
* @param string $commands Command to execute on server
* @return int packet identificator
* @throws MinecraftException
*/
public function execute(string ...$commands);

/**
* Method to execute server rcon commands
* @param array $commands Command to execute on server
* @return int packet identificator
* @throws MinecraftException
*/
public function executeArray(array $commands);

/**
* Execute a command from server rcon
* Example:
* <code>
* $mc->call('list uuids')
* </code>
* @param string $commands Command to execute on server
* @return array|null
* @throws MinecraftException
*/
public function execute($command);
public function call(string ...$commands);

/**
* Execute a command from server rcon
*
* Example:
* <code>
* $mc->call('list uuids')
* </code>
*
* @param string $command Command to execute on server
* @return array|null
* @param array $commands Command to execute on server
* @return array|null
* @throws MinecraftException
*/
public function call($command);
public function callArray(array $commands);

/**
* Parse the results from Minecraft
*
* @return array
* @throws MinecraftException
* @param int $packID
* @return array
* @throws MinecraftException
*/
public function parseResult();
public function parseResult($packID);
}

0 comments on commit b0aaa03

Please sign in to comment.