Skip to content

Commit

Permalink
- support for TOXIKK 1.1.8 official/ranked/modded status fields
Browse files Browse the repository at this point in the history
- support for user friendly role names (mapped through game extensions)
  • Loading branch information
PredatH0r committed Jul 23, 2017
1 parent 30a6031 commit 497df44
Show file tree
Hide file tree
Showing 6 changed files with 4,118 additions and 4,004 deletions.
2 changes: 2 additions & 0 deletions ServerBrowser/Games/GameExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ public virtual void Rcon(ServerRow row, int port, string password, string comman
public virtual bool IsValidPlayer(ServerRow row, Player player) => true;

public virtual string GetServerCellToolTip(ServerRow row, string fieldName) => null;

public virtual string GetPrettyNameForRule(ServerRow row, string ruleName) => ruleName;
}
#endregion

Expand Down
86 changes: 82 additions & 4 deletions ServerBrowser/Games/Toxikk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class Toxikk : GameExtension
private const string ScoreLimit = "p268435704";
private const string TimeLimit = "p268435705";
private const string Mutators = "p1073741828";
private const string IsOfficial = "s15";
private const string OldOfficialNewRanked = "s15";
private const string NewOfficial = "s18";
private const string ModdingLevel = "s19";
private const string GameVersion = "p1073741839";

private const int SecondsToWaitForMainWindowAfterLaunch = 45;
Expand Down Expand Up @@ -110,7 +112,9 @@ public override void CustomizeServerGridColumns(GridView view)
AddColumn(view, "_best", "Best", "Best player's Skill Class", 40, ++idx, UnboundColumnType.Integer);
AddColumn(view, ScoreLimit, "GS", "Goal Score", 30, ++idx, UnboundColumnType.Integer);
AddColumn(view, TimeLimit, "TL", "Time Limit", 30, ++idx, UnboundColumnType.Integer);
AddColumn(view, IsOfficial, "Ofcl", "Official Server managed by REAKKTOR", 35, ++idx, UnboundColumnType.Boolean);
AddColumn(view, NewOfficial, "Ofcl", "Official Server managed by REAKKTOR", 35, ++idx, UnboundColumnType.Boolean);
AddColumn(view, OldOfficialNewRanked, "Ranked", "MXP/SC saved", 35, ++idx, UnboundColumnType.Boolean);
AddColumn(view, ModdingLevel, "Modded", "unmodded, server-only, server+client", 35, ++idx, UnboundColumnType.String);
AddColumn(view, GameVersion, "Ver", "Game Version", 40);
}
#endregion
Expand All @@ -125,8 +129,24 @@ public override object GetServerCellValue(ServerRow row, string fieldName)
//return new ToxikkSkillInfo(row, this);
case "_best":
return Math.Round(this.GetBestPlayerSC(row), 1, MidpointRounding.AwayFromZero);
case IsOfficial:
return row.GetRule(fieldName) == "1";
case NewOfficial:
{
var ver = row.GetRule(GameVersion);
if (ver != null && CompareVersion(ver, "1.1.71") > 0)
return row.GetRule(NewOfficial) == "1";
return row.GetRule(OldOfficialNewRanked) == "1";
}
case OldOfficialNewRanked:
{
var ver = row.GetRule(GameVersion);
if (ver == null || CompareVersion(ver, "1.1.71") <= 0)
return null;
var val = row.GetRule(fieldName);
return val == null ? (object)null : val == "1";
}
case ModdingLevel:
var level = row.GetRule(ModdingLevel);
return level == "0" ? "-" : level == "1" ? "S" : level == "2" ? "S+C" : "";
case "_gametype":
{
var gt = row.ServerInfo.Extra.Keywords;
Expand Down Expand Up @@ -164,6 +184,30 @@ public override object GetServerCellValue(ServerRow row, string fieldName)
}
#endregion

