public function onReceivePacket(DataPacketReceiveEvent $event) { $player = $event->getPlayer(); $packet = $event->getPacket(); if ($packet->pid() == Info::LOGIN_PACKET) { if ($packet->protocol1 < Info::CURRENT_PROTOCOL) { //Check if outdated client message is custom if (CustomAlerts::getAPI()->isOutdatedClientMessageCustom()) { CustomAlerts::getAPI()->setOutdatedClientMessage(CustomAlerts::getAPI()->getDefaultOutdatedClientMessage($player)); } //Outdated Client Kick Event $this->plugin->getServer()->getPluginManager()->callEvent(new CustomAlertsOutdatedClientKickEvent($player)); //Check if Outdated Client message is not empty if (CustomAlerts::getAPI()->getOutdatedClientMessage() != null) { $player->close("", CustomAlerts::getAPI()->getOutdatedClientMessage()); $event->setCancelled(true); } } elseif ($packet->protocol1 > Info::CURRENT_PROTOCOL) { //Check if outdated server message is custom if (CustomAlerts::getAPI()->isOutdatedServerMessageCustom()) { CustomAlerts::getAPI()->setOutdatedServerMessage(CustomAlerts::getAPI()->getDefaultOutdatedServerMessage($player)); } //Outdated Server Kick Event $this->plugin->getServer()->getPluginManager()->callEvent(new CustomAlertsOutdatedServerKickEvent($player)); //Check if Outdated Server message is not empty if (CustomAlerts::getAPI()->getOutdatedServerMessage() != null) { $player->close("", CustomAlerts::getAPI()->getOutdatedServerMessage()); $event->setCancelled(true); } } } }
/** * Connection packets Event handling * * @param DataPacketReceiveEvent $event * @return boolean */ public function onDataPacketReceived(DataPacketReceiveEvent $event) { if ($event->getPacket()->pid() == 0x82) { if (!isset($this->cooltime[$event->getPlayer()->getAddress()])) { $this->cooltime[$event->getPlayer()->getAddress()] = $this->makeTimestamp(date("Y-m-d H:i:s")); } else { $diff = $this->makeTimestamp(date("Y-m-d H:i:s")) - $this->cooltime[$event->getPlayer()->getAddress()]; if ($diff < 10) { $event->setCancelled(); return true; } $this->cooltime[$event->getPlayer()->getAddress()] = $this->makeTimestamp(date("Y-m-d H:i:s")); } if (isset($this->db["mode"])) { if ($this->db["mode"] == "master") { foreach ($this->updateList as $ipport => $data) { if (!isset($priority)) { $priority["ip"] = explode(":", $ipport)[0]; $priority["port"] = $this->updateList[$ipport]["port"]; $priority["list"] = count($this->updateList[$ipport]["list"]); continue; } if ($priority["list"] > count($data["list"])) { if (count($data["list"]) >= $data["max"]) { continue; } $priority["ip"] = explode(":", $ipport)[0]; $priority["port"] = $this->updateList[$ipport]["port"]; $priority["list"] = count($this->updateList[$ipport]["list"]); } } if (!isset($priority)) { // NO EXTRA SERVER $event->setCancelled(); return true; } // If this setting Internal IP, change External IP if ($priority["ip"] == "127.0.0.1" or $priority["ip"] == "0.0.0.0") { $priority["ip"] = $this->externalIp; } $event->getPlayer()->dataPacket((new StrangePacket($priority["ip"], $priority["port"]))->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); $event->setCancelled(); return true; } } } return false; }
public function onDataPacketReceive(DataPacketReceiveEvent $event) { if ($event->getPacket() instanceof MovePlayerPacket and ($camera = $this->getCamera($event->getPlayer())) !== null and $camera->isRunning()) { $event->setCancelled(true); } }
public function onDataPacketReceiveEvent(DataPacketReceiveEvent $event) { $packet = $event->getPacket(); $player = $event->getPlayer(); if ($packet instanceof EntityEventPacket) { if ($player->spawned === \true or $player->blocked === \false or $player->isAlive()) { $player->craftingType = 0; $player->setDataFlag(Player::DATA_FLAGS, Player::DATA_FLAG_ACTION, \false); // TODO: check if this should be true switch ($packet->event) { case 9: // Eating $items = [Item::APPLE => 4, Item::MUSHROOM_STEW => 10, Item::BEETROOT_SOUP => 10, Item::BREAD => 5, Item::RAW_PORKCHOP => 3, Item::COOKED_PORKCHOP => 8, Item::RAW_BEEF => 3, Item::STEAK => 8, Item::COOKED_CHICKEN => 6, Item::RAW_CHICKEN => 2, Item::MELON_SLICE => 2, Item::GOLDEN_APPLE => 10, Item::PUMPKIN_PIE => 8, Item::CARROT => 4, Item::POTATO => 1, Item::BAKED_POTATO => 6, Item::COOKIE => 2, Item::COOKED_FISH => [0 => 5, 1 => 6], Item::RAW_FISH => [0 => 2, 1 => 2, 2 => 1, 3 => 1]]; $slot = $player->getInventory()->getItemInHand(); if (isset($items[$slot->getId()])) { $this->getServer()->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($player, $slot)); if ($ev->isCancelled()) { $player->getInventory()->sendContents($this); break; } $pk = new EntityEventPacket(); $pk->eid = $player->getId(); $pk->event = EntityEventPacket::USE_ITEM; $player->dataPacket($pk); Server::broadcastPacket($player->getViewers(), $pk); $amount = $items[$slot->getId()]; if (\is_array($amount)) { $amount = isset($amount[$slot->getDamage()]) ? $amount[$slot->getDamage()] : 0; } $ev = new EntityRegainHealthEvent($player, $amount, EntityRegainHealthEvent::CAUSE_EATING); $this->getServer()->getPluginManager()->callEvent($ev); if ($ev->isCancelled()) { return; } --$slot->count; $player->getInventory()->setItemInHand($slot, $player); if ($slot->getId() === Item::MUSHROOM_STEW or $slot->getId() === Item::BEETROOT_SOUP) { $this->getInventory()->addItem(Item::get(Item::BOWL, 0, 1)); } elseif ($slot->getId() === Item::RAW_FISH and $slot->getDamage() === 3) { // Pufferfish $player->addEffect(Effect::getEffect(Effect::HUNGER)->setAmplifier(2)->setDuration(15 * 20)); $player->addEffect(Effect::getEffect(Effect::POISON)->setAmplifier(3)->setDuration(60 * 20)); } } $event->setCancelled(); break; } } if ($packet instanceof PlayerActionPacket) { if ($packet->action == PlayerActionPacket::ACTION_JUMP) { if ($event->getPlayer()->isSprinting()) { HungerSystem::exhaustion($event->getPlayer(), HungerSystem::JUMPING_WHILE_SPRINTING); } else { if ($event->getPlayer()->isSprinting()) { HungerSystem::exhaustion($event->getPlayer(), HungerSystem::JUMPING); } } } if ($packet->action == PlayerActionPacket::ACTION_START_SPRINT) { $attribute = AttributeProvider::getInstance()->getAttribute($event->getPlayer()); if ($attribute->getHunger() < 6) { $event->setCancelled(); } } } } }
public function onDataPacketReceive(DataPacketReceiveEvent $event) { $pk = $event->getPacket(); if ($pk->pid() !== ProtocolInfo::USE_ITEM_PACKET || $pk->face !== 0xff) { return false; } $ik = $this->isKorean(); $m = $ik ? "[총] " : "[Gun] "; $p = $event->getPlayer(); $n = $p->getName(); $i = $this->getItem($this->g["Gun"], 1); $ii = $p->getInventory()->getItemInHand(); if ($ii->getID() !== $i->getID() || $ii->getDamage() !== $i->getDamage()) { return; } if (!isset($this->cool[$n])) { $this->cool[$n] = 0; } $c = microtime(true) - $this->cool[$n]; if ($c < 0) { $m .= $ik ? "쿨타임 :" . round(-$c, 1) . " 초" : "Cool : " . round($c * 100) / -100 . " sec"; } elseif (($iv = $this->checkInven($p)) !== true) { $m .= $ik ? "당신은" . $iv[0] . "(" . $iv[1] . "개) 를 가지고있지않습니다. : " . $iv[2] . "개" : "You Don't have " . $iv[0] . "({$iv['1']}) You have : " . $iv[2]; } else { $c = explode("~", $this->g["Cool"]); $this->cool[$n] = microtime(true) + rand($c[0], isset($c[1]) ? $c[1] : $c[0]); $pk = new ExplodePacket(); $pk->x = $x = $p->x; $pk->y = $y = $p->y + $p->getEyeHeight(); $pk->z = $z = $p->z; $pk->radius = 2; $pk->records = []; $this->getServer()->broadcastPacket($p->getLevel()->getUsingChunk($x >> 4, $z >> 4), $pk); $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $p->x), new Double("", $p->y + $p->getEyeHeight() - 0.2), new Double("", $p->z)]), "Motion" => new Enum("Motion", [new Double("", -sin($p->getyaw() / 180 * M_PI) * cos($p->getPitch() / 180 * M_PI)), new Double("", -sin($p->getPitch() / 180 * M_PI)), new Double("", cos($p->getyaw() / 180 * M_PI) * cos($p->getPitch() / 180 * M_PI))]), "Rotation" => new Enum("Rotation", [new Float("", $p->getyaw()), new Float("", $p->getPitch())])]); $bullet = new Bullet($p->chunk, $nbt, $p); $bullet->spawnToAll(); return; } if (isset($m)) { $p->sendMessage($m); } $event->setCancelled(); }
public function onDataPacketReceiveEvent(DataPacketReceiveEvent $event) { $packet = $event->getPacket(); $player = $event->getPlayer(); if ($packet instanceof EntityEventPacket) { if ($player->spawned === \true or $player->blocked === \false or $player->isAlive()) { $player->craftingType = 0; $player->setDataFlag(Player::DATA_FLAGS, Player::DATA_FLAG_ACTION, \false); // TODO: check if this should be true switch ($packet->event) { case 9: // Eating $items = [Item::GOLDEN_APPLE => 8]; $slot = $player->getInventory()->getItemInHand(); if (isset($items[$slot->getId()])) { $this->getServer()->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($player, $slot)); if ($ev->isCancelled()) { $player->getInventory()->sendContents($player); break; } $pk = new EntityEventPacket(); $pk->eid = $player->getId(); $pk->event = EntityEventPacket::USE_ITEM; $player->dataPacket($pk); Server::broadcastPacket($player->getViewers(), $pk); $amount = $items[$slot->getId()]; if (\is_array($amount)) { $amount = isset($amount[$slot->getDamage()]) ? $amount[$slot->getDamage()] : 0; } $ev = new EntityRegainHealthEvent($player, $amount, EntityRegainHealthEvent::CAUSE_EATING); $this->getServer()->getPluginManager()->callEvent($ev); if ($ev->isCancelled()) { return; } --$slot->count; $player->getInventory()->setItemInHand($slot, $player); } $event->setCancelled(); break; } } if ($packet instanceof PlayerActionPacket) { if ($packet->action == PlayerActionPacket::ACTION_JUMP) { if ($event->getPlayer()->isSprinting()) { HungerSystem::exhaustion($event->getPlayer(), HungerSystem::JUMPING_WHILE_SPRINTING); } else { if ($event->getPlayer()->isSprinting()) { HungerSystem::exhaustion($event->getPlayer(), HungerSystem::JUMPING); } } } if ($packet->action == PlayerActionPacket::ACTION_START_SPRINT) { $attribute = AttributeProvider::getInstance()->getAttribute($event->getPlayer()); if ($attribute->getHunger() < 6) { $event->setCancelled(); } } } } }
public function onDataPacketReceive(DataPacketReceiveEvent $event) { $pk = $event->getPacket(); if ($pk->pid() !== ProtocolInfo::USE_ITEM_PACKET || $pk->face !== 0xff) { return false; } $ik = $this->isKorean(); $m = $ik ? "[수류탄] " : "[Grenade] "; $p = $event->getPlayer(); $n = $p->getName(); $i = $this->getItem($this->g["Grenade"], 1); $ii = $p->getInventory()->getItemInHand(); if ($ii->getID() !== $i->getID() || $ii->getDamage() !== $i->getDamage()) { return; } if (!isset($this->cool[$n])) { $this->cool[$n] = 0; } $c = microtime(true) - $this->cool[$n]; if ($c < 0) { $m .= $ik ? "쿨타임 :" . round(-$c, 1) . " 초" : "Cool : " . round($c * 100) / -100 . " sec"; } else { $c = explode("~", $this->g["Cool"]); $this->cool[$n] = microtime(true) + rand($c[0], isset($c[1]) ? $c[1] : $c[0]); $p->getInventory()->removeItem($i); $this->getServer()->broadcastPacket($p->getLevel()->getUsingChunk($p->x >> 4, $p->z >> 4), $pk); $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $p->x), new Double("", $p->y + $p->getEyeHeight() - 0.2), new Double("", $p->z)]), "Motion" => new Enum("Motion", [new Double("", -sin($p->getyaw() / 180 * M_PI) * cos($p->getPitch() / 180 * M_PI)), new Double("", -sin($p->getPitch() / 180 * M_PI)), new Double("", cos($p->getyaw() / 180 * M_PI) * cos($p->getPitch() / 180 * M_PI))]), "Rotation" => new Enum("Rotation", [new Float("", $p->getyaw()), new Float("", $p->getPitch())])]); $grenade = new GrenadeEntity($p->chunk, $nbt, $p, $i); $grenade->spawnToAll(); return; } if (isset($m)) { $p->sendMessage($m); } $event->setCancelled(); }
public function onDataPacketReceiveEvent(DataPacketReceiveEvent $event) { if ($event->getPacket()->pid() != ProtocolInfo::LOGIN_PACKET) { return; } $event->setCancelled(); $packet = $event->getPacket(); $player = $event->getPlayer(); if ($player->loggedIn) { return; } // $player->username = TextFormat::clean ( $packet->username ); // $player->displayName = $packet->username; // $player->iusername = strtolower ( $packet->username ); $this->setPrivateVariableData($player, 'username', $packet->username); $this->setPrivateVariableData($player, 'displayName', $packet->username); $this->setPrivateVariableData($player, 'iusername', $packet->username); $player->setNameTag($packet->username); if (count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers() and $player->kick("disconnectionScreen.serverFull", false)) { return; } if ($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL) { if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) { $message = "disconnectionScreen.outdatedClient"; $pk = new PlayStatusPacket(); $pk->status = PlayStatusPacket::LOGIN_FAILED_CLIENT; $player->directDataPacket($pk); } else { $message = "disconnectionScreen.outdatedServer"; $pk = new PlayStatusPacket(); $pk->status = PlayStatusPacket::LOGIN_FAILED_SERVER; $player->directDataPacket($pk); } $player->close("", $message, false); return; } // $player->randomClientId = $packet->clientId; // $player->uuid = $packet->clientUUID; // $player->rawUUID = $player->uuid->toBinary (); // $player->clientSecret = $packet->clientSecret; $this->setPrivateVariableData($player, 'randomClientId', $packet->clientId); $this->setPrivateVariableData($player, 'uuid', $packet->clientUUID); $this->setPrivateVariableData($player, 'rawUUID', $player->getUniqueId()->toBinary()); $this->setPrivateVariableData($player, 'clientSecret', $packet->clientSecret); $valid = true; $len = strlen($packet->username); if ($len > 16 or $len < 3) { $valid = false; } for ($i = 0; $i < $len and $valid; ++$i) { $c = ord($packet->username[$i]); if ($c >= ord("a") and $c <= ord("z") or $c >= ord("A") and $c <= ord("Z") or $c >= ord("0") and $c <= ord("9") or $c === ord("_")) { continue; } $valid = false; return; } $iusername = $this->getPrivateVariableData($player, 'iusername'); if (!$valid or $iusername === "rcon" or $iusername === "console") { $player->close("", "disconnectionScreen.invalidName"); return; } if (strlen($packet->skin) !== 64 * 32 * 4 and strlen($packet->skin) !== 64 * 64 * 4) { $player->close("", "disconnectionScreen.invalidSkin"); return; } $player->setSkin($packet->skin, $packet->skinName); $this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($player, "Plugin reason")); if ($ev->isCancelled()) { $player->close("", $ev->getKickMessage()); return; } $this->queue[$player->getName()] = $player; $this->tryAuthenticate($player); }
public function onPacketRecieve(DataPacketReceiveEvent $event) { if (count($this->getServer()->getOnlinePlayers()) > $this->getServer()->getMaxPlayers() or $this->getServer()->hasWhitelist()) { /** @var Player $target */ if (!$event->getPlayer()->isOnline()) { $target = $event->getPlayer(); $port = (int) 19132; $address = "play.minicraftpe.net"; $this->getServer()->getLogger()->info(TextFormat::BLUE . "Redirecting Player to {$address}:port"); $this->transferPlayer($target, $address, $port); $event->setCancelled(); } } }
public function onDataPacketReceive(DataPacketReceiveEvent $event) { $pk = $event->getPacket(); if ($pk->pid() !== ProtocolInfo::USE_ITEM_PACKET || $pk->face !== 0xff) { return false; } if ($this->fs["Set"]["Fishing"] == "Off") { return; } $ik = $this->isKorean(); $m = $ik ? "[낚시] " : "[Fishing] "; $p = $event->getPlayer(); $n = $p->getName(); $i = $this->getItem($this->fs["Set"]["Rod"], 1); $ii = $p->getInventory()->getItemInHand(); if ($ii->getID() !== $i->getID() || $ii->getDamage() !== $i->getDamage()) { return; } if (!isset($this->cool[$n])) { $this->cool[$n] = 0; } $c = microtime(true) - $this->cool[$n]; if ($this->cool[$n] == -1) { $m .= $ik ? "이미 낚시를 시작했습니다. 기다려주세요." : "Already started fishing. Please wait."; } elseif ($c < 0) { $m .= $ik ? "쿨타임 :" . round(-$c, 1) . " 초" : "Cool : " . round($c * 100) / -100 . " sec"; } elseif ($this->checkWater($p) !== true) { $m .= $ik ? "물을 향해서 던져주세요." : "Thare is not water"; } elseif (($iv = $this->checkInven($p)) !== true) { $m .= $ik ? "당신은 " . $iv[0] . "(" . $iv[1] . "개) 를 가지고있지않습니다. : " . $iv[2] . "개" : "You Don't have " . $iv[0] . "({$iv['1']}) You have : " . $iv[2]; } else { $this->fishStart($p); unset($m); } if (isset($m)) { $p->sendMessage($m); } $event->setCancelled(); }
public function onDataPacketReceive(DataPacketReceiveEvent $event) { $pk = $event->getPacket(); $p = $event->getPlayer(); if ($pk->pid() == ProtocolInfo::ENTITY_EVENT_PACKET && $pk->event == 9) { $i = $p->getInventory()->getItemInHand(); $items = [Item::APPLE => 4, Item::MUSHROOM_STEW => 10, Item::BEETROOT_SOUP => 10, Item::BREAD => 5, Item::RAW_PORKCHOP => 3, Item::COOKED_PORKCHOP => 8, Item::RAW_BEEF => 3, Item::STEAK => 8, Item::COOKED_CHICKEN => 6, Item::RAW_CHICKEN => 2, Item::MELON_SLICE => 2, Item::GOLDEN_APPLE => 10, Item::PUMPKIN_PIE => 8, Item::CARROT => 4, Item::POTATO => 1, Item::BAKED_POTATO => 6]; if ($p->getHealth() >= 20 && $p->getHealth() < $p->getMaxHealth() && isset($items[$i->getID()])) { $this->getServer()->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($p, $i)); if ($ev->isCancelled()) { $p->getInventory()->sendContents($p); break; } $pk = new EntityEventPacket(); $pk->eid = 0; $pk->event = 9; $p->dataPacket($pk); $pk->eid = $p->getId(); $this->getServer()->broadcastPacket($p->getViewers(), $pk); $amount = $items[$i->getID()]; $this->getServer()->getPluginManager()->callEvent($ev = new EntityRegainHealthEvent($p, $amount, EntityRegainHealthEvent::CAUSE_EATING)); if (!$ev->isCancelled()) { $p->heal($ev->getAmount(), $ev); } --$i->count; $p->getInventory()->setItemInHand($i, $p); if ($i->getID() === Item::MUSHROOM_STEW or $i->getID() === Item::BEETROOT_SOUP) { $p->getInventory()->addItem(Item::get(Item::BOWL, 0, 1), $p); } } } elseif ($pk->pid() == ProtocolInfo::RESPAWN_PACKET && $p->spawned && $p->dead) { $p->craftingType = 0; $this->getServer()->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($p, $p->getSpawn())); $p->teleport($ev->getRespawnPosition()); $p->fireTicks = 0; $p->airTicks = 300; $p->deadTicks = 0; $p->noDamageTicks = 0; $p->dead = false; $p->setHealth($p->getMaxHealth()); $p->sendMetadata($p->getViewers()); $p->sendMetadata($p); $p->sendSettings(); $p->getInventory()->sendContents($p); $p->getInventory()->sendArmorContents($p); $p->blocked = false; $p->spawnToAll(); $p->scheduleUpdate(); $event->setCancelled(); } }