mainLib::_Server Class Reference

List of all members.

Public Member Functions

def __init__
 Default constructor.
def addBuddy
def createRoom
def destroyRoom
def disconnectUser
def dispatchPublicMessage
def dispatchPrivateMessage
def getCurrentZone
def getCurrentRoom
def getDatabaseManager
def getGuestName
def getSecretKey
def getTimer
def getUserById
def getUserByChannel
def getZone
def joinRoom
def leaveRoom
def loginUser
def logoutUser
def md5
def sendGenericMessage
def removeBuddy
def removeUser
def requestAddBuddyPermission
def sendBuddyListUpdate
def sendMail
def sendResponse
def sendRoomList
def setBuddyVariables
def setBuddyBlockStatus
def setRoomVariables
def setUserVariables
def switchSpectator
def trace


Detailed Description

Server Class: This is the main framework object that allows access to the server core functionalities

Member Function Documentation

def mainLib::_Server::addBuddy (   self,
  buddyName,
  user 
)

Add a buddy to a user's buddy list

Parameters:
buddyName the name of the buddy
user the buddy list owner
Since:
1.6.0

def mainLib::_Server::createRoom (   self,
  paramObj,
  user = None,
  roomVars = None,
  varsOwner = None,
  setOwnership = False,
  sendUpdate = True,
  broadcast = True 
)

Dynamically create a room

Parameters:
paramObj a dictionary with room properties
user the creator (None by default == owned by the server itself)
roomVars a list of roomVars to set (by default = None)
varsOwner the owner of the room variables being created/modified
setOwnership the roomVars setOwnership flag
sendUpdate send default update to clients
broadCast broadcast internal event

def mainLib::_Server::destroyRoom (   self,
  zone,
  roomId 
)

Destroy a server room

Parameters:
zone the zone object
roomId the id of the room to destroy

def mainLib::_Server::disconnectUser (   self,
  user 
)

Disconnect a user

Parameters:
user the user to be disconnected

def mainLib::_Server::dispatchPublicMessage (   self,
  message,
  room,
  user 
)

Dispatches a public message (after a "pubMsg" internal event)

Parameters:
message the message
room the target room
user the sender user

def mainLib::_Server::dispatchPrivateMessage (   self,
  message,
  room,
  sender,
  recipient 
)

Dispatches a private message (after a "privMsg" internal event)

Parameters:
message the message
room the target room
sender the sender user
recipient the recipient user

def mainLib::_Server::getCurrentZone (   self  ) 

Get the current extensions zone

Returns:
the current zone

def mainLib::_Server::getCurrentRoom (   self  ) 

Get the room to which the extension is attached to ( note: this is valid only for Room-Level extensions )

Returns:
the current Room

def mainLib::_Server::getDatabaseManager (   self,
  zoneName = None 
)

Get the database manager object (if configured in the current Zone)
( see more details in the javadoc -> DbManager Class )

Returns:
the DbManager instance

def mainLib::_Server::getGuestName (   self  ) 

Get a guest user name
returns an auto-generated guest user name in the form guest_x where x is a progressive integer.

Returns:
the guest user name

def mainLib::_Server::getSecretKey (   self,
  channel 
)

Get the user/channel random key
This key is unique for each user session and it used to perform a secure login. You learn more about this in the tutorial at chapter 8.9 of the documentation

Returns:
the secret key

def mainLib::_Server::getTimer (   self  ) 

Return current time in milliseconds

Returns:
current time

def mainLib::_Server::getUserById (   self,
  uid 
)

Get a user from its user id

Returns:
the User object

def mainLib::_Server::getUserByChannel (   self,
  channel 
)

Get a user from its socket channel

Returns:
the User object

def mainLib::_Server::getZone (   self,
  zoneName 
)

Get a Zone object from its name

Returns:
the Zone object

def mainLib::_Server::joinRoom (   self,
  user,
  currRoomId,
  leaveRoom,
  newRoomId,
  pwd = "",
  isSpec = False,
  broadcast = True 
)

Join a Room

Parameters:
user the user
currRoomId the current room in which the user is already joined ( -1 = no room )
leaveRoom if True the user will leave the current room
user newRoomId the room id of the room you want to join
pwd an optional password, if the room is private
isSpec True = join as Spectator ( must be a game room )
broadcast True = broadcast the event to the users in the target room
Exceptions:
it.gotoandplay.smartfoxserver.exceptions.JoinException 

def mainLib::_Server::leaveRoom (   self,
  user,
  roomId,
  broadcastAll = True 
)

Leave a room (for users in two or more rooms at the same time)
Note: it won't work if the user is joined in one room only

def mainLib::_Server::loginUser (   self,
  nick,
  pwd,
  chan 
)

Login User

Parameters:
nick the user nickname
pwd the user password (can be empty)
chan the client SocketChannel
Exceptions:
it.gotoandplay.smartfoxserver.exceptions.LoginException 

def mainLib::_Server::logoutUser (   self,
  user,
  fireClientEvt = True,
  fireInternalEvt = True 
)

Logout User

Parameters:
user the user
fireClientEvt True = fire event to other clients
fireInternalEvt True = fire an internal event, so extensions will be notified

def mainLib::_Server::md5 (   self,
  strValue 
)

Get MD5 hash

Parameters:
strValue a string
Returns:
an MD5 hex hash of the passed string

def mainLib::_Server::sendGenericMessage (   self,
  msg,
  sender,
  recipients 
)

Sends a generic Message
With this method you can send an arbitrary message, for example a modified version of a room list.
Note: The generic message implies that you send also the message header, so a good knowledge of the SFS Xml protocol is required.

Parameters:
msg the message
sender the sender User ( None = the server )
recipients a list of recipients

def mainLib::_Server::removeBuddy (   self,
  buddyName,
  user 
)

Removes a buddy from a user buddy list

If mutualRemoveBuddy is activated both users will be removed to their respective buddy lists.

Parameters:
buddyName the name of the buddy to remove
user the owner of the buddy list
Since:
1.6.0

def mainLib::_Server::removeUser (   self,
  who 
)

Removes a user from the server, disconnecting him

Parameters:
who the user

def mainLib::_Server::requestAddBuddyPermission (   self,
  sender,
  targetUserName,
  optionalMessage = None 
)

Requests permission for adding the target user in the sender buddy list.

This is already done by default if the security mode of the buddy list is set to ADVANCED. In most of the cases you wouldn't need to call this method in your extension.

It could be used to implement an off-line permission request system, where the system stores the requests for off-line users in a database and sends the requests as soon as the target user logs in.

Parameters:
sender the requester
targetUserName the name of the target user
optionalMessage an optional text message for the request.
Since:
1.6.0

def mainLib::_Server::sendBuddyListUpdate (   self,
  user 
)

Send a buddy list update.

Send an update about the specified User to all clients that have him/her in their buddy list.
Normally you don't need to call this method. Updates are sent automatically when needed.
You may need to force an update if you're manipulating the buddy lists without using the regular commands (add, remove, etc...)

Parameters:
user the user that should be updated
Since:
1.6.0

def mainLib::_Server::sendMail (   self,
  fromName,
  to,
  subject,
  message 
)

Send an Html formatted email

Parameters:
fromName the sender name
to the recipient email address
subject the email subject
message the email html message
Returns:
True if email was sent successfully

def mainLib::_Server::sendResponse (   self,
  resObj,
  fromRoom,
  who,
  recipientList,
  msgType = "xml" 
)

Send an Extension Response/Message to the client(s)

The resObj object is a dictionary containing any number of properties (strings, numbers, lists, dictionaries) that should be sent to the client(s)

Dictionaries and lists can be nested to create complex data structures, which are supported  by xml and json formats. If you use the str format you will need to pass an array of strings.

Parameters:
resObj the response object
fromRoom an optional room id ( -1 if not needed )
who the sender ( None if not needed )
recipientList a list of recipients
msgType the type of message -> can be "xml", "json", "str"

def mainLib::_Server::sendRoomList (   self,
  who 
)

Send Room List

Parameters:
who the recipient User

def mainLib::_Server::setBuddyVariables (   self,
  user,
  varDict 
)

Set the buddy variables of the specified user.

The variables dictionary should contain all the variables to set, where the key and value are strings

Since version 1.6.0 you can set off-line buddy variables by using a '$' sign as the first character of the variable name.

Since:
1.6.0
Parameters:
user the User
variables a map containing the variables to set

def mainLib::_Server::setBuddyBlockStatus (   self,
  user,
  buddyName,
  isBlocked 
)

Blocks / unblocks a buddy in the user's buddy list When the isBlocked flag is set to true the buddy won't be able to send any messages to the user.

Parameters:
user the owner of the buddy list
buddyName the name of the buddy to block / unblock
isBlocked the status (true == blocked)
Since:
1.6.0

def mainLib::_Server::setRoomVariables (   self,
  room,
  who,
  varList,
  setOwnership = True,
  broadcastAll = True 
)

Set Room Variables

For further informations about Room Variables check the examples and tutorials coming with SmartFoxServer PRO

The varList argument is a list of RoomVariable instances

Parameters:
room the target Room object
who the user, owner of the variables ( None = Server )
varList a list of variables
setOwnership if True will change the ownership of the variables to the user passed in the who argument
broadcastAll if True will send an update to the other clients in the target Room

def mainLib::_Server::setUserVariables (   self,
  who,
  varMap,
  broadcastAll = True 
)

Set User Variables

Set one or more User Variables. The varMap argument is a dictionary containing any number of number, string or boolean values.

Parameters:
who the target User
varMap a dictionary of variables
broadcastAll if True will send an update to the other users in Room

def mainLib::_Server::switchSpectator (   self,
  user,
  roomId,
  broadcastAll = True 
)

Switch a spectator into a player, if possible

Parameters:
user the user to switch (must be a spectator)
roomId the Room in which the user is joined (must be a game room)
broadcastAll if True, sends and update to all other clients in the Room

def mainLib::_Server::trace (   self,
  msg 
)

Trace a message to the console and AdminTool (if feature is active)

Parameters:
msg a text message


Generated on Wed Dec 12 11:08:29 2007 for Server side Python doc by  doxygen 1.5.4