org.starhope.appius.server
Class OsirisSFSExtension

java.lang.Object
  extended by it.gotoandplay.smartfoxserver.extensions.AbstractExtension
      extended by org.starhope.appius.server.OsirisSFSExtension
All Implemented Interfaces:
IEventListener, ISmartFoxExtension, Thread.UncaughtExceptionHandler

public class OsirisSFSExtension
extends AbstractExtension
implements Thread.UncaughtExceptionHandler

This is the part of Osiris which lives as a Smart Fox Server extension.

Author:
brpocock

Field Summary
private  Set<String> cullRooms
           
private static String EAVESDROP_PASSWORD
           The password for $Eaves is the medieval Tuscan interpretation of the inscription upon the Black Gates, as read by Virgil to Dante Alligheri in The Divine Comedy.
(package private)  Set<Zone> emptyZones
          List of empty zones
private static long lastCheckedZonesForSpawn
           
(package private)  Set<String> myEmptyZones
          Names of empty zones
private static int NPC_TICK_INTERVAL
          Time between updates for NPC's
private  boolean serverReady
          A flag set once the server has indicated that it's ready to go, to avoid issues with events firing off too soon (e.g.
private static God systemUser
          The system “God” user account
private static int USER_ROOM_MAX_USERS
          Max users allowed into one room of an user's house at a time
private static float ZONE_FULL_RATIO
          Get the percentage of "full" at which we consider a zone to be full enough to warrant spawning new ones.
private static float ZONE_LIGHT_RATIO
          Get the percentage of "full" at which we consider a zone to be light enough that it's almost empty
private static int ZONE_MAX_USERS
          The max.
private static int ZONE_SPAWN_SECONDS
          Time (in seconds) between spawning new zones
 
Fields inherited from class it.gotoandplay.smartfoxserver.extensions.AbstractExtension
__isActive, __roomName, __zoneName, adminExtension
 
Constructor Summary
OsirisSFSExtension()
          Default constructor
 
Method Summary
private  void assertStaffLevel(User u, int staffLevelRequired)
          Assert that the given user must have a given level of staff privileges
 void biff(User u, User user, Integer room)
           Async mail notification: { from: "postman", status: true, newMail: NNN }
