PDA

View Full Version : Utility Linux Admining


Gandalf Parker
September 1st, 2006, 01:39 PM
To answer the question in another thread that started this:

To admin remotely in text mode you have to login to a text-mode terminal. Two popular protocols are telnet and ssh. You can find terminal emulation programs that give you added features at your end which can be quite useful. I like NetTerm but its been a really REALLY long time since Ive looked at what was out there available.

Gandalf Parker
September 1st, 2006, 01:51 PM
Here is an example of a script I use to start a Dom3 game.
--------------------------
GAME=Armaggedon
PORT=7373

cd /home/dom3/dominions3
DIR=~/dominions3/savedgames/$GAME
mkdir $DIR

nice dom3 -T --makemap $GAME \
--mapaa --mapsize 1000 1000 --mapprov 250

nohup nice dom3 -g $GAME --port $PORT -STdddddddddd \
--preexec $DIR/pre_$GAME.sh \
--postexec $DIR/post_$GAME.sh \
--mapfile $GAME.map \
--era 3 --hofsize 15 --indepstr 6 \
--totalvp 18 --requiredvp 15 --summervp \
--magicsites 35 --renaming \
--hours 24 -q \
>>$DIR/$GAME.log 2>>$DIR/$GAME.err &

touch $DIR/pre_$GAME.sh
touch $DIR/post_$GAME.sh
chmod +x $DIR/*.sh

Gandalf Parker
September 1st, 2006, 02:02 PM
It looks like alot but its simple to use. You just change the first two lines to start a new game. The GAME and PORT variables.

Then it makes a gamesave directory. I know that the game makes one once the game starts but I need it before that.

This script generates a random map for the game to use that is named the same as the game. In this case, Armageddon. Thats a new Dom3 feature. When people join the game they will get the map sent to them. There are many map switches if you want to mess with them. Just add them there.
Just insert a # and remark it out if you dont want a random map. Change the --mapfile setting from $GAME to whatever map you want to use.

The game call itself adds many things you might not want. the ddddd heavy level of debug creates HUGE logs but they are fun to look at. You can change that to one d or take it off completely. I direct all of the games text responses to a log and the errors to an err file named for the game. In this case Armaggedon.log and Armageddon.err

the last 3 lines make sure that you have a pre and post shell that are in the right place and executable. They start out empty but you can easily edit them anytime even if the game has already started. They are great for various cleanup or management needs that popup.

Digest that abit and then I will put up a more complicated one. >:)

tibbs
September 1st, 2006, 03:15 PM
Thanks for all the useful info. I want to avoid using Telnet because it doesn't encrypt but I will look into NetTerm and SSH.

And this will take me a long time to digest. I just learned about the touch command and I think I need to re-read it because I have forgotten.

And it looks like I need to learn how to create scripts. This should keep me busy over the weekend.

Thanks,
Chris

Gandalf Parker
September 1st, 2006, 04:52 PM
Any commands you can type in to run can be put into a text file. If you make it executable (chmod +x file) then it becomes a script. You only have to iron out all of the steps one time. Then you put them into a script and forget all that trial and error you did.

The touch was a trick. It usually updates the creation date. But if the file doesnt exist then it makes one. That way you safely create a file but if one is already there then you wont destroy it.

alexti
September 2nd, 2006, 03:04 AM
I'd recommend PuTTY, especially if your client desktop is Windows.

Arker
September 2nd, 2006, 05:08 PM
Gandalf Parker said:
Any commands you can type in to run can be put into a text file. If you make it executable (chmod +x file) then it becomes a script.



It also helps to put the magic numbers in.

#!/bin/sh

should be the very first thing in the file.

And to make sure the permissions are right

chmod 755 file

Gandalf Parker
September 2nd, 2006, 06:33 PM
The script I did isnt shell specific. Some later ones I do have a shell line since they use special shell variables for things like randoms.

And yeah I guess for public info its probably best to chmod 755 but +x for executable seems easier for people to remember even if it is sloppy.

Of course for public info I probably shouldnt have mentioned telnet since trying to argue down ssh is something only security people would do.

So did everyone follow that script? No questions?

tibbs
September 5th, 2006, 02:39 PM
I didn't get a chance to try it yet. I was busy with painting a few rooms in the house. Hopefully early this week.

Bluebird
September 10th, 2006, 08:21 PM
Just as a hint: I am normally hosting games on unix using the 'screen' command. It is a like a 'window manager' for text consoles and has many features (too many to list them here). The nicest one is that you can 'detach' a terminal session which continues running even if you logout, and later 'reattach' to that terminal session on next login.

Gandalf Parker
September 10th, 2006, 10:00 PM
PRE hosting script
------------------

GAME="Armageddon"
DIR="/home/dom3/dominions3/savedgames/"$GAME
WEB="/home/dom3/public_html/games/"$GAME

# make backups
#maybe later I will make it rotating backups
zip -9 $GAME.zip $DIR/*

# blank the log file since it grows by about 5 meg each turn
# this way Im only logging one turn at a time
cp /dev/null $DIR/$GAME.log

# update the viewable copies of the shell files
cp /home/dom3/dominions3/$GAME.sh $WEB/$GAME_sh.txt
cp $DIR/pre_$GAME.sh $WEB/pre_$GAME_sh.txt
cp post_$GAME.sh $WEB/post_$GAME_sh.txt

# mark the time and load at the beginning of hosting
echo pre >>$DIR/system_load.txt
uptime >>$DIR/system_load.txt

Gandalf Parker
September 10th, 2006, 10:04 PM
POST hosting script
-------------------
$GAME="Armageddon"
DIR="/home/dom3/dominions3/savedgames/"$GAME
WEB="/home/dom3/public_html/games/"$GAME

# mark time and system load after host processing
#and make it available for viewing in the games web dir
echo post >>$DIR/system_load.txt
uptime >>$DIR/system_load.txt
echo " " >>$DIR/system_load.txt
cp $DIR/system_load.txt $WEB/system_load.txt

# rotate the score html files
mv $WEB/scores-4.html $WEB/scores-5.html
mv $WEB/scores-3.html $WEB/scores-4.html
mv $WEB/scores-2.html $WEB/scores-3.html
mv $WEB/scores-1.html $WEB/scores-2.html
mv $WEB/scores.html $WEB/scores-1.html
cp $DIR/scores.html $WEB/scores.html
cp $DIR/stats.txt $WEB/stats.txt

# zip up the debug log and then zero the log
zip -9 $DIR/$GAME.zip $DIR/$GAME.log
mv $DIR/$GAME.zip $WEB/$GAME.zip
cp $DIR/$GAME.log "$DIR/OLD"$GAME".log"
cp /dev/null $DIR/$GAME.log

# email notify players that have asked to be told of turns
cat $DIR/notify.txt |/usr/sbin/sendmail gandalf@example.com
cat $DIR/notify.txt |/usr/sbin/sendmail bogus@example.net

Gandalf Parker
September 10th, 2006, 10:17 PM
the notify.txt that is sent to players
--------------------------------------

Subject: the Armageddon game processed

Your turn is ready at
dom3minions.com

(courtesy of Gandalf Parker at Any1can.net)

----------------------------------------

the notification could also be changed to include the turn number. It could also easily be changed to include emailing the turn file.

Which makes you automatically think PbEM. If a game had its own email address such as armageddon@dom3minons.com then something like procmail could manage incoming emails to place the .2h files (which means "to host") into the game directory. It could also kick off a script to check for all turns being in and then run/quit the host. This would raise the number of games that a server can run by many levels.

Gandalf Parker
September 14th, 2006, 05:38 PM
I just realized that maybe this will interest some people....
Gandalf Parker

usage: dom3 [option(s)] [gamename]
options:
-v --version Print version number and exit
-d Increase debug level
-g --host Generate new turn and exit
--verify Verify all 2h-files and exit (creates .chk files)
--statfile Create a player info file after each turn (stats.txt)
--scoredump Create a score file after each turn (scores.html)
--finalhost Generate new turn, send out final score msg and exit
-c --nocredits Disables the end credits
******* Network Options *******
-C --tcpclient Connect to a Dominions multiplayer server
-S --tcpserver Start a Dominions multiplayer server
--ipadr XXX Use this IP-adr when connecting to server
--port X Use this port nbr
--preexec CMD Execute this command before each turn generation
--postexec CMD Execute this command after each turn generation
-t --hosttime X Y Host on day X (0=sunday) hour Y (0-23)
--minutes X Set host interval in minutes
-h --hours X Set host interval in hours
--pauseday X Stop timer on this day (0=sunday)
-q --quickhost Host as soon as all turns are done
-n --nonationsel No nation selection when resuming a network game
--noclientstart Clients cannot start the game during Choose Participants
--uploadtime X Game is created after this many minutes.
--uploadmaxp X Game is created if this many players join.
--closed X Nation closed X=nation number (0-79)
--easyai X Nation ai controlled X=nation number (0-79)
--normai X Nation ai controlled X=nation number (0-79)
--diffai X Nation ai controlled X=nation number (0-79)
--mightyai X Nation ai controlled X=nation number (0-79)
--impai X Nation ai controlled X=nation number (0-79)
******* New Game Options *******
--mapfile XXX Filename of map. E.g. eye.map
--randmap X Make and use a random map with X prov per player (10,15,20)
--research X Research difficulty 0-3 (default 1)
--hofsize X Size of Hall of Fame 5-15 (default 10)
--indepstr X Strength of Independents 0-9 (default 5)
--magicsites X Magic site frequency 0-75 (default 40)
--eventrarity X Random event rarity 1-2, 1=common 2=rare
--totalvp X Vic. points available in the world 0-25
--capitalvp One extra victory per capital
--requiredvp X Vic. points required for victory (default total/2)
--summervp Vic. points are accumulated each summer
--richness X Money multiple 50-300 (default 100)
--resources X Resource multiple 50-300 (default 100)
--supplies X Supply multiple 50-300 (default 100)
--masterpass XX Master password. E.g. masterblaster
--startprov X Number of starting provinces (1-9)
--renaming Enable commander renaming
--noscoregraphs Disable score graphs
--nonationinfo No info at all on other nations
--era X New game created in this era (1-3)
-M --enablemod XXX Enable the mod with filename XXX
******* Random Map Options *******
--makemap XXX Generate a random map with filename XXX and exit
--riverpart X 100 = normal amount of rivers, 0=no rivers
--seapart X Percent of map that is below water level (default=30)
--mountpart X Percent of map that is mountains (default=20)
--forestpart X Percent of lands that are forests (default=20)
--farmpart X Percent of lands that are farm lands (default=15)
--wastepart X Percent of lands that are wastes (default=10)
--swamppart X Percent of lands that are swamps (default=10)
--mapaa Enable antialiasing for random maps
--mapsize W H Set width and height of random map (default=1600 1200)
--mapprov X Set number of provinces (default=150)
--passmount Don't use impassable mountains on random maps
--mapgcol RGBA Ground color 0-255 (default=170 146 116 255)
--mapscol RGBA Sea color 0-255 (default=54 54 130 255)
--mapbcol RGBA Ground border color 0-255 (x4)
--mapsbcol RGBA Sea border color 0-255 (x4)
--mapnoise X Ground color noise 0-255 (default 15)
--borderwidth X Border width 0-500 (default 100)
******* Video Options *******
-w --window Run Dominions 3 in a window
-u --fullscreen Use the entire screen
--bitplanes X Try to use a color depth of X bits per pixel
--zbuffer X Try to use a depth buffer of X bits per pixel (default=16)
-T --textonly Use this with --tcpserver to get graphicless server
--gamma X Set gamma function (brightness) 0.1 - 5.0 (default=1.0)
--opacity X Set gui opacity 0 - 100
-r --res X Y Set screen resolution / window size (default=800 600)
--animback Use animated backgrounds
-a --noanimback Don't use animated backgrounds
--fade Use fade effects
-f --nofade No fade effects
--nopopups No helpful popups
--fps X Aim for this nbr of frames per second (default=20)
--maxfps X Maximum nbr of frames per second (default=50)
--filtering X Quality of OpenGL filtering 0-3 (default=2)
--maxtexsize X Max texture size in pixels 32-4096 (default=unlimited)
--treequal X Tree quality 1-5 (default=3)
--texqual X Texture quality 1-5 (default=3)
--nolightfx No light effects in battles
--partamount X Max nbr of particles 0-8 (0=none, 4=default, 8=max)
--nograss Don't draw the grass
--noarcade Don't draw floating damage numbers
--noglext Don't use any OpenGL extensions
--vsync Enable vsync
-V --novsync Disable vsync
--renderpath X Use different optimizations 0-1 (0=good for low mem cards)
-x --fastgrx Faster graphics (use 3 times for best performance (-xxx))
-p --perftest Run a performance test and exit
******* Audio Options *******
-s --nosound No sound effects or music
-m --nomusic No music
--musicvol X Set music volume, 0-100
--clickvol X Set mouse click volume, 0-100
--defsound Use default sound device
--directsound Use direct sound
--waveout Use waveout for sound
Example: dom3 -wm Run Dominons 3 in a window and without music

Gandalf Parker
September 19th, 2006, 12:11 PM
OK all of you Linux people. Have fun with THIS one. This is my bl_game.sh for creating small blitz games.
<font class="small">Code:</font><hr /><pre>
#!/bin/bash

OP1=`echo $RANDOM % 79|bc`
OP2=`echo $RANDOM % 79|bc`
OP3=`echo $RANDOM % 79|bc`
for OP in $OP1 $OP2 $OP3
do
if [ $OP -eq 25 ]
then $OP=0
fi
done

PORT=7777
PTtest=1
until [ $PTtest -eq 0 ]; do
PORT=`echo $RANDOM % 1000 + 8000|bc`
PTtest=`netstat -an|grep -c :$PORT`
done

MPASS=`makepasswd`
WURDnum=`echo $RANDOM$RANDOM % 118614 |bc`
WURD=`egrep "^....$|^.....$|^......$|^.......$|^........$|^.... .....$" \
/usr/share/dict/words|head -$WURDnum|tail -1`
GAME=bl_$WURD
MAP=eye.map
DIR=~/dominions3/savedgames/$GAME
ERA=$1
if [ -z "$1" ]
then
ERA=`echo $RANDOM % 3 + 1 |bc`
fi

DESC=" era $ERA game $GAME on port $PORT "
echo $DESC
#with $OP1 $OP2 $OP3
# --normai $OP1 --normai $OP2 --normai $OP3 \

dom3 -T --makemap $GAME --mapaa --mapsize 640 480 --mapprov 30
MAP=$GAME.map
echo $DESC
mkdir $DIR

nohup dom3 -g $GAME --port $PORT -ST --statfile --scoredump \
--preexec $DIR/pre.sh --postexec $DIR/post.sh \
--era $ERA --indepstr 6 --hofsize 15 --magicsites 65 \
--renaming --mapfile $MAP --masterpass $MPASS \
-q --hours 24 &gt;$DIR/game.log 2&gt;$DIR/game.err &amp;

echo $DESC &gt;&gt;BLITZ_games.txt

PID=`ps a | grep $GAME | grep dom3 | cut -d" " -f2`
echo "kill -9 "$PID &gt;$DIR/kill.sh
echo $MPASS &gt;$DIR/master.txt
ls -blart /tmp/dominion* |tail -1 &gt;$DIR/tmp.sh
echo " " &gt;$DIR/pre.sh
echo " " &gt;$DIR/post.sh

chmod +x $DIR/*.sh

# to stop the game immeadaitely after start
# unremark the next line
#cp $DIR/kill.sh $DIR/post.sh

echo "mv ~/dominions3/maps/$GAME.* $DIR/" &gt;$DIR/pre.sh
echo "cp /dev/null $DIR/pre.sh" &gt;&gt;$DIR/pre.sh

echo "cp $DIR/game.log $DIR/~game.log" &gt;$DIR/post.sh
echo "cp /dev/null $DIR/game.log" &gt;&gt;$DIR/post.sh
</pre><hr />

Gandalf Parker
September 19th, 2006, 12:23 PM
Some highlists on that blitz script...

It selects random opponents (presently rem'd out in its use)

It selects a random port and it tests to see if that port is in use

It creates a random password and uses that as the master password for the game

It chooses a random word from the system spelling dictionary and uses that as the game name (some very interesting results have come from that)

It chooses a random era

It creates a random map for the game of 640x480 and 30 provinces. Suitable for a 2 or 3 player blitz game

It creates a game log and a game error file

It adds the games description (game name, port, settings) to a BLITZ_games.txt so that if I whip off 10 quick new games I can just upload that text to announce them

It creates a quick-kill shell in the games directory

It creates pre and post shells.

Sets up the pre shell to move the blitz map to the game directory once the game starts. That saves on cleanup of the games later.

Sets up the post shell to rotate the logs which can get very large depending on how many d's you use on the games command line

Any questions?

Neophyte
September 30th, 2006, 12:56 AM
Does the IP address need to be specified (in the script) if one is IP forwarding through a firewall? If so, the address needs to be the address that remote clients will be using, correct? I hope I got the terminology right.

Thank's!

Gandalf Parker
September 30th, 2006, 12:01 PM
I understand your question but Im afraid that I dont know the answer. I dont know of any way to tell the game which IP to run on. I think that when hosting, the game only concerns itself with port. So if the clients address hits the firewall, and the firewall forwards it to the right machine, things should be transparent to the user. But Im afraid thats just guesswork on my part.

By the way, Dom3 handles both IP or domain name for the server. Thats something I have tested quite abit. So Im able to send people to either 63.199.8.158 OR dom3minions.com for a game. (also 63.199.8.157 host.dom3minions.com which I use for blitz games)

Neophyte
September 30th, 2006, 03:07 PM
Upon reflection, the whole IP thing is probably a switch issue not a computer issue anyhow - i.e. addyX:portZ internally is in all ways equivalent to addyY:portZ externally with IP forwarding setup. Should have thought of this last night, but it was late, and my networking knowledge is sporadic.

Thank's for the reply - I'll test out your scripts once Dom3 shows up hopefully next week.

Gandalf Parker
October 14th, 2006, 12:08 PM
PbEM scripting has been ironed out. The key is two switches which will start a game hosting automatically. The thread where this was discussed fully is at
http://www.shrapnelcommunity.com/threads/showflat.php?Cat=&amp;Board=dom3&amp;Number=451270&amp;Forum=f 187

The switches are:
--uploadtime
--uploadmaxp

Gandalf Parker
October 17th, 2006, 03:22 PM
Im rather proud of this altho it will make others cringe at its ugliness. I wanted a way for people to check which games need players. Doing an "ls" of the game directory from a CGI was easy enough but I realized that instead of using "ls" of the directorys as fact that the game exists, I should use the "ps". Then starting a game will automatically cause it to show, and if a game finishes or crashes then it will automatically not appear. I also arranged for it to pull the port from the ps display and show that.
http://host.dom3minions.com/bin/blitz_chk.cgi

<font class="small">Code:</font><hr /><pre>
#!/bin/bash
echo "Content-type: text/html"
echo -e "\n\n"

echo "&lt;H2&gt;&lt;b&gt;Dominions 3 Blitz games&lt;/b&gt;&lt;/H2&gt;"
echo "These are 2-player games on tiny maps&lt;br&gt;"
echo '&lt;a href="http://host.dom3minions.com/how-to.html"&gt;how to join a game&lt;/a&gt;&lt;b
r&gt;&lt;br&gt;'


cd /home/dom3/dominions3/savedgames
ps ax |grep dom3|grep bl_ | \
while read n n n n n n game n port n n n n n n n n era n
do
echo "era $era game &lt;b&gt;$game&lt;/b&gt; on port &lt;b&gt;$port&lt;/b&gt;&lt;br&gt;"
cd $game
for fyle in `ls -1 *.2h`
do
echo $fyle "&lt;br&gt;"
done
cd /home/dom3/dominions3/savedgames
echo "&lt;br&gt;"
done
</pre><hr />

Gandalf Parker
November 28th, 2006, 07:14 PM
Not much reaction to the fancy stuff. Maybe I shoud move the other direction...

Here is the simplest way to start a game in linux text mode so that you can be the server....

dom3 -STq
(take note that is a Q as in quick, not a G like in game)
it will ask you what port to use..
it will ask you to name the game..
it will ask you what era the game should be for
it will then wait for people to join and tell you each time someone does

When one of the players hits the "start game" then it will stop to show you a list of all the maps on your machine numbered, then ask you to type in the number of the map you want to use.

What it will NOT do is tell the machine to keep running the game in the background if you hang up your connection. I will cover that next.

Gandalf Parker

Gandalf Parker
November 28th, 2006, 07:37 PM
The simplest way to start a game in text mode on a linux server for continual running.. well there isnt one. The problem is that telling it to run continual and background tends to cut off your ability to answer the questions. I havent been able to get the answers to work coming from a text file with something like &lt;input.txt. So you will need to provide the answers on one line.

The simplest line I can come up with is..
nohup dom3 -STq fastgame --port 9999 --mapfile eye.map --era 1 &amp;
(again thats a Q not a G)
Of course you can change "fastgame" to any name you want, and 9999 to any port, eye.map to the map file for any map you have in the maps directory, and era to 1 2 or 3.

If you want to play with adding other settings then type
dom3 -h
which will give you a text screen of all the switches.

Gandalf Parker

Tals
January 6th, 2007, 08:54 AM
Great thread GP. I'm keen to run it from the text line and not have it running unattended - i.e always in a window. Is there a way of stopping it refreshing once a minute?

Also are there any commands you can give it whilst in text mode?

Tals

Gandalf Parker
January 23rd, 2007, 05:33 PM
Sorry that I didnt notice this.

There is no way to stop it refreshing. I tend to run it to a file then use a file viewer.

As far as I know there are no commands that will work on it when its running text mode. I prefer to script the starts of all of my games since any changes or updates involve having to stop the game and then restart it. I much prefer edting the script and restarting it than trying to type it all out again. Especially if you dont remember some of it.

Gandalf Parker
September 1st, 2008, 02:08 PM
:bump:
Since this subject is coming up again I thought Id bump this.

Gandalf Parker

Lihaässä
January 30th, 2009, 12:40 PM
Hi,

We're trying to figure out is there a way to host dom3 from a server computer with identical cd-key as one of the players? Nothing illegal, but none of our friends want to keep server running 24/7 and we have an existing server which could be used.

Thanks, nice thread

Gandalf Parker
January 30th, 2009, 05:08 PM
Its not supposed to be a problem.
The host doesnt check its own key against the players. But Im pretty sure it does have to be a good key (cant use one off a public list since they get banned pretty quick). Ive used my own key with no trouble even when the host is on the linux server and Im playing from my windows desktop.

Ornedan
January 30th, 2009, 05:39 PM
My server wrapper and backup scripts. For this thread, I think the interesting bit is the backup script, since it's parametrized by game name.

Both scripts assume the game directory is ~/dominions3

The server wrapper passes all parameters directly to dom3. It only deals with the last parameter, which is assumed to be the name of the game. The wrapper is mainly for having a bunch of default parameters that I want to have all the time.

The backup script writes the backups to ~/dominions/backups. It reads the scores.html file to determine current turn, so the game needs to be run with --scoredump on.


dom3serv:
#! /usr/bin/env python

from os import environ, execvp, mkdir
from os.path import exists, join
from sys import argv


# Common options
common = ["--scoredump",
"--tcpserver",
"--quickhost",
"--textonly"
]


# Newgame standard options
newgame = ["--masterpass", "*****",
"--renaming",
"--noscoregraphs"]


# Start game
HOME = environ["HOME"]
GAME = argv[-1]
EXECS = ["--preexec", "dom3backup %s" % (GAME,)
# ,"--postexec", "command %s" % (GAME,)
]

common = common + EXECS

if exists(join(HOME,"dominions3","savedgames",GAME,"ftherlnd")):
print "Resuming game %s" % (GAME,)
execvp("dom3", ["dom3"] + common + argv[1:])
else:
print "Starting new game %s" % (GAME,)
if not exists(join(HOME,"dominions3","savedgames",GAME)):
mkdir(join(HOME,"dominions3","savedgames",GAME))
execvp("dom3", ["dom3"] + common + newgame + argv[1:])


dom3backup:
#! /bin/bash

game=$1
savedir="$HOME/dominions3/savedgames"
gamedir="$savedir/$game"
backupdir="$HOME/dominions3/backups/$game"

fatherland="$gamedir/ftherlnd"

if [ ! -d $gamedir ]; then
echo "Can't backup non-existent game!"
exit
fi

if [ -f $fatherland ]; then
if [ -f $gamedir/scores.html ]; then
turn=`grep -Eo -m 1 "Dominions 3 Scores, $game turn ([[:digit:]]+)" $gamedir/scores.html | grep -Eo "[[:digit:]]+$"`
else
turn=1
fi
backupfile="$backupdir/turn_$turn.tar.bz2"
else
backupfile="$backupdir/pregame.tar.bz2"
fi


# Make sure backup dir exists

if [ ! -d $backupdir ]; then
mkdir -p $backupdir
fi

# Create backupfile for this turn

echo "Creating backup file $backupfile"
tar cjf $backupfile -C $savedir $game > /dev/null



Edit:
Regarding that unattendedness stuff, I run my server processes each in their own window under GNU screen, so they'll print their log to a terminal, but I don't have to have a local/remote login open all the time. But that's more a part of the fact that my setup currently requires me to start each game manually.

Lihaässä
January 31st, 2009, 04:25 AM
Thanks G

Gandalf Parker
January 31st, 2009, 01:00 PM
My server wrapper and backup scripts. For this thread, I think the interesting bit is the backup script, since it's parametrized by game name.

Excellent scripts.
I will definetly copy them and use them as examples as I work on consolidating mine. My stuff grew over time and I have a script to start each game type, and a script to restart for each game type, and one to kill/delete for each game type, and one to search/display dead games which the players didnt bother to turn off. Not to mention the many version 1, version 2, test this, test that scripts.

I really need to clean it all up and create larger scripts with options, I especailly like how you broke the common options from the newgame options for start and restart.

Gandalf Parker
January 31st, 2009, 01:07 PM
For backups I like to end it with a mime emailing to an account on another system. Backup on the same device is handy, on another device (drive, tape, etc) is handier, and on a completely different system is way handier.

Lihaässä
March 5th, 2009, 01:18 PM
First game finished using server hosting.. man that was simple! A new question occurred however while planning a new game. According to this list: http://www.dom3minions.com/docs/CommandLine.txt, its not possible to assign more than 1 victory point / province. I'm planning to set up game with one 3-vp and three 2-vp provinces in addition to 10 regular 1-vp provinces.

Any ideas is this possible? How?

Thanks already!

llamabeast
March 5th, 2009, 02:10 PM
I think you have to start the game using the GUI, then run it as a command line game once it's started. The detailed VP settings are curiously absent from the command line options.

Gandalf Parker
March 5th, 2009, 02:17 PM
Only time for quick answer. Ask if confusing.

For me, easiest is appending a few commands to the end of the games .map file
http://www.dom3minions.com/docs/map_qref.txt

If someone elses map, dupe to new name. It will use the same image file so not much work involved.

--
per peer-pressure preoccupation
My maps, mods, and mullings can be found at
http://www.Dom3Minions.com

Lihaässä
March 5th, 2009, 02:19 PM
Thanks llamabeast - I think it's not possible to use GUI in our case. Sounds really mysterious why such commands are not available. Any other options?

Apparently me and Gandalf replied at the same time - I'll look into his solution. Thanks!

Lihaässä
September 17th, 2009, 05:38 PM
Im trying to make a working, simple backup option for a hosting script. How do the commands --postexec and --preexec commands work? At the moment my script looks like this? It works ok without the --postexec command. At the moment the game refuses to start up.


#!/bin/bash
# Tällä käynnistellään dqotonen domi hostaukset
# jee


GAME="rivers"
MAP="Rivers.map"
ERA=3
MOD="CBcomplete_1.6.dm"
BUP=["rsync -a /home/dom/dominions3/savedgames/* /backup/"]
AID="57"
START=5

PORT="2222"
DOM="/home/dom/dominions3/dom3"

$DOM -S -T --port $PORT -g $GAME --era $ERA --mapfile $MAP -q --indepstr 9 --uploadmaxp $START --diffai $AID --enablemod $MOD --postexec $BUP

vfb
September 17th, 2009, 06:17 PM
It's probably the [] characters in $BUP, if it's calling system() to run the postexec command then it won't work, because system() does a "/bin/sh -c":


$ /bin/sh -c ["/bin/ls -a"]
/bin/sh: [/bin/ls: No such file or directory




I put my postexec commands in a script and that worked fine:


$DOM3EXE $DOM3GAME \
--port $PORT -ST${DEBUG} ${SCOREOPT} ${RENAMEOPT} \
--era ${ERA} \
--uploadmaxp ${PLAYERS} --noclientstart \
--requiredvp 0 --totalvp 0 \
--mapfile ${MAP} \
--enablemod ${MOD} \
-q \
--masterpass ${MASTERPASS} \
--preexec ${DOM3DIR}/prehost.sh --postexec ${DOM3DIR}/posthost.sh \
>>$DOM3LOGDIR/$DOM3GAME.log 2>>$DOM3LOGDIR/$GAME.err


Also, do you need -g? The help for that shows:


-g --host Generate new turn and exit

Lihaässä
September 18th, 2009, 03:50 AM
Thanks vfb. I'm almost there, you are correct, there is no need for "-g" command. At the moment the script looks like below. The game starts but when trying to play a turn it just closes the gamewindow. It also says "send, broken pipe"

#!/bin/bash
# Tällä käynnistellään dqotonen domi hostaukset
# jee


GAME="rivers"
MAP="Rivers.map"
ERA=3
MOD="CBcomplete_1.6.dm"
BUP={rsync -a /home/dom/dominions3/savedgames/* /backup/}
AID="0"
START=5

PORT="2222"
DOM="/home/dom/dominions3/dom3"

$DOM -S -T --port $PORT $GAME --era $ERA --mapfile $MAP \
-q --indepstr 9 --uploadmaxp $START --diffai $AID --enablemod $MOD --postexec $BUP

vfb
September 18th, 2009, 03:58 AM
Did you try this?

BUP="rsync -a /home/dom/dominions3/savedgames/* /backup/"

Lihaässä
September 18th, 2009, 04:08 AM
Yeah, after that it asks for the game name and this happens.

-- Waiting for participants to connect -- , time left: 1 seconds
Arcoscephale open
Ermor open
Man open
Ulm open
Marignon open
Mictlan open
T'ien Ch'i open
Jomon open
Agartha open
Abysia open
Caelum open
C'tis open
Pangaea open
Midg�rd human controlled
Utg�rd open
Patala open
Gath open
Atlantis open
R'lyeh open
Pythium open
Bogarus open
Enter game name: rivers
N�got gick fel!
fg: bad u
N�got gick fel!
fg: bad u
dom_server.sh: line 19: 20308 Aborted $DOM -S -T --port $PORT $GAME --era $ERA --mapfile $MAP -q --indepstr 9 --uploadmaxp $START --diffai $AID --enablemod $MOD --preexec $BUP

Gandalf Parker
September 18th, 2009, 12:40 PM
I generally use pre.sh and post.sh

Also I think you want --preexec rather than --postexec

Once the game hosts, saving a copy is not much use since it will match the game itself. Players will complain about the hosting results in which case you want to be able to return to the files prior to hosting.

By the way, I find it more useful in many many ways to do
nice zip -9 game.zip * -x *game.zip -x z*
and then attach it to a email going to an address off-system.
That provides:
A) backup
B) dated multiple backups allowing restore to multiple points
C) security in case of system crashes or hard drive failures
D) ease of forwarding the latest games files to someone else in case they volunteer to pick up running the game for some reason

Lihaässä
September 20th, 2009, 03:33 PM
Thanks for the answers and help! I'm still struggling with the script, but will make it work somehow. Fortunately backing up files isn't mandatory. Happiness is :)

Lihaässä
September 23rd, 2009, 02:05 PM
Done! Thanks to my awesome anonymous friend and you guys my script is ready for hosting. Feel free to copy if you need such a simple script. :D

#!/bin/bash
# Tällä käynnistellään dqotonen domi hostaukset
# Jos tämä toimii siis!

GAME="Rivers"
MAP="Rivers.map"
ERA="3"
MOD="CBcomplete_1.6.dm"
AID="0"
NID="0"
START="5"
HOF="15"
IND="5"

PORT="3737"
DOM="/home/dom/dominions3/dom3"

$DOM -S -T --port $PORT $GAME --era $ERA --mapfile $MAP \
-q --indepstr $IND --uploadmaxp $START --diffai $AID --normai $NID \
--noscoregraphs --hofsize $HOF --enablemod $MOD \
--preexec /home/dom/backup.sh
#!/bin/bash
rsync -a /home/dom/dominions3/savedgames/ /home/dom/dominions3/backup/

Ornedan
September 24th, 2009, 04:04 AM
#!/bin/bash
rsync -a /home/dom/dominions3/savedgames/ /home/dom/dominions3/backup/


I see a couple of problems here:

You copy all games every time any game hosts. Which clobbers the backups of all games other than the one about to be hosted.
You only maintain a backup of the latest turn. This will cause trouble when the game manages to **** itself up so that it crashes at next hosting, because by the time you notice it crashing, you've clobbered the backup from before it broke.
(Yes, this can happen. Guess what made me think it was a good thing I was already backing up all truns?)


If you look approximately halfway up the thread, I've posted a backup script that has neither of those particular issues.

Lihaässä
September 24th, 2009, 08:52 AM
You are correct, the script is simple but easily altered to backup only one game.. in this case /home/dom/dominions3/backup/Rivers/
I hope that the game won't crash and use this one. :)

Your script was too much for me and I didn't understand it. Thanks for your input. I will look it again when I find the time.

Ornedan
September 24th, 2009, 09:24 AM
Most of my backup script is about finding the current turn number and handling edge cases like being somehow called to backup a non-existent game (not detecting conditions like that will at best result in the script crashing and at worst data loss as it goes blindly ahead to do something stupid).


Doing

--preexec /home/dom/backup.sh "$GAME"
and

#!/bin/bash
rsync -a "/home/dom/dominions3/savedgames/$1" /home/dom/dominions3/backup

would have your backup command be parametrised by game name, so it'll backup each game to separate directory. Though I guess that might have been what you meant?

Ornedan
September 24th, 2009, 10:23 AM
Looks like edit period ran out... It should have been

--preexec "/home/dom/backup.sh \"$GAME\""

Lihaässä
September 24th, 2009, 10:48 AM
It works perfectly! :D

lch
September 30th, 2009, 07:00 AM
Hi there, I see that people are sharing their Linux server scripts here. In case it helps: somebody contacted me about the Linux server scripts that I use for administrating my Dom3 games around June, here's what I sent back. Configuration is done by editing the GAME and PORT variables inside the scripts, and by setting the player's email addresses for email notification in the post-exec script.

Main script "MyGame.sh", this is being started in a "screen" session
#!/bin/bash

GAME=MyGame
PORT=1337
DIR="/home/dom3/dominions3/savedgames/"$GAME

mkdir $DIR &>/dev/null

# reset timer for the stats.php script
if [ -e $DIR/ftherlnd ]
then
touch $DIR/ftherlnd
fi

~/Dom3/dom3 $GAME --port $PORT -STddd --scoredump --renaming \
--era 2 --mapfile 'MyGameMap.map' \
-q \
--masterpass MyGamePassword \
--noclientstart --uploadmaxp 7 \
--hofsize 15 --indepstr 6 --renaming \
--preexec /home/dom3/dominions3/${GAME}_pre.sh --postexec /home/dom3/dominions3/${GAME}_post.sh \
>>$DIR/$GAME.log 2>>$DIR/$GAME.err

Pre-hosting script "MyGame_pre.sh", this is being started before hosting and makes a backup of the game/turn data
#!/bin/bash

GAME=MyGame
PORT=1337
DIR="/home/dom3/dominions3/savedgames/$GAME"

# make backups
pushd "$DIR/.."
tar czf "/home/dom3/dominions3/backups/"$GAME-$(date +%s)-pre.tgz $GAME
popd

# blank the log files after backup
cp /dev/null $DIR/$GAME.log
cp /dev/null $DIR/$GAME.err

Post-hosting script "MyGame_post.sh", this is being started after hosting and makes a backup of the game/turn data, updates my online game statistics and sends a notification to the other players
#!/bin/bash

GAME=MyGame
PORT=1337
GAMElow=`echo $GAME | tr "[:upper:]" "[:lower:]"`
DIR="/home/dom3/dominions3/savedgames/$GAME"
SENDMAIL="sendmail -t "

# make backups & save scores
pushd "$DIR/.."
tar czf "/home/dom3/dominions3/backups/"$GAME-$(date +%s)-post.tgz $GAME
php /home/dom3/dominions3/backups/scores2mysql.php "$GAME/scores.html"
popd

# blank the log files after backup
cp /dev/null $DIR/$GAME.log
cp /dev/null $DIR/$GAME.err

# email notify players that have asked to be told of turns
Player1=player1@email.com
Player2=player2@email.com
Player3=player3@email.com
Player4=player4@email.com
Player5=player5@email.com
Player6=player6@email.com

# the actual sendmail needs a single dot "." in the last line at the end of the message, nbsmtp does not
$SENDMAIL <<EOF
From: '$GAME' Dom3 game server <$GAMElow@my-own.email>
Bcc: $Player1, $Player2, $Player3, $Player4, $Player5, $Player6, $GAMElow@my-own.email
Subject: $GAME has hosted!

The Dominions 3 game you are playing in ($GAME) has processed a new turn.
Please connect to server dom3.servegame.com port $PORT to play your next turn!

Here is the turn status page for the game: http://dom3.servegame.com/stats/stats.php?game=$GAME

EOF

I am not hosting games right now and my Dom3 activities are in hiatus, but maybe these shell scripts are an inspiration for somebody else. I needed to use PHP syntax highlighting environment here because the CODE environment doesn't display the shell code correctly. (double <)

Gandalf Parker
September 30th, 2009, 10:59 AM
More script examples are always helpful. I also have the old Dom2 pbem BBS using php and sql. I dont remember if Ive seen Llamabeasts scripts since about mid-way thru the discussions on creating his server. Those would be worthy to look at also.

One thing Id add would be the mail support. Ive played abit with
mail, sendmail, mutt, pine, postfix, mpack/munpack, and biabam. If I remember right I got them all to work. But now for receiving player files I use munpack, and for sending turn attachments I prefer biabam. I also like to attach the backup files to an outgoing email just to have them off-system

Gandalf Parker
--
You dont use Linux if you like asking a question and getting an answer.
You use Linux if you like asking a question and getting a hundred answers on a hundred different ways of doing the same thing.

Gandalf Parker
November 1st, 2009, 03:16 PM
OK since I mentioned my IP in many of the examples here I should update this. I have upgraded my DSL, switched ISPs from AT&T to Sonic.net, and received all new IP addresses. The new address for www.Dom3Minions.com and temporarily also for game.dom3minions.com where all the games are, is:
70.36.184.129

Gandalf Parker
January 23rd, 2010, 03:08 PM
OK some new territory here.

After running a PBEM game Ive decided that such games are a pita.
But it was an extensive learning experience.

Some new territory:
ProcMail nicely handles some features. Checking Subject lines in order to unpack player files to the game directory, or calling specific scripts to do things like allowing the games admin to change things such as the games hosting times.

One of the few good things about pbem was that Dom3 did not have to claim its share of server CPU load running continually. Having many copies of Dom3 running all the time can eat up a server. I didnt want to undo that benefit by having a script run continually or a cron job running every minute to see if the game should host in order to duplicate the "quick host" option of DirectConnect games. Since an incoming file should usually kick off "quick host" I have procmail unpacking each email AND running a host_check script.

To duplicate the Forced_Hosting option I used the "at" command to set system timers. One for the hosting time (such as 48 hours) and one for sending email reminders (forcehost - 9 hours).

Also I had to get into lock files and date math. And made extensive use of the .chk files that Dom3 generates using the --verify command in order to catch players sending in files that werent 2h, or didnt attach properly, matching serials, or arrived corrupted, or were the wrong dom game, or were the right dom game but the wrong turn (especially on the many rollbacks).

The resulting scripts are many and extensive (and ugly since they grew gradually with many tests inserted). I may clean them up and post them seperately. Oh yeah, and one note which I really REALLY need to try and remember. The initial big bomb is that the Dom3 games PBEM coding was prior to the change allowing us to keep multiple gods available for server games. So its very important that the initial god files sent in be cleaned up so that early_ulm_1.2h becomes just early_ulm.2h before trying to start the game.

Gandalf Parker
January 23rd, 2010, 03:34 PM
NEW TERRITORY:

Ive now been asked to host a multi-connect game. One that supports Direct, and PBEM, and FTP, and possibly WEB upload.

The first headache is that if I run the game 24/7 for direct connect then it doesnt "see" any new .2h files that are copied to the games directory. I had HOPED that something like a SIGHUP sent to the game would work like its used for other running programs to get them to reread their configurations without having to reboot them. (which would also be really handy with Dom3 for making changes such as hosting times). The only signals I can get to work is STOP and CONTinue (and of course KILL) although I havent actually tested every one.

The best I can come up with so far is something like:
pkill -f game_name ; sleep 1 ; ./start.sh
which kills the game and restarts it very quickly. I will need to add a check to make sure none of the direct-connects is uploading a file at the same time.

lch
January 26th, 2010, 01:50 PM
NEW TERRITORY:

Ive now been asked to host a multi-connect game. One that supports Direct, and PBEM, and FTP, and possibly WEB upload.

The first headache is that if I run the game 24/7 for direct connect then it doesnt "see" any new .2h files that are copied to the games directory.

I already hosted a networked game that had an alternative web upload method for one person who had firewall issues to connect normally and I don't remember any problems. What you should make sure is that the game server has access to the new *.2h files, so you should chmod them to 0666 after uploading or chown them to the account that the server is running under, and maybe "touch" them as well. If you want, I can send you the PHP turn file upload/download script that I created for my networked game.

Gandalf Parker
January 26th, 2010, 04:46 PM
Actually most of "getting the files there and usable" I think I have down from painful learning experience in game 1 of the series which was all pbem. Some simple bit of PHP for uploading would be useful though.

But do you remember, did you ever come up with a way to force Dom3 running in server mode to SEE the new files without taking the game down and restarting it? So far all tests seem to say thats what I will be forced to try and script.

Gandalf Parker
March 9th, 2010, 03:07 PM
In continuation of support for any other servers or anyone trying to iron out hosting games by providing copies of everything Ive worked out, I offer the following...
IF YOU ARE TRYING TO RUN MULTIPLE VERSIONS TO SUPPORT GAMES PRIOR TO UPDATE PATCHES

Running with -d will show something like this at the head...


-------------------------
----- DOMINIONS ---------
-------------------------

Version version 3.23b (323)dbglevel 1 pc_endian
datapath='/usr/local/games/dominions3'
confpath='/home/gandalf/dominions3'
savepath='/home/gandalf/dominions3/savedgames'
modpath='/home/gandalf/dominions3/mods'
mappath='/usr/local/games/dominions3/maps'
localmappath='/home/gandalf/dominions3/maps'
temppath='/tmp/dominions3_24145'
Keeping a copy of the dom3 executable as a new name such as old_dom3 and using it might seem like an answer but it causes problems due to conflicts with some of the library files. Making a complete copy of the dominions3 directory and running the game out of that might seem the answer but in many cases it only changes some of the path variables, but not all. Most importantly in this case, the datapath directory.

This has worked for me. Setting DOM3_DATA= to the directory of the old copy, doing it on the same line but before the dom3 call (and not using a ; for some reason)
Such as....

DOM3_DATA=/home/gandalf/dom3_v3.23b/ /home/gandalf/dom3_v3.23b/dom3 \

Gandalf Parker
March 31st, 2010, 06:41 PM
Im not sure if Ive mentioned this little bit. But with the growth of usage on my server, plus doing more and more automation, this has become useful...

while [ ` cut -d. -f1 /proc/loadavg ` -gt 2 ]; do sleep 10 ;done

This will loop until the load on the system is below 2. Particularly important for large games, or generating maps, or extensive backups. It will keep those from kicking in while the system is already suffering under some other major process.

Its also handy to use the nice command with Dom3. Such as

nice -15 dom3

to tell it to operate at a lower priority than more immediate activities. After all, we usually arent that concerned with how long it takes to do a hosting in a server game. Not so much that it should take equal position to email, web, ftp, etc.

Gandalf Parker
April 18th, 2010, 10:39 PM
Whenever anyone requests a game I copy a script from another game and edit it. Whenever I see some of the always open public games have been taken I run a script to create another to take its place. Many of those involved special variables unique to that game, or even randomly decided features. So restarting games was rather a pain.

Recently I had one of the head-slapping *DOH* moments. While the script creating the game is running have it record the settings. So now each script writes the long start command to the game directory into a script named restart.sh

So now, when the machine reboots, all that needs done is

#!/bin/bash
cd ~/dominions3/savedgames

for fyle in `ls */restart.sh`
do
$fyle
sleep 10s
done
Ive extended the gap to 10 seconds between each restart. My first effort with no gap restarted 70 games within a minute. 24 hours later about 50 of them tried to host at the same time. Not good. Then I set it too long but even a 1minute gap would mean over an hour before all the games would be restarted. So for now Im trying 10s.

Gandalf Parker
April 18th, 2010, 10:51 PM
I also had another recent head-slapper. I can now offer the feature "refuses player going AI"

In one of the special games the person running it asked if the game could be set to refuse allowing anyone to go AI. He wanted a chance to always try to find a sub, or set AI later as a last resort. My initial response was to say it couldnt be done. Then I thought how nice it would be if it could. Then I realized how it could be done.

A) My pre.sh always make a zip of the game just before hosting. For backups, or I email it to the person running the game, or for doing rollbacks.

B) If the game is run with the --statfile switch then the stats.txt is generated each turn which looks like this...
Helheim played this turn
Hinnom didn't play this turn
Atlantis is computer controlled

The post.sh which runs just after hosting can check the stats.txt for anyone that went computer controlled. Then shut down the game. The options would be to unpack the zip, delete the 2h that went ai, and then rehost (that one would go stale) or wait until a sub can turn in a good 2h file.

Yeah I know. Not very impressive or difficult. We should have thought of it long ago.
Next?

Gandalf Parker
April 22nd, 2010, 11:40 PM
servers see everything
OK It has come up that someone has accessed someone elses nation and changed their turn actions. This has been verified. Its not unexpected and Ive been prepared for a long time. Yes I know that "is what happens when you dont password protect your god" or by using sloppy passwords when playing network games. Getting caught at it is also what happens when you play network games. Servers see EVERYTHING.

Servers can see what IP uploads a turn. So the servers are able to see who is using player files they shouldnt be using.
Example for Linux

while [ x ]
do
cat IPlog.txt|grep \*|sort |uniq >IPusers.txt

for x in `seq 1 1000`
do

netstat -n |grep 63.199.8.157:8|cut -d: -f2 >listIP.txt
cat listIP.txt|\
while read PID IP
do
if [ $PID ]
then
GAME=`ps ax|grep dom3|grep $PID|cut -dg -f2|cut -d" " -f2`
LOGINS=`tail -1 $DIR/$GAME/game.log`
echo $IP" "$GAME" "$LOGINS >>IPlog.txt
fi
done

sleep 10
done
done


Also, if the user is the same as is in the game, or any game on that server then the 2h files can be checked for matching serials. The dom3 command switch of --verify gamename will create .chk files for each .2h and part of the information is a serial hash.

example for linux

cd ~/dominions3/savedgames

for gaym in `ls -1`
do
nice dom3 --verify $gaym
done

grep serial */*.chk |cut -d" " -f4 |sort -n |uniq -c |sort -n
cd -

Gandalf Parker
May 5th, 2010, 11:34 AM
OK yet another lesson learned (that makes me look bad).

It appears that Dom3 can develop a problem. Im still trying to pin it down. Possibly something with the way a player disconnects. Im thinking maybe by hitting the red X in the upper right corner (in windowed mode) killing his program, instead of using the disconnect button on the menu when connected to the server. What I get is a log file full of continual (and very fast unfortunately) messages about trying to resend a packet. In any case, the result is a log file that grows larger and larger and larger until it fills up the machine and starts to crash things.

The fix? I havent quite decided yet. Dont use debug logs? I dont use them all the time but when I do they are extremely useful. Or a watchdog script that "sees" the runaway log-growth and kills that game? Im abit to eager to do watchdogs. Im beginning to think I have too many running now. Or maybe keep the logs on a different drive? I can do that. Have the logs write to the /backup which is a separate hard drive. That way at least when it fills up it wont crash other things. But that will make game cleanup alot more complicated. I have enough of that already.

Gandalf Parker
May 5th, 2010, 12:24 PM
hmmm... I wonder if I can get along with a soft link to the separate drive. That way the game.log in the games directory is kept elsewhere but can be cleaned up with the game

Gandalf Parker
July 16th, 2010, 12:48 PM
OK we are back to the runaway logs problem.
There might be two versions. One that does continual packet messages which might be due to users not disconnecting properly (killing dom3 instead of using the quit). And one where a combat loops. Unfortunately, when it happens the panic to fix it before it wipes out the whole server tends to destroy the evidence of what caused it. :) Oops, my bad. Hey, no one else seems to be coughing up anything helpful.

This is NOT what I planned to do today. But I might get around to testing out soft links. That would be my best bet since it would not mean totally rewriting all the scripts from scratch.

The next option would be a watchdog script to continually watch for the harddrive getting 90% full then text messaging me. For just this problem that would seem to be sloppy and overkill but on the other hand it would be a reasonable thing to have in place since runaway processes and runaway logs CAN be caused by other programs on the system (much rarer but it can happen). I should probably do a search since it seems like someone might have already come up with something along this line that I can just download.

The last option would be redesigning the whole Dom3 games setups. There are many "gee I wish you would" on the lists that could be tackled at the same time. I really thought someone else would have done a "serious direct server" by now to match the quality of the two excellent PbEM servers and one excellent game registration server. This choice is abit of a daunting task since the scripts are SOOooooooo spaghettied now. Virtual drives? Hard and Soft Links? Split game directories using Dom3's internal variables like DOM3_DATA or DOM3_CONF? Dom3 already hogs the /tmp directory far beyond any other internet service and does a lacking job of cleaning up (something else on the need-to-script list).

Another plus to the redesign and rewrite options is the number of games is hitting a max. If I keep doing the always-open blitz-type games then I might need to create a new account to manage the games other people are having me host. It would make it easier to keep one from impacting the other. I keep hitting the limit on maps or game directories or mods. I dont THINK splitting the "user" would split the cpu load but Id have to test that. And as long as Im considering a new user with hard-set limits I MIGHT consider adding another for the must-have-a-menu crowd to put into play something like
http://www.dom3minions.com/lab/MakeGame.htm which has been around longer than anyones. Altho Im still not sure about automation on a server that isnt totally Dom3 dedicated. Pros and Cons.

Gandalf Parker
October 16th, 2010, 04:00 PM
OK this is for a game with a 24 hour host timer that wanted 12 hour reminders.

# if the game name is "megagame" then I use queue M or queue m
# so in the pre.sh

# remove the old reminder timer in case quickturn kicked in
atrm `atq |grep "M domgames"|cut -f1 `
# set a new timer to run reminders.sh in 12 hours in queue P
at -f reminders.sh -v now + 12 hours -q M

# then the reminders.sh has a line for each nation and its owner
# if fatherland is newer than the last .2h for that nation then email
if [ ftherlnd -nt early_pangaea.2h ] ; then echo "waiting for your turn" \
|mail -s "MegaGame is waiting" gandalf@community.net ; fi

I could tighten it up abit by adding a check of the stats.txt for whether the nation is still playing and not AI to avoid false reminders. Maybe later.

Gandalf Parker
October 22nd, 2010, 06:56 PM
Now I have a new "check the game" script for personal games on the server. So far it looks like this..

Dominions 3 Scores, goongame turn 16

goongame, Connections 1, Time 22h (quick host)
*Py- (Man) Mac+ Ag- Ca+ Jo+ shi+ As-


mid_agartha.2h
mid_bakemono.trn*
mid_caelum.trn*
mid_gath.trn*
mid_jotunheim.trn*
mid_machaka.2h
mid_man.2h
mid_pythium.2h
mid_vanheim.2h

If the game is called goongame then cat goongame.cgi gives


#!/bin/bash
echo "Content-type: text/html"
echo -e "\n\n"

cd /home/domgames/dominions3/savedgames/goongame/
head -9 scores.html
echo "<html>"
echo "<h4>"
tail game.log | \
grep Connections | tail -n 1
echo "<br>"
tail game.log | \
egrep "\-|\+" |tail -n 1
echo "<br>"
echo "</h4>"

for fyle in `ls -1 *.2h`
do
nation=`echo $fyle|cut -d. -f1`
if [ $nation.trn -nt ftherlnd ]
then echo $nation".trn<font color=red>*</font><br>"
else
echo "<font color=black>"$nation".2h </font><br>"
fi
done

echo "</html>"


The first sections grabs the top of goongames latest scores.html (which dom3 creates).
That gives us a nice html header, and title, game name, and the turn number.

The next section grabs the tail end of the game.log twice (created by the dom3 debug switch).
That gives us game name, how much time is left on the timer, and the note (quickhost) if its on.
then it lists the nations and lets us know who is connected *, who has done a turn +, who hasnt done a turn -, and who is AI ( ).

The final section lists the player files with a red asterisk on anyone the game is still waiting on. Yes thats redundant but it has two purposes. The file names are sometimes clearer than the 2-letter codes, and it works even BEFORE the game starts so it makes an easy way for the person who is running the game to see who has turned in a pretender.

All of this is so that people can use a browser to check their games status as much as possible without having to load up Dom3 to connect in order to see it.

Mark Weston
September 10th, 2011, 02:38 PM
I know this isn't quite a linux question, but it seems like the right place.

I was planning on trying to host some games from my Mac. I figured this would be straightforward because the Mac is a unix based OS, and I've done it from a Linux machine before.

But I can't get it to run in a properly text-only mode as a background process. Has anyone had any luck doing this?

Gandalf Parker
September 10th, 2011, 02:53 PM
Well I can give you an answer for Linux test-mode...

Here is an example script from my system of an actual game..

nohup nice dom3 --era 2 -g Warhammergoons --port 28911 -STddd \
--statfile --scoredump -q --hours 48 \
--preexec /home/domgames/dominions3/savedgames/Warhammergoons/pre.sh \
--postexec /home/domgames/dominions3/savedgames/Warhammergoons/post.sh \
--renaming --hofsize 15 \
--enablemod Expanded_Nations_1_v1_02.dm --masterpass xxxxxx \
--mapfile Streamlands_8P_warhammer.map \
>/home/domgames/dominions3/savedgames/Warhammergoons/game.log \
2>/home/domgames/dominions3/savedgames/Warhammergoons/game.err &
Some of the non-Dom3 elements are
nohup: No Hangup command so I can log off without the game dying
nice: so it doesnt hog the CPU
&: the ampersand at the very end of the script is what tells it to run in background

a common error is running it & (background) but forgetting nohup (no hangup) so when you logoff, it dies

JonBrave
September 14th, 2011, 05:20 PM
I was about to say: I haven't seen a Unix command in about 20 years. I see people are still writing "nohup nice ... &", amazing ;)

I used to use /bin/csh. Do I vaguely recall, there you didn't have to "nohup" if you "&"-ed, because its background processes were automatically immune? :eek:

GenericOverusedName
July 1st, 2012, 12:25 PM
Well I can give you an answer for Linux test-mode...

Here is an example script from my system of an actual game..

nohup nice dom3 --era 2 -g Warhammergoons --port 28911 -STddd \
--statfile --scoredump -q --hours 48 \
--preexec /home/domgames/dominions3/savedgames/Warhammergoons/pre.sh \
--postexec /home/domgames/dominions3/savedgames/Warhammergoons/post.sh \
--renaming --hofsize 15 \
--enablemod Expanded_Nations_1_v1_02.dm --masterpass xxxxxx \
--mapfile Streamlands_8P_warhammer.map \
>/home/domgames/dominions3/savedgames/Warhammergoons/game.log \
2>/home/domgames/dominions3/savedgames/Warhammergoons/game.err &
Some of the non-Dom3 elements are
nohup: No Hangup command so I can log off without the game dying
nice: so it doesnt hog the CPU
&: the ampersand at the very end of the script is what tells it to run in background

a common error is running it & (background) but forgetting nohup (no hangup) so when you logoff, it dies

Why not use screen? Or does it take up too much resources?

Gandalf Parker
July 1st, 2012, 12:31 PM
Up to you. My server runs many things including 2 online worlds. And I have up to 100 Dom3 games on my server at a time. I dont really have much of a need to access them directly.

But of course for people managing fewer games at a time then screen might be a good idea.

Joku
August 6th, 2012, 05:28 AM
This might be a stupid question, but how can you manually make the command line server to change turn? I host the game on a server on screen..

Gandalf Parker
August 6th, 2012, 08:31 AM
The game does not accept normal kill command requests such as "reset" or "reread config"

So the only way I have been found is to slip into PbEM mode temporarily. I take the game down, run it again without the "S" switch (server), and then when its done I restart it again with the S switch back on.

Just for fun I have messed around with automating it along with lots of other admin commands if you want to discuss that.

Joku
August 6th, 2012, 10:04 AM
Thanks, I don't need to automate it as I'm just running a single game currently. :)

Anyways, for some reason the game seems to crash sometimes, the script in the screen just stops running and it's back on the command line.. has anybody any idea what is causing that? I'm running it on FreeBSD 8.2 with Linux emulation, though.

Gandalf Parker
August 6th, 2012, 06:10 PM
add a -dd switch and redirect to a file. The last thing in the file should be the reason it crashed.

Joku
August 9th, 2012, 01:07 AM
I added -ddd switch, and the last lines are these, doesn't really indicate anything though:


gameserver got packet 11
sendpacket first:12 len:7


Then it just exited to command line.. I was running it on a screen, so I try to run it with nohup to see if there's some issues with screen.

Joku
August 26th, 2012, 06:26 PM
Also, for some reason crowns appear on the map, and victory points aren't set on by options. The game options window when playing a turn doesn't say they are on, either. Does anybody know the reason for this?

ascen
October 6th, 2012, 04:03 PM
I'm trying to set up a Linux server, but am running into
weird problems with the IP address the Dom3 uses for the server.
For some reason the game decides to use IP 127.0.1.1 (loopback?).

I'm running the game on a netbook with only WLAN connectivity.
After noticing that IP address, I did "ifconfig ... down" for both my eth0 and lo interfaces, so wlan0 is the only interface up at the moment. Still the same IP though.

Looking through the thread it seems there is no flag for setting the server ip? Does anyone have any ideas how this could be fixed?

My desired end result should be it getting an local network address, which the firewall would port forward to.

Gandalf Parker
October 6th, 2012, 04:35 PM
Thats a problem on all machines. Especially the windows ones.

The game sets itself up with the local machines address which is all that it can easily "see". If no other address is set for the machine, it will not create one for itself.

However, usually external addresses work fine for reaching it. Just go ahead and try it. For the windows users we usually have them use their browser from that machine to visit a site such as WhatIsMyIP.com to find out what address is being seen by the internet. Giving that address to players will usually let them find the game ok

ascen
October 6th, 2012, 04:57 PM
Thanks GP, for making me take yet another look at it.

I was testing it from my laptop on the same local network,
so the external IP was never an issue.
The actual problem was that the server was running an unpatched version, and Dom3 displays this situation as not having found a server at all.

Once I patched the server and tried again, it works like a charm.
So the displayed IP has no function at all - even though it lists a loopback address, it's still listening on the local network address(es).

Gandalf Parker
October 21st, 2013, 06:41 PM
YAY! after DAYS of messing with it I finally got an ugly ugly script that works!

AI="diffai "
t=0

cp /home/gandalf/dominions4/Files_EA.txt paste.txt
rm done.txt

# add uploaded gods as team leaders
for FYL in `ls -1 *.2h | cut -f1 -d.`
do
let t=t+1
sed -i "/$FYL/s/^/--team / ; s/$FYL.*$/$t 1 \\\/" paste.txt
done


# add one AI team
let t=t+1
cnt=`grep -c _ paste.txt`
chc=`echo $RANDOM % $cnt + 1 | bc`
PRET=`grep _ paste.txt |head -$chc |tail -1|cut -f2 -d' '`
grep $PRET paste.txt | sed "s/^/--$AI/;s/$PRET.*$/\\\/" >>done.txt
sed -i "/$PRET/s/^/--team / ; s/$PRET.*$/$t 1 \\\/" paste.txt

for TT in `seq 1 $t`
do
cnt=`grep -c _ paste.txt`
chc=`echo $RANDOM % $cnt + 1 | bc`
DISC=`grep _ paste.txt |head -$chc |tail -1|cut -f2 -d' '`
echo $chc
echo $DISC
grep $DISC paste.txt | sed "s/^/--$AI/;s/$DISC.*$/\\\/" >>done.txt
sed -i "/$DISC/s/^/--team / ; s/$DISC.*$/$TT 2 \\\/" paste.txt
done

for TT in `seq 1 $t`
do
cnt=`grep -c _ paste.txt`
chc=`echo $RANDOM % $cnt + 1 | bc`
DISC=`grep _ paste.txt |head -$chc |tail -1|cut -f2 -d' '`
echo $chc
echo $DISC
grep $DISC paste.txt | sed "s/^/--$AI/;s/$DISC.*$/\\\/" >>done.txt
sed -i "/$DISC/s/^/--team / ; s/$DISC.*$/$TT 2 \\\/" paste.txt
done

grep "\-\-team" paste.txt >>done.txt



It is so that a --teamplay game of Dom4 can be started allowing everyone to send a full pretender. When the start button is pressed the game should crash (using --mapfile foo.map will do it). Then run this script and add the done.txt to the start script for the game.

What it does is:
if 4 pretender files were uploaded then it treats those as team leaders 1 2 3 4 and it adds an AI leader for a +1 team (in this case team 5). Then it randomly assigns 2 nations as AI Disciples for each team. So the 4 people that signed up all become pretenders with 2 AI disciples clustered near them.

UNFORTUNATELY I now have to figure out why Dom4 has a problem starting a game with AIs. :(

Gandalf Parker
November 15th, 2013, 01:59 PM
OK another brain fart that worked out well... :)


#!/bin/bash

while [ ! -f ftherlnd ]

do
ls -1 *.2h |sort >list.txt

if ! diff list.txt oldlist.txt
then
zip -9 GodSaves *
mv list.txt oldlist.txt
else
sleep 3
fi
done

figlet GAME START



What it does:
This is a script I can start in a games directory as soon as I have set it up for someone. It gets around the problem that pre.sh and post.sh do not activate for initial hosting.

It sits and watches for the fatherland file to exist (meaning the game has started and created its initial hosting).

If fatherland does NOT exist yet, then it watches for new pretender files (*.2h) to show up. And when a new one does then it updates the GodSave.zip file. As soon as the fatherland file appears, it shouts GAME START and quits running.

Im thinking of adding a no-clobber to the zip command to help insure first-come-first-served. Other people overwriting uploaded gods has been a problem in some games. And the recognition of fatherland could create the games first backup which has always been missing.

In any case it has proven quite useful in restarting bad starts without forcing people to re-upload their gods.