Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 5a7eb8ab4d

Fetching latest commit…

Cannot retrieve the latest commit at this time

..
Failed to load latest commit information.
Character
Database
Game
Install
Log
User
pages
Cache.njs
README.md
index.html
mootools-core-1.4.2-server.njs
rpgApp.njs

README.md

Server Side Stuff

All requests are processed through rpgApp.njs

rpgApp.njs


Starts the Node.js server listening on the specified port. In the case of IISNode we need to use process.env.PORT

Imports


Exports


  • RPG.App

Request Handling


All requests begin at onRequest and are handled in the following order:

  1. Attach an event handler to the request object to start receiving incoming data from post requests. Upon receiving all the data the request.data variable will be populated with this data.
  2. Determine who the user is by looking at their cookies (create a user if not found) continue on to step 2 when a determination has been made.
  3. Check to see if an XmlHttpRequest is being made.
    1. false : No XHR means initial load - Send the client the /server/index.html template. End Request
    2. true : pass control to routeXHR
  4. routeXHR uses the querystring parameter a as the 'Action' to be performed. a can contain a hashtag which signifies the /server/pages/ to use
    1. if a contains a ? in it's value, everything after the ? (seperated by ::) is converted into a querystring an appended to the current querystring
  5. Attempt to handle the request using the /common/pages.js object.
    1. if a suitable handler is found then control is passed to the handler.
  6. Attempt to handle the request in other ways
    1. if a suitable handler is found then control is passed to the handler.
  7. return an error if no suitable handler was found.

Response Handling


All responses should go through onRequestComplete. The onRequestComplete function is attached to each response object so the callback can occur anywhere the response object goes.

To end a request simply use: response.onResponseComplete(response,results)

if the result is an error object: eg { error : errorStuff } then onRequestComplete will use a 500 header instead of a 200 header.

Something went wrong with that request. Please try again.