Skip to content

Commit a7d9d18

Browse files
committed
Upgrades to Console - SteamCMD "Wrap" & Read.
1 parent 9d525ab commit a7d9d18

File tree

11 files changed

+409
-58
lines changed

11 files changed

+409
-58
lines changed

Steam Server Creation Tool V2/Comments.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ start "" D:\Forest\steamapps\common\TheForestDedicatedServer\TheForestDedicatedS
44

55
exit
66

7-
Improvements to StartServerScript eventually
7+
Improvements to StartServerScript eventually
8+
9+
// These seems to require login and that you own the game.
10+
[19-11-2023 21:59] ERROR! Failed to install app '2218990' (No subscription)
11+
[19-11-2023 22:00] ERROR! Failed to install app '1769020' (No subscription)
12+

Steam Server Creation Tool V2/Core/Core.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static class Core
3636
public static BuildTypes buildType = BuildTypes.Alpha;
3737
public static int majorVersion = 0;
3838
public static int minorVersion = 0;
39-
public static int buildVersion = 3;
39+
public static int buildVersion = 4;
4040

4141
private static bool checkingUpdate = false;
4242
public static bool updateAvailable = false;

Steam Server Creation Tool V2/DataContainers/Settings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ public class Settings
1313
public UserData userData;
1414
public bool useAnonymousAuth = true; // Use anonymous user.
1515

16-
// Steam parameters
16+
// Software/Steam parameters
1717
public bool CheckUpdates = true;
1818
public bool autoClose = true;
1919
public bool validate = true;
2020
public bool allowAutoUpdate = false; // False positive as of right now. Disabled.
21+
public bool wrapSteamCMD = true; // False positive as of right now. Disabled.
22+
public bool SupressNoneError = false; // False positive as of right now. Disabled.
2123

2224
// SteamCMD install directory
2325
public string steamCMD_installLocation = "";
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Steam_Server_Creation_Tool_V2
5+
{
6+
/// <summary>
7+
/// Class to store information between sessions
8+
/// </summary>
9+
[Serializable]
10+
public class Settings
11+
{
12+
// User data / Settings
13+
public UserData userData;
14+
public bool useAnonymousAuth = true; // Use anonymous user.
15+
16+
// Software/Steam parameters
17+
public bool CheckUpdates = true;
18+
public bool autoClose = true;
19+
public bool validate = true;
20+
public bool allowAutoUpdate = false; // False positive as of right now. Disabled.
21+
public bool wrapSteamCMD = true; // False positive as of right now. Disabled.
22+
public bool SupressNoneError = false; // False positive as of right now. Disabled.
23+
24+
// SteamCMD install directory
25+
public string steamCMD_installLocation = "";
26+
27+
// Server data
28+
public List<InstalledServer> installedServer = new List<InstalledServer>();
29+
30+
/// <summary>
31+
/// Get login information as string to use as parameters in SteamCMD client.
32+
/// </summary>
33+
/// <returns></returns>
34+
public string GetLogin()
35+
{
36+
if (useAnonymousAuth) return "anonymous";
37+
else if (!useAnonymousAuth && !userData.IsEmpty()) return userData.Username + " " + userData.GetPassword();
38+
else return null;
39+
}
40+
}
41+
}

Steam Server Creation Tool V2/Forms/MainForm.Designer.cs

Lines changed: 162 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Steam Server Creation Tool V2/Forms/MainForm.cs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
using System.Threading.Tasks;
1010
using System.Windows.Forms;
1111

