Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating with the latest Facepunch Steamworks API and populating steam lobby class. #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
16 changes: 8 additions & 8 deletions Runtime/Integrations/Steam/SteamLobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ public override int Capacity {

readonly SteamLobbyManager _manager;

public SteamLobby(Steamworks.Data.Lobby lobby, SteamLobbyManager manager) : base() {
public SteamLobby(Steamworks.Data.Lobby lobby, SteamLobbyManager manager, bool connected = false) : base() {
Assert.IsNotNull(manager);
_manager = manager;
Members.Refresh();
_lobby = lobby;
if (connected)
{
Members.Refresh();
}
}

public override int MemberCount => _lobby.MemberCount;
Expand Down Expand Up @@ -63,7 +67,7 @@ internal override void SetMemberMetadata(AccountHandle handle, string key, strin
if (handle.Id != UserId) {
throw new InvalidOperationException("Cannnot set the metadata of a Steam lobby member other than the current user.");
}
_lobby.SetMemberData(new Friend(handle.Id), key, value);
_lobby.SetMemberData(key, value);
}

internal override void DeleteMemberMetadata(AccountHandle handle, string key) =>
Expand Down Expand Up @@ -95,11 +99,7 @@ internal override unsafe void SendNetworkMessage(AccountHandle target, ReadOnlyS
}

public override unsafe void SendLobbyMessage(ReadOnlySpan<byte> msg) {
fixed (byte* ptr = msg) {
if (!_lobby.SendChatBytes(ptr, msg.Length)) {
Debug.LogError("Failed to send Steam Lobby Packet.");
}
}
throw new NotImplementedException("Steam Facepunch API no longer supports sending bytes");
}

}
Expand Down
38 changes: 32 additions & 6 deletions Runtime/Integrations/Steam/SteamLobbyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public SteamLobbyManager() {
SteamMatchmaking.OnLobbyMemberDisconnected += OnLobbyMemberLeave;
SteamMatchmaking.OnLobbyMemberKicked += OnLobbyMemberRemoved;
SteamMatchmaking.OnLobbyMemberBanned += OnLobbyMemberRemoved;
SteamMatchmaking.OnLobbyMemberDataChanged += OnLobbyMemberDataChanged;
}

public unsafe void Update() {
Expand Down Expand Up @@ -61,7 +62,7 @@ public async Task<Lobby> CreateLobby(LobbyCreateParams createParams) {
steamLobby.SetData(kvp.Key, kvp.Value.ToString());
}
}
var lobby = new SteamLobby(steamLobby, this);
var lobby = new SteamLobby(steamLobby, this, true);
_connectedLobbies.Add(steamLobby.Id, lobby);
return lobby;
}
Expand All @@ -87,15 +88,39 @@ public LobbySearchBuilder(LobbyQuery query) {
}

public ILobbySearchBuilder Filter(string key, SearchComparison comparison, string value) {
var comp = (LobbyComparison)((int)comparison);
_query.AddStringFilter(key, value, comp);
// Facepunch Steamworks no longer support comparison of strings greater or lesser, only equal.
// This is untested.
_query.WithKeyValue(key, value);
return this;
}

public ILobbySearchBuilder Filter(string key, SearchComparison comparison, int value) {
var comp = (LobbyComparison)((int)comparison);
_query.AddNumericalFilter(key, value, comp);
return this;
// This is untested.
if (comparison == SearchComparison.LessThanOrEqual)
{
_query.WithLower(key, value + 1);
}
else if (comparison == SearchComparison.LessThan)
{
_query.WithLower(key, value);
}
else if (comparison == SearchComparison.Equal)
{
_query.WithEqual(key, value + 1);
}
else if (comparison == SearchComparison.GreaterThan)
{
_query.WithHigher(key, value);
}
else if (comparison == SearchComparison.GreaterThanOrEqual)
{
_query.WithHigher(key, value + 1);
}
else if (comparison == SearchComparison.NotEqual)
{
_query.WithNotEqual(key, value);
}
return this;
}

public ILobbySearchBuilder Sort(string key, string value) {
Expand Down Expand Up @@ -124,6 +149,7 @@ public void Dispose() {
SteamMatchmaking.OnLobbyMemberDisconnected += OnLobbyMemberLeave;
SteamMatchmaking.OnLobbyMemberKicked += OnLobbyMemberRemoved;
SteamMatchmaking.OnLobbyMemberBanned += OnLobbyMemberRemoved;
SteamMatchmaking.OnLobbyMemberDataChanged += OnLobbyMemberDataChanged;
}

internal async Task JoinLobby(SteamLobby lobby) {
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Lobbies/LobbyMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class LobbyMember : INetworkConnection, IMetadataContainer, IDisposable {
public static IMessageProcessor MessageProcessor;

static LobbyMember() {
MessageProcessor = new LZFCompressor();
MessageProcessor = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason this was removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using LZFCompressor instantly crashes Unity. I'm not sure where it goes wrong so I just commented it out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that's a sign we have a memory access violation somewhere in our code. I think we can keep this for now, but please leave a TODO(james7132) comment to investigate this. The LZF compression is part of the reason why we have been able to keep our bandwidth usage low despite sending a network message basically every tick in Backroll.

}

public enum ConnectionState {
Expand Down