Skip to content

Proxy Class

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

import KBEngine

Parent Class

Entity

Member Functions

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 ):

Callback Functions

def onClientDeath( self ):

def onClientGetCell( self ):

def onClientEnabled( self ):

def onGiveClientToFailure( self ):

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

def onStreamComplete( self, id, success ):

Properties

__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

Detailed Description

Proxy is a special type of Entity that inherits from Entity and has an associated client. Essentially, it is an entity that acts as a proxy for the client, handling all server-to-client updates. You cannot directly create a Proxy object in scripts.

Member Function Documentation


def disconnect( self ):

Disconnects the client connection.


def getClientType( self ):

Description:

This function returns the client type.

Returns:

  • UNKNOWN_CLIENT_COMPONENT_TYPE = 0
  • CLIENT_TYPE_MOBILE = 1 // Mobile
  • CLIENT_TYPE_WIN = 2 // PC, usually exe client
  • CLIENT_TYPE_LINUX = 3 // Linux Application program
  • CLIENT_TYPE_MAC = 4 // Mac Application program
  • CLIENT_TYPE_BROWSER = 5 // Web application, html5, flash
  • CLIENT_TYPE_BOTS = 6 // Bots
  • CLIENT_TYPE_MINI = 7 // Mini-Client
  • CLIENT_TYPE_END = 8 // end

def getClientDatas( self ):

Description:

This function returns the data attached by the client during login and registration.
This data can be used for operational system extensions. If a third-party account service is connected, this data will be sent to the third-party service system via the interfaces process.

Returns:

tuple, a fixed 2-element tuple (login data bytes, registration data bytes). The first element is the datas parameter passed by the client during login, the second is the datas parameter passed during registration. Since arbitrary binary data can be stored, both are of type bytes.


def giveClientTo( self, proxy ):

Description:

Transfers the client controller to another Proxy. The current Proxy must have a client, and the target Proxy must not have an associated client, otherwise an error will occur.

See Also:

Proxy.onGiveClientToFailure

Parameters:

proxy: The entity to which control will be transferred.


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

Description:

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

See Also:

Proxy.onStreamComplete

Parameters:

resourceName: The name of the resource to send, including the path.

desc: An optional string, a description of the resource sent to the client.

id: A 16-bit id, the value is entirely up to the caller. If -1 is passed, the system will select an unused id from the queue. The client can use this id to identify the resource.

Returns:

The id associated with this download.


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

Description:

Sends some data to the client bound to this entity. If the client disconnects, the data is cleared, and this function can only be called again when the client is re-bound to the entity. The 16-bit id is entirely up to the caller.
If the caller does not specify this ID, the system will assign an unused id. The client can use this id to identify the resource.

You can define a callback function (onStreamComplete) in the derived class of Proxy. When all data is successfully sent to the client or the download fails, this callback function will be called.

See: Proxy.onStreamComplete and client entity Entity . onStreamDataStarted and Entity . onStreamDataRecv and Entity . onStreamDataCompleted .

Parameters:

data: The string to send.

desc: An optional string, a description sent to the client.

id: A 16-bit id, the value is entirely up to the caller. If -1 is passed, the system will select an unused id from the queue.

Returns:

The id associated with this download.

Callback Function Documentation


def onClientDeath( self ):

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


def onClientGetCell( self ):

If this callback is implemented in the script, it is called when the client can access the entity's cell property.


def onClientEnabled( self ):

If this callback is implemented in the script, it is called when the entity is available ( all initialization is complete and it can communicate with the client). This method has no parameters.
Note: giveClientTo assigning control to this entity will also trigger this callback.


def onGiveClientToFailure( self ):

If this callback is implemented in the 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 the script, this function is triggered when the client attempts to log in with the current account entity.
This usually happens when the entity exists in memory and is valid. The most obvious example is user A logs in with this account, then user B logs in with the same account, triggering this callback.

This callback function can return the following constants:
KBEngine.LOG_ON_ACCEPT: Allow the new client to bind to the entity. If the entity is already bound to a client, the previous client will be kicked out.
KBEngine.LOG_ON_REJECT: Reject the new client from binding to the entity.
KBEngine.LOG_ON_WAIT_FOR_DESTROY: Wait for the entity to be destroyed before binding the client.

Parameters:

ip: The IP address of the client attempting to log in.

port: The port the client is connecting to.

password: The MD5 password used by the user to log in.


def onStreamComplete( self, id, success ):

If this callback is implemented in the script, it is called when the user completes Proxy.streamStringToClient() or Proxy.streamFileToClient().

Parameters:

id: The id associated with the download.

success: Whether it succeeded.

Property Documentation


__ACCOUNT_NAME__

Description:

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


__ACCOUNT_PASSWORD__

Description:

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


clientAddr

This is a tuple object containing the client's IP and port.


clientEnabled

Whether the entity is available. Scripts cannot communicate with the client before the entity is available.


hasClient

Whether the Proxy is bound to a client connection.


roundTripTime

The average round-trip time for communication between the server and the client bound to this Proxy over a period of time. This property is only effective on Linux.


timeSinceHeardFromClient

The time (in seconds) since the last data packet was received from the client.

文档内容由 Comblock® 提供