Skip to content

Usergroups and Restrictions

Cody Scott edited this page Aug 18, 2013 · 4 revisions

Certain commands shouldn't be made available to all players. In order to grant specific players access to those commands, you will need to create a password & restricting identifier (e.g. 'admin', 'mod', 'user1') for each user/group which you can then assign to your commands.

Players can access these commands by typing /login {password} where {password} is the password they've been assigned.

Creating More Usergroups


Follow these steps to create a new group:

  1. Open config/base.py
  2. Find the following lines:
passwords = {
    'PASSWORDREPLACEME': ['admin']
}

You should change PASSWORDREPLACEME with a new password used to login as admin 3. To create a new usergroup, add a comma to the end of the second line, and copy the formatting style on a new line:

passwords = {
    'admin_password': ['admin'],
    'mod_password': ['mod']
}

Change admin_password and mod_password to the passwords you wish to use for each group 4. You may now login to either the admin group or the mod group by typing in /login {password} where {password} is 'admin/mod_password' in the example

Restricting A Command


NOTE: By default, the console/terminal that is running the cuwo server will have access to all unrestricted commands, and those restricted to either/both the 'admin' and 'console' usergroup.

To restrict a command to multiple usergroups, follow these two simple steps:

  1. Import restrict from cuwo.script
  2. Add @restrict('group1', 'group2', 'group3') between the @command decorator and the command definition

Example - Changing a command from 'admin' only to 'admin' and 'mod' only

(Before) Quick method for restricting a command to users logged in as 'admin'
from cuwo.script import ServerScript, command, admin


@command
@admin
def say(script, *args):
    message = ' '.join(args)
    script.server.send_chat(message)
(After) Restrict a command to users logged in as 'admin' or 'mod'
from cuwo.script import ServerScript, command, restrict


@command
@restrict('admin', 'mod')
def say(script, *args):
    message = ' '.join(args)
    script.server.send_chat(message)

@restrict Shortcuts


To avoid copying the same @restrict value and needing to edit multiple copies, you may assign a decorator which only requires you to update a single copy.

To change @restrict('admin', 'supermod', 'mod') to @staff, follow these steps:

  1. Below your imports, add staff = restrict('admin', 'supermod', 'mod')
  2. Place @staff between the @command decorator and command definition
(Before) Making repeating changes to a staff group
@command
@restrict('admin', 'supermod', 'mod')
def say(script, *args):
    message = ' '.join(args)
    script.server.send_chat(message)


@command
@restrict('admin', 'supermod', 'mod')
def kick(script, name):
    player = script.get_player(name)
    player.kick()
(After) Making changes to a staff group on one line
staff = restrict('admin', 'supermod', 'mod')


@command
@staff
def say(script, *args):
    message = ' '.join(args)
    script.server.send_chat(message)


@command
@staff
def kick(script, name):
    player = script.get_player(name)
    player.kick()