_server.createRoom()

Availability:

SmartFoxServer PRO 1.4.0 / Refactored in version 1.4.5

Usage:

Version 1.4.0:
_server.createRoom(roomObj, user, sendUpdate, broadcastEvt)

Version 1.4.5 and higher:
_server.createRoom(roomObj, user, sendUpdate, broadcastEvt, roomVars, varsOwner, setOwnership)

Description:

Creates a new room.

Properties:

roomObj  

an object describing the room properties. The following is a list of available properties:

name   the room name
pwd   the room password (optional)
maxU   max number of users
maxS   max number of spectators (optional for game rooms)
isGame   a boolean flag. If true the room is a game room
isLimbo   a boolean flag. If true the game will be of type Limbo
uCount   a boolean flag. If true the room will receive the uCount update messages.
xtName   The name that will be used to reference the extension once attached to the room
xtClass   The name of the class (Java) or script (Actionscript) to load as extension.
The file extension should only be specified for Actionscript files (.as)
If you are loading a java class, use the class name without the ".class" extension.

For more info on the room configuration, please check this page
user   the User object of the client who is creating the room.
If user is null the room will be "owned" by the Server and it will persist during all the server activity
sendUpdate   (optional) a boolean flag. By default it is set to true.
If false the server won't send an update to the clients notifying the creation of the new room
broadcastEvt   (optional) a boolean flag. By default set to true. Used for broadcasting the server internal event that notifies the creation of a new room
roomVars  

a list of objects representing each variable. Each object has the following properties:

name   the variable name
val   variable value (null to delete an existing variable)
priv   true if the variable is private
persistent   true if the variable is persistent (will continue to exist when the user goes to another room. It is destroyed when the user closes the connection)

varsOwner   the User who owns the variables (null for Server owned variables)
setOwnership   (optional) a boolean flag. By deafult is set to true. Set it to false to avoid to change the ownership of the variable(s)

Returns:

the new Room object. If null is returned an error occured.

Example #1:

Create a room with a max of 25 users

/*
* Create a new room owned by the server itself
*/

var roomObj = {}
roomObj.name = "A new Room"
roomObj.maxU = 25

var newRoom = _server.createRoom(roomObj, null)

if (newRoom != null)
	trace("Great the room was created")
else
	trace("A problem occurred, better check the server logs")


Example #2:

Create a game room with many different variables

/*
* Create a new game room owned by the server
*/

// --- Room params -------------------------
var roomObj = {}
roomObj.name = "TheGameRoom"
roomObj.maxU = 10
roomObj.isGame = true

// --- Vars --------------------------------
roomVars = 	[
				{name:"Manufacturer", val:"Commodore", priv:true, persistent:true},
				{name:"Model", val:"C64", priv:true, persistent:false},
				{name:"CPU", val:"Motorola 6502", priv:true, persistent:true},
				{name:"RAM", val:64, priv:true, persistent:true},
				{name:"8-Bit", val:true, priv:false, persistent:true},
			]

theRoom = _server.createRoom(roomObj, null, true, true, roomVars)

if (theRoom != null)
	trace("Room Created Successfully")
else
	trace("OUCH! Room was not created!!!")

See also: