2019-04-24 17:01:43 +02:00
mod implementation ;
2019-04-25 23:37:16 +02:00
pub use self ::implementation ::* ;
2019-06-05 19:32:23 +02:00
mod autoconnect ;
pub use self ::autoconnect ::start_autoconnect_server_async ;
2019-05-24 17:23:12 +02:00
use std ::fmt ::Display ;
2019-04-20 01:24:19 +02:00
2019-04-24 17:01:43 +02:00
use crate ::model ::* ;
2019-04-20 01:24:19 +02:00
2019-04-24 17:01:43 +02:00
use std ::io ;
2019-04-20 01:24:19 +02:00
2019-05-24 17:23:12 +02:00
pub trait ClientConnection : Display { }
2019-04-24 17:01:43 +02:00
pub trait ProtocolHandler : Send + Sync + Clone {
2019-05-24 17:23:12 +02:00
fn new_connection ( & mut self , _con : & ClientConnection ) { }
fn query ( & mut self , con : & ClientConnection , query : & [ String ] ) -> ProtocolResult < Vec < Texture > > ;
2019-04-20 01:24:19 +02:00
2019-05-24 17:23:12 +02:00
fn get_texture_by_id (
& mut self ,
con : & ClientConnection ,
id : & str ,
) -> ProtocolResult < Option < Texture > > ;
2019-04-20 01:24:19 +02:00
2019-05-24 17:23:12 +02:00
fn get_texture_by_name (
& mut self ,
con : & ClientConnection ,
name : & str ,
) -> ProtocolResult < Option < Texture > > ;
2019-04-20 01:24:19 +02:00
2019-05-24 17:23:12 +02:00
fn get_texture_file ( & mut self , con : & ClientConnection , hash : Sha256 )
-> ProtocolResult < Vec < u8 > > ;
2019-04-20 01:24:19 +02:00
2019-04-24 19:24:00 +02:00
fn get_texture_preview (
& mut self ,
2019-05-24 17:23:12 +02:00
con : & ClientConnection ,
2019-04-24 19:24:00 +02:00
hash : Sha256 ,
format : TextureFormat ,
) -> ProtocolResult < Vec < u8 > > ;
2019-04-20 01:24:19 +02:00
fn replace_texture (
& mut self ,
2019-05-24 17:23:12 +02:00
con : & ClientConnection ,
2019-04-20 01:24:19 +02:00
delete : Option < Texture > ,
insert : Option < Texture > ,
insert_texture_data : Option < Vec < u8 > > ,
) -> ProtocolResult < ReplaceTextureStatus > ;
2019-05-24 17:23:12 +02:00
fn disconnected ( & mut self , _con : & ClientConnection ) { }
2019-04-20 01:24:19 +02:00
}
2019-04-24 17:01:43 +02:00
#[ derive(Clone, Debug) ]
2019-04-20 01:24:19 +02:00
pub struct ProtocolConfig {
pub port : u16 ,
2019-04-24 17:01:43 +02:00
pub read_timeout_s : u64 ,
pub write_timeout_s : u64 ,
pub listen_addr : String ,
2019-06-05 19:35:10 +02:00
pub autoconnect_multicastv6_addr : String ,
2019-04-20 01:24:19 +02:00
}
2019-04-24 17:01:43 +02:00
impl ProtocolConfig {
pub fn new ( ) -> ProtocolConfig {
ProtocolConfig ::default ( )
}
}
impl Default for ProtocolConfig {
fn default ( ) -> ProtocolConfig {
ProtocolConfig {
port : 10796 ,
2019-06-19 15:49:13 +02:00
read_timeout_s : 3 * 600 , // 30 Min.
2019-04-24 17:01:43 +02:00
write_timeout_s : 75 ,
2019-06-03 16:55:40 +02:00
listen_addr : " :: " . to_owned ( ) ,
2019-06-05 19:32:23 +02:00
autoconnect_multicastv6_addr : " ff02::dd42:c0fe " . to_owned ( ) ,
2019-04-24 17:01:43 +02:00
}
}
}