diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index 94a472711..d22658250 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -686,10 +686,21 @@ linux_relay_receive( CommonGlobals* cGlobals, unsigned char* buf, int bufSize ) strerror(errno) ); } - if ( cGlobals->params->dropNth > 0 ) { - if ( --cGlobals->params->dropNth == 0 ) { - XP_LOGF( "%s: dropping packet per --drop-nth-packet", - __func__ ); + LaunchParams* params = cGlobals->params; + ++params->nPacketsRcvd; + if ( params->dropNthRcvd == 0 ) { + /* do nothing */ + } else if ( params->dropNthRcvd > 0 ) { + if ( params->nPacketsRcvd == params->dropNthRcvd ) { + XP_LOGF( "%s: dropping %dth packet per --drop-nth-packet", + __func__, params->nPacketsRcvd ); + nRead = -1; + } + } else { + if ( 0 == XP_RANDOM() % -params->dropNthRcvd ) { + XP_LOGF( "%s: RANDOMLY dropping %dth packet " + "per --drop-nth-packet", + __func__, params->nPacketsRcvd ); nRead = -1; } } @@ -1049,7 +1060,7 @@ main( int argc, char** argv ) mainParams.duplicatePackets = XP_TRUE; break; case CMD_DROPNTHPACKET: - mainParams.dropNth = atoi( optarg ); + mainParams.dropNthRcvd = atoi( optarg ); break; case CMD_NOHINTS: mainParams.gi.hintsNotAllowed = XP_TRUE; diff --git a/xwords4/linux/main.h b/xwords4/linux/main.h index 4aeebb05a..388f8586d 100644 --- a/xwords4/linux/main.h +++ b/xwords4/linux/main.h @@ -54,7 +54,8 @@ typedef struct LaunchParams { VTableMgr* vtMgr; XP_U16 nLocalPlayers; XP_U16 nHidden; - XP_U16 dropNth; + XP_S16 dropNthRcvd; /* negative means use for random calc */ + XP_U16 nPacketsRcvd; /* toward dropNthRcvd */ XP_Bool askNewGame; XP_S16 quitAfter; XP_Bool sleepOnAnchor; diff --git a/xwords4/linux/scripts/discon_ok2.sh b/xwords4/linux/scripts/discon_ok2.sh index 55a5292b5..69c0661f4 100755 --- a/xwords4/linux/scripts/discon_ok2.sh +++ b/xwords4/linux/scripts/discon_ok2.sh @@ -10,7 +10,7 @@ DICTS=${DICTS:-dict.xwd} SAVE_GOOD=${SAVE_GOOD:-YES} MAXDEVS=${MAXDEVS:-4} RESIGN_RATIO=${RESIGN_RATIO:-$((NGAMES/3))} -DROP_N=1 +DROP_N=${DROP_N:-1} declare -a DICTS_ARR for DICT in $DICTS; do @@ -257,7 +257,7 @@ run_cmds() { sleep 2 # make sure it's had some time kill ${PIDS[$KEY]} || true PIDS[$KEY]=0 - increment_drop $KEY + [ $DROP_N -ge 0 ] && increment_drop $KEY check_game $KEY fi done