NewPerms branch has been merged

Official Announcements about Source.Python.
User avatar
Ayuto
Project Leader
Posts: 1587
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

NewPerms branch has been merged

Postby Ayuto » Sat May 21, 2016 10:21 am

We have finally merged the NewPerms branch into the master! The main purpose of this branch was to updated the permission system, but we have also developed a new feature called typed commands.

In our Wiki you can find information on how to use the new permission system as a server owner and as a developer.

Tutorials for typed server commands are still missing, so I will just drop a few examples here:

Example #1:

Syntax: Select all

from commands.typed import TypedServerCommand

@TypedServerCommand('multiply')
def on_test(command_info, x:int, y:int):
"""Multiply x and y and print the result."""
print('Result:', x * y)

Output:

Code: Select all

multiply
Not enough arguments:
  multiply <x:int> <y:int>
 
multiply 10 5
Result: 50

multiply 10 5 3
Too many arguments:
  multiply <x:int> <y:int>
 
multiply 10 a
'a' is an invalid value for 'y:int'.

sp help multiply
multiply <x:int> <y:int>
  Multiply x and y and print the result.


Example #2:

Syntax: Select all

from commands.typed import TypedServerCommand

@TypedServerCommand('add')
def on_test(command_info, x:int, y:int=10):
"""Add x and y and print the result."""
print('Result:', x + y)

Output:

Code: Select all

add
Not enough arguments:
  add <x:int> [y:int=10]
 
add 5
Result: 15

add 5 3
Result: 8


Example #3:

Syntax: Select all

from commands.typed import TypedServerCommand

@TypedServerCommand(['test', 'a'])
def on_test(command_info, x):
print('a', x)

@TypedServerCommand(['test', 'b'])
def on_test(command_info, x, y):
print('b', (x, y))

Output:

Code: Select all

test
A sub-command is required:
  test a <x>
  test b <x> <y>
 
test a
Not enough arguments:
  test a <x>
 
test b "Hello, world!"
Not enough arguments:
  test b <x> <y>

test b "Hello, world!" bla
b ('Hello, world!', 'bla')


We have also updated the "sp" command to use the new typed commands.

Code: Select all

sp
A sub-command is required:
  sp auth <sub-command>                     Authorization specific commands.
  sp credits                                List all credits for Source.Python.
  sp delay <delay:float> <command> [*args]  Execute a command after a given delay.
  sp docs <sub-command>                     Documentation specific commands.
  sp dump <sub-command>                     Dump various data to files.
  sp help [command=None] [*sub_commands]    Print all sp sub-commands or help for a
                                              specific command.
  sp list                                   List all currently loaded plugins.
  sp load <plugin>                          Load a plugin.
  sp reload <plugin>                        Reload a plugin.
  sp unload <plugin>                        Unload a plugin.
  sp version                                Display Source.Python version
                                              information.


Summarized, the typed commands (also available for say and client commands) will take care of an abitrary number of sub-commands, the number of arguments, their types (if provided) and default arguments. Btw. you can also define variadic arguments (unlimited arguments) by using *args. You can also print custom error messages if a a type conversion failed or provide your own types like our filter_str type to easily iterate over players. More on that will be added to the Wiki later.

Edit:
Documentation for typed commands is now online!
http://builds.sourcepython.com/job/Sour ... mands.html
User avatar
BackRaw
Senior Member
Posts: 413
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany

Re: NewPerms branch has been merged

Postby BackRaw » Sat May 21, 2016 9:10 pm

Absolutely wonderful :D

I have a question tho, How exactly is the "admin.kick" command defined? I guess "admin" is the plugin and "kick" is a Say/Client/Server command the plugin defines?
necavi
Developer
Posts: 129
Joined: Wed Jan 30, 2013 9:51 pm

Re: NewPerms branch has been merged

Postby necavi » Sat May 21, 2016 11:24 pm

Where exactly in the documentation do you see admin.kick? Most likely that is a permissions node, not actually a command. Permissions nodes are "defined" simply by asking NewPerms if a user has that permission. In the case of a command that is done automatically when a user types the command based on the permissions node you specify.
User avatar
BackRaw
Senior Member
Posts: 413
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany

Re: NewPerms branch has been merged

Postby BackRaw » Sun May 22, 2016 12:06 am

necavi wrote:Where exactly in the documentation do you see admin.kick? Most likely that is a permissions node, not actually a command. Permissions nodes are "defined" simply by asking NewPerms if a user has that permission. In the case of a command that is done automatically when a user types the command based on the permissions node you specify.

Here:

Code: Select all

{
    "[U:1:6456723]": {
        "permissions": [
            "admin.kick",
            "admin.ban"
        ]
    },
    "STEAM_0:323145": {
        "permissions": [
            "fun.rtd"
        ]
    },
    "78944003194": {
        "parents": [
            "administrator"
        ]
    }
}
http://builds.sourcepython.com/job/Source.Python%20-%20Documentation/lastSuccessfulBuild/artifact/cstrike/addons/source-python/docs/source-python/build/general/config-auth.html

So that means the server command 'kick'? :D
necavi
Developer
Posts: 129
Joined: Wed Jan 30, 2013 9:51 pm

Re: NewPerms branch has been merged

Postby necavi » Sun May 22, 2016 12:58 am

Ah, yes. That means the permissions node "admin.kick" which, by convention would be the "admin" module/plugin with a command "kick", yes.
User avatar
BackRaw
Senior Member
Posts: 413
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany

Re: NewPerms branch has been merged

Postby BackRaw » Sun May 22, 2016 1:21 am

Alright, thanks.
User avatar
Ayuto
Project Leader
Posts: 1587
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: NewPerms branch has been merged

Postby Ayuto » Sun May 22, 2016 10:12 pm

Documentation for typed commands is now online!
http://builds.sourcepython.com/job/Sour ... mands.html
User avatar
BackRaw
Senior Member
Posts: 413
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany

Re: NewPerms branch has been merged

Postby BackRaw » Mon May 23, 2016 6:54 am

Just what I needed. Great! :D

Return to “News & Announcements”

Who is online

Users browsing this forum: No registered users and 1 guest