Skip to content

Commit 58cbd1e

Browse files
Stefan-Hankenicolodavis
authored andcommitted
Redact Log Events (#268)
1 parent ed165a8 commit 58cbd1e

13 files changed

Lines changed: 373 additions & 7 deletions

File tree

docs/api/Game.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ game state and the moves. The moves are converted to a
3131
Code to run at the end of a move.
3232
* `flow.movesPerTurn` (_number_): Ends the turn automatically if a certain number
3333
of moves have been made.
34-
* `flow.undoableMoves` (_array_): Enables undo and redo of listed moves.
35-
Leave `undefined` if all moves should be undoable.
34+
* `flow.undoableMoves` (_array_): Enables undo and redo of listed moves. Leave `undefined` if all moves should be undoable.
35+
* `flow.redactedMoves` (_array_): List of moves to redact from the log.
36+
* `flow.optimisticUpdate` (_function_): _(G, ctx, move) => boolean_
37+
Return `false` to disable optimistic execution of a particular move on the client.
3638
* `flow.phases` (_object_): Optional spec of game phases. See
3739
[Phases](/phases) for more information.
3840

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright 2018 The boardgame.io Authors
3+
*
4+
* Use of this source code is governed by a MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
.secret-state section {
10+
text-align: left;
11+
padding: 10px;
12+
margin-bottom: 20px;
13+
background: #eee;
14+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2017 The boardgame.io Authors.
3+
*
4+
* Use of this source code is governed by a MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
import React from 'react';
10+
import PropTypes from 'prop-types';
11+
import './board.css';
12+
13+
const Board = ({ G, ctx, moves, playerID, log }) => (
14+
<div className="secret-state">
15+
<section>
16+
<strong>G</strong>
17+
<pre>{JSON.stringify(G, null, 2)}</pre>
18+
19+
<strong>log</strong>
20+
<pre>{JSON.stringify(log, null, 2)}</pre>
21+
{playerID && (
22+
<button
23+
onClick={() =>
24+
moves.clickCell({ secret: G.players[ctx.currentPlayer] })
25+
}
26+
>
27+
Click Cell
28+
</button>
29+
)}
30+
</section>
31+
</div>
32+
);
33+
34+
Board.propTypes = {
35+
G: PropTypes.any.isRequired,
36+
ctx: PropTypes.any.isRequired,
37+
moves: PropTypes.any.isRequired,
38+
playerID: PropTypes.any,
39+
log: PropTypes.any,
40+
};
41+
42+
export default Board;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2018 The boardgame.io Authors
3+
*
4+
* Use of this source code is governed by a MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
import { Game, PlayerView, TurnOrder } from 'boardgame.io/core';
10+
11+
const RedactedMoves = Game({
12+
name: 'secret-state',
13+
14+
setup: () => ({
15+
other: {},
16+
players: {
17+
0: 'player 0 state',
18+
1: 'player 1 state',
19+
},
20+
}),
21+
22+
moves: {
23+
/* eslint-disable no-unused-vars */
24+
clickCell(G, ctx, secretstuff) {
25+
return { ...G };
26+
},
27+
/* eslint-enable no-unused-vars */
28+
},
29+
30+
flow: {
31+
redactedMoves: ['clickCell'],
32+
turnOrder: TurnOrder.ANY,
33+
},
34+
35+
playerView: PlayerView.STRIP_SECRETS,
36+
});
37+
38+
export default RedactedMoves;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2018 The boardgame.io Authors.
3+
*
4+
* Use of this source code is governed by a MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
import Multiview from './multiview';
10+
11+
const routes = [
12+
{
13+
path: '/redacted_move',
14+
text: 'Example',
15+
component: Multiview,
16+
},
17+
];
18+
19+
export default { routes };
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2018 The boardgame.io Authors.
3+
*
4+
* Use of this source code is governed by a MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
import React from 'react';
10+
import { Client } from 'boardgame.io/react';
11+
import Game from './game';
12+
import Board from './board';
13+
14+
const App = Client({
15+
game: Game,
16+
numPlayers: 2,
17+
board: Board,
18+
debug: false,
19+
multiplayer: { local: true },
20+
});
21+
22+
const Multiview = () => (
23+
<div style={{ padding: 50 }}>
24+
<h1>Redacted Moves</h1>
25+
<p>
26+
This examples demonstrates the use of redacted moves. Using redacted moves
27+
allows for secret information to be stripped from the log for other
28+
players.
29+
</p>
30+
<p>
31+
Clicking the button on one of the players, you should see complete log
32+
event for that player but a redacted one for everyone else.
33+
</p>
34+
<div className="runner">
35+
<div className="run">
36+
<App gameID="redacted-move" playerID="0" />
37+
&lt;App playerID=&quot;0&quot;/&gt;
38+
</div>
39+
<div className="run">
40+
<App gameID="redacted-move" playerID="1" />
41+
&lt;App playerID=&quot;1&quot;/&gt;
42+
</div>
43+
<div className="run">
44+
<App gameID="redacted-move" />
45+
&lt;App/&gt;
46+
</div>
47+
</div>
48+
</div>
49+
);
50+
51+
export default Multiview;

examples/react/routes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import random from './random';
1414
import turnorder from './turnorder';
1515
import ui from './ui';
1616
import threejs from './threejs';
17+
import redacted_move from './redacted-move';
1718

1819
const routes = [
1920
{
@@ -40,6 +41,10 @@ const routes = [
4041
name: 'Secret State',
4142
routes: secret_state.routes,
4243
},
44+
{
45+
name: 'Redacted Move',
46+
routes: redacted_move.routes,
47+
},
4348
{
4449
name: 'UI',
4550
routes: ui.routes,

examples/react/secret-state/board.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,28 @@ import React from 'react';
1010
import PropTypes from 'prop-types';
1111
import './board.css';
1212

13-
const Board = ({ G }) => (
13+
const Board = ({ G, ctx, moves, playerID }) => (
1414
<div className="secret-state">
1515
<section>
1616
<pre>{JSON.stringify(G, null, 2)}</pre>
17+
{playerID && (
18+
<button
19+
onClick={() =>
20+
moves.clickCell({ secret: G.players[ctx.currentPlayer] })
21+
}
22+
>
23+
Click Cell
24+
</button>
25+
)}
1726
</section>
1827
</div>
1928
);
2029

2130
Board.propTypes = {
2231
G: PropTypes.any.isRequired,
32+
ctx: PropTypes.any.isRequired,
33+
moves: PropTypes.any.isRequired,
34+
playerID: PropTypes.any,
2335
};
2436

2537
export default Board;

examples/react/secret-state/game.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ const SecretState = Game({
2020
},
2121
}),
2222

23+
moves: {
24+
clickCell(G) {
25+
return { ...G };
26+
},
27+
},
28+
2329
playerView: PlayerView.STRIP_SECRETS,
2430
});
2531

examples/react/secret-state/multiview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const App = Client({
1616
numPlayers: 3,
1717
board: Board,
1818
debug: false,
19-
multiplayer: true,
19+
multiplayer: { local: true },
2020
});
2121

2222
const Multiview = () => (

0 commit comments

Comments
 (0)