Skip to content

Commit

Permalink
Add support for cs2
Browse files Browse the repository at this point in the history
  • Loading branch information
ijre committed Oct 13, 2023
1 parent 5e774b7 commit f124719
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/GAMES.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
232250 tf Team Fortress 2
740 csgo Counter-Strike: Global Offensive
730 csgo Counter-Strike 2
// Due to current (13/10/2023 EU format) limitations, to host a cs2 server you must have an entirely separate install of cs2
// thus requiring using 730 (game appid) instead of 740 (dedicated server appid)
232330 cstrike Counter-Strike: Source
222860 left4dead2 Left 4 Dead 2
21 changes: 15 additions & 6 deletions src/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ private void RunServerButton_Click(object sender, EventArgs e)
buttonParams += "-dev ";
}

string addDedicatedIfCS2 = ServerPath.Text.EndsWith("\\game") && GameInfo[GameListRunTab.SelectedIndex][0] == "730" ? "-dedicated" : "";

string arguments =
$"-console -game {GameInfo[GameListRunTab.SelectedIndex][1]} -port {UDPPort.Text} +hostname \"{Hostname.Text}\" " +
$"-console ${addDedicatedIfCS2} -game {GameInfo[GameListRunTab.SelectedIndex][1]} -port {UDPPort.Text} +hostname \"{Hostname.Text}\" " +
$"+map {MapList.SelectedItem} +maxplayers {MaxPlayers.Text} +sv_lan {NetworkType.SelectedIndex} " +
$"+rcon_password {Rcon.Text} +sv_password {PasswordServer.Text} " +
$"{buttonParams} {AdditionalCommands.Text}";
Expand All @@ -250,13 +252,20 @@ private void RunServerButton_Click(object sender, EventArgs e)
private int lastCount;
private void MapList_EnterOrLeave(object sender, EventArgs e)
{
string root = GameInfo[GameListRunTab.SelectedIndex][1];

List<string> maps;

try
{
maps = Directory.GetFiles($"{SrcdsPath.Text.Substring(0, SrcdsPath.Text.LastIndexOf("\\"))}\\{root}\\maps").ToList();
string root = GameInfo[GameListRunTab.SelectedIndex][1];

if (ServerPath.Text.EndsWith("\\game") && GameInfo[GameListRunTab.SelectedIndex][0] == "730")
{
maps = Directory.GetFiles($"{ServerPath.Text.Substring(0, ServerPath.Text.LastIndexOf("\\"))}\\{root}\\maps").ToList();
}
else
{
maps = Directory.GetFiles($"{SrcdsPath.Text.Substring(0, SrcdsPath.Text.LastIndexOf("\\"))}\\{root}\\maps").ToList();
}
}
catch (DirectoryNotFoundException)
{
Expand Down Expand Up @@ -436,7 +445,7 @@ private void SteamCMDPathBrowse_Click(object sender, EventArgs e)

private void ServerPathBrowse_Click(object sender, EventArgs e)
{
string folder = GetFolder("Select the root of your server");
string folder = GetFolder("Select the root of your server (for cs2, you must select the \"game\" folder)");

if (string.IsNullOrWhiteSpace(folder))
return;
Expand All @@ -447,7 +456,7 @@ private void ServerPathBrowse_Click(object sender, EventArgs e)

private void SrcdsPathBrowse_Click(object sender, EventArgs e)
{
string file = GetFile("Select the srcds.exe file", "srcds.exe");
string file = GetFile("Select the srcds.exe file (for cs2, you must select the cs2.exe in \"game/bin/win64\")", "srcds.exe;cs2.exe");

if (string.IsNullOrWhiteSpace(file))
return;
Expand Down

0 comments on commit f124719

Please sign in to comment.