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-react": "^6.11.1",
"howler": "^2.0.1",
"js-base64": "^2.1.9",
"react": "^15.3.2",
"react-dom": "^15.3.2"
},

View File

@@ -53,7 +53,7 @@ class MineSeeker extends React.Component {
session
.call(
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(
(gridServer) => {
@@ -63,7 +63,7 @@ class MineSeeker extends React.Component {
/** save session to GridControl */
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,
channel: this.state.channel
});

View File

@@ -20,5 +20,6 @@
{{ ws_client() }}
<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>
{% endblock %}

View File

@@ -43,7 +43,7 @@ class AcmeRpc implements RpcInterface
* @param ConnectionInterface $connection
* @param WampRequest $request
* @param array $params
* @return Grid
* @return boolean
*/
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)
{
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
* @return Grid
* @return boolean
*/
private function saveGrid($data)
{
$playedGame = new PlayedGame();
$grid = new Grid();
foreach ($data[0] as $row) {
foreach (json_decode(base64_decode($data[0])) as $row) {
$gridRow = new GridRow();
foreach ($row as $col) {