Skip to content

Flash EEPROM/HDD not fully functional for 12 years #2603

@Denneisk

Description

@Denneisk

--[[
if SERVER then
-- Concommand to send a single stream of bytes
local buffer = {}
local bufferBlock = nil
concommand.Add("wire_hdd_uploaddata", function(player, command, args)
local HDDID = tonumber(args[1])
if (not HDDID) or (HDDID < 0) or (HDDID > 3) then return end
HDDID = math.floor(HDDID)
local STEAMID = player:SteamID()
STEAMID = string.gsub(STEAMID, ":", "_")
if (STEAMID == "UNKNOWN") or (STEAMID == "STEAM_0_0_0") then
STEAMID = "SINGLEPLAYER"
end
local address = tonumber(args[2]) or 0
local value = tonumber(args[3]) or 0
local block = math.floor(address / 32)
if block == bufferBlock then
buffer[address % 32] = value
else
if bufferBlock then
file.Write(GetStructName(STEAMID,HDDID,bufferBlock),MakeFloatTable(buffer))
file.Write(GetStructName(STEAMID,HDDID,"drive"),
"FLASH1\n"..GetConVarNumber("wire_hdd_drivecap").."\n"..(address+31))
end
bufferBlock = block
buffer = {}
buffer[address % 32] = value
end
end)
concommand.Add("wire_hdd_uploadend", function(player, command, args)
local HDDID = tonumber(args[1])
if (not HDDID) or (HDDID < 0) or (HDDID > 3) then return end
HDDID = math.floor(HDDID)
local STEAMID = player:SteamID()
STEAMID = string.gsub(STEAMID, ":", "_")
if (STEAMID == "UNKNOWN") or (STEAMID == "STEAM_0_0_0") then
STEAMID = "SINGLEPLAYER"
end
if bufferBlock then
file.Write(GetStructName(STEAMID,HDDID,block),MakeFloatTable(buffer))
file.Write(GetStructName(STEAMID,HDDID,"drive"),
"FLASH1\n"..GetConVarNumber("wire_hdd_drivecap").."\n"..(address))
end
bufferBlock = nil
buffer = {}
end)
-- Download from server to client
local downloadPointer = {}
concommand.Add("wire_hdd_download", function(player, command, args)
local HDDID = tonumber(args[1])
if (not HDDID) or (HDDID < 0) or (HDDID > 3) then return end
HDDID = math.floor(HDDID)
local STEAMID = player:SteamID()
STEAMID = string.gsub(STEAMID, ":", "_")
if (STEAMID == "UNKNOWN") or (STEAMID == "STEAM_0_0_0") then
STEAMID = "SINGLEPLAYER"
end
local formatData = file.Read(GetStructName(STEAMID,HDDID,"drive")) or ""
local driveCap,blockSize = ParseFormatData(formatData)
-- Download code
downloadPointer[player:UserID()] = 0
timer.Remove("flash_download"..player:UserID())
timer.Create("flash_download"..player:UserID(),1/60,0,function()
local umsgrp = RecipientFilter()
umsgrp:AddPlayer(player)
if file.Exists(GetStructName(STEAMID,HDDID,downloadPointer[player:UserID()])) then
local dataTable = GetFloatTable(file.Read(GetStructName(STEAMID,HDDID,downloadPointer[player:UserID()])))
umsg.Start("flash_downloaddata", umsgrp)
umsg.Long(downloadPointer[player:UserID()]*blockSize)
umsg.Long(blockSize)
for i=1,blockSize do
umsg.Float(dataTable[i-1])
end
umsg.End()
end
downloadPointer[player:UserID()] = downloadPointer[player:UserID()] + 1
if downloadPointer[player:UserID()] >= driveCap*1024/blockSize then
timer.Remove("flash_download"..player:UserID())
end
end)
end)
-- Clear hard drive
concommand.Add("wire_hdd_clearhdd", function(player, command, args)
local HDDID = tonumber(args[1])
if (not HDDID) or (HDDID < 0) or (HDDID > 3) then return end
local STEAMID = player:SteamID()
STEAMID = string.gsub(STEAMID or "UNKNOWN", ":", "_")
if (STEAMID == "UNKNOWN") or (STEAMID == "STEAM_0_0_0") then
STEAMID = "SINGLEPLAYER"
end
local formatData = file.Read(GetStructName(STEAMID,HDDID,"drive")) or ""
local driveCap,blockSize = ParseFormatData(formatData)
-- FIXME: have to limit this to 2 kb until I add a timer
driveCap = math.min(driveCap,2)
file.Delete(GetStructName(STEAMID,HDDID,"drive"))
for block = 0,math.floor(driveCap*1024/blockSize) do
if file.Exists(GetStructName(STEAMID,HDDID,block)) then
file.Delete(GetStructName(STEAMID,HDDID,block))
end
end
end)
else
function CPULib.OnDownloadData(um)
local HDDID = GetConVarNumber("wire_hdd_client_driveid")
local offset,size = um:ReadLong(),um:ReadLong()
local dataTable = {}
for address=1,size do
dataTable[address] = um:ReadFloat()
end
file.Write(GetStructName("SINGLEPLAYER",HDDID,math.floor(offset/size)),MakeFloatTable(dataTable))
file.Write(GetStructName("SINGLEPLAYER",HDDID,"drive"),
"FLASH1\n"..GetConVarNumber("wire_hdd_drivecap").."\n"..(offset+size-1))
end
usermessage.Hook("flash_downloaddata", CPULib.OnDownloadData)
concommand.Add("wire_hdd_clearhdd_client", function(player, command, args)
local HDDID = GetConVarNumber("wire_hdd_client_driveid")
local formatData = file.Read(GetStructName("SINGLEPLAYER",HDDID,"drive")) or ""
local driveCap,blockSize = ParseFormatData(formatData)
-- FIXME: have to limit this to 2 kb until I add a timer
driveCap = math.min(driveCap,2)
file.Delete(GetStructName("SINGLEPLAYER",HDDID,"drive"))
for block = 0,math.floor(driveCap*1024/blockSize) do
if file.Exists(GetStructName("SINGLEPLAYER",HDDID,block)) then
file.Delete(GetStructName("SINGLEPLAYER",HDDID,block))
end
end
end)
-- Upload from client to server
local uploadPointer = 0
concommand.Add("wire_hdd_upload", function(player, command, args)
local HDDID = GetConVarNumber("wire_hdd_client_driveid")
local TGTHDDID = GetConVarNumber("wire_hdd_driveid")
local formatData = file.Read(GetStructName("SINGLEPLAYER",HDDID,"drive")) or ""
local driveCap,blockSize = ParseFormatData(formatData)
-- Upload code
uploadPointer = 0
timer.Remove("flash_upload")
timer.Create("flash_upload",1/10,0,function()
if file.Exists(GetStructName("SINGLEPLAYER",HDDID,uploadPointer)) then
local dataTable = GetFloatTable(file.Read(GetStructName("SINGLEPLAYER",HDDID,uploadPointer)))
for i=0,blockSize-1 do
RunConsoleCommand("wire_hdd_uploaddata",TGTHDDID,i+uploadPointer*blockSize,dataTable[i])
end
end
uploadPointer = uploadPointer + 1
if uploadPointer >= driveCap*1024/blockSize then
RunConsoleCommand("wire_hdd_uploadend",TGTHDDID)
end
end)
end)
end
]]--

According to the last relevant update, this was supposed to be finalized in "the next update". Would appreciate some eyes on this as I like its functionality.

Would also like to consider, while we're here, having an ability for the server to request downloading a specific drive from the client. Or maybe don't request, just do. Not like anyone stores anything valuable on these anyway, probably.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis issue is a general bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions