---++!! !EmuUsers %TOC{title="Contents:"}% %STARTINCLUDE% ---++ user emulation module | *Title* | user emulation module | | *Author(s)* | LiXizhi | | *Date* | 2008/12/21 | | *File* | script/kids/3DMapSystemNetwork/EmuUsers.lua | ---+++ Description Only one virtual user is allowed to login and interacts with the GUI. However, we allow unlimited accounts to simulaneously login in as emulated users. An emu user is a full fledged active user in the viewpoint of the server. User emulation is primarily used for * server stress test, so that we can simulate 100 characters with low client side cost. * clients service management, one human client service personel can simultaneously chat with clients on behalf of multiple characters in different locations in the virtual world. * auto bot. a robot agent that can do an variety of things. it therefore allows a single instance to run multiple auto bots. this is similar to MSN bot. User Guide ------------------- The main user should be testers and client service personels. A simple configuration file is used to setup all emu users. The file contains username and password for each user. Additional features per user include displayname, initial world, hangout positions; auto-reply text; gossip text, etc. To start the emu layer, specify your EmuUsersDB file and call Map3DSystem.EmuUsers.LoadUsers("config/EmuUsersDB.table"), and off you go. The implementation ------------------- instead of calling the default login API. a special login API is provided and the user session is maintained by the user emulation layer. %T% __Sample Code__ <verbatim> paraworld.ChangeDomain({domain="test.pala5.cn", chatdomain="192.168.0.233"}) NPL.load("(gl)script/kids/3DMapSystemNetwork/EmuUsers.lua"); Map3DSystem.EmuUsers.LoadUsers("config/EmuUsersDB.xml") </verbatim> ---+++ Member Functions ---++++ !user:new <verbatim> create a special Emu REST API wrapper paraworld.CreateRESTJsonWrapper("Map3DSystem.EmuUsers.AuthUser", "%MAIN%/Auth/AuthUser.ashx"); array of user being emulated. local Users = {}; mapping from user.nid to instance of EmuUsers.user local mapNID = {}; mapping from user.JID to instance of EmuUsers.user local mapJID = {}; --------------------------------- user template and functions --------------------------------- local user = { -- whether REST API auth is passed. IsAuthenticated, username, password, domain, nid, sessionKey, jid, -- usually nid@chatdomain. chatdomain, -------------------------- -- emu parameters -------------------------- -- number of milli-seconds since last frame move call. TimeSinceLastFrameMove = 0, -- The last time that it receives a message from the JGSL server. LastJGSLReceiveTime = 0, -- jabber client instance jc, -------------------------- -- additional features: all of them are optional. -------------------------- nickname, -- the world to login to worldpath, -- the jid of the server to connect to. it can omit the domain, such as "1100", instead of "1100@pala5.com" server, -- initial agent appearance. agent = { -- current position. After compressing, it has 2 decimal x=nil,y=nil,z=nil, -- the nick name to be displayed on head of character nickname=nil, -- id or string of the main asset file of the agent AssetFile=nil, -- customizable character string, ccs=nil, -- scaling.After compressing, it has 2 decimal scaling=nil, -- anim id or string anim=nil, -- character facing. After compressing, it is [0,6.28/256) facing=nil, }, -- an array table containing hangout positions hangoutPos, -- an array of text or a CSV string of text to automatically reply to incoming calls. autoreply, -- an array of text to speak every time interval, so the emu user appears to be alive. gossiptext, }</verbatim> EmuUsers.user = user; a mapping from key name to string(the string is in CSV format). EmuUsers.TextGroup = {}; __syntax__ <verbatim>function user:new (o)</verbatim> __parameters__ | *o* | | ---++++ !user:log function to be called periodically. __syntax__ <verbatim>function user:log(...)</verbatim> ---++++ !user:FrameMove function to be called periodically. __syntax__ <verbatim>function user:FrameMove(timeNow)</verbatim> __parameters__ | *timeNow* | | ---++++ !user:Release call this function to release the user and remove it from the emulation layer. __syntax__ <verbatim>function user:Release(timeNow)</verbatim> __parameters__ | *timeNow* | | ---++++ !user:Connect call this function to authenticate the user with the central API and then connect to JGSL server. __syntax__ <verbatim>function user:Connect()</verbatim> ---++++ !user:JC_Connect connecting to jabber client __syntax__ <verbatim>function user:JC_Connect()</verbatim> ---++++ !user:LoginJGSL login to JGSL server __syntax__ <verbatim>function user:LoginJGSL()</verbatim> ---++++ !user:GetAutoReply get a random text string from auto reply text if any. * _return_ __the__ : text or nil. __syntax__ <verbatim>function user:GetAutoReply()</verbatim> __parameters__ | *return* | text or nil. | ---++++ !user:SendChatMessage send a chat message to a given jid __syntax__ <verbatim>function user:SendChatMessage(jid, body)</verbatim> __parameters__ | *jid* | | | *body* | | ---++++ !EmuUsers.JE_OnConnect --------------------------------- jabber event callback functions --------------------------------- __syntax__ <verbatim>function EmuUsers.JE_OnConnect()</verbatim> ---++++ !EmuUsers.EachUser --------------------------------- pub functions --------------------------------- do something for each user e.g. EmuUsers.EachUser(function(user) user:Connect() end) * _param_ __callbackFunc__ : a function (user) end, this function will be call for each user, with user table as input. __syntax__ <verbatim>function EmuUsers.EachUser(callbackFunc)</verbatim> __parameters__ | *callbackFunc* | a function (user) end, this function will be call for each user, with user table as input. | ---++++ !EmuUsers.FrameMove this function should be called periodically (such as every second) to simulate all emu users. internally it iterate all users and send update to server if needed. * _param_ __timeNow__ : the current system time in milliseconds. It is used to deduce the elapsed time since last call. __syntax__ <verbatim>function EmuUsers.FrameMove(timeNow)</verbatim> __parameters__ | *timeNow* | the current system time in milliseconds. It is used to deduce the elapsed time since last call. | ---++++ !EmuUsers.LoadUsers load users from a configuration file * _param_ __filename__ : filename. __syntax__ <verbatim>function EmuUsers.LoadUsers(filename)</verbatim> __parameters__ | *filename* | filename. | ---++++ !EmuUsers.CreateUser Create a new user to the emulation layer. It will authenticate the user, connect to JGSL, and then begins simulation * _param_ __usertable__ : {username, password, chatdomain, worldpath, server} username: input to the AuthUser Rest API. it should be the user's email address. password: password to the AuthUser Rest API. chatdomain: if nil, the default one %CHATDOMAIN% will be used. __syntax__ <verbatim>function EmuUsers.CreateUser(usertable)</verbatim> __parameters__ | *usertable* | {username, password, chatdomain, worldpath, server} username: input to the AuthUser Rest API. it should be the user's email address. password: password to the AuthUser Rest API. chatdomain: if nil, the default one %CHATDOMAIN% will be used. | ---++++ !EmuUsers.GetUserByNID return a given EmuUsers.user __syntax__ <verbatim>function EmuUsers.GetUserByNID(nid)</verbatim> __parameters__ | *nid* | | ---++++ !EmuUsers.GetUserByJID return a given EmuUsers.user __syntax__ <verbatim>function EmuUsers.GetUserByJID(jid)</verbatim> __parameters__ | *jid* | | ---++++ !EmuUsers.FindUserByName return a given EmuUsers.user if found __syntax__ <verbatim>function EmuUsers.FindUserByName(username)</verbatim> __parameters__ | *username* | | %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