Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ImNotAVirus/elvengard_network
Browse files Browse the repository at this point in the history
  • Loading branch information
ImNotAVirus committed Jun 28, 2024
2 parents 5fb5056 + 2be6570 commit d950017
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/elven_gard/network/packet_serializer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,21 @@ defmodule ElvenGard.Network.PacketSerializer do
case Keyword.get(opts, :if) do
nil ->
quote location: :keep do
unquote(type).encode(Map.fetch!(var!(packet), unquote(name)), unquote(opts))
case {Map.fetch!(var!(packet), unquote(name)), unquote(opts)[:default]} do
{nil, value} when not is_nil(value) -> value
{value, _} -> unquote(type).encode(value, unquote(opts))
end
end

condition ->
quote location: :keep do
if unquote(condition) in [nil, false] do
:"$drop"
else
unquote(type).encode(Map.fetch!(var!(packet), unquote(name)), unquote(opts))
case {Map.fetch!(var!(packet), unquote(name)), unquote(opts)[:default]} do
{nil, value} when not is_nil(value) -> value
{value, _} -> unquote(type).encode(value, unquote(opts))
end
end
end
end
Expand Down

0 comments on commit d950017

Please sign in to comment.