+ print("input " + prefix + ": " + cmd)
+ try:
+ tokens = shlex.split(cmd, comments=True)
+ except ValueError as err:
+ print("Can't tokenize command string: " + str(err) + ".")
+ return
+ if 0 == len(tokens):
+ pass
+ elif "PING" == tokens[0] and 1 == len(tokens):
+ io_db["file_out"].write("PONG\n")
+ elif "QUIT" == tokens[0] and 1 == len(tokens):
+ record("# " + cmd, path_recordfile)
+ raise SystemExit("received QUIT command")
+ elif "MAKE_WORLD" == tokens[0] and 2 == len(tokens):
+ print("I would generate a new world now, if only I knew how.")
+ record(cmd, io_db["path_record"])
+ else:
+ print("Invalid command/argument, or bad number of tokens.")
+
+
+def record(cmd, path_recordfile):
+ """Append cmd string plus newline to file at path_recordfile."""
+ # Doesn't yet replace old record() fully.
+ file = open(path_recordfile, "a")
+ file.write(cmd + "\n")
+ file.close()