handle auth early
This commit is contained in:
parent
c4be86b59f
commit
e566bbc7e9
@ -11,9 +11,6 @@
|
||||
|
||||
* Global rolls
|
||||
|
||||
* Stats
|
||||
* Scrabble grid
|
||||
|
||||
* skills
|
||||
* handle setting account better maybe?
|
||||
* ensure cryp untargetable and doesn't resolve when KO
|
||||
@ -22,8 +19,6 @@
|
||||
* private fields for opponents
|
||||
* attack
|
||||
* can you attack yourself?
|
||||
* fetch existing battles
|
||||
* check for game participation
|
||||
* write players row for every team+cryp added
|
||||
* return results<>
|
||||
* defensive
|
||||
@ -40,25 +35,6 @@
|
||||
|
||||
* Bosses
|
||||
|
||||
|
||||
* rez ✔
|
||||
* move rpc functions out ✔
|
||||
* cooldowns reduce each turn ✔
|
||||
* statuses reduce each turn ✔
|
||||
* teach cyps skills ✔
|
||||
* spell/phys dmg ✔
|
||||
* offensive -> choose target ✔
|
||||
* ws reconnect ✔
|
||||
* Levelling ✔
|
||||
* Logins ✔️
|
||||
* Cryp Ownership ✔
|
||||
* Matchmaking ✔
|
||||
* Lobbies ✔
|
||||
* Create ✔
|
||||
* Join ✔
|
||||
* Resolve ✔
|
||||
|
||||
|
||||
# Db maintenance
|
||||
* delete games when a cryp is deleted
|
||||
* does this need to happen? can have historical games
|
||||
|
||||
@ -33,26 +33,38 @@ impl Rpc {
|
||||
None => None,
|
||||
};
|
||||
|
||||
println!("{:?}", account);
|
||||
// check the method
|
||||
// if no auth required
|
||||
match v.method.as_ref() {
|
||||
"account_create" => (),
|
||||
"account_login" => (),
|
||||
_ => match account {
|
||||
Some(_) => (),
|
||||
None => return Err(err_msg("auth required")),
|
||||
},
|
||||
};
|
||||
|
||||
// now we have the method name
|
||||
// match on that to determine what fn to call
|
||||
let response = match v.method.as_ref() {
|
||||
"cryp_spawn" => Rpc::cryp_spawn(data, &mut tx, account, client),
|
||||
"cryp_learn" => Rpc::cryp_learn(data, &mut tx, account, client),
|
||||
"cryp_forget" => Rpc::cryp_forget(data, &mut tx, account, client),
|
||||
"game_state" => Rpc::game_state(data, &mut tx, account, client),
|
||||
"game_pve" => Rpc::game_pve(data, &mut tx, account, client),
|
||||
"game_pvp" => Rpc::game_pvp(data, &mut tx, account, client),
|
||||
"game_join" => Rpc::game_join(data, &mut tx, account, client),
|
||||
"game_joinable_list" => Rpc::game_joinable_list(data, &mut tx, account, client),
|
||||
"game_skill" => Rpc::game_skill(data, &mut tx, account, client),
|
||||
"game_target" => Rpc::game_target(data, &mut tx, account, client),
|
||||
"account_create" => Rpc::account_create(data, &mut tx, account, client),
|
||||
"account_login" => Rpc::account_login(data, &mut tx, account, client),
|
||||
"account_cryps" => Rpc::account_cryps(data, &mut tx, account, client),
|
||||
"item_list" => Rpc::item_list(data, &mut tx, account, client),
|
||||
"item_use" => Rpc::item_use(data, &mut tx, account, client),
|
||||
// no auth methods
|
||||
"account_create" => Rpc::account_create(data, &mut tx, client),
|
||||
"account_login" => Rpc::account_login(data, &mut tx, client),
|
||||
|
||||
// auth methods
|
||||
"cryp_spawn" => Rpc::cryp_spawn(data, &mut tx, account.unwrap(), client),
|
||||
"cryp_learn" => Rpc::cryp_learn(data, &mut tx, account.unwrap(), client),
|
||||
"cryp_forget" => Rpc::cryp_forget(data, &mut tx, account.unwrap(), client),
|
||||
"game_state" => Rpc::game_state(data, &mut tx, account.unwrap(), client),
|
||||
"game_pve" => Rpc::game_pve(data, &mut tx, account.unwrap(), client),
|
||||
"game_pvp" => Rpc::game_pvp(data, &mut tx, account.unwrap(), client),
|
||||
"game_join" => Rpc::game_join(data, &mut tx, account.unwrap(), client),
|
||||
"game_joinable_list" => Rpc::game_joinable_list(data, &mut tx, account.unwrap(), client),
|
||||
"game_skill" => Rpc::game_skill(data, &mut tx, account.unwrap(), client),
|
||||
"game_target" => Rpc::game_target(data, &mut tx, account.unwrap(), client),
|
||||
"account_cryps" => Rpc::account_cryps(data, &mut tx, account.unwrap(), client),
|
||||
"item_list" => Rpc::item_list(data, &mut tx, account.unwrap(), client),
|
||||
"item_use" => Rpc::item_use(data, &mut tx, account.unwrap(), client),
|
||||
|
||||
_ => Err(err_msg("unknown method")),
|
||||
};
|
||||
@ -73,88 +85,63 @@ impl Rpc {
|
||||
}
|
||||
}
|
||||
|
||||
fn game_state(data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let a = match account {
|
||||
Some(a) => a,
|
||||
None => return Err(err_msg("auth required")),
|
||||
};
|
||||
|
||||
fn game_state(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<GameStateMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
let game_response = RpcResponse {
|
||||
method: "game_state".to_string(),
|
||||
params: RpcResult::GameState(game_state(msg.params, tx, &a)?)
|
||||
params: RpcResult::GameState(game_state(msg.params, tx, &account)?)
|
||||
};
|
||||
|
||||
return Ok(game_response);
|
||||
}
|
||||
|
||||
|
||||
fn game_pve(data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let a = match account {
|
||||
Some(a) => a,
|
||||
None => return Err(err_msg("auth required")),
|
||||
};
|
||||
|
||||
fn game_pve(data: Vec<u8>, tx: &mut Transaction, account: Account, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<GamePveMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
let game_response = RpcResponse {
|
||||
method: "game_state".to_string(),
|
||||
params: RpcResult::GameState(game_pve(msg.params, tx, &a)?)
|
||||
params: RpcResult::GameState(game_pve(msg.params, tx, &account)?)
|
||||
};
|
||||
|
||||
Rpc::send_msg(client, RpcResponse {
|
||||
method: "account_cryps".to_string(),
|
||||
params: RpcResult::CrypList(account_cryps(tx, &a)?)
|
||||
params: RpcResult::CrypList(account_cryps(tx, &account)?)
|
||||
})?;
|
||||
|
||||
return Ok(game_response);
|
||||
}
|
||||
|
||||
fn game_pvp(data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let a = match account {
|
||||
Some(a) => a,
|
||||
None => return Err(err_msg("auth required")),
|
||||
};
|
||||
|
||||
fn game_pvp(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<GamePvpMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
let game_response = RpcResponse {
|
||||
method: "game_state".to_string(),
|
||||
params: RpcResult::GameState(game_pvp(msg.params, tx, &a)?)
|
||||
params: RpcResult::GameState(game_pvp(msg.params, tx, &account)?)
|
||||
};
|
||||
|
||||
return Ok(game_response);
|
||||
}
|
||||
|
||||
|
||||
fn game_join(data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let a = match account {
|
||||
Some(a) => a,
|
||||
None => return Err(err_msg("auth required")),
|
||||
};
|
||||
|
||||
fn game_join(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<GameJoinMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
let game_response = RpcResponse {
|
||||
method: "game_state".to_string(),
|
||||
params: RpcResult::GameState(game_join(msg.params, tx, &a)?)
|
||||
params: RpcResult::GameState(game_join(msg.params, tx, &account)?)
|
||||
};
|
||||
|
||||
return Ok(game_response);
|
||||
}
|
||||
|
||||
fn game_joinable_list(_data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let a = match account {
|
||||
Some(a) => a,
|
||||
None => return Err(err_msg("auth required")),
|
||||
};
|
||||
|
||||
fn game_joinable_list(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
// let msg = from_slice::<GameJoinMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
let game_list = RpcResponse {
|
||||
method: "game_joinable_list".to_string(),
|
||||
params: RpcResult::GameJoinableList(game_joinable_list(tx, &a)?)
|
||||
params: RpcResult::GameJoinableList(game_joinable_list(tx, &account)?)
|
||||
};
|
||||
|
||||
return Ok(game_list);
|
||||
@ -162,114 +149,89 @@ impl Rpc {
|
||||
|
||||
|
||||
|
||||
fn game_skill(data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let a = match account {
|
||||
Some(a) => a,
|
||||
None => return Err(err_msg("auth required")),
|
||||
};
|
||||
|
||||
fn game_skill(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<GameSkillMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
let game_response = RpcResponse {
|
||||
method: "game_state".to_string(),
|
||||
params: RpcResult::GameState(game_skill(msg.params, tx, &a)?)
|
||||
params: RpcResult::GameState(game_skill(msg.params, tx, &account)?)
|
||||
};
|
||||
|
||||
// Rpc::send_msg(client, RpcResponse {
|
||||
// method: "account_cryps".to_string(),
|
||||
// params: RpcResult::CrypList(account_cryps(tx, &a)?)
|
||||
// params: RpcResult::CrypList(account_cryps(tx, &account)?)
|
||||
// })?;
|
||||
|
||||
return Ok(game_response);
|
||||
}
|
||||
|
||||
fn game_target(data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let a = match account {
|
||||
Some(a) => a,
|
||||
None => return Err(err_msg("auth required")),
|
||||
};
|
||||
|
||||
fn game_target(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<GameTargetMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
let game_response = RpcResponse {
|
||||
method: "game_state".to_string(),
|
||||
params: RpcResult::GameState(game_target(msg.params, tx, &a)?)
|
||||
params: RpcResult::GameState(game_target(msg.params, tx, &account)?)
|
||||
};
|
||||
|
||||
// Rpc::send_msg(client, RpcResponse {
|
||||
// method: "account_cryps".to_string(),
|
||||
// params: RpcResult::CrypList(account_cryps(tx, &a)?)
|
||||
// params: RpcResult::CrypList(account_cryps(tx, &account)?)
|
||||
// })?;
|
||||
|
||||
return Ok(game_response);
|
||||
}
|
||||
|
||||
|
||||
fn cryp_spawn(data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let a = match account {
|
||||
Some(a) => a,
|
||||
None => return Err(err_msg("auth required")),
|
||||
};
|
||||
|
||||
fn cryp_spawn(data: Vec<u8>, tx: &mut Transaction, account: Account, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<CrypSpawnMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
Rpc::send_msg(client, RpcResponse {
|
||||
method: "cryp_spawn".to_string(),
|
||||
params: RpcResult::CrypSpawn(cryp_spawn(msg.params, tx, &a)?)
|
||||
params: RpcResult::CrypSpawn(cryp_spawn(msg.params, tx, &account)?)
|
||||
})?;
|
||||
|
||||
let cryp_list = RpcResponse {
|
||||
method: "account_cryps".to_string(),
|
||||
params: RpcResult::CrypList(account_cryps(tx, &a)?)
|
||||
params: RpcResult::CrypList(account_cryps(tx, &account)?)
|
||||
};
|
||||
|
||||
Ok(cryp_list)
|
||||
}
|
||||
|
||||
fn cryp_learn(data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let a = match account {
|
||||
Some(a) => a,
|
||||
None => return Err(err_msg("auth required")),
|
||||
};
|
||||
|
||||
fn cryp_learn(data: Vec<u8>, tx: &mut Transaction, account: Account, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<CrypLearnMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
Rpc::send_msg(client, RpcResponse {
|
||||
method: "cryp_learn".to_string(),
|
||||
params: RpcResult::CrypLearn(cryp_learn(msg.params, tx, &a)?)
|
||||
params: RpcResult::CrypLearn(cryp_learn(msg.params, tx, &account)?)
|
||||
})?;
|
||||
|
||||
let cryp_list = RpcResponse {
|
||||
method: "account_cryps".to_string(),
|
||||
params: RpcResult::CrypList(account_cryps(tx, &a)?)
|
||||
params: RpcResult::CrypList(account_cryps(tx, &account)?)
|
||||
};
|
||||
|
||||
Ok(cryp_list)
|
||||
}
|
||||
|
||||
fn cryp_forget(data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let a = match account {
|
||||
Some(a) => a,
|
||||
None => return Err(err_msg("auth required")),
|
||||
};
|
||||
|
||||
fn cryp_forget(data: Vec<u8>, tx: &mut Transaction, account: Account, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<CrypForgetMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
Rpc::send_msg(client, RpcResponse {
|
||||
method: "cryp_forget".to_string(),
|
||||
params: RpcResult::CrypForget(cryp_forget(msg.params, tx, &a)?)
|
||||
params: RpcResult::CrypForget(cryp_forget(msg.params, tx, &account)?)
|
||||
})?;
|
||||
|
||||
let cryp_list = RpcResponse {
|
||||
method: "account_cryps".to_string(),
|
||||
params: RpcResult::CrypList(account_cryps(tx, &a)?)
|
||||
params: RpcResult::CrypList(account_cryps(tx, &account)?)
|
||||
};
|
||||
|
||||
Ok(cryp_list)
|
||||
}
|
||||
|
||||
|
||||
fn account_create(data: Vec<u8>, tx: &mut Transaction, _account: Option<Account>, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
fn account_create(data: Vec<u8>, tx: &mut Transaction, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
match from_slice::<AccountCreateMsg>(&data) {
|
||||
Ok(v) => Ok(RpcResponse {
|
||||
method: v.method,
|
||||
@ -279,7 +241,7 @@ impl Rpc {
|
||||
}
|
||||
}
|
||||
|
||||
fn account_login(data: Vec<u8>, tx: &mut Transaction, _account: Option<Account>, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
fn account_login(data: Vec<u8>, tx: &mut Transaction, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
match from_slice::<AccountLoginMsg>(&data) {
|
||||
Ok(v) => Ok(RpcResponse {
|
||||
method: v.method,
|
||||
@ -289,39 +251,28 @@ impl Rpc {
|
||||
}
|
||||
}
|
||||
|
||||
fn account_cryps(_data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
match account {
|
||||
Some(a) => Ok(RpcResponse {
|
||||
method: "account_cryps".to_string(),
|
||||
params: RpcResult::CrypList(account_cryps(tx, &a)?)
|
||||
}),
|
||||
None => Err(err_msg("auth required")),
|
||||
}
|
||||
fn account_cryps(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
Ok(RpcResponse {
|
||||
method: "account_cryps".to_string(),
|
||||
params: RpcResult::CrypList(account_cryps(tx, &account)?)
|
||||
})
|
||||
}
|
||||
|
||||
fn item_list(_data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
match account {
|
||||
Some(a) => Ok(RpcResponse {
|
||||
method: "item_list".to_string(),
|
||||
params: RpcResult::ItemList(items_list(tx, &a)?)
|
||||
}),
|
||||
None => Err(err_msg("auth required")),
|
||||
}
|
||||
fn item_list(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
Ok(RpcResponse {
|
||||
method: "item_list".to_string(),
|
||||
params: RpcResult::ItemList(items_list(tx, &account)?)
|
||||
})
|
||||
}
|
||||
|
||||
fn item_use(data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let a = match account {
|
||||
Some(a) => a,
|
||||
None => return Err(err_msg("auth required")),
|
||||
};
|
||||
|
||||
fn item_use(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<ItemUseMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
item_use(msg.params, tx, &a)?;
|
||||
item_use(msg.params, tx, &account)?;
|
||||
|
||||
let cryps_list = RpcResponse {
|
||||
method: "account_cryps".to_string(),
|
||||
params: RpcResult::CrypList(account_cryps(tx, &a)?)
|
||||
params: RpcResult::CrypList(account_cryps(tx, &account)?)
|
||||
};
|
||||
|
||||
return Ok(cryps_list);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user