it.gotoandplay.smartfoxserver.data
Class Room

java.lang.Object
  extended by it.gotoandplay.smartfoxserver.data.Room

public class Room
extends java.lang.Object

The Room object is responsible for grouping logged users together allowing them to interact with each other and providing high level services such as Room Variables, user count updates, public and private messaging and a lot more.

For a detailed overview of the Room types and features check this tutorial.

Author:
(c) 2004-2007 gotoAndPlay() -- www.gotoandplay.it

Field Summary
 java.util.Map properties
           
 
Constructor Summary
Room(java.lang.String name, int maxUsers, boolean isTemp, boolean isGame, boolean isPrivate, java.lang.String password, java.lang.String zone)
          Full Constructor
Room(java.lang.String name, int maxUsers, boolean isTemp, java.lang.String zone)
          Basic Constructor
 
Method Summary
 boolean contains(java.lang.String name)
          Check if the room contains a certain user
 boolean deleteVariable(java.lang.String vName, User owner)
           
 void destroyExtensions()
          Destroy all extensions for this room
 User[] getAllPlayers()
          Return an array of players (for game rooms)
 User[] getAllSpectators()
          Return an array of all spectators in this room
 User[] getAllUsers()
          Get all the users in the Room
 User[] getAllUsersButOne(java.lang.Integer excludedUserId)
          Get an array of Users excluding the one passed to the function This can be useful when you need to broadcast a message to all people in the room except for the one who sent the request to the server.
 User[] getAllUsersButOne(User excludedUser)
          Get an array of Users excluding the one passed to the function This can be useful when you need to broadcast a message to all people in the room except for the one who sent the request to the server.
 java.util.LinkedList getChannellList()
          Get a list of the SocketChannels in this room
 java.nio.channels.SocketChannel getCreator()
           
 it.gotoandplay.smartfoxserver.extensions.ExtensionManager getExtManager()
           
 int getId()
          Get room id
 int getMaxSpectator()
           
 int getMaxUsers()
          Get the max number of users allowed
 java.lang.String getName()
          getName()
 java.lang.String getPassword()
          Get the optional room password
 int getSpectatorCount()
           
 java.lang.Object[] getSpectatorList()
          Get an array of spectators in this room
 boolean getUcountUpdates()
          Get the status of the "uCount" server updates
 User getUserByName(java.lang.String userName)
          Get a user from its name
 User getUserByPlayerIndex(int pid)
          Return a player by its player id
 int getUserCount()
           
 java.lang.Object[] getUserList()
          Return an array of users
 RoomVariable getVariable(java.lang.String varName)
          Get a room variable
 java.util.LinkedList getVariableNames()
           
 java.util.HashMap getVariables()
          Get a map of variables
 java.lang.String getXmlUserList()
           
 java.lang.String getXmlVariable(java.lang.String varName)
           
 java.lang.String getXmlVarList()
           
 java.lang.String getZone()
          Get the parent zone
 int howManyUsers()
           
 boolean isGame()
           
 boolean isLimbo()
           
 boolean isPrivate()
           
 boolean isTemp()
           
 void join(User u, java.lang.String pwd, boolean isSpectator)
           
 boolean removeUser(User u, boolean updateUserRoomList, boolean destroyVars)
           
static void resetRoomStaticData()
          Reset the autoId when the server is restarted
 void setCreator(java.nio.channels.SocketChannel ch)
           
 void setGame()
          Set as a game room
 void setLimbo(boolean isLimbo)
           
 void setMaxSpectators(int s)
          Set the max number of spectators
 void setName(java.lang.String name)
          setName()
 void setPassword(java.lang.String pw)
          Set the room password
 void setUcountUpdates(boolean b)
          Turn on/off the "uCount" server updates
 boolean setVariable(java.lang.String vn, java.lang.String vt, java.lang.String vv, boolean pr, boolean ps, User owner, boolean setOwnership)
           
 boolean switchPlayer(User u)
           
 int switchSpectator(User u)
           
 void updateUserCount()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

properties

public java.util.Map properties
Constructor Detail

Room

public Room(java.lang.String name,
            int maxUsers,
            boolean isTemp,
            java.lang.String zone)
Basic Constructor

Parameters:
name - = room name
maxUsers - = max number of users allowed
isTemp - = marks the room as temporary if = true

Room

public Room(java.lang.String name,
            int maxUsers,
            boolean isTemp,
            boolean isGame,
            boolean isPrivate,
            java.lang.String password,
            java.lang.String zone)
Full Constructor

Parameters:
name - the room name
maxUsers - max number of users allowed in the room
isTemp - temp room
isGame - game room
isPrivate - private room
password - an optional password
zone - the zone name
Method Detail

destroyExtensions

public void destroyExtensions()
Destroy all extensions for this room


switchSpectator

public int switchSpectator(User u)

switchPlayer

public boolean switchPlayer(User u)

setMaxSpectators

public void setMaxSpectators(int s)
Set the max number of spectators

Parameters:
s -

getMaxSpectator

