ChatAppDev
description: 鑱婂ぉ鍗虫椂閫氳: 鏀寔缁勩€佸ソ鍙嬪垪琛ㄣ€侀殣绉佺鐞嗙瓑
Chat app for Paraworld
Title |
Chat app for Paraworld |
Author(s) |
WangTian, original template by LiXizhi |
Date |
2008/1/9, Added Summon mode 2008.7.18 lxz |
File |
script/kids/3DMapSystemUI/Chat/app_main.lua |
Description
chatting via jabber
Summon Mode
More information, please see
NPL.load("(gl)script/kids/3DMapSystemUI/Chat/SummonMode.lua");
-- activate summon mode
Map3DSystem.App.Commands.Call("Profile.Chat.Summon");
-- block a summoned agent
Map3DSystem.App.Commands.Call("Profile.Chat.BlockAgent", {JID = JID});
Sample Code
NPL.load("(gl)script/kids/3DMapSystemUI/Chat/app_main.lua");
Member Functions
Map3DSystem.App.Chat.OnConnection
requires
create class
commonlib.setfield("Map3DSystem.App.Chat", {});
event handlers
OnConnection method is the obvious point to place your UI (menus, mainbars, tool buttons) through which the user will communicate to the app.
This method is also the place to put your validation code if you are licensing the add-in. You would normally do this before putting up the UI.
If the user is not a valid user, you would not want to put the UI into the IDE.
- param app : the object representing the current application in the IDE.
- param connectMode : type of ConnectMode.
syntax
function Map3DSystem.App.Chat.OnConnection(app, connectMode)
parameters
app |
the object representing the current application in the IDE. |
connectMode |
|
Map3DSystem.App.Chat.OnDisconnection
Receives notification that the Add-in is being unloaded.
syntax
function Map3DSystem.App.Chat.OnDisconnection(app, disconnectMode)
parameters
Map3DSystem.App.Chat.OnQueryStatus
This is called when the command's availability is updated
When the user clicks a command (menu or mainbar button), the
QueryStatus event is fired.
The
QueryStatus event returns the current status of the specified named command, whether it is enabled, disabled,
or hidden in the
CommandStatus parameter, which is passed to the msg by reference (or returned in the event handler).
- param commandName : The name of the command to determine state for. Usually in the string format "Category.SubCate.Name".
- param statusWanted : what status of the command is queried. it is of type CommandStatusWanted
- return __ : returns according to statusWanted. it may return an integer by adding values in CommandStatus.
syntax
function Map3DSystem.App.Chat.OnQueryStatus(app, commandName, statusWanted)
parameters
app |
|
commandName |
The name of the command to determine state for. Usually in the string format "Category.SubCate.Name". |
statusWanted |
|
return |
returns according to statusWanted. it may return an integer by adding values in CommandStatus. |
Map3DSystem.App.Chat.OnExec
This is called when the command is invoked.The Exec is fired after the
QueryStatus event is fired, assuming that the return to the statusOption parameter of
QueryStatus is supported and enabled.
This is the event where you place the actual code for handling the response to the user click on the command.
- param commandName : The name of the command to determine state for. Usually in the string format "Category.SubCate.Name".
syntax
function Map3DSystem.App.Chat.OnExec(app, commandName, params)
parameters
app |
|
commandName |
The name of the command to determine state for. Usually in the string format "Category.SubCate.Name". |
params |
|
Map3DSystem.App.Chat.OnRenderBox
Change and render the 3D world with mcml data that is usually retrieved from the current user's profile page for this application.
syntax
function Map3DSystem.App.Chat.OnRenderBox(mcmlData)
parameters
Map3DSystem.App.Chat.Navigate
called when the user wants to nagivate to the 3D world location relavent to this application
syntax
function Map3DSystem.App.Chat.Navigate()
Map3DSystem.App.Chat.GotoHomepage
called when user clicks to check out the homepage of this application. Homepage usually includes:
developer info, support, developer worlds information, app global news, app updates, all community user rating, active users, trade, currency transfer, etc.
syntax
function Map3DSystem.App.Chat.GotoHomepage()
Map3DSystem.App.Chat.DoQuickAction
called when user clicks the quick action for this application.
syntax
function Map3DSystem.App.Chat.DoQuickAction()
Map3DSystem.App.Chat.OnDeactivateDesktop
syntax
function Map3DSystem.App.Chat.OnDeactivateDesktop()
Map3DSystem.App.Chat.MSGProc
client world database function helpers.
all related messages
APPS can be invoked in many ways:
Through app Manager
mainbar or menu command or buttons
Command Line
3D World installed apps
syntax
function Map3DSystem.App.Chat.MSGProc(window, msg)
parameters
Lobby BBS channel manager
Title |
Lobby BBS channel manager |
Author(s) |
WangTian |
Date |
2008/6/24, Doc requirement added LiXizhi. 2008.7.20 |
File |
script/kids/3DMapSystemUI/Chat/ChannelManager.lua |
Description
Message format
{
uid = user id,
date = send date,
channelName = channel name that this message belongs to,
channelColor = text color, [optional]
text = pure or mcml text,
name = fullname of the user sending the message.
JID = JID of the user sending the message.
}
Please note that in the remote database, we only store three fields {uid, date, content}
Hence, uid, date are read exactly as in the remote database.
channelColor and channelName are added locally according to local settings when a message is retrieved.
text, name, JID are stored as
NPL table in content column. Whenever we received the content field from the server,
we will decide if it is xml (pure text) or a serialized
NPL table string(begins with '{'). If it is table, all table fields
are extracted to the message.
Sending message
Usually when we send messages, we usually send a serialized table string containing {text, name, JID}, such as
{
uid,
channelName,
content = commonlib.serialize_compact({text, name, JID});
}
The text length is limited to 256 characters.
Displaying message in chat window
we will reconstruct an mcml string from available message fields to display a given message. the reconstruction is as below.
[{msg.channelName}]
:{msg.text}
We will display 8 messsages at a time in a screen.
Getting latest messages
the way client getting messages from server is based on polling. the polling logic is below
- If lastUpdateTime==nil, immediately fetch from the server the lastest 50 messages.
- If we have just send out a text, immediately fetch from the server the lastest messages since the lastUpdateTime
we will prevent entering text again until either the last update returned or some serverTimeOut(10 s) is passed.
- If we have not been sending messages then
if chat window is enabled then
if the last fetched messages are Not empty
update from server again activeUpdateInterval( 1 seconds) after the last fetching result is available or some serverTimeOut(10 s) is passed.
else
update from server again after activeEmptyUpdateInterval( 5 seconds) after the last fetching result is available or some serverTimeOut(10 s) is passed.
end
else
if the last fetched messages are Not empty
update from server again passiveUpdateInterval( 5 seconds) after the last fetching result is available or some serverTimeOut(10 s) is passed.
else
update from server again after passiveEmptyUpdateInterval( 10 seconds) after the last fetching result is available or some serverTimeOut(10 s) is passed.
end
end
end
Getting already fetched messages
Call the following method to retrieve already fetched messages. It can be called as many times by any other applications.
such as the summon mode. It only returns from the local memory.
local msgs = Map3DSystem.App.Chat.ChannelManager.GetFetchedMessages({
channel = nil, if nil it means from all channels,
afterDate = nil, if nil it means the latest
pageSize = 50, return the latest number of message after afterDate
})
Sample Code
NPL.load("(gl)script/kids/3DMapSystemUI/Chat/ChannelManager.lua");
Map3DSystem.App.Chat.ChannelManager.AddChannel("Channel_1")
Member Functions
ChannelManager.Init
create class
local
ChannelManager = {};
commonlib.setfield("Map3DSystem.App.Chat.ChannelManager",
ChannelManager);
all channel messages are stored in the channels table
each entry with a treeview node inside residing all the messages in that channel
treeview can use that node as a root node to show the messages directly
ChannelManager.channels = {};
text color of the default channel messages
TextColors = {
["Public"] = "FAEBD7",
["Help"] = "ADD8E6",
["World"] = "32CD32",
["Chat"] = "FFC0CB",
};
init the channels and the message time
syntax
function ChannelManager.Init()
ChannelManager.OnUISetup
init the message on UISetup
syntax
function ChannelManager.OnUISetup()
ChannelManager.AddChannel
add a channel to manager
syntax
function ChannelManager.AddChannel(channelName, channelText)
parameters
ChannelManager.RemoveChannel
remove a channel from manager
syntax
function ChannelManager.RemoveChannel(channelName)
parameters
ChannelManager.GetChannelRootTreeNode
get the channel root treenode, it containing all the message information
NOTE: this node is the root node of channel manager, all channels post information to this node
syntax
function ChannelManager.GetChannelRootTreeNode()
ChannelManager.ChangeFocusChannel
change focus to channel
syntax
function ChannelManager.ChangeFocusChannel(channelName)
parameters
ChannelManager.GetFocusChannelText
get focus channel text
syntax
function ChannelManager.GetFocusChannelText()
ChannelManager.AppendJabberChatMessage
append the jabber chat message to the channel root node
syntax
function ChannelManager.AppendJabberChatMessage(JID, subject, body)
parameters
ChannelManager.UpdateMessages
common show update interval
local isProcessing = false; -- is web service processing
CommonShowUpdateInterval = 500; -- in milliseconds
update 0.1 second after text sent
TextSentUpdateLatency = 100;
local _elapsedtime = 0;
local _currentTime = 0; -- only for deltatime
get all messages from all channels
syntax
function ChannelManager.UpdateMessages()
ChannelManager.PostMessage
post message to the current focus channel
- param content : the message content
syntax
function ChannelManager.PostMessage(contentStr)
parameters
chat window
Title |
chat window |
Author(s) |
WangTian |
Date |
2007/10/14 |
File |
script/kids/3DMapSystemUI/Chat/ChatWnd.lua |
Description
Sample Code
NPL.load("(gl)script/kids/3DMapSystemUI/Chat/ChatWnd.lua");
Member Functions
Map3DSystem.UI.Chat.ChatWnd:new
constructor
syntax
function Map3DSystem.UI.Chat.ChatWnd:new(o)
parameters
Map3DSystem.UI.Chat.ChatWnd:show
- param bShow : boolean to show or hide. if nil, it will toggle current setting.
syntax
function Map3DSystem.UI.Chat.ChatWnd:show(bShow)
parameters
bShow |
boolean to show or hide. if nil, it will toggle current setting. |
Map3DSystem.UI.Chat.ChatWnd:InitUI
init the
ChatWnd UI
syntax
function Map3DSystem.UI.Chat.ChatWnd:InitUI(parent)
parameters
Map3DSystem.UI.Chat.ChatWnd.DrawContactNodeHandler
chat window chatting history treeview owner draw function
syntax
function Map3DSystem.UI.Chat.ChatWnd.DrawContactNodeHandler(_parent, treeNode)
parameters
Map3DSystem.UI.Chat.ChatWnd.MSGProc
chat window message procedure
syntax
function Map3DSystem.UI.Chat.ChatWnd.MSGProc(window, msg)
parameters
Map3DSystem.UI.Chat.ChatWnd.GetWindowFrame
get the window frame according to the user JID
syntax
function Map3DSystem.UI.Chat.ChatWnd.GetWindowFrame(sJID)
parameters
Map3DSystem.UI.Chat.ChatWnd.ShowUI
show ui function of the chat window
- param bShow : true or false
- param parentUI : parent UI contain object
- param parentWindow : parent os window object
syntax
function Map3DSystem.UI.Chat.ChatWnd.ShowUI(bShow, parentUI, parentWindow)
parameters
bShow |
true or false |
parentUI |
|
parentWindow |
parent os window object |
Map3DSystem.UI.Chat.ChatWnd.OnCloseWindow
close callback function of the chat window
syntax
function Map3DSystem.UI.Chat.ChatWnd.OnCloseWindow(sJID)
parameters
Map3DSystem.UI.Chat.ChatWnd:OnClose
close the chat windows
syntax
function Map3DSystem.UI.Chat.ChatWnd:OnClose()
Map3DSystem.UI.Chat.ChatWnd:AddTextToChatHistory
add a line of text to the chat history
- param from : the name of the user
- param subject : nil
- param body : the message body
syntax
function Map3DSystem.UI.Chat.ChatWnd:AddTextToChatHistory(from, subject, body)
parameters
from |
the name of the user |
subject |
|
body |
the message body |
Map3DSystem.UI.Chat.ChatWnd:OnReceiveMessage
called when received a message from server
- param from : the name of the user
- param subject : nil
- param body : the message body
syntax
function Map3DSystem.UI.Chat.ChatWnd:OnReceiveMessage(from, subject, body)
parameters
from |
the name of the user |
subject |
|
body |
the message body |
Map3DSystem.UI.Chat.ChatWnd:SendChatMessage
called to send a message
- param to : JID
- param body : the message body
syntax
function Map3DSystem.UI.Chat.ChatWnd:SendChatMessage(to, body)
parameters
Map3DSystem.UI.Chat.ChatWnd.UpdateContactStatus
update the contact status of the given user
- param sJID : given user JID
- param status : online status
- param personalMSG : personal message
syntax
function Map3DSystem.UI.Chat.ChatWnd.UpdateContactStatus(sJID, status, personalMSG)
parameters
sJID |
given user JID |
status |
|
personalMSG |
personal message |
Map3DSystem.UI.Chat.ChatWnd.GetWindowFrameDocument
get the document window UI object of the given user
- param sJID : given user JID
syntax
function Map3DSystem.UI.Chat.ChatWnd.GetWindowFrameDocument(sJID)
parameters
Map3DSystem.UI.Chat.ChatWnd.OnSendMessage_static
static function
send message in the textBox of the chat window
syntax
function Map3DSystem.UI.Chat.ChatWnd.OnSendMessage_static(sJID)
parameters
Chat contact window user interface
Title |
Chat contact window user interface |
Author(s) |
WangTian |
Date |
2008/5/27 |
File |
script/kids/3DMapSystemUI/Chat/ChatWnd2.lua |
Description
Sample Code
NPL.load("(gl)script/kids/3DMapSystemUI/Chat/ChatWnd2.lua");
local chatwnd = Map3DSystem.App.Chat.ChatWnd:CreateGetWnd({"andy2@pala5.cn"});
chatwnd:ShowMainWnd(true);
Member Functions
Map3DSystem.App.Chat.ChatWnd:CreateGetWnd
get the
ChatWnd by its JID list. if the
ChatWnd of the given JIDs list is not created. it will create a new one and return.
- param JIDs : e.x. {"andy2@pala5.cn", "leio@pala5.cn", "lixizhi@pala5.cn", "Clayman@pala5.cn", ...} create ChatWnd object
syntax
function Map3DSystem.App.Chat.ChatWnd:CreateGetWnd(JIDs)
parameters
Map3DSystem.App.Chat.ChatWnd:ShowMainWnd
Show the Chat window
- param bShow :
- param bSilentInit : if true, the window is init but not show
syntax
function Map3DSystem.App.Chat.ChatWnd:ShowMainWnd(bShow, bSilentInit)
parameters
Map3DSystem.App.Chat.ChatWnd:GetVisible
return the window frame visibility
nil if the window frame is not inited
syntax
function Map3DSystem.App.Chat.ChatWnd:GetVisible()
Map3DSystem.App.Chat.ChatWnd:IsTopFrame
return if the window frame top frame
syntax
function Map3DSystem.App.Chat.ChatWnd:IsTopFrame()
Map3DSystem.App.Chat.ChatWnd:GetTextAndIcon
get the text and icon according to
ChatWnd JID list
- return text :, icon, shortText: string
syntax
function Map3DSystem.App.Chat.ChatWnd:GetTextAndIcon()
parameters
return |
, icon, shortText: string |
Map3DSystem.App.Chat.ChatWnd:Update
update the UI
syntax
function Map3DSystem.App.Chat.ChatWnd:Update()
Map3DSystem.App.Chat.ChatWnd:RecvMSG
recv message
- param JID :
- param subject :
- param body :
syntax
function Map3DSystem.App.Chat.ChatWnd:RecvMSG(JID, subject, body)
parameters
Map3DSystem.App.Chat.ChatWnd:SendMSG
send message
syntax
function Map3DSystem.App.Chat.ChatWnd:SendMSG()
Map3DSystem.App.Chat.ChatWnd:AppendMSG
append the message to conversation treeview and update
syntax
function Map3DSystem.App.Chat.ChatWnd:AppendMSG(JID, body)
parameters
Map3DSystem.App.Chat.ChatWnd.OnToggleChatTab
click on the chat tab
syntax
function Map3DSystem.App.Chat.ChatWnd.OnToggleChatTab(ID)
parameters
Map3DSystem.App.Chat.ChatWnd.GenerateID
generate a unique ID of this chat window using the JIDs
syntax
function Map3DSystem.App.Chat.ChatWnd.GenerateID(JIDs)
parameters
Map3DSystem.App.Chat.ChatWnd.GetChatWndByID
get the chat window using ID
syntax
function Map3DSystem.App.Chat.ChatWnd.GetChatWndByID(ID)
parameters
Map3DSystem.App.Chat.ChatWnd.MSGProc
Message Processor of Chat chat window control
syntax
function Map3DSystem.App.Chat.ChatWnd.MSGProc(window, msg)
parameters
Map3DSystem.App.Chat.ChatWnd.Show
show Chat
ChatWnd in the parent window
- param bShow : boolean to show or hide. if nil, it will toggle current setting.
- param __ :_parent: parent window inside which the content is displayed. it can be nil.
- param parentWindow : parent os window object, parent window for sending messages
syntax
function Map3DSystem.App.Chat.ChatWnd.Show(bShow, _parent, parentWindow)
parameters
bShow |
boolean to show or hide. if nil, it will toggle current setting. |
parent |
|
parentWindow |
parent os window object, parent window for sending messages |
Map3DSystem.App.Chat.ChatWnd.OnInputTextChange
monitor the keychange, enter to send message
syntax
function Map3DSystem.App.Chat.ChatWnd.OnInputTextChange(ChatWndID)
parameters
Chat system contacts bar
Title |
Chat system contacts bar |
Author(s) |
WangTian |
Date |
2008/8/13 |
File |
script/kids/3DMapSystemUI/Chat/ContactsBar.lua |
Description
contacts bar is a container shown on the right bottom of the screen, right above the status bar.
Each item in the contacts bar is an icon represents a user in the chat contact list. Each icon
is accociated with a chat window which is triggered by the user or receive a message.
Chat window can be minimized to the coresponding icon. Online status of the contact is shown on
the right bottom 1/4 corner over the icon. If new message received, and chat window is minimized(not visible),
new messages are shown with a bubble.
Sample Code
NPL.load("(gl)script/kids/3DMapSystemUI/Chat/ContactsBar.lua");
Member Functions
ContactsBar.AddContact
if(not
ContactsBar) then
ContactsBar = {}; end
local
ContactsBar = {};
ContactsBar =
ContactsBar;
ContactsBarNodes =
TreeNode:new({Text = "contactsbar", Name = "contactsbar"});
add a status bar task.
- param task : { name = "Chat1", icon = "optional icon, usually has it", text = "this is optional", tooltip = "some text", commandName = "", }
- param priority : number Priority defines the position of the given command in the status bar. Higher priority shown on the right. For those items with the same priority, the more recent added has lower priority which shows on the left. Here are some default priorities for official applications:
- ChatWindow
- 3, OfficalAppStatus: 8, DefaultPriority: 5
syntax
function ContactsBar.AddContact(contact, priority)
parameters
ContactsBar.RemoveContact
remove contact icon from the contacts bar
- param contactName : the task to be removed from the contacts bar
syntax
function ContactsBar.RemoveContact(contactName)
parameters
contactName |
the task to be removed from the contacts bar |
ContactsBar.ClearContacts
remove all tasks in contacts bar
syntax
function ContactsBar.ClearContacts()
ContactsBar.Refresh
refresh the contacts bar with the UI parent container
syntax
function ContactsBar.Refresh(_parent)
parameters
history window
Title |
history window |
Author(s) |
WangTian |
Date |
2007/10/14 |
File |
script/kids/3DMapSystemUI/Chat/HistoryWnd.lua |
Description
Sample Code
NPL.load("(gl)script/kids/3DMapSystemUI/Chat/HistoryWnd.lua");
Member Functions
Map3DSystem.UI.Chat.HistoryWnd.ShowUI
- param bShow : show or hide the panel
- param parentUI : parent container inside which the content is displayed. it can be nil.
- param parentWindow : parent window for sending messages
syntax
function Map3DSystem.UI.Chat.HistoryWnd.ShowUI(bShow, parentUI, parentWindow)
parameters
bShow |
show or hide the panel |
parentUI |
|
parentWindow |
parent window for sending messages |
Lobby BBS channel page
Title |
Lobby BBS channel page |
Author(s) |
WangTian |
Date |
2008/6/23 |
File |
script/kids/3DMapSystemUI/Chat/LobbyBBSChannelPage.lua |
Description
Sample Code
NPL.load("(gl)script/kids/3DMapSystemUI/Chat/LobbyBBSChannelPage.lua");
Map3DSystem.App.Chat.LobbyBBSChannelPage.Show()
Member Functions
LobbyBBSChannelPage.OnInit
create class
local
LobbyBBSChannelPage = {};
commonlib.setfield("Map3DSystem.App.Chat.LobbyBBSChannelPage",
LobbyBBSChannelPage);
text line height of a message. some fixed line height.
local
FixedLineHeight = 18;
on init show the current avatar in pe:avatar
syntax
function LobbyBBSChannelPage.OnInit()
LobbyBBSChannelPage.OnClose
open using external system web browser, such as ie
syntax
function LobbyBBSChannelPage.OnClose()
LobbyBBSChannelPage.DoFramemove
update 0.05 second after first shown
local _elapsedtime = 0;
FirstShowUpdateLatency = 0.05;
on init show the current avatar in pe:avatar
syntax
function LobbyBBSChannelPage.DoFramemove()
LobbyBBSChannelPage.Show
show the lobby BBS channel page
syntax
function LobbyBBSChannelPage.Show(bShow)
parameters
LobbyBBSChannelPage.ShowBBS
- param params : a table containing
syntax
function LobbyBBSChannelPage.ShowBBS(bShow, _parent, params)
parameters
bShow |
|
parent |
|
params |
a table containing |
Map3DSystem.App.Chat.LobbyBBSChannelPage.ChatOption
onclick the four control button in the channel page
syntax
function Map3DSystem.App.Chat.LobbyBBSChannelPage.ChatOption()
new chat system for 3D Map system
Title |
new chat system for 3D Map system |
Author(s) |
WangTian |
Date |
2008/5/27, Autoreconnect added LiXizhi 2009.1.15 |
File |
script/kids/3DMapSystemUI/Chat/Main.lua |
Description
Chat system main
Chat system is based on the Jabber client and works as a part of the paraworld online experience.
OneTimeInit funciton is part of
login procedure. Users are organized in groups(router in jabber) and shown with user icon picture and online status.
Chat system provides a chat window for each contact. The chat window can also minimized to icons lined on the right bottom corner
of the screen, right above the status bar.
Sample Code
NPL.load("(gl)script/kids/3DMapSystemUI/Chat/Main.lua");
Map3DSystem.App.Chat.OneTimeInit();
-- call Map3DSystem.App.Chat.InitJabber periodically if disconnected.
Map3DSystem.App.Chat.InitJabber();
-- they contains the jid
Map3DSystem.App.Chat.jid;
Map3DSystem.App.Chat.UserJID;
Member Functions
Chat.OneTimeInit
private:
LastConnectionTime = 0;
connect timer
ConnectTimer = -100000;
only reconnect every 20 seconds
ConnectPeriod = 20000; -- 20000 milliseconds
once ondisconnected, we will try to Auto reconnect by 2 times before waiting until the next
ConnectPeriod
AutoConnectCount = 2;
ReconnectCount_ = 0;
ReconnectTimerID = 5151;
log chat application event traffic
local LOG_CHAT_JC_TRAFFIC = true;
a mapping from event name to their callback functions
local jc_event_callbacks = {};
one time initialize to chat system
Call
OneTimeInit() at authentication success
login to
JGSL chat during login procedure, see
Map3DSystem.App.Login.Proc_Authentication
including:
-
- init the jabber client instant messanger
- init the os.window object for message process
syntax
function Chat.OneTimeInit()
Chat.GetClient
Get default jabber client, create if not exist
It does not open a connection immediately.
syntax
function Chat.GetClient()
Chat.GetConnectedClient
get the currently connected client. return nil, if connection is not valid
syntax
function Chat.GetConnectedClient()
Chat.CheckLastTime
this function will return true if nMilliSecondsPassed is passed since last timer of timerName is set
- param timerName : such as "ConnectTimer"
- param nMilliSecondsPassed : such as 20000 milliseconds
- param bUpdateIfTrue : whether it will update last connection time if true.
syntax
function Chat.CheckLastTime(timerName, nMilliSecondsPassed, bUpdateIfTrue)
parameters
timerName |
such as "ConnectTimer" |
nMilliSecondsPassed |
|
bUpdateIfTrue |
whether it will update last connection time if true. |
Chat.InitJabber
initiate the instant messager client
- param username : user name
- param password : password
- param servername : server name, "paraweb3d.com", "pala5.cn", "192.168.0.223" .etc
- param NetworkHost : the actuall IP address to connect to. If it is nil, IP address will be resolved from servername. Such as "192.168.0.223", "119.145.5.38" such as InitIM("andy", "1234567", "pala5.cn")
syntax
function Chat.InitJabber(username, password, servername, NetworkHost)
parameters
username |
user name |
password |
|
servername |
server name, "paraweb3d.com", "pala5.cn", "192.168.0.223" .etc |
NetworkHost |
|
Chat.AddEventListener
Connect and Auth Event -------------------------
add a function call back to a given JC event
TODO: use hook for other message types.
- param JE :_EventName: currently only "JE_OnAuthenticate" and "JE_OnDisconnect" is supported.
- param funcCallBack : it is of type function(msg) end
syntax
function Chat.AddEventListener(JE_EventName, funcCallBack)
parameters
JE |
_EventName: currently only "JE_OnAuthenticate" and "JE_OnDisconnect" is supported. |
EventName |
|
funcCallBack |
|
Chat.FireEvent
fire a given event.
syntax
function Chat.FireEvent(JE_EventName, msg)
parameters
Chat.OnTimer
set timer
syntax
function Chat.OnTimer()
Chat.OnMessage
Common Event -------------------------
syntax
function Chat.OnMessage()
Chat.OnReceiveChatMessage
on receive chat message
syntax
function Chat.OnReceiveChatMessage(msg)
parameters
Map3DSystem.App.Chat.VisualizeMessage
show the message with
ChatWnd
- param JID :
- param subject :
- param body :
syntax
function Map3DSystem.App.Chat.VisualizeMessage(JID, subject, body)
parameters
Chat.GetPendingMSGs
pending messages
these messages usually need
MessageBox to show, the message will queue up for the
DoPendingMSGTimer() to
show on screen one by one, otherwise the next message will close the previous messagebox
PendingMSGs =
PendingMSGs or {};
client user interface may get the
PnRoster messaged that received before ui objects are created
syntax
function Chat.GetPendingMSGs()
Chat.OnSelfPresence
presence mapping, updated every time jabber client receives a presence message
Chat.JID_Presence_mapping = {};
syntax
function Chat.OnSelfPresence()
Chat.UpdateContactList
update contact list
in online mode, contact information is retrieved from the jabber client
in offline mode, contact information is retrieved from the history
syntax
function Chat.UpdateContactList()
Chat.GetContactList
get the roster groups and roster items
syntax
function Chat.GetContactList()
parameters
Chat.IsInContactList
is JID in contact list
- param __ : JID of the user
syntax
function Chat.IsInContactList(JID)
parameters
Chat.GetNameFromJID
return the name of a Jabber ID, if not including any "@" sign the whole JID is returned
- param sJID : the given JID
- return __ : the name of the JID e.g. for JID:"andy@paraweb3d.com" it returns "andy"
syntax
function Chat.GetNameFromJID(sJID)
parameters
Chat.MSGProc
Message Processor of Chat jabber client
it handles various messages
syntax
function Chat.MSGProc(window, msg)
parameters
Instant messenging main window in Map 3D system
Title |
Instant messenging main window in Map 3D system |
Author(s) |
WangTian |
Date |
2007/10/12 |
File |
script/kids/3DMapSystemUI/Chat/MainWnd.lua |
Description
Member Functions
Map3DSystem.UI.Chat.MainWnd.ShowMainWndUI
- param bShow : show or hide the panel
- param parentUI : parent container inside which the content is displayed. it can be nil.
- param parentWindow : parent window for sending messages
syntax
function Map3DSystem.UI.Chat.MainWnd.ShowMainWndUI(bShow, parentUI, parentWindow)
parameters
bShow |
show or hide the panel |
parentUI |
|
parentWindow |
parent window for sending messages |
Map3DSystem.UI.Chat.MainWnd.OnUserIconClick
onclick function on the login user icon
syntax
function Map3DSystem.UI.Chat.MainWnd.OnUserIconClick()
Map3DSystem.UI.Chat.MainWnd.DrawContactNodeHandler
owner draw function of the contact list treeview
syntax
function Map3DSystem.UI.Chat.MainWnd.DrawContactNodeHandler(_parent, treeNode)
parameters
Map3DSystem.UI.Chat.MainWnd.UpdateContactList
update the entire UI
syntax
function Map3DSystem.UI.Chat.MainWnd.UpdateContactList()
Map3DSystem.UI.Chat.MainWnd.OnClickUser
called when clicking a user
- param treeNode : treenode of the contact treeview
syntax
function Map3DSystem.UI.Chat.MainWnd.OnClickUser(treeNode)
parameters
treeNode |
treenode of the contact treeview |
Map3DSystem.UI.Chat.MainWnd.OnClickGroupContextMenuItem
group context menu event handler
- param menuItem :
- param UserNode :
syntax
function Map3DSystem.UI.Chat.MainWnd.OnClickGroupContextMenuItem(menuItem, UserNode)
parameters
Map3DSystem.UI.Chat.MainWnd.OnClickUserContextMenuItem
user context menu event handler
- param menuItem :
- param UserNode :
syntax
function Map3DSystem.UI.Chat.MainWnd.OnClickUserContextMenuItem(menuItem, UserNode)
parameters
Map3DSystem.UI.Chat.MainWnd.AddContact
add the contact shown in the textBoxAddContact text box
syntax
function Map3DSystem.UI.Chat.MainWnd.AddContact()
Map3DSystem.UI.Chat.MainWnd.ShowChatWithUser
show the
ChatWnd instance for a given sJID, it will create the window if it has never been created before.
- param sJID : the JID of the communicate user
syntax
function Map3DSystem.UI.Chat.MainWnd.ShowChatWithUser(sJID)
parameters
sJID |
the JID of the communicate user |
Map3DSystem.UI.Chat.MainWnd.ShowUserOnMap
TODO: show the user on the map
TODO: write proper command for map application
syntax
function Map3DSystem.UI.Chat.MainWnd.ShowUserOnMap(sJID)
parameters
Map3DSystem.UI.Chat.MainWnd.OnChangePersonalMsg
dirty change personal msg
TODO: more actions for editBox
syntax
function Map3DSystem.UI.Chat.MainWnd.OnChangePersonalMsg()
Map3DSystem.UI.Chat.MainWnd.SetUserPersonalMSG
set the user's personal information
- param personalMSG : the personal information message
- param bBroadcast : whether broadcast the user presence information, default true
syntax
function Map3DSystem.UI.Chat.MainWnd.SetUserPersonalMSG(personalMSG, bBroadcast)
parameters
personalMSG |
the personal information message |
bBroadcast |
|
Map3DSystem.UI.Chat.MainWnd.OnSelectUserStatus
change the main window current user status according to the control selection, automaticly set the user's presence information
- param sCtrlName : dropdownlistbox name
syntax
function Map3DSystem.UI.Chat.MainWnd.OnSelectUserStatus(sCtrlName)
parameters
sCtrlName |
dropdownlistbox name |
Map3DSystem.UI.Chat.MainWnd.SetUserStatus
set main window current user status, automaticly set the user's presence information
syntax
function Map3DSystem.UI.Chat.MainWnd.SetUserStatus(status)
parameters
Map3DSystem.UI.Chat.MainWnd.AddChattingTab
add a new chatting tab in tab contianer in main chat window
- param sJID : the communicating user JID
syntax
function Map3DSystem.UI.Chat.MainWnd.AddChattingTab(sJID)
parameters
sJID |
the communicating user JID |
Map3DSystem.UI.Chat.MainWnd.RemoveChattingTab
remove a chatting tab in tab contianer in main chat window
- param sJID : the communicating user JID
syntax
function Map3DSystem.UI.Chat.MainWnd.RemoveChattingTab(sJID)
parameters
sJID |
the communicating user JID |
Map3DSystem.UI.Chat.MainWnd.RefreshChattingTab
refresh the chatting tab in main chat window
syntax
function Map3DSystem.UI.Chat.MainWnd.RefreshChattingTab()
Map3DSystem.UI.Chat.MainWnd.GetNameFromJID
return the name of a Jabber ID, if not including any "@" sign the whole JID is returned
- param sJID : the given JID
- return __ : the name of the JID e.g. for JID:"andy@paraweb3d.com" it returns "andy"
syntax
function Map3DSystem.UI.Chat.MainWnd.GetNameFromJID(sJID)
parameters
Map3DSystem.UI.Chat.MainWnd.UpdateContactStatus
update the contact status, automaticly update the chat window contact status
- param sJID : contact's JID
- param status : status of the contact
- param personalMSG : personal information message
syntax
function Map3DSystem.UI.Chat.MainWnd.UpdateContactStatus(sJID, status, personalMSG)
parameters
sJID |
contact's JID |
status |
|
personalMSG |
personal information message |
Map3DSystem.UI.Chat.MainWnd.OnClickChattingTab
onclick chatting tab info
- param sJID : communicating user's JID
syntax
function Map3DSystem.UI.Chat.MainWnd.OnClickChattingTab(sJID)
parameters
sJID |
communicating user's JID |
Chat main window user interface
Title |
Chat main window user interface |
Author(s) |
WangTian |
Date |
2008/5/27 |
File |
script/kids/3DMapSystemUI/Chat/MainWnd2.lua |
Description
Sample Code
NPL.load("(gl)script/kids/3DMapSystemUI/Chat/MainWnd2.lua");
Map3DSystem.App.Chat.MainWnd.ShowMainWnd(true);
Member Functions
Map3DSystem.App.Chat.MainWnd.ShowMainWnd
Show the Chat main window
- param bSilentInit : if true, the window is init but not show
syntax
function Map3DSystem.App.Chat.MainWnd.ShowMainWnd(bShow, bSilentInit)
parameters
bShow |
|
bSilentInit |
if true, the window is init but not show |
Map3DSystem.App.Chat.MainWnd.DestroyMainWnd
destory the main window, usually called when the world is closed
syntax
function Map3DSystem.App.Chat.MainWnd.DestroyMainWnd()
Map3DSystem.App.Chat.MainWnd.MSGProc
Message Processor of Chat main control
syntax
function Map3DSystem.App.Chat.MainWnd.MSGProc(window, msg)
parameters
Map3DSystem.App.Chat.MainWnd.ShowUnvisualizedMSG
Message Processor of Chat main control
syntax
function Map3DSystem.App.Chat.MainWnd.ShowUnvisualizedMSG()
Map3DSystem.App.Chat.MainWnd.IsUIAvailable
check if the main window UI is available
on world switching the UI is all reset
syntax
function Map3DSystem.App.Chat.MainWnd.IsUIAvailable()
Map3DSystem.App.Chat.MainWnd.Show
show Chat
MainWnd in the parent window
- param bShow : boolean to show or hide. if nil, it will toggle current setting.
- param __ :_parent: parent window inside which the content is displayed. it can be nil.
- param parentWindow : parent os window object, parent window for sending messages
syntax
function Map3DSystem.App.Chat.MainWnd.Show(bShow, _parent, parentWindow)
parameters
bShow |
boolean to show or hide. if nil, it will toggle current setting. |
parent |
|
parentWindow |
parent os window object, parent window for sending messages |
Map3DSystem.App.Chat.MainWnd.AddContactImmediate
add contact immediately
- param JID : the JID of user to be added
syntax
function Map3DSystem.App.Chat.MainWnd.AddContactImmediate(JID)
parameters
JID |
the JID of user to be added |
Map3DSystem.App.Chat.MainWnd.ChatWithContactImmediate
chat with contact immediately
- param JID : the JID of user to be chatted to
syntax
function Map3DSystem.App.Chat.MainWnd.ChatWithContactImmediate(JID)
parameters
JID |
the JID of user to be chatted to |
Map3DSystem.App.Chat.MainWnd.SetUserStatus
set main window current user status, automaticly set the user's presence information
syntax
function Map3DSystem.App.Chat.MainWnd.SetUserStatus(status)
parameters
Map3DSystem.App.Chat.MainWnd.OnSelfPresence
set main window current user status, automaticly set the user's presence information
syntax
function Map3DSystem.App.Chat.MainWnd.OnSelfPresence(presence)
parameters
Map3DSystem.App.Chat.MainWnd.DrawContactNodeHandler
owner draw function of the contact list treeview
syntax
function Map3DSystem.App.Chat.MainWnd.DrawContactNodeHandler(_parent, treeNode)
parameters
Quick chat window
Title |
Quick chat window |
Author(s) |
WangTian |
Date |
2008/6/16 |
File |
script/kids/3DMapSystemUI/Chat/QuickChat.lua |
Description
Quick chat window is shown on the bottom of the screen area, right above the application toolbar.
Quich chat window is trigger by hitting enter button if not focusing on any editbox.
Sample Code
NPL.load("(gl)script/kids/3DMapSystemUI/Chat/QuickChat.lua");
Member Functions
QuickChat.ShowMainWnd
NPL.load("(gl)script/kids/3DMapSystem_Data.lua");
commonlib.echo("\n script/kids/3DMapSystemUI/Chat/QuickChat.lua loaded\n")
local L =
CommonCtrl.Locale("IDE");
local
QuickChat = {};
commonlib.setfield("Map3DSystem.App.Chat.QuickChat",
QuickChat);
Show the Quick chat window
syntax
function QuickChat.ShowMainWnd(bShow)
parameters
QuickChat.MSGProc
Message Processor of
QuickChat window control
syntax
function QuickChat.MSGProc(window, msg)
parameters
QuickChat.Show
show
QuickChat in the parent window
- param bShow : boolean to show or hide. if nil, it will toggle current setting.
- param __ :_parent: parent window inside which the content is displayed. it can be nil.
- param parentWindow : parent os window object, parent window for sending messages
syntax
function QuickChat.Show(bShow, _parent, parentWindow)
parameters
bShow |
boolean to show or hide. if nil, it will toggle current setting. |
parent |
|
parentWindow |
parent os window object, parent window for sending messages |
Quick chat page
Title |
Quick chat page |
Author(s) |
WangTian |
Date |
2008/6/26 |
File |
script/kids/3DMapSystemUI/Chat/QuickChatPage.lua |
Description
Sample Code
NPL.load("(gl)script/kids/3DMapSystemUI/Chat/QuickChatPage.lua");
Map3DSystem.App.Chat.QuickChatPage....()
Member Functions
QuickChatPage.OnInit
create class
local
QuickChatPage = {};
commonlib.setfield("Map3DSystem.App.Chat.QuickChatPage",
QuickChatPage);
local page;
text style to use like "style='color:#ff0000'", please note to use single quotation mark.
TextStyle = nil;
on init
syntax
function QuickChatPage.OnInit()
QuickChatPage.OnClose
close quick chat
syntax
function QuickChatPage.OnClose()
QuickChatPage.OnShowInput
show input wnd
syntax
function QuickChatPage.OnShowInput()
QuickChatPage.OnHideInput
close input wnd
syntax
function QuickChatPage.OnHideInput()
QuickChatPage.OnChangeTextColor
change the current text color
- param textcolor : like "ff0000"
syntax
function QuickChatPage.OnChangeTextColor(textColor)
parameters
QuickChatPage.OnSpace
check the input box for channel switch command
syntax
function QuickChatPage.OnSpace()
QuickChatPage.OnTab
check the input box for channel target switch command
syntax
function QuickChatPage.OnTab()
Summon mode
Title |
Summon mode |
Author(s) |
LiXizhi |
Date |
2008/7/16 |
File |
script/kids/3DMapSystemUI/Chat/SummonMode.lua |
Description
The idea of summon mode is to select a few from online people. and display their avatars' agent near the current player avatar.
In this case, the current user can communicate with agents face to face without compromising other people. The communication, however, is limited to
chat and animation. The agent movement is usually AI based such as facing to the speaking character near it.
The procedure is as below
- start the summon effects on the current player
- make remote requests to selects a given number of uids from a given pool (such as online users and recently BBS speaking users)
- find their JIDs from their uids.
- for each candidate{
if(avater with JID does not exist) then
if(filter(
IsFriend or
JustSpeaked)) then
retrieve its avatar ccs info
Create a character using its JID, make it non-persistent.
create the agent avatar as agent OPC in the scene.
mark the agent with agent head on display
Assign agent AI module to the agent OPC. (more info, please see
SummonedAgent.lua)
end
end
move the player to a location near the current character.
play summon effects and animation on the agent for 2 seconds.
}
the context menu for agent includes
- teleport to avater of the agent.
- private chat.
- see profile of its user.
- recast as local character.
- delete (ban) this candiate
Whenever the user receives or sends a BBS message in public or world channels. it will search in OPC and main player and display head on text for some seconds.
Additional agent functions
Instead of avatars, one can also summon pets from other offline/online players and adopt them in their world. One can right click on an agent and recast(rename) it as a local character.
blocking an agent
call
BlockAgent(JID)
Sample Code
NPL.load("(gl)script/kids/3DMapSystemUI/Chat/SummonMode.lua");
Map3DSystem.App.Chat.SummonMode.Activate()
Member Functions
SummonMode.OnInit
create class
local
SummonMode = {};
commonlib.setfield("Map3DSystem.App.Chat.SummonMode",
SummonMode);
max summon spawning radius
SummonMode.spawn_radius = 6;
private: current summon candidates, mapping from uid to candidate table.
local candidates = {}
summon mode page init
syntax
function SummonMode.OnInit()
SummonMode.CallSummonEffect
fire the summon effect at a given position. It is just a particle effect that moves slowly at above head position.
where fromX, fromY, fromZ is position at feet height.
syntax
function SummonMode.CallSummonEffect(fromX, fromY, fromZ)
parameters
SummonMode.Activate
activate the summon mode immediately.
syntax
function SummonMode.Activate()
SummonMode.SelectCandidates
make remote requests to selects a given number of uids from a given pool (such as online users and recently BBS speaking users)
syntax
function SummonMode.SelectCandidates()
SummonMode.InitAgent
initialize the agent, it will try to fetch its appearance first if not fetched before.
syntax
function SummonMode.InitAgent(candidate)
parameters
SummonMode.BlockAgent
we will prevent the given JID from being added as an agent.
syntax
function SummonMode.BlockAgent(JID, bUnblock)
parameters
SummonMode.CreateAgent
create a given agent avatar if it has not created before. It will fire the summon effect.
- param candidate : a table of {JID, uid, CCSInfoStr[optional]}
syntax
function SummonMode.CreateAgent(candidate)
parameters
candidate |
a table of {JID, uid, CCSInfoStr[optional]} |