Skip to content
This repository was archived by the owner on Apr 20, 2020. It is now read-only.
Merged
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
26 changes: 19 additions & 7 deletions CoreRCON.sln
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{600446C9-F807-4B19-807C-DDDE625CE558}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A25CF464-1990-4F9D-92E4-E69BC9B9D137}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
EndProjectSection
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreRCON", "src\CoreRCON\CoreRCON.csproj", "{CDFCA475-8F06-424B-9CF7-7D1E5D21F6D5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TF2Example", "src\TF2Example\TF2Example.csproj", "{4157A4E6-B76E-4BC5-BE32-2171EA3A0BE1}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CoreRCON", "src\CoreRCON\CoreRCON.xproj", "{CDFCA475-8F06-424B-9CF7-7D1E5D21F6D5}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MCExample", "src\MCExample\MCExample.csproj", "{A7392D55-A455-4415-AD20-9298C5CFE7CB}"
ProjectSection(ProjectDependencies) = postProject
{CDFCA475-8F06-424B-9CF7-7D1E5D21F6D5} = {CDFCA475-8F06-424B-9CF7-7D1E5D21F6D5}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -22,11 +24,21 @@ Global
{CDFCA475-8F06-424B-9CF7-7D1E5D21F6D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CDFCA475-8F06-424B-9CF7-7D1E5D21F6D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CDFCA475-8F06-424B-9CF7-7D1E5D21F6D5}.Release|Any CPU.Build.0 = Release|Any CPU
{4157A4E6-B76E-4BC5-BE32-2171EA3A0BE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4157A4E6-B76E-4BC5-BE32-2171EA3A0BE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4157A4E6-B76E-4BC5-BE32-2171EA3A0BE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4157A4E6-B76E-4BC5-BE32-2171EA3A0BE1}.Release|Any CPU.Build.0 = Release|Any CPU
{A7392D55-A455-4415-AD20-9298C5CFE7CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7392D55-A455-4415-AD20-9298C5CFE7CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7392D55-A455-4415-AD20-9298C5CFE7CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7392D55-A455-4415-AD20-9298C5CFE7CB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CDFCA475-8F06-424B-9CF7-7D1E5D21F6D5} = {600446C9-F807-4B19-807C-DDDE625CE558}
{4157A4E6-B76E-4BC5-BE32-2171EA3A0BE1} = {600446C9-F807-4B19-807C-DDDE625CE558}
{A7392D55-A455-4415-AD20-9298C5CFE7CB} = {600446C9-F807-4B19-807C-DDDE625CE558}
EndGlobalSection
EndGlobal
6 changes: 0 additions & 6 deletions global.json

This file was deleted.

26 changes: 26 additions & 0 deletions src/CoreRCON/CoreRCON.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>A .NET Core implementation of Valve's RCON spec and SRCDS's logaddress function.</Description>
<AssemblyTitle>CoreRCON</AssemblyTitle>
<VersionPrefix>2.0.0</VersionPrefix>
<Authors>Scott Kaye</Authors>
<TargetFramework>netstandard1.6</TargetFramework>
<AssemblyName>CoreRCON</AssemblyName>
<OutputType>Library</OutputType>
<PackageId>CoreRCON</PackageId>
<PackageTags>valve;rcon;logaddress;srcds</PackageTags>
<PackageIconUrl>https://cdn.rawgit.com/ScottKaye/CoreRCON/master/logo.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/ScottKaye/CoreRCON</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/ScottKaye/CoreRCON</RepositoryUrl>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>

<Target Name="PostcompileScript" AfterTargets="Build" Condition=" '$(IsCrossTargetingBuild)' != 'true' ">
<Exec Command="dotnet pack --no-build --configuration $(Configuration)" />
</Target>

</Project>
19 changes: 0 additions & 19 deletions src/CoreRCON/CoreRCON.xproj

This file was deleted.

39 changes: 32 additions & 7 deletions src/CoreRCON/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

Expand Down Expand Up @@ -26,6 +27,30 @@ public static string ReadNullTerminatedString(this byte[] bytes, int start, ref
return Encoding.UTF8.GetString(bytes, start, end - start);
}

public static List<string> ReadNullTerminatedStringArray(this byte[] bytes, int start, ref int i)
{
var result = new List<string>();
var byteindex = start;
while (bytes[byteindex] != 0x00)
{
result.Add(ReadNullTerminatedString(bytes, byteindex, ref byteindex));
}
i = byteindex + 1;
return result;
}

public static Dictionary<string, string> ReadNullTerminatedStringDictionary(this byte[] bytes, int start, ref int i)
{
var result = new Dictionary<string, string>();
var byteindex = start;
while (bytes[byteindex] != 0x00)
{
result.Add(ReadNullTerminatedString(bytes, byteindex, ref byteindex), ReadNullTerminatedString(bytes, byteindex, ref byteindex));
}
i = byteindex + 1;
return result;
}

/// <summary>
/// Read a short from a byte array and update the offset.
/// </summary>
Expand All @@ -38,13 +63,13 @@ public static short ReadShort(this byte[] bytes, int start, ref int i)
return BitConverter.ToInt16(bytes, start);
}

