rust/hedgewars-server/src/server/database.rs
changeset 14785 a1077e8d26f4
parent 14779 f43ab2bd76ae
child 15074 c5a6e8566425
equal deleted inserted replaced
14784:8390d5e4e39c 14785:a1077e8d26f4
    13 
    13 
    14 const STORE_STATS_QUERY: &str = r"INSERT INTO gameserver_stats
    14 const STORE_STATS_QUERY: &str = r"INSERT INTO gameserver_stats
    15             (players, rooms, last_update)
    15             (players, rooms, last_update)
    16             VALUES
    16             VALUES
    17             (:players, :rooms, UNIX_TIMESTAMP())";
    17             (:players, :rooms, UNIX_TIMESTAMP())";
       
    18 
       
    19 const GET_REPLAY_NAME_QUERY: &str = r"SELECT filename FROM achievements WHERE id = :id";
    18 
    20 
    19 struct ServerStatistics {
    21 struct ServerStatistics {
    20     rooms: u32,
    22     rooms: u32,
    21     players: u32,
    23     players: u32,
    22 }
    24 }
    93 
    95 
    94     pub fn store_achievements(&mut self, achievements: &Achievements) -> Result<(), ()> {
    96     pub fn store_achievements(&mut self, achievements: &Achievements) -> Result<(), ()> {
    95         Ok(())
    97         Ok(())
    96     }
    98     }
    97 
    99 
    98     pub fn get_replay_name(&mut self, replay_id: u32) -> Result<String, ()> {
   100     pub fn get_replay_name(&mut self, replay_id: u32) -> Result<Option<String>, Error> {
    99         Err(())
   101         if let Some(pool) = &self.pool {
       
   102             if let Some(row) =
       
   103                 pool.first_exec(GET_REPLAY_NAME_QUERY, params! { "id" => replay_id })?
       
   104             {
       
   105                 let (filename) = from_row_opt::<(String)>(row)?;
       
   106                 Ok(Some(filename))
       
   107             } else {
       
   108                 Ok(None)
       
   109             }
       
   110         } else {
       
   111             Err(DriverError::SetupError.into())
       
   112         }
   100     }
   113     }
   101 }
   114 }
   102 
   115 
   103 fn get_hash(protocol_number: u16, web_password: &str, salt1: &str, salt2: &str) -> Sha1Digest {
   116 fn get_hash(protocol_number: u16, web_password: &str, salt1: &str, salt2: &str) -> Sha1Digest {
   104     let s = format!(
   117     let s = format!(