wiremod / advduplicator

Garry's Mod add-on that allows a player to save and load contraptions
http://www.wiremod.com
Apache License 2.0
67 stars 43 forks source link

User messages are obsolete #92

Open dvdvideo1234 opened 2 months ago

dvdvideo1234 commented 2 months ago

Consider user messages being deprecated:

function AdvDupe.SendClientError(ply, errormsg, NoSound)
    if ( !IsValid(ply) or !ply:IsPlayer() or !errormsg ) then return end
    MsgN("AdvDupe: Sending this ErrorMsg to ",tostring(ply),"\nAdvDupe-ERROR: \"",tostring(errormsg).."\"")
    umsg.Start("AdvDupeCLError", ply)
        umsg.String(errormsg)
        umsg.Bool(NoSound)
    umsg.End("AdvDupeCLError")
end

usermessage.Hook("AdvDupeCLError", AdvDupeCLError)

To become:

if(SERVER) then
  util.AddNetworkString("AdvDupeCLError")
else

  function AdvDupeCLError(len, ply) 
    AdvDupeClient.Error( net.ReadString(), net.ReadBool() )
  end

  net.Receive("AdvDupeCLError", AdvDupeCLError)
end

--- Somewhere in the server code

function AdvDupe.SendClientError(ply, errormsg, NoSound)
  if ( not (IsValid(ply) and ply:IsPlayer()) ) then return end -- Validate player only to check for empty error messages
  MsgN("AdvDupe: Sending this error message to ",ply:Nick(),"\nAdvDupe-ERROR: \"",tostring(errormsg ).."\"")
    net.Start("AdvDupeCLError")
      net.WriteString(errormsg)
      net.WriteBool(NoSound)
    net.Send(ply)
end

AdvSupe1 better switch to the net library.