a277bbbb by Barry

Added some new things to the login to get character setup rolling

1 parent a757808c
......@@ -727,20 +727,6 @@ class CommandHandler(object):
if callable(command_method):
params = params.lower().strip()
return command_method(id, params, players, mud, tokens, cmd)
# else:
# ldict = locals()
# with open('commands/{}.txt'.format(cmd), 'r', encoding='utf-8') as f:
# command_text = f.read()
# exec(command_text, globals(), ldict)
# del command_text
# if ldict['next_command'] is not None:
# locals()['tokens'] = []
# tokens = []
# with open('commands/{}.txt'.format(ldict['next_command']), 'r', encoding='utf-8') as f:
# exec(f.read())
# del ldict
#raise Exception("Missing command: {}".format(cmd))
except Exception as e:
print('Command handler exception:')
if 'esp' not in sys.platform:
......
......@@ -48,12 +48,15 @@ class MudServer(object):
# the last time we checked if the client was still connected
lastcheck = 0
color_enabled = True
def __init__(self, socket, address, buffer, lastcheck):
self.socket = socket
self.address = address
self.buffer = buffer
self.lastcheck = lastcheck
# Used to store different types of occurences
_EVENT_NEW_PLAYER = 1
_EVENT_PLAYER_LEFT = 2
......@@ -223,20 +226,29 @@ class MudServer(object):
"""
# we make sure to put a newline on the end so the client receives the
# message on its own line
message = multiple_replace(message, get_color_list())
try:
color_enabled = self._clients[to].color_enabled
except KeyError:
color_enabled = False
message = multiple_replace(message, get_color_list(), color_enabled)
if nowrap:
lines = [message]
else:
chunks, chunk_size = len(message), 80 #len(x)/4
lines = [message[i:i + chunk_size] for i in range(0, chunks, chunk_size)]
if color:
if color and self._clients[to].color_enabled:
if isinstance(color, list):
colors = ''.join([get_color(c) for c in color])
self._attempt_send(to, colors + '\r\n'.join(lines) + line_ending + get_color('reset'))
else:
self._attempt_send(to, get_color(color) + '\r\n'.join(lines) + line_ending + get_color('reset'))
else:
self._attempt_send(to, '\r\n'.join(lines) + line_ending + get_color('reset'))
if color_enabled:
self._attempt_send(to, '\r\n'.join(lines) + line_ending + get_color('reset'))
else:
self._attempt_send(to, '\r\n'.join(lines) + line_ending)
def shutdown(self):
"""Closes down the server, disconnecting all clients and
......
......@@ -36,9 +36,12 @@ def get_color(name):
return '\x1b[{}m'.format(codes.get(name, 0))
def multiple_replace(text, replace_words):
def multiple_replace(text, replace_words, color_enabled=True):
for word, replacement in replace_words.items():
text = text.replace(word, get_color(replacement))
if color_enabled:
text = text.replace(word, get_color(replacement))
else:
text = text.replace(word, '')
return text
def save_object_to_file(obj, filename):
......