From bf52d416500b530bb65ccb54cdc41e5d7d6c4d51 Mon Sep 17 00:00:00 2001 From: kpcyrd Date: Sat, 9 Aug 2014 12:01:43 +0200 Subject: [PATCH 1/4] Improve type-safty in player.php --- player.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/player.php b/player.php index 33f02215..1f9600d8 100644 --- a/player.php +++ b/player.php @@ -1,12 +1,15 @@ - <?php echo htmlspecialchars($_GET['t']); ?> + <?php echo htmlspecialchars($t); ?> @@ -17,8 +20,8 @@ $loop = ($_GET['loop'] != "0"); >[loop]
-
From 33c6d6644e9e94904327f9f93f5c7a13e2727e0b Mon Sep 17 00:00:00 2001 From: kpcyrd Date: Sat, 9 Aug 2014 12:14:56 +0200 Subject: [PATCH 2/4] Suppress warnings that might leak information --- player.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/player.php b/player.php index 1f9600d8..d1a76a86 100644 --- a/player.php +++ b/player.php @@ -1,8 +1,8 @@ From 1ea3da1db6c5291abfbd99aa8f5f7e28de8ed9ed Mon Sep 17 00:00:00 2001 From: 8chan Date: Sun, 10 Aug 2014 14:51:45 +0000 Subject: [PATCH 3/4] Merge Barrucadu/diceroll into master --- inc/config.php | 4 ++++ inc/functions.php | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/inc/config.php b/inc/config.php index 91e53a6d..802a1471 100644 --- a/inc/config.php +++ b/inc/config.php @@ -549,6 +549,10 @@ 'eu' => 'Europe' ); */ + + // Allow dice rolling: an email field of the form "dice XdY+/-Z" will result in X Y-sided dice rolled and summed, + // with the modifier Z added, with the result displayed at the top of the post body. + $config['allow_roll'] = false; /* * ==================== diff --git a/inc/functions.php b/inc/functions.php index af2136bb..24ec3863 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -243,6 +243,9 @@ function loadConfig() { if (is_array($config['anonymous'])) $config['anonymous'] = $config['anonymous'][array_rand($config['anonymous'])]; + if ($config['allow_roll']) + event_handler('post', 'diceRoller'); + event('load-config'); if ($config['debug']) { @@ -2323,3 +2326,61 @@ function shell_exec_error($command, $suppress_stdout = false) { return $return === 'TB_SUCCESS' ? false : $return; } + +/* Die rolling: + * If "dice XdY+/-Z" is in the email field (where X or +/-Z may be + * missing), X Y-sided dice are rolled and summed, with the modifier Z + * added on. The result is displayed at the top of the post. + */ +function diceRoller($post) { + if(strpos(strtolower($post->email), 'dice%20') === 0) { + $dicestr = str_split(substr($post->email, strlen('dice%20'))); + + // Get params + $diceX = ''; + $diceY = ''; + $diceZ = ''; + + $curd = 'diceX'; + for($i = 0; $i < count($dicestr); $i ++) { + if(is_numeric($dicestr[$i])) { + $$curd .= $dicestr[$i]; + } else if($dicestr[$i] == 'd') { + $curd = 'diceY'; + } else if($dicestr[$i] == '-' || $dicestr[$i] == '+') { + $curd = 'diceZ'; + $$curd = $dicestr[$i]; + } + } + + // Default values for X and Z + if($diceX == '') { + $diceX = '1'; + } + + if($diceZ == '') { + $diceZ = '+0'; + } + + // Intify them + $diceX = intval($diceX); + $diceY = intval($diceY); + $diceZ = intval($diceZ); + + // Continue only if we have valid values + if($diceX > 0 && $diceY > 0) { + $dicerolls = array(); + $dicesum = $diceZ; + for($i = 0; $i < $diceX; $i++) { + $roll = rand(1, $diceY); + $dicerolls[] = $roll; + $dicesum += $roll; + } + + // Prepend the result to the post body + $modifier = ($diceZ != 0) ? ((($diceZ < 0) ? ' - ' : ' + ') . abs($diceZ)) : ''; + $dicesum = ($diceX > 1) ? ' = ' . $dicesum : ''; + $post->body = 'Rolled ' . implode(', ', $dicerolls) . $modifier . $dicesum . '
' . $post->body; + } + } +} From e28f233e3de6d471ab2ce9c178ba8d626bbeb563 Mon Sep 17 00:00:00 2001 From: 8chan Date: Sun, 10 Aug 2014 15:14:11 +0000 Subject: [PATCH 4/4] Close #51: Prevent players from cheating the dice roller by using markup --- inc/functions.php | 3 +- static/d10.svg | 161 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 static/d10.svg diff --git a/inc/functions.php b/inc/functions.php index 24ec3863..a88e8fc8 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2333,6 +2333,7 @@ function shell_exec_error($command, $suppress_stdout = false) { * added on. The result is displayed at the top of the post. */ function diceRoller($post) { + global $config; if(strpos(strtolower($post->email), 'dice%20') === 0) { $dicestr = str_split(substr($post->email, strlen('dice%20'))); @@ -2380,7 +2381,7 @@ function diceRoller($post) { // Prepend the result to the post body $modifier = ($diceZ != 0) ? ((($diceZ < 0) ? ' - ' : ' + ') . abs($diceZ)) : ''; $dicesum = ($diceX > 1) ? ' = ' . $dicesum : ''; - $post->body = 'Rolled ' . implode(', ', $dicerolls) . $modifier . $dicesum . '
' . $post->body; + $post->body = '
Dice rollRolled ' . implode(', ', $dicerolls) . $modifier . $dicesum . '

' . $post->body; } } } diff --git a/static/d10.svg b/static/d10.svg new file mode 100644 index 00000000..4d608be7 --- /dev/null +++ b/static/d10.svg @@ -0,0 +1,161 @@ + + + + Ten Side Dice + + + + + + + + image/svg+xml + + + + + Openclipart + + + Ten Sided Dice + 2010-11-06T04:13:53 + A single-colour graphic of a 10-sided die (d10) as used in roleplaying and wargaming. + https://openclipart.org/detail/94495/ten-sided-dice-by-wirelizard + + + wirelizard + + + + + RPG + d10 + dice + die + game + gamer + gaming + roleplay + ten side + + + + + + + + + + +