.:HyPeX:. Posted February 20, 2015 Share Posted February 20, 2015 (edited) Hello everyone i've found one issue with my custom downloading images from the forum (Avatars) system. It fucks up alone when there is more than one player online and the images are saved with 5bytes. if i'm alone on the server it downloads my avatar perfectly. Server: local Database = dbConnect("mysql",***) gTable = {} addEventHandler('onPlayerLogin',root,function() local acc = getPlayerAccount(source) local acc = getAccountName(acc) local query = dbQuery(function(qh,player) local result = dbPoll(qh,0) local gvalue = 0 setElementData(player, "member_id", result[1]["member_id"]) gvalue = result[1]["member_id"] local query = dbQuery(function(qh,player) local result = dbPoll(qh,0) id, photo = "","" id = result[1]["pp_member_id"] photo = result[1]["pp_main_photo"] if photo ~= "" then setElementData(player, "pp_main_photo", result[1]["pp_main_photo"]) else setElementData(player, "pp_main_photo", "profile/photo-0.jpg") end fetchImage(id, photo) end,{player},Database, "SELECT pp_member_id,pp_main_photo FROM profile_portal WHERE pp_member_id = '?'", gvalue) end,{source},Database, "SELECT member_id FROM members WHERE name='"..acc.."'") end) function fetchImage(id,photo) fetchRemote ( "http://emp-clan.eu/uploads/"..photo, returnImage, "", false, id,photo ) end function returnImage(image, error, id, photo) if fileExists("saved/"..photo) then local file = fileOpen("saved/"..photo) local size = fileGetSize(file) local result = fileRead(file,size) fileClose(file) if result ~= image then fileDelete("saved/"..photo) local file = fileCreate("saved/"..photo) fileWrite(file, image) fileClose(file) end else local file = fileCreate("saved/"..photo) fileWrite(file, image) fileClose(file) end end addEvent("RequestAvatars",true) addEventHandler("RequestAvatars", root, function(player,id,photo,size) if size then local file = fileOpen("saved/"..photo) if size ~= fileGetSize(file) then local info = fileRead(file,fileGetSize(file)) fileClose(file) triggerClientEvent(client,"SaveAvatars",resourceRoot,id,photo,info) end fileClose(file) else if fileExists("saved/"..photo) then local file = fileOpen("saved/"..photo) local info = fileRead(file,fileGetSize(file)) fileClose(file) triggerClientEvent(client,"SaveAvatars",resourceRoot,id,photo,info) end fileClose(file) end end) Client addEventHandler('onClientResourceStart',root,function() for i,v in ipairs(getElementsByType("player")) do local id = getElementData(v, "member_id") local photo = getElementData(v, "pp_main_photo") if photo then if fileExists("saved/"..photo) then local file = fileOpen("saved/"..photo) local size = fileGetSize(file) fileClose(file) outputConsole(size) triggerServerEvent("RequestAvatars", resourceRoot, localPlayer,id, photo, size) else triggerServerEvent("RequestAvatars", resourceRoot, localPlayer,id, photo) end end end end) addEvent('SaveAvatars',true) addEventHandler('SaveAvatars', root, function(id,photo,info) if info then if fileExists("saved/"..photo) then fileDelete("saved/"..photo) local file = fileCreate("saved/"..photo) fileWrite(file, info) fileClose(file) else local file = fileCreate("saved/"..photo) fileWrite(file, info) fileClose(file) end setElementData(localPlayer, photo, true) end end) addEventHandler('onClientElementDataChange',root,function(name,old) if name == "pp_main_photo" then local id = getElementData(source, "member_id") local photo = getElementData(source, "pp_main_photo") if photo then if fileExists("saved/"..photo) then local file = fileOpen("saved/"..photo) local size = fileGetSize(file) fileClose(file) outputConsole(size) triggerServerEvent("RequestAvatars", resourceRoot, localPlayer,id, photo, size) else triggerServerEvent("RequestAvatars", resourceRoot, localPlayer,id, photo) end end end end) Edited February 23, 2015 by Guest Link to comment
.:HyPeX:. Posted February 21, 2015 Author Share Posted February 21, 2015 Bump, anyone? i cannot find any reason for this not to work... Link to comment
.:HyPeX:. Posted February 23, 2015 Author Share Posted February 23, 2015 No one? 100 views already... I finally tracked down the issue to server side - The files are cut on 5byte. I tested checking if the files were cut by a request client-side - without client side, on player login a 5byte file is created. I checked, it was a txt with "ERROR". (Badly i didnt checked for error argument) Error id is 215 - What is 215? Its not listed in the wiki. EDIT: Error 215 was a wrong argument passed - i now get error 404 - even thought the file exists! [url=http://emp-clan.eu/uploads/profile/photo-215.png]http://emp-clan.eu/uploads/profile/photo-215.png[/url] ERROR 404 215 ERROR OBTAINING IMAGE. ERROR ID: 215 function fetchImage(id,photo) outputChatBox("http://emp-clan.eu/uploads/"..photo) fetchRemote ( "http://emp-clan.eu/uploads/"..photo, returnImage, "", false, id,photo ) end function returnImage(image, error, id, photo) outputChatBox(image.." "..error.." "..id) if errro ~= 0 then outputChatBox("ERROR OBTAINING IMAGE. ERROR ID: ".. id) else if fileExists("saved/"..photo) then local file = fileOpen("saved/"..photo) local size = fileGetSize(file) local result = fileRead(file,size) fileClose(file) if result ~= image then fileDelete("saved/"..photo) local file = fileCreate("saved/"..photo) fileWrite(file, image) fileClose(file) end else local file = fileCreate("saved/"..photo) fileWrite(file, image) fileClose(file) end end end Link to comment
Gallardo9944 Posted February 23, 2015 Share Posted February 23, 2015 Clientside fetchremote can't access remote hosts except the one it's connected to. Are you sure your server is located on emp-clan.eu too? Link to comment
.:HyPeX:. Posted February 23, 2015 Author Share Posted February 23, 2015 Clientside fetchremote can't access remote hosts except the one it's connected to. Are you sure your server is located on emp-clan.eu too? Its server side fetchremote, and actually it is not in the same server... Link to comment
.:HyPeX:. Posted February 23, 2015 Author Share Posted February 23, 2015 Clientside fetchremote can't access remote hosts except the one it's connected to. Are you sure your server is located on emp-clan.eu too? Solved it, it was some bad misconfig rule for outgoing connections from the VPS. Link to comment
AleksCore Posted February 12, 2016 Share Posted February 12, 2016 How did you solved it? Link to comment
.:HyPeX:. Posted February 18, 2016 Author Share Posted February 18, 2016 How did you solved it? I dont remember (It was over a year ago rofl), but on the new VPS i got this on i didnt have to touch anything and it worked fine. Probably that old one wasnt well set up? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now