Resource Web Access: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 23: Line 23:


===Parsed files===
===Parsed files===
If a file is not specified in the meta file as "raw", then it is passed through a pre-processor before it is returned to the client. This pre-processor works much like PHP or ASP, but uses LUA. You can embed standard MTA scripts within HTML pages, controlling the output. Almost all standard MTA functions work, plus all [[Template:HTTP functions]] (such as [[httpWrite]], a function that outputs text to the buffer).
If a file is not specified in the meta file as "raw", then it is passed through a pre-processor before it is returned to the client. This pre-processor works much like PHP or ASP, but uses LUA. You can embed standard MTA scripts within HTML pages, controlling the output. Almost all standard MTA functions work, plus a number of special [[Template:HTTP functions|HTTP Functions]], such as [[httpWrite]], a function that outputs text to the buffer.


For example:
For example:
Line 29: Line 29:
<html>
<html>
     <body>
     <body>
         This resource is called <* httpWrite( getResourceName(getThisResource()) )>
         This resource is called <* httpWrite( getResourceName(getThisResource()) ) *>
     </body>
     </body>
<html>
<html>
</syntaxhighlight>
</syntaxhighlight>


Aside from HTTP functions, embedded Lua has access to the following environment variables:
There is a shorthand (in common with PHP and ASP) for this code, meaning that you can also write the above code as:
<syntaxhighlight lang="lua">
 
table requestHeaders
<syntaxhighlight lang="lua">[html]
table form
<html>
table cookies
    <body>
string hostname
        This resource is called <* = getResourceName(getThisResource()) *>
string url
    </body>
table querystring
<html>
</syntaxhighlight>
</syntaxhighlight>
Aside from HTTP functions, embedded Lua has access to the following environment variables that contain information about how the page was requested:
* table '''requestHeaders''': This is a table containing all the headers that were requested with the page. You can set returned headers using [[httpSetResponseHeader]].
* table '''form''': This is a table containing all the form data submitted to the page using HTTP POST.
* table '''cookies''': This is a table of all the cookies. You can modify cookies using [[httpSetResponseCookie]].
* string '''hostname''': This is a string containing the IP address or hostname that requested the page.
* string '''url''': This is the URL of the page.
* table '''querystring''': This is a table of all the values passed in the query string (after the ''?'' in the URL).


==See Also==
==See Also==

Revision as of 17:35, 27 October 2007

Dialog-information.png This article needs checking.

Reason(s): HTTP vars need explanation --jbeta 11:24, 27 October 2007 (CDT)

The Multi Theft Auto Server provides a web interface that resources can use in a variety of ways. This document's purpose is to explain what these ways are and how to go about using them.

Overview

There are two key parts that make up this system. The first is a standard web server that allows web browsers to request pages and files you have in a resource. The second is a system for allowing web browsers to call functions you have exported from your resource.

Pages

Specifying a file in the meta

You can specify in your resource's meta file that certain files are accessible through the web server. To do this, you add a line:

<html src="filename" />

You can then access this file from your web browser by visiting: http://host:port/resourcename/filename

Binary files

Despite the misleading name, files specified using the html node can be of any type. If they are binary files (like images, zip files) then you need to specify this in the meta file, by adding raw="true" to the html node. This means that the files are not preprocessed before being sent to the web browser.

For example:

<html src="image.gif" raw="true" />

Parsed files

If a file is not specified in the meta file as "raw", then it is passed through a pre-processor before it is returned to the client. This pre-processor works much like PHP or ASP, but uses LUA. You can embed standard MTA scripts within HTML pages, controlling the output. Almost all standard MTA functions work, plus a number of special HTTP Functions, such as httpWrite, a function that outputs text to the buffer.

For example:

[html]
<html>
    <body>
        This resource is called <* httpWrite( getResourceName(getThisResource()) ) *>
    </body>
<html>

There is a shorthand (in common with PHP and ASP) for this code, meaning that you can also write the above code as:

[html]
<html>
    <body>
        This resource is called <* = getResourceName(getThisResource()) *>
    </body>
<html>

Aside from HTTP functions, embedded Lua has access to the following environment variables that contain information about how the page was requested:

  • table requestHeaders: This is a table containing all the headers that were requested with the page. You can set returned headers using httpSetResponseHeader.
  • table form: This is a table containing all the form data submitted to the page using HTTP POST.
  • table cookies: This is a table of all the cookies. You can modify cookies using httpSetResponseCookie.
  • string hostname: This is a string containing the IP address or hostname that requested the page.
  • string url: This is the URL of the page.
  • table querystring: This is a table of all the values passed in the query string (after the ? in the URL).

See Also