Skip to content

Commit

Permalink
Do not rebroadcast $emoteLengthTicks
Browse files Browse the repository at this point in the history
Seems to be irrelevant for the client, we cannot risk rebroadcasting random values received
  • Loading branch information
IvanCraft623 committed Sep 19, 2024
1 parent c92f938 commit d828172
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/entity/Human.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ public function jump() : void{
}
}

public function emote(string $emoteId, int $emoteLengthTicks = 0) : void{
public function emote(string $emoteId) : void{
NetworkBroadcastUtils::broadcastEntityEvent(
$this->getViewers(),
fn(EntityEventBroadcaster $broadcaster, array $recipients) => $broadcaster->onEmote($recipients, $this, $emoteId, $emoteLengthTicks)
fn(EntityEventBroadcaster $broadcaster, array $recipients) => $broadcaster->onEmote($recipients, $this, $emoteId)
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/network/mcpe/EntityEventBroadcaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ public function onPickUpItem(array $recipients, Entity $collector, Entity $picke
/**
* @param NetworkSession[] $recipients
*/
public function onEmote(array $recipients, Human $from, string $emoteId, int $emoteLengthTicks) : void;
public function onEmote(array $recipients, Human $from, string $emoteId) : void;
}
11 changes: 9 additions & 2 deletions src/network/mcpe/StandardEntityEventBroadcaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,14 @@ public function onPickUpItem(array $recipients, Entity $collector, Entity $picke
$this->sendDataPacket($recipients, TakeItemActorPacket::create($collector->getId(), $pickedUp->getId()));
}

public function onEmote(array $recipients, Human $from, string $emoteId, int $emoteLengthTicks) : void{
$this->sendDataPacket($recipients, EmotePacket::create($from->getId(), $emoteId, $emoteLengthTicks, "", "", EmotePacket::FLAG_SERVER | EmotePacket::FLAG_MUTE_ANNOUNCEMENT));
public function onEmote(array $recipients, Human $from, string $emoteId) : void{
$this->sendDataPacket($recipients, EmotePacket::create(
$from->getId(),
$emoteId,
0, //seems to be irrelevant for the client, we cannot risk rebroadcasting random values received
"",
"",
EmotePacket::FLAG_SERVER | EmotePacket::FLAG_MUTE_ANNOUNCEMENT
));
}
}
2 changes: 1 addition & 1 deletion src/network/mcpe/handler/InGamePacketHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{
}

public function handleEmote(EmotePacket $packet) : bool{
$this->player->emote($packet->getEmoteId(), $packet->getEmoteLengthTicks());
$this->player->emote($packet->getEmoteId());
return true;
}
}
4 changes: 2 additions & 2 deletions src/player/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -2013,15 +2013,15 @@ public function toggleSwim(bool $swim) : bool{
return true;
}

public function emote(string $emoteId, int $emoteLengthTicks = 0) : void{
public function emote(string $emoteId) : void{
$currentTick = $this->server->getTick();
if($currentTick - $this->lastEmoteTick > 5){
$this->lastEmoteTick = $currentTick;
$event = new PlayerEmoteEvent($this, $emoteId);
$event->call();
if(!$event->isCancelled()){
$emoteId = $event->getEmoteId();
parent::emote($emoteId, $emoteLengthTicks);
parent::emote($emoteId);
}
}
}
Expand Down

0 comments on commit d828172

Please sign in to comment.