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 18 Mar 2010 02:48:24 PM UTC  
 
Category: generalSeverity: 1 - Wish
Priority: 1 - LaterStatus: Fixed
Assigned to: Engla <englabenny>Originator Email: -unavailable-
Open/Closed: ClosedRelease: 
Operating System: NonePlanned Release: 2.3

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 29 Mar 2010 05:36:42 PM UTC, 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 27 Mar 2010 12:21:29 PM UTC, comment #7:

Thanks for the comments. Here is an updated patch.

Engla <englabenny>
Project MemberIn charge of this item.
Thu 25 Mar 2010 09:53:16 PM UTC, 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 25 Mar 2010 06:34:32 PM UTC, 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()


or

> /lua dir(City)

(file #8651)

Engla <englabenny>
Project MemberIn charge of this item.
Sat 20 Mar 2010 11:34:28 AM UTC, 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 20 Mar 2010 11:14:58 AM UTC, 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 20 Mar 2010 11:09:05 AM UTC, 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()
..
end
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 18 Mar 2010 05:20:22 PM UTC, comment #1:

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

pepeto <pepeto>
Project Member
Thu 18 Mar 2010 02:48:24 PM UTC, 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.

Examples:

/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.

Anonymous

 

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

Attach File(s):
   
   
Comment:
   

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

 

Digest:
   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.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 10 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 29 Mar 2010 05:37:28 PM UTCenglabennyStatusReady For Test=>Fixed
      Open/ClosedOpen=>Closed
    Sat 27 Mar 2010 12:23:08 PM UTCenglabennyAttached File-=>Added 0001-Add-lua-server-command-to-evaluate-a-line-of-freeciv.patch, #8670
    Thu 25 Mar 2010 06:45:30 PM UTCenglabennyDependencies-=>Depends on bugs #15624
    Thu 25 Mar 2010 06:34:32 PM UTCenglabennyAttached 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 18 Mar 2010 05:20:22 PM UTCpepetoPriority5 - Normal=>1 - Later
    Thu 18 Mar 2010 02:48:24 PM UTCNoneAttached File-=>Added lua_command.diff, #8560
    Show feedback again

    Back to the top


    Powered by Savane 3.1-cleanup