12+
// TODO: Check possible servers to exclude
13+
1214
namespace Steam_Server_Creation_Tool_V2
1315
{
1416
public partial class MainForm : Form
1517
{
1618
// Settings data - Servers, User auth etc
1719
public Settings settings = null;
1820

21+
// Console feature
22+
public ConsoleHandler console = null;
23+
1924
// Steam API data
2025
public SteamAppListResponse SteamList = null;
2126

@@ -44,8 +49,6 @@ public MainForm()
4449

4550
//We do not await this async command
4651
InitializeAsyncStart();
47-
48-
4952
}
5053

5154
/// <summary>
@@ -104,6 +107,8 @@ private async Task InitializeAsyncStart()
104107

105108
ApplyLoadedSettings();
106109

110+
console = new ConsoleHandler(this);
111+
107112
//Check for updates
108113
if (settings.CheckUpdates)
109114
{
@@ -127,6 +132,7 @@ private void ApplyLoadedSettings()
127132
AutoClose_Checkbox.Checked = settings.autoClose;
128133
CheckForUpdates_Checkbox.Checked = settings.CheckUpdates;
129134
AllowUpdater_Checkbox.Checked = settings.allowAutoUpdate;
135+
WrapSteamCMD_Checkbox.Checked = settings.wrapSteamCMD;
130136

131137
if (settings.useAnonymousAuth)
132138
{
@@ -349,6 +355,8 @@ public async Task RefreshAPIData()
349355
SteamCMD_Button.Enabled = false;
350356
NewServer_Button.Enabled = false;
351357
ManageServers_Button.Enabled = false;
358+
PortScan_Button.Enabled = false;
359+
PanelConsole_button.Enabled = false;
352360
SettingsButton.Enabled = false;
353361

354362
//RefreshAPI_Button
@@ -367,6 +375,8 @@ public async Task RefreshAPIData()
367375
SteamCMD_Button.Enabled = true;
368376
NewServer_Button.Enabled = true;
369377
ManageServers_Button.Enabled = true;
378+
PortScan_Button.Enabled = true;
379+
PanelConsole_button.Enabled = true;
370380
SettingsButton.Enabled = true;
371381

372382
NewInstall_Dropbox.SelectedIndex = 0;
@@ -596,6 +606,7 @@ private void SaveSettings_Button_Click(object sender, EventArgs e)
596606
settings.autoClose = AutoClose_Checkbox.Checked;
597607
settings.CheckUpdates = CheckForUpdates_Checkbox.Checked;
598608
settings.allowAutoUpdate = AllowUpdater_Checkbox.Checked;
609+
settings.wrapSteamCMD = WrapSteamCMD_Checkbox.Checked;
599610

600611
settings.steamCMD_installLocation = SteamCMD_SettingsInstallLocation_Textbox.Text;
601612

@@ -943,5 +954,36 @@ private async void PortScanSend_Button_Click(object sender, EventArgs e)
943954
PortScanSend_Button.Enabled = true;
944955
PortScanSend_Button.Visible = true;
945956
}
957+
958+
private void WrapSteamCMD_Checkbox_CheckedChanged(object sender, EventArgs e) => settings.wrapSteamCMD = WrapSteamCMD_Checkbox.Checked;
959+
960+
private void PanelConsole_button_MouseEnter(object sender, EventArgs e) => UIHandler.Label_MouseHover(sender, e);
961+
962+
private void PanelConsole_button_MouseLeave(object sender, EventArgs e) => UIHandler.Label_MouseLeave(sender, e);
963+
964+
public void PanelConsole_button_Click(object sender, EventArgs e) => UIHandler.ChangePanel(UIHandler.Panel.Console, this, sender);
965+
966+
private async void ResetSettings_Button_Click(object sender, EventArgs e)
967+
{
968+
settings = null;
969+
GC.Collect();
970+
971+
settings = new Settings();
972+
Core.SaveSettings(settings);
973+
974+
MessageBox.Show("Settings reset was successful.","Reset result", MessageBoxButtons.OK, MessageBoxIcon.Information);
975+
976+
//Set default values to labels and fields
977+
ClearDefaultNSetup();
978+
979+
Console.Clear();
980+
await InitializeAsyncStart();
981+
}
982+
983+
private void Console_TextChanged(object sender, EventArgs e)
984+
{
985+
Console.SelectionStart = Console.Text.Length;
986+
Console.ScrollToCaret();
987+
}
946988
}
947989
}

