I'm using render.Capture on a script which seems to work fine locally but I get weird results when I use it on a server, example : [url]http://image.noelshack.com/fichiers/2013/26/1372082260-3633007-1372080971.jpeg[/url]
Any ideas?
Thanks
[editline]24th June 2013[/editline]
oh and if you don't get it I don't use the function serverside, I use it clientside but get weird pictures when I join a server
Post the script.
There it is, I'm basically sending the screenshot from the client to the server.
[lua]
if SERVER then
util.AddNetworkString("Ask_Screenshot")
util.AddNetworkString("Send_Screenshot")
AddCSLuaFile()
local id = 0
local receiving = {}
local function AskScreenshot(ply)
local found = false
for k,v in pairs(receiving) do
if v.ply == ply then
found = true
end
end
if not found and IsValid(ply) and not ply:IsBot() then
id = id + 1
local steamid = ply:SteamID()
steamid = string.Right(steamid, #steamid-10)
receiving[id] = {
str = {},
steamid = steamid,
ply = ply
}
net.Start("Ask_Screenshot")
net.WriteUInt(id, 32)
net.Send(ply)
end
end
local function SaveScreenshot(id)
local infos = receiving[id]
if infos.str then
local str = ""
for k,v in ipairs(infos.str) do
str = str..v
end
print(#str)
file.Write(infos.steamid.."_"..tostring(os.time())..".txt", str)
receiving[id] = nil
end
end
concommand.Add("test_anticheat", function(ply)
AskScreenshot(ply)
end)
net.Receive("Send_Screenshot", function(_, ply)
local id = net.ReadUInt(32)
local pos = net.ReadUInt(32)
local size = net.ReadUInt(32)
local str = net.ReadData(size)
local finished = net.ReadUInt(1)
if id and pos and str and finished then
local tbl = receiving[id]
if tbl then
tbl.str[pos] = str
if finished == 1 then
SaveScreenshot(id)
end
end
end
end)
else
net.Receive("Ask_Screenshot", function()
local id = net.ReadUInt(32)
local picture = render.Capture({
format = "jpeg",
h = ScrH(),
w = ScrW(),
quality = 30,
x = 0,
y = 0
})
if picture then
file.Write("test_screen.txt", picture)
local split = {}
local temp = ""
for i=0,picture:len() do
temp = temp..picture:sub(i, i)
if temp:len() == 62000 then
table.insert(split, temp)
temp = ""
end
end
table.insert(split, temp)
for k,v in pairs(split) do
net.Start("Send_Screenshot")
net.WriteUInt(id, 32)
net.WriteUInt(k, 32)
net.WriteUInt(#v, 32)
net.WriteData(v, #v)
net.WriteUInt(size == i and 1 or 0, 1)
net.SendToServer()
end
end
end
end)
end
[/lua]
[editline]24th June 2013[/editline]
I now think it's a bug.. just try this :
file.Write('test.txt', render.Capture({}))
Then rename the file to jpeg and see the result when you're on a server
You shouldn't really use the net library for this to be honest, send the image to a webserver or something, otherwise you'll just cause horrendous network lag and server load.
[code]file.Write("test_screen.txt", picture)[/code]
needs to be a binary write
[code]
F = file.Open( "screenshot.txt", wb, "DATA" )
F:Write(picture)
F:Close()
[/code]
Not sure if that's what you were looking for btw.
EDIT: appears yup :P
Thanks, but I'll try Wizard's method first, I think it's indeed better.
[QUOTE=Wizard of Ass;41169684]You shouldn't really use the net library for this to be honest, send the image to a webserver or something, otherwise you'll just cause horrendous network lag and server load.[/QUOTE]
But wouldn't that be easy to exploit? Since you would have to send their SteamID which you wouldn't be able to verify was really sent by them.
[QUOTE=isnipeu;41170425]But wouldn't that be easy to exploit? Since you would have to send their SteamID which you wouldn't be able to verify was really sent by them.[/QUOTE]
Pretty sure those frenchy kids I have on my server will not exploit anything
[editline]24th June 2013[/editline]
I tried sending it using http.Post and some php code and it worked, thanks a lot!
[QUOTE=Nalo;41170470]Pretty sure those frenchy kids I have on my server will not exploit anything[/QUOTE]
You really shouldn't take a risk like that, if someone dislikes someone else on the server they could fake it and frame them (resulting in them getting banned).
[QUOTE=isnipeu;41170503]You really shouldn't take a risk like that, if someone dislikes someone else on the server they could fake it and frame them (resulting in them getting banned).[/QUOTE]
True, but then I don't see how I can prevent this D:
[QUOTE=Nalo;41170579]True, but then I don't see how I can prevent this D:[/QUOTE]
You could easily have a certain argument on the http.Post that acts as a verification and in worst case have something like a generated key to be the extra argument and validate that key on the webserver.
And that key would be sent to their client before sending the screenshot to the webserver ofcourse.
[QUOTE=goldenlukis;41170637]You could easily have a certain argument on the http.Post that acts as a verification and in worst case have something like a generated key to be the extra argument and validate that key on the webserver.
And that key would be sent to their client before sending the screenshot to the webserver ofcourse.[/QUOTE]
Yeah, good idea.
Thanks for the help everyone, I'm closing this.
Sorry, you need to Log In to post a reply to this thread.