Freeciv Forum Index Freeciv
'Cause civilization should be free!
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

HowTo: Set up a FreeCiv LT server from scratch!

 
Post new topic   Reply to topic    Freeciv Forum Index -> Longturn
View previous topic :: View next topic  
Author Message
Munk



Joined: 01 Dec 2008
Posts: 137
Location: The Universe

PostPosted: Thu Dec 18, 2008 1:50 pm    Post subject: HowTo: Set up a FreeCiv LT server from scratch! Reply with quote

I'm a bit of a n00b when it comes to FreeCiv, although I loved Civ I & Civ II and still play SMACX regularly. Last month I took a look at FreeCiv and fell in love all over again. After playing a couple of games, I decided I wanted to set up a server at my house that I could invite some friends from all around the country to play.

Doing so is not exactly an intuitive task if you haven't done that kind of thing before, and I spent a week or so painstakingly googling up the info I needed, and performing successful installations of FreeCiv 2.1.6, Warserver 0.10.2, and finally FreeCiv 2.1.8 - and then I started writing a document detailing the process from bare drive to functioning server accepting client connections.

Part 1 of this document details simply setting up the computer and getting it accepting connections to play games. It's not a very secure setup, so is prolly not useful for setting up a server for general access and announcing it to the world.

Part 2 of this document is unfinished, although I'm including my disorganized notes, and will detail setting up the webservice on your server to at least generate pretty graphs and animated gifs of past games, and possibly (depending on the level of MySQL integration for game status and logging in future versions) even features that used to be available in the old PubServer project.

Anyway, here's the document:

###############################################
Howto: Install FreeCiv LongTurn Server and a webserver for your games in Ubuntu using your home internet connection.

1) Install Ubuntu Desktop on your spare computer (I used 8.10).
http://www.ubuntu.com/getubuntu/download
Download ISO and burn to CD.
Install onto computer.
when it asks for your username, use "freeciv".

2) Install Apache2/PHP5/MySQL5 using Synaptic Package Manager
System > Administration > Synaptic Package Manager
sometimes they don't show up in a search. if that happens, let Ubuntu do all of its updates and restart the computer. then check the Synaptic Package Manager again, and they'll show up in a search.
Make sure to set up a root mysql password when it asks - don't leave it blank.
Your webroot will be in /var/www
Check http://localhost to verify installation

3) Install PHPMyAdmin
sudo apt-get install phpmyadmin
select Apache2 installation in dialog box.
Check http://localhost/phpmyadmin to verify installation. Log in with username "root" and the password you set up previously.

4) Set up an account at no-ip.com and install the no-ip client.
see http://ubuntulinuxhowto.blogspot.com/2006/06/dynamic-dns-no-ip.html
set up a port 80 redirect for your web server domain name (i used port 5550)
set up an A NAME record for your FreeCiv server.
sudo apt-get install no-ip
fill in the info asked and select the domains you set up previously in the step.

5) Set up Ubuntu for static IP address.
http://chrisjohnston.org/2008/set-up-a-static-ip-address-on-your-ubuntu-810-desktop
"address" is the local IP address you want your server to be. I chose 192.168.2.51
"netmask" is almost always 255.255.255.0
"network" is the base IP of your local network. For mine it's 192.168.2.0
"broadcast" i dunno, but 192.168.2.255 worked for me.
"gateway" is the router's local IP address. Mine is 192.168.2.1

Many ISPs and Cable Internet Providers block port 80 and port 8080 to inbound connections. Luckily, No-IP.com allows you to do a port 80 redirect (set up above). You'll need to change the Apache config to handle the connections to the non-standard port for web traffic, and I chose port 5550:
6) Alter apache config to cause Apache to listen to alternate port.
sudo pico /etc/apache2/ports.conf
add a line "Listen 5550" beneath "Listen 80" and save file.
sudo pico /etc/apache2/sites-enabled/000-default
change "<VirtualHost *:80>" to "<VirtualHost *>" and save file.
sudo /etc/init.d/apache2 reload

6) Set up your router to direct traffic to your server.
point your web browser to your router's web interface. (mine's http://192.168.2.1)
On my Dynex Enhanced-G Wireless model, this page is called "Virtual Servers"
set up one for the webservice:
Inbound Port: 5550
Type: TCP
Private IP: 192.168.2.51
Private Port: 5550
then set up one for the FreeCiv service:
Inbound Port: 5556
Type: TCP
Private IP: 192.168.2.51
Private Port: 5556
save your changes and restart your router if needed.

At this point, you can check to make sure the outside world can now get to your webserver by checking the urls you set up at no-ip.com - at the web url you should get the standard Apache "It works!" page. The FreeCiv url won't work yet because we haven't installed FreeCiv. Let's do that now.

