Skip to content

Commit

Permalink
Simplify access to ServerAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
sliekens committed Sep 16, 2023
1 parent a7a1f1b commit 417d80a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
5 changes: 1 addition & 4 deletions GW2SDK.Tests/Features/Mumble/GameLinkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@ public void The_link_provides_context()
var gameTick = sut.GetSnapshot();
Assert.True(gameTick.Context.BuildId > 100_000, "Game build should be over 100,000");

var server = gameTick.Context.GetServerAddress();
var server = gameTick.Context.ServerAddress;
Assert.NotEmpty(server.ToString());

var address = gameTick.Context.GetServerAddress();
Assert.NotNull(address.Address);

// Port is not specified
Assert.Equal(0, server.Port);
}
Expand Down
9 changes: 4 additions & 5 deletions GW2SDK/Features/Mumble/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace GuildWars2.Mumble;

[PublicAPI]
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
public struct Context
public record struct Context
{
[FieldOffset(0)]
internal readonly sockaddr_in ServerAddress;
internal readonly sockaddr_in serverAddress;

[FieldOffset(28)]
public readonly uint MapId;
Expand Down Expand Up @@ -63,9 +63,8 @@ public struct Context

public bool IsMounted => MountIndex != 0;

[Pure]
public IPEndPoint GetServerAddress() =>
new(ServerAddress.sin_addr.s_un.s_addr, ServerAddress.sin_port);
public readonly IPEndPoint ServerAddress =>
new(serverAddress.sin_addr.s_un.s_addr, serverAddress.sin_port);

[Pure]
public MountName GetMount() =>
Expand Down

0 comments on commit 417d80a

Please sign in to comment.