Steam Server Creation Tool V2/Forms/MainForm.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@
120120
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121121
<value>17, 17</value>
122122
</metadata>
123+
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
124+
<value>17, 17</value>
125+
</metadata>
123126
<data name="WrapSteamCMD_Checkbox.ToolTip" xml:space="preserve">
124127
<value>This will start the SteamCMD process invisible to the user but it allows SSCTV2 to read information.
125128
Example: success or errors. This will result in better managment and overall, system possibilities of SSCTV2</value>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Steam_Server_Creation_Tool_V2
8+
{
9+
public class ConsoleHandler
10+
{
11+
MainForm form;
12+
13+
public ConsoleHandler(MainForm form)
14+
{
15+
this.form = form;
16+
17+
AddMessage($"{Core.softwareName} {Core.GetVersion()} has been initialized...", false);
18+
}
19+
20+
public void AddMessage(string message, bool append = true)
21+
{
22+
if(append)
23+
form.Console.AppendText($"{Environment.NewLine}[{DateTime.Now.ToString("dd-MM-yyyy HH:mm")}] {message}");
24+
else
25+
form.Console.AppendText($"[{DateTime.Now.ToString("dd-MM-yyyy HH:mm")}] {message}");
26+
}
27+
}
28+
}

Steam Server Creation Tool V2/Handlers/SteamAPI/SteamCMDHelper.cs

