Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions ConsoleApp/src/DemoArgProcessing/Options/Hidden/OptServerInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using ConsoleApp.GenericArgProcessing;
using DemoParser.Parser;
using DemoParser.Parser.Components.Messages;
using DemoParser.Parser.Components.Packets;
using DemoParser.Utils;

namespace ConsoleApp.DemoArgProcessing.Options.Hidden
{

public class OptServerInfo : DemoOption<OptServerInfo.InfoFlags>
{

public static readonly ImmutableArray<string> DefaultAliases = new[] { "--server-info" }.ToImmutableArray();

private const int FmtIdt = -25;

[Flags]
public enum InfoFlags
{
ServerCountOnly = 1,
}

public OptServerInfo() : base(
DefaultAliases,
Arity.ZeroOrOne,
"Print SvcServerInfo" +
$"\nUse flag \"{InfoFlags.ServerCountOnly}\" or \"1\" to print server count only.",
"flags",
Utils.ParseEnum<InfoFlags>,
default,
true)
{ }


protected override void AfterParse(DemoParsingSetupInfo setupObj, InfoFlags arg, bool isDefault)
{
setupObj.ExecutableOptions++;
}

protected override void Process(DemoParsingInfo infoObj, InfoFlags arg, bool isDefault)
{
infoObj.PrintOptionMessage("searching for SvcServerInfo");
try
{
bool any = false;
foreach ((SvcServerInfo info, int tick) in infoObj.CurrentDemo.FilterForMessage<SvcServerInfo>())
{
any = true;
WriteServerInfo(info, Console.Out, arg);
break;
}
if (!any)
Utils.Warning("SvcServerInfo not found");
}
catch (Exception)
{
Utils.Warning("Search for SvcServerInfo failed.\n");
}
}

public static IEnumerable<SvcServerInfo> GetServerInfo(SourceDemo demo)
{
return
from packet in demo.FilterForPacket<Packet>()
from message in packet.MessageStream
where message?.GetType() == typeof(SvcServerInfo)
select (SvcServerInfo)message;
}

public static void WriteServerInfo(SvcServerInfo info, TextWriter tw, InfoFlags flags)
{
if (flags == InfoFlags.ServerCountOnly)
{
tw.Write($"{"Server count ",FmtIdt}: {info.ServerCount}\n\n");
}
else
{
tw.Write($"{"Network protocol ",FmtIdt}: {info.NetworkProtocol}" +
$"\n{"Server count ",FmtIdt}: {info.ServerCount}" +
$"\n{"Is hltv ",FmtIdt}: {info.IsHltv}" +
$"\n{"Is dedicated ",FmtIdt}: {info.IsDedicated}");
if (info.RestrictWorkshopAddons != null)
{
tw.Write($"\n{"Restrict workshop addons ",FmtIdt}: {info.RestrictWorkshopAddons}");
}
tw.Write($"\n{"Player count ",FmtIdt}: {info.PlayerCount}" +
$"\n{"Max player count ",FmtIdt}: {info.MaxClients}" +
$"\n{"Tick interval ",FmtIdt}: {info.TickInterval}" +
$"\n{"Platform ",FmtIdt}: {info.Platform}" +
$"\n{"Game directory ",FmtIdt}: {info.GameDir}" +
$"\n{"Map name ",FmtIdt}: {info.MapName}" +
$"\n{"Skybox name ",FmtIdt}: {info.SkyName}" +
$"\n{"Host name ",FmtIdt}: {info.HostName}");
if (info.MissionName != null && info.MutationName != null)
{
tw.Write($"\n{"Mission name ",FmtIdt}: {info.MissionName}" +
$"\n{"Mutation name ",FmtIdt}: {info.MutationName}");
}

if (info.HasReplay != null)
{
tw.Write($"\n{"Has replay ",FmtIdt}: {info.HasReplay}");
}
tw.Write("\n\n");
}
}

protected override void PostProcess(DemoParsingInfo infoObj, InfoFlags arg, bool isDefault) { }
}
}
1 change: 1 addition & 0 deletions ConsoleApp/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public static void Main(string[] args) {
new OptPortals(),
new OptInputs(),
new OptDemoDump(),
new OptServerInfo(),
new OptTime() // this option should always be here and probably be last, it's sort of a default
}.ToImmutableArray()
);
Expand Down