mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-25 12:54:03 +00:00
more exception handling cleanup
This commit is contained in:
parent
053defb7dc
commit
48a99937b9
@ -701,7 +701,7 @@ class Server{
|
|||||||
$nbt = new BigEndianNbtSerializer();
|
$nbt = new BigEndianNbtSerializer();
|
||||||
try{
|
try{
|
||||||
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed($ev->getSaveData()));
|
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed($ev->getSaveData()));
|
||||||
}catch(\Throwable $e){
|
}catch(\ErrorException $e){
|
||||||
$this->logger->critical($this->getLanguage()->translateString("pocketmine.data.saveError", [$name, $e->getMessage()]));
|
$this->logger->critical($this->getLanguage()->translateString("pocketmine.data.saveError", [$name, $e->getMessage()]));
|
||||||
$this->logger->logException($e);
|
$this->logger->logException($e);
|
||||||
}
|
}
|
||||||
@ -1200,7 +1200,7 @@ class Server{
|
|||||||
$this->getIp(),
|
$this->getIp(),
|
||||||
$this->getConfigInt("rcon.max-clients", 50)
|
$this->getConfigInt("rcon.max-clients", 50)
|
||||||
);
|
);
|
||||||
}catch(\Exception $e){
|
}catch(\RuntimeException $e){
|
||||||
$this->getLogger()->critical("RCON can't be started: " . $e->getMessage());
|
$this->getLogger()->critical("RCON can't be started: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1782,7 +1782,7 @@ class Server{
|
|||||||
$this->logger->info("[UPnP] Trying to port forward...");
|
$this->logger->info("[UPnP] Trying to port forward...");
|
||||||
try{
|
try{
|
||||||
UPnP::PortForward($this->getPort());
|
UPnP::PortForward($this->getPort());
|
||||||
}catch(\Exception $e){
|
}catch(\RuntimeException $e){
|
||||||
$this->logger->alert("UPnP portforward failed: " . $e->getMessage());
|
$this->logger->alert("UPnP portforward failed: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,11 +64,20 @@ class RCON{
|
|||||||
/** @var resource */
|
/** @var resource */
|
||||||
private $ipcThreadSocket;
|
private $ipcThreadSocket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Server $server
|
||||||
|
* @param string $password
|
||||||
|
* @param int $port
|
||||||
|
* @param string $interface
|
||||||
|
* @param int $maxClients
|
||||||
|
*
|
||||||
|
* @throws \RuntimeException
|
||||||
|
*/
|
||||||
public function __construct(Server $server, string $password, int $port = 19132, string $interface = "0.0.0.0", int $maxClients = 50){
|
public function __construct(Server $server, string $password, int $port = 19132, string $interface = "0.0.0.0", int $maxClients = 50){
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
$this->server->getLogger()->info("Starting remote control listener");
|
$this->server->getLogger()->info("Starting remote control listener");
|
||||||
if($password === ""){
|
if($password === ""){
|
||||||
throw new \InvalidArgumentException("Empty password");
|
throw new \RuntimeException("Empty password");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||||
|
@ -35,6 +35,11 @@ use function trim;
|
|||||||
|
|
||||||
abstract class UPnP{
|
abstract class UPnP{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $port
|
||||||
|
*
|
||||||
|
* @throws \RuntimeException
|
||||||
|
*/
|
||||||
public static function PortForward(int $port) : void{
|
public static function PortForward(int $port) : void{
|
||||||
if(!Internet::$online){
|
if(!Internet::$online){
|
||||||
throw new \RuntimeException("Server is offline");
|
throw new \RuntimeException("Server is offline");
|
||||||
@ -56,8 +61,12 @@ abstract class UPnP{
|
|||||||
throw new \RuntimeException("Failed to portforward using UPnP. Ensure that network discovery is enabled in Control Panel.");
|
throw new \RuntimeException("Failed to portforward using UPnP. Ensure that network discovery is enabled in Control Panel.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
/** @noinspection PhpUndefinedFieldInspection */
|
/** @noinspection PhpUndefinedFieldInspection */
|
||||||
$com->StaticPortMappingCollection->Add($port, "UDP", $port, $myLocalIP, true, "PocketMine-MP");
|
$com->StaticPortMappingCollection->Add($port, "UDP", $port, $myLocalIP, true, "PocketMine-MP");
|
||||||
|
}catch(\com_exception $e){
|
||||||
|
throw new \RuntimeException($e->getMessage(), 0, $e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function RemovePortForward(int $port) : bool{
|
public static function RemovePortForward(int $port) : bool{
|
||||||
@ -68,16 +77,18 @@ abstract class UPnP{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
|
||||||
/** @noinspection PhpUndefinedClassInspection */
|
/** @noinspection PhpUndefinedClassInspection */
|
||||||
$com = new \COM("HNetCfg.NATUPnP");
|
$com = new \COM("HNetCfg.NATUPnP");
|
||||||
/** @noinspection PhpUndefinedFieldInspection */
|
/** @noinspection PhpUndefinedFieldInspection */
|
||||||
if($com === false or !is_object($com->StaticPortMappingCollection)){
|
if($com === false or !is_object($com->StaticPortMappingCollection)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
/** @noinspection PhpUndefinedFieldInspection */
|
/** @noinspection PhpUndefinedFieldInspection */
|
||||||
$com->StaticPortMappingCollection->Remove($port, "UDP");
|
$com->StaticPortMappingCollection->Remove($port, "UDP");
|
||||||
}catch(\Throwable $e){
|
}catch(\com_exception $e){
|
||||||
|
//TODO: should this really be silenced?
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user