mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Initial pass at getting coverage for Client functions in API
This commit is contained in:
parent
ed632baf38
commit
e3f84eac32
@ -55,6 +55,7 @@ public partial class Client : BaseSteamworks
|
||||
|
||||
public Voice Voice { get; private set; }
|
||||
public ServerList ServerList { get; private set; }
|
||||
public LobbyList LobbyList { get; private set; }
|
||||
public App App { get; private set; }
|
||||
public Achievements Achievements { get; private set; }
|
||||
public Stats Stats { get; private set; }
|
||||
@ -88,6 +89,7 @@ public Client( uint appId )
|
||||
//
|
||||
Voice = new Voice( this );
|
||||
ServerList = new ServerList( this );
|
||||
LobbyList = new LobbyList(this);
|
||||
App = new App( this );
|
||||
Stats = new Stats( this );
|
||||
Achievements = new Achievements( this );
|
||||
@ -159,6 +161,12 @@ public override void Dispose()
|
||||
ServerList = null;
|
||||
}
|
||||
|
||||
if (LobbyList != null)
|
||||
{
|
||||
LobbyList.Dispose();
|
||||
LobbyList = null;
|
||||
}
|
||||
|
||||
if ( App != null )
|
||||
{
|
||||
App.Dispose();
|
||||
|
202
Facepunch.Steamworks/Client/Lobby.cs
Normal file
202
Facepunch.Steamworks/Client/Lobby.cs
Normal file
@ -0,0 +1,202 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using SteamNative;
|
||||
using Result = SteamNative.Result;
|
||||
|
||||
namespace Facepunch.Steamworks
|
||||
{
|
||||
public partial class Client : IDisposable
|
||||
{
|
||||
public void JoinLobby(ulong LobbyID)
|
||||
{
|
||||
native.matchmaking.JoinLobby(LobbyID, OnLobbyJoined);
|
||||
}
|
||||
|
||||
void OnLobbyJoined(LobbyEnter_t callback, bool error)
|
||||
{
|
||||
//TODO:
|
||||
}
|
||||
|
||||
|
||||
//The type of lobby you are creating
|
||||
public enum LobbyType : int
|
||||
{
|
||||
Private = SteamNative.LobbyType.Private,
|
||||
FriendsOnly = SteamNative.LobbyType.FriendsOnly,
|
||||
Public = SteamNative.LobbyType.Public,
|
||||
Invisible = SteamNative.LobbyType.Invisible
|
||||
}
|
||||
|
||||
// Create a lobby, auto joins the created lobby
|
||||
public Lobby CreateLobby(LobbyType lobbyType, int maxMembers, string name)
|
||||
{
|
||||
var lobby = new Lobby(this);
|
||||
native.matchmaking.CreateLobby((SteamNative.LobbyType)lobbyType, maxMembers, lobby.OnLobbyCreated);
|
||||
if (lobby.IsValid)
|
||||
{
|
||||
lobby.Name = name;
|
||||
lobby.MaxMembers = maxMembers;
|
||||
lobby.LobbyType = lobbyType;
|
||||
}
|
||||
return lobby;
|
||||
}
|
||||
}
|
||||
public class Lobby : IDisposable
|
||||
{
|
||||
internal Client client;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if we tried to create this lobby but it returned
|
||||
/// an error.
|
||||
/// </summary>
|
||||
public bool IsError { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if this lobby is valid, ie, we've received
|
||||
/// a positive response from Steam about it.
|
||||
/// </summary>
|
||||
public bool IsValid => LobbyID != 0;
|
||||
|
||||
/// <summary>
|
||||
/// The CSteamID of the lobby that was created
|
||||
/// </summary>
|
||||
internal ulong LobbyID { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the lobby as a property for easy getting/setting
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return LobbyData["name"]; }
|
||||
set { SetLobbyData("name", value); }
|
||||
}
|
||||
|
||||
public Lobby(Client c)
|
||||
{
|
||||
client = c;
|
||||
}
|
||||
|
||||
internal void OnLobbyCreated(LobbyCreated_t callback, bool error)
|
||||
{
|
||||
//from SpaceWarClient.cpp 793
|
||||
if (error || (callback.Result != Result.OK))
|
||||
{
|
||||
IsError = true;
|
||||
return;
|
||||
}
|
||||
|
||||
Owner = client.SteamId; //this is implicitly set on creation but need to cache it here
|
||||
LobbyID = callback.SteamIDLobby;
|
||||
}
|
||||
|
||||
Dictionary<string, string> LobbyData = new Dictionary<string, string>();
|
||||
public void SetLobbyData(string key, string value)
|
||||
{
|
||||
if (LobbyData.ContainsKey(key))
|
||||
{
|
||||
if (LobbyData[key] == value)
|
||||
return;
|
||||
|
||||
LobbyData[key] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
LobbyData.Add(key, value);
|
||||
}
|
||||
|
||||
client.native.matchmaking.SetLobbyData(LobbyID, key, value);
|
||||
}
|
||||
|
||||
public void RemoveLobbyData(string key)
|
||||
{
|
||||
if (LobbyData.ContainsKey(key))
|
||||
{
|
||||
LobbyData.Remove(key);
|
||||
}
|
||||
|
||||
client.native.matchmaking.DeleteLobbyData(LobbyID, key);
|
||||
}
|
||||
|
||||
public Client.LobbyType LobbyType
|
||||
{
|
||||
get { return _lobbyType; }
|
||||
set { if (_lobbyType == value) return; client.native.matchmaking.SetLobbyType(LobbyID, (SteamNative.LobbyType)value); _lobbyType = value; } //returns bool
|
||||
}
|
||||
Client.LobbyType _lobbyType;
|
||||
|
||||
|
||||
//Must be the owner to change the owner
|
||||
public ulong Owner
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_owner == 0)
|
||||
{
|
||||
_owner = client.native.matchmaking.GetLobbyOwner(LobbyID);
|
||||
return _owner;
|
||||
}
|
||||
return _owner;
|
||||
}
|
||||
private set { if (_owner == value) return; client.native.matchmaking.SetLobbyOwner(LobbyID, value); _owner = value; }
|
||||
}
|
||||
ulong _owner = 0;
|
||||
|
||||
// Can the lobby be joined by other people
|
||||
public bool Joinable
|
||||
{
|
||||
get { return _joinable; }
|
||||
set { if (_joinable == value) return; client.native.matchmaking.SetLobbyJoinable(LobbyID, value); _joinable = value; }
|
||||
}
|
||||
bool _joinable = true; //steam default
|
||||
|
||||
// How many people can be in the Lobby
|
||||
public int MaxMembers
|
||||
{
|
||||
get { return _maxMembers; }
|
||||
set { if (_maxMembers == value) return; client.native.matchmaking.SetLobbyMemberLimit(LobbyID, value); _maxMembers = value; }
|
||||
}
|
||||
int _maxMembers = 0;
|
||||
|
||||
public void Leave()
|
||||
{
|
||||
client.native.matchmaking.LeaveLobby(LobbyID);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
client = null;
|
||||
}
|
||||
|
||||
/*not implemented
|
||||
// returns a lobby metadata key/values pair by index
|
||||
client.native.matchmaking.GetLobbyDataByIndex;
|
||||
|
||||
//set the game server of the lobby
|
||||
client.native.matchmaking.GetLobbyGameServer;
|
||||
client.native.matchmaking.SetLobbyGameServer;
|
||||
|
||||
//data for people in the actual lobby - scores/elo/characters/etc.
|
||||
client.native.matchmaking.SetLobbyMemberData; //local user
|
||||
client.native.matchmaking.GetLobbyMemberData; //any user in this lobby
|
||||
|
||||
|
||||
// returns steamid of member
|
||||
// note that the current user must be in a lobby to retrieve CSteamIDs of other users in that lobby
|
||||
client.native.matchmaking.GetLobbyMemberByIndex;
|
||||
|
||||
//for linking lobbies idk havent looked hard yet
|
||||
client.native.matchmaking.SetLinkedLobby;
|
||||
|
||||
//chat functions
|
||||
client.native.matchmaking.SendLobbyChatMsg;
|
||||
client.native.matchmaking.GetLobbyChatEntry;
|
||||
|
||||
//get total data count (why?)
|
||||
client.native.matchmaking.GetLobbyDataCount
|
||||
|
||||
//invite your frans
|
||||
client.native.matchmaking.InviteUserToLobby //this invites the user the current lobby the invitee is in
|
||||
*/
|
||||
}
|
||||
}
|
33
Facepunch.Steamworks/Client/LobbyList.Lobby.cs
Normal file
33
Facepunch.Steamworks/Client/LobbyList.Lobby.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Facepunch.Steamworks
|
||||
{
|
||||
public partial class LobbyList
|
||||
{
|
||||
public class Lobby
|
||||
{
|
||||
internal Client Client;
|
||||
public string Name { get; private set; }
|
||||
public ulong LobbyID { get; private set; }
|
||||
public ulong Owner { get; private set; }
|
||||
public int MemberLimit{ get; private set; }
|
||||
public int NumMembers{ get; private set; }
|
||||
|
||||
internal static Lobby FromSteam(Client client, ulong lobby)
|
||||
{
|
||||
return new Lobby()
|
||||
{
|
||||
Client = client,
|
||||
LobbyID = lobby,
|
||||
Name = client.native.matchmaking.GetLobbyData(lobby, "name"),
|
||||
MemberLimit = client.native.matchmaking.GetLobbyMemberLimit(lobby),
|
||||
Owner = client.native.matchmaking.GetLobbyOwner(lobby),
|
||||
NumMembers = client.native.matchmaking.GetNumLobbyMembers(lobby)
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
117
Facepunch.Steamworks/Client/LobbyList.cs
Normal file
117
Facepunch.Steamworks/Client/LobbyList.cs
Normal file
@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using SteamNative;
|
||||
|
||||
namespace Facepunch.Steamworks
|
||||
{
|
||||
public partial class LobbyList : IDisposable
|
||||
{
|
||||
internal Client client;
|
||||
public List<Lobby> Lobbies = new List<Lobby>();
|
||||
|
||||
internal LobbyList(Client client)
|
||||
{
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public void Refresh ( LobbyFilter filter = null)
|
||||
{
|
||||
if(filter != null)
|
||||
{
|
||||
client.native.matchmaking.AddRequestLobbyListDistanceFilter((SteamNative.LobbyDistanceFilter)filter.DistanceFilter);
|
||||
client.native.matchmaking.AddRequestLobbyListFilterSlotsAvailable(filter.SlotsAvailable);
|
||||
client.native.matchmaking.AddRequestLobbyListResultCountFilter(filter.MaxResults);
|
||||
foreach (KeyValuePair<string, string> fil in filter.StringFilters)
|
||||
{
|
||||
client.native.matchmaking.AddRequestLobbyListStringFilter(fil.Key, fil.Value, SteamNative.LobbyComparison.Equal);
|
||||
}
|
||||
foreach (KeyValuePair<string, int> fil in filter.NearFilters)
|
||||
{
|
||||
client.native.matchmaking.AddRequestLobbyListNearValueFilter(fil.Key, fil.Value);
|
||||
}
|
||||
foreach (KeyValuePair<string, KeyValuePair<LobbyFilter.Comparison, int>> fil in filter.NumericalFilters)
|
||||
{
|
||||
client.native.matchmaking.AddRequestLobbyListNumericalFilter(fil.Key, fil.Value.Value, (SteamNative.LobbyComparison)fil.Value.Key);
|
||||
}
|
||||
}
|
||||
|
||||
// this will never return lobbies that are full (via the actual api)
|
||||
client.native.matchmaking.RequestLobbyList(OnLobbyList);
|
||||
|
||||
/*
|
||||
if (filter == null) may need this if we are getting too many lobbies
|
||||
{
|
||||
filter = new Filter();
|
||||
//filter.Add("appid", client.AppId.ToString());
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
void OnLobbyList(LobbyMatchList_t callback, bool error)
|
||||
{
|
||||
if (error) return;
|
||||
Lobbies.Clear();
|
||||
uint lobbiesMatching = callback.LobbiesMatching;
|
||||
// lobbies are returned in order of closeness to the user, so add them to the list in that order
|
||||
for (int i = 0; i < lobbiesMatching; i++)
|
||||
{
|
||||
ulong lobby = client.native.matchmaking.GetLobbyByIndex(i);
|
||||
Lobby newLobby = Lobby.FromSteam(client, lobby);
|
||||
if (newLobby.Name != "")
|
||||
{
|
||||
Lobbies.Add(newLobby);
|
||||
}
|
||||
else
|
||||
{
|
||||
//need to sub the lobbyid to the request func
|
||||
//client.native.matchmaking.RequestLobbyData(lobby)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
client = null;
|
||||
}
|
||||
|
||||
public class LobbyFilter
|
||||
{
|
||||
// Filters that match actual metadata keys exactly
|
||||
public Dictionary<string, string> StringFilters = new Dictionary<string, string>();
|
||||
// Filters that are of string key and int value for that key to be close to
|
||||
public Dictionary<string, int> NearFilters = new Dictionary<string, int>();
|
||||
//Filters that are of string key and int value, with a comparison filter to say how we should relate to the value
|
||||
public Dictionary<string, KeyValuePair<Comparison, int>> NumericalFilters = new Dictionary<string, KeyValuePair<Comparison, int>>();
|
||||
public Distance DistanceFilter { get; set; }
|
||||
public int SlotsAvailable { get; set; }
|
||||
public int MaxResults { get; set; }
|
||||
|
||||
public enum Distance : int
|
||||
{
|
||||
Close = SteamNative.LobbyDistanceFilter.Close,
|
||||
Default = SteamNative.LobbyDistanceFilter.Default,
|
||||
Far = SteamNative.LobbyDistanceFilter.Far,
|
||||
Worldwide = SteamNative.LobbyDistanceFilter.Worldwide
|
||||
}
|
||||
|
||||
public enum Comparison : int
|
||||
{
|
||||
EqualToOrLessThan = SteamNative.LobbyComparison.EqualToOrLessThan,
|
||||
LessThan = SteamNative.LobbyComparison.LessThan,
|
||||
Equal = SteamNative.LobbyComparison.Equal,
|
||||
GreaterThan = SteamNative.LobbyComparison.GreaterThan,
|
||||
EqualToOrGreaterThan = SteamNative.LobbyComparison.EqualToOrGreaterThan,
|
||||
NotEqual = SteamNative.LobbyComparison.NotEqual
|
||||
}
|
||||
|
||||
public LobbyFilter(Distance distanceFilter, int slotsAvailable, int maxResults)
|
||||
{
|
||||
DistanceFilter = distanceFilter;
|
||||
SlotsAvailable = slotsAvailable;
|
||||
MaxResults = maxResults;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user