forked from HanashiDev/eu.hanashi.wsc.teamspeak-api
/
MinecraftConsoleForm.class.php
141 lines (126 loc) · 3.72 KB
/
MinecraftConsoleForm.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
namespace wcf\acp\form;
use wcf\system\WCF;
use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\MinecraftException;
use wcf\system\minecraft\MinecraftConnectionHandler;
use wcf\data\minecraft\Minecraft;
use wcf\form\AbstractForm;
/**
* MinecraftConsole Form class
*
* @author xXSchrandXx
* @license Creative Commons Zero v1.0 Universal (http://creativecommons.org/publicdomain/zero/1.0/)
* @package WoltLabSuite\Core\Acp\Form
*/
class MinecraftConsoleForm extends AbstractForm
{
/**
* @inheritDoc
*/
public $neededPermissions = ['admin.minecraft.canManageConnection'];
/**
* @inheritDoc
*/
public $activeMenuItem = 'wcf.acp.menu.link.configuration.minecraft.minecraftList';
/**
* @inheritDoc
*/
public $minecraft;
/**
* @inheritDoc
*/
public $command;
/**
* @inheritDoc
*/
public $response;
public $rsp;
/**
* The MinecraftConnectionHandler for the Action.
* @var MinecraftConnectionHandler
*/
public $connection;
/**
* @inheritDoc
*/
public function readParameters()
{
parent::readParameters();
if (isset($_REQUEST['id'])) {
$minecraftID = (int)$_REQUEST['id'];
}
if (!isset($minecraftID)) {
throw new IllegalLinkException();
}
$this->minecraft = new Minecraft($minecraftID);
if (!$this->minecraft->minecraftID) {
throw new IllegalLinkException();
}
try {
$this->connection = $this->minecraft->getConnection();
} catch (MinecraftException $e) {
$this->errorType = 'cantConnect';
if (\ENABLE_DEBUG_MODE) {
\wcf\functions\exception\logThrowable($e);
}
} catch (\Exception $e) {
$this->errorType = 'cantConnect';
if (\ENABLE_DEBUG_MODE) {
\wcf\functions\exception\logThrowable($e);
}
}
if (\ENABLE_DEBUG_MODE && isset($this->connection->minecraftHandler->rsp)) {
$this->rsp = $this->connection->minecraftHandler->rsp;
}
}
/**
* @inheritDoc
*/
public function readFormParameters()
{
if (isset($_POST['command'])) {
$tmpResponse = [];
$command = $_POST['command'];
try {
$tmpResponse = $this->connection->call($command);
} catch (MinecraftException $e) {
$this->errorType = 'cantConnect';
if (\ENABLE_DEBUG_MODE) {
\wcf\functions\exception\logThrowable($e);
}
}
if (empty($tmpResponse)) {
$this->errorType = 'cantConnect';
} else {
if ($tmpResponse['Response'] == 0) {
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';
}
}
}
}
/**
* @inheritDoc
*/
public function assignVariables()
{
parent::assignVariables();
WCF::getTPL()->assign([
'minecraftID' => $this->minecraft->minecraftID,
'connectionName' => $this->minecraft->connectionName,
'rsp' => $this->rsp,
'response' => $this->response
]);
}
}