---++!! !JGSL_serverproxy %TOC{title="Contents:"}% %STARTINCLUDE% ---++ epolling style server proxy for client communicating with server. | *Title* | epolling style server proxy for client communicating with server. | | *Author(s)* | LiXizhi | | *Date* | 2008/12/23 | | *File* | script/kids/3DMapSystemNetwork/JGSL_serverproxy.lua | ---+++ Description Event polling implements a messaging pattern that the client only send another packet when server replies. %T% __Sample Code__ <verbatim> NPL.load("(gl)script/kids/3DMapSystemNetwork/JGSL_serverproxy.lua"); local proxy = Map3DSystem.JGSL.ServerProxy:new({DefaultFile="your_server_neuron_filename.lua"}); if(proxy:CheckState()) then proxy:Send(...); end </verbatim> ---+++ Member Functions ---++++ !ServerProxy:new <verbatim> proxy status local proxystate = { -- proxy is reset none = nil, -- waiting for server response waiting = 1, -- server already responded, the client can send message at anytime ready = 2, -- the server is timed out at least once timeout = 3, -- the server is dead, because it has timed out too many times. dead = 5, } ------------------------------------ a server proxy is used by client to communicate with a epoll server. ------------------------------------ local ServerProxy = { -- nil means we are ready to send a packet. state = proxystate.none, -- the last time the client sends message to a server proxy, this is measured by the local clock. LastSendTime, -- the last time the client receives message from the server, this is measured by the local clock. LastReceiveTime, -- default neuron file DefaultFile, -- JID jid, -- the jabber client to use. if nil, JGSL.GetJC() is used. jc, -- whether we have signed in to the server and has its session key in cookies, SignedIn, -- cookies: nil or a table containing name value pairs, such as {sk="sessionkeyhere"} cookies, -- id of this grid node on the server side. id, -- default server timeout time -- usually if the server is not responding in 20 seconds, we will report to user about connecion lost or unsuccessful. ServerTimeOut = 20000, -- we will retry this number of times if the server time outs. If this is 0, we will never retry, but put to this proxy to proxystate.dead immediately upon first time out. MaxTimeOutRetry = 1, -- how many timeout retry times we have done. TimeOutCount = 0, -- default keep alive interval KeepAliveInterval = 10000, -- the following is just for grid server proxy. host user id in paraworldAPI uid = nil, -- The role that the server assigned to this client. It can be one of the "guest", "administrator", "friend". UserRole = "guest", -- we will recover at most maxrecoversize number of intact agents at a time. maxrecoversize = 5, -- a commar separated string containing the nid of to be recovered agents. recoverlist = nil, -- 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, -- client time as seen by server ct = nil, -- last server time as tolde by server st = nil, -- grid tile pos, it marks the simulation region within the self.worldpath. -- from (x*size, y*size) to (x*size+size, y*size+size) x=nil, y=nil, -- grid tile size, if nil, it means infinite size. we always return the smallest sized grid server size=nil, -- these are computed on demand from_x=nil, from_y=nil, to_x=nil, to_y=nil, }</verbatim> Map3DSystem.JGSL.ServerProxy = ServerProxy; __syntax__ <verbatim>function ServerProxy:new (o)</verbatim> __parameters__ | *o* | | ---++++ !ServerProxy:Reset it will send CS_Logout if old connection contains cookies __syntax__ <verbatim>function ServerProxy:Reset()</verbatim> ---++++ !ServerProxy:Logout log out only if it has signed in before but retains session key and self.st and put the proxy to ready state. NOTE: this proxy can be reused when the client need it again, since it retains all session key and server time (self.st). __syntax__ <verbatim>function ServerProxy:Logout()</verbatim> ---++++ !ServerProxy:CanEdit check whether this grid node allow users to edit the world * _param_ __rule__ : if nil, it means editing right. __syntax__ <verbatim>function ServerProxy:CanEdit()</verbatim> ---++++ !ServerProxy:IsEqual return true if the input proxy is same as self. they are only same when the jid, world path and region all matches. __syntax__ <verbatim>function ServerProxy:IsEqual(proxy)</verbatim> __parameters__ | *proxy* | | ---++++ !ServerProxy:Contains whether this node contains the 3d point x,y,z in worldpath __syntax__ <verbatim>function ServerProxy:Contains(worldpath,x,y,z)</verbatim> __parameters__ | *worldpath* | | | *x* | | | *y* | | | *z* | | ---++++ !ServerProxy:Send send a message to server using this proxy. * _param_ __msg__ : msg to send * _param_ __neuronfile__ : if nil, self.DefaultFile is used. __syntax__ <verbatim>function ServerProxy:Send(msg, neuronfile)</verbatim> __parameters__ | *msg* | msg to send | | *neuronfile* | | ---++++ !ServerProxy:OnRespond call this function whenever the proxy has a response from the server. it makes the proxy ready to send another message. __syntax__ <verbatim>function ServerProxy:OnRespond()</verbatim> ---++++ !ServerProxy:UpdateSessionKey update session key * _param_ __bInsertToCookie__ : if true, it will insert sk to cookies, so that sk will be sent along with all subsequent Send calls. __syntax__ <verbatim>function ServerProxy:UpdateSessionKey(sk, bInsertToCookie)</verbatim> __parameters__ | *sk* | | | *bInsertToCookie* | if true, it will insert sk to cookies, so that sk will be sent along with all subsequent Send calls. | ---++++ !ServerProxy:IsReady whether the proxy is in ready state ready state means that the proxy is connected and not waiting for response. __syntax__ <verbatim>function ServerProxy:IsReady()</verbatim> ---++++ !ServerProxy:MakeReady force the proxy to ready state __syntax__ <verbatim>function ServerProxy:MakeReady()</verbatim> ---++++ !ServerProxy:IsKeepAlive whether deltaTime is passed since the last time that we send message to server. if return true, we usually need to send a normal update to server to keep the client alive. * _param_ __deltaTime__ : in milliseconds. usually several times the normal update interval. If nil, self.KeepAliveInterval is used. __syntax__ <verbatim>function ServerProxy:IsKeepAlive(deltaTime)</verbatim> __parameters__ | *deltaTime* | in milliseconds. usually several times the normal update interval. If nil, self.KeepAliveInterval is used. | ---++++ !ServerProxy:IsDead whether the server is dead __syntax__ <verbatim>function ServerProxy:IsDead()</verbatim> ---++++ !ServerProxy:IsTimeOut return true if we are not receiving server response for too long __syntax__ <verbatim>function ServerProxy:IsTimeOut(curTime)</verbatim> __parameters__ | *curTime* | | ---++++ !ServerProxy:AddToRecoverList append to the recover list of this proxy. the recover list has a max size. if max size is reached, we will ignore and return nil. * _return_ ____ : return true if added to recover list or already added before. __syntax__ <verbatim>function ServerProxy:AddToRecoverList(agent)</verbatim> __parameters__ | *agent* | | | *return* | return true if added to recover list or already added before. | ---++++ !ServerProxy:log output a log message __syntax__ <verbatim>function ServerProxy:log(...)</verbatim> ---++++ !ServerProxy:Dump output to log. for debugging only. __syntax__ <verbatim>function ServerProxy:Dump()</verbatim> ---++++ !ServerProxy:CheckState update the self.state according to the current time. it will change the state from wait to timeout if the server is not responding since last send * _return_ ____ : return true if state is proxystate.ready or proxystate.timeout, meaning that u should send an update immediately. __syntax__ <verbatim>function ServerProxy:CheckState(curTime)</verbatim> __parameters__ | *curTime* | | | *return* | return true if state is proxystate.ready or proxystate.timeout, meaning that u should send an update immediately. | %STOPINCLUDE%
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2008-02-29
-
LiXizhi
Home
Site map
CCWeb web
HaqiTeen web
Main web
ParaEngine web
TWiki web
Main Web
Users
Groups
Index
Search
Changes
Notifications
RSS Feed
Statistics
导航页WebTopMenu
Preferences
开发指南
Getting Started
ParacraftSDK
NPL
MCML
NPL Reference Manual
美术Mod
Account
Log In
English
简体中文
簡體中文
E
dit
A
ttach
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback