Browse Source

Add country code to User struct.

wip
Titouan Rigoudy 9 years ago
parent
commit
c4c293056e
2 changed files with 19 additions and 6 deletions
  1. +16
    -5
      src/proto/server/response.rs
  2. +3
    -1
      src/user.rs

+ 16
- 5
src/proto/server/response.rs View File

@ -161,8 +161,6 @@ impl FromPacket for JoinRoomResponse {
try!(response.read_user_infos(packet));
try!(packet.read_array(&mut response.user_countries, Packet::read_str));
if packet.bytes_remaining() > 0 {
response.owner = Some(try!(packet.read_str()));
try!(packet.read_array(&mut response.operators, Packet::read_str));
@ -188,6 +186,7 @@ impl JoinRoomResponse {
num_files: 0,
num_folders: 0,
num_free_slots: 0,
country: None,
})
});
let num_statuses = try!(num_statuses_res);
@ -214,10 +213,22 @@ impl JoinRoomResponse {
});
let num_free_slots = try!(num_free_slots_res);
if num_statuses != num_infos || num_statuses != num_free_slots {
let num_countries_res: result::Result<usize> =
packet.read_array_with(|packet, i| {
if let Some(user) = self.user_infos.get_mut(i) {
user.country = Some(try!(packet.read_str()));
}
Ok(())
});
let num_countries = try!(num_countries_res);
if num_statuses != num_infos ||
num_statuses != num_free_slots ||
num_statuses != num_countries
{
warn!(
"JoinRoomResponse: mismatched vector sizes {}, {}, {}",
num_statuses, num_infos, num_free_slots
"JoinRoomResponse: mismatched vector sizes {}, {}, {}, {}",
num_statuses, num_infos, num_free_slots, num_countries
);
}


+ 3
- 1
src/user.rs View File

@ -40,7 +40,7 @@ impl Status {
/// This structure contains the last known information about a fellow user.
/// It does not store the name, as that is stored implicitly as the key in the
/// user hash table.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Debug)]
pub struct User {
/// The last known status of the user.
pub status: Status,
@ -56,6 +56,8 @@ pub struct User {
pub num_folders: usize,
/// The number of free download slots of this user.
pub num_free_slots: usize,
/// The user's country code. If unknown, set to None.
pub country: Option<String>,
}
/// Contains the mapping from user names to user data and provides a clean


Loading…
Cancel
Save