EmuUsers
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
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.
Sample Code
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")
Member Functions
user:new
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,
}
EmuUsers.user = user;
a mapping from key name to string(the string is in CSV format).
TextGroup = {};
syntax
function user:new (o)
parameters
user:log
function to be called periodically.
syntax
function user:log(...)
user:FrameMove
function to be called periodically.
syntax
function user:FrameMove(timeNow)
parameters
user:Release
call this function to release the user and remove it from the emulation layer.
syntax
function user:Release(timeNow)
parameters
user:Connect
call this function to authenticate the user with the central API and then connect to
JGSL server.
syntax
function user:Connect()
user:JC_Connect
connecting to jabber client
syntax
function user:JC_Connect()
user:LoginJGSL
login to
JGSL server
syntax
function user:LoginJGSL()
user:GetAutoReply
get a random text string from auto reply text if any.
- return the : text or nil.
syntax
function user:GetAutoReply()
parameters
user:SendChatMessage
send a chat message to a given jid
syntax
function user:SendChatMessage(jid, body)
parameters
EmuUsers.JE_OnConnect
jabber event callback functions
syntax
function EmuUsers.JE_OnConnect()
EmuUsers.EachUser
pub functions
do something for each user
e.g.
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
function EmuUsers.EachUser(callbackFunc)
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
function EmuUsers.FrameMove(timeNow)
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
function EmuUsers.LoadUsers(filename)
parameters
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
function EmuUsers.CreateUser(usertable)
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
function EmuUsers.GetUserByNID(nid)
parameters
EmuUsers.GetUserByJID
return a given
EmuUsers.user
syntax
function EmuUsers.GetUserByJID(jid)
parameters
EmuUsers.FindUserByName
return a given
EmuUsers.user if found
syntax
function EmuUsers.FindUserByName(username)
parameters