7) Install FreeCiv with MySQL Authentication
http://ubuntuforums.org/archive/index.php/t-684027.html
We're installing 2.1.8, so the dance goes like this:
if you chose the username "freeciv", then your home directory is /home/freeciv. Open a terminal window there.
sudo apt-get install build-essential checkinstall libmysqlclient15-dev mysql-server mysql-admin
sudo apt-get build-dep freeciv
wget http://prdownloads.sourceforge.net/freeciv/freeciv-2.1.8.tar.bz2?download
tar -xf freeciv-2.1.8.tar.bz2
cd freeciv-2.1.8
./configure --enable-auth=yes
make
sudo checkinstall -y

Now log into your PHPMyAdmin interface at http://localhost/phpmyadmin and create a database called "freeciv". Since this computer is going to be dedicated as a FreeCiv server, I don't mind it if FreeCiv uses the MySQL root account. You wouldn't do this if anything important shared the database.

bash scripts/setup_auth_server.sh
use "root" as the username and the password you selected earlier.
allow the script to save the password to the config file.

Now we can test the setup by starting the FreeCiv server:
civserver -N -a fc_auth.conf

Test your setup by launching the FreeCiv client on another computer and connecting to your server using the URL you set up at no-ip.com, port 5556. If it connects and you can start a game, congratulations!

Now we need to set up a LongTurn ruleset directory and a server rules file. I use the LTXIII ruleset from longturn.org, which can be found here:
http://www.longturn.org/ruleset-files
copy these files into a new directory at /home/freeciv/freeciv-2.1.8/longturn

Now you can start your LongTurn game! Here's the server settings file I use:
###################### core settings #####################
# SSW Longturn FreeCiv
# 12-10-08
# options are explained here:
# http://freeciv.wikia.com/wiki/Server_options
# starting server command:
# civserver -N -P -e -a fc_auth.conf -r start_freeciv -R ranklog -s savegames
##########################################################
# set the RuleSet directory
rulesetdir longturn
cmdlevel none
# Map Generator/Geology settings
set size=7
set generator=3
set startpos=1
set tinyisles=0
set separatepoles=0
set alltemperate=0
set temperature=50
set landmass=30
set steepness=20
set wetness=50
set specials=500
set huts=100
# Gameplay Settings
set saveturns=1
set savename=SSWlt5
set scorelog=1
set gamelog=30
set civstyle=2
set diplomacy=4
# 24h timeout AND turnblocking, but not fixedtimeout
set timeout=86400
set turnblock=1
set fixedlength=0
set minplayers=4
set maxplayers=10
# Player settings
set startunits=cccccwwwwxxx
set dispersion=3
set gold=50
set techlevel=0
# other settings
set researchcost=20
set techpenalty=80
set diplcost=0
set conquercost=0
set freecost=0
set foodbox=6
set aqueductloss=0
set fulltradesize=1
set notradesize=0
set unhappysize=6
set angrycitizen=1
set cityfactor=30
set happyborders=1
set citynames=2
set barbarians=0
set onsetbarbs=1000
set revolen=0
set diplchance=80
set spacerace=1
set civilwarsize=10
set contactturns=0
set allowtake=HAhad
set autotoggle=0
set endyear=5000
# end game config
#################################


... more coming soon!
[NOTES FOR ADDITIONS BELOW]
(these notes pertain to my desire to resurrect some of the really cool features of the old Pubserver system, and build some new features that will make the webserver you just installed worthwhile.)

PHP SCRIPT FOR WEB SIGNUP HERE (presumably, starting the server without the -N flag will restrict signups from the client - not tested. Ideally, the FCDB authentication table will be used to authenticate the player for the website so that there is a single signup/login for both the game client and for web features. Features can include custom forums with access to individual forums based on userlevel [assuming FCDB contains the players userlevel in the table], Team affiliation [also assuming that is stored in FCDB somewhere], and can include a simple PM system.)

