current username checked && refactor && remove players in channel when they are more than 2
This commit is contained in:
@@ -4,6 +4,7 @@ import MineSeeker from './mine-seeker/app';
|
|||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<MineSeeker env={document.getElementById('mine-wrapper').dataset.env}
|
<MineSeeker env={document.getElementById('mine-wrapper').dataset.env}
|
||||||
gameId={document.getElementById('mine-wrapper').dataset.gameId}/>,
|
gameId={document.getElementById('mine-wrapper').dataset.gameId}
|
||||||
|
userName={document.getElementById('mine-wrapper').dataset.userName}/>,
|
||||||
document.getElementById('mine-wrapper')
|
document.getElementById('mine-wrapper')
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,11 +8,13 @@ class MineSeeker extends React.Component {
|
|||||||
|
|
||||||
var gameAssoc = props.gameId !== '' ? props.gameId : this.makeGameAssoc(50);
|
var gameAssoc = props.gameId !== '' ? props.gameId : this.makeGameAssoc(50);
|
||||||
var channel = "acme/channel/" + gameAssoc;
|
var channel = "acme/channel/" + gameAssoc;
|
||||||
|
var userName = props.userName;
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
gameInherited: props.gameId !== '',
|
gameInherited: props.gameId !== '',
|
||||||
gameAssoc: gameAssoc,
|
gameAssoc: gameAssoc,
|
||||||
channel: channel,
|
channel: channel,
|
||||||
|
userName: userName,
|
||||||
session: null,
|
session: null,
|
||||||
createGrid: false,
|
createGrid: false,
|
||||||
stepCache: null
|
stepCache: null
|
||||||
@@ -66,12 +68,14 @@ class MineSeeker extends React.Component {
|
|||||||
channel: this.state.channel
|
channel: this.state.channel
|
||||||
});
|
});
|
||||||
|
|
||||||
/** setup the web player */
|
/** setup the web player && save player name */
|
||||||
if (this.refs.gridControl.state.webPlayer === null) {
|
if (this.refs.gridControl.state.webPlayer === null) {
|
||||||
if (this.state.gameInherited) {
|
if (this.state.gameInherited) {
|
||||||
this.refs.gridControl.state.webPlayer = 'blue';
|
this.refs.gridControl.state.webPlayer = 'blue';
|
||||||
|
this.refs.gridControl.refs.userControl.refs.blue.setState({name: this.state.userName});
|
||||||
} else {
|
} else {
|
||||||
this.refs.gridControl.state.webPlayer = 'red';
|
this.refs.gridControl.state.webPlayer = 'red';
|
||||||
|
this.refs.gridControl.refs.userControl.refs.red.setState({name: this.state.userName});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,12 +90,19 @@ class MineSeeker extends React.Component {
|
|||||||
/** Auto-Step if this player is not the current user */
|
/** Auto-Step if this player is not the current user */
|
||||||
if (this.refs.gridControl.state.webPlayer !== payload.data.player) {
|
if (this.refs.gridControl.state.webPlayer !== payload.data.player) {
|
||||||
console.warn('Opponent stepped: Auto-Step process');
|
console.warn('Opponent stepped: Auto-Step process');
|
||||||
|
|
||||||
this.refs.gridControl.refs.userControl.state.bombSelected = payload.data.bomb;
|
this.refs.gridControl.refs.userControl.state.bombSelected = payload.data.bomb;
|
||||||
this.refs.gridControl.stepEvent(payload.data.coords);
|
this.refs.gridControl.stepEvent(payload.data.coords);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.info("User has been subscribed to the channel!");
|
console.info(
|
||||||
|
(typeof payload.user !== 'undefined' ? payload.user : 'user') + " has been subscribed to the channel!"
|
||||||
|
);
|
||||||
|
|
||||||
|
// /** Save the opponent's player name */
|
||||||
|
// if (this.state.gameInherited) {
|
||||||
|
// this.refs.gridControl.refs.userControl.refs.blue.setState({name: payload.user});
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -368,14 +368,8 @@ class GridControl extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<div className="game-wrapper">
|
<div className="game-wrapper">
|
||||||
<UserControl ref="userControl"
|
<UserControl ref="userControl"
|
||||||
blue="Olcsó János"
|
|
||||||
red="Eszet Lenke"
|
|
||||||
bombClear={this.bombClear.bind(this)}/>
|
bombClear={this.bombClear.bind(this)}/>
|
||||||
<div className="grid">
|
<div className="grid"> {grid} </div>
|
||||||
{/*{this.renderGridFields()}*/}
|
|
||||||
{grid}
|
|
||||||
</div>
|
|
||||||
{/*{this.playingSound()}*/}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ class UserControl extends React.Component {
|
|||||||
<div className="users">
|
<div className="users">
|
||||||
<User ref="blue"
|
<User ref="blue"
|
||||||
color="blue"
|
color="blue"
|
||||||
name={this.props.blue}
|
|
||||||
active={this.state.activePlayer === 1}
|
active={this.state.activePlayer === 1}
|
||||||
onClickBombSelector={this.onClickBombSelector.bind(this, 1)}/>
|
onClickBombSelector={this.onClickBombSelector.bind(this, 1)}/>
|
||||||
<div className="active-mines-container">
|
<div className="active-mines-container">
|
||||||
@@ -56,7 +55,6 @@ class UserControl extends React.Component {
|
|||||||
<div className="clear"></div>
|
<div className="clear"></div>
|
||||||
<User ref="red"
|
<User ref="red"
|
||||||
color="red"
|
color="red"
|
||||||
name={this.props.red}
|
|
||||||
active={this.state.activePlayer === 0}
|
active={this.state.activePlayer === 0}
|
||||||
onClickBombSelector={this.onClickBombSelector.bind(this, 0)}/>
|
onClickBombSelector={this.onClickBombSelector.bind(this, 0)}/>
|
||||||
<div className="resign">
|
<div className="resign">
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class User extends React.Component {
|
|||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
name: props.name,
|
name: "...",
|
||||||
active: props.active,
|
active: props.active,
|
||||||
color: props.color === 'blue' ? 1 : 0,
|
color: props.color === 'blue' ? 1 : 0,
|
||||||
mines: 0,
|
mines: 0,
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
{% block body %}
|
{% block body %}
|
||||||
<div id="mine-wrapper"
|
<div id="mine-wrapper"
|
||||||
data-env="{{ env }}"
|
data-env="{{ env }}"
|
||||||
data-game-id="{{ app.request.get('gameAssoc') }}">
|
data-game-id="{{ app.request.get('gameAssoc') }}"
|
||||||
|
data-user-name="{{ app.user.username }}">
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@@ -43,12 +43,17 @@ class AcmeTopic implements TopicInterface
|
|||||||
$user = $this->clientManipulator->getClient($connection);
|
$user = $this->clientManipulator->getClient($connection);
|
||||||
$userName = is_string($user) ? $user : $user->getUsername();
|
$userName = is_string($user) ? $user : $user->getUsername();
|
||||||
|
|
||||||
$topic->broadcast([
|
/** if more user wants to connect than 2 to one channel */
|
||||||
'userTopicId' => $connection->resourceId,
|
if ($topic->count() > 2) {
|
||||||
'channel' => $topic->getId(),
|
$topic->remove($connection);
|
||||||
'user' => $userName,
|
} else {
|
||||||
'userCnt' => $topic->count()
|
$topic->broadcast([
|
||||||
]);
|
'userTopicId' => $connection->resourceId,
|
||||||
|
'channel' => $topic->getId(),
|
||||||
|
'user' => $userName,
|
||||||
|
'userCnt' => $topic->count()
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user