Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions lua/wire/stools/expression2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -343,22 +343,28 @@ if SERVER then
-- ------------------------------------------------------------
-- Serverside Receive
-- ------------------------------------------------------------
local function SendFailedUpload(ply, reason)
net.Start("wire_expression2_upload")
net.WriteString(reason)
net.Send(ply)
end

net.Receive("wire_expression2_upload", function(len, ply)
local toentID = net.ReadUInt(16)
local toent = Entity(toentID)

if (not IsValid(toent) or toent:GetClass() ~= "gmod_wire_expression2") then
WireLib.AddNotify(ply, "Invalid Expression chip specified. Upload aborted.", NOTIFY_ERROR, 7, NOTIFYSOUND_DRIP3)
SendFailedUpload(ply, "Invalid Expression chip specified. Upload aborted.")
return
end

if not WireLib.CanTool(ply, toent, "wire_expression2") then
WireLib.AddNotify(ply, "You are not allowed to upload to the target Expression chip. Upload aborted.", NOTIFY_ERROR, 7, NOTIFYSOUND_DRIP3)
SendFailedUpload(ply, "You are not allowed to upload to the target Expression chip. Upload aborted.")
return
end

if toent.Uploading then
WireLib.AddNotify(ply, "This Expression chip is already uploading. Upload aborted.", NOTIFY_ERROR, 7, NOTIFYSOUND_DRIP3)
SendFailedUpload(ply, "This Expression chip is already uploading. Upload aborted.")
return
end
toent.Uploading = true
Expand Down Expand Up @@ -582,16 +588,22 @@ if CLIENT then
return
end

uploading = true
net.Start( "wire_expression2_upload" )
net.WriteUInt( targetEntID, 16 )
net.WriteStream( datastr, function()
uploading = net.WriteStream( datastr, function()
uploading = false
uploadNext()
end )
net.SendToServer()
end

-- Upload fail
net.Receive("wire_expression2_upload", function()
WireLib.AddNotify(LocalPlayer(), net.ReadString(), NOTIFY_ERROR, 7, NOTIFYSOUND_DRIP3)
uploading:Remove()
uploading = false
end)

function WireLib.Expression2Upload(targetEntID, code, filepath)
if isentity( targetEntID ) then
targetEntID = targetEntID:EntIndex()
Expand Down
Loading