PHP SCRIPT FOR PARSING civscore.log FOR COMPLETED GAMES HERE (want to add the animated game progress gif to this application, but I've posted the current script in the FreeCiv forums already)

PHP SCRIPT FOR SHOWING PLAYER SCORES HERE (this one might not be possible until the forthcoming integration of Warserver features into the main FreeCiv branch. Especially need the additional Warserver MySQL game logging and scoring. Additionally, it would be nice if the game logging linked the player username to the game faction leader name, which it doesn't in the current civscore.log)

(this section is being worked on - i'd like to automate generation of the graphs with an animated gif of the game progress when a game ends, still figuring this part out, but here's what i've found so far)

Animated Gifs of past games can be created using this awesome perl script:
http://old.freeciv.org/~rp/utilities/civpow
you need to install some graphic utilities first:
sudo apt-get install gifsicle
sudo apt-get install netpbm
You can then run the perl script on your saved PPM files:
./civpow -v -e 3 -o fc5.gif savegames/*.ppm
(currently, this script compiles the PPM files in the wrong order and cannot read the gzipped savegame files - todo: among other post-game processing scripts I need to write, build one that unzips the savegame files and reorders/renames them along with renaming the PPMs so that this script can process them in the correct order.)
###############################################

_________________

My Freeciv Server
Back to top
View user's profile Send private message Visit poster's website
book



Joined: 05 Jul 2006
Posts: 761

PostPosted: Thu Dec 18, 2008 2:42 pm    Post subject: Reply with quote

Great guide! Consider putting this information into a "howto" page
on the freeciv wiki (e.g. "Server Howto"). That way others can add
to it and other pages can link to it. There have been a number
of such server setup guides made in the past (see for example
the warclient forums) and it would be nice if they could all be
collected and merged into one master document for easy search
and reference.
Back to top
View user's profile Send private message
Munk



Joined: 01 Dec 2008
Posts: 137
Location: The Universe

PostPosted: Thu Dec 18, 2008 4:13 pm    Post subject: Reply with quote

book wrote:
Great guide! Consider putting this information into a "howto" page
on the freeciv wiki (e.g. "Server Howto"). That way others can add
to it and other pages can link to it.


I will certainly do that once I finish the second part of the HowTo. I'm currently writing some PHP scripts to process the finished gamelogs and generate nice views of past games that are web-accessible. Ideally, I can package those scripts as a download and have the second part of the howto detail how to install and use them.

Depending on how close the porting of the MySQL gamelogging from Warserver to the main FreeCiv branch is, I'd also like to set up other web pages to display that information and player scores, and probably also set up some simple forums that authenticate against the FCDB. In the end, I'm envisioning this HowTo as a step-by-step list for the average joe to set up and run a FreeCiv LongTurn game with some nice social networking additions.

Heh, I know this wish prolly ought to go in the wishlist forum, but I'm wishing real hard for that Warserver-style expanded MySQL integration to make it's way into the main branch soon. Very Happy

_________________

My Freeciv Server
Back to top
View user's profile Send private message Visit poster's website
book



Joined: 05 Jul 2006
Posts: 761

PostPosted: Thu Dec 18, 2008 6:02 pm    Post subject: Reply with quote

Munk wrote:
Heh, I know this wish prolly ought to go in the wishlist forum, but I'm wishing real hard for that Warserver-style expanded MySQL integration to make it's way into the main branch soon. Very Happy

I do plan on working on porting such warclient features to the main
branch, though before that can happen at least the editor code
needs to be finished and the 2.2 borders system fixed. And before
I can focus on that I have to deal with bug reports and patch
submissions... :/

I am glad though, that more people are deciding to contribute
reports and patches. Some more experienced developers helping
to handle these would be welcome. Wink
Back to top
View user's profile Send private message
Munk



Joined: 01 Dec 2008
Posts: 137
Location: The Universe

PostPosted: Thu Dec 18, 2008 7:14 pm    Post subject: Reply with quote

book wrote:
I am glad though, that more people are deciding to contribute
reports and patches. Some more experienced developers helping
to handle these would be welcome. Wink


I'm kinda sad that I know nothing about C programming, although I'm happy to offer my PHP skills for the web-enabled parts. That's about where my expertise ends, tho.

_________________

My Freeciv Server
Back to top
View user's profile Send private message Visit poster's website
Munk



Joined: 01 Dec 2008
Posts: 137
Location: The Universe

PostPosted: Fri Dec 26, 2008 2:53 pm    Post subject: Reply with quote

book wrote:
I do plan on working on porting such warclient features to the main
branch, though before that can happen at least the editor code
needs to be finished and the 2.2 borders system fixed.


I've been doing some further research and I believe I can parse the info I'm wanting from the savegame files (using a script to open up the file and parse the data, and reformatting it for insertion into database tables.) So far, I am able to run a script at the end of a game to parse the savegame files and generate an animated GIF of the game progress map. Extracting out specific data like how many cities and what techs each player has each turn appears to be pretty trivial to do using the same process.

I don't suppose there's any way to make the freeciv server execute a command at the end of each turn and a different one when the game ends? If I could get it to run a perl script at the end of each turn, seems like I could automate my own data parsing scripts that insert the data into MySQL as the game is running turn-by-turn, and then a different script to run at game end to generate a fairly detailed synopsis/score page. Very Happy

I also have a sort of deranged idea about creating a page that a player could log into and get a nicely detailed list of their trade routes and what trade they're generating (assuming I can automatically parse that data from savegame files at the end of each turn).

_________________

My Freeciv Server
Back to top
View user's profile Send private message Visit poster's website
book



Joined: 05 Jul 2006
Posts: 761

PostPosted: Fri Dec 26, 2008 5:13 pm    Post subject: Reply with quote

Munk wrote:
I don't suppose there's any way to make the freeciv server execute a command at the end of each turn and a different one when the game ends? If I could get it to run a perl script at the end of each turn, seems like I could automate my own data parsing scripts that insert the data into MySQL as the game is running turn-by-turn, and then a different script to run at game end to generate a fairly detailed synopsis/score page. Very Happy

Probably cleaner (but less efficient I suppose) would be to have
your perl script run by cron and check what save files exist in
a certain directory (e.g. use the -s option to civserver) and take
appropriate action based on if it already parsed those or not.
You could detect game end via the ranklog file.

If that turns out to be too messy, you can always hack the server
source and put in a call to system("your_script") (read the man
page; be aware that it blocks the main program).
Back to top
View user's profile Send private message
Munk



Joined: 01 Dec 2008
Posts: 137
Location: The Universe

PostPosted: Sun Dec 28, 2008 2:28 pm    Post subject: Reply with quote

book wrote:
Probably cleaner (but less efficient I suppose) would be to have
your perl script run by cron and check what save files exist in
a certain directory (e.g. use the -s option to civserver) and take
appropriate action based on if it already parsed those or not.
You could detect game end via the ranklog file.


Hmmn. that could work. I'll have to give that a try. Thanks!

_________________

My Freeciv Server
Back to top
View user's profile Send private message Visit poster's website
Munk



Joined: 01 Dec 2008
Posts: 137
Location: The Universe

PostPosted: Mon Dec 29, 2008 6:34 pm    Post subject: Reply with quote

book wrote:
You could detect game end via the ranklog file.


I'm not sure if the ranklog file is being properly generated in 2.1.8 - my server start command is:

civserver -N -P -e -a fc_auth.conf -r start_freeciv -R ranklog -s savegames

and while it's reading my auth and start_freeciv files ok, and properly generating a civscore.log file, it's not generating a ranklog file anywhere that I can find.

This post seems to suggest that the ranklog file code is busted. grr. Razz

Oh, well. I'll write my PHP code to run manually to process the gamelogs at game end, i suppose. It's not a huge deal, but it woulda been nice to be able to trigger some things automagically (:

_________________

My Freeciv Server
Back to top
View user's profile Send private message Visit poster's website
book



Joined: 05 Jul 2006
Posts: 761

PostPosted: Mon Dec 29, 2008 7:48 pm    Post subject: Reply with quote

How about this... a lua script event is added for game start,
turn end, and game end? You can then hook your own
lua script into these events and make it do whatever you
need.
Back to top
View user's profile Send private message
Munk



Joined: 01 Dec 2008
Posts: 137
Location: The Universe

PostPosted: Mon Dec 29, 2008 9:05 pm    Post subject: Reply with quote

book wrote:
How about this... a lua script event is added for game start,
turn end, and game end? You can then hook your own
lua script into these events and make it do whatever you
need.


That would rock! Very Happy

[edit] it'd rock even better if the LUA script could be passed certain info, like the filename of the savegame file at turn end- such as the variable set by the "-s" flag and the value set by the "set savename" directive. If these values are present in the environment that the lua script could draw useful variables from, it would be really ideal.

Heh, you'll have to forgive my lack of knowledge on the topic, I just googled up LUA scripting and read a couple tutorials. It looks like something I can figure out, though. [/edit]

_________________

My Freeciv Server
Back to top
View user's profile Send private message Visit poster's website
book



Joined: 05 Jul 2006
Posts: 761

PostPosted: Mon Dec 29, 2008 10:00 pm    Post subject: Reply with quote

I checked the scripting code and there is a "turn_started"
signal, but no "game_start" or "game_end". I suppose these
will have to be added, along with functions that can be used
to get the savefile information.

Unfortunately these are added features, so they won't be
possible for 2.1.x (only bug fixes in that series). If you can't
wait for 2.2 you can always just make a custom hack in the
server sources (e.g. a call to system() as I suggested before).
Back to top
View user's profile Send private message
Munk



Joined: 01 Dec 2008
Posts: 137
Location: The Universe

PostPosted: Mon Dec 29, 2008 10:19 pm    Post subject: Reply with quote

Ahh, well. Maybe when I finish up some of the scripts I have in mind, there'll be a reason to add the hooks to make it automatible. (:

Thanks for letting me know what can and can't be done in the present codebase. That's extremely helpful for figuring out what I can start doing.

_________________

My Freeciv Server
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Freeciv Forum Index -> Longturn All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group