JGSL_server
OBSOLETED use JGSL_grid instead: When a jabber server receives a message from the client, it will accept it or reject it. If accepted, it will reply so and create a JGSL_client_agent character on the server computer if it has never been created before. This JGSL_client_agent will be responsible to keep track of an active client on the server.
Title |
OBSOLETED use JGSL_grid instead: When a jabber server receives a message from the client, it will accept it or reject it. If accepted, it will reply so and create a JGSL_client_agent character on the server computer if it has never been created before. This JGSL_client_agent will be responsible to keep track of an active client on the server. |
Author(s) |
LiXizhi |
Date |
2007/11/6, revised by LiXizhi 2008.6.26 |
File |
script/kids/3DMapSystemNetwork/JGSL_server.lua |
Description
Sample Code
NPL.load("(gl)script/kids/3DMapSystemNetwork/JGSL.lua");
Member Functions
JGSL_server.Reset
server session key, it is regenerated each time we load a different world.
JGSL_server.SessionKey = ParaGlobal.GenerateUniqueID();
server version
JGSL_server.ServerVersion = 1;
required client version
JGSL_server.ClientVersion = 1;
the agent of the current player
JGSL_server.playeragent = nil;
timer ID
JGSL_server.TimerID = 17;
contains all client and server agent creation and environmental action history.
JGSL_server.history = {
creations = {},
env = {},
}
max number of creations in a message
JGSL_server.max_creations_per_msg = 5;
max number of env updates in a message
JGSL_server.max_env_per_msg = 5;
a timer that is enabled when there are active client connected to this server.
should be smaller or equal to
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;
if true, the game server is a dedicated server usually without any user interface. Pure server will use a different restart function.
IsPureServer = nil;
a new character will be located at radius = miniSpawnRadius+math.sqrt(
OnlineUserNum+1)*3;
JGSL_server.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(
GetAppCommandLineByParam("RestartOnCreateNum", "0"));
client agents on server, where JGSL_server.agents[JID] = {agent}.
JGSL_server.agents = {};
public function
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
function JGSL_server.Reset()
JGSL_server.MakeServerPassive
stop the timer and clear the server creation history. call this function when there are no users connected.
JGSL will be active as long as there is a new client connection to it.
syntax
function JGSL_server.MakeServerPassive()
JGSL_server.GetPlayerAgent
private functions
get the agent representing the current player.
syntax
function JGSL_server.GetPlayerAgent()
JGSL_server.GetAgent
it will create the agent structure if it does not exist
syntax
function JGSL_server.GetAgent(JID)
parameters
JGSL_server.CreateAgent
create an agent. it will overwrite existing one, if any, with a newly created one.
syntax
function JGSL_server.CreateAgent(JID)
parameters
JGSL_server.history.clear
some statistics
JGSL_server.statistics = {
StartTime = ParaGlobal.GetDateFormat(nil)..ParaGlobal.GetTimeFormat(nil),
OnlineUserNum = 0,
VisitsSinceStart = 0,
NumObjectCreated = 0,
}
clear all history. call this function when a server restart.
syntax
function JGSL_server.history.clear()
JGSL_server.history.AddCreations
when the server receives some client updates that contains creations, it will save all clients' creations
to an array. At normal update time, the server will broadcast previous creations to the clients.
- param creations : an array of creation history
- param fromJID : who added this creations.
syntax
function JGSL_server.history.AddCreations(creations, fromJID)
parameters
creations |
an array of creation history |
fromJID |
|
JGSL_server.history.AddEnvs
when the server receives some client updates that contains env updates, it will save all clients' creations
to an array. At normal update time, the server will broadcast previous envs to the clients.
- param env : an array of env history
- param fromJID : who added this env.
syntax
function JGSL_server.history.AddEnvs(env, fromJID)
parameters
env |
an array of env history |
fromJID |
|
JGSL_server.history.GetCreationsForClientAgent
get an array of creations from the server creation history.
- param agent : the agent for whom creations will be retrieved. In fact, it will return all creations who time is larger than agent.LastCreationHistoryTime, and whose agent.fromJID is different from the one in creation history.
- param MaxCount : nil or max number of creations to return. This prevents sending too many in a single message.
- return __ : return nil or an array of creations for sending back to the client agent
syntax
function JGSL_server.history.GetCreationsForClientAgent(agent, MaxCount)
parameters
|
agent | the agent for whom creations will be retrieved. In fact, it will return all creations
who time is larger than agent.LastCreationHistoryTime, and whose agent.fromJID is different from the one in creation history. |
MaxCount |
|
return |
return nil or an array of creations for sending back to the client agent |
JGSL_server.history.GetEnvsForClientAgent
get an array of creations from the server creation history.
- param agent : the agent for whom creations will be retrieved. In fact, it will return all creations who time is larger than agent.LastEnvHistoryTime, and whose agent.fromJID is different from the one in creation history.
- param MaxCount : nil or max number of creations to return. This prevents sending too many in a single message.
- return __ : return nil or an array of creations for sending back to the client agent
syntax
function JGSL_server.history.GetEnvsForClientAgent(agent, MaxCount)
parameters
|
agent | the agent for whom creations will be retrieved. In fact, it will return all creations
who time is larger than agent.LastEnvHistoryTime, and whose agent.fromJID is different from the one in creation history. |
MaxCount |
|
return |
return nil or an array of creations for sending back to the client agent |
JGSL_server.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_server.ApplyCreations(creations)
parameters
JGSL_server.ApplyEnvs
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_server.ApplyEnvs(env)
parameters
JGSL_server.OnTimer
a very slowly kicked timer that periodically check user status
syntax
function JGSL_server.OnTimer()