bugFreeciv - Bugs: bug #15644, Add server command to run freeciv...

Show feedback again

bug #15644: Add server command to run freeciv script

Submitted by:  None
Submitted on:  Thu Mar 18 14:48:24 2010  
Category: generalSeverity: 1 - Wish
Priority: 1 - LaterStatus: Fixed
Assigned to: Engla <englabenny>Originator Email: -unavailable-
Open/Closed: ClosedRelease: 
Operating System: NonePlanned Release: 2.3
Contains string changes: None

Add a New Comment (Rich MarkupRich Markup):

You are not logged in

Please log in, so followups can be emailed to you.


(Jump to the original submission Jump to the original submission)

Mon Mar 29 17:36:42 2010, SVN revision 17191:

Add /lua server command to evaluate a line of freeciv script

This script snippet is evaluated inside the current game, and has
access to exactly the same environment as the ruleset or scenario
script, you may even define/override functions.

The /lua command has ALLOW_ADMIN access restrictions.

See gna bug #15644

(Browse SVN revision 17191)

Engla <englabenny>
Project MemberIn charge of this item.
Sat Mar 27 12:21:29 2010, comment #7:

Thanks for the comments. Here is an updated patch.

Engla <englabenny>
Project MemberIn charge of this item.
Thu Mar 25 21:53:16 2010, comment #6:

Some comments about coding style:

  • There is a missing dot at the end of the /lua command documentation.
  • There shouldn't be 3 empty lines in the code (what you added at the beginning of server/stdinhand.c).
pepeto <pepeto>
Project Member
Thu Mar 25 18:34:32 2010, comment #5:

Here is the patch, just in a slightly cleane up version again.

This /lua command is very very convenient when debugging and exploring the lua runtime from the server prompt. If we implement normal_log or a similar function, /lua can be conveniently used for debugging even from the client (lua's print() output is only shown on server's standard output).

Anyone have comments on the command name? /lua or /script? This version of the patch has the command as ALLOW_ADMIN.

Here is a very useful function for listing tables (namespaces, modules and our API types are all tables):

(In one line to be pasted in as function def from the command line)

/lua function dir(T) if T == nil then T = _G end ; local sorted = {}; for key in pairs(T) do table.insert(sorted, key) end ; table.sort(sorted); for index, k in ipairs(sorted) do local v = T[k]; local src = ""; if type(v) == "function" then src = debug.getinfo(v).short_src end; print(string.format("%s \t%-30s\t%s", type(v), tostring(k), src)) end end

use like:

> /lua dir()


> /lua dir(City)

(file #8651)

Engla <englabenny>
Project MemberIn charge of this item.
Sat Mar 20 11:34:28 2010, comment #4:

Once the sanitized environment for scripts is implemented, there should be no way to read scripts from a file or in any way interact with the OS, only the game. Look at the proof-of-concept patch, the codestring given to /lua will be interpreted inside the same namespace as the ruleset and scenario code.

Engla <englabenny>
Project MemberIn charge of this item.
Sat Mar 20 11:14:58 2010, comment #3:

Probably the CTRL access is a bit too low for lot of things. Remember that those command are available from vote (or if someone is alone on a server, all votes pass). Notably to read a script from a file. Maybe will we have to think about many lua command levels. Then HACK would have full access to the functions, ADMIN a bit restricted and CTRL again more?

pepeto <pepeto>
Project Member
Sat Mar 20 11:09:05 2010, comment #2:

Yes, security is absolutely a concern. I didn't think about it before but: Hack access makes sense for the "free scripting" command /lua. However in reality we should allow this at CTRL access. Ideally, scripts can not influence the server, only the game, so CTRL access would be more consistent.

However, every security hole in our script runtime, turns into a remote hole if we allow CTRL access to /lua. Here is an alternative idea to think about:

Allow "triggers" that are similar to the current signal.connect(..) approach. You may register any function call as a custom-named trigger:

in ruleset or scenario script:

function create_new_player()
trigger.connect("createplayer", "create_new_player")


Then we add a /trigger command. The gamemaster or anyone with CTRL access may then say /trigger createnewplayer

So the ruleset may setup triggers like this, and they can be triggered at any time. However it is not as flexible as /lua. Both could be implemented in parallel, with /lua only having hack access. Of course, if we gain trust in our security solution for the script runtime, we can put the "free" version under CTRL access instead.

Engla <englabenny>
Project MemberIn charge of this item.
Thu Mar 18 17:20:22 2010, comment #1:

It looks like an excellent idea for me. However, this needs to be thought about security issues.

pepeto <pepeto>
Project Member
Thu Mar 18 14:48:24 2010, original submission:

This is a wishlist/idea bug.

Add a server command that interprets a string of lua script directly in the current game. (This requires hack access since you may for example give victory immediately or so.)

Proposed command:

/lua <script>

The string given is directly interpreted. A single line of lua script may be setting a variable or even defining a function. Defined variables or functions are persistent. As normal, if you define a function of the same name as a previous function (or callback) you override that function.


/lua print(find.player(1).name)

/lua create_base(find.tile(40,46), "Ruins", nil)

/lua default_hut_enter_callback = function(unit) return not unleash_barbarians(unit.tile) end

This script access may make it drastically easier for tasks like longturn's inserting of players: It can be mostly implemented as a script function in the ruleset and activated via a '/lua createplayer()' command.

Is it feasible? Of course no one is encouraged to major programming during a game, but it might be useful like the longturn example I gave, as well as for editing or experimenting.



(Note: upload size limit is set to 1024 kB, after insertion of the required escape characters.)

Attach File(s):

Attached Files
file #8560:  lua_command.diff added by None (3kB - text/x-patch - Proof of concept implementation)


   bug dependencies.

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by englabenny (Posted a comment)
  • -unavailable- added by pepeto (Posted a comment)
  • -unavailable- added by None (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Error: not logged in



    Follow 10 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon Mar 29 17:37:28 2010englabennyStatusReady For Test=>Fixed
    Sat Mar 27 12:23:08 2010englabennyAttached File-=>Added 0001-Add-lua-server-command-to-evaluate-a-line-of-freeciv.patch, #8670
    Thu Mar 25 18:45:30 2010englabennyDependencies-=>Depends on bugs #15624
    Thu Mar 25 18:34:32 2010englabennyAttached File-=>Added 0001-Add-lua-server-command-to-evaluate-freeciv-script.patch, #8651
      StatusNone=>Ready For Test
      Assigned toNone=>englabenny
      Planned Release=>2.3
    Thu Mar 18 17:20:22 2010pepetoPriority5 - Normal=>1 - Later
    Thu Mar 18 14:48:24 2010NoneAttached File-=>Added lua_command.diff, #8560
    Show feedback again

    Back to the top

    Powered by Savane 3.1-cleanup