---++!! !JGSL_grid %TOC{title="Contents:"}% %STARTINCLUDE% ---++ JGSL Grid (grid server) | *Title* | JGSL Grid (grid server) | | *Author(s)* | LiXizhi | | *Date* | 2008/8/3 | | *File* | script/kids/3DMapSystemNetwork/JGSL_grid.lua | ---+++ Description %T% __Sample Code__ <verbatim> NPL.load("(gl)script/kids/3DMapSystemNetwork/JGSL_grid.lua"); Map3DSystem.JGSL_grid.Restart(); Map3DSystem.JGSL_grid.activate(); </verbatim> ---+++ Member Functions ---++++ !GridNode:CanEdit <verbatim> an array of active grid nodes. JGSL_grid.nodes = {}; timer ID JGSL_grid.TimerID = 18; if true, we will create a new instance if a previous one is full or non existant for a given world and tile position. JGSL_grid.AutoSpawn = true; a timer that is enabled when there are active client connected to this server. should be smaller or equal to Map3DSystem.JGSL.client.NormalUpdateInterval to prevent duplicate group2 info to be sent for the same client. JGSL_grid.TimerInterval = 3000 if true, the game server is a dedicated server usually without any user interface. Pure server will use a different restart function. JGSL_grid.IsPureServer = nil; ------------------------------ Grid Node ------------------------------ a grid node is a single piece of JGSL server, it is similar to JGSL_server, but without loading game world specific data JGSL_grid adds, deletes, maintains many active grid nodes at the same time. local GridNode = { -- server session key, it is regenerated each time a grid node is created or reset, or the underlying game world changes. sk = ParaGlobal.GenerateUniqueID(), -- grid node id id = nil, -- the world path that this grid node is hosting. worldpath = 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, -- the default role assigned to any incoming users. UserRole="guest", -- server version ServerVersion = 1, -- required client version ClientVersion = 1, -- grid configuration file configfile = nil, -- Map3DSystem.JGSL.history: contains all client and server agent creation and environmental action history. history = nil, -- clear the history when the creation has reached this number of times. If this is nil, all history are kept. clear_history_count = 30, -- max number of creations in a message max_creations_per_msg = 5, -- max number of env updates in a message max_env_per_msg = 5, -- VIP ATTRIBUTE: max number of connected users allowed in this grid, this is total number of agents and observers. -- TODO: when there are more than JGSL_grid.max_users on a single server, and when a jid client leaves a such a over crowded grid node and reenters again. the client will receive nothing. max_users = 500, -- a timer that is enabled when there are active client connected to this server. -- should be smaller or equal to Map3DSystem.JGSL.client.NormalUpdateInterval to prevent duplicate group2 info to be sent for the same client. TimerInterval = 3000, -- if a client is not responding in 20 seconds, we will make it inactive user and remove from active user list. ClientTimeOut = 20000, -- a new character will be located at radius = miniSpawnRadius+math.sqrt(OnlineUserNum+1)*3; miniSpawnRadius = 5, -- When the server has broadcasted this number of objects, the server will be automatically restarted; this is usually the setting for testing public server. RestartOnCreateNum = tonumber(ParaEngine.GetAppCommandLineByParam("RestartOnCreateNum", "0")), -- we will recover at most maxrecoversize number of intact client agent request at a time. maxrecoversize = 5, -- -- TODO: for Andy. For each grid node, we need to load NPC within the region and work with Quest server for the world self.worldpath -- Multiple grid nodes for the same self.worldpath may need to share the same server DB. -- For NPC, creatures and dropped items, they should be treated as a special kind of agent in GameObjects table. -- this part is not implemented yet. -- GameObjects = {}, -- client agents or observers on server, where agents[jid] = {agent}. agents = {}, -- increased by one eact time a normal update is replied timeid = 1, -- node statistics statistics = { -- strange: LXZ 2008.12.25: ParaGlobal.GetDateFormat(nil) returns invalid XML char code. just ignore it for now. StartTime = nil, -- commonlib.Encoding.DefaultToUtf8(ParaGlobal.GetDateFormat(nil)..ParaGlobal.GetTimeFormat(nil)), OnlineUserNum = 0, VisitsSinceStart = 0, NumObjectCreated = 0, }, }; JGSL_grid.GridNode = GridNode; state of the agent local agentstate = { agent = 1, observer = 2, }</verbatim> ------------------------------ public function ------------------------------ check whether this grid node allow users to edit the world * _param_ __rule__ : if nil, it means editing right. __syntax__ <verbatim>function GridNode:CanEdit()</verbatim> ---++++ !GridNode:Release release a grid node. __syntax__ <verbatim>function GridNode:Release()</verbatim> ---++++ !GridNode:log output log __syntax__ <verbatim>function GridNode:log(...)</verbatim> ---++++ !GridNode:Reset regenerate session and become a new server. This is usually called by Map3DSystem.JGSL.Reset() call this to reset the server to inital disconnected state where there is a new session key, no history, no timer, no agents. __syntax__ <verbatim>function GridNode:Reset()</verbatim> ---++++ !GridNode:CheckClose TODO: close the node, if there are no agents or observers in it and is not active for a good period of time. __syntax__ <verbatim>function GridNode:CheckClose()</verbatim> ---++++ !GridNode:Load load the grid node from a config structure, but does not reset * _param_ __config__ : a table of {worldpath, x,y,size, UserRole,} __syntax__ <verbatim>function GridNode:Load(config)</verbatim> __parameters__ | *config* | a table of {worldpath, x,y,size, UserRole,} | ---++++ !GridNode:GetAgent ------------------------------ private functions ------------------------------ it will create the agent structure if it does not exist __syntax__ <verbatim>function GridNode:GetAgent(jid)</verbatim> __parameters__ | *jid* | | ---++++ !GridNode:CreateAgent create an agent. it will overwrite existing one, if any, with a newly created one. __syntax__ <verbatim>function GridNode:CreateAgent(jid)</verbatim> __parameters__ | *jid* | | ---++++ !GridNode:IsFull whether the grid node has reached maximum number of connected users allowed. __syntax__ <verbatim>function GridNode:IsFull()</verbatim> ---++++ !GridNode:IsEmpty whether the grid node is empty. __syntax__ <verbatim>function GridNode:IsEmpty()</verbatim> ---++++ !GridNode:Contains whether this grid node contains the 3d point x,y,z in worldpath __syntax__ <verbatim>function GridNode:Contains(worldpath,x,y,z)</verbatim> __parameters__ | *worldpath* | | | *x* | | | *y* | | | *z* | | ---++++ !GridNode:SendToClient send a message to client * _param_ __jid__ : the jid of a client. If this is nil. Messages is sent to all active clients. * _param_ __neuronfile__ : if nil, the DefaultClientFile is used * _return_ __true__ : if successfully send __syntax__ <verbatim>function GridNode:SendToClient(jid, msg, neuronfile)</verbatim> __parameters__ | *jid* | the jid of a client. If this is nil. Messages is sent to all active clients. | | *msg* | | | *neuronfile* | | | *return* | if successfully send | ---++++ !GridNode:HandleMessage handle server messages __syntax__ <verbatim>function GridNode:HandleMessage(msg)</verbatim> __parameters__ | *msg* | | ---++++ !GridNode:OnTimer this function is called periodically. __syntax__ <verbatim>function GridNode:OnTimer(curTime)</verbatim> __parameters__ | *curTime* | | ---++++ !JGSL_grid.Reset ------------------------------ Grid Manager related ------------------------------ shut down all server grid node __syntax__ <verbatim>function JGSL_grid.Reset()</verbatim> ---++++ !JGSL_grid.GetGridNode get a gridnode by id and sessionkey of the grid node __syntax__ <verbatim>function JGSL_grid.GetGridNode(id, sk)</verbatim> __parameters__ | *id* | | | *sk* | | ---++++ !JGSL_grid.GetBestGridNode get available server grid node for a given world path. * _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__ <verbatim>function JGSL_grid.GetBestGridNode(worldpath, x, y, z, IsObserver)</verbatim> __parameters__ | *worldpath* | the world that the grid node is in. | | *x* | | | *y* | | | *z* | | | *IsObserver* | true if we are just getting for an observer node. | ---++++ !JGSL_grid.CreateGetBestGridNode Get the best grid node for a given world path. if no suitable node is found, we will spawn a new one. * _return_ ____ : return a grid node structure. __syntax__ <verbatim>function JGSL_grid.CreateGetBestGridNode(worldpath, x, y, z, IsObserver)</verbatim> __parameters__ | *worldpath* | | | *x* | | | *y* | | | *z* | | | *IsObserver* | | | *return* | return a grid node structure. | ---++++ !JGSL_grid.CreateGridNode create a new grid node of world path it will reuse empty grid node, if there is none, it will create a new one at the end. * _return_ ____ : the grid node created or reused are returned. __syntax__ <verbatim>function JGSL_grid.CreateGridNode(worldpath)</verbatim> __parameters__ | *worldpath* | | | *return* | the grid node created or reused are returned. | ---++++ !JGSL_grid.Restart restart the grid server * _param_ __configfile__ : nil or config file path. __syntax__ <verbatim>function JGSL_grid.Restart(configfile)</verbatim> __parameters__ | *configfile* | nil or config file path. | %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