Codeblocks

Untitled

Aug 2nd, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.97 KB | None | 0 0
  1. --Simple test that shows how awful the net library is, and what makes it so impractical as a 'usermessage' alernative in source.
  2. --The problems in the 'net' library stem from the fact that it sends it's queue out a frame earlier than usermessages, so they're received, and handled first.
  3. --Because source engine relies on usermessages for entity creation, and everything else there's no guarentee.
  4. --That these objects that should exist when the message is received, do exist on the client.
  5. --This is NOT PVS related, there are cases with 'usermessage' when the object that's created is too far and it is,
  6. --But not in this case, the object can be created on the server BEFORE the server sends out the net-msg,
  7. --And at-least 1 frame before the client receives the usermessage telling it that this entity has been created,
  8. --The 'net' library has already received, and handled it's message, this creates problems like:
  9.  
  10. --1) You will have to use timer.Simple(0, function() end) needlessy throughout your script when sending information
  11. --  about a new entity over the network via the 'net' library. (And even this isn't reliable w/ the net library, umsg guarentees delivery order.)
  12. --2) All source-object related networking functions don't guarentee that the client has knowledge of this object existing
  13. --  before handling the received 'net' msg that contains info about said object.
  14.  
  15. if SERVER then
  16.     hook.Add("PlayerSpawn", "NETMSGSUCKS::PlayerSpawn", function(player)
  17.         local ent = ents.Create("prop_physics")
  18.         ent:SetModel("models/error.mdl")
  19.         ent:SetPos(player:GetPos())
  20.         ent:Spawn()
  21.         net.Start("test")
  22.             net.WriteEntity(ent)
  23.         net.Send(player)
  24.         umsg.Start("test", player)
  25.             umsg.Entity(ent)
  26.         umsg.End()
  27.     end)
  28. end
  29.  
  30. if CLIENT then
  31.     net.Receive("test", function(len)
  32.         print("Net: " .. tostring(IsValid(net.ReadEntity))
  33.     end)
  34.  
  35.     umsg.Hook("test", function(msg) --msg being our bf_read object. (Part of source engine.)
  36.         print("Umsg: "tostring(msg:ReadEntity()))
  37.     end)
  38. ebd
Add Comment
Please, Sign In to add comment