Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit fd71b86

Browse files
committed
introduce new ValveQuery.dll and command sending remake
1 parent 0e55c67 commit fd71b86

File tree

13 files changed

+92
-34
lines changed

13 files changed

+92
-34
lines changed

Interop/LoggingControl.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ public static class LoggingControl
88
public static TextBox LogBox;
99
public static void LogAction(string message, int newLines = 1)
1010
{
11-
LogBox.Text += $"[{DateTime.Now:HH:mm:ss}] {message} {new string('\n', newLines)}";
12-
LogBox.CaretIndex = LogBox.Text.Length;
13-
LogBox.ScrollToEnd();
11+
try
12+
{
13+
LogBox.Text += $"[{DateTime.Now:HH:mm:ss}] {message} {new string('\n', newLines)}";
14+
LogBox.CaretIndex = LogBox.Text.Length;
15+
LogBox.ScrollToEnd();
16+
}
17+
catch (Exception)
18+
{
19+
20+
}
1421
}
1522
}

Interop/TranslationProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ private void FillToEnglishDefaults()
296296
language.Add("OBTextConfig", "Config Directory");
297297
language.Add("CopyingFiles", "Copying files");
298298
language.Add("FTPUploading", "Uploading files");
299-
language.Add("RCONCommand", "Seconding RCON Commands");
299+
language.Add("RCONCommand", "Sending RCON Commands");
300300
language.Add("JavaInstallCheck", "Checking for Java installation");
301301
language.Add("JavaNotFoundTitle", "Java was not found");
302302
language.Add("JavaNotFoundMessage",

QueryMaster/Ionic.BZip2.dll

-56 KB
Binary file not shown.

QueryMaster/QueryMaster.dll

-70 KB
Binary file not shown.

Spcode.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<Reference Include="System.Xml.Linq" />
9090
<Reference Include="UIAutomationProvider" />
9191
<Reference Include="ValveQuery">
92-
<HintPath>QueryMaster\ValveQuery.dll</HintPath>
92+
<HintPath>ValveQuery\ValveQuery.dll</HintPath>
9393
</Reference>
9494
<Reference Include="WindowsBase" />
9595
<Reference Include="WindowsFormsIntegration" />

UI/MainWindow/MainWindowSPCompiler.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public partial class MainWindow
2626
private bool InCompiling;
2727
private Thread ServerCheckThread;
2828

29+
private ProgressDialogController ProgressTask;
30+
2931
private bool ServerIsRunning;
3032
private Process ServerProcess;
3133

@@ -123,9 +125,9 @@ await this.ShowMessageAsync(Program.Translations.GetLanguage("Error"),
123125
{
124126
// Shows the 'Compiling...' window
125127
ErrorResultGrid.Items.Clear();
126-
var progressTask = await this.ShowProgressAsync(Program.Translations.GetLanguage("Compiling"), "",
128+
ProgressTask = await this.ShowProgressAsync(Program.Translations.GetLanguage("Compiling"), "",
127129
false, MetroDialogOptions);
128-
progressTask.SetProgress(0.0);
130+
ProgressTask.SetProgress(0.0);
129131
var stringOutput = new StringBuilder();
130132
var errorFilterRegex =
131133
new Regex(Constants.ErrorFilterRegex,
@@ -143,7 +145,7 @@ await this.ShowMessageAsync(Program.Translations.GetLanguage("Error"),
143145
}
144146

145147
var file = ScriptsCompiled[i];
146-
progressTask.SetMessage($"{file} ({i}/{compileCount}) ");
148+
ProgressTask.SetMessage($"{file} ({i}/{compileCount}) ");
147149
ProcessUITasks();
148150
var fileInfo = new FileInfo(file);
149151
if (fileInfo.Exists)
@@ -180,7 +182,7 @@ await this.ShowMessageAsync(Program.Translations.GetLanguage("Error"),
180182
process.StartInfo.Arguments =
181183
"\"" + fileInfo.FullName + "\" -o=\"" + outFile + "\" -e=\"" + errorFile + "\"" +
182184
includeStr + " -O=" + currentConfig.OptimizeLevel + " -v=" + currentConfig.VerboseLevel;
183-
progressTask.SetProgress((i + 1 - 0.5d) / compileCount);
185+
ProgressTask.SetProgress((i + 1 - 0.5d) / compileCount);
184186
var execResult = ExecuteCommandLine(currentConfig.PreCmd, fileInfo.DirectoryName, currentConfig.CopyDirectory,
185187
fileInfo.FullName, fileInfo.Name, outFile, destinationFileName);
186188
if (!string.IsNullOrWhiteSpace(execResult))
@@ -197,7 +199,7 @@ await this.ShowMessageAsync(Program.Translations.GetLanguage("Error"),
197199

198200
if (process.ExitCode != 1 && process.ExitCode != 0)
199201
{
200-
await progressTask.CloseAsync();
202+
await ProgressTask.CloseAsync();
201203
await this.ShowMessageAsync(Program.Translations.GetLanguage("Error"),
202204
"The SourcePawn compiler has crashed.\n" +
203205
"Try again, or file an issue at the SourcePawn GitHub repository describing your steps that lead to this instance in detail.\n" +
@@ -210,7 +212,7 @@ await this.ShowMessageAsync(Program.Translations.GetLanguage("Error"),
210212
}
211213
catch (Exception)
212214
{
213-
await progressTask.CloseAsync();
215+
await ProgressTask.CloseAsync();
214216
await this.ShowMessageAsync(Program.Translations.GetLanguage("SPCompNotStarted"),
215217
Program.Translations.GetLanguage("Error"), MessageDialogStyle.Affirmative,
216218
MetroDialogOptions);
@@ -270,7 +272,7 @@ await this.ShowMessageAsync(Program.Translations.GetLanguage("SPCompNotStarted")
270272

271273
}
272274

273-
progressTask.SetProgress((double)(i + 1) / compileCount);
275+
ProgressTask.SetProgress((double)(i + 1) / compileCount);
274276
ProcessUITasks();
275277
}
276278
}
@@ -282,29 +284,29 @@ await this.ShowMessageAsync(Program.Translations.GetLanguage("SPCompNotStarted")
282284

283285
if (!PressedEscape)
284286
{
285-
progressTask.SetProgress(1.0);
287+
ProgressTask.SetProgress(1.0);
286288
if (currentConfig.AutoCopy)
287289
{
288-
progressTask.SetTitle(Program.Translations.GetLanguage("CopyingFiles"));
289-
progressTask.SetIndeterminate();
290+
ProgressTask.SetTitle(Program.Translations.GetLanguage("CopyingFiles") + "...");
291+
ProgressTask.SetIndeterminate();
290292
await Task.Run(() => Copy_Plugins());
291-
progressTask.SetProgress(1.0);
293+
ProgressTask.SetProgress(1.0);
292294
}
293295

294296
if (currentConfig.AutoUpload)
295297
{
296-
progressTask.SetTitle(Program.Translations.GetLanguage("FTPUploading"));
297-
progressTask.SetIndeterminate();
298+
ProgressTask.SetTitle(Program.Translations.GetLanguage("FTPUploading") + "...");
299+
ProgressTask.SetIndeterminate();
298300
await Task.Run(FTPUpload_Plugins);
299-
progressTask.SetProgress(1.0);
301+
ProgressTask.SetProgress(1.0);
300302
}
301303

302304
if (currentConfig.AutoRCON)
303305
{
304-
progressTask.SetTitle(Program.Translations.GetLanguage("RCONCommand"));
305-
progressTask.SetIndeterminate();
306+
ProgressTask.SetTitle(Program.Translations.GetLanguage("RCONCommand") + "...");
307+
ProgressTask.SetIndeterminate();
306308
await Task.Run(Server_Query);
307-
progressTask.SetProgress(1.0);
309+
ProgressTask.SetProgress(1.0);
308310
}
309311

310312
if (CompileOutputRow.Height.Value < 11.0)
@@ -313,7 +315,7 @@ await this.ShowMessageAsync(Program.Translations.GetLanguage("SPCompNotStarted")
313315
}
314316
}
315317

316-
await progressTask.CloseAsync();
318+
await ProgressTask.CloseAsync();
317319
}
318320
InCompiling = false;
319321
}

UI/MainWindow/MainWindowServerQuery.cs

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
using System.Windows;
66
using ValveQuery.GameServer;
77
using SPCode.Interop;
8+
using System.Net.Sockets;
9+
using System.Linq;
10+
using MahApps.Metro.Controls.Dialogs;
811

912
namespace SPCode.UI;
1013

@@ -13,9 +16,25 @@ public partial class MainWindow
1316
/// <summary>
1417
/// Queries the server with the specified command in the command box of the config.
1518
/// </summary>
16-
private void Server_Query()
19+
20+
private ServerInfo ServerInfoGlobal;
21+
22+
private async void Server_Query()
1723
{
24+
if (ProgressTask == null)
25+
{
26+
ProgressTask = await this.ShowProgressAsync(Program.Translations.GetLanguage("RCONCommand") + "...", "", false, MetroDialogOptions);
27+
ProgressTask.SetIndeterminate();
28+
}
29+
1830
var output = new List<string>();
31+
32+
if (!ServerIsRunning)
33+
{
34+
output.Add("No server running to send commands to.");
35+
goto Dispatcher;
36+
}
37+
1938
var c = Program.Configs[Program.SelectedConfig];
2039
if (string.IsNullOrWhiteSpace(c.RConIP) || string.IsNullOrWhiteSpace(c.RConCommands))
2140
{
@@ -25,7 +44,7 @@ private void Server_Query()
2544

2645
try
2746
{
28-
using var server = ServerQuery.GetServerInstance(c.RConIP, c.RConPort, throwExceptions: true);
47+
using var server = ServerQuery.GetServerInstance(c.RConIP, c.RConPort, false, 500, 500, 2, true);
2948
var serverInfo = server.GetInfo();
3049

3150
if (serverInfo == null)
@@ -34,35 +53,59 @@ private void Server_Query()
3453
goto Dispatcher;
3554
}
3655

37-
output.Add(serverInfo.Name);
56+
ServerInfoGlobal = serverInfo;
3857

39-
if (!server.GetControl(c.RConPassword, false))
40-
{
41-
output.Add("Incorrect RCON password.");
42-
goto Dispatcher;
43-
}
58+
server.GetControl(c.RConPassword, false);
4459

60+
output.Add($"Server: {serverInfo.Name}");
4561
output.Add("Sending commands...");
4662

4763
var cmds = ReplaceRconCMDVariables(c.RConCommands).Split('\n');
4864

65+
if (cmds.Any(x => x.Contains("{plugin")))
66+
{
67+
output.Add("No plugins available to replace placeholders commands with. Removing them...");
68+
cmds = cmds.Where(x => !x.Contains("{plugin")).ToArray();
69+
}
70+
4971
foreach (var cmd in cmds)
5072
{
5173
var t = Task.Run(() =>
5274
{
5375
var command = cmd.Trim('\r').Trim();
5476
if (!string.IsNullOrWhiteSpace(command))
5577
{
56-
server.Rcon.SendCommand(command);
78+
output.Add(server.Rcon.SendCommand(command));
5779
}
5880
});
5981
t.Wait();
6082
}
6183
output.Add("Commands sent.");
6284
}
63-
catch (Exception e)
85+
catch (Exception ex)
6486
{
65-
output.Add("Error: " + e.Message);
87+
if (ex.Message.Contains("Not authorized"))
88+
{
89+
output.Add("Incorrect RCON password.");
90+
goto Dispatcher;
91+
}
92+
if (ex is SocketException socketEx)
93+
{
94+
switch ((SocketError)socketEx.ErrorCode)
95+
{
96+
case SocketError.ConnectionReset:
97+
output.Add("The connection was reset. You were probably IP banned for rcon hacking attempts.");
98+
goto Dispatcher;
99+
case SocketError.NotConnected:
100+
case SocketError.TimedOut:
101+
output.Add("Connection to the server timed out. Make sure you've set it up correctly.\n" +
102+
"Your data:\n" +
103+
$" - IP: { c.RConIP}\n" +
104+
$" - Port: {c.RConPort}");
105+
goto Dispatcher;
106+
}
107+
}
108+
output.Add($"SPCode unhandled error: {ex.Message}");
66109
}
67110

68111
Dispatcher:
@@ -75,6 +118,12 @@ private void Server_Query()
75118
CompileOutputRow.Height = new GridLength(200.0);
76119
}
77120
});
121+
122+
if (ProgressTask.IsOpen)
123+
{
124+
await ProgressTask.CloseAsync();
125+
ProgressTask = null;
126+
}
78127
}
79128

80129
/// <summary>

0 commit comments

Comments
 (0)