-
Notifications
You must be signed in to change notification settings - Fork 11
Asynchronous Request System
The following page describes the classes the client uses to make asynchronous JSON requests to the webserver.
The AsyncJSONRequest is a wrapper class around Unity's WWW and WWWForm classes for making asynchronous POST and GET HTTP requests to the AsyncRPGWebServer. Unity's coroutine mechanism is used to make this request non-blocking. Because coroutines only work on Unity components, the static AsyncJSONRequest.Create() method is used to "hop-on" an instance of the AsyncJSONRequest component to a given game object. UI Model classes create these requests using the game object associated with the game state that owns the Model class (see Model-View-Controller in the UI System page).
All AsyncRPGServer web requests return a JSON string. The AsyncJSONRequest class attempts to parse this string into a JsonData instance (from the LitJSON library, basically a dictionary). The Model class that issued the request gets the JsonData blob using the GetRequest() method and pulls out the fields it cares about.
Player movement requests are interesting because they are actually a two-stage asynchronous request. The first stage is to do an asynchronous path finding request to the PathFindingSystem, which takes place totally on the client. The second stage, pending a successful path find, sends the appropriate AsyncJSONRequest to the web server. In order to make the client code simpler, we wrap these compound async request classes into a single helper class. All of these request classes will return a list of game events that resulted from the player's movement upon successful completion of the request:
- AsyncCharacterMoveRequest - Move to the player to desired target in the room.
- AsyncCharacterPortalRequest - Move the player through desired target portal (door, stairs, or transporter) to an adjacent room.
- AsyncDrainEnergyTankRequest - Move the player to an energy tank in the current room and attempt to drain energy from it.
- AsyncHackEnergyTankRequest - Move the player to an energy tank in the current room and attempt to make it owned by the player faction (must be player faction to drain it).
Server Project Organization - How the files in the server project are arranged
Mob Types - Format for the mob type definitions
Room Templates - How the room templates are validated and stored in the DB
Navigation - How AI navigation is computed on the server
AI Decision Making - How AIs make decisions in response to players moves
Request Processors - How incoming JSON requests are processed
Database Query Layer - How database queries are structured and cached
Standalone And Embedded Web Server - How the stand alone and client embedded web server are structured
ASPX Web Service - How the IIS hosted web server is structured
Client Project Organization - How the files in the client project are arranged
UI System - Wrapper around Unity immediate mode UI and UI event handling
Asynchronous Request System - How JSON requests are sent to the web server
Game Event System - How the game state changes as a result of player actions
AI Path Finding and Steering - How the AI compute a path and drive toward path waypoints
IRC and Push Notifications - How chat and server push notifications are routed through IRC