remove instance list
This commit is contained in:
+34
-1
@@ -301,7 +301,8 @@ pub fn account_team(tx: &mut Transaction, account: &Account) -> Result<Vec<Const
|
||||
SELECT data
|
||||
FROM constructs
|
||||
WHERE account = $1
|
||||
AND team = true;
|
||||
AND team = true
|
||||
LIMIT 3;
|
||||
";
|
||||
|
||||
let result = tx
|
||||
@@ -328,6 +329,38 @@ pub fn account_team(tx: &mut Transaction, account: &Account) -> Result<Vec<Const
|
||||
return Ok(constructs);
|
||||
}
|
||||
|
||||
pub fn account_set_team(tx: &mut Transaction, account: &Account, ids: Vec<Uuid>) -> Result<Vec<Construct>, Error> {
|
||||
let query = "
|
||||
UPDATE constructs
|
||||
SET team = false
|
||||
WHERE account = $1;
|
||||
";
|
||||
|
||||
let updated = tx
|
||||
.execute(query, &[&account.id, &ids])?;
|
||||
|
||||
if updated > 3 {
|
||||
warn!("team members >3 account={:?} count={:?}", account, updated);
|
||||
}
|
||||
|
||||
let query = "
|
||||
UPDATE constructs
|
||||
SET team = true
|
||||
WHERE account = $1
|
||||
AND id in $2
|
||||
RETURNING data;
|
||||
";
|
||||
|
||||
let updated = tx
|
||||
.execute(query, &[&account.id, &ids])?;
|
||||
|
||||
if updated != 3 {
|
||||
return Err(format_err!("could not create team of 3 account={:?} updated={:?}", account, updated));
|
||||
}
|
||||
|
||||
account_team(tx, account)
|
||||
}
|
||||
|
||||
pub fn account_instances(tx: &mut Transaction, account: &Account) -> Result<Vec<Instance>, Error> {
|
||||
let query = "
|
||||
SELECT data, id
|
||||
|
||||
+11
-7
@@ -498,7 +498,7 @@ pub fn instance_create(tx: &mut Transaction, instance: Instance) -> Result<Insta
|
||||
|
||||
let query = "
|
||||
INSERT INTO instances (id, data)
|
||||
VALUES ($1, $2, $3)
|
||||
VALUES ($1, $2)
|
||||
RETURNING id;
|
||||
";
|
||||
|
||||
@@ -575,11 +575,10 @@ pub fn instance_delete(tx: &mut Transaction, id: Uuid) -> Result<(), Error> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn instance_list(tx: &mut Transaction) -> Result<Vec<Instance>, Error> {
|
||||
pub fn _instance_list(tx: &mut Transaction) -> Result<Vec<Instance>, Error> {
|
||||
let query = "
|
||||
SELECT data, id
|
||||
FROM instances
|
||||
WHERE open = true
|
||||
AND finished = false;
|
||||
";
|
||||
|
||||
@@ -677,13 +676,16 @@ pub fn instance_practice(tx: &mut Transaction, account: &Account) -> Result<Inst
|
||||
.set_name(bot.name.clone())?;
|
||||
|
||||
let constructs = account::account_team(tx, account)?;
|
||||
let player = player_create(tx, Player::new(account.id, &account.name, constructs), instance.id, account)?;
|
||||
let player = Player::new(account.id, &account.name, constructs);
|
||||
|
||||
instance.add_player(player)?;
|
||||
instance.add_player(player.clone())?;
|
||||
instance.add_player(bot)?;
|
||||
instance.player_ready(bot_id)?;
|
||||
|
||||
instance_create(tx, instance)
|
||||
instance = instance_create(tx, instance)?;
|
||||
player_create(tx, player, instance.id, account)?;
|
||||
|
||||
Ok(instance)
|
||||
}
|
||||
|
||||
// pub fn instance_queue(tx: &mut Transaction, a: &Account, b: &Account) -> Result<Instance, Error> {
|
||||
@@ -694,13 +696,15 @@ pub fn instance_pvp(tx: &mut Transaction, a: &Account, b: &Account) -> Result<In
|
||||
// TODO generate nice game names
|
||||
.set_name("PVP".to_string())?;
|
||||
|
||||
instance = instance_create(tx, instance)?;
|
||||
|
||||
for account in [a, b].iter() {
|
||||
let constructs = account::account_team(tx, account)?;
|
||||
let player = player_create(tx, Player::new(account.id, &account.name, constructs), instance.id, account)?;
|
||||
instance.add_player(player)?;
|
||||
}
|
||||
|
||||
instance_create(tx, instance)
|
||||
instance_update(tx, instance)
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -1,7 +1,7 @@
|
||||
use rand::prelude::*;
|
||||
use rand::{thread_rng};
|
||||
|
||||
const FIRSTS: [&'static str; 36] = [
|
||||
const FIRSTS: [&'static str; 37] = [
|
||||
"artificial",
|
||||
"ambient",
|
||||
"borean",
|
||||
@@ -12,6 +12,7 @@ const FIRSTS: [&'static str; 36] = [
|
||||
"concave",
|
||||
"convex",
|
||||
"distorted",
|
||||
"deserted",
|
||||
"emotive",
|
||||
"emotionless",
|
||||
"fierce",
|
||||
|
||||
+2
-7
@@ -1,4 +1,4 @@
|
||||
use std::net::TcpStream;
|
||||
|
||||
use std::time::{Instant};
|
||||
|
||||
use serde_cbor::{from_slice};
|
||||
@@ -11,7 +11,7 @@ use construct::{Construct};
|
||||
use game::{Game, game_state, game_skill, game_ready};
|
||||
use account::{Account, account_constructs};
|
||||
use skill::{Skill, dev_resolve, Resolutions};
|
||||
use instance::{Instance, instance_state, instance_list, instance_practice, instance_ready, instance_pvp};
|
||||
use instance::{Instance, instance_state, instance_practice, instance_ready, instance_pvp};
|
||||
use vbox::{vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_reclaim, vbox_unequip};
|
||||
use item::{Item, ItemInfoCtr, item_info};
|
||||
|
||||
@@ -27,7 +27,6 @@ pub enum RpcMessage {
|
||||
GameState(Game),
|
||||
ItemInfo(ItemInfoCtr),
|
||||
|
||||
OpenInstances(Vec<Instance>),
|
||||
InstanceState(Instance),
|
||||
|
||||
Pong(()),
|
||||
@@ -56,8 +55,6 @@ enum RpcRequest {
|
||||
AccountShop {},
|
||||
AccountConstructs {},
|
||||
|
||||
InstanceList {},
|
||||
InstanceLobby { construct_ids: Vec<Uuid>, name: String, pve: bool, password: Option<String> },
|
||||
InstancePvp {},
|
||||
InstancePractice {},
|
||||
InstanceReady { instance_id: Uuid },
|
||||
@@ -119,8 +116,6 @@ pub fn receive(data: Vec<u8>, db: &Db, begin: Instant, account: &Option<Account>
|
||||
RpcRequest::GameReady { id } =>
|
||||
Ok(RpcMessage::GameState(game_ready(&mut tx, account, id)?)),
|
||||
|
||||
RpcRequest::InstanceList {} =>
|
||||
Ok(RpcMessage::OpenInstances(instance_list(&mut tx)?)),
|
||||
// RpcRequest::InstanceQueue {} =>
|
||||
// Ok(RpcMessage::QueueState(instance_queue(&mut tx, account)?)),
|
||||
RpcRequest::InstancePractice {} =>
|
||||
|
||||
Reference in New Issue
Block a user