Mythruna
November 12, 2024, 05:40:14 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome to the new forums. See "Announcements" for a note for new users.
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Scriptable Console Commands  (Read 13628 times)
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« on: August 18, 2011, 06:14:40 AM »

Last night I added the ability to configure custom console commands on the server.  It's entirely up to a particular server configuration which commands are setup and who gets them.  I thought some might be interested in this, though.

As a test, I've implemented a "respawn" command and a "tp" (teleport) command.

The server has had a scripting engine embedded in it for a while now and I use groovy to generate the server status page for the public server.  This is the first chance I've gotten to expand it to handle client-sent console commands.

The way the server is setup right now is that anything in the ./scripts directory that matches *.init.groovy is executed when the server starts up.  Facilities are provided for hooking into the various server events like playerConnected or playerDisconnected.  Groovy makes it kind of nice to make sort of a customized language for dealing with things.  

This latest update also adds the ability to attach console commands to a player when they login.

As an example, here is the one that gives just me the ability to respawn and teleport people:
Code:
on( [playerConnected] ) {
    type, event ->
        
    conn = event.getConnection();
    p = conn.getAttribute( "player" );

    if( !p.get("userInfo.userId").equals( "pspeed" ) )
        return;
        
    println( "Adding admin commands to " + p.get("userInfo.userId") );
    
    addShellCommand( conn, "respawn", "Moves you back to the starting location.", null ) {
        respawn( conn, console );      
    }
 
    addShellCommand( conn, "tp", "Teleports a player.", null ) {
    
/// Snipped code that parses the parameters for clarity...
            console.echo( "Warping " + from + " to:" + x + ", " + y + ", " + z );
            warp( tpPlayer, x + 0.5, y + 0.5, z );                          
        }        
    }
          
}

You can see the on( [event type] ) nice customization that makes it easy to run code on one or more different event types.  The rest checks to see if it's me and then adds the commands.  This could just as easily check to see if the player object has specific permissions, etc..

The point isn't that there is a teleport command here but how easy it is to add.  (This is not a very user friendly teleport and I want to handle in-game teleporting in a different way... I added this because it helps me jump around to the parts of the world that need degriefing.)

Next will be to add a versioning module to the world and then the console backup/restore/etc. commands.  Hopefully that won't take very long and I can get an intermediate release out soon... with the property system to follow in a release 5 or 6 days later.  Then back to physics.

Note: this next version also includes scriptable client tools (you know, where you currently have block types and objects... there will be additional stuff) but that's another story.
« Last Edit: August 18, 2011, 06:19:53 AM by pspeed » Logged
xXxGIBBZxXx
Newbie
*
Posts: 12


View Profile
« Reply #1 on: August 18, 2011, 10:16:59 AM »

Im a little confused... Does this mean that we will be able to configure our own console commands in the next release?
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #2 on: August 18, 2011, 02:42:02 PM »

If you are running your own server and know a little groovy you can write your own commands.  Though for a while the API that the script has access to won't really be documented.
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #3 on: August 18, 2011, 02:42:53 PM »

The interesting part is that this is exposing more modding power, slowly but surely... and from a user perspective it potentially means that I can add more features faster in some cases.
Logged
scorch
Newbie
*
Posts: 36



View Profile
« Reply #4 on: August 19, 2011, 10:00:08 AM »

This only works for Multiplayer? I don't know how mythruna works, but i guess that the easier way to do the singleplayer is to create a server instance in the user's computer, or at least something like this, so, will custom commands work in singleplayer? Smiley
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #5 on: August 19, 2011, 02:21:41 PM »

Single player would actually have an easier time except... there is no way to add them.

The server already had an event system for hooking scripts in every time the player connects or disconnects.  So it was easy for me to add some scripts that configured some new commands for them and then open a way for the clients to send commands directly to the server.  (Most commands go through local proxies first.)

Single player uses the same game code as multiplayer but doesn't have anything like connections or networking or any of that.  It goes directly to the game classes because there's no reason for the extra overhead.

Eventually there will be some support for this in single player mode but I didn't need it for anti-griefing since that's a server problem.  I don't know if single player scripting will make it into this release or not.  I still have to finish custom tools and I may turn it on for that since I'm testing that in single player first.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!