diff --git a/src/api/attack/mod.rs b/src/api/attack/mod.rs index 8a4a9c0c..3bde322d 100644 --- a/src/api/attack/mod.rs +++ b/src/api/attack/mod.rs @@ -101,8 +101,6 @@ async fn init_attack( .await? .map_err(|err| error::handle_error(err.into()))?; - println!("obatain {}", obtainable_artifacts); - let mut conn = pool.get().map_err(|err| error::handle_error(err.into()))?; let user_details = @@ -117,7 +115,6 @@ async fn init_attack( }) .await? .map_err(|err| error::handle_error(err.into()))?; - println!("Added game: {}", game_id); //Generate attack token to validate the /attack/start let attack_token = util::encode_attack_token(attacker_id, opponent_id, game_id) @@ -150,7 +147,6 @@ async fn init_attack( game_id, }; - println!("Sent game id {} to frontend", game_id); Ok(Json(response)) } @@ -160,7 +156,6 @@ async fn socket_handler( req: HttpRequest, body: web::Payload, ) -> Result { - println!("error bug fs"); let query_params = req.query_string().split('&').collect::>(); let user_token = query_params[0].split('=').collect::>()[1]; let attack_token = query_params[1].split('=').collect::>()[1]; @@ -171,18 +166,14 @@ async fn socket_handler( util::decode_attack_token(attack_token).map_err(|err| error::handle_error(err.into()))?; let game_id = attack_token_data.game_id; - println!("Received game id {} from frontend", game_id); - let mut conn = pool.get().map_err(|err| error::handle_error(err.into()))?; if attacker_id != attack_token_data.attacker_id { - println!("Attacker:{} is not authorised", attacker_id); return Err(ErrorBadRequest("User not authorised")); } let defender_id = attack_token_data.defender_id; if attacker_id == defender_id { - println!("Attacker:{} can't attack yourself", attacker_id); return Err(ErrorBadRequest("Can't attack yourself")); } @@ -191,16 +182,13 @@ async fn socket_handler( .map_err(|err| error::handle_error(err.into()))?; if let Ok(Some(_)) = util::get_game_id_from_redis(attacker_id, &mut redis_conn, true) { - println!("Attacker:{} has an ongoing game", attacker_id); return Err(ErrorBadRequest("Attacker has an ongoing game")); } if let Ok(Some(_)) = util::get_game_id_from_redis(defender_id, &mut redis_conn, false) { - println!("Defender:{} has an ongoing game", defender_id); return Err(ErrorBadRequest("Defender has an ongoing game")); } - println!("Checking if there are incomplte games"); if util::check_and_remove_incomplete_game(&attacker_id, &defender_id, &game_id, &mut conn) .is_err() { @@ -223,7 +211,6 @@ async fn socket_handler( let map_id = if let Some(map) = map { map } else { - println!("Defender:{}'s base is invalid", defender_id); return Err(ErrorBadRequest("Invalid base")); }; @@ -385,7 +372,6 @@ async fn socket_handler( if let Ok(response_json) = serde_json::to_string(&response) { // println!("Response Json ---- {}", response_json); if response.result_type == ResultType::GameOver { - println!("Game over. Terminating the socket..."); if session_clone1.text(response_json).await.is_err() { return; } @@ -402,23 +388,19 @@ async fn socket_handler( println!("Error terminating the game 1"); } } else if response.result_type == ResultType::MinesExploded { - println!("MinesExploded response sent"); if session_clone1.text(response_json).await.is_err() { return; } } else if response.result_type == ResultType::DefendersDamaged { - println!("DefendersDamaged response sent"); if session_clone1.text(response_json).await.is_err() { return; } } else if response.result_type == ResultType::DefendersTriggered { - println!("DefendersTriggered response sent"); if session_clone1.text(response_json).await.is_err() { return; } } else if response.result_type == ResultType::BuildingsDamaged { - println!("BuildingsDamaged response sent"); if util::deduct_artifacts_from_building( response.damaged_buildings.unwrap(), &mut conn, @@ -431,15 +413,13 @@ async fn socket_handler( return; } } else if response.result_type == ResultType::PlacedAttacker { - println!("PlacedAttacker response sent"); - if session_clone1.text(response_json).await.is_err() { - return; - } - } else if response.result_type == ResultType::Nothing { - // println!("Nothing response sent"); if session_clone1.text(response_json).await.is_err() { return; } + } else if response.result_type == ResultType::Nothing + && session_clone1.text(response_json).await.is_err() + { + return; } } else { println!("Error serializing JSON"); @@ -459,14 +439,14 @@ async fn socket_handler( } } } else { - println!("Error parsing JSON"); + println!("Error serializing JSON"); + if session_clone1.text("Error parsing JSON").await.is_err() { return; } } } - Message::Close(s) => { - println!("Received close: {:?}", s); + Message::Close(_s) => { if util::terminate_game(game_logs, &mut conn, &mut redis_conn).is_err() { println!("Error terminating the game 2"); } @@ -481,7 +461,6 @@ async fn socket_handler( let timeout_duration = time::Duration::from_secs((GAME_AGE_IN_MINUTES as u64) * 60); let last_activity = time::Instant::now(); - println!("Started timer"); loop { actix_rt::time::sleep(time::Duration::from_secs(1)).await; @@ -504,8 +483,6 @@ async fn socket_handler( return; } - println!("Connection timed out"); - break; } } diff --git a/src/api/attack/util.rs b/src/api/attack/util.rs index 0e8454e1..4d7e7b5f 100644 --- a/src/api/attack/util.rs +++ b/src/api/attack/util.rs @@ -170,7 +170,6 @@ pub fn add_game( error: err, })?; - println!("Successfully inserted game to table: {}", inserted_game.id); Ok(inserted_game.id) } @@ -341,8 +340,6 @@ pub fn get_random_opponent_id( return Err(anyhow::anyhow!("Failed to find an opponent")); }; - println!("Random opponent: {}", random_opponent); - loop { if let Ok(Some(_)) = get_game_id_from_redis(random_opponent, &mut redis_conn, false) { random_opponent = @@ -360,14 +357,12 @@ pub fn get_random_opponent_id( return Err(anyhow::anyhow!("Failed to find another opponent")) } }; - println!("Random opponent (retry): {}", random_opponent); } else { return Ok(Some(random_opponent)); } } else { return Err(anyhow::anyhow!("Cannot check if attack can happen now")); } - println!("Random opponent: {}", random_opponent); attempts += 1; if attempts > 10 { @@ -434,7 +429,6 @@ pub fn add_game_id_to_redis( ) .map_err(|err| anyhow::anyhow!("Failed to set attacker key: {}", err))?; - println!("Attacker:{} redis creation done", attacker_id); redis_conn .set_ex( format!("Defender:{}", defender_id), @@ -442,7 +436,6 @@ pub fn add_game_id_to_redis( GAME_AGE_IN_MINUTES * 60, ) .map_err(|err| anyhow::anyhow!("Failed to set defender key: {}", err))?; - println!("Defender:{} redis creation done", defender_id); Ok(()) } @@ -470,15 +463,12 @@ pub fn delete_game_id_from_redis( defender_id: i32, redis_conn: &mut RedisConn, ) -> Result<()> { - println!("Deletion of game ids from redis in progress..."); redis_conn .del(format!("Attacker:{}", attacker_id)) .map_err(|err| anyhow::anyhow!("Failed to delete attacker key: {}", err))?; - println!("Attacker redis deletion done"); redis_conn .del(format!("Defender:{}", defender_id)) .map_err(|err| anyhow::anyhow!("Failed to delete defender key: {}", err))?; - println!("Defender redis deletion done"); Ok(()) } @@ -694,10 +684,6 @@ pub fn update_buidling_artifacts( // Update the buildings with the artifact count for building in buildings.iter_mut() { building.artifacts_obtained = *artifact_count.get(&building.id).unwrap_or(&0) as i32; - println!( - "during import : == Building id: {},hp: {}, Artifacts: {}", - building.id, building.total_hp, building.artifacts_obtained - ); } Ok(buildings) @@ -716,17 +702,12 @@ pub fn terminate_game( let artifacts_collected = game_log.r.a; let game_id = game_log.g; - println!("Damage done: {}", damage_done); - println!("Artifacts Collected: {}", artifacts_collected); - let (attack_score, defense_score) = if damage_done < WIN_THRESHOLD { (damage_done - 100, 100 - damage_done) } else { (damage_done, -damage_done) }; - println!("Attack score: 1"); - let attacker_details = user::table .filter(user::id.eq(attacker_id)) .first::(conn) @@ -735,7 +716,6 @@ pub fn terminate_game( function: function!(), error: err, })?; - println!("Attack score: 2"); let defender_details = user::table .filter(user::id.eq(defender_id)) @@ -746,8 +726,6 @@ pub fn terminate_game( error: err, })?; - println!("Attack score: 3"); - let attack_score = attack_score as f32 / 100_f32; let defence_score = defense_score as f32 / 100_f32; @@ -758,8 +736,6 @@ pub fn terminate_game( defence_score, ); - println!("Attack score: 4"); - //Add bonus trophies (just call the function) game_log.r.oa = attacker_details.trophies; @@ -767,9 +743,6 @@ pub fn terminate_game( game_log.r.na = new_trophies.0; game_log.r.nd = new_trophies.1; - println!("Attack score: 5"); - - println!("Going to update game table {}", game_id); diesel::update(game::table.find(game_id)) .set(( game::damage_done.eq(damage_done), @@ -786,9 +759,6 @@ pub fn terminate_game( error: err, })?; - println!("Done update game table {}", game_id); - println!("Attack score: 6"); - let (attacker_wins, defender_wins) = if damage_done < WIN_THRESHOLD { (0, 1) } else { @@ -862,8 +832,6 @@ pub fn terminate_game( // println!("Event: {:?}\n", event); // } - println!("Result: {:?}", game_log.r); - println!("Game termination is done"); Ok(()) } @@ -890,10 +858,9 @@ pub fn check_and_remove_incomplete_game( error: err, })?; - let len = pending_games.len(); + let _len = pending_games.len(); for pending_game in pending_games { - println!("removing game id {}", pending_game.id); diesel::delete(game.filter(id.eq(pending_game.id))) .execute(conn) .map_err(|err| DieselError { @@ -903,8 +870,6 @@ pub fn check_and_remove_incomplete_game( })?; } - println!("Removed {} incomplete games", len); - Ok(()) } diff --git a/src/api/defense/mod.rs b/src/api/defense/mod.rs index abd3d7bf..42e2fcb9 100644 --- a/src/api/defense/mod.rs +++ b/src/api/defense/mod.rs @@ -269,7 +269,6 @@ async fn set_base_details( user: AuthUser, ) -> Result { let defender_id = user.0; - println!("Defender ID: {}", defender_id); let map_spaces = map_spaces.into_inner(); let mut conn = pool.get().map_err(|err| error::handle_error(err.into()))?; let (map, blocks, buildings) = web::block(move || { diff --git a/src/api/defense/shortest_path.rs b/src/api/defense/shortest_path.rs index 7770c959..006ab54b 100644 --- a/src/api/defense/shortest_path.rs +++ b/src/api/defense/shortest_path.rs @@ -111,10 +111,5 @@ pub fn run_shortest_paths( // })?; // } - println!( - "shortest path ------------------------------------------------------------------- {:?}", - shortest_paths.len() - ); - Ok(shortest_paths) } diff --git a/src/api/defense/validate.rs b/src/api/defense/validate.rs index 6d959e39..b42e1c94 100644 --- a/src/api/defense/validate.rs +++ b/src/api/defense/validate.rs @@ -140,10 +140,6 @@ pub fn is_valid_save_layout( let building_type = block.building_type; if artifacts > buildings[&building_type].capacity { - println!("Artifacts: {}", artifacts); - println!("Capacity: {}", buildings[&building_type].capacity); - println!("Building name: {}", buildings[&building_type].name); - println!("Block id: {}", block_type_id); return Err(BaseInvalidError::InvalidArtifactCount); } @@ -175,8 +171,6 @@ pub fn is_valid_save_layout( } } - println!("Total Artifacts: {}", total_artifacts); - println!("User Artifacts: {}", user_artifacts); if total_artifacts != *user_artifacts { return Err(BaseInvalidError::InvalidArtifactCount); } diff --git a/src/api/game/mod.rs b/src/api/game/mod.rs index bdbf3758..319e553f 100644 --- a/src/api/game/mod.rs +++ b/src/api/game/mod.rs @@ -62,8 +62,6 @@ async fn get_game_details( let user_id = user.0; let game_id = game_id.into_inner(); - println!("Request for game_id stats: {}", game_id); - let response = web::block(move || { let mut conn = pool.get()?; util::fetch_game_details(game_id, user_id, &mut conn) @@ -71,6 +69,5 @@ async fn get_game_details( .await? .map_err(|err| error::handle_error(err.into()))?; - println!("{:#?}", response); Ok(web::Json(response)) } diff --git a/src/api/game/util.rs b/src/api/game/util.rs index 9d519cf8..ca7b1f10 100644 --- a/src/api/game/util.rs +++ b/src/api/game/util.rs @@ -133,8 +133,6 @@ pub fn fetch_replay(game_id: i32, conn: &mut PgConnection) -> Result Result { use crate::schema::game; - println!("Fetching game details for game_id: {}", game_id); - Ok(game::table .filter(game::id.eq(game_id)) .filter(game::attack_id.eq(user_id).or(game::defend_id.eq(user_id))) diff --git a/src/api/inventory/util.rs b/src/api/inventory/util.rs index f38c6637..88cf4847 100644 --- a/src/api/inventory/util.rs +++ b/src/api/inventory/util.rs @@ -728,7 +728,6 @@ pub(crate) fn upgrade_building( bank_map_space_id, ); let building_map_space_id = get_building_map_space_id(conn, &id_of_map, &next_level_block_id)?; - println!("building_map_space_id: {:?}", building_map_space_id); Ok(building_map_space_id) } @@ -988,7 +987,9 @@ pub(crate) fn upgrade_attacker( })?; conn.transaction(|conn| { diesel::update( - available_blocks::table.filter(available_blocks::attacker_type_id.eq(attacker_id)), + available_blocks::table + .filter(available_blocks::attacker_type_id.eq(attacker_id)) + .filter(available_blocks::user_id.eq(player_id)), ) .set(available_blocks::attacker_type_id.eq(next_level_attacker_id)) .execute(conn)?; @@ -1072,9 +1073,13 @@ pub(crate) fn upgrade_emp(player_id: i32, conn: &mut PgConnection, emp_id: i32) return Err(anyhow::anyhow!("Not enough artifacts in bank")); } conn.transaction(|conn| { - diesel::update(available_blocks::table.filter(available_blocks::emp_type_id.eq(emp_id))) - .set(available_blocks::emp_type_id.eq(next_level_emp_id)) - .execute(conn)?; + diesel::update( + available_blocks::table + .filter(available_blocks::emp_type_id.eq(emp_id)) + .filter(available_blocks::user_id.eq(player_id)), + ) + .set(available_blocks::emp_type_id.eq(next_level_emp_id)) + .execute(conn)?; //update artifacts in bank diesel::update(artifact::table.filter(artifact::map_space_id.eq(bank_map_space_id))) diff --git a/src/bin/penalise_invalid_bases.rs b/src/bin/penalise_invalid_bases.rs index 77d98e91..32f421ea 100644 --- a/src/bin/penalise_invalid_bases.rs +++ b/src/bin/penalise_invalid_bases.rs @@ -29,6 +29,4 @@ fn main() { .set(user::trophies.eq(user::trophies - ((4.0 * SCALE_FACTOR) as i32))) .execute(&mut conn) .expect("Could not update user ratings"); - - println!("Ratings have been updated"); } diff --git a/src/bin/update_rating.rs b/src/bin/update_rating.rs index f988c563..814a5995 100755 --- a/src/bin/update_rating.rs +++ b/src/bin/update_rating.rs @@ -10,6 +10,4 @@ fn main() { .set(user::trophies.eq(1000)) .execute(&mut conn) .expect("Could not update user ratings"); - - println!("Ratings have been updated"); } diff --git a/src/validator/mod.rs b/src/validator/mod.rs index 41027c7c..0dc1a3f7 100644 --- a/src/validator/mod.rs +++ b/src/validator/mod.rs @@ -76,10 +76,6 @@ pub fn game_handler( _game_log.r.au += 1; if _game_state.in_validation.is_invalidated { - println!( - "Invalidated due to: {}", - _game_state.in_validation.message.clone() - ); return Some(Ok(send_terminate_game_message( socket_request.frame_number, _game_state.in_validation.message.clone(), @@ -173,10 +169,6 @@ pub fn game_handler( } if _game_state.in_validation.is_invalidated { - println!( - "Invalidated due to: {}", - _game_state.in_validation.message.clone() - ); return Some(Ok(send_terminate_game_message( socket_request.frame_number, _game_state.in_validation.message.clone(), @@ -223,10 +215,6 @@ pub fn game_handler( } if _game_state.in_validation.is_invalidated { - println!( - "Invalidated due to: {}", - _game_state.in_validation.message.clone() - ); return Some(Ok(send_terminate_game_message( socket_request.frame_number, _game_state.in_validation.message.clone(), @@ -252,7 +240,6 @@ pub fn game_handler( ActionType::PlaceBombs => { let attacker_delta: Vec = socket_request.attacker_path.clone(); let current_pos = socket_request.start_position.unwrap(); - println!("attacker delta: {:?}", attacker_delta); let bomb_coords = socket_request.bomb_position; if _game_state.bombs.total_count == 0 { @@ -304,10 +291,6 @@ pub fn game_handler( }; if _game_state.in_validation.is_invalidated { - println!( - "Invalidated due to: {}", - _game_state.in_validation.message.clone() - ); return Some(Ok(send_terminate_game_message( socket_request.frame_number, _game_state.in_validation.message.clone(), diff --git a/src/validator/state.rs b/src/validator/state.rs index 5d6ff539..7b6a5f0e 100644 --- a/src/validator/state.rs +++ b/src/validator/state.rs @@ -72,7 +72,6 @@ impl State { for defender in self.defenders.iter_mut() { defender.target_id = None; } - println!("attacker died due to self destruct"); } pub fn set_total_hp_buildings(&mut self) { @@ -94,9 +93,6 @@ impl State { pub fn place_attacker(&mut self, attacker: Attacker) { self.attacker = Some(attacker); // println!("defnders: {:?}",self.defenders); - for defender in self.defenders.iter_mut() { - println!("defender: {:?}", defender.id); - } } pub fn mine_blast_update(&mut self, _id: i32, damage_to_attacker: i32) { @@ -106,10 +102,6 @@ impl State { attacker.attacker_health = std::cmp::max(0, attacker.attacker_health - damage_to_attacker); if attacker.attacker_health == 0 { - println!( - "attacker died due to mine blast and mine damage : {}", - damage_to_attacker - ); self.attacker_death_count += 1; for defender in self.defenders.iter_mut() { defender.target_id = None; @@ -146,8 +138,6 @@ impl State { }; } - println!("state frame: {} current frame: {}", self.frame_no, frame_no); - for coord in attacker_current.path_in_current_frame.clone().into_iter() { if !roads.contains(&(coord.x, coord.y)) { // GAME_OVER @@ -236,7 +226,6 @@ impl State { // } if self.bombs.total_count <= 0 { - println!("Bomb over"); self.in_validation = InValidation { message: "Bomb Count forged".to_string(), is_invalidated: true, @@ -245,7 +234,6 @@ impl State { if let Some(attacker) = &mut self.attacker { attacker.bomb_count -= 1; - println!("bomb count: {}", attacker.bomb_count); } if current_pos.x != bomb_position.x || current_pos.y != bomb_position.y { @@ -265,7 +253,6 @@ impl State { attacker_delta: Vec, shortest_path: &HashMap, ) -> DefenderReturnType { - println!("attacker delta: {:?}", attacker_delta); let attacker = self.attacker.as_mut().unwrap(); let mut defenders_damaged: Vec = Vec::new(); @@ -350,11 +337,6 @@ impl State { defender.defender_pos = *next_hop; defender.path_in_current_frame.push(defender.defender_pos); - println!( - "{i}; attacker pos: {:?}, defender pos: {:?}", - attacker.attacker_pos, defender.defender_pos - ); - // if defender and attacker are on the same tile, add the defender to the collision_array if (defender.defender_pos == attacker.attacker_pos) || (defender.path_in_current_frame[(i - 1) as usize] == attacker.attacker_pos) @@ -380,7 +362,6 @@ impl State { if time > 1.0 { break; } - println!("defender id: {} collided at time: {}", index, time); if attacker.attacker_health == 0 { self.defenders[index].defender_pos = self.defenders[index].path_in_current_frame [1 + (attacker_death_time * (self.defenders[index].speed as f32)) as usize]; @@ -400,7 +381,6 @@ impl State { if attacker.attacker_health == 0 { attacker_death_time = time; self.attacker_death_count += 1; - println!("attacker died"); } } @@ -435,7 +415,6 @@ impl State { pub fn bomb_blast(&mut self, bomb_position: Coords) -> Vec { let bomb = &mut self.bombs; - println!("bomb blast damage: {}", bomb.damage); let mut buildings_damaged: Vec = Vec::new(); for building in self.buildings.iter_mut() { if building.current_hp > 0 { @@ -463,20 +442,10 @@ impl State { coinciding_coords_damage as f32 / building_matrix.len() as f32; if damage_buildings != 0.0 { - println!( - "damage building: {}, bomb damage: {}, total_hp:{}", - damage_buildings, bomb.damage, building.total_hp - ); - let old_hp = building.current_hp; let mut current_damage = (damage_buildings * (bomb.damage as f32 * BOMB_DAMAGE_MULTIPLIER)) .round() as i32; - println!( - "current damage: {}, current_hp: {}", - current_damage, - building.current_hp - current_damage - ); building.current_hp -= current_damage;