Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Queues to E2 File Extension #2763

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 9 additions & 9 deletions lua/entities/gmod_wire_expression2/core/cl_files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
By: Dan (McLovin)
]]--

local cv_max_transfer_size = CreateConVar( "wire_expression2_file_max_size", "300", { FCVAR_REPLICATED, FCVAR_ARCHIVE } ) //in kib
local cv_max_transfer_size = CreateConVar("wire_expression2_file_max_size", "300", { FCVAR_REPLICATED, FCVAR_ARCHIVE }, "Maximum file size in kibibytes.")

local upload_buffer = {}
local download_buffer = {}

local upload_chunk_size = 20000 //Our overhead is pretty small so lets send it in moderate sized pieces, no need to max out the buffer
local upload_chunk_size = 20000 --Our overhead is pretty small so lets send it in moderate sized pieces, no need to max out the buffer

local allowed_directories = { //prefix with >(allowed directory)/file.txt for files outside of e2files/ directory
local allowed_directories = { --prefix with >(allowed directory)/file.txt for files outside of e2files/ directory
["e2files"] = "e2files",
["e2shared"] = "expression2/e2shared",
["cpushared"] = "cpuchip/e2shared",
Expand Down Expand Up @@ -47,18 +47,18 @@ local function process_filepath( filepath )
return string.GetPathFromFilename( fullpath ) or "e2files/", string.GetFileFromFilename( fullpath ) or "noname.txt"
end

/* --- File Read --- */
--- File Read ---

local function upload_callback()
if not upload_buffer or not upload_buffer.data then return end

local chunk_size = math.Clamp( string.len( upload_buffer.data ), 0, upload_chunk_size )
local chunk_size = math.Clamp(#upload_buffer.data, 0, upload_chunk_size)

net.Start("wire_expression2_file_chunk")
net.WriteUInt(chunk_size, 32)
net.WriteData(upload_buffer.data, chunk_size)
net.SendToServer()
upload_buffer.data = string.sub( upload_buffer.data, chunk_size + 1, string.len( upload_buffer.data ) )
upload_buffer.data = string.sub(upload_buffer.data, chunk_size + 1)

if upload_buffer.chunk >= upload_buffer.chunks then
net.Start("wire_expression2_file_finish") net.SendToServer()
Expand Down Expand Up @@ -96,12 +96,12 @@ net.Receive("wire_expression2_request_file", function(netlen)
timer.Create( "wire_expression2_file_upload", 1/60, upload_buffer.chunks, upload_callback )
else
net.Start("wire_expression2_file_begin")
net.WriteUInt(0, 32) // 404 file not found, send len of 0
net.WriteUInt(0, 32) -- 404 file not found, send len of 0
net.SendToServer()
end
end )

/* --- File Write --- */
--- File Write ---
net.Receive("wire_expression2_file_download_begin", function( netlen )
local fpath,fname = process_filepath( net.ReadString() )
if not E2Lib.isValidFileWritePath(fname) then return end
Expand All @@ -128,7 +128,7 @@ net.Receive("wire_expresison2_file_download_finish", function( netlen )
end
end )

/* --- File List --- */
--- File List ---

net.Receive( "wire_expression2_request_list", function( netlen )
local dir = process_filepath(net.ReadString())
Expand Down
Loading
Loading