Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modular.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions modules/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion modules/file_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/gzlogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
4 changes: 2 additions & 2 deletions modules/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
4 changes: 2 additions & 2 deletions modules/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion modules/scholar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
19 changes: 15 additions & 4 deletions pycat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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__')
Expand Down