public int getMaxSpectator()
Returns:
the max number of spectators

setUcountUpdates

public void setUcountUpdates(boolean b)
Turn on/off the "uCount" server updates

Parameters:
b -

getUcountUpdates

public boolean getUcountUpdates()
Get the status of the "uCount" server updates

Returns:
the flag

getExtManager

public it.gotoandplay.smartfoxserver.extensions.ExtensionManager getExtManager()

join

public void join(User u,
                 java.lang.String pwd,
                 boolean isSpectator)
          throws it.gotoandplay.smartfoxserver.exceptions.JoinRoomException
Throws:
it.gotoandplay.smartfoxserver.exceptions.JoinRoomException

getXmlUserList

public java.lang.String getXmlUserList()

getUserList

public java.lang.Object[] getUserList()
Return an array of users


getUserByName

public User getUserByName(java.lang.String userName)
Get a user from its name

Parameters:
userName - the user name
Returns:
the user object
Since:
1.6.3-M6

getSpectatorList

public java.lang.Object[] getSpectatorList()
Get an array of spectators in this room

Returns:
an array of spectators
Since:
1.5.7

getAllUsers

public User[] getAllUsers()
Get all the users in the Room

Returns:
an array of Users

getAllUsersButOne

public User[] getAllUsersButOne(User excludedUser)
Get an array of Users excluding the one passed to the function This can be useful when you need to broadcast a message to all people in the room except for the one who sent the request to the server.

Parameters:
excludedUser - the User object
Returns:
an array of Users excluding the one specified
Since:
1.5.8

getAllUsersButOne

public User[] getAllUsersButOne(java.lang.Integer excludedUserId)
Get an array of Users excluding the one passed to the function This can be useful when you need to broadcast a message to all people in the room except for the one who sent the request to the server.

Parameters:
excludedUserId - the user to exclude (int id)
Returns:
the array of users, except the one passed
Since:
1.5.8

getAllPlayers

public User[] getAllPlayers()
Return an array of players (for game rooms)

Returns:
an array of players in this room
Since:
1.5.6

getAllSpectators

public User[] getAllSpectators()
Return an array of all spectators in this room

Returns:
array of spectators
Since:
1.5.6

getUserByPlayerIndex

public User getUserByPlayerIndex(int pid)
Return a player by its player id

Parameters:
pid - the player id
Returns:
the user

getXmlVarList

public java.lang.String getXmlVarList()

getXmlVariable

public java.lang.String getXmlVariable(java.lang.String varName)

getVariableNames

public java.util.LinkedList getVariableNames()

getVariables

public java.util.HashMap getVariables()
Get a map of variables

Returns:
the HashMap with the variables

getVariable

public RoomVariable getVariable(java.lang.String varName)
Get a room variable

Parameters:
varName - the name of the variable
Returns:
the variable

getId

public int getId()
Get room id

Returns:
the id

getZone

public java.lang.String getZone()
Get the parent zone

Returns:
the zone name

getPassword

public java.lang.String getPassword()
Get the optional room password

Returns:
the password

getChannellList

public java.util.LinkedList getChannellList()
Get a list of the SocketChannels in this room

Returns:
a LinkedList of Channels for all users in this room

getName

public java.lang.String getName()
getName()

Returns:
the room name

setName

public void setName(java.lang.String name)
setName()

Parameters:
name - the name of the room

isPrivate

public boolean isPrivate()
Returns:
isPrivate flag

isTemp

public boolean isTemp()
Returns:
isTemp flag

isGame

public boolean isGame()
Returns:
isGame flag

setGame

public void setGame()
Set as a game room


setPassword

public void setPassword(java.lang.String pw)
Set the room password

Parameters:
pw - the password

getMaxUsers

public int getMaxUsers()
Get the max number of users allowed

Returns:
the max number

getUserCount

public int getUserCount()
Returns:
The number of clients in this room

getSpectatorCount

public int getSpectatorCount()
Returns:
the number of spectators in the room

removeUser

public boolean removeUser(User u,
                          boolean updateUserRoomList,
                          boolean destroyVars)

setVariable

public boolean setVariable(java.lang.String vn,
                           java.lang.String vt,
                           java.lang.String vv,
                           boolean pr,
                           boolean ps,
                           User owner,
                           boolean setOwnership)

deleteVariable

public boolean deleteVariable(java.lang.String vName,
                              User owner)

updateUserCount

public void updateUserCount()

howManyUsers

public int howManyUsers()

setCreator

public void setCreator(java.nio.channels.SocketChannel ch)

getCreator

public java.nio.channels.SocketChannel getCreator()

contains

public boolean contains(java.lang.String name)
Check if the room contains a certain user

Parameters:
name - the user name
Returns:
true if the user was found

resetRoomStaticData

public static void resetRoomStaticData()
Reset the autoId when the server is restarted


isLimbo

public boolean isLimbo()
Returns:
Returns the isLimbo.

setLimbo

public void setLimbo(boolean isLimbo)
Parameters:
isLimbo - The isLimbo to set.