Skip to content

Commit 252a69b

Browse files
authored
improv. add udp for MCPE (bedrock version) (#263)
* improv. add udp for MCPE (bedrock version) * improv. add udp for MCPE (bedrock version) * improv. add udp for MCPE (bedrock version)
1 parent ca29b1f commit 252a69b

9 files changed

Lines changed: 169 additions & 140 deletions

File tree

app/Controller/Component/ServerComponent.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function call($methods = [], $server_id = false, $debug = false)
8585
$multi = false;
8686
}
8787

88-
if ($config['type'] == 1 || $config['type'] == 2) {
88+
if ($config['type'] == 1 || $config['type'] == 2 || $config['type'] == 3) {
8989
$methodsName = array_map(function ($method) {
9090
return array_keys($method)[0];
9191
}, $methods);
@@ -100,7 +100,7 @@ public function call($methods = [], $server_id = false, $debug = false)
100100
}
101101

102102
if (count($methodsName) > 0) {
103-
$ping = $this->ping(['ip' => $config['ip'], 'port' => $config['port']]);
103+
$ping = $this->ping(['ip' => $config['ip'], 'port' => $config['port'], 'udp' => $config['type'] == 3]);
104104
foreach ($methods as $key => $method) {
105105
$name = array_keys($method)[0];
106106
if (isset($ping[$name]))
@@ -216,7 +216,7 @@ public function ping($config = false)
216216
App::import('Vendor', 'MinecraftPingException', ['file' => 'ping-xpaw/MinecraftPingException.php']);
217217

218218
try {
219-
$Query = new MinecraftPing($config['ip'], $config['port'], $this->getTimeout());
219+
$Query = new MinecraftPing($config['ip'], $config['port'], $this->getTimeout(), $config['udp']);
220220
$Info = $Query->Query();
221221
} catch (MinecraftPingException $e) {
222222
return false;
@@ -369,10 +369,8 @@ public function online($server_id = false, $debug = false)
369369
$config = $this->getConfig($server_id);
370370
if (!$config) // server not found
371371
return $this->online[$server_id] = false;
372-
373-
if ($config['type'] == 1 || $config['type'] == 2) // ping only
374-
return $this->online[$server_id] = ($this->ping(['ip' => $config['ip'], 'port' => $config['port']])) ? true : false;
375-
372+
if ($config['type'] == 1 || $config['type'] == 2 || $config['type'] == 3) // ping only
373+
return $this->online[$server_id] = ($this->ping(['ip' => $config['ip'], 'port' => $config['port'], 'udp' => $config['type'] == 3])) ? true : false;
376374
list($return, $code, $error) = $this->request($this->getUrl($server_id), $this->encryptWithKey("[]"));
377375
if ($return && $code === 200)
378376
return $this->online[$server_id] = true;

app/Controller/ServerController.php

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ public function admin_link_ajax()
263263
* 0 : Plugin
264264
* 1 : Ping
265265
* 2 : Rcon
266+
* 3 : Ping MCPE
266267
*/
267268

268269
if ($this->request->data['type'] == 0) {
@@ -277,8 +278,8 @@ public function admin_link_ajax()
277278
}
278279

279280
} // use simple ping to retrieve data from MC protocol
280-
else if ($this->request->data['type'] == 1) {
281-
if (!$this->Server->ping(['ip' => $this->request->data['host'], 'port' => $this->request->data['port']])) {
281+
else if ($this->request->data['type'] == 1 || $this->request->data['type'] == 3) {
282+
if (!$this->Server->ping(['ip' => $this->request->data['host'], 'port' => $this->request->data['port'], 'udp' => $this->request->data['type'] == 3])) {
282283
$msg = $this->Lang->get('SERVER__LINK_ERROR_FAILED');
283284
$msg .= $this->linkDebugPing();
284285
return $this->response->body(json_encode(['statut' => false, 'msg' => $msg]));
@@ -318,37 +319,6 @@ public function admin_link_ajax()
318319
return $this->response->body(json_encode(['statut' => true, 'msg' => $this->Lang->get('SERVER__LINK_SUCCESS')]));
319320
}
320321

321-
private function linkDebugFull($msg, $host, $port)
322-
{
323-
$msg .= $this->linkDebugPing();
324-
325-
$msg .= "<br /><br />";
326-
$msg .= "<i class=\"fa fa-times\"></i> ";
327-
328-
if ($this->Server->ping(['ip' => $host, 'port' => $port]))
329-
$msg .= $this->Lang->get('SERVER__SEEMS_USED');
330-
else
331-
$msg .= $this->Lang->get('SERVER__PORT_CLOSE_OR_BAD');
332-
333-
return $msg;
334-
}
335-
336-
private function linkDebugPing()
337-
{
338-
$msg = "<br /><br />";
339-
340-
$hypixelIp = gethostbyname('mc.hypixel.net');
341-
if ($this->Server->ping(['ip' => $hypixelIp, 'port' => 25565])) {
342-
$msg .= "<i class=\"fa fa-check\"></i> ";
343-
$msg .= $this->Lang->get('SERVER__PORT_OPEN');
344-
} else {
345-
$msg .= "<i class=\"fa fa-times\"></i> ";
346-
$msg .= $this->Lang->get('SERVER__SEEMS_CLOSE_OR_BLOCKED');
347-
}
348-
349-
return $msg;
350-
}
351-
352322
public function admin_banlist($server_id = false)
353323
{
354324
$this->layout = 'admin';
@@ -406,4 +376,35 @@ public function admin_online($server_id = false)
406376
$this->set('title_for_layout', $this->Lang->get('SERVER__STATUS_ONLINE'));
407377
}
408378

379+
private function linkDebugFull($msg, $host, $port, $udp = false)
380+
{
381+
$msg .= $this->linkDebugPing();
382+
383+
$msg .= "<br /><br />";
384+
$msg .= "<i class=\"fa fa-times\"></i> ";
385+
386+
if ($this->Server->ping(['ip' => $host, 'port' => $port, 'udp' => $udp]))
387+
$msg .= $this->Lang->get('SERVER__SEEMS_USED');
388+
else
389+
$msg .= $this->Lang->get('SERVER__PORT_CLOSE_OR_BAD');
390+
391+
return $msg;
392+
}
393+
394+
private function linkDebugPing()
395+
{
396+
$msg = "<br /><br />";
397+
398+
$hypixelIp = gethostbyname('mc.hypixel.net');
399+
if ($this->Server->ping(['ip' => $hypixelIp, 'port' => 25565, 'udp' => false])) {
400+
$msg .= "<i class=\"fa fa-check\"></i> ";
401+
$msg .= $this->Lang->get('SERVER__PORT_OPEN');
402+
} else {
403+
$msg .= "<i class=\"fa fa-times\"></i> ";
404+
$msg .= $this->Lang->get('SERVER__SEEMS_CLOSE_OR_BLOCKED');
405+
}
406+
407+
return $msg;
408+
}
409+
409410
}

app/View/Admin/admin_index.ctp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@
272272

273273
<div class="card card-body bg-light">
274274
<?php if ($Server->online($value['Server']['id'])) { ?>
275-
<?php if ($value['Server']['type'] != 1 && $Permissions->can('SEND_SERVER_COMMAND_FROM_DASHBOARD')) { ?>
275+
<?php if ($value['Server']['type'] != 1 && $value['Server']['type'] != 3 && $Permissions->can('SEND_SERVER_COMMAND_FROM_DASHBOARD')) { ?>
276276
<div class="row-fluid text-center">
277277
<button class="btn" type="button" data-toggle="modal"
278278
onClick="$('#server_id').val(<?= $value['Server']['id'] ?>)"

app/View/Server/admin_link.ctp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<option value="0"<?= ($value['Server']['type'] == '0') ? ' selected' : '' ?>><?= $Lang->get('SERVER__TYPE_DEFAULT') ?></option>
8080
<option value="1"<?= ($value['Server']['type'] == '1') ? ' selected' : '' ?>><?= $Lang->get('SERVER__TYPE_QUERY') ?></option>
8181
<option value="2"<?= ($value['Server']['type'] == '2') ? ' selected' : '' ?>><?= $Lang->get('SERVER__TYPE_RCON') ?></option>
82+
<option value="3"<?= ($value['Server']['type'] == '3') ? ' selected' : '' ?>><?= $Lang->get('SERVER__TYPE_QUERY_MCPE') ?></option>
8283
</select>
8384
</div>
8485

@@ -179,7 +180,7 @@
179180
var infos = '<div class="alert alert-info"><?= addslashes($Lang->get('SERVER__TYPE_DEFAULT_INFOS')) ?></div>'
180181
select.parent().parent().find('input[name="server_data[rcon_port]"]').parent().remove()
181182
select.parent().parent().find('input[name="server_data[rcon_password]"]').parent().remove()
182-
} else if (type == 1) {
183+
} else if (type == 1 || type == 3) {
183184
var infos = '<div class="alert alert-info"><?= addslashes($Lang->get('SERVER__TYPE_QUERY_INFOS')) ?></div>'
184185
select.parent().parent().find('input[name="server_data[rcon_port]"]').parent().remove()
185186
select.parent().parent().find('input[name="server_data[rcon_password]"]').parent().remove()

lang/en_UK.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@
533533
"SERVER__TYPE": "Type of connection",
534534
"SERVER__TYPE_DEFAULT": "Default",
535535
"SERVER__TYPE_QUERY": "Ping (no need for plugin)",
536+
"SERVER__TYPE_QUERY_MCPE": "Ping MCPE (no need for plugin)",
536537
"SERVER__TYPE_RCON": "RCON (no need for plugin)",
537538
"SERVER__TYPE_DEFAULT_INFOS": "You need to install the MineWebBridge plugin on your server to use this type of link.All information related to this manipulation is available on <a href=\"http://docs.mineweb.org/#link-server-site\"> documentation </a>",
538539
"SERVER__TYPE_QUERY_INFOS": "You do not need to install the MineWebBridge plugin on your server to use this type of link, this type of link only allows you to display the number of connected on your infrastructure. this manipulation are available on <a href=\"http://docs.mineweb.org/#lier-server-site\"> documentation </a> ",

lang/en_US.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@
537537
"SERVER__TYPE": "Type of connection",
538538
"SERVER__TYPE_DEFAULT": "Default",
539539
"SERVER__TYPE_QUERY": "Ping (no need for plugin)",
540+
"SERVER__TYPE_QUERY_MCPE": "Ping MCPE (no need for plugin)",
540541
"SERVER__TYPE_RCON": "RCON (no need for plugin)",
541542
"SERVER__TYPE_DEFAULT_INFOS": "You need to install the MineWebBridge plugin on your server to use this type of link.All information related to this manipulation is available on <a href=\"http://docs.mineweb.org/#link-server-site\"> documentation </a>",
542543
"SERVER__TYPE_QUERY_INFOS": "You do not need to install the MineWebBridge plugin on your server to use this type of link, this type of link only allows you to display the number of connected on your infrastructure. this manipulation are available on <a href=\"http://docs.mineweb.org/#lier-server-site\"> documentation </a> ",

lang/fr_FR.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@
535535
"SERVER__TYPE": "Type de la connexion",
536536
"SERVER__TYPE_DEFAULT": "Par défaut",
537537
"SERVER__TYPE_QUERY": "Ping (pas besoin de plugin)",
538+
"SERVER__TYPE_QUERY_MCPE": "Ping MCPE (pas besoin de plugin)",
538539
"SERVER__TYPE_RCON": "RCON (pas besoin de plugin)",
539540
"SERVER__TYPE_DEFAULT_INFOS": "Vous avez besoin d'installer le plugin MineWebBridge sur votre serveur pour utiliser ce type de liaison. Toutes les informations relatives à cette manipulation sont disponibles sur <a href=\"http://docs.mineweb.org/#lier-serveur-site\">la documentation</a>",
540541
"SERVER__TYPE_QUERY_INFOS": "Vous n'avez pas besoin d'installer le plugin MineWebBridge sur votre serveur pour utiliser ce type de liaison. Ce type de liaison vous permet seulement d'afficher le nombre de connecté sur votre infrastructure. Toutes les informations relatives à cette manipulation sont disponibles sur <a href=\"http://docs.mineweb.org/#lier-serveur-site\">la documentation</a>",

lang/ru_RU.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@
537537
"SERVER__TYPE": "Тип подключения",
538538
"SERVER__TYPE_DEFAULT": "По умолчанию",
539539
"SERVER__TYPE_QUERY": "Ping (не нужен плагин)",
540+
"SERVER__TYPE_QUERY_MCPE": "Ping MCPE (не нужен плагин)",
540541
"SERVER__TYPE_RCON": "RCON (не требуется плагин)",
541542
"SERVER__TYPE_DEFAULT_INFOS": "Вам необходимо установить плагин MineWebBridge на свой сервер, чтобы использовать этот тип ссылки. Вся информация, касающаяся этой манипуляции, доступна на <a href = \"http://docs.mineweb.org/#link- сервер-сайт \"> документация </a>",
542543
"SERVER__TYPE_QUERY_INFOS": "Вам не нужно устанавливать плагин MineWebBridge на вашем сервере, чтобы использовать ссылку этого типа, этот тип ссылки позволяет только отображать количество подключенных в вашей инфраструктуре. Эти манипуляции доступны на <a href = \"http://docs.mineweb.org/#lier-server-site \"> документация </a>",

0 commit comments

Comments
 (0)