Module bzClient :: Class bzClient
[frames] | no frames]

Class bzClient

source code


This class is the main canevas for a BZoo client application object.

The Hello World program.

The simplest BZoo client.

Source:
   import bzClient
   
   login = 'MyLogin'
   password = 'MyPassword'
   
   aClient = bzClient.bzClient(hostname='127.0.0.1', port=50001, pseudo=login)
   aClient.OpenSession(login, password)
   aClient.SayMessage('Hello World')
   aClient.CloseSession()

This simple program opens a connection with the server that should be running on the local computer. Next, it opens a session and send a "Hello world" message to others. The message should appear in the chat windows of all connected people currently playing in the same scene. Finally, it closes the session with the server.

It is to be noted that in this basic example, no control is made upon connection results. Moreover, it is a very short session. The connection only last the time to say "Hello World" .

Entertaining connection.

Let's see a more complete example.

Sources:
   class ThreadClient ( threading.Thread, bzClient.bzClient ):
       
       def __init__ ( self , login, passwd):
           bzClient.bzClient.__init__(self, hostname='127.0.0.1', port=50001, pseudo=login)
           [result, reason] = self.OpenSession(login, passwd)
           print "Connection result = ", [result, reason]
           threading.Thread.__init__(self)
           self.running = False
          
       
       def run ( self ):
           self.running = True
           while (self.running == True):
              self.Pulse()
              time.sleep (0.35)

      def stop ( self ):
          self.running = False
          self.CloseConnection()

   login = 'MyLogin'
   passwd = 'MyPassword'
   client = ThreadClient(login, passwd)
   client.start ()
In practice, when using BZoo client within Blender Game engine, you don't have to deal with thread. The game engine does it for you. Thus, in a Blender game, a typical use of bzClient object could be to: Sources:
   if hasattribute(GameLogic,"BClient") == False:
       GameLogic.BClient = bzClient.bzClient(hostname='127.0.0.1', port=50001, pseudo=login)
       GameLogic.BClient.OpenSession(login, password)
       GameLogic.BClient.SayMessage('Hello World')
   else:
       GameLogic.BClient.Pulse()
The program above, when cyclically called by an always sensor, first creates a bzClient if it doesn't already exist and start a session on server. It entertains the connection with the server by periodically calling the Pulse() method of bzClient Object it it exists.

Depicting the current world situation.

The goal of the connection we depicted above is to provide a way, for a BZoo Client program, to get informed of what other client situation (their position, oritentation, their current action, and so on). Thanks to these informations, a BZoo client application can control the game engine to make it depicting the whole game context. The principle relies on a periodic exchange of information between client and server that runs in 3 steps: Information exchanges are handled and monitored by the bzClient.Pulse() function. The BZoo programmer is only in charge of providing updated information about player situation so that the reporting process can send them to the server. Typical information are: the bzClient provides method to It also provides functions to read equivalent report from other players. The two following sections describe the way to refresh player current information and The third section talks about the exchange that can occurs aperiodically

Getting information on game context

TO BE WRITTEN

Sources:
   if hasattribute(GameLogic,"BClient") == True:
       nbc = GameLogic.BClient.GetNbClients()
       print "there are %d people in this game scene"%nbc

       inventory = GameLogic.BClient.GetInventoryContent()
       print "My inventory content is : ", inventory

Updating your information on server

TO BE WRITTEN

Sources:
   if hasattribute(GameLogic,"BClient") == True:
       GameLogic.BClient.StorePosition([posX, posY, posZ])
       GameLogic.BClient.StoreScene()
The above example only shows the position updating. Similar call StorePosition() StoreOrientation() and StoreHeading()

Aperiodic exchanges

TO BE WRITTEN

Sources:
   if hasattribute(GameLogic,"BClient") == True:
   
       GameLogic.BClient.GrabObject(1, "Lamp")
       GameLogic.BClient.SayMessage("I've just grabbed a lamp!")
       
       GameLogic.BClient.ActivateObject("Door", 1)
       GameLogic.BClient.SayMessage("I've just opened the door!")

Getting closer from the protocol.

Using Network Message Handler

TO BE WRITTEN

Using System Command

TO BE WRITTEN

Extending protocol

TO BE WRITTEN

Instance Methods
bzClient
__init__(self, hostname='127.0.0.1', port=50000, pseudo='Guest')
Returns: N/A
source code
 
ActivateObjectEvent(self, values)
Handles reception of a Activate Object Message
source code
 
InitInventoryEvent(self, values)
Handles reception of a Init Inventory Message
source code
 
ClientsMessagesEvent(self, values)
Handles reception of a Clients Message
source code
 
ClientsSituationReportEvent(self, values)
Handles reception of a Clients Situation Report.
source code
 
VanishObjectEvent(self, values)
Handles reception of a Vanish Object message.
source code
 
