11using System ;
22using System . Text ;
3- using System . Windows ;
43using System . Threading . Tasks ;
5- using Spedit . Interop ;
4+ using System . Windows ;
65using QueryMaster ;
76
87namespace Spedit . UI
@@ -11,98 +10,87 @@ public partial class MainWindow
1110 {
1211 private void Server_Query ( )
1312 {
14- Config c = Program . Configs [ Program . SelectedConfig ] ;
15- if ( string . IsNullOrWhiteSpace ( c . RConIP ) || string . IsNullOrWhiteSpace ( c . RConCommands ) )
16- { return ; }
17- StringBuilder stringOutput = new StringBuilder ( ) ;
13+ var c = Program . Configs [ Program . SelectedConfig ] ;
14+ if ( string . IsNullOrWhiteSpace ( c . RConIP ) || string . IsNullOrWhiteSpace ( c . RConCommands ) ) return ;
15+ var stringOutput = new StringBuilder ( ) ;
1816 try
1917 {
20- EngineType type = EngineType . GoldSource ;
21- if ( c . RConUseSourceEngine )
22- {
23- type = EngineType . Source ;
24- }
25- using ( Server server = ServerQuery . GetServerInstance ( type , c . RConIP , c . RConPort , null ) )
18+ var type = EngineType . GoldSource ;
19+ if ( c . RConUseSourceEngine ) type = EngineType . Source ;
20+ using ( var server = ServerQuery . GetServerInstance ( type , c . RConIP , c . RConPort , null ) )
2621 {
2722 var serverInfo = server . GetInfo ( ) ;
2823 stringOutput . AppendLine ( serverInfo . Name ) ;
2924 using ( var rcon = server . GetControl ( c . RConPassword ) )
3025 {
31- string [ ] cmds = ReplaceRconCMDVariables ( c . RConCommands ) . Split ( '\n ' ) ;
26+ var cmds = ReplaceRconCMDVariables ( c . RConCommands ) . Split ( '\n ' ) ;
3227 foreach ( var cmd in cmds )
3328 {
34- Task t = Task . Run ( ( ) =>
29+ var t = Task . Run ( ( ) =>
3530 {
36- string command = ( cmd . Trim ( '\r ' ) ) . Trim ( ) ;
31+ var command = cmd . Trim ( '\r ' ) . Trim ( ) ;
3732 if ( ! string . IsNullOrWhiteSpace ( command ) )
38- {
3933 stringOutput . AppendLine ( rcon . SendCommand ( command ) ) ;
40- }
4134 } ) ;
4235 t . Wait ( ) ;
4336 }
4437 }
4538 }
39+
4640 stringOutput . AppendLine ( "Done" ) ;
4741 }
4842 catch ( Exception e )
4943 {
5044 stringOutput . AppendLine ( "Error: " + e . Message ) ;
5145 }
52- CompileOutput . Text = stringOutput . ToString ( ) ;
53- if ( CompileOutputRow . Height . Value < 11.0 )
46+
47+ Dispatcher . Invoke ( ( ) =>
5448 {
55- CompileOutputRow . Height = new GridLength ( 200.0 ) ;
56- }
49+ CompileOutput . Text = stringOutput . ToString ( ) ;
50+ if ( CompileOutputRow . Height . Value < 11.0 ) CompileOutputRow . Height = new GridLength ( 200.0 ) ;
51+ } ) ;
5752 }
5853
5954 private string ReplaceRconCMDVariables ( string input )
6055 {
61- if ( compiledFileNames . Count < 1 )
62- { return input ; }
56+ if ( compiledFileNames . Count < 1 ) return input ;
6357 if ( input . IndexOf ( "{plugins_reload}" , StringComparison . Ordinal ) >= 0 )
6458 {
65- StringBuilder replacement = new StringBuilder ( ) ;
59+ var replacement = new StringBuilder ( ) ;
6660 replacement . AppendLine ( ) ;
6761 foreach ( var fileName in compiledFileNames )
68- {
6962 replacement . Append ( "sm plugins reload " + StripSMXPostFix ( fileName ) + ";" ) ;
70- }
7163 replacement . AppendLine ( ) ;
7264 input = input . Replace ( "{plugins_reload}" , replacement . ToString ( ) ) ;
7365 }
66+
7467 if ( input . IndexOf ( "{plugins_load}" , StringComparison . Ordinal ) >= 0 )
7568 {
76- StringBuilder replacement = new StringBuilder ( ) ;
69+ var replacement = new StringBuilder ( ) ;
7770 replacement . AppendLine ( ) ;
7871 foreach ( var fileName in compiledFileNames )
79- {
8072 replacement . Append ( "sm plugins load " + StripSMXPostFix ( fileName ) + ";" ) ;
81- }
8273 replacement . AppendLine ( ) ;
8374 input = input . Replace ( "{plugins_load}" , replacement . ToString ( ) ) ;
8475 }
76+
8577 if ( input . IndexOf ( "{plugins_unload}" , StringComparison . Ordinal ) >= 0 )
8678 {
87- StringBuilder replacement = new StringBuilder ( ) ;
79+ var replacement = new StringBuilder ( ) ;
8880 replacement . AppendLine ( ) ;
8981 foreach ( var fileName in compiledFileNames )
90- {
9182 replacement . Append ( "sm plugins unload " + StripSMXPostFix ( fileName ) + ";" ) ;
92- }
9383 replacement . AppendLine ( ) ;
9484 input = input . Replace ( "{plugins_unload}" , replacement . ToString ( ) ) ;
9585 }
86+
9687 return input ;
9788 }
9889
9990 private string StripSMXPostFix ( string fileName )
10091 {
101- if ( fileName . EndsWith ( ".smx" ) )
102- {
103- return fileName . Substring ( 0 , fileName . Length - 4 ) ;
104- }
92+ if ( fileName . EndsWith ( ".smx" ) ) return fileName . Substring ( 0 , fileName . Length - 4 ) ;
10593 return fileName ;
10694 }
10795 }
108- }
96+ }
0 commit comments