Added some new things to the login to get character setup rolling
Showing
4 changed files
with
18 additions
and
17 deletions
... | @@ -727,20 +727,6 @@ class CommandHandler(object): | ... | @@ -727,20 +727,6 @@ class CommandHandler(object): |
727 | if callable(command_method): | 727 | if callable(command_method): |
728 | params = params.lower().strip() | 728 | params = params.lower().strip() |
729 | return command_method(id, params, players, mud, tokens, cmd) | 729 | return command_method(id, params, players, mud, tokens, cmd) |
730 | # else: | ||
731 | # ldict = locals() | ||
732 | |||
733 | # with open('commands/{}.txt'.format(cmd), 'r', encoding='utf-8') as f: | ||
734 | # command_text = f.read() | ||
735 | # exec(command_text, globals(), ldict) | ||
736 | # del command_text | ||
737 | # if ldict['next_command'] is not None: | ||
738 | # locals()['tokens'] = [] | ||
739 | # tokens = [] | ||
740 | # with open('commands/{}.txt'.format(ldict['next_command']), 'r', encoding='utf-8') as f: | ||
741 | # exec(f.read()) | ||
742 | # del ldict | ||
743 | #raise Exception("Missing command: {}".format(cmd)) | ||
744 | except Exception as e: | 730 | except Exception as e: |
745 | print('Command handler exception:') | 731 | print('Command handler exception:') |
746 | if 'esp' not in sys.platform: | 732 | if 'esp' not in sys.platform: | ... | ... |
... | @@ -48,12 +48,15 @@ class MudServer(object): | ... | @@ -48,12 +48,15 @@ class MudServer(object): |
48 | # the last time we checked if the client was still connected | 48 | # the last time we checked if the client was still connected |
49 | lastcheck = 0 | 49 | lastcheck = 0 |
50 | 50 | ||
51 | color_enabled = True | ||
52 | |||
51 | def __init__(self, socket, address, buffer, lastcheck): | 53 | def __init__(self, socket, address, buffer, lastcheck): |
52 | self.socket = socket | 54 | self.socket = socket |
53 | self.address = address | 55 | self.address = address |
54 | self.buffer = buffer | 56 | self.buffer = buffer |
55 | self.lastcheck = lastcheck | 57 | self.lastcheck = lastcheck |
56 | 58 | ||
59 | |||
57 | # Used to store different types of occurences | 60 | # Used to store different types of occurences |
58 | _EVENT_NEW_PLAYER = 1 | 61 | _EVENT_NEW_PLAYER = 1 |
59 | _EVENT_PLAYER_LEFT = 2 | 62 | _EVENT_PLAYER_LEFT = 2 |
... | @@ -223,20 +226,29 @@ class MudServer(object): | ... | @@ -223,20 +226,29 @@ class MudServer(object): |
223 | """ | 226 | """ |
224 | # we make sure to put a newline on the end so the client receives the | 227 | # we make sure to put a newline on the end so the client receives the |
225 | # message on its own line | 228 | # message on its own line |
226 | message = multiple_replace(message, get_color_list()) | 229 | |
230 | try: | ||
231 | color_enabled = self._clients[to].color_enabled | ||
232 | except KeyError: | ||
233 | color_enabled = False | ||
234 | |||
235 | message = multiple_replace(message, get_color_list(), color_enabled) | ||
227 | if nowrap: | 236 | if nowrap: |
228 | lines = [message] | 237 | lines = [message] |
229 | else: | 238 | else: |
230 | chunks, chunk_size = len(message), 80 #len(x)/4 | 239 | chunks, chunk_size = len(message), 80 #len(x)/4 |
231 | lines = [message[i:i + chunk_size] for i in range(0, chunks, chunk_size)] | 240 | lines = [message[i:i + chunk_size] for i in range(0, chunks, chunk_size)] |
232 | if color: | 241 | if color and self._clients[to].color_enabled: |
233 | if isinstance(color, list): | 242 | if isinstance(color, list): |
234 | colors = ''.join([get_color(c) for c in color]) | 243 | colors = ''.join([get_color(c) for c in color]) |
235 | self._attempt_send(to, colors + '\r\n'.join(lines) + line_ending + get_color('reset')) | 244 | self._attempt_send(to, colors + '\r\n'.join(lines) + line_ending + get_color('reset')) |
236 | else: | 245 | else: |
237 | self._attempt_send(to, get_color(color) + '\r\n'.join(lines) + line_ending + get_color('reset')) | 246 | self._attempt_send(to, get_color(color) + '\r\n'.join(lines) + line_ending + get_color('reset')) |
238 | else: | 247 | else: |
248 | if color_enabled: | ||
239 | self._attempt_send(to, '\r\n'.join(lines) + line_ending + get_color('reset')) | 249 | self._attempt_send(to, '\r\n'.join(lines) + line_ending + get_color('reset')) |
250 | else: | ||
251 | self._attempt_send(to, '\r\n'.join(lines) + line_ending) | ||
240 | 252 | ||
241 | def shutdown(self): | 253 | def shutdown(self): |
242 | """Closes down the server, disconnecting all clients and | 254 | """Closes down the server, disconnecting all clients and | ... | ... |
... | @@ -36,9 +36,12 @@ def get_color(name): | ... | @@ -36,9 +36,12 @@ def get_color(name): |
36 | return '\x1b[{}m'.format(codes.get(name, 0)) | 36 | return '\x1b[{}m'.format(codes.get(name, 0)) |
37 | 37 | ||
38 | 38 | ||
39 | def multiple_replace(text, replace_words): | 39 | def multiple_replace(text, replace_words, color_enabled=True): |
40 | for word, replacement in replace_words.items(): | 40 | for word, replacement in replace_words.items(): |
41 | if color_enabled: | ||
41 | text = text.replace(word, get_color(replacement)) | 42 | text = text.replace(word, get_color(replacement)) |
43 | else: | ||
44 | text = text.replace(word, '') | ||
42 | return text | 45 | return text |
43 | 46 | ||
44 | def save_object_to_file(obj, filename): | 47 | def save_object_to_file(obj, filename): | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment