using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Facepunch.Steamworks
{
public class ServerAuth
{
internal Server server;
///
/// Steamid, Ownerid, Status
///
public Action OnAuthChange;
///
/// Steam authetication statuses
///
public enum Status : int
{
OK = 0,
UserNotConnectedToSteam = 1,
NoLicenseOrExpired = 2,
VACBanned = 3,
LoggedInElseWhere = 4,
VACCheckTimedOut = 5,
AuthTicketCanceled = 6,
AuthTicketInvalidAlreadyUsed = 7,
AuthTicketInvalid = 8,
PublisherIssuedBan = 9,
}
internal ServerAuth( Server s )
{
server = s;
server.RegisterCallback( OnAuthTicketValidate );
}
void OnAuthTicketValidate( SteamNative.ValidateAuthTicketResponse_t data )
{
if ( OnAuthChange != null )
OnAuthChange( data.SteamID, data.OwnerSteamID, (Status) data.AuthSessionResponse );
}
///
/// Start authorizing a ticket. This user isn't authorized yet. Wait for a call to OnAuthChange.
///
public unsafe bool StartSession( byte[] data, ulong steamid )
{
fixed ( byte* p = data )
{
var result = server.native.gameServer.BeginAuthSession( (IntPtr)p, data.Length, steamid );
if ( result == SteamNative.BeginAuthSessionResult.OK )
return true;
return false;
}
}
///
/// Forget this guy. They're no longer in the game.
///
public void EndSession( ulong steamid )
{
server.native.gameServer.EndAuthSession( steamid );
}
}
}