Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Barry
/
esp8266-Mud
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
a277bbbb
authored
2018-05-25 01:24:32 -0700
by
Barry
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Added some new things to the login to get character setup rolling
1 parent
a757808c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
19 deletions
commandhandler.py
mudserver.py
utils.py
weemud.py
commandhandler.py
View file @
a277bbb
...
...
@@ -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
:
...
...
mudserver.py
View file @
a277bbb
...
...
@@ -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
...
...
utils.py
View file @
a277bbb
...
...
@@ -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
):
...
...
weemud.py
View file @
a277bbb
This diff is collapsed.
Click to expand it.
Please
register
or
sign in
to post a comment