InventoryAddEvent(self, values)
Handles reception of an Inventory Add message.
source code
 
InstanciateObjectEvent(self, values)
Handles reception of an Instanciate Object message.
source code
[Int, Int]
OpenSession(self, pseudo, password)
Open a session on the server by: sending an ACCEPT String Initialize scene, position, orientation, heading, and throw bzException.BZooConnectionError
source code
String
GetPseudo(self)
Returns: The pseudo used in the session
source code
Integer
GetId(self)
Returns: The current id for this session
source code
Integer
GetScene(self)
Returns: The number of the scene the client is in
source code
Integer
GetNbClients(self)
Give the number of clients connected to the serveur.
source code
list of tuple [Integer, String]
GetInventoryContent(self)
Gives the content of the client's inventory
source code
Integer
GetVariableValue(self, var_name)
Gives the value of player's variable 'var_name'
source code
 
StorePosition(self, position)
Give the current position of the player associated with this client.
source code
 
StoreOrientation(self, orientation)
Set the current orientation of the player associated with this client
source code
 
StoreHeading(self, heading)
Set the current heading of the player associated with this client
source code
 
StoreScene(self, scene)
Set the current scene of the player associated with this client
source code
 
StoreAction(self, action)
Set the current action of the player associated with this client
source code
 
StoreState(self, state)
Set the current state of the player associated with this client
source code
 
Pulse(self)
Performs an exchange with server.
source code
 
Say(self, message)
Send a text message to all players connected to the server
source code
 
ChooseAvatar(self, id_avatar)
Set the avatar choosen by the player
source code
 
PrivateSay(self, pseudo, message)
Send a text message to all players connected to the server
source code
 
GrabObject(self, quantity, objname)
Make the client grab an object from the scene
source code
 
DeclareVar(self, quantity, varname)
Declare a player variable onto the server.
source code
 
ReleaseObject(self, objname='Lamp', position=[0.0, 0.0, 0.0])
Make the client release an object from the scene at a given position.
source code
 
ActivateObject(self, objname, value)
Make the client activate an object from the scene
source code
 
SaveOnServer(self)
Make the client send a SAVEME command to the server
source code

Inherited from bzProtocol.bzProtocol: __repr__, addHandler, getNextDataMessage, processDataMessage

Inherited from bzConnection: CloseSession

Inherited from bzClientSocket: CloseConnection, Connect, Connected, ReceiveData, SendData

Inherited from bzPicture.bzPicture: getNbPlayers, getPlayerAction, getPlayerId, getPlayerOrientation, getPlayerPosition, getPlayerPseudo, getPlayerScene, getPlayersActions, getPlayersOrientations, getPlayersPositions, getPlayersPseudo, getPlayersScenes, popTextMessage, updateFromMessageList

Instance Variables
integer action
the current action of the player (???).
list of integer actions
list of players'current actions
list of integer avatars
list of players'avatar id
bzTools.bzDisplay display
the ????
3*3 Matrix. heading
the current heading of the player.
list of 3*3 matrix headings
list of players'headings
integer id_avatar
the number of the player's avatar
bzInventory.bzInventory inventory
the player's inventory
array of L???? message_queue
the message to be sent.
  object_activation
dictionnary of action upon object.
3*3 Matrix orientation
the current orientation of the player
list of 3*3 matrix orientations
list of players'orientations
3*1 Vector position
the current position of the player
list of 3*1 vector positions
list of players'positions
list of string pseudos
list of pseudos
integer scene
the scene the player is currently in.
list of integer scenes
list of scene player's are in.
3*1 Vector @ivar start_orientation = the start orientation start_position
the start position
integer. start_scene
the scene number to start in.
integer state
the state the player is in (???).
list of integer states
lsit of player's states

Inherited from bzProtocol.bzProtocol: HandlerTable, MessageTable

Inherited from bzConnection: id, password, pseudo

Inherited from bzClientSocket: port, receive_status, sa, servername, socket

Method Details

__init__(self, hostname='127.0.0.1', port=50000, pseudo='Guest')
(Constructor)

source code 
Parameters:
  • hostname (String.) - The server hostname or IP adress
  • port (Integer) - The port of the server to connect to
  • pseudo (Character string.) - The pseudo of the player
Returns: bzClient
N/A
Overrides: bzProtocol.bzProtocol.__init__

ActivateObjectEvent(self, values)

source code 
Handles reception of a Activate Object Message
Parameters:
  • values ([String, Integer].) - [objname, action]

InitInventoryEvent(self, values)

source code 
Handles reception of a Init Inventory Message
Parameters:
  • values ([list of [String, Integer]].) - [list of [object_name, quantity]]

ClientsMessagesEvent(self, values)

source code 
Handles reception of a Clients Message
Parameters:
  • values ([String, String].) - [pseudo, message]

ClientsSituationReportEvent(self, values)

