Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-19 Thread Michal Mazurek
I made a git repo for longturn from svn (about 500MB)
git clone git://git.longturn.org/longturn.git

-- 
Michal Mazurek

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-19 Thread Michal Mazurek
On Tue, Nov 15, 2011 at 09:48:07PM +0100, Matthias Pfafferodt wrote:
> > Yes; I did a check and due to the changes in trunk these patches do not
> > apply anymore. I will try to create a patch set which can be used on top
> > of the longturn branch. I will use the lt.diff from 29. October as a
> > starting point.
> 
> Done; see attached file. I did focus on patches by me. Thus, some bug fixes 
> could be missing! It implements all the lua changes done for S2_4

After applying the patch, and compiling with
'./autogen.sh --disable-nls --disable-client --enable-fcdb=postgres'
I get the following error:

libtool: link: ar cru .libs/libaicore.a  aisupport.o path_finding.o pf_tools.o 
cm.o citymap.o caravan.o
libtool: link: ranlib .libs/libaicore.a
libtool: link: ( cd ".libs" && rm -f "libaicore.la" && ln -s "../libaicore.la" 
"libaicore.la" )
gmake[4]: Leaving directory `/home/dude/src/freeciv/common/aicore'
Making all in scriptcore
gmake[4]: Entering directory `/home/dude/src/freeciv/common/scriptcore'
../../dependencies/tolua-5.1/src/bin/tolua -n common_a -o 
./tolua_common_a_gen.c \
-H ./tolua_common_a_gen.h ./tolua_common_a.pkg
gmake[4]: ../../dependencies/tolua-5.1/src/bin/tolua: Command not found
gmake[4]: *** [tolua_common_a_gen.c] Error 127
gmake[4]: Leaving directory `/home/dude/src/freeciv/common/scriptcore'
gmake[3]: *** [all-recursive] Error 1
gmake[3]: Leaving directory `/home/dude/src/freeciv/common'
gmake[2]: *** [all] Error 2
rm packets_generate
gmake[2]: Leaving directory `/home/dude/src/freeciv/common'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/home/dude/src/freeciv'
gmake: *** [all] Error 2

I noticed the patch you made removes ltauth.[ch], can you explain a bit to
me what my next step is, if I want to write auth as a lua script?

> If you plan to continue to support S2_3, I think it would be easier to rebase 
> all longturn patches to S2_4 and do one patch which changes the network 
> protocol to be compatible to S2_3. An advantage is that you could easily 
> switch to the new version. As you do plan to do auth and newcommers / 
> respawn(?) in lua, the diff would also be smaller.

Well, hopefuly after rewriting all patches to lua there will be no problem
in rebasing to S2_4. Only the patches that substitute nation name for player
name will be left.

Frankly, I don't know why I was so reluctant to lua before - it seems a really
great idea!

-- 
Michal Mazurek

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-17 Thread Michal Mazurek
On Wed, Nov 16, 2011 at 10:38:15PM +0100, Matthias Pfafferodt wrote:
> Am Mittwoch, 16. November 2011, 19:47:45 schrieb Michal Mazurek:
> > On Tue, Nov 15, 2011 at 09:48:07PM +0100, Matthias Pfafferodt wrote:
> > > The hardest part is the
> > > transmission of the veteran ruleset definitions (IMHO).
> > 
> > Speaking of veterans, while looking at freecivs png files i noticed
> > there are four more veteran levels graphics. Did freeciv use to have 8
> > veteran levels?
> 
> Freeciv 2.3 supports up to 10 veteran levels but only 4 are used; in 2.4 this 
> will be increased to 20 levels which can be different for different units. 
> See 
> the experimental ruleset for an example (settlers).

This is great! Here are the values I think I'll use for LTeX:

veteran_names = _("green"), _("veteran 1"), _("veteran 2"), _("veteran 3"), 
_("hardened 1"), _("hardened 2"), _("hardened 3"), _("elite 1 "), _("elite 2"), 
_("elite 3")
veteran_raise_chance = 50, 45, 40, 35, 30, 25, 20, 15, 10, 0
veteran_power_fact = 100, 150, 175, 200, 225, 250, 275, 300, 325, 350
veteran_work_raise_chance = 12, 9, 9, 9, 7, 7, 7, 5, 5, 5
veteran_move_bonus = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9


-- 
Michal Mazurek

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-16 Thread Matthias Pfafferodt
Am Dienstag, 15. November 2011, 22:24:29 schrieb Marko Lindqvist:
> On 15 November 2011 22:48, Matthias Pfafferodt
> 
>  wrote:
> > If you plan to continue to support S2_3, I think it would be easier to
> > rebase all longturn patches to S2_4 and do one patch which changes the
> > network protocol to be compatible to S2_3.
> 
>  ...
> 
> > I attached a file with the diff between S2_3 and S2_4 for packets.def.
> > Most of the work to be done is to remove S2_4 features. The hardest part
> > is the transmission of the veteran ruleset definitions (IMHO).
> 
>  Please note that there's more to network compatibility than
> packets.def changes.  While it lists all the packet fields there is in
> the network protocol, legal ranges of those values can change outside
> it, and even meaning of any single value (for example when value is
> removed from the middle of enum) can change.

You are right. All the other things also have to be compared / checked. 
Yesterday evening I did create such a hack. The client 2.3 can connect but 
there are still some bugs as settlers can't build cities ...
From 45f5bc822f9e52c5943eb2ccd67be315dbc21e6b Mon Sep 17 00:00:00 2001
From: Matthias Pfafferodt 
Date: Tue, 15 Nov 2011 23:30:19 +0100
Subject: [PATCH 1/2] use S2_3 protocol by S2_4 server (longturn)

---
 common/citizens.c |   10 +++---
 common/game.h |3 +-
 common/map.h  |6 +---
 common/packets.def|   70 ++--
 common/requirements.c |   22 ---
 common/requirements.h |   22 +++
 common/unit.c |7 -
 fc_version|4 +-
 server/citizenshand.c |4 +-
 server/citytools.c|   18 
 server/cityturn.c |6 ++--
 server/edithand.c |5 ---
 server/gamehand.c |7 +++--
 server/maphand.c  |   15 --
 server/plrhand.c  |   13 +
 server/ruleset.c  |   58 +++-
 server/savegame2.c|8 +++---
 server/srv_main.c |6 +---
 server/unittools.c|4 +--
 19 files changed, 86 insertions(+), 202 deletions(-)

diff --git a/common/citizens.c b/common/citizens.c
index f54c50f..5397412 100644
--- a/common/citizens.c
+++ b/common/citizens.c
@@ -32,7 +32,7 @@ void citizens_init(struct city *pcity)
 {
   fc_assert_ret(pcity);
 
-  if (game.info.citizen_nationality != TRUE) {
+  if (TRUE) {
 return;
   }
 
@@ -73,7 +73,7 @@ void citizens_free(struct city *pcity)
 citizens citizens_nation_get(const struct city *pcity,
  const struct player_slot *pslot)
 {
-  if (game.info.citizen_nationality != TRUE) {
+  if (TRUE) {
 return 0;
   }
 
@@ -105,7 +105,7 @@ void citizens_nation_add(struct city *pcity, const struct player_slot *pslot,
 {
   citizens nationality = citizens_nation_get(pcity, pslot);
 
-  if (game.info.citizen_nationality != TRUE) {
+  if (TRUE) {
 return;
   }
 
@@ -144,7 +144,7 @@ void citizens_nation_move(struct city *pcity,
 void citizens_nation_set(struct city *pcity, const struct player_slot *pslot,
  citizens count)
 {
-  if (game.info.citizen_nationality != TRUE) {
+  if (TRUE) {
 return;
   }
 
@@ -163,7 +163,7 @@ citizens citizens_count(const struct city *pcity)
   /* Use int here to check for an possible overflow at the end. */
   int count = 0;
 
-  if (game.info.citizen_nationality != TRUE) {
+  if (TRUE) {
 return city_size_get(pcity);
   }
 
diff --git a/common/game.h b/common/game.h
index 5a30ca9..316ed93 100644
--- a/common/game.h
+++ b/common/game.h
@@ -158,6 +158,7 @@ struct civ_game {
   int unitwaittime;   /* minimal time between two movements of a unit */
   int upgrade_veteran_loss;
   bool vision_reveal_tiles;
+  int base_bribe_cost;
 
   bool debug[DEBUG_LAST];
   int timeoutint; /* increase timeout every N turns... */
@@ -570,7 +571,7 @@ extern struct civ_game game;
 #define GAME_UNIT_BRIBE_DIST_MAX 32
 
 /* Max number of recursive transports. */
-#define GAME_TRANSPORT_MAX_RECURSIVE 5
+#define GAME_TRANSPORT_MAX_RECURSIVE 1
 
 /* ruleset settings */
 
diff --git a/common/map.h b/common/map.h
index 9e70dee..35fe7a4 100644
--- a/common/map.h
+++ b/common/map.h
@@ -574,7 +574,7 @@ extern const int DIR_DY[8];
  * below. */
 #define MAP_DEFAULT_SIZE 4
 #define MAP_MIN_SIZE 0
-#define MAP_MAX_SIZE 2048
+#define MAP_MAX_SIZE 128
 
 FC_STATIC_ASSERT(MAP_MAX_SIZE * 1000 <= MAX_DBV_LENGTH,
  map_too_big_for_bitvector);
@@ -585,9 +585,7 @@ FC_STATIC_ASSERT(MAP_MAX_SIZE * 1000 <= MAX_DBV_LENGTH,
 
 /* This defines the maximum linear size in _map_ coordinates. */
 #define MAP_DEFAULT_LINEAR_SIZE  64
-/* 32 * 1024 is 2^15; thus, x*y is <= 2^15 * 2^15 = 2^30. This can be
- * represented by an signed int as required by the network protocol. */
-#define MAP_MAX_LINEAR_SIZE  (32 * 1024)
+#define MAP_MAX_LINEAR_SIZE  512
 #define MAP_MIN_

Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-16 Thread Matthias Pfafferodt
Am Mittwoch, 16. November 2011, 19:47:45 schrieb Michal Mazurek:
> On Tue, Nov 15, 2011 at 09:48:07PM +0100, Matthias Pfafferodt wrote:
> > The hardest part is the
> > transmission of the veteran ruleset definitions (IMHO).
> 
> Speaking of veterans, while looking at freecivs png files i noticed
> there are four more veteran levels graphics. Did freeciv use to have 8
> veteran levels?

Freeciv 2.3 supports up to 10 veteran levels but only 4 are used; in 2.4 this 
will be increased to 20 levels which can be different for different units. See 
the experimental ruleset for an example (settlers).

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-16 Thread Michal Mazurek
On Tue, Nov 15, 2011 at 09:48:07PM +0100, Matthias Pfafferodt wrote:
> The hardest part is the 
> transmission of the veteran ruleset definitions (IMHO).

Speaking of veterans, while looking at freecivs png files i noticed
there are four more veteran levels graphics. Did freeciv use to have 8
veteran levels?

-- 
Michal Mazurek

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-15 Thread Michal Mazurek
On Tue, Nov 15, 2011 at 10:11:58PM +0200, Marko Lindqvist wrote:
> On 15 November 2011 21:52, Michal Mazurek  wrote:
> >  a ruleset I download from dubious sources does
> > not, from it's script.lua, run a file i already have on my filesystem,
> > that's nasty. Even though it could just contain it,
> 
>  You consider all files already in your system something that everyone
> should be allowed to read/use? It could hardly contain something that
> its author does not know contents of.
> Not that I can come up with any real attack scenario offhand, but
> better to be safe than sorry.

Can there at least be a GNU-style flag like --allow-lua-dofile?

-- 
Michal Mazurek

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-15 Thread Marko Lindqvist
On 15 November 2011 22:48, Matthias Pfafferodt
 wrote:
>
> If you plan to continue to support S2_3, I think it would be easier to rebase
> all longturn patches to S2_4 and do one patch which changes the network
> protocol to be compatible to S2_3.

 ...

> I attached a file with the diff between S2_3 and S2_4 for packets.def. Most of
> the work to be done is to remove S2_4 features. The hardest part is the
> transmission of the veteran ruleset definitions (IMHO).

 Please note that there's more to network compatibility than
packets.def changes.  While it lists all the packet fields there is in
the network protocol, legal ranges of those values can change outside
it, and even meaning of any single value (for example when value is
removed from the middle of enum) can change.


 - ML

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-15 Thread Marko Lindqvist
On 15 November 2011 21:52, Michal Mazurek  wrote:
>  a ruleset I download from dubious sources does
> not, from it's script.lua, run a file i already have on my filesystem,
> that's nasty. Even though it could just contain it,

 You consider all files already in your system something that everyone
should be allowed to read/use? It could hardly contain something that
its author does not know contents of.
Not that I can come up with any real attack scenario offhand, but
better to be safe than sorry.


 - ML

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-15 Thread Michal Mazurek
On Tue, Nov 15, 2011 at 07:11:10PM +0100, Matthias Pfafferodt wrote:
> > In S2_3 there is only lua that executes a line of lua code. There is no
> > functionality to load a file, I'll try to backport it to my repo
> > tomorrow.
> > 
> > 
> > Frankly, I dont understand how that helps with security. If you are the
> > administrator you can do anything anyway, so why restrict yourself?
> > Could you please provide a scenario when dofile can lead to something
> > nasty?
> 
> This restriction is a long time thing for freeciv. This prevents bad script 
> from doing nasty things, or do you check all scripts you run (new rulesets, 
> etc)? Also, not everybody who runs a server is an admin and knows what can 
> happen if there is something hidden in a script file.

I still don't get it. Where does the included nasty code come from in
the first place? Or differently: why do you assume script.lua is ok,
while something that's included is not? From what I understand, this
restriction is so that a ruleset I download from dubious sources does
not, from it's script.lua, run a file i already have on my filesystem,
that's nasty. Even though it could just contain it, instead of dofileing
it in the first place. dofile in lua is just like #include in c. I
really see no harm in allowing it.

-- 
Michal Mazurek

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-15 Thread Matthias Pfafferodt
Am Dienstag, 15. November 2011, 11:26:49 schrieb Michal Mazurek:
> On Mon, Nov 14, 2011 at 09:40:51PM +0100, Matthias Pfafferodt wrote:
> > missed an important thing:
> > 
> > The needed patches are only in S2_4 and trunk; you have to pick svn20274-
> > sv20277 and svn20286-svn20296. These patches do not change the network
> > interface. Thus, they should be easily be backported to S2_3.
> 
> I have trouble applying those revisions.
> 
> This is what i do:
> [11:17:ttyp9][dude@hopek:~:3]$ cat /tmp/diff
> git svn log -p -r 20274 > /tmp/lua/20274
> git svn log -p -r 20275 > /tmp/lua/20275
> git svn log -p -r 20276 > /tmp/lua/20276
> git svn log -p -r 20277 > /tmp/lua/20277
> git svn log -p -r 20286 > /tmp/lua/20286
> git svn log -p -r 20287 > /tmp/lua/20287
> git svn log -p -r 20288 > /tmp/lua/20288
> git svn log -p -r 20289 > /tmp/lua/20289
> git svn log -p -r 20290 > /tmp/lua/20290
> git svn log -p -r 20291 > /tmp/lua/20291
> git svn log -p -r 20292 > /tmp/lua/20292
> git svn log -p -r 20293 > /tmp/lua/20293
> git svn log -p -r 20294 > /tmp/lua/20294
> git svn log -p -r 20295 > /tmp/lua/20295
> git svn log -p -r 20296 > /tmp/lua/20296
> 
> Run this script after 'git checkout master'
> Run 'git checkout S2_3-lua' which is a branch i created from the
> remotes/S2_3 branch.
> Try to apply the first revision:
> [11:18:ttyp6][dude@hopek:~/src/freeciv:65]$ patch -p1 < /tmp/lua/20274
> 
> Get many errors:
> [lots of output]
> Hunk #1 failed at 0.
> 1 out of 1 hunks failed--saving rejects to

Yes; I did a check and due to the changes in trunk these patches do not apply 
anymore. I will try to create a patch set which can be used on top of the 
longturn branch. I will use the lt.diff from 29. October as a starting point.

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-15 Thread Matthias Pfafferodt
> > > Why can't i dofile() in freeciv?
> > 
> > The usage of such commands is restricted due to security implications.
> > You can not load a lua file! Only default.lua and script.lua are read.
> > Or you have to use the command 'lua file <...>' (I think it is named
> > luafile in S2_3).
> 
> In S2_3 there is only lua that executes a line of lua code. There is no
> functionality to load a file, I'll try to backport it to my repo
> tomorrow.
> 
> 
> Frankly, I dont understand how that helps with security. If you are the
> administrator you can do anything anyway, so why restrict yourself?
> Could you please provide a scenario when dofile can lead to something
> nasty?

This restriction is a long time thing for freeciv. This prevents bad script 
from doing nasty things, or do you check all scripts you run (new rulesets, 
etc)? Also, not everybody who runs a server is an admin and knows what can 
happen if there is something hidden in a script file.

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-15 Thread Michal Mazurek
On Tue, Nov 15, 2011 at 06:27:31PM +0100, Matthias Pfafferodt wrote:
> Am Dienstag, 15. November 2011, 10:59:47 schrieb Michal Mazurek:
> > On Mon, Nov 14, 2011 at 10:09:56AM +0100, Michal Mazurek wrote:
> > > Can i have other files than the default.lua and script.lua? I want each
> > > functionality (auth, newcomers) to be in a separate file.
> > 
> > I added dofile("longturn.lua") to script.lua. This is what i got:
> > 
> > 1: lua error:
> > data/longturn/script.lua:56: attempt to call global 'dofile' (a nil 
> value)
> > stack traceback:
> > data/longturn/script.lua:56: in main chunk
> > 0: "data/longturn/script.lua": could not load ruleset script.
> > 
> > 
> > Why can't i dofile() in freeciv?
> 
> The usage of such commands is restricted due to security implications. You 
> can 
> not load a lua file! Only default.lua and script.lua are read. Or you have to 
> use the command 'lua file <...>' (I think it is named luafile in S2_3).

In S2_3 there is only lua that executes a line of lua code. There is no
functionality to load a file, I'll try to backport it to my repo
tomorrow.


Frankly, I dont understand how that helps with security. If you are the
administrator you can do anything anyway, so why restrict yourself?
Could you please provide a scenario when dofile can lead to something
nasty?

-- 
Michal Mazurek

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-15 Thread Matthias Pfafferodt
Am Dienstag, 15. November 2011, 10:59:47 schrieb Michal Mazurek:
> On Mon, Nov 14, 2011 at 10:09:56AM +0100, Michal Mazurek wrote:
> > Can i have other files than the default.lua and script.lua? I want each
> > functionality (auth, newcomers) to be in a separate file.
> 
> I added dofile("longturn.lua") to script.lua. This is what i got:
> 
> 1: lua error:
>   data/longturn/script.lua:56: attempt to call global 'dofile' (a nil 
value)
> stack traceback:
> data/longturn/script.lua:56: in main chunk
> 0: "data/longturn/script.lua": could not load ruleset script.
> 
> 
> Why can't i dofile() in freeciv?

The usage of such commands is restricted due to security implications. You can 
not load a lua file! Only default.lua and script.lua are read. Or you have to 
use the command 'lua file <...>' (I think it is named luafile in S2_3).

> 
> The version is S2_3, I'm yet to apply the svn revisions Matthias said I
> should

This will not help for the problem you describe above as the handling of these 
functions did not change.

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-15 Thread Michal Mazurek
On Mon, Nov 14, 2011 at 09:40:51PM +0100, Matthias Pfafferodt wrote:
> missed an important thing:
> 
> The needed patches are only in S2_4 and trunk; you have to pick svn20274-
> sv20277 and svn20286-svn20296. These patches do not change the network 
> interface. Thus, they should be easily be backported to S2_3.

I have trouble applying those revisions.

This is what i do:
[11:17:ttyp9][dude@hopek:~:3]$ cat /tmp/diff
git svn log -p -r 20274 > /tmp/lua/20274
git svn log -p -r 20275 > /tmp/lua/20275
git svn log -p -r 20276 > /tmp/lua/20276
git svn log -p -r 20277 > /tmp/lua/20277
git svn log -p -r 20286 > /tmp/lua/20286
git svn log -p -r 20287 > /tmp/lua/20287
git svn log -p -r 20288 > /tmp/lua/20288
git svn log -p -r 20289 > /tmp/lua/20289
git svn log -p -r 20290 > /tmp/lua/20290
git svn log -p -r 20291 > /tmp/lua/20291
git svn log -p -r 20292 > /tmp/lua/20292
git svn log -p -r 20293 > /tmp/lua/20293
git svn log -p -r 20294 > /tmp/lua/20294
git svn log -p -r 20295 > /tmp/lua/20295
git svn log -p -r 20296 > /tmp/lua/20296

Run this script after 'git checkout master'
Run 'git checkout S2_3-lua' which is a branch i created from the
remotes/S2_3 branch.
Try to apply the first revision:
[11:18:ttyp6][dude@hopek:~/src/freeciv:65]$ patch -p1 < /tmp/lua/20274

Get many errors:
[lots of output]
Hunk #1 failed at 0.
1 out of 1 hunks failed--saving rejects to server/scripting/api_actions.c.rej
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--
|diff --git a/server/scripting/api_actions.h b/server/scripting/api_actions.h
|deleted file mode 100644
|index 871038a..000
|--- a/server/scripting/api_actions.h
|+++ /dev/null
--
Patching file server/scripting/api_actions.h using Plan A...
Empty context always matches.
Hunk #1 failed at 0.
1 out of 1 hunks failed--saving rejects to server/scripting/api_actions.h.rej
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--
|diff --git a/server/scripting/api_auth.c b/server/scripting/api_auth.c
|deleted file mode 100644
|index df568f5..000
|--- a/server/scripting/api_auth.c
|+++ /dev/null
--
File to patch: 

I kill it after this, since it waits for some input.

Some chunks succeed, some fail. I use OpenBSD's patch, not GNU patch, if
that matters.

This is `git stat` after trying to apply the first diff:
[11:22:ttyp6][dude@hopek:~/src/freeciv:67]$ git stat
# On branch S2_3-lua
# Changes not staged for commit:
#   (use "git add ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
#   modified:   common/Makefile.am
#   modified:   configure.ac
#   modified:   manual/Makefile.am
#   modified:   server/auth.c
#   modified:   server/citytools.c
#   modified:   server/cityturn.c
#   modified:   server/diplhand.c
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#   common/scriptcore/
no changes added to commit (use "git add" and/or "git commit -a")

What is curious, is that previous commits are empty:
[11:24:ttyp6][dude@hopek:~/src/freeciv:76]$ git svn log -p -r 20273 

[11:25:ttyp6][dude@hopek:~/src/freeciv:77]$ git svn log -p -r 20272 

r20271 fixes some bug in the client so it is not relevant.


-- 
Michal Mazurek

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-15 Thread Michal Mazurek
On Mon, Nov 14, 2011 at 10:09:56AM +0100, Michal Mazurek wrote:
> Can i have other files than the default.lua and script.lua? I want each
> functionality (auth, newcomers) to be in a separate file.

I added dofile("longturn.lua") to script.lua. This is what i got:

1: lua error:
data/longturn/script.lua:56: attempt to call global 'dofile' (a nil 
value)
stack traceback:
data/longturn/script.lua:56: in main chunk
0: "data/longturn/script.lua": could not load ruleset script.


Why can't i dofile() in freeciv?

The version is S2_3, I'm yet to apply the svn revisions Matthias said I
should

-- 
Michal Mazurek

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-14 Thread Matthias Pfafferodt
missed an important thing:

The needed patches are only in S2_4 and trunk; you have to pick svn20274-
sv20277 and svn20286-svn20296. These patches do not change the network 
interface. Thus, they should be easily be backported to S2_3.


Am Montag, 14. November 2011, 21:26:43 schrieben Sie:
> Hello Michal,
> 
> Am Montag, 14. November 2011, 10:09:56 schrieb Michal Mazurek:
> > Now that i finished the new website i want to move the c patches to lua.
> > I guess I'll start with postgres authentication.
> 
> good idea - I will help as much as I can!
> 
> I think I have somewhere an old patch which starts to implement respawn in
> lua.
> 
> > I have some questions though:
> > Can the lua scripts be reloaded while the server is running?
> 
> The lua files for the database can be reloaded (database.lua - use 'fcdb
> reload'); about the files used for the game (default.lua, script.lua) I'm
> not sure. I think the command 'lua file ' will reload
> this files in the context of the game lua script.
> 
> > Can i have other files than the default.lua and script.lua? I want each
> > functionality (auth, newcomers) to be in a separate file.
> 
> The freeciv database (auth) and the game engine are two separate lua
> instances. They are completely separated. As stated above, one is defined
> in database.lua while the other is loaded from default.lua and script.lua.
> 
> For authentication I hacked up a database.lua file for postgres. Perhaps
> you could get it to a cleanup state (timestamps, etc.) and post it as
> patch? The attached files include the database.lua file as well as the
> command to start the server and an exemplary config file. The sql
> statement to create the databases is included in the database.lua file.
> 
> > I'm collecting statistics and generating plots:
> > http://longturn.org/game/LTeX23/ . Maybe this can be incorporated into
> > freeciv? Right now i write statistics to files called (T%03d) % turn,
> > and then parse them with perl and generate plots with gnuplot. Freeciv
> > already generates gifs of the map across time, plots would be a nice
> > addition.
> 
> Did you check the freeciv log file? It does something like this! In the
> forum some time ago scripts were posted which load this data and create
> plots. Perhaps it can be reused?
> 
> Matthias (aka syntron)

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] Moving Longturn patches to Lua

2011-11-14 Thread Matthias Pfafferodt
Hello Michal,

Am Montag, 14. November 2011, 10:09:56 schrieb Michal Mazurek:
> Now that i finished the new website i want to move the c patches to lua.
> I guess I'll start with postgres authentication.

good idea - I will help as much as I can!

I think I have somewhere an old patch which starts to implement respawn in 
lua.
 
> I have some questions though:
> Can the lua scripts be reloaded while the server is running?

The lua files for the database can be reloaded (database.lua - use 'fcdb 
reload'); about the files used for the game (default.lua, script.lua) I'm not 
sure. I think the command 'lua file ' will reload this files 
in the context of the game lua script.

> Can i have other files than the default.lua and script.lua? I want each
> functionality (auth, newcomers) to be in a separate file.

The freeciv database (auth) and the game engine are two separate lua 
instances. They are completely separated. As stated above, one is defined in 
database.lua while the other is loaded from default.lua and script.lua.

For authentication I hacked up a database.lua file for postgres. Perhaps you 
could get it to a cleanup state (timestamps, etc.) and post it as patch? The 
attached files include the database.lua file as well as the command to start 
the server and an exemplary config file. The sql statement to create the 
databases is included in the database.lua file.

> I'm collecting statistics and generating plots:
> http://longturn.org/game/LTeX23/ . Maybe this can be incorporated into
> freeciv? Right now i write statistics to files called (T%03d) % turn,
> and then parse them with perl and generate plots with gnuplot. Freeciv
> already generates gifs of the map across time, plots would be a nice
> addition.

Did you check the freeciv log file? It does something like this! In the forum 
some time ago scripts were posted which load this data and create plots. 
Perhaps it can be reused?

Matthias (aka syntron)
-- **
-- basic postgres functions
-- **

-- luasql postgres
local sql = luasql.postgres()
local dbh = nil

-- connect to the database (or stop with an error)
local function connect()
  local err -- error message

  if dbh then
dbh:close()
  end

  -- Load the database parameters.
  local database = fcdb.option(fcdb.param.DATABASE)
  local user = fcdb.option(fcdb.param.USER)
  local password = fcdb.option(fcdb.param.PASSWORD)
  local host = fcdb.option(fcdb.param.HOST)

  dbh, err = sql:connect(database, user, password, host)
  if not dbh then
log.error('[postgres:connect]: %s', err)
return fcdb.status.ERROR
  else
return fcdb.status.TRUE
  end
end

-- execute a sql query
local function execute(query)
  local res -- result handle
  local err -- error message

  if not dbh then
return fcdb.status.ERROR, "[execute] Invalid database handle."
  end

  log.verbose("Postgres query: %s", query)

  res, err = dbh:execute(query)
  if not res then
log.error("[postgres:execute]: %s\nquery: %s", err, query)
return fcdb.status.ERROR, err
  else
return fcdb.status.TRUE, res
  end
end


-- **
-- The freeciv database tables can be created with the following:
--
-- FIXME: update postgres tables!
--
-- CREATE TABLE fcdb_auth (
--   id SERIAL NOT NULL,
--   name varchar(48) default NULL,
--   password varchar(32) default NULL,
--   email varchar(128) default NULL,
--   createtime integer default NULL,
--   accesstime integer default NULL,
--   address varchar(255) default NULL,
--   createaddress varchar(15) default NULL,
--   logincount integer default '0',
--   PRIMARY KEY  (id)
-- );
--
-- CREATE TABLE fcdb_log (
--   id SERIAL NOT NULL,
--   name varchar(32) default NULL,
--   logintime integer default NULL,
--   address varchar(255) default NULL,
--   succeed char(1) default 'S',
--   PRIMARY KEY  (id)
-- );
--
-- N.B. if the tables are not of this format, then the select, insert,
--  and update syntax in the following functions must be changed.
-- **

-- **
-- freeciv user auth functions
-- **

-- load user data
function user_load(conn)
  local status  -- return value (status of the request)
  local res -- result handle
  local numrows -- number of rows in the sql result
  local row -- one row of the sql result
  local query   -- sql query

  local fields = 'password'

  local table_user = fcdb.option(fcdb.param.TABLE_USER)
  local table_log = fcdb.option(fcdb.param.TABLE_LOG)

  if not dbh then
log.error("Missing database connection ...")
return fcdb.status.ERROR
  end

  local username = dbh:escape(auth.get_username(conn))