JGSL_client
The jabber client will send the first message to the server, and wait for the server's reply until the next message is sent. If the client does not receive any reply, it will assume that the connection is lost.
Title |
The jabber client will send the first message to the server, and wait for the server's reply until the next message is sent. If the client does not receive any reply, it will assume that the connection is lost. |
Author(s) |
LiXizhi |
Date |
2007/11/6 |
File |
script/kids/3DMapSystemNetwork/JGSL_client.lua |
Description
Sample Code
NPL.load("(gl)script/kids/3DMapSystemNetwork/JGSL.lua");
Map3DSystem.JGSL_client:Dump()
Member Functions
client:new
private: client state
local clientstate = {
-- client has been reset
none = nil,
-- contacting gateway
gateway = 1,
-- sending normal update with grid server
normalupdate = 2,
-- disconnected from server, because of time out.
-- disconnected = 3,
}
local client = {
-- client session key, it is regenerated each time we are connecting to a user server.
SessionKey = ParaGlobal.GenerateUniqueID(),
-- client version
ClientVersion = 1,
-- required server version
ServerVersion = 1,
-- player agent.
playeragent = nil,
-- server agents on client, where agents[jid] = {agent}.
agents = {},
-- a pool of timed out agents
timeoutagents = {},
-- jc instance. if nil, JGSL.GetJC will be used.
jc = nil,
-- the jid of this server.
jid = nil,
-- whether this client is emulated.
IsEmulated = nil,
-- LoginServer will be forced to login to this world regardless the current world.
EmuUser_worldpath = nil,
-- private: keep a reference to the world path. this is sent automatically and should not be modified by users.
worldpath = nil,
-- timer ID
TimerID = 16,
-- emulation timer ID
EmuTimerID = 21,
-- if a client shall only send a message to the server every 3 seconds and after it receives the last server message.
-- if the client does not receive message from server within this time, it will continue to wait until ServerTimeOut
NormalUpdateInterval = 3000,
-- if the client does not receive any messages from the server for 10 seconds. It will send the normal update again.
-- it is usually twice of NormalUpdateInterval.
MaxNormalUpdateInterval = 6000,
-- if the server is not responding in 20 seconds, we will report to user about connecion lost or unsuccessful.
ServerTimeOut = 20000,
-- if an agent is not active for this time, it will be removed from the scene
AgentTimeOut = 20000,
-- the gate way server proxy object
gatewayProxy = nil,
-- the grid node server proxies. mapping from grid node server key to proxy object
gridnodeProxies = nil,
-- we will need to connect to all grid node servers within 30 meters, as agent or observers.
sense_radius = 30,
state = clientstate.none,
-- increased by one eact time a normal update is sent
timeid = 1,
}
JGSL.client = client;
public functions
create a new instance of this class.
if there is only one instance, just use the default JGSL_client object without calling new() method.
- param o : if emulated, use new({IsEmulated=true, jid=jid})
syntax
function client:new (o)
parameters
o |
if emulated, use new({IsEmulated=true, jid=jid}) |
client:log
output a log message
syntax
function client:log(...)
client:Dump
dump the current
JGSL status.
syntax
function client:Dump()
client:GetAgent
it will create the agent structure if it does not exist
syntax
function client:GetAgent(jid)
parameters
client:GetJC
get the JC instance
syntax
function client:GetJC()
client:GetJID
get the jid instance
syntax
function client:GetJID()
client:GetGatewayServerJID
jid of the gateway server
syntax
function client:GetGatewayServerJID()
client:Send
send a message to a given jid
- param msg : msg to send
- param neuronfile : if nil, self.DefaultFile is used.
syntax
function client:Send(jid, msg, neuronfile)
parameters
jid |
|
msg |
msg to send |
neuronfile |
|
client:LoginServer
login to a server with a known jid name
if we have a previous connection with the same gateway, all grid nodes sessions are reused. and the function returns immediately.
- param jid : should be a jid like "lixizhi@paraweb3d.com"
syntax
function client:LoginServer(jid)
parameters
jid |
should be a jid like "lixizhi |
client:LogoutServer
logout the current connected gateway and grid servers
- param bSilent : if true, we shall inform the UI.
syntax
function client:LogoutServer(bSilent)
parameters
bSilent |
if true, we shall inform the UI. |
client:PingGateway
sent ping to gateway server to establish connection with it
syntax
function client:PingGateway()
client:QueryGateway
get gateway round trip time for debugging purposes.
syntax
function client:QueryGateway()
client:GetServerInfo
get a ready only copy of currently connected server info table.
it will return nil if not connected yet.
syntax
function client:GetServerInfo()
client:GetPlayerAgent
private functions:
get the agent representing the current player.
syntax
function client:GetPlayerAgent()
client:OnTimerEmu
a timer that periodically send messages for emulated users
syntax
function client:OnTimerEmu()
client:OnTimer
a timer that periodically send messages
syntax
function client:OnTimer()
client:ApplyCreations
when some remote user creations are received by this computer, it will be applied in this world, however, without writing into the history.
syntax
function client:ApplyCreations(creations)
parameters
client:ApplyEnvs
when some remote user env updates are received by this computer, it will be applied in this world, however, without writing into the history.
syntax
function client:ApplyEnvs(env)
parameters
client:VerifySessionKey
verify the session key in the message is the same as the gateway's session key
syntax
function client:VerifySessionKey(msg)
parameters
client:FindBestGridProxy
get available best server grid proxy for a given world path.
a best grid proxy is a proxy that is smallest in size.
- param worldpath : the world that the grid node is in.
- param x :, y, z: a position that the grid node contains.
- param IsObserver : true if we are just getting for an observer node.
syntax
function client:FindBestGridProxy(worldpath, x, y, z)
parameters
worldpath |
the world that the grid node is in. |
x |
|
y |
|
z |
|
client:RemoveGridProxy
remove grid proxy
syntax
function client:RemoveGridProxy(proxy)
parameters
client:CreateGridNodeProxy
Create a connected grid node server proxy, each grid node is responsible for simulating a specific region in the world.
- param msg : the reply NPL message from SC_Login_Reply. It should contain grid node session key and info {gk, gjid, gx,gy,gsize, worldpath}
- return __ : return the proxy object if succeeded
syntax
function client:CreateGridNodeProxy(msg)
parameters
msg |
the reply NPL message from SC_Login_Reply. It should contain grid node session key and info {gk, gjid, gx,gy,gsize, worldpath} |
client:SendNormalUpdate
send a normal update packet to the grid node containing the request location.
if no grid node connection is available for the region, we will ask the gateway for it.
syntax
function client:SendNormalUpdate()
client:HandleMessage
handle server messages
syntax
function client:HandleMessage(msg)
parameters