@@ -46,7 +46,7 @@ async fn init_attack(
4646 is_self : web:: Query < HashMap < String , bool > > ,
4747) -> Result < impl Responder > {
4848 let attacker_id = user. 0 ;
49-
49+ let is_self_attack = * is_self . get ( "is_self" ) . unwrap_or ( & false ) ;
5050 log:: info!( "Attacker:{} is trying to initiate an attack" , attacker_id) ;
5151 let mut conn = pool. get ( ) . map_err ( |err| error:: handle_error ( err. into ( ) ) ) ?;
5252 if let Ok ( check) = util:: can_attack_happen ( & mut conn, attacker_id, true ) {
@@ -73,7 +73,7 @@ async fn init_attack(
7373 . map_err ( |err| error:: handle_error ( err. into ( ) ) ) ?;
7474
7575 let opponent_id: i32 ;
76- if * is_self . get ( "is_self" ) . unwrap_or ( & false ) {
76+ if is_self_attack {
7777 opponent_id = attacker_id;
7878 } else {
7979 let random_opponent_id = web:: block ( move || {
@@ -142,10 +142,10 @@ async fn init_attack(
142142
143143 log:: info!( "User details fetched for Opponent:{}" , opponent_id) ;
144144
145- //Create game
145+ //Create a new game
146146 let mut conn = pool. get ( ) . map_err ( |err| error:: handle_error ( err. into ( ) ) ) ?;
147147 let game_id = web:: block ( move || {
148- Ok ( util:: add_game ( attacker_id, opponent_id, map_id, & mut conn) ?) as anyhow:: Result < i32 >
148+ Ok ( util:: add_game ( attacker_id, opponent_id, map_id, & mut conn, is_self_attack ) ?) as anyhow:: Result < i32 >
149149 } )
150150 . await ?
151151 . map_err ( |err| error:: handle_error ( err. into ( ) ) ) ?;
@@ -244,7 +244,7 @@ async fn socket_handler(
244244 } else {
245245 if attacker_id != defender_id {
246246 log:: info!( "Attacker:{} is trying to attack someone else" , attacker_id) ;
247- return Err ( ErrorBadRequest ( "Can't attack yourself " ) ) ;
247+ return Err ( ErrorBadRequest ( "Can't attack someone else " ) ) ;
248248 }
249249 }
250250
0 commit comments