"CStream" (for the lack of a better name, suggestions are welcome) is a resource to load client-side scripts instead of storing it on the client's harddisk. Because the scripts aren't on the client's harddisk, they can't simply open their resources folder to see your scripts. This makes your scripts a lot harder to steal.
This is not all, however. CStream also provides scripts with a "streamFile" function, which allows them to only send scripts to the client if they actually need it. For instance, if you have a custom admin resource at the moment with client-side scripts, the scripts are also sent to players who aren't admins. This, of course, is not desirable.
- Place the CStream resource into your server resources folder
- Copy the "cstreaminject.lua" file from CStream into your resource
- Add the script file you just copied to the meta.xml file in your resource, by typing:
<script src="cstreaminject.lua" type="client"/>
- Now, add all of the scripts you want to stream using the following syntax:
- Add CStream as an include in your resource, by adding:
- Start your resource
Streaming using "streamFile"
As mentioned before, streamFile can be used to delay sending of script files. This requires a few steps:
The <cstream/> tag automatically sends the script to the client. To disable this, add sos="false" to the <cstream/> tag.
Note: sos stands for "stream on start" in this case, not "save our souls"
<cstream src="script_file.lua" sos="false"/>
In a server-side script, you can then do:
exports.cstream:streamFile ( string filePath [, player target = getRootElement() ] )
- filePath: Location of the file to be streamed. If you do not add the resource to the filepath, it will automatically be added by CStream
- target: Player who should receive the file. If not specified, it will be sent to all players on the server.
Function "onStart" is triggered for files streamed using streamFile.
- v 0.1
- First released version
- Line numbers and file names in errors or warnings might not be 100% correct. Because of the way CStream works, I kind of had to try and hack around it.
- onClientResourceStart will trigger twice. Once to indicate the resource started, and once for all streamed files to be started. Make sure your resources don't break when onClientResourceStart is triggered twice.
- There's no check if files are sent to the client already. This means that doing streamFile twice will also result in the same script running twice
- CStream needs admin rights, because it "modifies other resources". (aka, loading files from other resources)
- CStream does not work on compiled scripts
Please report any problems on the discussion page, or contact me through IRC. (Host: irc.gtanet.com; Name: Gamesnert; Channels: #mta, #mta.dutch, #mta.scripting)