@@ -21,7 +21,7 @@ use sodiumoxide::crypto::sign;
2121
2222use crate :: {
2323 compress:: { compress, decompress} ,
24- log,
24+ is_client , is_host , is_sos , is_standard , log,
2525 password_security:: {
2626 decrypt_str_or_original, decrypt_vec_or_original, encrypt_str_or_original,
2727 encrypt_vec_or_original, symmetric_crypt,
@@ -70,6 +70,8 @@ lazy_static::lazy_static! {
7070 pub static ref OVERWRITE_LOCAL_SETTINGS : RwLock <HashMap <String , String >> = Default :: default ( ) ;
7171 pub static ref HARD_SETTINGS : RwLock <HashMap <String , String >> = Default :: default ( ) ;
7272 pub static ref BUILTIN_SETTINGS : RwLock <HashMap <String , String >> = Default :: default ( ) ;
73+ pub static ref STRATEGY_OVERRIDE_SETTINGS : RwLock <HashMap <String , String >> = Default :: default ( ) ;
74+ pub static ref STRATEGY_HARD_SETTINGS : RwLock <HashMap <String , String >> = Default :: default ( ) ;
7375}
7476
7577lazy_static:: lazy_static! {
@@ -986,13 +988,22 @@ impl Config {
986988 pub fn get_options ( ) -> HashMap < String , String > {
987989 let mut res = DEFAULT_SETTINGS . read ( ) . unwrap ( ) . clone ( ) ;
988990 res. extend ( CONFIG2 . read ( ) . unwrap ( ) . options . clone ( ) ) ;
991+ res. extend ( STRATEGY_OVERRIDE_SETTINGS . read ( ) . unwrap ( ) . clone ( ) ) ;
989992 res. extend ( OVERWRITE_SETTINGS . read ( ) . unwrap ( ) . clone ( ) ) ;
990993 res
991994 }
992995
993996 #[ inline]
994997 fn purify_options ( v : & mut HashMap < String , String > ) {
995- v. retain ( |k, v| is_option_can_save ( & OVERWRITE_SETTINGS , k, & DEFAULT_SETTINGS , v) ) ;
998+ v. retain ( |k, v| {
999+ is_option_can_save (
1000+ & OVERWRITE_SETTINGS ,
1001+ & STRATEGY_OVERRIDE_SETTINGS ,
1002+ k,
1003+ & DEFAULT_SETTINGS ,
1004+ v,
1005+ )
1006+ } ) ;
9961007 }
9971008
9981009 pub fn set_options ( mut v : HashMap < String , String > ) {
@@ -1008,6 +1019,7 @@ impl Config {
10081019 pub fn get_option ( k : & str ) -> String {
10091020 get_or (
10101021 & OVERWRITE_SETTINGS ,
1022+ & STRATEGY_OVERRIDE_SETTINGS ,
10111023 & CONFIG2 . read ( ) . unwrap ( ) . options ,
10121024 & DEFAULT_SETTINGS ,
10131025 k,
@@ -1020,7 +1032,13 @@ impl Config {
10201032 }
10211033
10221034 pub fn set_option ( k : String , v : String ) {
1023- if !is_option_can_save ( & OVERWRITE_SETTINGS , & k, & DEFAULT_SETTINGS , & v) {
1035+ if !is_option_can_save (
1036+ & OVERWRITE_SETTINGS ,
1037+ & STRATEGY_OVERRIDE_SETTINGS ,
1038+ & k,
1039+ & DEFAULT_SETTINGS ,
1040+ & v,
1041+ ) {
10241042 return ;
10251043 }
10261044 let mut config = CONFIG2 . write ( ) . unwrap ( ) ;
@@ -1098,6 +1116,13 @@ impl Config {
10981116 {
10991117 return ;
11001118 }
1119+ if STRATEGY_OVERRIDE_SETTINGS
1120+ . read ( )
1121+ . unwrap ( )
1122+ . contains_key ( keys:: OPTION_PROXY_URL )
1123+ {
1124+ return ;
1125+ }
11011126
11021127 let mut config = CONFIG2 . write ( ) . unwrap ( ) ;
11031128 if config. socks == socks {
@@ -1156,6 +1181,9 @@ impl Config {
11561181
11571182 pub fn get_socks ( ) -> Option < Socks5Server > {
11581183 Self :: get_socks_from_custom_client_advanced_settings ( & OVERWRITE_SETTINGS . read ( ) . unwrap ( ) )
1184+ . or ( Self :: get_socks_from_custom_client_advanced_settings (
1185+ & STRATEGY_OVERRIDE_SETTINGS . read ( ) . unwrap ( ) ,
1186+ ) )
11591187 . or ( CONFIG2 . read ( ) . unwrap ( ) . socks . clone ( ) )
11601188 . or ( Self :: get_socks_from_custom_client_advanced_settings (
11611189 & DEFAULT_SETTINGS . read ( ) . unwrap ( ) ,
@@ -1176,6 +1204,14 @@ impl Config {
11761204 {
11771205 return NetworkType :: ProxySocks ;
11781206 }
1207+ if STRATEGY_OVERRIDE_SETTINGS
1208+ . read ( )
1209+ . unwrap ( )
1210+ . get ( keys:: OPTION_PROXY_URL )
1211+ . is_some ( )
1212+ {
1213+ return NetworkType :: ProxySocks ;
1214+ }
11791215 if CONFIG2 . read ( ) . unwrap ( ) . socks . is_some ( ) {
11801216 return NetworkType :: ProxySocks ;
11811217 }
@@ -1766,6 +1802,7 @@ impl LocalConfig {
17661802 pub fn get_option ( k : & str ) -> String {
17671803 get_or (
17681804 & OVERWRITE_LOCAL_SETTINGS ,
1805+ & STRATEGY_OVERRIDE_SETTINGS ,
17691806 & LOCAL_CONFIG . read ( ) . unwrap ( ) . options ,
17701807 & DEFAULT_LOCAL_SETTINGS ,
17711808 k,
@@ -1777,6 +1814,7 @@ impl LocalConfig {
17771814 pub fn get_option_from_file ( k : & str ) -> String {
17781815 get_or (
17791816 & OVERWRITE_LOCAL_SETTINGS ,
1817+ & STRATEGY_OVERRIDE_SETTINGS ,
17801818 & Self :: load ( ) . options ,
17811819 & DEFAULT_LOCAL_SETTINGS ,
17821820 k,
@@ -1789,7 +1827,13 @@ impl LocalConfig {
17891827 }
17901828
17911829 pub fn set_option ( k : String , v : String ) {
1792- if !is_option_can_save ( & OVERWRITE_LOCAL_SETTINGS , & k, & DEFAULT_LOCAL_SETTINGS , & v) {
1830+ if !is_option_can_save (
1831+ & OVERWRITE_LOCAL_SETTINGS ,
1832+ & STRATEGY_OVERRIDE_SETTINGS ,
1833+ & k,
1834+ & DEFAULT_LOCAL_SETTINGS ,
1835+ & v,
1836+ ) {
17931837 return ;
17941838 }
17951839 let mut config = LOCAL_CONFIG . write ( ) . unwrap ( ) ;
@@ -1814,6 +1858,7 @@ impl LocalConfig {
18141858 pub fn get_flutter_option ( k : & str ) -> String {
18151859 get_or (
18161860 & OVERWRITE_LOCAL_SETTINGS ,
1861+ & STRATEGY_OVERRIDE_SETTINGS ,
18171862 & LOCAL_CONFIG . read ( ) . unwrap ( ) . ui_flutter ,
18181863 & DEFAULT_LOCAL_SETTINGS ,
18191864 k,
@@ -1946,6 +1991,7 @@ impl UserDefaultConfig {
19461991 pub fn set ( & mut self , key : String , value : String ) {
19471992 if !is_option_can_save (
19481993 & OVERWRITE_DISPLAY_SETTINGS ,
1994+ & STRATEGY_OVERRIDE_SETTINGS ,
19491995 & key,
19501996 & DEFAULT_DISPLAY_SETTINGS ,
19511997 & value,
@@ -1995,6 +2041,7 @@ impl UserDefaultConfig {
19952041 fn get_after ( & self , k : & str ) -> Option < String > {
19962042 get_or (
19972043 & OVERWRITE_DISPLAY_SETTINGS ,
2044+ & STRATEGY_OVERRIDE_SETTINGS ,
19982045 & self . options ,
19992046 & DEFAULT_DISPLAY_SETTINGS ,
20002047 k,
@@ -2174,6 +2221,12 @@ pub struct GroupPeer {
21742221 skip_serializing_if = "String::is_empty"
21752222 ) ]
21762223 pub login_name : String ,
2224+ #[ serde(
2225+ default ,
2226+ deserialize_with = "deserialize_string" ,
2227+ skip_serializing_if = "String::is_empty"
2228+ ) ]
2229+ pub user : String ,
21772230}
21782231
21792232#[ derive( Debug , Default , Serialize , Deserialize , Clone ) ]
@@ -2184,6 +2237,12 @@ pub struct GroupUser {
21842237 skip_serializing_if = "String::is_empty"
21852238 ) ]
21862239 pub name : String ,
2240+ #[ serde(
2241+ default ,
2242+ deserialize_with = "deserialize_string" ,
2243+ skip_serializing_if = "String::is_empty"
2244+ ) ]
2245+ pub user : String ,
21872246}
21882247
21892248#[ derive( Debug , Default , Serialize , Deserialize , Clone ) ]
@@ -2291,26 +2350,30 @@ deserialize_default!(deserialize_hashmap_resolutions, HashMap<String, Resolution
22912350#[ inline]
22922351fn get_or (
22932352 a : & RwLock < HashMap < String , String > > ,
2294- b : & HashMap < String , String > ,
2295- c : & RwLock < HashMap < String , String > > ,
2353+ b : & RwLock < HashMap < String , String > > ,
2354+ c : & HashMap < String , String > ,
2355+ d : & RwLock < HashMap < String , String > > ,
22962356 k : & str ,
22972357) -> Option < String > {
22982358 a. read ( )
22992359 . unwrap ( )
23002360 . get ( k)
2301- . or ( b. get ( k) )
2302- . or ( c. read ( ) . unwrap ( ) . get ( k) )
2361+ . or ( b. read ( ) . unwrap ( ) . get ( k) )
2362+ . or ( c. get ( k) )
2363+ . or ( d. read ( ) . unwrap ( ) . get ( k) )
23032364 . cloned ( )
23042365}
23052366
23062367#[ inline]
23072368fn is_option_can_save (
23082369 overwrite : & RwLock < HashMap < String , String > > ,
2370+ strategy_override : & RwLock < HashMap < String , String > > ,
23092371 k : & str ,
23102372 defaults : & RwLock < HashMap < String , String > > ,
23112373 v : & str ,
23122374) -> bool {
23132375 if overwrite. read ( ) . unwrap ( ) . contains_key ( k)
2376+ || strategy_override. read ( ) . unwrap ( ) . contains_key ( k)
23142377 || defaults. read ( ) . unwrap ( ) . get ( k) . map_or ( false , |x| x == v)
23152378 {
23162379 return false ;
@@ -2320,29 +2383,36 @@ fn is_option_can_save(
23202383
23212384#[ inline]
23222385pub fn is_incoming_only ( ) -> bool {
2323- HARD_SETTINGS
2324- . read ( )
2325- . unwrap ( )
2326- . get ( "conn-type" )
2327- . map_or ( false , |x| x == ( "incoming" ) )
2386+ is_host ( )
2387+ || is_sos ( )
2388+ || ( is_standard ( )
2389+ && HARD_SETTINGS
2390+ . read ( )
2391+ . unwrap ( )
2392+ . get ( "conn-type" )
2393+ . map_or ( false , |x| x == ( "incoming" ) ) )
23282394}
23292395
23302396#[ inline]
23312397pub fn is_outgoing_only ( ) -> bool {
2332- HARD_SETTINGS
2333- . read ( )
2334- . unwrap ( )
2335- . get ( "conn-type" )
2336- . map_or ( false , |x| x == ( "outgoing" ) )
2398+ is_client ( )
2399+ || ( is_standard ( )
2400+ && HARD_SETTINGS
2401+ . read ( )
2402+ . unwrap ( )
2403+ . get ( "conn-type" )
2404+ . map_or ( false , |x| x == ( "outgoing" ) ) )
23372405}
23382406
23392407#[ inline]
23402408fn is_some_hard_opton ( name : & str ) -> bool {
2341- HARD_SETTINGS
2342- . read ( )
2343- . unwrap ( )
2344- . get ( name)
2345- . map_or ( false , |x| x == ( "Y" ) )
2409+ if let Some ( value) = HARD_SETTINGS . read ( ) . unwrap ( ) . get ( name) {
2410+ return value == "Y" ;
2411+ }
2412+ if let Some ( value) = STRATEGY_HARD_SETTINGS . read ( ) . unwrap ( ) . get ( name) {
2413+ return value == "Y" ;
2414+ }
2415+ false
23462416}
23472417
23482418#[ inline]
@@ -2362,12 +2432,12 @@ pub fn is_disable_ab() -> bool {
23622432
23632433#[ inline]
23642434pub fn is_disable_account ( ) -> bool {
2365- is_some_hard_opton ( "disable-account" )
2435+ is_sos ( ) || is_host ( ) || ( is_standard ( ) && is_some_hard_opton ( "disable-account" ) )
23662436}
23672437
23682438#[ inline]
23692439pub fn is_disable_installation ( ) -> bool {
2370- is_some_hard_opton ( "disable-installation" )
2440+ is_sos ( ) || is_some_hard_opton ( "disable-installation" )
23712441}
23722442
23732443// This function must be kept the same as the one in flutter and sciter code.
@@ -2610,6 +2680,7 @@ pub mod keys {
26102680 OPTION_VIDEO_SAVE_DIRECTORY ,
26112681 OPTION_ENABLE_UDP_PUNCH ,
26122682 OPTION_ENABLE_IPV6_PUNCH ,
2683+ OPTION_ENABLE_CHECK_UPDATE ,
26132684 ] ;
26142685 // DEFAULT_SETTINGS, OVERWRITE_SETTINGS
26152686 pub const KEYS_SETTINGS : & [ & str ] = & [
@@ -2655,6 +2726,7 @@ pub mod keys {
26552726 OPTION_ENABLE_DIRECTX_CAPTURE ,
26562727 OPTION_ENABLE_ANDROID_SOFTWARE_ENCODING_HALF_SCALE ,
26572728 OPTION_ENABLE_TRUSTED_DEVICES ,
2729+ OPTION_ALLOW_AUTO_UPDATE ,
26582730 ] ;
26592731
26602732 // BUILDIN_SETTINGS
0 commit comments