diff --git a/Nasal/IOrules b/Nasal/IOrules index 0c62b5687..68c18b276 100644 --- a/Nasal/IOrules +++ b/Nasal/IOrules @@ -32,3 +32,4 @@ WRITE ALLOW $FG_HOME/*.sav WRITE ALLOW $FG_HOME/Export/* WRITE ALLOW $FG_HOME/state/*.xml WRITE ALLOW $FG_HOME/aircraft-data/*.xml +WRITE ALLOW $FG_HOME/mp-message.log diff --git a/Nasal/gui.nas b/Nasal/gui.nas index 41115b021..aca484211 100644 --- a/Nasal/gui.nas +++ b/Nasal/gui.nas @@ -104,7 +104,7 @@ _setlistener("/sim/signals/nasal-dir-initialized", func { # enable/disable menu entries menuEnable("fuel-and-payload", fdm == "yasim" or fdm == "jsb"); menuEnable("autopilot", props.globals.getNode("/autopilot/KAP140/locks") == nil); - menuEnable("multiplayer", getprop("/sim/multiplay/txport") or getprop("/sim/multiplay/rxport")); + menuEnable("multiplayer", multiplayer.is_active()); menuEnable("tutorial-start", size(props.globals.getNode("/sim/tutorials", 1).getChildren("tutorial"))); menuEnable("joystick-info", size(props.globals.getNode("/input/joysticks").getChildren("js"))); diff --git a/Nasal/multiplayer.nas b/Nasal/multiplayer.nas index 428115d9b..7dbbe75c3 100644 --- a/Nasal/multiplayer.nas +++ b/Nasal/multiplayer.nas @@ -9,6 +9,8 @@ # 3) Allow chat messages to be written by the user. +var is_active = func getprop("/sim/multiplay/txport") or getprop("/sim/multiplay/rxport"); + var check_messages = func { foreach (var mp; values(model.callsign)) { @@ -48,13 +50,28 @@ var echo_message = func(callsign, msg) { settimer(func { - # Call-back to ensure we see our own messages. - setlistener("/sim/multiplay/chat", func(n) { - echo_message(getprop("/sim/multiplay/callsign"), n.getValue()); - }); + if (is_active()) { + if (getprop("/sim/multiplay/write-message-log")) { + var ac = getprop("/sim/aircraft"); + var cs = getprop("/sim/multiplay/callsign"); + var (date, time) =_= split("T", getprop("/sim/time/gmt")); + var apt = airportinfo().id; + var file = string.normpath(getprop("/sim/fg-home") ~ "/mp-message.log"); + var f = io.open(file, "a"); + io.write(f, sprintf("\n-- %s -- %s -- %s -- %s -- '%s' --\n", date, time, apt, ac, cs)); + setlistener("/sim/signals/exit", func io.write(f, "--END--\n") and io.close(f)); + setlistener("/sim/messages/mp-plane", func(n) { + io.write(f, sprintf("%s: %s\n", getprop("/sim/time/gmt-string"), n.getValue())); + io.flush(f); + }); + } + check_messages(); + } - # check for new messages - check_messages(); + # Call-back to ensure we see our own messages. + setlistener("/sim/multiplay/chat", func(n) { + echo_message(getprop("/sim/multiplay/callsign"), n.getValue()); + }); }, 1);