2006-10-10 05:23:38 +00:00
|
|
|
# Multiplayer Chat
|
|
|
|
# ================
|
|
|
|
#
|
|
|
|
# 1) Display chat messages from other aircraft to
|
|
|
|
# the screen using screen.nas
|
|
|
|
#
|
|
|
|
# 2) Display a complete history of chat via dialog.
|
|
|
|
#
|
|
|
|
# 3) Allow chat messages to be written by the user.
|
|
|
|
|
|
|
|
var messages = {};
|
|
|
|
|
|
|
|
check_messages = func
|
2007-08-01 19:37:51 +00:00
|
|
|
{
|
2006-10-10 05:23:38 +00:00
|
|
|
|
|
|
|
var mp = props.globals.getNode("/ai/models").getChildren("multiplayer");
|
2007-08-01 19:37:51 +00:00
|
|
|
|
2006-10-10 05:23:38 +00:00
|
|
|
foreach (i; mp)
|
|
|
|
{
|
|
|
|
var lmsg = getprop(i.getPath() ~ "/sim/multiplay/chat");
|
|
|
|
var lcallsign = getprop(i.getPath() ~ "/callsign");
|
2007-08-01 19:37:51 +00:00
|
|
|
|
2006-10-10 05:23:38 +00:00
|
|
|
if ((lmsg != nil) and (lmsg != "") and (lcallsign != nil) and (lcallsign != ""))
|
|
|
|
{
|
|
|
|
#print("Call Sign: " ~ lcallsign);
|
|
|
|
#print("lmsg: " ~ lmsg);
|
|
|
|
#print("Freq: " ~ ltransmitfreq);
|
|
|
|
|
|
|
|
if ((! contains(messages, lcallsign)) or (lmsg != messages[lcallsign]))
|
|
|
|
{
|
|
|
|
# Indicate we've seen this message.
|
|
|
|
messages[lcallsign] = lmsg;
|
2007-08-01 19:37:51 +00:00
|
|
|
echo_message(lmsg, lcallsign);
|
2006-10-10 05:23:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-01 19:37:51 +00:00
|
|
|
|
2006-10-10 05:23:38 +00:00
|
|
|
# Check for new messages every couple of seconds.
|
2007-08-01 19:37:51 +00:00
|
|
|
settimer(check_messages, 3);
|
2006-10-10 05:23:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo_message = func(msg, callsign)
|
|
|
|
{
|
|
|
|
if (callsign != nil)
|
|
|
|
{
|
|
|
|
msg = callsign ~ ": " ~ msg;
|
|
|
|
}
|
2007-08-01 19:37:51 +00:00
|
|
|
|
|
|
|
var ldisplay = getprop("/sim/multiplay/chat-display");
|
2006-10-10 05:23:38 +00:00
|
|
|
|
|
|
|
if ((ldisplay != nil) and (ldisplay == "1"))
|
|
|
|
{
|
|
|
|
# Only display the message to screen if configured.
|
|
|
|
setprop("/sim/messages/ai-plane", msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Add the chat to the chat history.
|
2007-08-01 19:37:51 +00:00
|
|
|
var lchat = getprop("/sim/multiplay/chat-history");
|
2006-10-10 05:23:38 +00:00
|
|
|
|
|
|
|
if (lchat == nil)
|
|
|
|
{
|
2007-08-01 19:37:51 +00:00
|
|
|
setprop("/sim/multiplay/chat-history", msg);
|
|
|
|
}
|
2006-10-10 05:23:38 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (substr(lchat, size(lchat) -1, 1) != "\n")
|
|
|
|
{
|
|
|
|
lchat = lchat ~ "\n";
|
|
|
|
}
|
2007-08-01 19:37:51 +00:00
|
|
|
|
|
|
|
setprop("/sim/multiplay/chat-history", lchat ~ msg);
|
2006-10-10 05:23:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
settimer(func {
|
|
|
|
# Call-back to ensure we see our own messages.
|
2007-10-15 18:27:42 +00:00
|
|
|
setlistener("/sim/multiplay/chat", func(n) { echo_message(n.getValue(), getprop("/sim/multiplay/callsign")); });
|
2006-10-10 05:23:38 +00:00
|
|
|
|
|
|
|
# check for new messages
|
|
|
|
check_messages();
|
2007-08-01 19:37:51 +00:00
|
|
|
|
2006-10-10 05:23:38 +00:00
|
|
|
}, 1);
|
|
|
|
|
|
|
|
|