Implemented @encoding command as a default way for managing encodings on a per-player level.

This commit is contained in:
Griatch 2010-10-03 20:34:46 +00:00
parent c29649cd53
commit 7080de4022
3 changed files with 58 additions and 1 deletions

View file

@ -29,6 +29,7 @@ class DefaultCmdSet(CmdSet):
self.add(general.CmdWho())
self.add(general.CmdSay())
self.add(general.CmdGroup())
self.add(general.CmdEncoding())
# The help system
self.add(help.CmdHelp())

View file

@ -3,6 +3,7 @@ Generic command module. Pretty much every command should go here for
now.
"""
import time
from django.conf import settings
from src.server import sessionhandler
from src.permissions.models import PermissionGroup
from src.permissions.permissions import has_perm, has_perm_string
@ -650,6 +651,61 @@ class CmdPose(MuxCommand):
## GLOBAL_CMD_TABLE.add_command("@fpose", cmd_fpose)
class CmdEncoding(MuxCommand):
"""
encoding - set a custom text encoding
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"
def func(self):
"""
Sets the encoding.
"""
caller = self.caller
if 'clear' in self.switches:
# remove customization
old_encoding = caller.player.db.encoding
if old_encoding:
string = "Your custom text encoding ('%s') was cleared." % old_encoding
else:
string = "No custom encoding was set."
del caller.player.db.encoding
elif not self.args:
# just list the encodings supported
encodings = []
encoding = caller.player.db.encoding
string = "Supported encodings "
if encoding:
encodings.append(encoding)
string += "(the first one you can change with {w@encoding <encoding>{n)"
encodings.extend(settings.ENCODINGS)
string += ":\n " + ", ".join(encodings)
else:
# change encoding
old_encoding = caller.player.db.encoding
encoding = self.args
caller.player.db.encoding = encoding
string = "Your custom text encoding was changed from '%s' to '%s'." % (old_encoding, encoding)
caller.msg(string)
class CmdGroup(MuxCommand):
"""
group - show your groups

View file

@ -29,7 +29,7 @@ class CmdTest(MuxCommand):
key = "@test"
aliases = ["@te", "@test all"]
#permissions = "cmd:Immortals Wizards"
permissions = "cmd:Immortals Wizards"
# the muxcommand class itself handles the display
# so we just defer to it by not adding any function.