/// <summary>
/// Read a float from a byte array and update the offset.
/// </summary>
/// <param name="bytes">Byte array.</param>
/// <param name="start">Offset to start reading from.</param>
/// <param name="i">Offset variable to move to the end of the string.</param>
public static float ReadFloat(this byte[] bytes, int start, ref int i)
/// <summary>
/// Read a float from a byte array and update the offset.
/// </summary>
/// <param name="bytes">Byte array.</param>
/// <param name="start">Offset to start reading from.</param>
/// <param name="i">Offset variable to move to the end of the string.</param>
public static float ReadFloat(this byte[] bytes, int start, ref int i)
{
i += 4;
return BitConverter.ToSingle(bytes, start);
Expand Down
10 changes: 10 additions & 0 deletions src/CoreRCON/PacketFormats/IQueryInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CoreRCON.PacketFormats
{
public interface IQueryInfo
{
}
}
47 changes: 47 additions & 0 deletions src/CoreRCON/PacketFormats/MinecraftQueryPackets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;

namespace CoreRCON.PacketFormats
{
public class MinecraftQueryInfo : IQueryInfo
{
public string MessageOfTheDay { get; private set; }
public string Gametype { get; private set; }
public string GameId { get; private set; }
public string Version { get; private set; }
public string Plugins { get; private set; }
public string Map { get; private set; }
public string NumPlayers { get; private set; }
public string MaxPlayers { get; private set; }
public string HostPort { get; private set; }
public string HostIp { get; private set; }

public IEnumerable<string> Players { get; private set; }

public static MinecraftQueryInfo FromBytes(byte[] buffer)
{
int i = 16; // 1x type, 4x session, 11x padding
var serverinfo = buffer.ReadNullTerminatedStringDictionary(i, ref i);
i += 10;
var players = buffer.ReadNullTerminatedStringArray(i, ref i);

return new MinecraftQueryInfo
{
MessageOfTheDay = serverinfo["hostname"],
Gametype = serverinfo["gametype"],
GameId = serverinfo["game_id"],
Version = serverinfo["version"],
Plugins = serverinfo["plugins"],
Map = serverinfo["map"],
NumPlayers = serverinfo["numplayers"],
MaxPlayers = serverinfo["maxplayers"],
HostPort = serverinfo["hostport"],
HostIp = serverinfo["hostip"],
Players = players
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public enum ServerVisibility
Private = 0x1
}

public class ServerQueryInfo
{
public class SourceQueryInfo : IQueryInfo
{
public byte Bots { get; private set; }
public ServerEnvironment Environment { get; private set; }
public string Folder { get; private set; }
Expand All @@ -42,10 +42,10 @@ public class ServerQueryInfo
public ServerVAC VAC { get; private set; }
public ServerVisibility Visibility { get; private set; }

public static ServerQueryInfo FromBytes(byte[] buffer)
public static SourceQueryInfo FromBytes(byte[] buffer)
{
int i = 6;
return new ServerQueryInfo
return new SourceQueryInfo
{
ProtocolVersion = buffer[4],
Name = buffer.ReadNullTerminatedString(i, ref i),
Expand Down
2 changes: 1 addition & 1 deletion src/CoreRCON/Parsers/ParserHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static class ParserHelpers
internal static IParser<T> CreateParser<T>()
where T : class, IParseable, new()
{
var implementor = new T().GetType().GetTypeInfo().Assembly.GetTypes().FirstOrDefault(t => t.GetInterfaces().Contains(typeof(IParser<T>)));
var implementor = new T().GetType().GetTypeInfo().Assembly.GetTypes().FirstOrDefault(t => t.GetTypeInfo().GetInterfaces().Contains(typeof(IParser<T>)));
if (implementor == null) throw new ArgumentException($"A class implementing {nameof(IParser)}<{typeof(T).FullName}> was not found in the assembly.");
return (IParser<T>)Activator.CreateInstance(implementor);
}
Expand Down
75 changes: 0 additions & 75 deletions src/CoreRCON/Program.cs

This file was deleted.

Loading