Skip to content

Commit

Permalink
improv. add udp for MCPE (bedrock version) (#263)
Browse files Browse the repository at this point in the history
* improv. add udp for MCPE (bedrock version)

* improv. add udp for MCPE (bedrock version)

* improv. add udp for MCPE (bedrock version)
  • Loading branch information
nivcoo authored Jan 4, 2021
1 parent ca29b1f commit 252a69b
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 140 deletions.
12 changes: 5 additions & 7 deletions app/Controller/Component/ServerComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function call($methods = [], $server_id = false, $debug = false)
$multi = false;
}

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

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

try {
$Query = new MinecraftPing($config['ip'], $config['port'], $this->getTimeout());
$Query = new MinecraftPing($config['ip'], $config['port'], $this->getTimeout(), $config['udp']);
$Info = $Query->Query();
} catch (MinecraftPingException $e) {
return false;
Expand Down Expand Up @@ -369,10 +369,8 @@ public function online($server_id = false, $debug = false)
$config = $this->getConfig($server_id);
if (!$config) // server not found
return $this->online[$server_id] = false;

if ($config['type'] == 1 || $config['type'] == 2) // ping only
return $this->online[$server_id] = ($this->ping(['ip' => $config['ip'], 'port' => $config['port']])) ? true : false;

if ($config['type'] == 1 || $config['type'] == 2 || $config['type'] == 3) // ping only
return $this->online[$server_id] = ($this->ping(['ip' => $config['ip'], 'port' => $config['port'], 'udp' => $config['type'] == 3])) ? true : false;
list($return, $code, $error) = $this->request($this->getUrl($server_id), $this->encryptWithKey("[]"));
if ($return && $code === 200)
return $this->online[$server_id] = true;
Expand Down
67 changes: 34 additions & 33 deletions app/Controller/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ public function admin_link_ajax()
* 0 : Plugin
* 1 : Ping
* 2 : Rcon
* 3 : Ping MCPE
*/

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

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

private function linkDebugFull($msg, $host, $port)
{
$msg .= $this->linkDebugPing();

$msg .= "<br /><br />";
$msg .= "<i class=\"fa fa-times\"></i> ";

if ($this->Server->ping(['ip' => $host, 'port' => $port]))
$msg .= $this->Lang->get('SERVER__SEEMS_USED');
else
$msg .= $this->Lang->get('SERVER__PORT_CLOSE_OR_BAD');

return $msg;
}

private function linkDebugPing()
{
$msg = "<br /><br />";

$hypixelIp = gethostbyname('mc.hypixel.net');
if ($this->Server->ping(['ip' => $hypixelIp, 'port' => 25565])) {
$msg .= "<i class=\"fa fa-check\"></i> ";
$msg .= $this->Lang->get('SERVER__PORT_OPEN');
} else {
$msg .= "<i class=\"fa fa-times\"></i> ";
$msg .= $this->Lang->get('SERVER__SEEMS_CLOSE_OR_BLOCKED');
}

return $msg;
}

public function admin_banlist($server_id = false)
{
$this->layout = 'admin';
Expand Down Expand Up @@ -406,4 +376,35 @@ public function admin_online($server_id = false)
$this->set('title_for_layout', $this->Lang->get('SERVER__STATUS_ONLINE'));
}

private function linkDebugFull($msg, $host, $port, $udp = false)
{
$msg .= $this->linkDebugPing();

$msg .= "<br /><br />";
$msg .= "<i class=\"fa fa-times\"></i> ";

if ($this->Server->ping(['ip' => $host, 'port' => $port, 'udp' => $udp]))
$msg .= $this->Lang->get('SERVER__SEEMS_USED');
else
$msg .= $this->Lang->get('SERVER__PORT_CLOSE_OR_BAD');

return $msg;
}

private function linkDebugPing()
{
$msg = "<br /><br />";

$hypixelIp = gethostbyname('mc.hypixel.net');
if ($this->Server->ping(['ip' => $hypixelIp, 'port' => 25565, 'udp' => false])) {
$msg .= "<i class=\"fa fa-check\"></i> ";
$msg .= $this->Lang->get('SERVER__PORT_OPEN');
} else {
$msg .= "<i class=\"fa fa-times\"></i> ";
$msg .= $this->Lang->get('SERVER__SEEMS_CLOSE_OR_BLOCKED');
}

return $msg;
}

}
2 changes: 1 addition & 1 deletion app/View/Admin/admin_index.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@

