File.Exists serverside/clientside

Hello.

I’m a begineer in LUA and i’m making an missions addon with an other guy.
So we have an PNJ who give missions and so we have some data to save.

Currently we have done the save of data clientside only but i’m trying to convert it serverside.

So for file.Write i converted this :


file.Write("mm/1.txt", "1")

Into this (in my clientside file) :


net.Start("writemissionone")
net.SendToServer()

And in my serverside file :


util.AddNetworkString( "writemissionone" )
net.Receive( "writemissionone", function( len, ply )
file.CreateDir( "mission/" .. ply:SteamID64() )
file.Write( "mission/" .. ply:SteamID64() .. "1.txt","1" )
end )

It work perfect but the problem is not here. In my clientside file i have to check if file exist to continue the missions.
So if i save clientside i just have to do this :


if(file.Exists( "mm/1.txt" ,"DATA")) then 
chat.AddText(Color(51, 102, 255, 51), "Abdel Kalif: ",Color(255,255,255), "Do what i asked you." )

But i can’t found the way to convert the if(file.Exists) in a net.Start who will return me “itexists” or “itdoenstexist” in my clientside file.

Sorry if it isn’t really clear,english isn’t my primary language.

Thanks.

From what I can tell you are sending files to the server as a way of saving data?

It’s really not a good idea to trust the client when it comes to stuff like writing files on the server. EVER.
In general you should do the file operations and whatnot SERVERSIDE and network things such as chat.AddText TO THE CLIENT rather than this way around.

Doing it like this would also fix your issue since you would be telling the client that it doesn’t exist rather than asking the server ‘does it exist?’ then getting a response. (I assume this is what you meant with the file.Exists stuff)

Thx for reply.

I’m not downloading file from client.
When i started coding this addons,i saved data clientside,now i’m trying to convert my code to save it serverside.

But i can’t convert this code from clientside to serverside :


if(file.Exists( "mm/1.txt" ,"DATA")) then 

For file.Write i’ve done this way :


net.Start("writemissionone")
net.SendToServer()

Clientside code.


util.AddNetworkString( "writemissionone" )
net.Receive( "writemissionone", function( len, ply )
file.CreateDir( "mission/" .. ply:SteamID64() )
file.Write( "mission/" .. ply:SteamID64() .. "1.txt","1" )
end ) 

Serverside code

The ideal would be the net.Start return something if the check is good.


if(file.Exists( "mm/1.txt" ,"DATA")) then

Become ->


if(file.Exists( "mission/" .. ply:SteamID64() .. "1.txt" ,"DATA")) then 

bump

Whats your steam i have an idea but would rather use that as facepunch is being buggy for me :confused:

EDIT

Okay so my idea

make a single file for each user only one for all the missions and have it send the user there progress upon join, mission complete and update sooo for an example

Player Joins
net -> Your on mission one

Player Gets to part two on mission
net to sv -> update said file for said player

Player Completes the mission
net -> Player has advanced

Player gets a new mission which was unlocked by completing previous mission
net -> Updates the file

Here my steam profile.

Yeah but the problem is still the same with your method,i don’t know how to convert the if.

Thanks!

Why not add the steamid yourself and see what happens?



file.CreateDir( "mission/76561197960279927" )
file.Write( "mission/765611979602799271.txt","1" )


Notice how you aren’t using the created dir since you forgot a / to write into the directory you just created.
That folder will, naturally, be empty.

Yeah,i forgot a /,i fixed this a little bit moment after this post.

The folder is fine,the file is fine too.

My problem is for the if.


if(file.Exists( "mission/" .. ply:SteamID64() .. "1.txt" ,"DATA")) then

I want to convert this clientside to serverside with a net.Start.

Honestly, pdata and nwvars seem smarter than trying to deal with files.

bump

bump

You made 2 bumps in less than 6 hours. Jesus Christs give people a chance