source code 
Handles reception of a Clients Situation Report.
Parameters:
  • values ([ Int[],String[], Vector[], Matrix[], Matrix[], Int[], Int[], Int[], Int[]].) - [ ids, pseudos, positions, orientations, headings, states, actions, scenes, avatars]

VanishObjectEvent(self, values)

source code 
Handles reception of a Vanish Object message. DO NOTHING !!
Parameters:
  • values ([ String].) - [ obj_name]

InventoryAddEvent(self, values)

source code 
Handles reception of an Inventory Add message.
Parameters:
  • values ([ Int, String].) - [ quantity, obj_name]

InstanciateObjectEvent(self, values)

source code 
Handles reception of an Instanciate Object message. DO NOTHING !!
Parameters:
  • values ([ Int, String].) - [ quantity, obj_name]

OpenSession(self, pseudo, password)

source code 
Open a session on the server by: sending an ACCEPT String Initialize scene, position, orientation, heading, and throw bzException.BZooConnectionError
Parameters:
  • pseudo (String.) - the login to use for this session.
  • password (String.) - the password.
Returns: [Int, Int]
[result, reason]
Overrides: bzConnection.OpenSession

GetPseudo(self)

source code 
Returns: String
The pseudo used in the session

GetId(self)

source code 
Returns: Integer
The current id for this session

GetScene(self)

source code 
Returns: Integer
The number of the scene the client is in

GetNbClients(self)

source code 
Give the number of clients connected to the serveur.
Returns: Integer
The number of people connected to the server

GetInventoryContent(self)

source code 
Gives the content of the client's inventory
Returns: list of tuple [Integer, String]
the client's inventory (list of [Quantity, ObjectType])

GetVariableValue(self, var_name)

source code 
Gives the value of player's variable 'var_name'
Parameters:
  • var_name (String.) - the name of the variable.
Returns: Integer
the client's inventory (list of [Quantity, ObjectType])

StorePosition(self, position)

source code 
Give the current position of the player associated with this client. This position is the one that is sent. This function must be periodically called to inform other players of the player's current position
Parameters:
  • position (3*1 Vector) - The current position of the Player

StoreOrientation(self, orientation)

source code 

Set the current orientation of the player associated with this client

This orientation is the one that is sent to other clients

This function must be periodically called to inform other players of the player's current orientation
Parameters:
  • orientation (3*3 Matrix) - The current orientation of the Player

StoreHeading(self, heading)

source code 

Set the current heading of the player associated with this client

This orientation is the one that is sent to other clients

This function must be periodically called to inform other players of the player's current heading
Parameters:
  • heading (3*3 Matrix) - The current heading of the Player

StoreScene(self, scene)

source code 

Set the current scene of the player associated with this client

This orientation is the one that is sent to other clients

This function must be periodically called to inform other players of the player's current scene
Parameters:
  • scene (Integer) - The current scene of the Player

StoreAction(self, action)

source code 

Set the current action of the player associated with this client

This action is the one that is sent to other clients

This function must be periodically called to inform other players of the player's current action
Parameters:
  • action (Integer) - The current action of the Player

StoreState(self, state)

source code 

Set the current state of the player associated with this client

This state is the one that is sent to other clients

This function must be periodically called to inform other players of the player's current state
Parameters:
  • state (Integer) - The current state of the Player

Pulse(self)

source code 

Performs an exchange with server.

Player send information about his position and orientation and collect other client's information from server This function must be periodically called (at each game TIC)

Say(self, message)

source code 
Send a text message to all players connected to the server
Parameters:
  • message (String) - The message to be sent to other players

ChooseAvatar(self, id_avatar)

source code 

Set the avatar choosen by the player

This function is called when player choose is avatar
Parameters:
  • id_avatar (Integer) - The id of the choosen avatar

PrivateSay(self, pseudo, message)

source code 
Send a text message to all players connected to the server
Parameters:
  • pseudo (String) - The pseudo of the player to sent the message to
  • message (String) - The message to be sent to other players

GrabObject(self, quantity, objname)

source code 
Make the client grab an object from the scene
Parameters:
  • quantity (String) - The quantity of grabbed object
  • objname (String) - The name of the grabbed object

DeclareVar(self, quantity, varname)

source code 
Declare a player variable onto the server. It is used to inform the server of a variable that has to be dealt with for this player "Health", "Strength", ...
Parameters:
  • quantity (Int) - The initialisation value of variable
  • varname (String) - The name of the variable

ReleaseObject(self, objname='Lamp', position=[0.0, 0.0, 0.0])

source code 
Make the client release an object from the scene at a given position.
Parameters:
  • objname (String) - The name of the released object
  • position (String) - The location where the object is released

ActivateObject(self, objname, value)

source code 
Make the client activate an object from the scene
Parameters:
  • objname (String) - The name of the activated object
  • value (Integer) - The activation value