Private
Public Access
1
0

add base64 encryption to grid when it has been sended to server

This commit is contained in:
2016-10-31 19:44:20 +01:00
parent 625c0e9c91
commit 23d334ab27
4 changed files with 8 additions and 6 deletions

View File

@@ -11,6 +11,7 @@
"babel-preset-es2015": "^6.14.0", "babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.11.1", "babel-preset-react": "^6.11.1",
"howler": "^2.0.1", "howler": "^2.0.1",
"js-base64": "^2.1.9",
"react": "^15.3.2", "react": "^15.3.2",
"react-dom": "^15.3.2" "react-dom": "^15.3.2"
}, },

View File

@@ -53,7 +53,7 @@ class MineSeeker extends React.Component {
session session
.call( .call(
this.state.gameInherited ? "sample/connectGame" : "sample/startGame", this.state.gameInherited ? "sample/connectGame" : "sample/startGame",
this.state.gameInherited ? this.state.gameAssoc : [gridClient, this.state.gameAssoc] this.state.gameInherited ? this.state.gameAssoc : [Base64.encode(JSON.stringify(gridClient)), this.state.gameAssoc]
) )
.then( .then(
(gridServer) => { (gridServer) => {
@@ -63,7 +63,7 @@ class MineSeeker extends React.Component {
/** save session to GridControl */ /** save session to GridControl */
this.refs.gridControl.setState({ this.refs.gridControl.setState({
grid: this.state.gameInherited ? JSON.parse(gridServer) : gridClient, grid: this.state.gameInherited ? JSON.parse(Base64.decode(gridServer)) : gridClient,
session: this.state.session, session: this.state.session,
channel: this.state.channel channel: this.state.channel
}); });

View File

@@ -20,5 +20,6 @@
{{ ws_client() }} {{ ws_client() }}
<script type="text/javascript" src="{{ asset('node/howler/dist/howler.min.js') }}"></script> <script type="text/javascript" src="{{ asset('node/howler/dist/howler.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('node/js-base64/base64.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/index.js') }}"></script> <script type="text/javascript" src="{{ asset('js/index.js') }}"></script>
{% endblock %} {% endblock %}

View File

@@ -43,7 +43,7 @@ class AcmeRpc implements RpcInterface
* @param ConnectionInterface $connection * @param ConnectionInterface $connection
* @param WampRequest $request * @param WampRequest $request
* @param array $params * @param array $params
* @return Grid * @return boolean
*/ */
public function startGame(ConnectionInterface $connection, WampRequest $request, array $params) public function startGame(ConnectionInterface $connection, WampRequest $request, array $params)
{ {
@@ -58,7 +58,7 @@ class AcmeRpc implements RpcInterface
*/ */
public function connectGame(ConnectionInterface $connection, WampRequest $request, array $params) public function connectGame(ConnectionInterface $connection, WampRequest $request, array $params)
{ {
return json_encode($this->getGrid($params), JSON_NUMERIC_CHECK); return base64_encode(json_encode($this->getGrid($params), JSON_NUMERIC_CHECK));
} }
/** /**
@@ -91,14 +91,14 @@ class AcmeRpc implements RpcInterface
/** /**
* @param $data * @param $data
* @return Grid * @return boolean
*/ */
private function saveGrid($data) private function saveGrid($data)
{ {
$playedGame = new PlayedGame(); $playedGame = new PlayedGame();
$grid = new Grid(); $grid = new Grid();
foreach ($data[0] as $row) { foreach (json_decode(base64_decode($data[0])) as $row) {
$gridRow = new GridRow(); $gridRow = new GridRow();
foreach ($row as $col) { foreach ($row as $col) {