org.starhope.appius.game
Class Commands

java.lang.Object
  extended by org.starhope.appius.game.Commands

public class Commands
extends Object

Command processor for Appius Game Server (JSON Commands)

This is the command interpreter library for JSON command received from the game client. The server will search for commands in the general library (using Java reflection to examine this class), as well as a configuration-specified local “library” class for extensions specific to a given game.

This command processor is scanned for a method name matching the command name specified in the RPC call (JSON call) from the client. These commands can be invoked by any client.

Command names must start with do_, followed by the (typically javaCamelCased) command verb. The method signature must be exactly public static void do_ verb (Zone, JSONObject, User, Integer) .

Security is generally voluntary and must be enforced by individual methods.

Author:
brpocock

Constructor Summary
Commands()
           
 
Method Summary
static void do_addFurniture(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
           
static void do_addToList(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
          WRITEME: document this method (brpocock, Aug 31, 2009)
static void do_createUserHouse(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
           Response from the first run screen for the user's house
static void do_doff(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
           JSON object contains "type" = either "clothes" or "pivitz".
static void do_don(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
           JSON object has the item ID to be worn (clothes, patterns, pivitz) and optionally set the color (for patterns)
static void do_echo(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
           Echoes back the supplied ActionScript object to the client.
static void do_gameAction(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
          TODO: document this method (brpocock, Nov 13, 2009)
static void do_getAvatars(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
          Get avatar data for a list of (other) users.
static void do_getColorPalettes(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
          returns palettes in "extraColors", "baseColors", "patternColors" in the JSON result object (from: "getColorPalettes")
static void do_getInventoryByType(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
           JSON object has the type of item from the following list of strings: "clothes" "patterns" "pivitz" "furniture" "structure" "music"
static void do_getOnlineUsers(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
          Get a list of users in a Zone, or in a Room.
static void do_getServerTime(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
           Send the server time to the client requesting it (for synchronization purposes)
static void do_getStoreItems(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
          WRITEME: document this method (brpocock, Aug 26, 2009)
static void do_getUserLists(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
          WRITEME: document this method (brpocock, Aug 31, 2009)
static void do_getZoneList(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
          Get a list of all Zones currently active/visible.
static void do_initUserRoom(org.json.JSONObject jso, AbstractUser u, AbstractRoom userCurrentRoomInZone)
           Creates room named user/user's name/room — room is the room index number given in the JSON data as “room,” it will always be zero right now as all users have single-room houses.
static void do_ping(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
          WRITEME: document this method (brpocock, Sep 8, 2009)
static void do_removeFromList(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
          WRITEME: document this method (brpocock, Aug 31, 2009)
static void do_reportBug(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
          This method allows the client to “phone home”
static void do_reportUser(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
          WRITEME: document this method (brpocock, Aug 31, 2009)
static void do_sendOutOfBandMessage(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
          WRITEME: document this method (brpocock, Sep 2, 2009) { sender: sender, from: outOfBand, status: true, body: {JSON} } Adds "roomTitle" to body if body contains "room" and title can be determined
static void do_setAvatarColor(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
           Params: "base" and "extra" are color numbers
static void do_setFurniture(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
           Set or change a furniture item.
static void do_spawnZone(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
          Spawn an additional zone.
static void do_speak(org.json.JSONObject jso, AbstractUser u, AbstractRoom room)
           
private static String getBuddySignature(AbstractUser u, AbstractUser u2)
          Create a fancy signature thing to validate buddy list requests
static String getRev()
          TODO: document this method (brpocock, Dec 10, 2009)
(package private) static String handleDice(String inSpeech)
          Handle die rolls, coin tosses, and magic Rock-Paper-Scissors picker
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Commands

public Commands()
Method Detail

do_addFurniture

public static void do_addFurniture(org.json.JSONObject jso,
                                   AbstractUser u,
                                   AbstractRoom room)
                            throws org.json.JSONException,
                                   NotFoundException
Parameters:
jso - WRITEME
u - WRITEME
room - WRITEME
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form
NotFoundException - WRITEME
See Also:
do_setFurniture(JSONObject, AbstractUser, AbstractRoom)

do_addToList

public static void do_addToList(org.json.JSONObject jso,
                                AbstractUser u,
                                AbstractRoom room)
                         throws org.json.JSONException
WRITEME: document this method (brpocock, Aug 31, 2009)

Parameters:
jso - { buddy: (name) } or { ignore: (name) } or { buddy: (name), confirm: (boolean), sign: (signature) } or
u - WRITEME
room - WRITEME
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form

do_createUserHouse

public static void do_createUserHouse(org.json.JSONObject jso,
                                      AbstractUser u,
                                      AbstractRoom room)
                               throws org.json.JSONException

Response from the first run screen for the user's house

Parameters:
jso - Data describing the user's lot { lot: lot-ID, house: house-ID }
u - The user buying the lot
room - The room in which the user is found — for communications purposes, at least.
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form

do_doff

public static void do_doff(org.json.JSONObject jso,
                           AbstractUser u,
                           AbstractRoom room)
                    throws org.json.JSONException

JSON object contains "type" = either "clothes" or "pivitz". Does not affect patterns.

Response with total avatar info from "wardrobe"

Parameters:
jso - WRITEME
u - WRITEME
room - WRITEME
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form

do_don

public static void do_don(org.json.JSONObject jso,
                          AbstractUser u,
                          AbstractRoom room)
                   throws org.json.JSONException,
                          NumberFormatException,
                          DataException

JSON object has the item ID to be worn (clothes, patterns, pivitz) and optionally set the color (for patterns)

Response with total avatar info from "wardrobe"

Parameters:
jso - { item = (itemID) }
u - WRITEME
room - WRITEME
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form
DataException - for bad colour
NumberFormatException - for bad colour numeric parts

do_echo

public static void do_echo(org.json.JSONObject jso,
                           AbstractUser u,
                           AbstractRoom room)

Echoes back the supplied ActionScript object to the client. This method exists solely for testing purposes.

Sends response containing:

Parameters:
jso - Any JSON object, the contents of which will be returned to the caller.
u - The user calling (to whom the response is sent)
room - The room in which the user calls us (ignored)

do_gameAction

public static void do_gameAction(org.json.JSONObject jso,
                                 AbstractUser u,
                                 AbstractRoom room)
                          throws org.json.JSONException
TODO: document this method (brpocock, Nov 13, 2009)

Parameters:
jso - WRITEME
u - WRITEME
room - WRITEME
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form

do_getAvatars

public static void do_getAvatars(org.json.JSONObject jso,
                                 AbstractUser u,
                                 AbstractRoom room)
                          throws org.json.JSONException
Get avatar data for a list of (other) users.

Parameters:
jso - JSON object, with (ignored) keys tied to values which must be the names of users.
u - The calling user. The calling user's avatar data will not be returned.
room - the (ignored) room in which the method is being called
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form

do_getColorPalettes

public static void do_getColorPalettes(org.json.JSONObject jso,
                                       AbstractUser u,
                                       AbstractRoom room)
                                throws SQLException,
                                       org.json.JSONException
returns palettes in "extraColors", "baseColors", "patternColors" in the JSON result object (from: "getColorPalettes")

Parameters:
jso - JSON parameters: ignored
u - calling user
room - calling user's room
Throws:
SQLException - if something squirrelly happens
org.json.JSONException - if something squirrelly happens

do_getInventoryByType

public static void do_getInventoryByType(org.json.JSONObject jso,
                                         AbstractUser u,
                                         AbstractRoom room)
                                  throws org.json.JSONException

JSON object has the type of item from the following list of strings: "clothes" "patterns" "pivitz" "furniture" "structure" "music"

Returns a set of items as inv: { 0: { id: 123, isActive: boolean }, ... } — furniture with placement data will also have x, y, and facing vars. Other attributes are "from":"inventory", "type": matching the type of the question

Parameters:
jso - WRITEME
u - WRITEME
room - WRITEME
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form

do_getOnlineUsers

public static void do_getOnlineUsers(org.json.JSONObject jso,
                                     AbstractUser u,
                                     AbstractRoom room)
                              throws org.json.JSONException,
                                     PrivilegeRequiredException
Get a list of users in a Zone, or in a Room. This is an administrative function, only available to staff members.

Parameters:
jso - The JSON data provided by the caller. If this contains an attribute of "inRoom" with a room moniker, we'll only return the users in that room. Otherwise, all users in the Zone will be returned.
u - The caller's ID. Must have staff privileges.
room - The room from which the caller is making the extension call: ignored.
Throws:
org.json.JSONException - if the JSON data can't be processed, in or out.
PrivilegeRequiredException - if the user doesn't have STAFF_LEVEL_STAFF_MEMBER

do_getServerTime

public static void do_getServerTime(org.json.JSONObject jso,
                                    AbstractUser u,
                                    AbstractRoom room)
                             throws org.json.JSONException

Send the server time to the client requesting it (for synchronization purposes)

Sends a JSON object with a single property, serverTime, with the current time in milliseconds (give or take transit time)

Parameters:
jso - ignored
u - The user requesting the time
room - The room in which the user is standing
Throws:
org.json.JSONException - If the JSON data can't be written out

do_getStoreItems

public static void do_getStoreItems(org.json.JSONObject jso,
                                    AbstractUser u,
                                    AbstractRoom room)
                             throws NumberFormatException,
                                    org.json.JSONException
WRITEME: document this method (brpocock, Aug 26, 2009)

Results: totalPeanuts, stores...

Parameters:
jso - WRITEME
u - WRITEME
room - WRITEME
Throws:
NumberFormatException - WRITEME
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form

do_getUserLists

public static void do_getUserLists(org.json.JSONObject jso,
                                   AbstractUser u,
                                   AbstractRoom room)
                            throws org.json.JSONException
WRITEME: document this method (brpocock, Aug 31, 2009)

{ buddyList: { 0: { buddy-notice... } , 1: { buddy-notice... } , ... } , ignoreList: { 0: ignoredUserName, 1: ignoredUserName, ... } }

Parameters:
jso - no parameters needed
u - WRITEME
room - WRITEME
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form

do_getZoneList

public static void do_getZoneList(org.json.JSONObject jso,
                                  AbstractUser u,
                                  AbstractRoom room)
                           throws org.json.JSONException
Get a list of all Zones currently active/visible. (Empty and retired Zones are culled. See AbstractZone.getZoneList_JSON(org.starhope.appius.user.AbstractUser) )

Parameters:
jso - Ignored
u - The user requesting the data.
room - Ignored
Throws:
org.json.JSONException - If something untoward happens

do_initUserRoom

public static void do_initUserRoom(org.json.JSONObject jso,
                                   AbstractUser u,
                                   AbstractRoom userCurrentRoomInZone)
                            throws org.json.JSONException

Creates room named user/user's name/room — room is the room index number given in the JSON data as “room,” it will always be zero right now as all users have single-room houses. This will populate all furniture-type items for that room onto a set of room variables owned by the user. The user calling this method must be the owner of the room. If the user has not visited his/her house before, this will return an asynchronous "make a new house" notification to do the "first run" screen, by sending a message of type { "from": "initUserRoom", "status": false, "err": "showFirstRun" }.

Success: responds with true, and "moniker": the room's moniker (user/WHOEVER/123)

Parameters:
jso - { room: (room-number), autoJoin: (boolean) }
u - WRITEME
userCurrentRoomInZone - WRITEME
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form

do_ping

public static void do_ping(org.json.JSONObject jso,
                           AbstractUser u,
                           AbstractRoom room)
                    throws org.json.JSONException
WRITEME: document this method (brpocock, Sep 8, 2009)

Parameters:
jso - WRITEME
u - WRITEME
room - WRITEME
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form

do_removeFromList

public static void do_removeFromList(org.json.JSONObject jso,
                                     AbstractUser u,
                                     AbstractRoom room)
                              throws org.json.JSONException
WRITEME: document this method (brpocock, Aug 31, 2009)

Parameters:
jso - { buddy: (name) } or { ignore: (name) }
u - WRITEME
room - WRITEME
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form

do_reportBug

public static void do_reportBug(org.json.JSONObject jso,
                                AbstractUser u,
                                AbstractRoom room)
                         throws org.json.JSONException
This method allows the client to “phone home”

Parameters:
jso - Must contain a single string attribute named "bug." Other attributes will be ignored.
u - The user reporting the bug.
room - The user's current room.
Throws:
org.json.JSONException - JSON encoding error

do_reportUser

public static void do_reportUser(org.json.JSONObject jso,
                                 AbstractUser u,
                                 AbstractRoom room)
                          throws org.json.JSONException
WRITEME: document this method (brpocock, Aug 31, 2009)

Parameters:
jso - { userName = user to be reported }
u - WRITEME
room - WRITEME
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form

do_sendOutOfBandMessage

public static void do_sendOutOfBandMessage(org.json.JSONObject jso,
                                           AbstractUser u,
                                           AbstractRoom room)
                                    throws org.json.JSONException
WRITEME: document this method (brpocock, Sep 2, 2009) { sender: sender, from: outOfBand, status: true, body: {JSON} } Adds "roomTitle" to body if body contains "room" and title can be determined

Parameters:
jso - { to: userName, body: {JSON} } { toRoom: true, body: {JSON} }
u - WRITEME
room - WRITEME
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form

do_setAvatarColor

public static void do_setAvatarColor(org.json.JSONObject jso,
                                     AbstractUser u,
                                     AbstractRoom room)
                              throws org.json.JSONException

Params: "base" and "extra" are color numbers

WRITEME: document this method (brpocock, Aug 27, 2009)

Parameters:
jso - WRITEME
u - WRITEME
room - WRITEME
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form

do_setFurniture

public static void do_setFurniture(org.json.JSONObject jso,
                                   AbstractUser u,
                                   AbstractRoom room)
                            throws org.json.JSONException,
                                   NotFoundException

Set or change a furniture item. To add a structural item to the room, put item: 123 without anything else. To place furniture on the floor, also add attributes x, y, and facing.

To change furniture, replace item: with slot: (to avoid ambiguities about “which chair”)

To remove an item from the room, send { slot: 123, remove: true }

Parameters:
jso - WRITEME
u - WRITEME
room - WRITEME
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form
NotFoundException - WRITEME

do_spawnZone

public static void do_spawnZone(org.json.JSONObject jso,
                                AbstractUser u,
                                AbstractRoom room)
                         throws org.json.JSONException,
                                PrivilegeRequiredException
Spawn an additional zone.

Parameters:
jso - JSON object, containing an associative array whose values are zones to be spawned
u - The caller responsible
room - Where is the caller?
Throws:
org.json.JSONException - if something goes awry
PrivilegeRequiredException - if the user isn't a Developer

do_speak

public static void do_speak(org.json.JSONObject jso,
                            AbstractUser u,
                            AbstractRoom room)
                     throws org.json.JSONException,
                            NotFoundException
Parameters:
jso - WRITEME
u - WRITEME
room - WRITEME
Throws:
org.json.JSONException - Thrown if the data cannot be interpreted from the JSON objects passed in, or conversely, if we can't encode a response into a JSON form
NotFoundException - WRITEME

getBuddySignature

private static String getBuddySignature(AbstractUser u,
                                        AbstractUser u2)
Create a fancy signature thing to validate buddy list requests

Parameters:
u - WRITEME
u2 - WRITEME
Returns:
WRITEME

getRev

public static String getRev()
TODO: document this method (brpocock, Dec 10, 2009)

Returns:
WRITEME

handleDice

static String handleDice(String inSpeech)
Handle die rolls, coin tosses, and magic Rock-Paper-Scissors picker

Parameters:
inSpeech - Speech before filtering
Returns:
Speech after filtering