|
|
@ -27,24 +27,26 @@ print("Using minetestserver: " + mts) |
|
|
|
print("Using primary_world_path: " + wp) |
|
|
|
print("Using world_name: " + wn) |
|
|
|
print() |
|
|
|
process = None |
|
|
|
try: |
|
|
|
process = subprocess.Popen( |
|
|
|
[mts, '--gameid', game_id, '--worldname', wn], |
|
|
|
stdout=subprocess.PIPE |
|
|
|
stdout=subprocess.PIPE, |
|
|
|
stderr=subprocess.PIPE |
|
|
|
) |
|
|
|
except: |
|
|
|
print(mts + " could not be executed. Try installing the " |
|
|
|
" minetest-server package or compiling from git instructions" |
|
|
|
" on minetest.net") |
|
|
|
exit(1) |
|
|
|
msg_flags = ["WARNING[Server]: ", "ACTION[Server]: "] |
|
|
|
msg_lists = {} # where flag is key |
|
|
|
for flag in msg_flags: |
|
|
|
msg_lists[flag] = [] |
|
|
|
# see https://www.endpoint.com/blog/2015/01/28/getting-realtime-output- |
|
|
|
# using-python |
|
|
|
while True: |
|
|
|
try: |
|
|
|
output_original = process.stdout.readline() |
|
|
|
if output_original == '' and process.poll() is not None: |
|
|
|
break |
|
|
|
if output_original: |
|
|
|
output = output_original.decode("utf-8") |
|
|
|
# works on python2 or 3 |
|
|
|
|
|
|
|
def print_unique_only(output): |
|
|
|
output_strip = output.strip() |
|
|
|
# (output_original is bytes) |
|
|
|
show_enable = True |
|
|
@ -68,6 +70,25 @@ while True: |
|
|
|
if found_flag is not None: |
|
|
|
print("[ mtsenliven.py ] INFO: this is the last" |
|
|
|
" time the message above will be shown") |
|
|
|
|
|
|
|
def process_msg(bstring): |
|
|
|
output = output_original.decode("utf-8") |
|
|
|
# works on python2 or 3 |
|
|
|
print_unique_only(output) |
|
|
|
|
|
|
|
|
|
|
|
while True: |
|
|
|
try: |
|
|
|
output_original = process.stdout.readline() |
|
|
|
err_original = process.stderr.readline() |
|
|
|
if (output_original == '') and \ |
|
|
|
(err_original == '') and \ |
|
|
|
(process.poll() is not None): |
|
|
|
break |
|
|
|
if output_original: |
|
|
|
process_msg(output_original) |
|
|
|
if err_original: |
|
|
|
process_msg(err_original) |
|
|
|
rc = process.poll() |
|
|
|
except KeyboardInterrupt: |
|
|
|
break |
|
|
|