def command(cmd, name, admin=False, guest=False):
def wrapper(user, params):
if admin and not user.isAdmin:
user.writeln(name, " requires administrator privileges.")
return False
if user.isGuest and not guest:
user.writeln(name, " requires you to login first.")
return False
cmd(user, params)
return True
return wrapp
@command("ban", admin=True)
def cmd_ban(user, params):
user.writeln("Banning that scumbag!")
# ban user specific in params[0]
@command("who", guest=True)
def cmd_who(user, params):
user.writeln("Current users:")
# send list of users to the user
@command("quit")
def cmd_quit(user, params):
user.writeln("Goodbye!")
user.disconnect()
command(name: 'ban', admin: true, func: function(user, params) begin
// command's code
end)
class CommandBan extends Command:
function requireAdmin() begin
return true
end
function getName() begin
return "ban"
end
function command(user, params) begin
# finally able to write the damn command body
end
end
Classes, modules, and objects are interrelated. In the diagram that
follows, the vertical arrows represent inheritance, and the
parentheses meta-classes. All metaclasses are instances of the
class `Class'.
+——————+
| |
Object—->(Object) |
^ ^ ^ ^ |
| | | | |
| | +—–+ +———+ |
| | | | |
| +———–+ | |
| | | | |
+——+ | Module—>(Module) |
| | ^ ^ |
OtherClass–>(OtherClass) | | |
| | |
Class—->(Class) |
^ |
| |
+—————-+
You need access to the mobile's private data when saving, but not when performing a command.
Furthermore, certain commands may be usable by players who don't have a mobile instance. For example in my mud, the 'who' command can be used without needing to log on first.