mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-17 08:54:22 +00:00
Fixed server crash on invalid gamemode in SetPlayerGameTypePacket
this really ought to be detected at the decode layer, but right now that's a bit difficult ...
This commit is contained in:
parent
7fe6815f7c
commit
25998720ce
@ -91,7 +91,7 @@ class TypeConverter{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function protocolGameModeToCore(int $gameMode) : GameMode{
|
public function protocolGameModeToCore(int $gameMode) : ?GameMode{
|
||||||
switch($gameMode){
|
switch($gameMode){
|
||||||
case ProtocolGameMode::SURVIVAL:
|
case ProtocolGameMode::SURVIVAL:
|
||||||
return GameMode::SURVIVAL();
|
return GameMode::SURVIVAL();
|
||||||
@ -103,7 +103,7 @@ class TypeConverter{
|
|||||||
case ProtocolGameMode::SURVIVAL_VIEWER:
|
case ProtocolGameMode::SURVIVAL_VIEWER:
|
||||||
return GameMode::SPECTATOR();
|
return GameMode::SPECTATOR();
|
||||||
default:
|
default:
|
||||||
throw new \UnexpectedValueException("Unmapped protocol game mode $gameMode");
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -667,8 +667,8 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{
|
public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{
|
||||||
$converter = TypeConverter::getInstance();
|
$gameMode = TypeConverter::getInstance()->protocolGameModeToCore($packet->gamemode);
|
||||||
if(!$converter->protocolGameModeToCore($packet->gamemode)->equals($this->player->getGamemode())){
|
if($gameMode === null || !$gameMode->equals($this->player->getGamemode())){
|
||||||
//Set this back to default. TODO: handle this properly
|
//Set this back to default. TODO: handle this properly
|
||||||
$this->session->syncGameMode($this->player->getGamemode(), true);
|
$this->session->syncGameMode($this->player->getGamemode(), true);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user