<div class="card card-body bg-light">
<?php if ($Server->online($value['Server']['id'])) { ?>
<?php if ($value['Server']['type'] != 1 && $Permissions->can('SEND_SERVER_COMMAND_FROM_DASHBOARD')) { ?>
<?php if ($value['Server']['type'] != 1 && $value['Server']['type'] != 3 && $Permissions->can('SEND_SERVER_COMMAND_FROM_DASHBOARD')) { ?>
<div class="row-fluid text-center">
<button class="btn" type="button" data-toggle="modal"
onClick="$('#server_id').val(<?= $value['Server']['id'] ?>)"
Expand Down
3 changes: 2 additions & 1 deletion app/View/Server/admin_link.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<option value="0"<?= ($value['Server']['type'] == '0') ? ' selected' : '' ?>><?= $Lang->get('SERVER__TYPE_DEFAULT') ?></option>
<option value="1"<?= ($value['Server']['type'] == '1') ? ' selected' : '' ?>><?= $Lang->get('SERVER__TYPE_QUERY') ?></option>
<option value="2"<?= ($value['Server']['type'] == '2') ? ' selected' : '' ?>><?= $Lang->get('SERVER__TYPE_RCON') ?></option>
<option value="3"<?= ($value['Server']['type'] == '3') ? ' selected' : '' ?>><?= $Lang->get('SERVER__TYPE_QUERY_MCPE') ?></option>
</select>
</div>

Expand Down Expand Up @@ -179,7 +180,7 @@
var infos = '<div class="alert alert-info"><?= addslashes($Lang->get('SERVER__TYPE_DEFAULT_INFOS')) ?></div>'
select.parent().parent().find('input[name="server_data[rcon_port]"]').parent().remove()
select.parent().parent().find('input[name="server_data[rcon_password]"]').parent().remove()
} else if (type == 1) {
} else if (type == 1 || type == 3) {
var infos = '<div class="alert alert-info"><?= addslashes($Lang->get('SERVER__TYPE_QUERY_INFOS')) ?></div>'
select.parent().parent().find('input[name="server_data[rcon_port]"]').parent().remove()
select.parent().parent().find('input[name="server_data[rcon_password]"]').parent().remove()
Expand Down
1 change: 1 addition & 0 deletions lang/en_UK.json
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@
"SERVER__TYPE": "Type of connection",
"SERVER__TYPE_DEFAULT": "Default",
"SERVER__TYPE_QUERY": "Ping (no need for plugin)",
"SERVER__TYPE_QUERY_MCPE": "Ping MCPE (no need for plugin)",
"SERVER__TYPE_RCON": "RCON (no need for plugin)",
"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>",
"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> ",
Expand Down
1 change: 1 addition & 0 deletions lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@
"SERVER__TYPE": "Type of connection",
"SERVER__TYPE_DEFAULT": "Default",
"SERVER__TYPE_QUERY": "Ping (no need for plugin)",
"SERVER__TYPE_QUERY_MCPE": "Ping MCPE (no need for plugin)",
"SERVER__TYPE_RCON": "RCON (no need for plugin)",
"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>",
"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> ",
Expand Down
1 change: 1 addition & 0 deletions lang/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@
"SERVER__TYPE": "Type de la connexion",
"SERVER__TYPE_DEFAULT": "Par défaut",
"SERVER__TYPE_QUERY": "Ping (pas besoin de plugin)",
"SERVER__TYPE_QUERY_MCPE": "Ping MCPE (pas besoin de plugin)",
"SERVER__TYPE_RCON": "RCON (pas besoin de plugin)",
"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>",
"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>",
Expand Down
1 change: 1 addition & 0 deletions lang/ru_RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@
"SERVER__TYPE": "Тип подключения",
"SERVER__TYPE_DEFAULT": "По умолчанию",
"SERVER__TYPE_QUERY": "Ping (не нужен плагин)",
"SERVER__TYPE_QUERY_MCPE": "Ping MCPE (не нужен плагин)",
"SERVER__TYPE_RCON": "RCON (не требуется плагин)",
"SERVER__TYPE_DEFAULT_INFOS": "Вам необходимо установить плагин MineWebBridge на свой сервер, чтобы использовать этот тип ссылки. Вся информация, касающаяся этой манипуляции, доступна на <a href = \"http://docs.mineweb.org/#link- сервер-сайт \"> документация </a>",
"SERVER__TYPE_QUERY_INFOS": "Вам не нужно устанавливать плагин MineWebBridge на вашем сервере, чтобы использовать ссылку этого типа, этот тип ссылки позволяет только отображать количество подключенных в вашей инфраструктуре. Эти манипуляции доступны на <a href = \"http://docs.mineweb.org/#lier-server-site \"> документация </a>",
Expand Down
Loading

0 comments on commit 252a69b

Please sign in to comment.