Implement Server Logging
This commit is contained in:
@ -21,7 +21,11 @@ impl ServerState {
|
||||
}
|
||||
|
||||
impl ProtocolHandler for ServerState {
|
||||
fn query(&mut self, query: &[String]) -> ProtocolResult<Vec<Texture>> {
|
||||
fn new_connection(&mut self, con: &ClientConnection) {
|
||||
println!("{}: New Connection", con);
|
||||
}
|
||||
|
||||
fn query(&mut self, con: &ClientConnection, query: &[String]) -> ProtocolResult<Vec<Texture>> {
|
||||
let q = Query::parse(query)
|
||||
.map_err(|e| ProtocolError::BadRequest(format!("Invalid Query String: {:?}", e)))?;
|
||||
|
||||
@ -31,40 +35,83 @@ impl ProtocolHandler for ServerState {
|
||||
.unwrap_or_else(|_| handle_broken_rwlock());
|
||||
|
||||
let mut textures = data_store.borrow_textures();
|
||||
Ok(q.search(&mut textures))
|
||||
|
||||
let found = q.search(&mut textures);
|
||||
|
||||
println!("{}: Query '{:?}' found: {}", con, query, found.len());
|
||||
|
||||
Ok(found)
|
||||
}
|
||||
|
||||
fn get_texture_by_id(&mut self, id: &str) -> ProtocolResult<Option<Texture>> {
|
||||
fn get_texture_by_id(
|
||||
&mut self,
|
||||
con: &ClientConnection,
|
||||
id: &str,
|
||||
) -> ProtocolResult<Option<Texture>> {
|
||||
let data_store = self
|
||||
.data_store
|
||||
.read()
|
||||
.unwrap_or_else(|_| handle_broken_rwlock());
|
||||
|
||||
Ok(data_store.texture_by_id(id))
|
||||
let found = data_store.texture_by_id(id);
|
||||
|
||||
println!(
|
||||
"{}: Texture by id: '{}' found: {}",
|
||||
con,
|
||||
id,
|
||||
found.is_some()
|
||||
);
|
||||
|
||||
Ok(found)
|
||||
}
|
||||
|
||||
fn get_texture_by_name(&mut self, name: &str) -> ProtocolResult<Option<Texture>> {
|
||||
fn get_texture_by_name(
|
||||
&mut self,
|
||||
con: &ClientConnection,
|
||||
name: &str,
|
||||
) -> ProtocolResult<Option<Texture>> {
|
||||
let data_store = self
|
||||
.data_store
|
||||
.read()
|
||||
.unwrap_or_else(|_| handle_broken_rwlock());
|
||||
|
||||
Ok(data_store.texture_by_name(name))
|
||||
let found = data_store.texture_by_name(name);
|
||||
|
||||
println!(
|
||||
"{}: Texture by name: '{}' found: {}",
|
||||
con,
|
||||
name,
|
||||
found.is_some()
|
||||
);
|
||||
|
||||
Ok(found)
|
||||
}
|
||||
|
||||
fn get_texture_file(&mut self, hash: Sha256) -> ProtocolResult<Vec<u8>> {
|
||||
fn get_texture_file(
|
||||
&mut self,
|
||||
con: &ClientConnection,
|
||||
hash: Sha256,
|
||||
) -> ProtocolResult<Vec<u8>> {
|
||||
let data_store = self
|
||||
.data_store
|
||||
.read()
|
||||
.unwrap_or_else(|_| handle_broken_rwlock());
|
||||
|
||||
let data = data_store.read_texture_file_by_hash(&hash)?;
|
||||
let data = data_store.read_texture_file_by_hash(&hash);
|
||||
|
||||
Ok(data)
|
||||
println!(
|
||||
"{}: Texture File: '{:?}' found: {}",
|
||||
con,
|
||||
&hash,
|
||||
data.is_ok()
|
||||
);
|
||||
|
||||
Ok(data?)
|
||||
}
|
||||
|
||||
fn get_texture_preview(
|
||||
&mut self,
|
||||
con: &ClientConnection,
|
||||
hash: Sha256,
|
||||
format: TextureFormat,
|
||||
) -> ProtocolResult<Vec<u8>> {
|
||||
@ -73,17 +120,27 @@ impl ProtocolHandler for ServerState {
|
||||
.write()
|
||||
.unwrap_or_else(|_| handle_broken_rwlock());
|
||||
|
||||
let preview = data_store.get_texture_preview(&hash, format)?;
|
||||
let preview = data_store.get_texture_preview(&hash, format);
|
||||
|
||||
Ok(preview)
|
||||
println!(
|
||||
"{}: Texture Preview: '{:?}' found: {}",
|
||||
con,
|
||||
&hash,
|
||||
preview.is_ok()
|
||||
);
|
||||
|
||||
Ok(preview?)
|
||||
}
|
||||
|
||||
fn replace_texture(
|
||||
&mut self,
|
||||
con: &ClientConnection,
|
||||
delete: Option<Texture>,
|
||||
insert: Option<Texture>,
|
||||
insert_texture_data: Option<Vec<u8>>,
|
||||
) -> ProtocolResult<ReplaceTextureStatus> {
|
||||
println!("{}: Replace Texture Request", con);
|
||||
|
||||
let mut data_store = self
|
||||
.data_store
|
||||
.write()
|
||||
@ -152,6 +209,10 @@ impl ProtocolHandler for ServerState {
|
||||
(None, None) => Ok(ReplaceTextureStatus::Ok),
|
||||
}
|
||||
}
|
||||
|
||||
fn disconnected(&mut self, con: &ClientConnection) {
|
||||
println!("{}: Disconnected", con);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_broken_rwlock() -> ! {
|
||||
|
Reference in New Issue
Block a user