(a00338777) v0.9.2.1
This commit is contained in:
@@ -14,17 +14,60 @@ namespace Facepunch.Steamworks
|
||||
get
|
||||
{
|
||||
if ( _auth == null )
|
||||
_auth = new Auth{ client = this };
|
||||
_auth = new Auth(this);
|
||||
|
||||
return _auth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Steam authentication statuses
|
||||
/// </summary>
|
||||
public enum ClientAuthStatus : int
|
||||
{
|
||||
OK = 0,
|
||||
UserNotConnectedToSteam = 1,
|
||||
NoLicenseOrExpired = 2,
|
||||
VACBanned = 3,
|
||||
LoggedInElseWhere = 4,
|
||||
VACCheckTimedOut = 5,
|
||||
AuthTicketCanceled = 6,
|
||||
AuthTicketInvalidAlreadyUsed = 7,
|
||||
AuthTicketInvalid = 8,
|
||||
PublisherIssuedBan = 9,
|
||||
}
|
||||
|
||||
public enum ClientStartAuthSessionResult : int
|
||||
{
|
||||
OK = 0,
|
||||
InvalidTicket = 1,
|
||||
DuplicateRequest = 2,
|
||||
InvalidVersion = 3,
|
||||
GameMismatch = 4,
|
||||
ExpiredTicket = 5,
|
||||
ServerNotConnectedToSteam = 6,
|
||||
}
|
||||
|
||||
public class Auth
|
||||
{
|
||||
public Auth(Client c)
|
||||
{
|
||||
client = c;
|
||||
|
||||
client.RegisterCallback<SteamNative.ValidateAuthTicketResponse_t>(OnAuthTicketValidate);
|
||||
}
|
||||
|
||||
void OnAuthTicketValidate(SteamNative.ValidateAuthTicketResponse_t data)
|
||||
{
|
||||
if (OnAuthChange != null)
|
||||
OnAuthChange(data.SteamID, data.OwnerSteamID, (ClientAuthStatus)data.AuthSessionResponse);
|
||||
}
|
||||
|
||||
internal Client client;
|
||||
|
||||
public Action<ulong, ulong, ClientAuthStatus> OnAuthChange;
|
||||
|
||||
public class Ticket : IDisposable
|
||||
{
|
||||
internal Client client;
|
||||
@@ -77,6 +120,27 @@ namespace Facepunch.Steamworks
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start authorizing a ticket. This user isn't authorized yet. Wait for a call to OnAuthChange.
|
||||
/// </summary>
|
||||
public unsafe ClientStartAuthSessionResult StartSession(byte[] data, ulong steamid)
|
||||
{
|
||||
fixed (byte* p = data)
|
||||
{
|
||||
var result = client.native.user.BeginAuthSession((IntPtr)p, data.Length, steamid);
|
||||
|
||||
return (ClientStartAuthSessionResult)result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Forget this guy. They're no longer in the game.
|
||||
/// </summary>
|
||||
public void EndSession(ulong steamid)
|
||||
{
|
||||
client.native.user.EndAuthSession(steamid);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,12 @@ namespace Facepunch.Steamworks
|
||||
if ( data.ContainsKey( k ) )
|
||||
{
|
||||
if ( data[k] == v ) { return true; }
|
||||
if ( client.native.matchmaking.SetLobbyData( lobby, k, v ) )
|
||||
bool setKey = true;
|
||||
if (lobby == client.Lobby.CurrentLobby && client.Lobby.Owner == client.SteamId)
|
||||
{
|
||||
setKey = client.native.matchmaking.SetLobbyData(lobby, k, v);
|
||||
}
|
||||
if ( setKey )
|
||||
{
|
||||
data[k] = v;
|
||||
return true;
|
||||
@@ -68,7 +73,12 @@ namespace Facepunch.Steamworks
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( client.native.matchmaking.SetLobbyData( lobby, k, v ) )
|
||||
bool setKey = true;
|
||||
if (lobby == client.Lobby.CurrentLobby && client.Lobby.Owner == client.SteamId)
|
||||
{
|
||||
setKey = client.native.matchmaking.SetLobbyData(lobby, k, v);
|
||||
}
|
||||
if ( setKey )
|
||||
{
|
||||
data.Add( k, v );
|
||||
return true;
|
||||
|
||||
@@ -169,19 +169,29 @@ namespace Facepunch.Steamworks
|
||||
/// <summary>
|
||||
/// Updates the LobbyData property to have the data for the current lobby, if any
|
||||
/// </summary>
|
||||
private bool suppressUpdateLobbyData = false;
|
||||
internal void UpdateLobbyData()
|
||||
{
|
||||
int dataCount = client.native.matchmaking.GetLobbyDataCount( CurrentLobby );
|
||||
CurrentLobbyData = new LobbyData( client, CurrentLobby );
|
||||
for ( int i = 0; i < dataCount; i++ )
|
||||
if (suppressUpdateLobbyData) { return; }
|
||||
try
|
||||
{
|
||||
if ( client.native.matchmaking.GetLobbyDataByIndex( CurrentLobby, i, out string key, out string value ) )
|
||||
suppressUpdateLobbyData = true;
|
||||
int dataCount = client.native.matchmaking.GetLobbyDataCount(CurrentLobby);
|
||||
CurrentLobbyData = new LobbyData(client, CurrentLobby);
|
||||
for (int i = 0; i < dataCount; i++)
|
||||
{
|
||||
CurrentLobbyData.SetData( key, value );
|
||||
if (client.native.matchmaking.GetLobbyDataByIndex(CurrentLobby, i, out string key, out string value))
|
||||
{
|
||||
CurrentLobbyData.SetData(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( OnLobbyDataUpdated != null ) { OnLobbyDataUpdated(); }
|
||||
if (OnLobbyDataUpdated != null) { OnLobbyDataUpdated(); }
|
||||
}
|
||||
finally
|
||||
{
|
||||
suppressUpdateLobbyData = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace Facepunch.Steamworks
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool registeredLobbyDataUpdated = false;
|
||||
void OnLobbyList(LobbyMatchList_t callback, bool error)
|
||||
{
|
||||
if (error) return;
|
||||
@@ -89,6 +89,9 @@ namespace Facepunch.Steamworks
|
||||
{
|
||||
//add the lobby to the list of requests
|
||||
ulong lobby = client.native.matchmaking.GetLobbyByIndex(i);
|
||||
|
||||
if (requests.Contains(lobby)) { continue; }
|
||||
|
||||
requests.Add(lobby);
|
||||
|
||||
//cast to a LobbyList.Lobby
|
||||
@@ -103,7 +106,11 @@ namespace Facepunch.Steamworks
|
||||
{
|
||||
//else we need to get the info for the missing lobby
|
||||
client.native.matchmaking.RequestLobbyData(lobby);
|
||||
client.RegisterCallback<SteamNative.LobbyDataUpdate_t>( OnLobbyDataUpdated );
|
||||
if (!registeredLobbyDataUpdated)
|
||||
{
|
||||
client.RegisterCallback<SteamNative.LobbyDataUpdate_t>(OnLobbyDataUpdated);
|
||||
registeredLobbyDataUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -115,7 +122,7 @@ namespace Facepunch.Steamworks
|
||||
|
||||
void checkFinished()
|
||||
{
|
||||
if (Lobbies.Count == requests.Count)
|
||||
if (Lobbies.Count >= requests.Count)
|
||||
{
|
||||
Finished = true;
|
||||
return;
|
||||
@@ -128,11 +135,12 @@ namespace Facepunch.Steamworks
|
||||
if (callback.Success == 1) //1 if success, 0 if failure
|
||||
{
|
||||
//find the lobby that has been updated
|
||||
Lobby lobby = Lobbies.Find(x => x.LobbyID == callback.SteamIDLobby);
|
||||
Lobby lobby = Lobbies.Find(x => x != null && x.LobbyID == callback.SteamIDLobby);
|
||||
|
||||
//if this lobby isn't yet in the list of lobbies, we know that we should add it
|
||||
if (lobby == null)
|
||||
{
|
||||
lobby = Lobby.FromSteam(client, callback.SteamIDLobby);
|
||||
Lobbies.Add(lobby);
|
||||
checkFinished();
|
||||
}
|
||||
@@ -140,8 +148,6 @@ namespace Facepunch.Steamworks
|
||||
//otherwise lobby data in general was updated and you should listen to see what changed
|
||||
if (OnLobbiesUpdated != null) { OnLobbiesUpdated(); }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Action OnLobbiesUpdated;
|
||||
|
||||
@@ -46,16 +46,36 @@ namespace Facepunch.Steamworks
|
||||
|
||||
internal static Server FromSteam( Client client, SteamNative.gameserveritem_t item )
|
||||
{
|
||||
int serverNameLength = item.ServerName.Length;
|
||||
for (int i = 0; i < item.ServerName.Length; i++)
|
||||
{
|
||||
if (item.ServerName[i] == '\0')
|
||||
{
|
||||
serverNameLength = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int mapLength = item.Map.Length;
|
||||
for (int i = 0; i < item.Map.Length; i++)
|
||||
{
|
||||
if (item.Map[i] == '\0')
|
||||
{
|
||||
mapLength = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new Server()
|
||||
{
|
||||
Client = client,
|
||||
Address = Utility.Int32ToIp( item.NetAdr.IP ),
|
||||
ConnectionPort = item.NetAdr.ConnectionPort,
|
||||
QueryPort = item.NetAdr.QueryPort,
|
||||
Name = Encoding.UTF8.GetString(item.ServerName),
|
||||
Name = Encoding.UTF8.GetString(item.ServerName, 0, serverNameLength),
|
||||
Ping = item.Ping,
|
||||
GameDir = item.GameDir,
|
||||
Map = Encoding.UTF8.GetString(item.Map),
|
||||
Map = Encoding.UTF8.GetString(item.Map, 0, mapLength),
|
||||
Description = item.GameDescription,
|
||||
AppId = item.AppID,
|
||||
Players = item.Players,
|
||||
|
||||
Reference in New Issue
Block a user