This is minimal Python bindings of the SmartFox c++ client API. It does not contains all possible functionality of the client application, but only one that used in Two World project game, server sources, client-server communication guide (on Russian)
Accept the following events:
CONNECTION
CONNECTION_LOST
LOGIN
ROOM_JOIN
USER_VARIABLES_UPDATE
MMOITEM_VARIABLES_UPDATE
PROXIMITY_LIST_UPDATE
EXTENSION_RESPONSE
ADMIN_MESSAGE
PUBLIC_MESSAGE
PRIVATE_MESSAGE
All data from events packed into DataContainer
- special class that can contains the following items:
SFSObject
User
MMOItem
Import and client class instance
import SFSCommunicator as sfs
client = sfs.SFSClient()
Then in any non-blocking loop call update
datas_list = client.update()
datas_list
is a list of DataContainer
s with data, received from events. To obtain event title, for which each container d
is created
e_name = d.get_event_name()
e_name
is one of the following strings:
connection
forCONNECTION
eventconnection_lost
forCONNECTION_LOST
eventlogin
forLOGIN
eventjoin_room
forROOM_JOIN
eventuser_update
forUSER_VARIABLES_UPDATE
eventmmoitem_update
forMMOITEM_VARIABLES_UPDATE
eventproximity_update
forPROXIMITY_LIST_UPDATE
eventextension
forEXTENSION_RESPONSE
eventadmin_message
forADMIN_MESSAGE
eventpublic_message
forPUBLIC_MESSAGE
eventprivate_message
forPRIVATE_MESSAGE
event
For different event container contains different set of data. For example, if container corresponds to EXTENSION_RESPONSE
event, then we can get the name of the external command by
cmd = d.get_command()
Then we can get data from corresponding SFSObject
by using methods
d.get_int(key)
d.get_byte(key)
d.get_float(key)
d.get_fouble(key)
d.get_bool(key)
d.get_string(key)
d.get_double_array(key)
d.get_sfs_array(key)
If the data event contains user (as, for example, in USER_VARIABLES_UPDATE
), then we can obtain user variables by using methods
d.get_user_string(key)
d.get_user_int(key)
d.get_user_float(key)
d.get_user_double(key)
d.get_user_bool(key)
Also we can use d.get_user_id()
to obtain Id of the stored user.
Similar for MMOItems
d.get_mmoitem_string(key)
d.get_mmoitem_int(key)
d.get_mmoitem_float(key)
d.get_mmoitem_double(key)
For PROXIMITY_LIST_UPDATE
the container stores lists for users and mmo-items. We can get it by using
add_user_list = d.get_list_add_users()
remove_user_list = d.get_list_remove_users()
add_mmoitem_list = d.get_list_add_mmoitems()
remove_mmoitem_list = d.get_list_remove_mmoitems()
This Python module were used in TwoWorlds bot.