Lines changed: 113 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Linq;
77
using System.Text;
8+
using System.Text.RegularExpressions;
89
using System.Threading;
910
using System.Threading.Tasks;
1011
using System.Windows.Forms;
@@ -21,6 +22,8 @@ internal class SteamCMDHelper
2122
{
2223
internal static async Task StartNewDownload(MainForm form, App app, string installName, string installDir, InstallationType steamCMD_type = InstallationType.NewInstall)
2324
{
25+
if (form.settings.wrapSteamCMD) form.PanelConsole_button_Click(null, null);
26+
2427
//Keep track of success
2528
bool install = true;
2629

@@ -41,22 +44,51 @@ internal static async Task StartNewDownload(MainForm form, App app, string insta
4144
// Start a new thread with the installation as async using user input
4245
await Task.Run(() =>
4346
{
47+
Process process = CreateProcess(form.settings.wrapSteamCMD, form, installDir, login, appID, validated, quit);
48+
4449
// Initiating process
45-
using (Process process = new Process
50+
using (process)
4651
{
47-
// Setting startinfo
48-
StartInfo =
52+
53+
process.OutputDataReceived += (sender, e) =>
4954
{
50-
UseShellExecute = false,
51-
FileName = form.settings.steamCMD_installLocation,
52-
Arguments = $"+force_install_dir \"{installDir}\" +login " + login + " +app_update " + appID + " " + validated + quit // Building argument string
53-
}
54-
})
55-
{
55+
if (e.Data != null)
56+
{
57+
// Update the RichTextBox in the UI thread
58+
form.Invoke((MethodInvoker)delegate
59+
{
60+
form.console.AddMessage(e.Data + Environment.NewLine);
61+
62+
// Check for specific lines using Regex
63+
CheckForSpecificLines(e.Data, form);
64+
});
65+
}
66+
};
67+
68+
process.ErrorDataReceived += (sender, e) =>
69+
{
70+
if (e.Data != null)
71+
{
72+
// Update the RichTextBox in the UI thread
73+
form.Invoke((MethodInvoker)delegate
74+
{
75+
form.console.AddMessage($"Error: {e.Data}" + Environment.NewLine);
76+
77+
// Check for specific lines using Regex
78+
CheckForSpecificLines(e.Data, form);
79+
});
80+
}
81+
};
82+
5683
// Try starting the process
5784
try
5885
{
5986
process.Start();
87+
if(form.settings.wrapSteamCMD)
88+
{
89+
process.BeginOutputReadLine();
90+
process.BeginErrorReadLine();
91+
}
6092
}
6193
catch (Exception ex)
6294
{
@@ -79,21 +111,89 @@ await Task.Run(() =>
79111
if (install && steamCMD_type == InstallationType.NewInstall)
80112
{
81113
string startScript = Properties.Resources.StartServerScript_txt;
82-
startScript = startScript.Replace("{steamcmd_dir}", $"\"{Path.GetDirectoryName(form.settings.steamCMD_installLocation)}\"")
114+
startScript = startScript
115+
.Replace("{steamcmd_dir}", $"\"{Path.GetDirectoryName(form.settings.steamCMD_installLocation)}\"")
83116
.Replace("{server_dir}", installDir)
84-
.Replace("{app_id}", appID)
85-
.Replace("{app_name}", app.Name)
86-
.Replace("{login_cred}", form.settings.GetLogin());
117+
.Replace("{app_id}", appID)
118+
.Replace("{app_name}", app.Name)
119+
.Replace("{login_cred}", form.settings.GetLogin());
87120

88121
Core.SaveToFile(installDir + @"\StartServerScript.bat", startScript);
89122

90123
form.settings.installedServer.Add(new InstalledServer(installName, installDir, DateTime.Now.ToString("dd/MM/yyyy HH:mm"), app));
91124
Core.SaveSettings(form.settings);
92125
}
93126

127+
// Update the RichTextBox in the UI thread
128+
form.Invoke((MethodInvoker)delegate
129+
{
130+
form.console.AddMessage($"SteamCMD has completed the task!");
131+
});
132+
94133
System.Media.SystemSounds.Exclamation.Play();
95134
}
96135
});
97136
}
137+
138+
private static Process CreateProcess(bool wrapSteamCMD, MainForm form, string installDir, string login, string appID, string validated, string quit)
139+
{
140+
Process process = null;
141+
142+
if(wrapSteamCMD) {
143+
process = new Process() {
144+
StartInfo = {
145+
FileName = form.settings.steamCMD_installLocation,
146+
Arguments = $"+force_install_dir \"{installDir}\" +login " + login + " +app_update " + appID + " " + validated + quit,
147+
UseShellExecute = false,
148+
RedirectStandardInput = true,
149+
RedirectStandardOutput = true,
150+
RedirectStandardError = true,
151+
CreateNoWindow = true
152+
}
153+
};
154+
}
155+
else {
156+
process = new Process() {
157+
StartInfo = {
158+
UseShellExecute = false,
159+
FileName = form.settings.steamCMD_installLocation,
160+
Arguments = $"+force_install_dir \"{installDir}\" +login " + login + " +app_update " + appID + " " + validated + quit // Building argument string
161+
}
162+
};
163+
164+
}
165+
166+
return process;
167+
}
168+
169+
private static void CheckForSpecificLines(string line, MainForm form = null)
170+
{
171+
// Use Regex to match the patterns of the success and error messages
172+
Regex message = new Regex(@"Waiting for client config...OK");
173+
Regex successRegex = new Regex(@"Success! App '\d+' fully installed.");
174+
Regex errorRegex = new Regex(@"Error! App '\d+' state is 0x[0-9A-Fa-f]+ after update job.");
175+
176+
if (successRegex.IsMatch(line))
177+
{
178+
// Take action based on the specific line
179+
// For example, update UI or log the information
180+
181+
//Console.WriteLine($"Found success line: {line}");
182+
}
183+
else if (errorRegex.IsMatch(line))
184+
{
185+
// Take action based on the specific line
186+
// For example, update UI or log the information
187+
188+
//Console.WriteLine($"Found error line: {line}");
189+
}
190+
else if (message.IsMatch(line))
191+
{
192+
// Take action based on the specific line
193+
// For example, update UI or log the information
194+
195+
form.console.AddMessage($"Please wait while SteamCMD is installing the server...{Environment.NewLine}");
196+
}
197+
}
98198
}
99199
}

0 commit comments

Comments
 (0)