diff --git a/modular.py b/modular.py index 5de8704..93fa4f1 100644 --- a/modular.py +++ b/modular.py @@ -121,8 +121,8 @@ def alias(self, line): else: line = sublines[0] - if re.match(r'#\d+ .+', line): - match = re.match(r'#(\d+) (.+)', line) + if re.match(self.mud.cmd_char + r'\d+ .+', line): + match = re.match(self.mud.cmd_char + r'(\d+) (.+)', line) times, cmd = match.groups() for i in range(int(times)): if not self.alias(cmd): diff --git a/modules/eval.py b/modules/eval.py index 0b3279c..6a42a9a 100644 --- a/modules/eval.py +++ b/modules/eval.py @@ -4,11 +4,11 @@ class Eval(BaseModule): def alias(self, line): - if line.startswith('#py '): + if line.startswith(self.mud.cmd_char + 'py '): rest = line[4:] self.mud.log("\n" + pformat(eval(rest))) return True - elif line.startswith('#pye '): + elif line.startswith(self.mud.cmd_char + 'pye '): rest = line[5:] exec(rest) return True diff --git a/modules/file_editor.py b/modules/file_editor.py index c3c1e9e..a31ea6c 100644 --- a/modules/file_editor.py +++ b/modules/file_editor.py @@ -22,7 +22,7 @@ def alias(self, line: str) -> bool: elif line.startswith("#edit "): self.send_file(line[6:]) return True - elif line.startswith('#write-file '): + elif line.startswith(self.mud.cmd_char + 'write-file '): self.write_file(line[12:]) return True return False diff --git a/modules/gzlogging.py b/modules/gzlogging.py index 041d511..570bdbe 100644 --- a/modules/gzlogging.py +++ b/modules/gzlogging.py @@ -14,8 +14,8 @@ def quit(self): self.file.close() def alias(self, line): - if line.startswith('#grep '): - arg = line[len('#grep '):] + if line.startswith(self.mud.cmd_char + 'grep '): + arg = line[len(self.mud.cmd_char + 'grep '):] grep = subprocess.Popen(['/bin/sh', '-c', 'tail -n10000 {} | zgrep -a {}'.format(self.logfname, arg)], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = grep.communicate(timeout=5) self.mud.log('\n' + out.decode('utf-8')) diff --git a/modules/logging.py b/modules/logging.py index 5655c34..13d7c4b 100644 --- a/modules/logging.py +++ b/modules/logging.py @@ -12,8 +12,8 @@ def quit(self): self.file.close() def alias(self, line): - if line.startswith('#grep '): - arg = line[len('#grep '):] + if line.startswith(self.mud.cmd_char + 'grep '): + arg = line[len(self.mud.cmd_char + 'grep '):] grep = subprocess.Popen(['/bin/sh', '-c', 'tail -n10000 {} | grep -a {}'.format(self.logfname, arg)], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = grep.communicate(timeout=5) self.mud.log('\n' + out.decode('utf-8')) diff --git a/modules/mapper.py b/modules/mapper.py index c9e9868..a8fbab1 100644 --- a/modules/mapper.py +++ b/modules/mapper.py @@ -511,7 +511,7 @@ def startExit(self, args): self.exitFrom['data'] = dict(zone=room['zone'], terrain = room['terrain']) for k, v in room['exits'].items(): self.exitFrom['exits'][k.lower()] = {'tgt': roomnr(v)} - self.log("Type '#map endexit' when you're in the right room, or #map endexit abort") + self.log(f"Type '{self.mud.cmd_char}map endexit' when you're in the right room, or #map endexit abort") self.exitKw = self.exitKw.replace(';', '\n') self.exitKw = self.exitKw.replace('~', '\n') self.log("Exit: " + repr(self.exitKw)) @@ -739,7 +739,7 @@ def __init__(self, mud, drawAreas, mapfname, spacesInRun=True): def alias(self, line): words = line.split(' ') - if words[0].lower() != '#map': + if words[0].lower() != self.mud.cmd_char + 'map': return if len(words) == 1: diff --git a/modules/scholar.py b/modules/scholar.py index 78f183b..7f94b72 100644 --- a/modules/scholar.py +++ b/modules/scholar.py @@ -148,7 +148,7 @@ def doneTeaching(world, matches): class Scholar(BaseModule): def getAliases(self): return { - '#learnfrom (.+)': learnFrom, + self.mud.cmd_char + 'learnfrom (.+)': learnFrom, } def getTriggers(self): diff --git a/pycat.py b/pycat.py index 82d68d6..a2c2fe9 100755 --- a/pycat.py +++ b/pycat.py @@ -21,6 +21,8 @@ def __init__(self, world_module, port, arg): self.world_module = world_module self.arg = arg self.world = world_module.getClass()(self, self.arg) + self.cmd_char = '#' # The prefix for pycat commands + try: self.socketToPipeR, self.pipeToSocketW, self.stopFlag, runProxy = proxy('::1', port) self.pipeToSocketW = os.fdopen(self.pipeToSocketW, 'wb') @@ -179,7 +181,7 @@ def handle_from_pipe(self): def handle_output_line(self, data): pprint.pprint(data) - if data == '#reload' and self.world: + if data == self.cmd_char + 'reload' and self.world: self.log('Reloading world') try: state = self.world.state @@ -212,8 +214,13 @@ def run(self): self.handle_from_telnet() elif fd == self.socketToPipeR: self.handle_from_pipe() - except Exception as e: - traceback.print_exc() + except (Exception, KeyboardInterrupt) as error: + if type(error) is EOFError: + pass # This simply means the telnet connection was closed. + elif type(error) is KeyboardInterrupt: + raise # pass the user's C^c up to main() + else: + traceback.print_exc() finally: self.log("Closing") self.telnet.close() @@ -228,7 +235,11 @@ def main(): port = int(sys.argv[2]) arg = sys.argv[3] if len(sys.argv) == 4 else None ses = Session(world_module, port, arg) - ses.run() + try: + ses.run() + except KeyboardInterrupt: + print('\nConnection Terminated. Awaiting interrupt to exit program.') + exit(0) # Exit on C^c assert(__name__ == '__main__')