Skip to content

Commit

Permalink
Refactor A2SServer
Browse files Browse the repository at this point in the history
  • Loading branch information
tuokri committed Mar 9, 2024
1 parent 0b97494 commit a18cd65
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions A2SServer/A2SServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public static class Constants
public const byte A2SInfoResponseHeader = 0x49;
public const byte A2SPlayerResponseHeader = 0x44;
public const byte A2SRulesResponseHeader = 0x45;
public const byte EdfPort = 0x80;
public const byte EdfSteamId = 0x10;
public const byte EdfKeywords = 0x20;
public const byte EdfGameId = 0x01;
}

public class A2SRequestPackage
Expand Down Expand Up @@ -134,7 +138,7 @@ public class Info
// TODO: better name?
public static class Utils
{
public static byte[] MakeInfoResponsePacket(ref Info info)
public static byte[] MakeInfoResponsePacket(Info info)
{
var basicInfo = new byte[]
{
Expand All @@ -146,7 +150,8 @@ public static byte[] MakeInfoResponsePacket(ref Info info)
info.Protocol,
};

var bytes = basicInfo.Concat(Encoding.ASCII.GetBytes(info.ServerName + '\0'))
var bytes = basicInfo
.Concat(Encoding.ASCII.GetBytes(info.ServerName + '\0'))
.Concat(Encoding.ASCII.GetBytes(info.Map + '\0'))
.Concat(Encoding.ASCII.GetBytes(info.GameDir + '\0'))
.Concat(Encoding.ASCII.GetBytes(info.GameName + '\0'))
Expand All @@ -165,7 +170,8 @@ public static byte[] MakeInfoResponsePacket(ref Info info)

bytes = bytes.Concat(moreInfo).Concat(Encoding.ASCII.GetBytes(info.Version + '\0'));

const byte edf = 0x80 | 0x10 | 0x20 | 0x01;
const byte edf = Constants.EdfPort | Constants.EdfSteamId | Constants.EdfKeywords |
Constants.EdfGameId;
bytes = bytes.Concat(new[] { edf });

bytes = bytes.Concat(BitConverter.GetBytes(info.Port))
Expand All @@ -176,7 +182,7 @@ public static byte[] MakeInfoResponsePacket(ref Info info)
return bytes.ToArray();
}

public static byte[] MakePlayerResponsePacket(ref List<PlayerInfo> players)
public static byte[] MakePlayerResponsePacket(List<PlayerInfo> players)
{
var data = new byte[]
{
Expand All @@ -200,7 +206,7 @@ public static byte[] MakePlayerResponsePacket(ref List<PlayerInfo> players)
return data.Concat(playerData).ToArray();
}

public static byte[] MakeRulesResponsePacket(ref Dictionary<string, string> rules)
public static byte[] MakeRulesResponsePacket(Dictionary<string, string> rules)
{
var data = new byte[]
{
Expand Down

0 comments on commit a18cd65

Please sign in to comment.