private  void checkZonesForSpawn()
          See if enough zones are full to warrant spawning a new one; or, if zones are empty and can be deallocated.
 void destroy()
          This is an overriding method.
 void do_addFurniture(org.json.JSONObject jso, User u, Integer room)
           
 void do_addToList(org.json.JSONObject jso, User u, Integer room)
          WRITEME: document this method (brpocock, Aug 31, 2009)
 void do_createUserHouse(org.json.JSONObject jso, User u, Integer room)
           Response from the first run screen for the user's house
 void do_doff(org.json.JSONObject jso, User u, Integer room)
           JSON object contains "type" = either "clothes" or "pivitz".
 void do_don(org.json.JSONObject jso, User u, Integer room)
           JSON object has the item ID to be worn (clothes, patterns, pivitz) and optionally set the color (for patterns)
 void do_echo(org.json.JSONObject jso, User u, Integer room)
           Echoes back the supplied ActionScript object to the client.
 void do_endEvent(org.json.JSONObject jso, User u, Integer room)
           This method terminates an event (probably a minigame, but possibly a fountain) which was initiated by startEvent.
 void do_getAvatars(org.json.JSONObject jso, User u, Integer room)
          Get avatar data for a list of (other) users.
 void do_getColorPalettes(org.json.JSONObject jso, User u, Integer room)
          returns palettes in "extraColors", "baseColors", "patternColors" in the JSON result object (from: "getColorPalettes")
 void do_getInventoryByType(org.json.JSONObject jso, User u, Integer room)
           JSON object has the type of item from the following list of strings: "clothes" "patterns" "pivitz" "furniture" "structure" "music"
 void do_getMailInBox(org.json.JSONObject jso, User u, Integer room)
           Response: mail: { 0: { id: number, from: userName, to: userName, subject: "", sentTime: date & time string, readTime: date & time string, body: "" }, ...
 void do_getMailMessage(org.json.JSONObject jso, User u, Integer room)
          WRITEME: document this method (brpocock, Aug 28, 2009) Response: message: { id: number, from: userName, to: userName, subject: "", sentTime: date & time string, readTime: date & time string, body: "" }
 void do_getOnlineUsers(org.json.JSONObject jso, User u, Integer room)
          Get a list of users in a Zone, or in a Room.
 void do_getPassport(org.json.JSONObject jso, User u, Integer room)
          Get the list of places that the user has already been to.
 void do_getStoreItems(org.json.JSONObject jso, User u, Integer room)
          WRITEME: document this method (brpocock, Aug 26, 2009)
 void do_getUserLists(org.json.JSONObject jso, User u, Integer room)
          WRITEME: document this method (brpocock, Aug 31, 2009)
 void do_getUserMailboxes(org.json.JSONObject jso, User u, Integer room)
          WRITEME: document this method (brpocock, Aug 28, 2009) Response: boxes: { 0: "INBOX" , ...
 void do_getZoneList(org.json.JSONObject jso, User u, Integer room)
          Get a list of all Zones currently active/visible.
 void do_initUserRoom(org.json.JSONObject jso, User u, Integer room)
           Creates room named user/user's name/room — room is the number given in the JSON data as "room," it will always be zero right now as all users have single-room houses.
 void do_markMailMessageAsRead(org.json.JSONObject jso, User u, Integer room)
          WRITEME: document this method (brpocock, Aug 28, 2009)
 void do_ping(org.json.JSONObject jso, User u, Integer room)
          TODO: document this method (brpocock, Sep 8, 2009)
 void do_purchase(org.json.JSONObject jso, User u, Integer room)
           Execute a purchase of an item by an user.
 void do_removeFromList(org.json.JSONObject jso, User u, Integer room)
          WRITEME: document this method (brpocock, Aug 31, 2009)
 void do_reportBug(org.json.JSONObject jso, User u, Integer room)
          This method allows the client to “phone home”
 void do_reportUser(org.json.JSONObject jso, User u, Integer room)
          WRITEME: document this method (brpocock, Aug 31, 2009)
 void do_sendMailMessage(org.json.JSONObject jso, User u, Integer room)
          TODO: document this method (brpocock, Sep 8, 2009)
 void do_sendOutOfBandMessage(org.json.JSONObject jso, User u, Integer 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
 void do_setAvatarColor(org.json.JSONObject jso, User u, Integer room)
           Params: "base" and "extra" are color numbers
 void do_setFurniture(org.json.JSONObject jso, User u, Integer room)
           Set or change a furniture item.
 void do_spawnZone(org.json.JSONObject jso, User u, Integer room)
          Spawn an additional zone.
 void do_stampPassport(org.json.JSONObject jso, User u, Integer room)
          TODO: document this method (brpocock, Sep 8, 2009)
 void do_startEvent(org.json.JSONObject jso, User u, Integer room)
           Attempt to begin an event.
private  void dropUser(User user)
          WRITEME: document this method (brpocock, Sep 2, 2009)
private  String getApple(SocketChannel channel, String pass)
          Get the “apple” (CHAP authentication string SHA1 digest encoded in hex) for the login system
 void getMedalRankings(org.json.JSONObject jso, User u, Integer room)
          WRITEME: document this method (brpocock, Sep 1, 2009)
 User getSFSSystemUser()
          WRITEME: document this method (brpocock, Aug 18, 2009)
private  org.json.JSONObject getZoneList_JSON()
           
private  void handleFileUpload(InternalEventObject ieo)
          Handle a file upload event — which we don't do, so I don't handle it, but let's kick the requesting user just for safety? (TODO)
 void handleInternalEvent(InternalEventObject ieo)
          This is an overriding method.
private  void handleJoin(String zoneName, User user, Room room)
          Handle (log only) an user joining a new room.
private  void handleLogin(String zoneName, String bigNick, String password, SocketChannel channel)
          Process a login request from the user
 void handleNewRoom(InternalEventObject ieo)
          WRITEME: document this method (brpocock, Jul 14, 2009)
 void handleRequest(String cmd, ActionscriptObject ao, User u, int fromRoom)
          This is an overriding method.
 void handleRequest(String cmd, org.json.JSONObject jso, User u, int fromRoom)
          This is an overriding method.
 void handleRequest(String cmd, String[] params, User u, int fromRoom)
          This is an overriding method.
 void handleRoomLost(InternalEventObject ieo)
          WRITEME: document this method (brpocock, Jul 14, 2009)
private  void handleServerReady()
          Once the server indicates its readiness, begin spawning auto-spawning Zones
private  void handleSpeak(InternalEventObject ieo)
          WRITEME: document this method (brpocock, Jul 14, 2009)
 void handleSpectatorSwitched(InternalEventObject ieo)
          WRITEME: document this method (brpocock, Jul 14, 2009)
 void handleUserLost(InternalEventObject ieo)
          WRITEME: document this method (brpocock, Jul 14, 2009)
 void handleUserPart(String zone, Room room, String uid, User user, String oldPlayerIndex)
          WRITEME: document this method (brpocock, Jul 14, 2009)
private  void handleWhisper(InternalEventObject ieo)
          WRITEME: document this method (brpocock, Jul 14, 2009)
 void init()
          This is an overriding method.
protected  void sendBuddyNotice(String buddyName, boolean isOnline, String roomMoniker, String roomTitle, User u, int room)
           Sends a buddy notice message to the client
private  void sendError_RAW(String xtnName, String message, SocketChannel channel)
          WRITEME: document this method (brpocock, Aug 19, 2009)
private  void sendErrorReply(String source, String error, org.json.JSONObject result, User u, int room)
          WRITEME: document this method (brpocock, Aug 20, 2009)
private  void sendSuccessReply(String source, org.json.JSONObject resultIn, User u, int room)
          WRITEME: document this method (brpocock, Aug 20, 2009)
private  void sendSuccessReply(String source, org.json.JSONObject resultIn, User u, int room, LinkedList<SocketChannel> recipients)
           
private  void sendUserLists(User u)
           
private  void sendUserLists(User u, User user)
           
private  void sendWardrobe(User user, User u, int room)
          Send a "from:wardrobe" message to the user
 void spawnNewZone()
          Create a new zone if one is needed
private  void spawnZone(String zoneName, String image)
          Create a new, empty zone, and attach the default properties to it.
 void uncaughtException(Thread t, Throwable e)
          This is an overriding method.
 
Methods inherited from class it.gotoandplay.smartfoxserver.extensions.AbstractExtension
getOwnerRoom, getOwnerZone, handleInternalRequest, isActive, loadConfig, registerForEvents, sendResponse, sendResponse, sendResponse, sendResponse, setActive, setOwner, trace, unRegister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EAVESDROP_PASSWORD

private static final String EAVESDROP_PASSWORD

The password for $Eaves is the medieval Tuscan interpretation of the inscription upon the Black Gates, as read by Virgil to Dante Alligheri in The Divine Comedy.

Perhaps the best English translation thereof is:

Through me the road to the city of desolation,
Through me the road to sorrows diuturnal,
Through me the road among the lost creation.
Justice moved my great maker; God eternal Wrought me:
the power, and the unsearchably High wisdom, and the primal love supernal.
Nothing ere I was made was made to be
Save things eterne, and I eterne abide;
Lay down all hope, you that go in by me.
-- Dorothy L. Sayers

See Also:
Constant Field Values

lastCheckedZonesForSpawn

private static long lastCheckedZonesForSpawn

NPC_TICK_INTERVAL

private static final int NPC_TICK_INTERVAL
Time between updates for NPC's

See Also:
Constant Field Values

systemUser

private static God systemUser
The system “God” user account


USER_ROOM_MAX_USERS

private static final int USER_ROOM_MAX_USERS
Max users allowed into one room of an user's house at a time

See Also:
Constant Field Values

ZONE_FULL_RATIO

private static final float ZONE_FULL_RATIO
Get the percentage of "full" at which we consider a zone to be full enough to warrant spawning new ones.

See Also:
Constant Field Values

ZONE_LIGHT_RATIO

private static final float ZONE_LIGHT_RATIO
Get the percentage of "full" at which we consider a zone to be light enough that it's almost empty

See Also:
Constant Field Values

ZONE_MAX_USERS

private static final int ZONE_MAX_USERS
The max. users per Zone (And per every room in every real zone)

See Also:
Constant Field Values

ZONE_SPAWN_SECONDS

private static final int ZONE_SPAWN_SECONDS
Time (in seconds) between spawning new zones

See Also:
Constant Field Values

cullRooms

private final Set<String> cullRooms

emptyZones

Set<Zone> emptyZones
List of empty zones


myEmptyZones

Set<String> myEmptyZones
Names of empty zones


serverReady

private boolean serverReady
A flag set once the server has indicated that it's ready to go, to avoid issues with events firing off too soon (e.g. NPC's)

Constructor Detail

OsirisSFSExtension

public OsirisSFSExtension()
Default constructor

Method Detail

assertStaffLevel

private void assertStaffLevel(User u,
                              int staffLevelRequired)
                       throws PrivilegeRequiredException
Assert that the given user must have a given level of staff privileges

Parameters:
u - The Smart Fox user object
staffLevelRequired - The staff level required to perform the action
Throws:
PrivilegeRequiredException - if the user

biff

public void biff(User u,
                 User user,
                 Integer room)
          throws org.json.JSONException

Async mail notification: { from: "postman", status: true, newMail: NNN }

Call this method to send an asynchronous mail notification for the given user.

Parameters:
u - the Smartfox user
user - the Braque user
room - the user's room
Throws:
org.json.JSONException

checkZonesForSpawn

private void checkZonesForSpawn()
See if enough zones are full to warrant spawning a new one; or, if zones are empty and can be deallocated.


destroy

public void destroy()
This is an overriding method.

Specified by:
destroy in interface ISmartFoxExtension
Overrides:
destroy in class AbstractExtension
See Also:
AbstractExtension.destroy()

do_addFurniture

public void do_addFurniture(org.json.JSONObject jso,
                            User u,
                            Integer room)
                     throws org.json.JSONException,
                            NotFoundException
Parameters:
jso -
u -
room -
Throws:
org.json.JSONException
NotFoundException
See Also:
#do_setFurniture(JSONObject, User, Integer)34

do_addToList

public void do_addToList(org.json.JSONObject jso,
                         User u,
                         Integer 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 -
room -
Throws:
org.json.JSONException

do_createUserHouse

public void do_createUserHouse(org.json.JSONObject jso,
                               User u,
                               Integer 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

do_doff

public void do_doff(org.json.JSONObject jso,
                    User u,
                    Integer 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 -
u -
room -
Throws:
org.json.JSONException

do_don

public void do_don(org.json.JSONObject jso,
                   User u,
                   Integer room)
            throws org.json.JSONException

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 -
room -
Throws:
org.json.JSONException

do_echo

public void do_echo(org.json.JSONObject jso,
                    User u,
                    Integer 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_endEvent

public void do_endEvent(org.json.JSONObject jso,
                        User u,
                        Integer room)
                 throws org.json.JSONException

This method terminates an event (probably a minigame, but possibly a fountain) which was initiated by startEvent.

For fountains, the score is ignored, and a random number from 1..100 is used as the effective score. Since fountains (should) have a 1:1 points:peanuts ratio, this will earn the player 1..100 peanuts randomly per fountain visit.

Response: JSON sent to user: { ended: event ID; peanuts: number of peanuts earned; highScores: array of scores, indexed by position on the high score list (1..24), each of which contains: { points: number of points scored by the high-scoring user; userName: the name of the user }, totalPeanuts: user's new total peanut balance }

Additionally, if this user earned a high score on this event, s/he will get the attribute in the top level of the response as "gotHighScore": with the value being the position number which was earned. For example, earning no high score omits the "gotHighScore" attribute altogether; earning the third highest score will return instead "gotHighScore" == 3.

Parameters:
jso - JSON parameters. { moniker = the event's moniker; id = the event ID to be ended; score = the earned score, in points (not peanuts); status = one of "cxl" to cancel an event (in which case, score should be 0), or "cmp" to complete an event (score may be zero or more). }
u - The calling user
room - The room in which the user is found (for replies)
Throws:
org.json.JSONException - if something nasty happens

do_getAvatars

public void do_getAvatars(org.json.JSONObject jso,
                          User u,
                          Integer 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

do_getColorPalettes

public void do_getColorPalettes(org.json.JSONObject jso,
                                User u,
                                Integer 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 void do_getInventoryByType(org.json.JSONObject jso,
                                  User u,
                                  Integer 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 -
u -
room -
Throws:
org.json.JSONException

do_getMailInBox

public void do_getMailInBox(org.json.JSONObject jso,
                            User u,
                            Integer room)
                     throws org.json.JSONException

Response: mail: { 0: { id: number, from: userName, to: userName, subject: "", sentTime: date & time string, readTime: date & time string, body: "" }, ... }

Parameters:
jso - { box: "INBOX" }
u -
room -
Throws:
org.json.JSONException

do_getMailMessage

public void do_getMailMessage(org.json.JSONObject jso,
                              User u,
                              Integer room)
                       throws NotFoundException,
                              org.json.JSONException
WRITEME: document this method (brpocock, Aug 28, 2009) Response: message: { id: number, from: userName, to: userName, subject: "", sentTime: date & time string, readTime: date & time string, body: "" }

Parameters:
jso - { id: mailboxID }
u -
room -
Throws:
org.json.JSONException
NotFoundException

do_getOnlineUsers

public void do_getOnlineUsers(org.json.JSONObject jso,
                              User u,
                              Integer 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_getPassport

public void do_getPassport(org.json.JSONObject jso,
                           User u,
                           Integer room)
                    throws org.json.JSONException,
                           SQLException
Get the list of places that the user has already been to.

Parameters:
jso -
u -
room -
Throws:
org.json.JSONException
SQLException

do_getStoreItems

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

Results: totalPeanuts, stores...

Parameters:
jso -
u -
room -
Throws:
NumberFormatException
org.json.JSONException

do_getUserLists

public void do_getUserLists(org.json.JSONObject jso,
                            User u,
                            Integer 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 -
room -
Throws:
org.json.JSONException

do_getUserMailboxes

public void do_getUserMailboxes(org.json.JSONObject jso,
                                User u,
                                Integer room)
                         throws org.json.JSONException
WRITEME: document this method (brpocock, Aug 28, 2009) Response: boxes: { 0: "INBOX" , ... }

Parameters:
jso - ( no input )
u -
room -
Throws:
org.json.JSONException

do_getZoneList

public void do_getZoneList(org.json.JSONObject jso,
                           User u,
                           Integer room)
                    throws org.json.JSONException
Get a list of all Zones currently active/visible. (Empty Zones are culled. See getZoneList_JSON() )

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

do_initUserRoom

public void do_initUserRoom(org.json.JSONObject jso,
                            User u,
                            Integer room)
                     throws org.json.JSONException,
                            it.gotoandplay.smartfoxserver.exceptions.CreateRoomException

Creates room named user/user's name/room — room is the 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: (roomnumber), autoJoin: (boolean) }
u -
room -
Throws:
org.json.JSONException
it.gotoandplay.smartfoxserver.exceptions.CreateRoomException
AlreadyExistsException

do_markMailMessageAsRead

public void do_markMailMessageAsRead(org.json.JSONObject jso,
                                     User u,
                                     Integer room)
                              throws NumberFormatException,
                                     org.json.JSONException,
                                     NotFoundException
WRITEME: document this method (brpocock, Aug 28, 2009)

Parameters:
jso - { id: message ID # }
u -
room -
Throws:
org.json.JSONException
NumberFormatException
NotFoundException

do_ping

public void do_ping(org.json.JSONObject jso,
                    User u,
                    Integer room)
             throws org.json.JSONException
TODO: document this method (brpocock, Sep 8, 2009)

Parameters:
jso -
u -
room -
Throws:
org.json.JSONException

do_purchase

public void do_purchase(org.json.JSONObject jso,
                        User u,
                        Integer room)
                 throws org.json.JSONException,
                        NotFoundException

Execute a purchase of an item by an user. Deducts peanuts, registers (and ends) an event, and adds the appropriate item to the user's inventory.

Returns a success reply to the caller with "bought": (itemID) , "title": (item title), and "totalPeanuts": (the user's new personal balance of peanuts to spend, with this transaction already deducted) (status:true, from:purchase)

Error reply of err="nsf" = not-sufficient-funds, or err="dupe" = duplicate item

Parameters:
jso - { "itemID": itemID }
u - The buyer
room - The buyer's room
Throws:
org.json.JSONException - if the data can't be put in or out of JSON-land.
NotFoundException - if the item was bought and didn't exist

do_removeFromList

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

Parameters:
jso - { buddy: (name) } or { ignore: (name) }
u -
room -
Throws:
org.json.JSONException

do_reportBug

public void do_reportBug(org.json.JSONObject jso,
                         User u,
                         Integer 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 void do_reportUser(org.json.JSONObject jso,
                          User u,
                          Integer room)
                   throws org.json.JSONException
WRITEME: document this method (brpocock, Aug 31, 2009)

Parameters:
jso - { userName = user to be reported }
u -
room -
Throws:
org.json.JSONException

do_sendMailMessage

public void do_sendMailMessage(org.json.JSONObject jso,
                               User u,
                               Integer room)
                        throws org.json.JSONException
TODO: document this method (brpocock, Sep 8, 2009)

Parameters:
jso -
u -
room -
Throws:
org.json.JSONException

do_sendOutOfBandMessage

public void do_sendOutOfBandMessage(org.json.JSONObject jso,
                                    User u,
                                    Integer 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} }
u -
room -
Throws:
org.json.JSONException

do_setAvatarColor

public void do_setAvatarColor(org.json.JSONObject jso,
                              User u,
                              Integer room)
                       throws org.json.JSONException

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

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

Parameters:
jso -
u -
room -
Throws:
org.json.JSONException

do_setFurniture

public void do_setFurniture(org.json.JSONObject jso,
                            User u,
                            Integer 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 -
u -
room -
Throws:
org.json.JSONException
NotFoundException

do_spawnZone

public void do_spawnZone(org.json.JSONObject jso,
                         User u,
                         Integer 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_stampPassport

public void do_stampPassport(org.json.JSONObject jso,
                             User u,
                             Integer room)
                      throws org.json.JSONException,
                             SQLException
TODO: document this method (brpocock, Sep 8, 2009)

Parameters:
jso - { room: (MONIKER) }
u -
room -
Throws:
org.json.JSONException
SQLException

do_startEvent

public void do_startEvent(org.json.JSONObject jso,
                          User u,
                          Integer room)
                   throws org.json.JSONException,
                          SQLException

Attempt to begin an event. Might return an error. Uses User.startEvent(String) for the heavy lifting.

Note that for all fountains, use the magic moniker “fountain”

Calls back the user with either of:

alreadyDone: true; status: false; err: "event.alreadyDone"
This returns for fountains that have already given peanuts today (where today started at midnight, database local time)
eventID: (NUM), filename: "blah.swf", asVersion: { 2, 3, or not }, status: true
For successfully registered events. Must be completed or canceled using do_endEvent(JSONObject, User, Integer)

Parameters:
jso - JSON payload from the caller. Data: moniker = event moniker.
u - The caller = the user performing the event
room - The caller's room. For fountains, we'll use this room's moniker to figure out which fountain is which
Throws:
org.json.JSONException - if JSON data can't be put into a response, or gotten out of a command.
SQLException - probably means that the moniker is bad, but I'm not really doing much to validate it here

dropUser

private void dropUser(User user)
WRITEME: document this method (brpocock, Sep 2, 2009)

Parameters:
user -

getApple

private String getApple(SocketChannel channel,
                        String pass)
Get the “apple” (CHAP authentication string SHA1 digest encoded in hex) for the login system

Parameters:
channel - The SocketChannel to the relevant user
pass - The plaintext password to be used
Returns:
the “apple” string

getMedalRankings

public void getMedalRankings(org.json.JSONObject jso,
                             User u,
                             Integer room)
                      throws org.json.JSONException,
                             NotFoundException,
                             SQLException
WRITEME: document this method (brpocock, Sep 1, 2009)

returns ranks {1: {name:"name", gold:int, silver:int, bronze:int} ...}

Parameters:
jso - { count=10, type=tootlympics }
u -
room -
Throws:
org.json.JSONException
NotFoundException
SQLException

getSFSSystemUser

public User getSFSSystemUser()
WRITEME: document this method (brpocock, Aug 18, 2009)

Returns:
the system's own user account

getZoneList_JSON

private org.json.JSONObject getZoneList_JSON()
                                      throws org.json.JSONException
Returns:
a zoneList object to be passed to the client
Throws:
org.json.JSONException - JSON encoding error

handleFileUpload

private void handleFileUpload(InternalEventObject ieo)
Handle a file upload event — which we don't do, so I don't handle it, but let's kick the requesting user just for safety? (TODO)

Parameters:
ieo - Internal Event Object

handleInternalEvent

public void handleInternalEvent(InternalEventObject ieo)
This is an overriding method.

Specified by:
handleInternalEvent in interface IEventListener
See Also:
IEventListener.handleInternalEvent(it.gotoandplay.smartfoxserver.events.InternalEventObject)

handleJoin

private void handleJoin(String zoneName,
                        User user,
                        Room room)
Handle (log only) an user joining a new room.

Parameters:
zoneName -
user -
room -

handleLogin

private void handleLogin(String zoneName,
                         String bigNick,
                         String password,
                         SocketChannel channel)
Process a login request from the user

Parameters:
zoneName - The name of the zone into which the user is trying to log in
bigNick - The user's requested nickname (attempted user name)
password - This is a bit of a misnomer. We actually are checking for the secret key (CHAP cookie) for the current channel, to which has been appended the user's actual password, as presented as a hex-coded SHA1 digest. (In brief: pseudocode of sha1( cookie + password ).toHex )
channel - This is the socket over which we are communicating with the prospective user

handleNewRoom

public void handleNewRoom(InternalEventObject ieo)
WRITEME: document this method (brpocock, Jul 14, 2009)

Parameters:
ieo -

handleRequest

public void handleRequest(String cmd,
                          ActionscriptObject ao,
                          User u,
                          int fromRoom)
This is an overriding method.

Specified by:
handleRequest in interface ISmartFoxExtension
See Also:
ISmartFoxExtension.handleRequest(java.lang.String, it.gotoandplay.smartfoxserver.lib.ActionscriptObject, it.gotoandplay.smartfoxserver.data.User, int)

handleRequest

public void handleRequest(String cmd,
                          org.json.JSONObject jso,
                          User u,
                          int fromRoom)
This is an overriding method.

Specified by:
handleRequest in interface ISmartFoxExtension
Overrides:
handleRequest in class AbstractExtension
See Also:
AbstractExtension.handleRequest(java.lang.String, org.json.JSONObject, it.gotoandplay.smartfoxserver.data.User, int)

handleRequest

public void handleRequest(String cmd,
                          String[] params,
                          User u,
                          int fromRoom)
This is an overriding method.

Specified by:
handleRequest in interface ISmartFoxExtension
See Also:
ISmartFoxExtension.handleRequest(java.lang.String, java.lang.String[], it.gotoandplay.smartfoxserver.data.User, int)

handleRoomLost

public void handleRoomLost(InternalEventObject ieo)
WRITEME: document this method (brpocock, Jul 14, 2009)

Parameters:
ieo -

handleServerReady

private void handleServerReady()
Once the server indicates its readiness, begin spawning auto-spawning Zones


handleSpeak

private void handleSpeak(InternalEventObject ieo)
WRITEME: document this method (brpocock, Jul 14, 2009)

Parameters:
ieo -
Throws:
org.json.JSONException

handleSpectatorSwitched

public void handleSpectatorSwitched(InternalEventObject ieo)
WRITEME: document this method (brpocock, Jul 14, 2009)

Parameters:
ieo -

handleUserLost

public void handleUserLost(InternalEventObject ieo)
WRITEME: document this method (brpocock, Jul 14, 2009)

Parameters:
ieo -

handleUserPart

public void handleUserPart(String zone,
                           Room room,
                           String uid,
                           User user,
                           String oldPlayerIndex)
WRITEME: document this method (brpocock, Jul 14, 2009)

Parameters:
zone -
room -
uid -
user -
oldPlayerIndex -

handleWhisper

private void handleWhisper(InternalEventObject ieo)
WRITEME: document this method (brpocock, Jul 14, 2009)

Parameters:
ieo -

init

public void init()
This is an overriding method.

Specified by:
init in interface ISmartFoxExtension
Overrides:
init in class AbstractExtension
See Also:
AbstractExtension.init()

sendBuddyNotice

protected void sendBuddyNotice(String buddyName,
                               boolean isOnline,
                               String roomMoniker,
                               String roomTitle,
                               User u,
                               int room)
                        throws org.json.JSONException

Sends a buddy notice message to the client

{ from: buddyNotice, status: true, notice: { buddy: name, online: boolean, room: moniker, roomName: title } }

Parameters:
buddyName -
isOnline -
roomMoniker -
roomTitle -
u -
room -
Throws:
org.json.JSONException

sendError_RAW

private void sendError_RAW(String xtnName,
                           String message,
                           SocketChannel channel)
WRITEME: document this method (brpocock, Aug 19, 2009)

Parameters:
xtnName -
message -
channel -

sendErrorReply

private void sendErrorReply(String source,
                            String error,
                            org.json.JSONObject result,
                            User u,
                            int room)
                     throws org.json.JSONException
WRITEME: document this method (brpocock, Aug 20, 2009)

Parameters:
source - The method returning the error message
error - The error message
result - The payload, if any. May be altered.
u - The user to whom to send the success reply
room - The room in which the user is standing
Throws:
org.json.JSONException

sendSuccessReply

private void sendSuccessReply(String source,
                              org.json.JSONObject resultIn,
                              User u,
                              int room)
                       throws org.json.JSONException
WRITEME: document this method (brpocock, Aug 20, 2009)

Parameters:
source - The method returning the success message
resultIn - The payload, if any. May be altered.
u - The user to whom to send the success reply
room - The room in which the user is standing
Throws:
org.json.JSONException

sendSuccessReply

private void sendSuccessReply(String source,
                              org.json.JSONObject resultIn,
                              User u,
                              int room,
                              LinkedList<SocketChannel> recipients)
                       throws org.json.JSONException
Throws:
org.json.JSONException

sendUserLists

private void sendUserLists(User u)
                    throws org.json.JSONException
Throws:
org.json.JSONException

sendUserLists

private void sendUserLists(User u,
                           User user)
                    throws org.json.JSONException
Throws:
org.json.JSONException

sendWardrobe

private void sendWardrobe(User user,
                          User u,
                          int room)
                   throws org.json.JSONException
Send a "from:wardrobe" message to the user

Parameters:
user -
u -
room -
Throws:
org.json.JSONException

spawnNewZone

public void spawnNewZone()
Create a new zone if one is needed


spawnZone

private void spawnZone(String zoneName,
                       String image)
Create a new, empty zone, and attach the default properties to it.

Parameters:
zoneName - the name of the new zone
image - the background nugget icon

uncaughtException

public void uncaughtException(Thread t,
                              Throwable e)
This is an overriding method.

Specified by:
uncaughtException in interface Thread.UncaughtExceptionHandler
See Also:
Thread.UncaughtExceptionHandler.uncaughtException(java.lang.Thread, java.lang.Throwable)