This fixes issue #569

This commit is contained in:
lu yijun 2014-09-07 02:22:12 +08:00
parent 46781d3ee1
commit dbbacb4bb3
6 changed files with 82 additions and 13 deletions

View file

@ -21,3 +21,4 @@ class UnloggedinCmdSet(CmdSet):
self.add(unloggedin.CmdUnconnectedQuit())
self.add(unloggedin.CmdUnconnectedLook())
self.add(unloggedin.CmdUnconnectedHelp())
self.add(unloggedin.CmdUnconnectedEncoding())

View file

@ -457,19 +457,21 @@ class CmdEncoding(MuxPlayerCommand):
"""
Sets the encoding.
"""
player = self.player
if self.session is None:
return
if 'clear' in self.switches:
# remove customization
old_encoding = player.db.encoding
old_encoding = self.session.encoding
if old_encoding:
string = "Your custom text encoding ('%s') was cleared." % old_encoding
else:
string = "No custom encoding was set."
del player.db.encoding
self.session.encoding = "utf-8"
elif not self.args:
# just list the encodings supported
pencoding = player.db.encoding
pencoding = self.session.encoding
string = ""
if pencoding:
string += "Default encoding: {g%s{n (change with {w@encoding <encoding>{n)" % pencoding
@ -480,9 +482,9 @@ class CmdEncoding(MuxPlayerCommand):
string = "No encodings found."
else:
# change encoding
old_encoding = player.db.encoding
old_encoding = self.session.encoding
encoding = self.args
player.db.encoding = encoding
self.session.encoding = encoding
string = "Your custom text encoding was changed from '%s' to '%s'." % (old_encoding, encoding)
self.msg(string.strip())

View file

@ -334,6 +334,69 @@ You can use the {wlook{n command if you want to see the connect screen again.
self.caller.msg(string)
class CmdUnconnectedEncoding(MuxCommand):
"""
set which text encoding to use in unconnected-in state
Usage:
@encoding/switches [<encoding>]
Switches:
clear - clear your custom encoding
This sets the text encoding for communicating with Evennia. This is mostly
an issue only if you want to use non-ASCII characters (i.e. letters/symbols
not found in English). If you see that your characters look strange (or you
get encoding errors), you should use this command to set the server
encoding to be the same used in your client program.
Common encodings are utf-8 (default), latin-1, ISO-8859-1 etc.
If you don't submit an encoding, the current encoding will be displayed
instead.
"""
key = "@encoding"
aliases = "@encode"
locks = "cmd:all()"
def func(self):
"""
Sets the encoding.
"""
if self.session is None:
return
if 'clear' in self.switches:
# remove customization
old_encoding = self.session.encoding
if old_encoding:
string = "Your custom text encoding ('%s') was cleared." % old_encoding
else:
string = "No custom encoding was set."
self.session.encoding = "utf-8"
elif not self.args:
# just list the encodings supported
pencoding = self.session.encoding
string = ""
if pencoding:
string += "Default encoding: {g%s{n (change with {w@encoding <encoding>{n)" % pencoding
encodings = settings.ENCODINGS
if encodings:
string += "\nServer's alternative encodings (tested in this order):\n {g%s{n" % ", ".join(encodings)
if not string:
string = "No encodings found."
else:
# change encoding
old_encoding = self.session.encoding
encoding = self.args
self.session.encoding = encoding
string = "Your custom text encoding was changed from '%s' to '%s'." % (old_encoding, encoding)
self.caller.msg(string.strip())
def _create_player(session, playername, password,
default_home, permissions, typeclass=None):
"""

View file

@ -268,9 +268,6 @@ class Player(TypeClass):
changing this method.
"""
# the text encoding to use.
self.db.encoding = "utf-8"
# A basic security setup
lockstring = "examine:perm(Wizards);edit:perm(Wizards);delete:perm(Wizards);boot:perm(Wizards);msg:all()"
self.locks.add(lockstring)

View file

@ -364,7 +364,7 @@ class AMPProtocol(amp.AMP):
"""
#print "msg portal->server (portal side):", sessid, msg, data
return self.safe_send(MsgPortal2Server, sessid,
msg=to_str(msg) if msg is not None else "",
msg=msg if msg is not None else "",
data=dumps(data))
# Server -> Portal message
@ -389,7 +389,7 @@ class AMPProtocol(amp.AMP):
"""
#print "msg server->portal (server side):", sessid, msg, data
return self.safe_send(MsgServer2Portal, sessid,
msg=to_str(msg) if msg is not None else "",
msg=msg if msg is not None else "",
data=dumps(data))
# Server administration from the Portal side

View file

@ -13,7 +13,7 @@ from django.conf import settings
#from src.scripts.models import ScriptDB
from src.comms.models import ChannelDB
from src.utils import logger, utils
from src.utils.utils import make_iter, to_unicode, escape_control_sequences
from src.utils.utils import make_iter, to_unicode, to_str, escape_control_sequences
from src.commands.cmdhandler import cmdhandler
from src.commands.cmdsethandler import CmdSetHandler
from src.server.session import Session
@ -198,7 +198,7 @@ class ServerSession(Session):
"""
if text:
# this is treated as a command input
text = to_unicode(escape_control_sequences(text))
text = to_unicode(escape_control_sequences(text), encoding=self.encoding)
# handle the 'idle' command
if text.strip() == IDLE_COMMAND:
self.update_session_counters(idle=True)
@ -231,6 +231,12 @@ class ServerSession(Session):
"""
Send Evennia -> User
"""
if text is None:
text = ""
else:
text = to_unicode(text)
text = to_str(text, self.encoding)
self.sessionhandler.data_out(self, text=text, **kwargs)
def __eq__(self, other):