Inseparable set of network changes - these all need each other to work

- Separated player handling and creation from network interfaces
- Rewire disconnects to make them not be recursive
- Batching now uses sessions instead of players
- Fixed DisconnectPacket getting sent to players who disconnect of their own accord
This commit is contained in:
Dylan K. Taylor
2018-07-21 20:03:05 +01:00
parent a86d3fe071
commit 85105ed066
10 changed files with 160 additions and 88 deletions

View File

@ -53,8 +53,7 @@ class LoginSessionHandler extends SessionHandler{
$this->session->sendDataPacket($pk, true);
//This pocketmine disconnect message will only be seen by the console (PlayStatusPacket causes the messages to be shown for the client)
$this->player->close(
"",
$this->session->disconnect(
$this->player->getServer()->getLanguage()->translateString("pocketmine.disconnect.incompatibleProtocol", [$packet->protocol]),
false
);
@ -63,13 +62,13 @@ class LoginSessionHandler extends SessionHandler{
}
if(!Player::isValidUserName($packet->username)){
$this->player->close("", "disconnectionScreen.invalidName");
$this->session->disconnect("disconnectionScreen.invalidName");
return true;
}
if($packet->skin === null or !$packet->skin->isValid()){
$this->player->close("", "disconnectionScreen.invalidSkin");
$this->session->disconnect("disconnectionScreen.invalidSkin");
return true;
}

View File

@ -86,7 +86,7 @@ class PreSpawnSessionHandler extends SessionHandler{
$this->player->sendAllInventories();
$this->player->getInventory()->sendCreativeContents();
$this->player->getInventory()->sendHeldItem($this->player);
$this->session->getInterface()->putPacket($this->player, $this->server->getCraftingManager()->getCraftingDataPacket());
$this->session->getInterface()->putPacket($this->session, $this->server->getCraftingManager()->getCraftingDataPacket());
$this->server->sendFullPlayerListData($this->player);
}

View File

@ -66,14 +66,14 @@ class ResourcePacksSessionHandler extends SessionHandler{
private function disconnectWithError(string $error) : void{
$this->player->getServer()->getLogger()->error("Error while downloading resource packs for " . $this->player->getName() . ": " . $error);
$this->player->close("", "disconnectionScreen.resourcePack", true);
$this->session->disconnect("disconnectionScreen.resourcePack");
}
public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{
switch($packet->status){
case ResourcePackClientResponsePacket::STATUS_REFUSED:
//TODO: add lang strings for this
$this->player->close("", "You must accept resource packs to join this server.", true);
$this->session->disconnect("You must accept resource packs to join this server.", true);
break;
case ResourcePackClientResponsePacket::STATUS_SEND_PACKS:
foreach($packet->packIds as $uuid){