As you may have guessed, this extension is for connecting to a Uniform Resource Locator or URL for short. You can get HTML from an internet page (pretty useless) or connect to a .php script on the web, in which case you would be able to read and submit data (pretty useful).
The extension is asynchronous, meaning you will have to check back after you submitted url_fetch query to see if there is a result ready. There are few limitations because originally it started as quick and dirty proof of concept, but later I decided to wrap it up in more usable package but it is still simplified.
- One request per turn. This means that if extension is still in the process of fetching, you will not be able to submit another request until first one is complete. This brings me to second limitation
- Server timeout is 10 seconds. If the queried server does not respond in 10 seconds it will be considered as result error. This also means that you may have to wait up to 10 seconds to submit another request because of this
- This dll will truncate result to the set variable limit (currently ~10kB). This means you will not be able to get large pages, only a portion of the page. I also have no plans for supporting this
- There is error reporting, but it is pretty limited
This extension uses cURL library. To run it you will need the following files (included in the download): curllib.dll, libeay32.dll, libsasl.dll, openldap.dll and of course url_fetch.dll. The extension works as following:
- A client submits URL encoded URL query (means spaces become %20 etc etc) to the extension
- At this point the extension will immediately return with either OK or BUSY. BUSY means it is still dealing with previous request. It is up to you how you handle this
- Upon receiving OK the client should send OK back to the extension to find out the status of submitted query
- The extension immediately returns with either WAIT, ERROR or the actual result. WAIT means you have to check back again (send OK) as result is not ready
- In case of ERROR, to find out the kind of last error, the client should send ERROR to the extension
- The extension immediately returns with one of the following: N/A – you tried to retrieve result without making any query first; INIT – cURL failed to initialise for some reason; RESULT – couldn’t get the result (server timeout, wrong URL, etc, etc)
It might sound a bit complicated so I made a sample function to handle the extension. You must use spawn or execVM (if you move it to file) since it uses waitUntil. Do not call this function or chances are you will get an error.
I’ve also made a sample hello.php script to demonstrate the concept. So this is how you fetch URL:
This will make the following entry in .rpt file: “>>> [url_fetch] >>> RESULT: Hello KK!”. You can change diag_log to hint in the function code to see it on the screen, but avoid dumping big chunks of output in a hint, it lags the game for some reason. Oh yeah, the download link is right below and for the installation, put all files from the zip into Arma 3 root directory.
NOTE: If you are getting missing .dlls messages, you might need to download and install Visual C++ Redistributable for Visual Studio 2012
url_fetch v2.0 is now available!