#region CompareVersion()
/// <summary>
/// Compares 2 version strings in the form of a.b.c
/// a and b are compared numerically, c alphanumerical so that .8 > .71
/// </summary>
public static int CompareVersion(string v1, string v2)
{
var p1 = v1.Split('.');
var p2 = v2.Split('.');
for (int i = 0; i < p1.Length; i++)
{
if (i > p2.Length)
return +1;
int c;
c = i <= 1 ? Comparer<int>.Default.Compare(int.Parse(p1[i]), int.Parse(p2[i])) : StringComparer.InvariantCulture.Compare(p1[i], p2[i]);
if (c != 0)
return c;
}
if (p2.Length > p1.Length)
return -1;
return 0;
}
#endregion

#region GetServerCellToolTip()
public override string GetServerCellToolTip(ServerRow row, string fieldName)
{
Expand Down Expand Up @@ -531,6 +575,40 @@ private void UpdatePlayerInfos(ServerRow server)
server.PlayerCount.Update();
}
#endregion

#region GetPrettyNameForRule()
public override string GetPrettyNameForRule(ServerRow row, string ruleName)
{
switch (ruleName)
{
case MinCombatants: return "min. Combatants";
case ScoreLimit: return "Score Limit";
case TimeLimit: return "Time Limit";
case Mutators: return "Mutators";
case GameVersion: return "GameVersion";
case OldOfficialNewRanked: return "Ranked (pre-1.1.8: Official)";
case NewOfficial: return "Official (since 1.1.8)";
case ModdingLevel: return "Modding level";
case ToxikkSkillInfo.MinSkillClass: return "Min SC";
case ToxikkSkillInfo.MaxSkillClass: return "Max SC";
case "p1073741825": return "Map";
case "p1073741826": return "Gametype Class";
case "p1073741827": return "Server Description";
case "p1073741829": return "Player IDs #1";
case "p1073741830": return "Player IDs #2";
case "p1073741831": return "Player IDs #3";
case "p1073741832": return "Player names #1";
case "p1073741833": return "Player names #2";
case "p1073741834": return "Player names #3";
case "p1073741837": return "Player SCs";
case "p1073741838": return "Player ranks";
case "s0": return "Bot difficulty";
case "p268435706": return "Max. players";
case "p1073741840": return "Map list";
}
return null;
}
#endregion
}

#region class ToxikkPlayerInfo
Expand Down
78 changes: 40 additions & 38 deletions ServerBrowser/ServerBrowserForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion ServerBrowser/ServerBrowserForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace ServerBrowser
{
public partial class ServerBrowserForm : XtraForm
{
private const string Version = "2.45.2";
private const string Version = "2.47";
private const string DevExpressVersion = "v15.2";
private const string SteamWebApiText = "<Steam Web API>";
private const string CustomDetailColumnPrefix = "ServerInfo.";
Expand Down Expand Up @@ -1920,6 +1920,18 @@ private void toolTipController_GetActiveObjectInfo(object sender, ToolTipControl
e.Info = new ToolTipControlInfo(row.EndPoint + "-" + hit.Column.FieldName, tip);
}
}
else if (e.Info == null && e.SelectedControl == this.gcRules)
{
var hit = this.gvRules.CalcHitInfo(e.ControlMousePosition);
if (hit.InRowCell && hit.Column == this.colRuleName)
{
var rule = (Rule)this.gvRules.GetRow(hit.RowHandle);
var server = (ServerRow) this.gvServers.GetFocusedRow();
var pretty = server?.GameExtension?.GetPrettyNameForRule(server, rule.Name);
if (pretty != null)
e.Info = new ToolTipControlInfo(rule.Name, rule.Name);
}
}
}
#endregion

Expand Down Expand Up @@ -2323,6 +2335,16 @@ private void miAddDetailColumnString_ItemClick(object sender, ItemClickEventArgs

// Rules grid

#region gvRules_CustomColumnDisplayText
private void gvRules_CustomColumnDisplayText(object sender, CustomColumnDisplayTextEventArgs e)
{
var server = (ServerRow)this.gvServers.GetFocusedRow();
var text = server?.GameExtension?.GetPrettyNameForRule(server, e.Value as string);
if (text != null)
e.DisplayText = text;
}
#endregion

#region gvRules_MouseDown
private void gvRules_MouseDown(object sender, MouseEventArgs e)
{
Expand Down
Loading

0 comments on commit 497df44

Please sign in to comment.