Merge pull request #169 from thegrb93/remove-nullesc

Remove unneeded null escaping
This commit is contained in:
thegrb93 2018-12-07 00:38:14 -05:00 committed by GitHub
commit e8a103acd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 74 deletions

View File

@ -8,8 +8,6 @@
Version: 1.0
]]
include "nullesc.lua"
AdvDupe2.NetFile = ""
local AutoSave = false
local uploading = false
@ -37,7 +35,8 @@ local function AdvDupe2_ReceiveFile(len, ply, len2)
local status = net.ReadInt(8)
if(status==1)then AdvDupe2.NetFile = "" end
AdvDupe2.NetFile=AdvDupe2.NetFile..net.ReadString()
local datalen = net.ReadUInt(32)
AdvDupe2.NetFile=AdvDupe2.NetFile..net.ReadData(datalen)
if(status==2)then
local path = ""
@ -48,21 +47,25 @@ local function AdvDupe2_ReceiveFile(len, ply, len2)
else
path = CheckFileNameCl(AdvDupe2.SavePath)
end
file.Write(path..".txt", AdvDupe2.Null.invesc(AdvDupe2.NetFile))
if(!file.Exists(path..".txt", "DATA"))then
local dupefile = file.Open(path..".txt", "wb", "DATA")
if(!dupefile)then
AdvDupe2.NetFile = ""
AdvDupe2.Notify("File was not saved!",NOTIFY_ERROR,5)
return
end
dupefile:Write(AdvDupe2.NetFile)
dupefile:Close()
local errored = false
if(LocalPlayer():GetInfo("advdupe2_debug_openfile")=="1")then
if(not file.Exists(path..".txt", "DATA"))then AdvDupe2.Notify("File does not exist", NOTIFY_ERROR) return end
local read = file.Read(path..".txt")
if not read then AdvDupe2.Notify("File could not be read", NOTIFY_ERROR) return end
local success,dupe,info,moreinfo = AdvDupe2.Decode(read)
local readFile = file.Open(path..".txt", "rb", "DATA")
if not readFile then AdvDupe2.Notify("File could not be read", NOTIFY_ERROR) return end
local readData = readFile:Read(readFile:Size())
readFile:Close()
local success,dupe,info,moreinfo = AdvDupe2.Decode(readData)
if(success)then
AdvDupe2.Notify("DEBUG CHECK: File successfully opens. No EOF errors.")
else
@ -271,8 +274,9 @@ local function SendFileToServer(eof)
AdvDupe2.ProgressBar.Percent = math.min(math.floor((AdvDupe2.LastPos/AdvDupe2.Length)*100),100)
net.Start("AdvDupe2_ReceiveFile")
net.WriteBit(AdvDupe2.LastPos>=AdvDupe2.Length)
net.WriteString(data)
net.WriteInt(AdvDupe2.LastPos>=AdvDupe2.Length and 1 or 0, 8)
net.WriteUInt(#data, 32)
net.WriteData(data, #data)
net.SendToServer()
end
@ -283,7 +287,7 @@ usermessage.Hook("AdvDupe2_ReceiveNextStep",function(um)
AdvDupe2.PendingDupe = nil
AdvDupe2.LoadGhosts(dupe, info, moreinfo, name )
AdvDupe2.File = AdvDupe2.Null.esc(read)
AdvDupe2.File = read
AdvDupe2.LastPos = 0
AdvDupe2.Length = string.len(AdvDupe2.File)
AdvDupe2.InitProgressBar("Opening:")

View File

@ -1,54 +0,0 @@
--[[
Title: Null Escaper
Desc: Escapes null characters.
Author: AD2 Team
Version: 1.0
]]
local char = string.char
local find = string.find
local gsub = string.gsub
local match = string.match
local Null = {}
local escseq = { --no palindromes
"bbq",
"wtf",
"cat",
"car",
"bro",
"moo",
"sky",
}
function Null.esc(str)
local genseq
for i=1,#escseq do
if not find(str, escseq[i]) then
local genseq = escseq[i]
return genseq.."\n"..gsub(str,"%z",genseq)
end
end
for i=30,200 do
genseq = char(i, i-1, i+1)
if not find(str, genseq) then
return genseq.."\n"..gsub(str,"%z",genseq)
end
genseq = char(i, i, i+1)
if not find(str, genseq) then
return genseq.."\n"..gsub(str,"%z",genseq)
end
end
error("nullesc could not escape the string")
end
function Null.invesc(str)
local delim,huff = match(str,"^(.-)\n(.-)$")
return gsub(huff,delim,"\0")
end
AdvDupe2.Null = Null

View File

@ -8,9 +8,6 @@
Version: 1.0
]]
include "nullesc.lua"
AddCSLuaFile "nullesc.lua"
AdvDupe2.Network = {}
AdvDupe2.Network.Networks = {}
@ -56,7 +53,7 @@ function AdvDupe2.EstablishNetwork(ply, file)
if(not IsValid(ply))then return end
local id = ply:UniqueID()
ply.AdvDupe2.Downloading = true
AdvDupe2.Network.Networks[id] = {Player = ply, File=AdvDupe2.Null.esc(file), Length = #file, LastPos=1}
AdvDupe2.Network.Networks[id] = {Player = ply, File=file, Length = #file, LastPos=1}
local Cur_Time = CurTime()
local time = AdvDupe2.Network.SvStaggerSendRate - Cur_Time
@ -97,7 +94,8 @@ function AdvDupe2_SendFile(ID)
net.Start("AdvDupe2_ReceiveFile")
net.WriteInt(status, 8)
net.WriteString(data)
net.WriteUInt(#data, 32)
net.WriteData(data, #data)
net.Send(Net.Player)
AdvDupe2.UpdateProgressBar(Net.Player, math.floor((Net.LastPos/Net.Length)*100))
@ -286,11 +284,12 @@ local function AdvDupe2_ReceiveFile(len, ply, len2)
return
end
local status = net.ReadBit()
Net.Data = Net.Data..net.ReadString()
local status = net.ReadInt(8)
local datalen = net.ReadUInt(32)
Net.Data = Net.Data..net.ReadData(datalen)
if(status==1)then
AdvDupe2.LoadDupe(ply, AdvDupe2.Decode(AdvDupe2.Null.invesc(Net.Data)))
AdvDupe2.LoadDupe(ply, AdvDupe2.Decode(Net.Data))
AdvDupe2.Network.ClientNetworks[id]=nil
ply.AdvDupe2.Downloading = false
ply.AdvDupe2.Uploading = false