Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Jan 22, 2024
1 parent 05fd375 commit 6c0bc74
Show file tree
Hide file tree
Showing 79 changed files with 4,261 additions and 4,417 deletions.
11 changes: 11 additions & 0 deletions OpenGSQ/BinaryReaderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,16 @@ public static bool TryReadStringEx(this BinaryReader br, out string outString, b
{
return br.TryReadStringEx(out outString, new byte[] { charByte });
}

/// <summary>
/// Reads a Pascal string from a binary stream.
/// </summary>
/// <param name="br">The binary reader to read the string from.</param>
/// <returns>A string read from the binary stream.</returns>
public static string ReadPascalString(this BinaryReader br)
{
int length = br.ReadByte();
return Encoding.UTF8.GetString(br.ReadBytes(length - 1));
}
}
}
40 changes: 17 additions & 23 deletions OpenGSQ/Protocols/ASE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ public async Task<Status> GetStatus()

return new Status
{
GameName = ReadString(br),
GamePort = int.Parse(ReadString(br)),
HostName = ReadString(br),
GameType = ReadString(br),
Map = ReadString(br),
Version = ReadString(br),
Password = ReadString(br) != "0",
NumPlayers = int.Parse(ReadString(br)),
MaxPlayers = int.Parse(ReadString(br)),
GameName = br.ReadPascalString(),
GamePort = int.Parse(br.ReadPascalString()),
Hostname = br.ReadPascalString(),
GameType = br.ReadPascalString(),
Map = br.ReadPascalString(),
Version = br.ReadPascalString(),
Password = br.ReadPascalString() != "0",
NumPlayers = int.Parse(br.ReadPascalString()),
MaxPlayers = int.Parse(br.ReadPascalString()),
Rules = ParseRules(br),
Players = ParsePlayers(br),
};
Expand All @@ -71,14 +71,14 @@ private Dictionary<string, string> ParseRules(BinaryReader br)

while (!br.IsEnd())
{
string key = ReadString(br);
string key = br.ReadPascalString();

if (string.IsNullOrEmpty(key))
{
break;
}

rules[key] = ReadString(br);
rules[key] = br.ReadPascalString();
}

return rules;
Expand All @@ -103,41 +103,35 @@ private Player ParsePlayer(BinaryReader br)

if ((flags & 1) == 1)
{
player.Name = ReadString(br);
player.Name = br.ReadPascalString();
}

if ((flags & 2) == 2)
{
player.Team = ReadString(br);
player.Team = br.ReadPascalString();
}

if ((flags & 4) == 4)
{
player.Skin = ReadString(br);
player.Skin = br.ReadPascalString();
}

if ((flags & 8) == 8)
{
player.Score = int.TryParse(ReadString(br), out int result) ? result : 0;
player.Score = int.TryParse(br.ReadPascalString(), out int result) ? result : 0;
}

if ((flags & 16) == 16)
{
player.Ping = int.TryParse(ReadString(br), out int result) ? result : 0;
player.Ping = int.TryParse(br.ReadPascalString(), out int result) ? result : 0;
}

if ((flags & 32) == 32)
{
player.Time = int.TryParse(ReadString(br), out int result) ? result : 0;
player.Time = int.TryParse(br.ReadPascalString(), out int result) ? result : 0;
}

return player;
}

private string ReadString(BinaryReader br)
{
int length = br.ReadByte();
return Encoding.UTF8.GetString(br.ReadBytes(length - 1));
}
}
}
2 changes: 1 addition & 1 deletion OpenGSQ/Responses/ASE/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Status
/// <summary>
/// Gets or sets the host name of the game.
/// </summary>
public string HostName { get; set; }
public string Hostname { get; set; }

/// <summary>
/// Gets or sets the type of the game.
Expand Down
1 change: 0 additions & 1 deletion OpenGSQ/Responses/Samp/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ public class Player
/// </summary>
public int Ping { get; set; }
}

}
File renamed without changes.
Loading

0 comments on commit 6c0bc74

Please sign in to comment.