Skip to content

Commit

Permalink
Do not use magic numbers for net.Read/WriteEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
robotboy655 committed Jun 27, 2023
1 parent 7a13754 commit 0bb9c8d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions garrysmod/lua/includes/extensions/net.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

-- This is just enough for the entity index. This however is not perfect
-- as the entity at given index may have changed during transport.
-- If this becomes a problem, inclusion of entity's serial will also be necessary
local MAX_EDICT_BITS = 13

TYPE_COLOR = 255

net.Receivers = {}
Expand Down Expand Up @@ -51,16 +56,16 @@ end
function net.WriteEntity( ent )

if ( !IsValid( ent ) ) then
net.WriteUInt( 0, 13 )
net.WriteUInt( 0, MAX_EDICT_BITS )
else
net.WriteUInt( ent:EntIndex(), 13 )
net.WriteUInt( ent:EntIndex(), MAX_EDICT_BITS )
end

end

function net.ReadEntity()

local i = net.ReadUInt( 13 )
local i = net.ReadUInt( MAX_EDICT_BITS )
if ( !i ) then return end

return Entity( i )
Expand Down

0 comments on commit 0bb9c8d

Please sign in to comment.