Skip to content

Commit

Permalink
Merge pull request #2959 from Aquanim/tourney-modoptions
Browse files Browse the repository at this point in the history
Add modoptions control to tournament page
  • Loading branch information
Licho1 authored Apr 6, 2024
2 parents c4a3660 + fa11312 commit 50cf0a7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
45 changes: 40 additions & 5 deletions Zero-K.info/Controllers/TourneyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TourneyModel
public List<int> Team1Ids { get; set; } = new List<int>();
public List<int> Team2Ids { get; set; } = new List<int>();
public string Title { get; set; }
public string ModoptString { get; set; }
}

// GET: Tourney
Expand All @@ -25,7 +26,7 @@ public ActionResult Index()
if (!Global.IsTourneyController) return DenyAccess();
var tourneyBattles = Global.Server.Battles.Values.Where(x => x != null).OfType<TourneyBattle>().ToList();

return View("TourneyIndex", new TourneyModel() {Battles = tourneyBattles});
return View("TourneyIndex", new TourneyModel() { Battles = tourneyBattles });
}

public ActionResult JoinBattle(string battleHost)
Expand Down Expand Up @@ -119,16 +120,43 @@ public ActionResult AddBattle(TourneyModel model)
model.Team2Ids.Select(x=> db.Accounts.Find(x)?.Name).Where(x=>x!=null).ToList()
}
});

string[] optionSplitters = { "," };
string[] modoptsStrings = model.ModoptString.Split(optionSplitters, System.StringSplitOptions.RemoveEmptyEntries);
foreach (var modStr in modoptsStrings)
{
bool validSetting = true;
string[] modComponent = modStr.Split('=');
if (modComponent.Length == 2)
{
tb.ModOptions.Add(modComponent[0], modComponent[1]);
}
}
Global.Server.AddBattle(tb);
}
return RedirectToAction("Index");
}

public ActionResult AddMultipleBattles(string battleList)
public ActionResult AddMultipleBattles(string battleList, string modoptStringMult)
{
if (!Global.IsTourneyController) return DenyAccess();
var db = new ZkDataContext();

// parse modoptions
Dictionary<string, string> modopts = new Dictionary<string, string>();
string[] optionSplitters = { "," };
string[] modoptsStrings = modoptStringMult.Split(optionSplitters, System.StringSplitOptions.RemoveEmptyEntries);
foreach (var modStr in modoptsStrings)
{
bool validSetting = true;
string[] modComponent = modStr.Split('=');
if (modComponent.Length == 2)
{
modopts.Add(modComponent[0], modComponent[1]);
}
}

// parse and creatge battles
string[] splitters = { "//" };
string[] battleSpecs = battleList.Split(splitters, System.StringSplitOptions.RemoveEmptyEntries);

Expand Down Expand Up @@ -182,6 +210,12 @@ public ActionResult AddMultipleBattles(string battleList)
team2Ids.Select(x=> db.Accounts.Find(x)?.Name).Where(x=>x!=null).ToList()
}
});

foreach (KeyValuePair<string, string> kvp in modopts)
{
tb.ModOptions.Add(kvp.Key, kvp.Value);
}

Global.Server.AddBattle(tb);
}
}
Expand All @@ -200,7 +234,7 @@ public ActionResult GetReplayList()
string line = string.Format("");
foreach (var team in tBat.Prototype.TeamPlayers)
{
foreach(var p in team)
foreach (var p in team)
{
line += "@U" + Account.AccountByName(db, p).AccountID + ", ";
}
Expand All @@ -214,11 +248,12 @@ public ActionResult GetReplayList()
foreach (var deb in tBat.Debriefings)
{
var bat = db.SpringBattles.FirstOrDefault(x => x.SpringBattleID == deb.ServerBattleID);
if (bat != null) {
if (bat != null)
{
batCount++;
line += "@B" + deb.ServerBattleID + ", ";
}

}
line = line.Remove(line.Length - 2);
if (batCount > 0)
Expand Down
15 changes: 14 additions & 1 deletion Zero-K.info/Views/Tourney/TourneyIndex.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@
<br />
<span>Mass create rooms:</span>
<form action="@Url.Action("AddMultipleBattles")" method="post">
@Html.TextBox("battleList", "TitleA,Player1,Player2//TitleB,Player1A,Player1B,Player2A,Player2B//...", new { style = "width:750px" })<br />
<table>
<tr>
<td>Room definition</td>
<td>@Html.TextBox("battleList", "TitleA,Player1,Player2//TitleB,Player1A,Player1B,Player2A,Player2B//...", new { style = "width:650px" }) </td>
</tr>
<tr>
<td>Modoptions</td>
<td>@Html.TextBox("modoptStringMult", "", new { style = "width:650px" }) </td>
</tr>
</table>
<input type="submit" value="Create Battles" class="js_confirm" />
</form>
<br />
Expand Down Expand Up @@ -103,6 +112,10 @@
@Html.MultiSelectFor(x => x.Team2Ids, Url.Action("UsersNoLink", "Autocomplete"), x => Html.PrintAccount(db.Accounts.Find(x)))
</td>
</tr>
<tr>
<td>Modoptions</td>
<td>@Html.TextBoxFor(x => x.ModoptString)</td>
</tr>
<tr><td colspan="2"><input type="submit" /></td></tr>
</table>

Expand Down

0 comments on commit 50cf0a7

Please sign in to comment.