mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
Localized remaining disconnection screens (except one or two that should never actually happen)
This commit is contained in:
@ -132,6 +132,7 @@ use function get_class;
|
||||
use function in_array;
|
||||
use function json_encode;
|
||||
use function ksort;
|
||||
use function random_bytes;
|
||||
use function strcasecmp;
|
||||
use function strlen;
|
||||
use function strtolower;
|
||||
@ -236,7 +237,11 @@ class NetworkSession{
|
||||
protected function createPlayer() : void{
|
||||
$this->server->createPlayer($this, $this->info, $this->authenticated, $this->cachedOfflinePlayerData)->onCompletion(
|
||||
\Closure::fromCallable([$this, 'onPlayerCreated']),
|
||||
fn() => $this->disconnect("Player creation failed") //TODO: this should never actually occur... right?
|
||||
function() : void{
|
||||
//TODO: this should never actually occur... right?
|
||||
$this->logger->error("Failed to create player");
|
||||
$this->disconnectWithError(KnownTranslationFactory::pocketmine_disconnect_error_internal());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@ -594,6 +599,10 @@ class NetworkSession{
|
||||
}, $reason);
|
||||
}
|
||||
|
||||
public function disconnectWithError(Translatable|string $reason) : void{
|
||||
$this->disconnect(KnownTranslationFactory::pocketmine_disconnect_error($reason, bin2hex(random_bytes(6))));
|
||||
}
|
||||
|
||||
public function disconnectIncompatibleProtocol(int $protocolVersion) : void{
|
||||
$this->tryDisconnect(
|
||||
function() use ($protocolVersion) : void{
|
||||
@ -606,7 +615,8 @@ class NetworkSession{
|
||||
/**
|
||||
* Instructs the remote client to connect to a different server.
|
||||
*/
|
||||
public function transfer(string $ip, int $port, Translatable|string $reason = "transfer") : void{
|
||||
public function transfer(string $ip, int $port, Translatable|string|null $reason = null) : void{
|
||||
$reason ??= KnownTranslationFactory::pocketmine_disconnect_transfer();
|
||||
$this->tryDisconnect(function() use ($ip, $port, $reason) : void{
|
||||
$this->sendDataPacket(TransferPacket::create($ip, $port), true);
|
||||
if($this->player !== null){
|
||||
@ -649,7 +659,7 @@ class NetworkSession{
|
||||
}
|
||||
|
||||
if($error !== null){
|
||||
$this->disconnect(KnownTranslationFactory::pocketmine_disconnect_invalidSession($error));
|
||||
$this->disconnectWithError(KnownTranslationFactory::pocketmine_disconnect_invalidSession($error));
|
||||
|
||||
return;
|
||||
}
|
||||
@ -1146,7 +1156,7 @@ class NetworkSession{
|
||||
|
||||
if($this->info === null){
|
||||
if(time() >= $this->connectTime + 10){
|
||||
$this->disconnect("Login timeout");
|
||||
$this->disconnectWithError(KnownTranslationFactory::pocketmine_disconnect_error_loginTimeout());
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -71,7 +71,7 @@ class LoginPacketHandler extends PacketHandler{
|
||||
$extraData = $this->fetchAuthData($packet->chainDataJwt);
|
||||
|
||||
if(!Player::isValidUserName($extraData->displayName)){
|
||||
$this->session->disconnect(KnownTranslationFactory::disconnectionScreen_invalidName());
|
||||
$this->session->disconnectWithError(KnownTranslationFactory::disconnectionScreen_invalidName());
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -81,7 +81,7 @@ class LoginPacketHandler extends PacketHandler{
|
||||
$skin = SkinAdapterSingleton::get()->fromSkinData(ClientDataToSkinDataHelper::fromClientData($clientData));
|
||||
}catch(\InvalidArgumentException | InvalidSkinException $e){
|
||||
$this->session->getLogger()->debug("Invalid skin: " . $e->getMessage());
|
||||
$this->session->disconnect(KnownTranslationFactory::disconnectionScreen_invalidSkin());
|
||||
$this->session->disconnectWithError(KnownTranslationFactory::disconnectionScreen_invalidSkin());
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -120,12 +120,19 @@ class LoginPacketHandler extends PacketHandler{
|
||||
$ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_SERVER_FULL, KnownTranslationFactory::disconnectionScreen_serverFull());
|
||||
}
|
||||
if(!$this->server->isWhitelisted($playerInfo->getUsername())){
|
||||
//TODO: l10n
|
||||
$ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_SERVER_WHITELISTED, "Server is whitelisted");
|
||||
$ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_SERVER_WHITELISTED, KnownTranslationFactory::pocketmine_disconnect_whitelisted());
|
||||
}
|
||||
if($this->server->getNameBans()->isBanned($playerInfo->getUsername()) || $this->server->getIPBans()->isBanned($this->session->getIp())){
|
||||
//TODO: l10n
|
||||
$ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_BANNED, "You are banned");
|
||||
|
||||
$banMessage = null;
|
||||
if(($banEntry = $this->server->getNameBans()->getEntry($playerInfo->getUsername())) !== null){
|
||||
$banReason = $banEntry->getReason();
|
||||
$banMessage = $banReason === "" ? KnownTranslationFactory::pocketmine_disconnect_ban_noReason() : KnownTranslationFactory::pocketmine_disconnect_ban($banReason);
|
||||
}elseif(($banEntry = $this->server->getIPBans()->getEntry($this->session->getIp())) !== null){
|
||||
$banReason = $banEntry->getReason();
|
||||
$banMessage = KnownTranslationFactory::pocketmine_disconnect_ban($banReason !== "" ? $banReason : KnownTranslationFactory::pocketmine_disconnect_ban_ip());
|
||||
}
|
||||
if($banMessage !== null){
|
||||
$ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_BANNED, $banMessage);
|
||||
}
|
||||
|
||||
$ev->call();
|
||||
|
@ -86,7 +86,7 @@ class ResourcePacksPacketHandler extends PacketHandler{
|
||||
|
||||
private function disconnectWithError(string $error) : void{
|
||||
$this->session->getLogger()->error("Error downloading resource packs: " . $error);
|
||||
$this->session->disconnect(KnownTranslationFactory::disconnectionScreen_resourcePack());
|
||||
$this->session->disconnectWithError(KnownTranslationFactory::disconnectionScreen_resourcePack());
|
||||
}
|
||||
|
||||
public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\network\mcpe\raklib;
|
||||
|
||||
use pocketmine\lang\KnownTranslationFactory;
|
||||
use pocketmine\network\AdvancedNetworkInterface;
|
||||
use pocketmine\network\mcpe\compression\ZlibCompressor;
|
||||
use pocketmine\network\mcpe\convert\TypeConverter;
|
||||
@ -46,10 +47,8 @@ use raklib\server\ServerEventListener;
|
||||
use raklib\utils\InternetAddress;
|
||||
use function addcslashes;
|
||||
use function base64_encode;
|
||||
use function bin2hex;
|
||||
use function implode;
|
||||
use function mt_rand;
|
||||
use function random_bytes;
|
||||
use function rtrim;
|
||||
use function substr;
|
||||
use const PHP_INT_MAX;
|
||||
@ -182,14 +181,12 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{
|
||||
try{
|
||||
$session->handleEncoded($buf);
|
||||
}catch(PacketHandlingException $e){
|
||||
$errorId = bin2hex(random_bytes(6));
|
||||
|
||||
$logger = $session->getLogger();
|
||||
$logger->error("Bad packet (error ID $errorId): " . $e->getMessage());
|
||||
$logger->error("Bad packet: " . $e->getMessage());
|
||||
|
||||
//intentionally doesn't use logException, we don't want spammy packet error traces to appear in release mode
|
||||
$logger->debug(implode("\n", Utils::printableExceptionInfo($e)));
|
||||
$session->disconnect("Packet processing error (Error ID: $errorId)");
|
||||
$session->disconnectWithError(KnownTranslationFactory::pocketmine_disconnect_error_badPacket());
|
||||
$this->interface->blockAddress($address, 5);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user