@@ -10,6 +10,7 @@ pub fn write_realmlist(
1010 wow_path : & str ,
1111 host : & str ,
1212 locale : & str ,
13+ account_name : Option < & str > ,
1314) -> Result < ( ) , String > {
1415 let base = Path :: new ( wow_path) ;
1516 let host = host. trim ( ) ;
@@ -25,46 +26,59 @@ pub fn write_realmlist(
2526 let realmlist_wtf = data_dir. join ( "realmlist.wtf" ) ;
2627 std:: fs:: write ( & realmlist_wtf, & content) . map_err ( |e| e. to_string ( ) ) ?;
2728
28- // 3. WTF/Config.wtf (some clients read realmlist from here )
29+ // 3. WTF/Config.wtf (realmlist + accountName )
2930 let wtf_dir = base. join ( "WTF" ) ;
3031 let config_wtf = wtf_dir. join ( "Config.wtf" ) ;
31- write_realmlist_into_config ( & config_wtf, host) ?;
32+ write_realmlist_into_config ( & config_wtf, host, account_name ) ?;
3233
3334 Ok ( ( ) )
3435}
3536
36- /// Updates or adds the realmlist line in WTF/Config.wtf.
37- /// Preserves all other lines; replaces any existing "set realmlist" or "SET portal" line.
38- fn write_realmlist_into_config ( config_path : & std:: path:: Path , host : & str ) -> Result < ( ) , String > {
39- let new_line = format ! ( "{}{}" , REALMLIST_LINE_PREFIX , host) ;
37+ /// Updates or adds the realmlist and accountName lines in WTF/Config.wtf.
38+ /// Preserves all other lines.
39+ fn write_realmlist_into_config (
40+ config_path : & std:: path:: Path ,
41+ host : & str ,
42+ account_name : Option < & str > ,
43+ ) -> Result < ( ) , String > {
44+ let new_realmlist = format ! ( "{}{}" , REALMLIST_LINE_PREFIX , host) ;
45+ let new_account = account_name
46+ . filter ( |n| !n. is_empty ( ) )
47+ . map ( |n| format ! ( "SET accountName \" {}\" " , n) ) ;
48+
49+ let mut had_realmlist = false ;
50+ let mut had_account = false ;
4051
41- let ( lines, had_realmlist ) = if config_path. exists ( ) {
52+ let mut lines: Vec < String > = if config_path. exists ( ) {
4253 let s = std:: fs:: read_to_string ( config_path) . map_err ( |e| e. to_string ( ) ) ?;
43- let lines: Vec < String > = s. lines ( ) . map ( String :: from) . collect ( ) ;
44- let mut had = false ;
45- let updated: Vec < String > = lines
46- . into_iter ( )
54+ s. lines ( )
4755 . map ( |line| {
48- let trimmed = line. trim ( ) ;
49- if trimmed. to_uppercase ( ) . starts_with ( "SET REALMLIST " )
50- || trimmed. to_uppercase ( ) . starts_with ( "SET PORTAL " )
51- {
52- had = true ;
53- new_line. clone ( )
56+ let upper = line. trim ( ) . to_uppercase ( ) ;
57+ if upper. starts_with ( "SET REALMLIST " ) || upper. starts_with ( "SET PORTAL " ) {
58+ had_realmlist = true ;
59+ new_realmlist. clone ( )
60+ } else if upper. starts_with ( "SET ACCOUNTNAME " ) {
61+ had_account = true ;
62+ new_account. clone ( ) . unwrap_or_default ( )
5463 } else {
55- line
64+ line. to_string ( )
5665 }
5766 } )
58- . collect ( ) ;
59- ( updated, had)
67+ . collect ( )
6068 } else {
61- ( Vec :: new ( ) , false )
69+ Vec :: new ( )
6270 } ;
6371
64- let mut lines = lines;
6572 if !had_realmlist {
66- lines. push ( new_line ) ;
73+ lines. push ( new_realmlist ) ;
6774 }
75+ if !had_account {
76+ if let Some ( acct) = & new_account {
77+ lines. push ( acct. clone ( ) ) ;
78+ }
79+ }
80+
81+ lines. retain ( |l| !l. is_empty ( ) ) ;
6882
6983 std:: fs:: create_dir_all ( config_path. parent ( ) . unwrap_or ( Path :: new ( "." ) ) )
7084 . map_err ( |e| e. to_string ( ) ) ?;
0 commit comments