instance lists
This commit is contained in:
parent
eb2089cc17
commit
2f4944db10
@ -17,6 +17,7 @@ const COLOURS = [
|
|||||||
|
|
||||||
function Menu(args) {
|
function Menu(args) {
|
||||||
const {
|
const {
|
||||||
|
account,
|
||||||
cryps,
|
cryps,
|
||||||
selectedCryps,
|
selectedCryps,
|
||||||
setSelectedCryps,
|
setSelectedCryps,
|
||||||
@ -31,14 +32,12 @@ function Menu(args) {
|
|||||||
if (!instances) return <div>...</div>;
|
if (!instances) return <div>...</div>;
|
||||||
|
|
||||||
const instancePanels = instances.map(instance => {
|
const instancePanels = instances.map(instance => {
|
||||||
const globalInstance = instance.instance === NULL_UUID;
|
const player = instance.players.find(p => p.account === account.id);
|
||||||
const name = globalInstance
|
const name = `${instance.name} | ${player.score.wins} : ${player.score.losses}`;
|
||||||
? 'Global Matchmaking'
|
|
||||||
: `${instance.instance.substring(0, 5)} | ${instance.score.wins} : ${instance.score.losses}`;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
className={`menu-instance-btn right ${globalInstance ? 'full' : ''}`}
|
className={'menu-instance-btn right'}
|
||||||
key={instance.id}
|
key={instance.id}
|
||||||
onClick={() => sendInstanceState(instance)}>
|
onClick={() => sendInstanceState(instance)}>
|
||||||
{name}
|
{name}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ const actions = require('./../actions');
|
|||||||
|
|
||||||
const addState = connect(
|
const addState = connect(
|
||||||
function receiveState(state) {
|
function receiveState(state) {
|
||||||
const { ws, cryps, selectedCryps, instances } = state;
|
const { ws, cryps, selectedCryps, instances, account } = state;
|
||||||
|
|
||||||
function sendInstanceJoin() {
|
function sendInstanceJoin() {
|
||||||
if (selectedCryps.length) {
|
if (selectedCryps.length) {
|
||||||
@ -26,10 +26,11 @@ const addState = connect(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sendInstanceState(instance) {
|
function sendInstanceState(instance) {
|
||||||
return ws.sendInstanceState(instance.instance);
|
return ws.sendInstanceState(instance.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
account,
|
||||||
cryps,
|
cryps,
|
||||||
selectedCryps,
|
selectedCryps,
|
||||||
sendInstanceJoin,
|
sendInstanceJoin,
|
||||||
|
|||||||
@ -50,8 +50,8 @@ function createSocket(events) {
|
|||||||
send({ method: 'account_cryps', params: {} });
|
send({ method: 'account_cryps', params: {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendAccountPlayers() {
|
function sendAccountInstances() {
|
||||||
send({ method: 'account_players', params: {} });
|
send({ method: 'account_instances', params: {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendAccountZone() {
|
function sendAccountZone() {
|
||||||
@ -171,10 +171,10 @@ function createSocket(events) {
|
|||||||
localStorage.setItem('account', JSON.stringify(login));
|
localStorage.setItem('account', JSON.stringify(login));
|
||||||
events.setAccount(login);
|
events.setAccount(login);
|
||||||
sendAccountCryps();
|
sendAccountCryps();
|
||||||
sendAccountPlayers();
|
sendAccountInstances();
|
||||||
}
|
}
|
||||||
|
|
||||||
function accountPlayerList(res) {
|
function accountInstanceList(res) {
|
||||||
const [struct, playerList] = res;
|
const [struct, playerList] = res;
|
||||||
events.setInstanceList(playerList);
|
events.setInstanceList(playerList);
|
||||||
}
|
}
|
||||||
@ -229,7 +229,7 @@ function createSocket(events) {
|
|||||||
account_login: accountLogin,
|
account_login: accountLogin,
|
||||||
account_create: accountLogin,
|
account_create: accountLogin,
|
||||||
account_cryps: accountCryps,
|
account_cryps: accountCryps,
|
||||||
account_players: accountPlayerList,
|
account_instances: accountInstanceList,
|
||||||
instance_scores: instanceScores,
|
instance_scores: instanceScores,
|
||||||
zone_create: res => console.log(res),
|
zone_create: res => console.log(res),
|
||||||
zone_state: zoneState,
|
zone_state: zoneState,
|
||||||
@ -285,7 +285,7 @@ function createSocket(events) {
|
|||||||
|
|
||||||
if (account) {
|
if (account) {
|
||||||
events.setAccount(account);
|
events.setAccount(account);
|
||||||
sendAccountPlayers();
|
sendAccountInstances();
|
||||||
sendAccountCryps();
|
sendAccountCryps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,7 +319,7 @@ function createSocket(events) {
|
|||||||
sendAccountCreate,
|
sendAccountCreate,
|
||||||
sendAccountDemo,
|
sendAccountDemo,
|
||||||
sendAccountCryps,
|
sendAccountCryps,
|
||||||
sendAccountPlayers,
|
sendAccountInstances,
|
||||||
sendAccountZone,
|
sendAccountZone,
|
||||||
sendGameState,
|
sendGameState,
|
||||||
sendGameJoin,
|
sendGameJoin,
|
||||||
|
|||||||
@ -27,7 +27,7 @@ class Home extends Phaser.Scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
create() {
|
create() {
|
||||||
this.registry.get('ws').sendAccountPlayers();
|
this.registry.get('ws').sendAccountInstances();
|
||||||
|
|
||||||
this.registry.events.on('changedata', this.updateData, this);
|
this.registry.events.on('changedata', this.updateData, this);
|
||||||
this.registry.events.on('setdata', this.updateData, this);
|
this.registry.events.on('setdata', this.updateData, this);
|
||||||
|
|||||||
@ -45,8 +45,8 @@ function createSocket(events) {
|
|||||||
send({ method: 'account_cryps', params: {} });
|
send({ method: 'account_cryps', params: {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendAccountPlayers() {
|
function sendAccountInstances() {
|
||||||
send({ method: 'account_players', params: {} });
|
send({ method: 'account_instances', params: {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendAccountZone() {
|
function sendAccountZone() {
|
||||||
@ -168,9 +168,9 @@ function createSocket(events) {
|
|||||||
sendAccountCryps();
|
sendAccountCryps();
|
||||||
}
|
}
|
||||||
|
|
||||||
function accountPlayerList(res) {
|
function accountInstanceList(res) {
|
||||||
const [struct, playerList] = res;
|
const [struct, instanceList] = res;
|
||||||
events.setPlayerList(playerList);
|
events.setInstanceList(instanceList);
|
||||||
}
|
}
|
||||||
|
|
||||||
function accountCryps(response) {
|
function accountCryps(response) {
|
||||||
@ -221,7 +221,7 @@ function createSocket(events) {
|
|||||||
account_login: accountLogin,
|
account_login: accountLogin,
|
||||||
account_create: accountLogin,
|
account_create: accountLogin,
|
||||||
account_cryps: accountCryps,
|
account_cryps: accountCryps,
|
||||||
account_players: accountPlayerList,
|
account_instances: accountInstanceList,
|
||||||
instance_scores: instanceScores,
|
instance_scores: instanceScores,
|
||||||
zone_create: res => console.log(res),
|
zone_create: res => console.log(res),
|
||||||
zone_state: zoneState,
|
zone_state: zoneState,
|
||||||
@ -302,7 +302,7 @@ function createSocket(events) {
|
|||||||
sendAccountCreate,
|
sendAccountCreate,
|
||||||
sendAccountDemo,
|
sendAccountDemo,
|
||||||
sendAccountCryps,
|
sendAccountCryps,
|
||||||
sendAccountPlayers,
|
sendAccountInstances,
|
||||||
sendAccountZone,
|
sendAccountZone,
|
||||||
sendGameState,
|
sendGameState,
|
||||||
sendGamePve,
|
sendGamePve,
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use postgres::transaction::Transaction;
|
|||||||
use rpc::{AccountCreateParams, AccountLoginParams};
|
use rpc::{AccountCreateParams, AccountLoginParams};
|
||||||
|
|
||||||
use cryp::{Cryp, cryp_recover};
|
use cryp::{Cryp, cryp_recover};
|
||||||
use player::{Player, player_delete};
|
use instance::{Instance, instance_delete};
|
||||||
|
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
@ -177,11 +177,16 @@ pub fn account_cryps(tx: &mut Transaction, account: &Account) -> Result<Vec<Cryp
|
|||||||
return Ok(cryps);
|
return Ok(cryps);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn account_players(tx: &mut Transaction, account: &Account) -> Result<Vec<Player>, Error> {
|
pub fn account_instances(tx: &mut Transaction, account: &Account) -> Result<Vec<Instance>, Error> {
|
||||||
let query = "
|
let query = "
|
||||||
SELECT data, id
|
SELECT data, id
|
||||||
FROM players
|
FROM instances
|
||||||
WHERE account = $1;
|
WHERE open = true
|
||||||
|
OR id IN (
|
||||||
|
SELECT instance
|
||||||
|
FROM players
|
||||||
|
WHERE account = $1
|
||||||
|
);
|
||||||
";
|
";
|
||||||
|
|
||||||
let result = tx
|
let result = tx
|
||||||
@ -193,15 +198,15 @@ pub fn account_players(tx: &mut Transaction, account: &Account) -> Result<Vec<Pl
|
|||||||
let bytes: Vec<u8> = row.get(0);
|
let bytes: Vec<u8> = row.get(0);
|
||||||
let id = row.get(1);
|
let id = row.get(1);
|
||||||
|
|
||||||
match from_slice::<Player>(&bytes) {
|
match from_slice::<Instance>(&bytes) {
|
||||||
Ok(i) => list.push(i),
|
Ok(i) => list.push(i),
|
||||||
Err(_e) => {
|
Err(_e) => {
|
||||||
player_delete(tx, id)?;
|
instance_delete(tx, id)?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
list.sort_by_key(|c| c.instance);
|
list.sort_unstable_by_key(|c| c.name.clone());
|
||||||
|
|
||||||
return Ok(list);
|
return Ok(list);
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ pub struct Instance {
|
|||||||
open: bool,
|
open: bool,
|
||||||
max_players: usize,
|
max_players: usize,
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Instance {
|
impl Instance {
|
||||||
@ -141,7 +141,7 @@ impl Instance {
|
|||||||
self.start();
|
self.start();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
InstancePhase::Vbox =>
|
InstancePhase::Vbox => {
|
||||||
if self.all_ready() {
|
if self.all_ready() {
|
||||||
self.games_phase_start();
|
self.games_phase_start();
|
||||||
}
|
}
|
||||||
@ -306,7 +306,10 @@ impl Instance {
|
|||||||
game = game.start();
|
game = game.start();
|
||||||
|
|
||||||
assert!(game.finished());
|
assert!(game.finished());
|
||||||
let winner = game.winner().unwrap();
|
let winner = match game.winner() {
|
||||||
|
Some(w) => w,
|
||||||
|
None => panic!("game has no winner {:?}", game),
|
||||||
|
};
|
||||||
|
|
||||||
round.finished = true;
|
round.finished = true;
|
||||||
|
|
||||||
@ -479,6 +482,25 @@ pub fn instance_get(tx: &mut Transaction, instance_id: Uuid) -> Result<Instance,
|
|||||||
return Ok(instance);
|
return Ok(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn instance_delete(tx: &mut Transaction, id: Uuid) -> Result<(), Error> {
|
||||||
|
let query = "
|
||||||
|
DELETE
|
||||||
|
FROM instances
|
||||||
|
WHERE id = $1;
|
||||||
|
";
|
||||||
|
|
||||||
|
let result = tx
|
||||||
|
.execute(query, &[&id])?;
|
||||||
|
|
||||||
|
if result != 1 {
|
||||||
|
return Err(format_err!("unable to delete instance {:?}", id));
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("instance deleted {:?}", id);
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
pub fn instance_get_open(tx: &mut Transaction) -> Result<Instance, Error> {
|
pub fn instance_get_open(tx: &mut Transaction) -> Result<Instance, Error> {
|
||||||
let query = "
|
let query = "
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -511,7 +533,6 @@ pub fn instance_lobby(params: InstanceLobbyParams, tx: &mut Transaction, account
|
|||||||
instance_join(join_params, tx, account)
|
instance_join(join_params, tx, account)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn instance_join(params: InstanceJoinParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> {
|
pub fn instance_join(params: InstanceJoinParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> {
|
||||||
let mut instance = instance_get(tx, params.instance_id)?;
|
let mut instance = instance_get(tx, params.instance_id)?;
|
||||||
|
|
||||||
@ -557,9 +578,9 @@ pub fn instance_scores(params: InstanceReadyParams, tx: &mut Transaction, _accou
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> {
|
pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> {
|
||||||
let player = player_get(tx, account.id, params.instance_id)?;
|
|
||||||
let mut instance = instance_get(tx, params.instance_id)?;
|
let mut instance = instance_get(tx, params.instance_id)?;
|
||||||
instance.player_ready(player.id)?;
|
let player_id = instance.account_player(account.id)?.id;
|
||||||
|
instance.player_ready(player_id)?;
|
||||||
|
|
||||||
instance_update(tx, instance)
|
instance_update(tx, instance)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ use failure::err_msg;
|
|||||||
use net::Db;
|
use net::Db;
|
||||||
use cryp::{Cryp, cryp_spawn};
|
use cryp::{Cryp, cryp_spawn};
|
||||||
use game::{Game, game_state, game_skill};
|
use game::{Game, game_state, game_skill};
|
||||||
use account::{Account, account_create, account_login, account_from_token, account_cryps, account_players};
|
use account::{Account, account_create, account_login, account_from_token, account_cryps, account_instances};
|
||||||
use skill::{Skill};
|
use skill::{Skill};
|
||||||
// use zone::{Zone, zone_create, zone_join, zone_close};
|
// use zone::{Zone, zone_create, zone_join, zone_close};
|
||||||
use spec::{Spec};
|
use spec::{Spec};
|
||||||
@ -64,7 +64,7 @@ impl Rpc {
|
|||||||
|
|
||||||
// auth methods
|
// auth methods
|
||||||
"account_cryps" => Rpc::account_cryps(data, &mut tx, account.unwrap(), client),
|
"account_cryps" => Rpc::account_cryps(data, &mut tx, account.unwrap(), client),
|
||||||
"account_players" => Rpc::account_players(data, &mut tx, account.unwrap(), client),
|
"account_instances" => Rpc::account_instances(data, &mut tx, account.unwrap(), client),
|
||||||
// "account_zone" => Rpc::account_zone(data, &mut tx, account.unwrap(), client),
|
// "account_zone" => Rpc::account_zone(data, &mut tx, account.unwrap(), client),
|
||||||
|
|
||||||
"cryp_spawn" => Rpc::cryp_spawn(data, &mut tx, account.unwrap(), client),
|
"cryp_spawn" => Rpc::cryp_spawn(data, &mut tx, account.unwrap(), client),
|
||||||
@ -210,10 +210,10 @@ impl Rpc {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn account_players(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
fn account_instances(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||||
Ok(RpcResponse {
|
Ok(RpcResponse {
|
||||||
method: "account_players".to_string(),
|
method: "account_instances".to_string(),
|
||||||
params: RpcResult::PlayerList(account_players(tx, &account)?)
|
params: RpcResult::InstanceList(account_instances(tx, &account)?)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,7 +391,7 @@ pub enum RpcResult {
|
|||||||
// ZoneState(Zone),
|
// ZoneState(Zone),
|
||||||
// ZoneClose(()),
|
// ZoneClose(()),
|
||||||
|
|
||||||
PlayerList(Vec<Player>),
|
InstanceList(Vec<Instance>),
|
||||||
InstanceState(Instance),
|
InstanceState(Instance),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user