add new mode that only launches games after the relay says there's a

message for them.  This is to mimic a common way games are played on
Android and to ensure that there are no points where that style of
play hangs because no device in the game will be "up".
This commit is contained in:
Andy2 2011-07-04 19:46:12 -07:00
parent 999d4c11e7
commit 4789bac85e
2 changed files with 95 additions and 6 deletions

View file

@ -14,6 +14,7 @@ RESIGN_RATIO=${RESIGN_RATIO:-$((NGAMES*2))}
DROP_N=${DROP_N:-0} DROP_N=${DROP_N:-0}
MINRUN=2 MINRUN=2
ONE_PER_ROOM="" ONE_PER_ROOM=""
ALL_VIA_RQ=${ALL_VIA_RQ:-FALSE}
declare -a DICTS_ARR declare -a DICTS_ARR
for DICT in $DICTS; do for DICT in $DICTS; do
@ -60,6 +61,9 @@ declare -A FILES
declare -A LOGS declare -A LOGS
declare -A MINEND declare -A MINEND
declare -A ROOM_PIDS declare -A ROOM_PIDS
# if [ TRUE = "$ALL_VIA_RQ" ]; then
# declare -A PIPES
# fi
PLAT_PARMS="" PLAT_PARMS=""
if [ $USE_GTK = FALSE ]; then if [ $USE_GTK = FALSE ]; then
@ -69,7 +73,7 @@ fi
usage() { usage() {
echo "usage: [env=val *] $0" 1>&2 echo "usage: [env=val *] $0" 1>&2
echo " current env variables and their values: " 1>&2 echo " current env variables and their values: " 1>&2
for VAR in NGAMES NROOMS USE_GTK TIMEOUT HOST PORT DICTS SAVE_GOOD MINDEVS MAXDEVS RESIGN_RATIO DROP_N; do for VAR in NGAMES NROOMS USE_GTK TIMEOUT HOST PORT DICTS SAVE_GOOD MINDEVS MAXDEVS RESIGN_RATIO DROP_N ALL_VIA_RQ; do
echo "$VAR:" $(eval "echo \$${VAR}") 1>&2 echo "$VAR:" $(eval "echo \$${VAR}") 1>&2
done done
exit 1 exit 1
@ -135,7 +139,9 @@ build_cmds() {
CMD="./obj_linux_memdbg/xwords --room $ROOM" CMD="./obj_linux_memdbg/xwords --room $ROOM"
CMD="$CMD --robot ${NAMES[$DEV]} --robot-iq $((1 + (RANDOM%100))) " CMD="$CMD --robot ${NAMES[$DEV]} --robot-iq $((1 + (RANDOM%100))) "
CMD="$CMD $OTHERS --game-dict $DICT --port $PORT --host $HOST " CMD="$CMD $OTHERS --game-dict $DICT --port $PORT --host $HOST "
CMD="$CMD --file $FILE --slow-robot 1:3 --drop-nth-packet $DROP_N $PLAT_PARMS" CMD="$CMD --file $FILE --slow-robot 1:3"
CMD="$CMD --drop-nth-packet $DROP_N $PLAT_PARMS"
CMD="$CMD $PUBLIC" CMD="$CMD $PUBLIC"
CMDS[$COUNTER]=$CMD CMDS[$COUNTER]=$CMD
ROOMS[$COUNTER]=$ROOM ROOMS[$COUNTER]=$ROOM
@ -184,6 +190,15 @@ launch() {
exec $CMD >/dev/null 2>>$LOG exec $CMD >/dev/null 2>>$LOG
} }
# launch_via_rq() {
# KEY=$1
# RELAYID=$2
# PIPE=${PIPES[$KEY]}
# ../relay/rq -f $RELAYID -o $PIPE &
# CMD="${CMDS[$KEY]}"
# exec $CMD >/dev/null 2>>$LOG
# }
close_device() { close_device() {
ID=$1 ID=$1
MVTO=$2 MVTO=$2
@ -212,7 +227,7 @@ close_device() {
kill_from_log() { kill_from_log() {
LOG=$1 LOG=$1
RELAYID=$(./scripts/relayID.sh $LOG) RELAYID=$(./scripts/relayID.sh --long $LOG)
if [ -n "$RELAYID" ]; then if [ -n "$RELAYID" ]; then
../relay/rq -a $HOST -d $RELAYID 2>/dev/null || true ../relay/rq -a $HOST -d $RELAYID 2>/dev/null || true
return 0 # success return 0 # success
@ -329,6 +344,55 @@ run_cmds() {
fi fi
} }
# add_pipe() {
# KEY=$1
# CMD=${CMDS[$KEY]}
# LOG=${LOGS[$KEY]}
# PIPE=${LOG/LOG.txt/pipe}
# PIPES[$KEY]=$PIPE
# echo "mkfifo $PIPE"
# mkfifo $PIPE
# CMDS[$KEY]="$CMD --with-pipe $PIPE"
# echo ${CMDS[$KEY]}
# }
run_via_rq() {
# launch then kill all games to give chance to hook up
for KEY in ${!CMDS[*]}; do
echo "launching $KEY"
launch $KEY &
PID=$!
sleep 1
kill $PID
wait $PID
# add_pipe $KEY
done
echo "now running via rq"
# then run them
while :; do
COUNT=${#CMDS[*]}
[ 0 -ge $COUNT ] && break
INDX=$(($RANDOM%COUNT))
KEYS=( ${!CMDS[*]} )
KEY=${KEYS[$INDX]}
CMD=${CMDS[$KEY]}
RELAYID=$(./scripts/relayID.sh --short ${LOGS[$KEY]})
MSG_COUNT=$(../relay/rq -a $HOST -m $RELAYID 2>/dev/null | sed 's,^.*-- ,,')
if [ $MSG_COUNT -gt 0 ]; then
launch $KEY &
PID=$!
sleep 2
kill $PID || true
wait $PID
fi
[ "$DROP_N" -ge 0 ] && increment_drop $KEY
check_game $KEY
done
} # run_via_rq
print_stats() { print_stats() {
: :
} }
@ -336,7 +400,11 @@ print_stats() {
echo "*********$0 starting: $(date)**************" echo "*********$0 starting: $(date)**************"
STARTTIME=$(date +%s) STARTTIME=$(date +%s)
[ -z "$RESUME" ] && build_cmds || read_resume_cmds [ -z "$RESUME" ] && build_cmds || read_resume_cmds
run_cmds if [ TRUE = "$ALL_VIA_RQ" ]; then
run_via_rq
else
run_cmds
fi
print_stats print_stats
wait wait

View file

@ -1,5 +1,22 @@
#!/bin/sh #!/bin/sh
set -u -e
usage() {
echo "usage: %0 --long|--short logfile*"
exit 1
}
if [ "--long" = $1 ]; then
LONG=1
elif [ "--short" = $1 ]; then
LONG=""
else
usage
fi
shift
while [ $# -ge 1 ]; do while [ $# -ge 1 ]; do
LOG=$1 LOG=$1
while read LINE; do while read LINE; do
@ -21,10 +38,14 @@ while [ $# -ge 1 ]; do
echo "HOSTID not found in $LOG" >&2 echo "HOSTID not found in $LOG" >&2
elif [ "${HOSTID}" -eq 0 ]; then elif [ "${HOSTID}" -eq 0 ]; then
echo "HOSTID 0 in $LOG; try later" >&2 echo "HOSTID 0 in $LOG; try later" >&2
elif [ -z "${SEED}" ]; then elif [ -n "$LONG" -a -z "${SEED}" ]; then
echo "SEED not found in $LOG" >&2 echo "SEED not found in $LOG" >&2
else else
echo ${CONNNAME}/${HOSTID}/${SEED} RESULT=${CONNNAME}/${HOSTID}
if [ -n "$LONG" ]; then
RESULT="${RESULT}/${SEED}"
fi
echo $RESULT
fi fi
shift shift