'
echo ''
}
get_scenario_list()
{
# Before 1.1.2, the versions weren't generally numbered. Now they
# should all be.
case $1 in
1.1-svn|1.1+svn|1.1.1|1.1.1+svn)
case $2 in
CAMPAIGN_HEIR_TO_THE_THRONE)
echo The_Elves_Besieged Blackwater_Port The_Isle_of_Anduin The_Bay_of_Pearls Muff_Malals_Peninsula Isle_of_the_Damned The_Siege_of_Elensefar Crossroads The_Princess_of_Wesnoth The_Valley_of_Death-The_Princesss_Revenge Gryphon_Mountain The_Ford_of_Abez Northern_Winter Mountain_Pass The_Dwarven_Doors Plunging_into_the_Darkness The_Lost_General Hasty_Alliance Scepter A_Choice_Must_Be_Made Snow_Plains Swamp_Of_Dread North_Elves Elven_Council valley_statue return_to_wesnoth trial_clans battle_for_wesnoth
;;
CAMPAIGN_TWO_BROTHERS)
# These are numbered!
/usr/bin/sqlite3 $DATABASE "select DISTINCT scenario FROM campaign_view WHERE campaign = '$2' AND version = '$1';" | sort -n
;;
*)
/usr/bin/sqlite3 $DATABASE "select DISTINCT scenario FROM campaign_view WHERE campaign = '$2' AND version = '$1';"
;;
esac
;;
*)
/usr/bin/sqlite3 $DATABASE "select DISTINCT scenario FROM campaign_view WHERE campaign = '$2' AND version = '$1';" | sort -n
;;
esac
}
# Returns sets of up to 10 comma-separated scenarios, given a scenario list.
chop_scenarios()
{
if [ $# = 1 ]; then
echo $1
return
fi
while [ $# -gt 8 ]; do
echo $1,$2,$3,$4,$5,$6,$7,$8
# Note that this deliberately repeats one.
shift 7
done
if [ $# -gt 1 ]; then
echo $@ | tr ' ' ','
fi
}
colorize()
{
sed -e 's,>aborted<,>aborted<,g' -e 's,>victory<,>victory<,g' -e 's,>defeat<,>defeat<,g'
}
# add_href field extra
add_href()
{
sed "s,^
'
/usr/bin/sqlite3 $DATABASE "SELECT campaign,difficulty,count(*) FROM campaign_view WHERE version='$W_VERSION' GROUP BY campaign,difficulty ORDER BY campaign,count(*) DESC;" | while IFS="|" read campaign diff count; do
if is_official $W_VERSION "$campaign"; then
echo "
'
/usr/bin/sqlite3 $DATABASE "SELECT campaign,difficulty,count(*) FROM campaign_view WHERE version='$W_VERSION' GROUP BY campaign,difficulty ORDER BY campaign,count(*) DESC;" | while IFS="|" read campaign diff count; do
if ! is_official $W_VERSION "$campaign"; then
echo "
'
/usr/bin/sqlite3 -html $DATABASE "SELECT DISTINCT campaign_view.player,game_count.games_received-1,game_count.last_upload FROM campaign_view,players,game_count WHERE campaign_view.version = '$W_VERSION' AND game_count.player_ref = players.rowid AND players.id = campaign_view.player;" | sed "s,^
'
}
add_graph()
{
echo ""
}
# Graph out all campaigns a player played (unless specific requested, from graph)
do_graph_player()
{
echo '(Green means victory, red means defeat, yellow means quit. Bars indicate start/finish turn). '
if [ -n "$W_CAMPAIGN" ]; then
EXTRA="AND campaign='$W_CAMPAIGN'"
fi
for campaign_diff in `/usr/bin/sqlite3 $DATABASE "SELECT DISTINCT campaign,difficulty FROM campaign_view WHERE player='$W_PLAYER' AND version='$W_VERSION' $EXTRA;"`; do
campaign=`echo "$campaign_diff" | cut -d\| -f1`
diff=`echo "$campaign_diff" | cut -d\| -f2`
SCENARIOS=$(chop_scenarios $(/usr/bin/sqlite3 $DATABASE "SELECT DISTINCT scenario FROM campaign_view WHERE player='$W_PLAYER' AND version='$W_VERSION' AND difficulty='$diff' AND campaign='$campaign';") )
echo "Campaign $campaign ($diff):"
for scen in $SCENARIOS; do
add_graph "W_SCENARIOS=$scen&W_VERSION=$W_VERSION&W_CAMPAIGN=$campaign&W_DIFF=$diff&W_PLAYER=$W_PLAYER&W_TYPE=player" "Player progress"
done
done
echo "
"
}
graph_player()
{
print_header "Wesnoth Player $W_PLAYER"
do_graph_player
}
# Print out all scenarios a player played.
print_player()
{
print_header "Wesnoth Player $W_PLAYER"
echo '
'
echo '
ID
'
echo '
Campaign Name
'
echo '
Scenario
'
echo '
Difficulty
'
echo '
'
i=1
/usr/bin/sqlite3 $DATABASE "SELECT DISTINCT campaign,scenario,difficulty FROM campaign_view WHERE player='$W_PLAYERP' AND version='$W_VERSION';" | while IFS='|' read campaign scenario diff; do
echo "
"
}
# Print out details on a given campaign
print_campaign()
{
print_header "Wesnoth $W_CAMPAIGN ($W_DIFF)"
echo '
'
echo '
Scenario
'
echo '
'
/usr/bin/sqlite3 -html $DATABASE "SELECT DISTINCT scenario FROM campaign_view WHERE campaign = '$W_CAMPAIGNP' AND difficulty = '$W_DIFF' AND version = '$W_VERSION';"| sed "s,^
'
}
# Print out details on a given scenario
print_scenario()
{
print_header "Wesnoth Scenario $W_SCENARIO ($W_CAMPAIGN $W_DIFF)"
echo '
'
echo '
Game ID
'
echo '
Player
'
echo '
Start turn
'
echo '
Start gold
'
echo '
Time taken (sec)
'
echo '
Result
'
echo '
End turn
'
echo '
Num turns
'
echo '
'
/usr/bin/sqlite3 -html $DATABASE "SELECT game,player,start_turn,gold,time,CASE result WHEN 0 THEN 'aborted' WHEN 1 THEN 'victory' ELSE 'defeat' END, end_turn, num_turns FROM campaign_view WHERE scenario = '$W_SCENARIO' AND campaign = '$W_CAMPAIGN' AND difficulty = '$W_DIFF';" | sed "s,^
'
}
# Print out details on a given scenario.
print_player_scenario()
{
print_header "Wesnoth Player $W_PLAYER playing $W_SCENARIO ($W_CAMPAIGN $W_DIFF)"
echo "Number of turns in scenario: "
# Ideally, only returns one number...
/usr/bin/sqlite3 $DATABASE "SELECT DISTINCT num_turns from campaign_view WHERE scenario='$W_SCENARIO' AND campaign='$W_CAMPAIGN' AND player='$W_PLAYER' AND difficulty='$W_DIFF' AND version='$W_VERSION';"
echo '
'
echo '
ID
'
echo '
Start turn
'
echo '
Start gold
'
echo '
Time taken (sec)
'
echo '
End turn
'
echo '
Result
'
echo '
'
/usr/bin/sqlite3 -html $DATABASE "SELECT game,start_turn,gold,time,end_turn,CASE result WHEN 0 THEN 'aborted' WHEN 1 THEN 'victory' ELSE 'defeat' END FROM campaign_view WHERE version='$W_VERSION' AND player='$W_PLAYER' AND scenario='$W_SCENARIO' AND difficulty='$W_DIFF' AND campaign='$W_CAMPAIGN' ORDER BY game;" | sed "s,^
'
}
# Print out details and units for a given game.
print_game()
{
print_header "Details of game $W_GAME"
echo '
'
/usr/bin/sqlite3 $DATABASE "SELECT campaign,difficulty,scenario,player,version,gold,start_turn,end_turn,num_turns,time,result FROM campaign_view WHERE game='$W_GAME';" | (IFS="|" read cam diff scen player ver gold st et nt time result
echo "Campaign: $cam "
echo "Difficulty: $diff "
echo "Scenario: $scen "
echo "Player: $player "
echo "Version: $ver "
echo "Start gold: $gold "
echo "Start turn: $st "
echo "End turn: $et "
echo "Num turns: $nt "
echo "Time taken (sec): $time "
echo "Result:"
case $result in
0) echo "aborted";;
1) echo "victory";;
2) echo "defeat";;
esac
echo " ")
echo "
Important Unit Stats (at Start of Game)
"
echo '
'
echo '
Name
'
echo '
Level
'
echo '
Experience
'
echo '
'
/usr/bin/sqlite3 -html $DATABASE "SELECT unit_names.name,special_units.level,special_units.experience FROM special_units,unit_names WHERE special_units.game_ref=$W_GAME AND unit_names.rowid=special_units.unit_name_ref;"
echo '
'
echo "
Wesnoth Unit Summary (at Start of Game)
"
echo '
'
echo '
Type
'
echo '
Level
'
echo '
Number
'
echo '
'
/usr/bin/sqlite3 -html $DATABASE "SELECT unit_types.name,unit_types.level,unit_tallies.count FROM unit_types,unit_tallies WHERE unit_tallies.game_ref=$W_GAME AND unit_types.rowid=unit_tallies.unit_type_ref ORDER BY unit_types.level DESC,unit_types.name;"
echo '
'
}
# Simple access page which is given in the Help Wesnoth dialog
my_page()
{
VERSIONS=`/usr/bin/sqlite3 $DATABASE "SELECT DISTINCT version FROM campaign_view WHERE player=$W_P;"`
# By default, use latest version for this player
if [ -z "$W_VERSION" ]; then
W_VERSION=`echo "$VERSIONS" | tail -1`
fi
print_header "Wesnoth Page for Player $W_PLAYER"
echo "Versions played: "
sep=""
for ver in $VERSIONS; do
if [ "$ver" = "$W_VERSION" ]; then
echo "$sep $W_VERSION"
else
echo "$sep $ver "
fi
sep="|"
done
W_PLAYER=$W_P do_graph_player
}
echo "Content-type: text/html"
echo
cat /home/rusty/public_html/stats.wesnoth.org/header.html
# We accept a simple numeric arg for player id.
if echo "$QUERY_STRING" | grep -q '^[0-9][0-9]*$'; then
QUERY_STRING="W_P=$QUERY_STRING"
fi
. check_args.sh
case "$QUERY_STRING" in
W_PLAYER=*)
graph_player
;;
W_PLAYERP=*)
print_player
;;
W_CAMPAIGN=*)
graph_campaign
;;
W_CAMPAIGNP=*)
print_campaign
;;
W_SCENARIO=*)
print_scenario
;;
W_PLAYERSCENARIO=*)
print_player_scenario
;;
W_GAME=*)
print_game
;;
W_P=*)
my_page
;;
W_PLAYERS=*)
print_players
;;
*)
print_main
;;
esac
echo '
This page based generated from a database, which was last modified '`date -u -r $DATABASE`'.