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");
Member Functions
JGSL_client.GetAgent
client session key, it is regenerated each time we are connecting to a user server.
SessionKey? =
GenerateUniqueID? ();
client version
ClientVersion? = 1;
required server version
ServerVersion? = 1;
player agents.
JGSL_client.playeragent = nil;
server agents on client, where JGSL_client.agents[JID] = {agent}.
JGSL_client.agents = {};
it will create the agent structure if it does not exist
syntax
function JGSL_client.GetAgent(JID)
parameters
JGSL_client.Reset
[[ the current state of the client.
nil: disconnected
0: waiting for server reply
1: needs to send update message to server at a proper time later.
]]
JGSL_client.state = nil;
timer ID
JGSL_client.TimerID = 16;
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
JGSL_client.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 JGSL_client.NormalUpdateInterval.
JGSL_client.MaxNormalUpdateInterval = JGSL_client.NormalUpdateInterval*2;
if the server is not responding in 20 seconds, we will report to user about connecion lost or unsuccessful.
JGSL_client.ServerTimeOut = 20000;
if an agent is not active for this time, it will be removed from the scene
JGSL_client.AgentTimeOut = 20000;
information about the current JGSL server that this client is connected with.
JGSL_client.server = {
-- if the server is invalid, this is nil. otherwise it will be the JGSL server ID.
JID = nil,
-- host user id in paraworldAPI
hostUID = nil,
-- this is true if we are connected to the server JID.
SignedIn = nil,
-- The role that the server assigned to this client. It can be one of the "guest", "administrator", "friend".
UserRole = "guest",
-- world path: worlds/MyWorlds/ABC
worldpath = nil,
-- world name: my_worlds
worldname = nil,
-- description
desc = nil,
-- current online user number
OnlineUserNum = 0,
StartTime = 0,
VisitsSinceStart = 0,
ServerVersion = 0,
ClientVersion = 0,
-- server session key, it is assigned when connected with a remote server. sk is forwarded for each client to server packet.
sk = nil,
-- a value indicating when we last send the server message, this is measured by the local clock.
LastSendMessageTime = nil,
-- a value indicating when we last received the server message, this is measured by the local clock.
LastReceiveMessageTime = nil;
};
LastCreationHistoryTime? = nil
LastEnvHistoryTime? = nil
public functions
regenerate session and become a unconnected client. This is usually called by
JGSL.Reset()
syntax
function JGSL_client.Reset()
JGSL_client.LoginServer
login to a server with a known JID name
- param JID : should be a JID like "lixizhi@paraweb3d.com"
syntax
function JGSL_client.LoginServer(JID)
parameters
| JID |
should be a JID like "lixizhi |
JGSL_client.LogoutServer
logout the current connected server
- param bSilent : if nil, it will send a logout message to server to inform this. if true, it just disconnect without sending any messages.
syntax
function JGSL_client.LogoutServer(bSilent)
parameters
|
bSilent | if nil, it will send a logout message to server to inform this.
if true, it just disconnect without sending any messages. |
JGSL_client.GetServerInfo
get a ready only copy of currently connected server info table.
it will return nil if not connected yet.
syntax
function JGSL_client.GetServerInfo()
JGSL_client.GetPlayerAgent
private functions:
get the agent representing the current player.
syntax
function JGSL_client.GetPlayerAgent()
JGSL_client.OnTimer
a timer that periodically send messages
syntax
function JGSL_client.OnTimer()
JGSL_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 JGSL_client.ApplyCreations(creations)
parameters
JGSL_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 JGSL_client.ApplyEnvs(env)
parameters
JGSL_client.SendNormalUpdate
send normal update to server, such as position, facing, animation, etc.
syntax
function JGSL_client.SendNormalUpdate()