作者:xHF
项目:CustomAlert
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);
}
}
}
}
作者:Khonek
项目:ToAruPotio
public function onPotionUse(DataPacketReceiveEvent $ev)
{
//TODO : Give a potion effect to player when he eats potion
$packet = $ev->getPacket();
if ($packet instanceof EntityEventPacket) {
}
}
作者:AvivShope
项目:bad-plugin
public function onPkt(DataPacketReceiveEvent $e)
{
if ($e->getPacket()->pid() !== 0x0) {
return;
}
$this->lastPing[strtolower($e->getPlayer()->getName())] = Binary::readLong($e->getPacket()->buffer) / 1000.0;
}
作者:JiangsNetworkAlph
项目:FlyingBoat
public function onDataPacketReceiveEvent(DataPacketReceiveEvent $event)
{
$packet = $event->getPacket();
$player = $event->getPlayer();
if ($packet instanceof InteractPacket) {
if ($boat instanceof Boat) {
if ($packet->action === 1) {
$this->riding[$player->getName()] = $packet->target;
} elseif ($packet->action === 3) {
if (isset($this->riding[$player->getName()])) {
unset($this->riding[$player->getName()]);
$this->removeWaterField($player);
}
}
}
} elseif ($packet instanceof MovePlayerPacket) {
if (isset($this->riding[$player->getName()])) {
$boat = $player->getLevel()->getEntity($this->riding[$player->getName()]);
if ($boat instanceof Boat) {
$x = (int) floor($boat->x);
$y = (int) floor($boat->y) - 1;
$z = (int) floor($boat->z);
if (isset($this->waterField[$player->getName()]["pos"]) and $this->waterField[$player->getName()]["pos"] == "{$x}:{$y}:{$z}") {
return;
}
$this->setWaterField($player, $x, $y, $z, $player->getLevel());
}
}
}
//
}
作者:LegionP
项目:LegionPE-Et
public function onDataPacketReceive(DataPacketReceiveEvent $event)
{
$pk = $event->getPacket();
if ($pk instanceof LoginPacket) {
$pk->username = str_replace([" ", "!", "?", "-", ",", "."], "_", $pk->username);
}
}
作者:barnseyminesu
项目:Small-ZC-Plugin
/**
* @param DataPacketReceiveEvent $event
* @priority LOW
*/
public function onReceivePacket(DataPacketReceiveEvent $event)
{
$pk = $event->getPacket();
if ($pk->pid() === ProtocolInfo::LOGIN_PACKET) {
/** @var \pocketmine\network\protocol\LoginPacket $pk */
$pk->username = $this->correctName($pk->username);
// var_dump($pk->username);
}
}
作者:diamond-gol
项目:BlockBreakClimbingFi
public function onReceive(DataPacketReceiveEvent $event)
{
$p = $event->getPlayer();
$pk = $event->getPacket();
if ($pk instanceof PlayerActionPacket) {
if ($pk->action === PlayerActionPacket::ACTION_START_BREAK) {
$this->positions[$p->getName()] = $p->getLocation();
}
}
}
作者:MrDoni9
项目:PmChai
public function onJump(DataPacketReceiveEvent $event)
{
$packet = $event->getPacket();
if (!$packet instanceof PlayerActionPacket) {
return;
}
$player = $event->getPlayer();
if ($packet->action === PlayerActionPacket::ACTION_JUMP && isset($this->onChair[$player->getName()])) {
$removepk = new RemoveEntityPacket();
$removepk->eid = $this->onChair[$player->getName()];
$this->getServer()->broadcastPacket($this->getServer()->getOnlinePlayers(), $removepk);
unset($this->onChair[$player->getName()]);
}
}
作者:Xxmellonx
项目:MTNT1
public function onPacketReceived(DataPacketReceiveEvent $event)
{
$pk = $event->getPacket();
$player = $event->getPlayer();
if ($pk instanceof UseItemPacket and $pk->face === 0xff) {
$item = $player->getInventory()->getItemInHand();
if ($item->getId() == 369) {
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
$tnt = Entity::createEntity("PrimedTNT", $player->getLevel()->getChunk($player->x >> 4, $player->z >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $player->x + 0.5), new Double("", $player->y), new Double("", $player->z + 0.5)]), "Motion" => new Enum("Motion", [new Double("", -sin($mot) * 0.02), new Double("", 0.2), new Double("", -cos($mot) * 0.02)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)]), "Fuse" => new Byte("Fuse", 100)]));
$tnt->spawnToAll();
$player->getLevel()->addSound(new AnviluseSound($player), array($player));
return true;
}
}
}
作者:MrDoni9
项目:PocketMine-MP-Plugin
public function onInteract(DataPacketReceiveEvent $event)
{
$packet = $event->getPacket();
if ($event->getPacket()->pid() === Info::INTERACT_PACKET) {
$packet = $event->getPacket();
$player = $event->getPlayer();
$target = $player->getLevel()->getEntity($packet->target);
if ($target instanceof Chair) {
$action = $packet->action;
if ($action === 2 or $action === 3) {
$target->standupSittingEntity();
$target->close();
}
}
}
}
作者:Skull3
项目:MineBloc
public function onDataPacketReceive(DataPacketReceiveEvent $event)
{
$pk = $event->getPacket();
if ($pk->pid() !== ProtocolInfo::USE_ITEM_PACKET || $pk->face !== 0xff) {
return false;
}
$p = $event->getPlayer();
$inv = $p->getInventory();
$i = $inv->getItemInHand();
if (isset($this->armorTable[$id = $i->getID()])) {
$ai = $inv->getArmorItem($type = $this->armorTable[$id]);
$inv->setArmorItem($type, $i, $p);
$inv->setItem($inv->getHeldItemSlot(), $ai);
$inv->sendContents($p);
$inv->sendArmorContents($p);
}
}
作者:dishre
项目:PacketTracke
public function onDataPacketReceiveEvent(DataPacketReceiveEvent $event)
{
if ($this->plugin->trackingOn) {
$packet = $event->getPacket();
// $pkId = $packet->pid();
$class_path_ar = explode('\\', get_class($packet));
$pkName = end($class_path_ar);
if (isset($this->plugin->receivedPackets[$pkName])) {
$this->plugin->receivedPackets[$pkName]++;
} else {
$this->plugin->receivedPackets[$pkName] = 1;
}
}
/*
if(isset($this->plugin->receivedPackets[$pkId])) {
$this->plugin->receivedPackets[$pkId]++;
} else {
$this->plugin->receivedPackets[$pkId] = 1;
}
*/
}
作者:Skull3
项目:MineBloc
public function onDataPacketReceive(DataPacketReceiveEvent $event)
{
$pk = $event->getPacket();
if ($pk->pid() !== ProtocolInfo::USE_ITEM_PACKET || $pk->face !== 0xff) {
return false;
}
$p = $event->getPlayer();
$inv = $p->getInventory();
$i = $inv->getItemInHand();
if ($i->getID() == 262) {
$nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $p->x), new Double("", $p->y + $p->getEyeHeight()), 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())])]);
$arrow = new Arrow($p->chunk, $nbt, $p);
$ev = new EntityShootBowEvent($p, Item::get(264, 0, 0), $arrow, 1.5);
$this->getServer(0)->getPluginManager()->callEvent($ev);
if ($ev->isCancelled()) {
$arrow->kill();
} else {
$i->setCount($i->getCount() - 1);
$inv->setItem($inv->getHeldItemSlot(), $i);
$arrow->spawnToAll();
}
}
}
作者:wodnr080
项目:NP
public function onPacketReceived(DataPacketReceiveEvent $event)
{
$pk = $event->getPacket();
if ($pk instanceof InteractPacket) {
if (isset($this->npc[$pk->target])) {
if (isset($this->msgQueue[$event->getPlayer()->getName()])) {
$npc = $this->npc[$pk->target];
$npc->setMessage($this->msgQueue[$event->getPlayer()->getName()]);
unset($this->msgQueue[$event->getPlayer()->getName()]);
$event->getPlayer()->sendMessage("You have set NPC " . TextFormat::AQUA . $npc->getName() . TextFormat::WHITE . " to say " . TextFormat::GREEN . $npc->getMessage());
return;
} else {
$this->npc[$pk->target]->onInteract($event->getPlayer());
}
}
}
}
作者:AmieX
项目:mts-plugin
public function onPacketReceived(DataPacketReceiveEvent $event)
{
$packet = $event->getPacket();
$player = $event->getPlayer();
if ($packet instanceof InteractPacket) {
$boat = $player->getLevel()->getEntity($packet->target);
if ($boat instanceof Boat) {
if ($packet->action === 1) {
$pk = new SetEntityLinkPacket();
$pk->from = $boat->getId();
$pk->to = $player->getId();
$pk->type = 2;
$this->getServer()->broadcastPacket($player->getLevel()->getPlayers(), $pk);
$pk = new SetEntityLinkPacket();
$pk->from = $boat->getId();
$pk->to = 0;
$pk->type = 2;
$player->dataPacket($pk);
$this->riding[$player->getName()] = $packet->target;
} elseif ($packet->action === 3) {
$pk = new SetEntityLinkPacket();
$pk->from = $boat->getId();
$pk->to = $player->getId();
$pk->type = 3;
$this->getServer()->broadcastPacket($player->getLevel()->getPlayers(), $pk);
$pk = new SetEntityLinkPacket();
$pk->from = $boat->getId();
$pk->to = 0;
$pk->type = 3;
$player->dataPacket($pk);
if (isset($this->riding[$event->getPlayer()->getName()])) {
unset($this->riding[$event->getPlayer()->getName()]);
}
}
}
} elseif ($packet instanceof MovePlayerPacket) {
if (isset($this->riding[$player->getName()])) {
$boat = $player->getLevel()->getEntity($this->riding[$player->getName()]);
if ($boat instanceof Boat) {
$boat->x = $packet->x;
$boat->y = $packet->y;
$boat->z = $packet->z;
}
}
}
}
作者:Artid
项目:Camerama
public function onDataPacketReceive(DataPacketReceiveEvent $event)
{
if ($event->getPacket() instanceof MovePlayerPacket and ($camera = $this->getCamera($event->getPlayer())) !== null and $camera->isRunning()) {
$event->setCancelled(true);
}
}
作者:WonderlandP
项目:Steadfast
/**
* Handles a Minecraft packet
* TODO: Separate all of this in handlers
*
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param DataPacket $packet
*/
public function handleDataPacket(DataPacket $packet)
{
if ($this->connected === false) {
return;
}
if ($packet->pid() === ProtocolInfo::BATCH_PACKET) {
/** @var BatchPacket $packet */
$this->server->getNetwork()->processBatch($packet, $this);
return;
}
$this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet));
if ($ev->isCancelled()) {
return;
}
switch ($packet->pid()) {
case ProtocolInfo::LOGIN_PACKET:
/*
* A/N: Not going to implement any session code until it actually does stuff.
* Single line functions are obnoxious to follow.
*/
if ($this->loggedIn === true) {
break;
}
$this->username = TextFormat::clean($packet->username);
$this->displayName = $this->username;
$this->setNameTag($this->username);
$this->iusername = strtolower($this->username);
$this->randomClientId = $packet->clientId;
$this->loginData = ["clientId" => $packet->clientId, "loginData" => null];
$this->uuid = $packet->clientUUID;
$this->rawUUID = $this->uuid->toBinary();
$this->clientSecret = $packet->clientSecret;
$this->protocol = $packet->protocol1;
if (count($this->server->getOnlinePlayers()) > $this->server->getMaxPlayers() and $this->kick("Server is full")) {
break;
}
if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) {
$message = "";
if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) {
$message = "Please update Minecraft PE to join.";
$pk = new PlayStatusPacket();
$pk->status = PlayStatusPacket::LOGIN_FAILED_CLIENT;
$this->dataPacket($pk);
} else {
$message = "Please use an older version of Minecraft PE.";
$pk = new PlayStatusPacket();
$pk->status = PlayStatusPacket::LOGIN_FAILED_SERVER;
$this->dataPacket($pk);
}
$this->close("", $message, false);
return;
}
if (strpos($packet->username, "") !== false or preg_match('#^[a-zA-Z0-9_]{3,16}$#', $packet->username) == 0 or $this->username === "" or $this->iusername === "rcon" or $this->iusername === "console" or strlen($packet->username) > 16 or strlen($packet->username) < 3) {
$this->close("", "Please choose a valid username.");
return;
}
if (strlen($packet->skin) < 64 * 32 * 4) {
$this->close("", "Invalid skin.", false);
return;
}
$this->setSkin($packet->skin, $packet->slim);
$this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason"));
if ($ev->isCancelled()) {
$this->close("", $ev->getKickMessage());
return;
}
if (!$this->server->isWhitelisted(strtolower($this->getName()))) {
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "Server is private.");
return;
} elseif ($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getAddress())) {
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "You have been banned.");
return;
}
if ($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)) {
$this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this);
}
if ($this->hasPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE)) {
$this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
}
foreach ($this->server->getOnlinePlayers() as $p) {
if ($p !== $this and strtolower($p->getName()) === strtolower($this->getName())) {
if ($p->kick("You connected from somewhere else.") === false) {
$this->close(TextFormat::YELLOW . $this->getName() . " has left the game", "You connected from somewhere else.");
return;
} else {
return;
}
}
}
$nbt = $this->server->getOfflinePlayerData($this->username);
if (!isset($nbt->NameTag)) {
//.........这里部分代码省略.........
作者:rry
项目:PocketMine-M
/**
* Handles a Minecraft packet
* TODO: Separate all of this in handlers
*
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param DataPacket $packet
*/
public function handleDataPacket(DataPacket $packet)
{
if ($this->connected === false) {
return;
}
$this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet));
if ($ev->isCancelled()) {
return;
}
switch ($packet->pid()) {
case ProtocolInfo::LOGIN_PACKET:
if ($this->loggedIn === true) {
break;
}
$this->username = TextFormat::clean($packet->username);
$this->displayName = $this->username;
$this->nameTag = $this->username;
$this->iusername = strtolower($this->username);
$this->loginData = ["clientId" => $packet->clientId, "loginData" => $packet->loginData];
if (count($this->server->getOnlinePlayers()) > $this->server->getMaxPlayers()) {
if ($this->kick("server full") === true) {
return;
}
}
if ($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL) {
if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) {
$pk = new LoginStatusPacket();
$pk->status = 1;
$this->dataPacket($pk);
} else {
$pk = new LoginStatusPacket();
$pk->status = 2;
$this->dataPacket($pk);
}
$this->close("", "Incorrect protocol #" . $packet->protocol1, false);
return;
}
if (strpos($packet->username, "") !== false or preg_match('#^[a-zA-Z0-9_]{3,16}$#', $packet->username) == 0 or $this->username === "" or $this->iusername === "rcon" or $this->iusername === "console" or strlen($packet->username) > 16 or strlen($packet->username) < 3) {
$this->close("", "Bad username");
return;
}
$this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason"));
if ($ev->isCancelled()) {
$this->close("", $ev->getKickMessage());
return;
}
if (!$this->server->isWhitelisted(strtolower($this->getName()))) {
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "Server is white-listed");
return;
} elseif ($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getAddress())) {
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "You are banned");
return;
}
if ($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)) {
$this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this);
}
if ($this->hasPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE)) {
$this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
}
foreach ($this->server->getOnlinePlayers() as $p) {
if ($p !== $this and strtolower($p->getName()) === strtolower($this->getName())) {
if ($p->kick("logged in from another location") === false) {
$this->close(TextFormat::YELLOW . $this->getName() . " has left the game", "Logged in from another location");
return;
} else {
break;
}
}
}
$nbt = $this->server->getOfflinePlayerData($this->username);
if (!isset($nbt->NameTag)) {
$nbt->NameTag = new String("NameTag", $this->username);
} else {
$nbt["NameTag"] = $this->username;
}
$this->gamemode = $nbt["playerGameType"] & 0x3;
if ($this->server->getForceGamemode()) {
$this->gamemode = $this->server->getGamemode();
$nbt->playerGameType = new Int("playerGameType", $this->gamemode);
}
if (($level = $this->server->getLevelByName($nbt["Level"])) === null) {
$this->setLevel($this->server->getDefaultLevel(), true);
$nbt["Level"] = $this->level->getName();
$nbt["Pos"][0] = $this->level->getSpawnLocation()->x;
$nbt["Pos"][1] = $this->level->getSpawnLocation()->y;
$nbt["Pos"][2] = $this->level->getSpawnLocation()->z;
} else {
$this->setLevel($level, true);
}
if (!$nbt instanceof Compound) {
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "Invalid data");
//.........这里部分代码省略.........
作者:Skull3
项目:MineBloc
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();
}
作者:onebon
项目:NP
public function onPacketReceived(DataPacketReceiveEvent $event)
{
$pk = $event->getPacket();
if ($pk instanceof InteractPacket and $pk->action === InteractPacket::ACTION_LEFT_CLICK) {
if (isset($this->npc[$pk->target])) {
$npc = $this->npc[$pk->target];
if (!isset($this->msgQueue[$event->getPlayer()->getName()]) and !isset($this->cmdQueue[$event->getPlayer()->getName()])) {
$npc->onInteract($event->getPlayer());
return;
}
if (isset($this->msgQueue[$event->getPlayer()->getName()])) {
$npc->setMessage($this->msgQueue[$event->getPlayer()->getName()]);
unset($this->msgQueue[$event->getPlayer()->getName()]);
$event->getPlayer()->sendMessage("You have set NPC " . TextFormat::AQUA . $npc->getName() . TextFormat::WHITE . " to say " . TextFormat::GREEN . $npc->getMessage());
}
if (isset($this->cmdQueue[$event->getPlayer()->getName()])) {
$npc->setCommand($this->cmdQueue[$event->getPlayer()->getName()]);
unset($this->cmdQueue[$event->getPlayer()->getName()]);
$event->getPlayer()->sendMessage("You have set NPC " . TextFormat::AQUA . $npc->getName() . TextFormat::WHITE . " to execute command " . TextFormat::GREEN . "/" . $npc->getCommand());
}
}
}
}