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:
-
Create an object with an allways sensor
-
Attach this sensor to a Python controller with the following
content:
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:
-
The client reports his situation to the server.
-
Server, as a reply, gives it the report of other client
situation.
-
The client update scene content in the game engine.
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:
-
Current position
-
Current orientation
-
Current heading
-
Current status
-
Current action
-
Current visited scene
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
|
bzClient
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[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
|
|
|
Integer
|
|
|
Integer
|
|
|
Integer
|
|
|
list of tuple [Integer, String]
|
|
|
Integer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Say(self,
message)
Send a text message to all players connected to 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
|
|
|
|
|
|
|
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
|
|
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
|
__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__
|
Handles reception of a Activate Object Message
- Parameters:
values ([String, Integer].) - [objname, action]
|
Handles reception of a Init Inventory Message
- Parameters:
values ([list of [String, Integer]].) - [list of [object_name, quantity]]
|
Handles reception of a Clients Message
- Parameters:
values ([String, String].) - [pseudo, message]
|
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]
|
Handles reception of a Vanish Object message. DO NOTHING !!
- Parameters:
values ([ String].) - [ obj_name]
|
Handles reception of an Inventory Add message.
- Parameters:
values ([ Int, String].) - [ quantity, obj_name]
|
Handles reception of an Instanciate Object message. DO NOTHING !!
- Parameters:
values ([ Int, String].) - [ quantity, obj_name]
|
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
|
- Returns: String
- The pseudo used in the session
|
- Returns: Integer
- The current id for this session
|
- Returns: Integer
- The number of the scene the client is in
|
Give the number of clients connected to the serveur.
- Returns: Integer
- The number of people connected to the server
|
Gives the content of the client's inventory
- Returns: list of tuple [Integer, String]
- the client's inventory (list of [Quantity, ObjectType])
|
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])
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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)
|
Send a text message to all players connected to the server
- Parameters:
message (String) - The message to be sent to other players
|
|
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
|
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
|
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
|
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
|
Make the client activate an object from the scene
- Parameters:
objname (String) - The name of the activated object
value (Integer) - The activation value
|