Proxy - KBEngine base

KBEngine API

KBEngine

Proxy class

[KBEngine module]

Proxy is part of the KBEngine module. More...

import KBEngine

Parent

Entity

Member function

def disconnect( self ):
def getClientType( self ):
def getClientDatas( self ):
def giveClientTo( self, proxy ):
def streamFileToClient( self, resourceName, desc="", id=-1 ):
def streamStringToClient( self, data, desc="", id=-1 ):

Callbacks

def onClientDeath( self ):
def onClientGetCell( self ):
def onClientEnabled( self ):
def onGiveClientToFailure( self ):
def onLogOnAttempt( self, ip, port, password ):
def onStreamComplete( self, id, success ):

Attributes

__ACCOUNT_NAME__  Read-only string
__ACCOUNT_PASSWORD__  Read-only string
clientAddr  Read-only
clientEnabled  Read-only bool
hasClient  Read-only bool
roundTripTime  Read-only
timeSinceHeardFromClient  Read-only

A detailed description

A Proxy is a special type of Entity. It inherits from Entity and has an associated client. By itself, it is a proxy client entity that handles all server-to-client updates. Cannot create Proxy class objects directly script.

Member functions documentation

def disconnect( self ):

Disconnect the client.

def getClientType( self ):

Function description:

This function returns the client type.

returns:

UNKNOWN_CLIENT_COMPONENT_TYPE = 0,
CLIENT_TYPE_MOBILE = 1, // Mobile phone
CLIENT_TYPE_WIN = 2, // PC, typically EXE clients
CLIENT_TYPE_LINUX = 3 // Linux Application program
CLIENT_TYPE_MAC = 4 // Mac Application program
CLIENT_TYPE_BROWSER = 5, // Web applications, HTML5, Flash
CLIENT_TYPE_BOTS = 6, // bots
CLIENT_TYPE_MINI = 7, // Mini-Client
CLIENT_TYPE_END = 8 // end

def getClientDatas( self ):

Function description:

This function returns the data attached to the client when logging in and registering.
This data can be used to expand the operating system. If a third-party account service is connected, this data is sent to the third-party service system through the interfaces process.

returns:

tuple, a tuple of 2 elements (login data bytes, registration data bytes), the first element is the datas parameter passed in when the client invokes the login, and the second element is passed in when the client registers. Since they can store arbitrary binary data, they all exist as bytes.

def giveClientTo( self, proxy ):

Function description:

The client's controller is transferred to another Proxy, the current Proxy must have a client and the target Proxy must have no associated client, otherwise it will cause an error.

See also:

Proxy.onGiveClientToFailure

parameters:

proxy Control will be transferred to this entity.

def streamFileToClient( self, resourceName, desc="", id=-1 ):

Function description:

This function is similar to streamStringToClient() and sends a resource file to the client. The sending process operates on different threads so it does not compromise the main thread.

See also:

Proxy.onStreamComplete

parameters:

resourceName The name of the resource to send, including the path.
desc An optional string that describes the resource sent to the client.
id A 16-bit id whose value depends entirely on the caller. If the incoming -1 system will select an unused id in the queue. The client can make resource judgments based on this id.

returns:

The id associated with this download.

def streamStringToClient( self, data, desc="", id=-1 ):

Function description:

Sends some data to the client bound to the current entity. If the client port data is cleared, this function can only be called when the client binds to the entity again. The 16-bit id is entirely up to the caller.
If the caller does not specify this ID then the system will allocate an unused id. The client can make resource judgments based on this id.

You can define a callback function (onStreamComplete) in a Proxy-derived class. This callback function is called when all data is successfully sent to the client or when the download fails.

See also: Proxy.onStreamComplete, client Entity.onStreamDataStarted, Entity.onStreamDataRecv, and Entity.onStreamDataCompleted.

parameters:

data The string to send
desc An optional description string sent.
id A 16-bit id whose value depends entirely on the caller. If the incoming -1 system will select an unused id in the queue.

returns:

The id associated with this download.


Callback functions documentation

def onClientDeath( self ):

If this callback is implemented in a script, this method will be called when the client disconnects. This method has no parameters.

def onClientGetCell( self ):

If this callback is implemented in a script, the callback is called when the client can call the entity's cell attribute

def onClientEnabled( self ):

If this callback is implemented in the script, it is invoked when the entity is available (various initializations and communication with the client). This method has no parameters.
Note: giveClientTo also assigns control to the entity and causes the callback to be called.

def onGiveClientToFailure( self ):

If this callback is implemented in a script, it is called when the entity fails to call giveClientTo. This method has no parameters.

def onLogOnAttempt( self, ip, port, password ):

If this callback is implemented in a script, it is invoked when a client attempts to log in using the current account entity.
This situation usually happens when the entity that exists in memory is in a valid state, the most obvious example is user A logs in with this account, and user B tries to use the same account to log in, triggering this callback.

This callback function can return the following constant values:
KBEngine.LOG_ON_ACCEPT: Allows the new client to bind to the entity. If the entity has bound a client, the previous client will be kicked out.
KBEngine.LOG_ON_REJECT: Reject new client entity binding.

KBEngine.LOG_ON_WAIT_FOR_DESTROY: Wait for the entity to be destroyed before the client binds.

parameters:

ip  The IP address of the client trying to log in.
port  The port to which the client attempted to log in.
password  The MD5 password used when the user logs in.

def onStreamComplete( self, id, success ):

If you implement this callback in a script, when a user uses Proxy.streamStringToClient() or Proxy.streamFileToClient() and is completed, this callback is invoked.

parameters:

id  The id associated with the download.
success  Success or failure


Attributes documentation

__ACCOUNT_NAME__

Note:

If the proxy is an account, you can access __ACCOUNT_NAME__ to get the account name.

__ACCOUNT_PASSWORD__

Note:

If the proxy is an account, you can access __ACCOUNT_PASSWORD__ to get the MD5 password.

clientAddr

This is a tuple object that contains the client's ip and port.

clientEnabled

Whether the entity is already available. The script cannot communicate with the client until the entity is available.

hasClient

Proxy is bound to a client connection.

roundTripTime

The average round-trip time for client communication between the server and this Proxy over a period of time. This property only takes effect under Linux.

timeSinceHeardFromClient

The time (in seconds) that has passed since the client packet was last received.