Jump to content

[TUT] Protect Client Script at the Highest Level


Recommended Posts

Protect your scripts at the highest level

Now, if you're scripting yourself, you know the importance of having your scripts safe. We don't want anyone to steal our code, right? And, even though users can only steal client-sided code (since it's downloaded to their computer), it can give you a headache when you see another server using similar scripts.

Compiling only gets you so far, it's fairly easy to decompile any script and extract some chunks of code from it. While not perfect, it makes it easier for that person to "make" the script themselves; sometimes you can decompile the whole code, and it will work flawlessly.

With the release of MTA 1.1, this method became possible (cheers to MTA developers for that ). There is a simple way of "preventing the scripts from downloading to the player's PC". Okay, don't hold me for that literaly. The scripts still get downloaded, but the user can't find them in his downloaded resources folder. How? Well, here's the "magic" behind it.

Whenever the player joins your server, he downloads any necessary files, images, sounds, and also client-sided scripts (if he joined for the first time). Afterwards, the client-sided scripts are loaded, and from that moment on, they are no longer required on the player's hard drive. Why do they stay there? I don't know, seems like we're just offering others to steal them.

How do we prevent that? Using simple LUA code, we delete the downloaded scripts after they are loaded into memory. It is as simple as it sounds. Anyone looking in the folder of your resource won't find any scripts.

This is the part of the this topic.Yes It's good way, but no so good.

First, you must delete the client files from meta.xml (If we do that client side scripts won't downloand to the other PCs).Now open a server-side lua file: named = "serverProtector.lua"

And put this one:

fileList = { 
"mygui.lua", 
"mydx.lua", -- your client side files (e.g: render.lua)  
"hello.lua", -- you can increase the files. 
"classes/animation_class.lua" -- if the file in other folder, you must write the folder names. (e.g classes/gui/anim/anim_class.lua) 
} 
  
addEvent("onPlayerResourceStart",true) 
addEventHandler("onPlayerResourceStart",getRootElement(),function() 
    readToEnd = function(file_name) 
        local file = fileOpen(file_name) 
         
        if (file) then 
            local buffer 
            local toend = "" 
            while not fileIsEOF(file) do 
                buffer = fileRead(file,500) 
                toend = toend .. buffer 
            end 
            fileClose(file) 
            return toend 
        else 
            return false 
        end 
    end 
    for i,v in ipairs(fileList) do 
        fileList[i] = readToEnd(v) 
    end 
    triggerClientEvent(source,"includeFiles",getRootElement(),fileList) 
end) 

Important: You must add your scripts list by list.So if you use some function from other scripts, other scripts must be before.

Now we completed at the server-side.Now open a new client-side script(named: "clientProtector.lua")

And put this one:

  
function includeFiles(fileList) 
    for _,v in ipairs(fileList) do 
        func = assert(loadstring(v)) 
        func() 
    end 
end 
addEvent("includeFiles",true) 
addEventHandler("includeFiles",getRootElement(),includeFiles) 
  
addEventHandler("onClientResourceStart",getRootElement(),function(res) 
    if (res == getThisResource()) then 
        triggerServerEvent("onPlayerResourceStart",getLocalPlayer()) 
    end 
end) 

Now open a new client side script(named:protectorDelete.lua).And put this one:

fileDelete("clientProtector.lua") 

And now It's finish.Meta.xml must be:

  

this list..

And you must not to add the client files to the meta.xml, you must put the script folder only...

It's finish you protected your files around %99..

Notice: Someone correct the English ?

Link to comment
  • 3 weeks later...
The reason it is saved client side is to decrease download the next-time you join that server. (You won't have to download the login panel again, or whatever. A one time download)

how much often size of the login panel?

10 kb?

20 kb?

30 kb?

50 kb?

this can be downloaded in less than 1 sec :roll:

i thinks the only things that should be saved is images and sounds and txd - dff or whatever the files that have large size.

Link to comment

Sure, but id still recommend it, they steal, mod it to be better then yours. Then you have an empty server, and children claiming the A+ code is theirs. Can't beat the hell out of them for it. Well you can, but it won't stop the influence.

P.S. Supernatural is a good series. I own them all.

Link to comment
  • 3 weeks later...
The reason it is saved client side is to decrease download the next-time you join that server. (You won't have to download the login panel again, or whatever. A one time download)

That's true, plus, if you want to open something and the client-side is deleted, then nothing is showing up :/

Link to comment
  • 3 weeks later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...