Skip to content
Merged
Show file tree
Hide file tree
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
34 changes: 20 additions & 14 deletions lua/pac3/editor/client/wear.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,10 @@

do -- to server
local function net_write_table(tbl)

local buffer = pac.StringStream()
buffer:writeTable(tbl)

local data = buffer:getString()
local ok, err = pcall(net.WriteStream, data)

if not ok then
return ok, err
end

net.WriteStream(data)
return #data
end

Expand Down Expand Up @@ -104,10 +97,11 @@

net.Start("pac_submit")

local bytes, err = net_write_table(data)
local ok, bytes = pcall(net_write_table, data)

if not bytes then
pace.Notify(false, "unable to transfer data to server: " .. tostring(err or "too big"), pace.pac_show_uniqueid:GetBool() and string.format("%s (%s)", part:GetName(), part:GetPrintUniqueID()) or part:GetName())
if not ok then
net.Abort()
pace.Notify(false, "unable to transfer data to server: " .. tostring(bytes or "too big"), pace.pac_show_uniqueid:GetBool() and string.format("%s (%s)", part:GetName(), part:GetPrintUniqueID()) or part:GetName())
return false
end

Expand All @@ -127,8 +121,9 @@
end

net.Start("pac_submit")
local ret, err = net_write_table(data)
if ret == nil then
local ok, err = pcall(net_write_table, data)
if not ok then
net.Abort()
pace.Notify(false, "unable to transfer data to server: " .. tostring(err or "too big"), name)
return false
end
Expand Down Expand Up @@ -236,14 +231,25 @@
net.Receive("pac_submit", function()
if not pac.IsEnabled() then return end

local owner = net.ReadEntity()
if owner:IsValid() and owner:IsPlayer() then
pac.Message("Receiving outfit from ", owner)
else
return
end

net.ReadStream(ply, function(data)
if not data then
pac.Message("message from server timed out")
return
end

local buffer = pac.StringStream(data)
local data = buffer:readTable()
local ok, data = pcall(buffer.readTable, buffer)
if not ok then
pac.Message("received invalid message from server!?")
return
end

if type(data.owner) ~= "Player" or not data.owner:IsValid() then
pac.Message("received message from server but owner is not valid!? typeof " .. type(data.owner) .. " || ", data.owner)
Expand Down Expand Up @@ -296,7 +302,7 @@

else
--prompt
local backup_files, directories = file.Find( "pac3/__backup/*.txt", "DATA", "datedesc")

Check warning on line 305 in lua/pac3/editor/client/wear.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: directories
local latest_outfit = cookie.GetString( "pac_last_loaded_outfit", "" )
if not backup_files then
local pnl = Derma_Query("Do you want to load your autoload outfit?", "PAC3 autoload (pac_prompt_for_autoload)",
Expand Down
54 changes: 27 additions & 27 deletions lua/pac3/editor/server/wear.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
local ProtectedCall = ProtectedCall

pace.StreamQueue = pace.StreamQueue or {}
pace.MaxStreamQueue = 32 -- Max queued outfits per player

timer.Create("pac_check_stream_queue", 0.1, 0, function()
local item = table.remove(pace.StreamQueue)
Expand Down Expand Up @@ -46,17 +47,10 @@
end

local function net_write_table(tbl)

local buffer = pac.StringStream()
buffer:writeTable(tbl)

local data = buffer:getString()
local ok, err = pcall(net.WriteStream, data)

if not ok then
return ok, err
end

net.WriteStream(data)
return #data
end

Expand Down Expand Up @@ -185,10 +179,10 @@

for key, v in pairs(pace.dupe_ents) do
if v.owner:IsValid() and v.owner == owner then
if v.ent:IsValid() and v.ent.pac_parts then
v.ent.pac_parts = nil
duplicator.ClearEntityModifier(v.ent, "pac_config")
end

Check warning on line 185 in lua/pac3/editor/server/wear.lua

View workflow job for this annotation

GitHub Actions / lint

"Double if-statement"

Double if statement. Please combine the condition of this if statement with that of the outer if statement using `and`.
end

pace.dupe_ents[key] = nil
Expand Down Expand Up @@ -272,17 +266,19 @@
local ret = pac.CallHook("SendData", players, data)
if ret == nil then
net.Start("pac_submit")
local bytes, err = net_write_table(data)
net.WriteEntity(owner)
local ok, err = pcall(net_write_table, data)

if not bytes then
if ok then
net.Send(players)
else
net.Abort()
local errStr = tostring(err)
ErrorNoHalt("[PAC3] Outfit broadcast failed for " .. tostring(owner) .. ": " .. errStr .. "\n")

if owner and owner:IsValid() then
owner:ChatPrint("[PAC3] ERROR: Could not broadcast your outfit: " .. errStr)
end
else
net.Send(players)
end
end

Expand All @@ -299,18 +295,22 @@

-- Inserts the given part into the StreamQueue
function pace.SubmitPart(data, filter, callback)
if istable(data.part) then
pac.dprint("queuing part %q from %s", data.part.self.Name, tostring(data.owner))
table.insert(pace.StreamQueue, {
data = data,
filter = filter,
callback = callback
})

return "queue"
if not ((istable(data.part) or isstring(data.part)) and IsValid(data.owner)) then return end
local owner = data.owner
local count = 0
for _, v in ipairs(pace.StreamQueue) do
if v.data.owner == owner then
if count == pace.MaxStreamQueue then return end
count = count + 1
end
end

return pace.SubmitPartNow(data, filter)
if data.part.self then pac.dprint("queuing part %q from %s", data.part.self.Name, tostring(data.owner)) end
table.insert(pace.StreamQueue, {
data = data,
filter = filter,
callback = callback
})
end

-- Inserts the given part into the StreamQueue, and notifies when it completes
Expand Down Expand Up @@ -402,15 +402,15 @@
return
end
local buffer = pac.StringStream(data)
pace.HandleReceivedData(ply, buffer:readTable())
local ok,tbl = pcall(buffer.readTable, buffer)

Check warning on line 405 in lua/pac3/editor/server/wear.lua

View workflow job for this annotation

GitHub Actions / lint

"Space after comma"

Style: Please add a space after the comma
if ok then
pace.HandleReceivedData(ply, tbl)
end
end)
end)

function pace.ClearOutfit(ply)
local uid = pac.Hash(ply)

pace.SubmitPart({part = "__ALL__", uid = pac.Hash(ply), owner = ply})
pace.CallHook("RemoveOutfit", ply)
pace.RemovePart({part = "__ALL__", uid = pac.Hash(ply), owner = ply})
end

function pace.RequestOutfits(ply)
Expand Down
Loading