2016-09-30 17:29:22 +03:00
|
|
|
|
using System;
|
2019-04-15 23:18:03 +03:00
|
|
|
|
using System.Threading.Tasks;
|
2016-09-30 17:29:22 +03:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2019-04-15 23:18:03 +03:00
|
|
|
|
|
|
|
|
|
namespace Steamworks
|
2016-09-30 17:29:22 +03:00
|
|
|
|
{
|
2016-10-25 12:29:35 +03:00
|
|
|
|
[DeploymentItem( "steam_api64.dll" )]
|
2020-02-22 23:29:37 +03:00
|
|
|
|
[DeploymentItem( "steam_api.dll" )]
|
|
|
|
|
[TestClass]
|
2019-04-15 23:18:03 +03:00
|
|
|
|
public partial class GameServerTest
|
2016-09-30 17:29:22 +03:00
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
2019-04-16 16:21:48 +03:00
|
|
|
|
SteamServer.DedicatedServer = true;
|
|
|
|
|
SteamServer.DedicatedServer = false;
|
2019-04-15 23:18:03 +03:00
|
|
|
|
}
|
2016-11-03 17:33:03 +03:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2019-04-15 23:18:03 +03:00
|
|
|
|
public async Task PublicIp()
|
2016-11-03 17:33:03 +03:00
|
|
|
|
{
|
2019-04-15 23:18:03 +03:00
|
|
|
|
while ( true )
|
2016-11-03 17:33:03 +03:00
|
|
|
|
{
|
2019-04-16 16:21:48 +03:00
|
|
|
|
var ip = SteamServer.PublicIp;
|
2016-11-03 17:33:03 +03:00
|
|
|
|
|
2019-04-15 23:18:03 +03:00
|
|
|
|
if ( ip == null )
|
2016-11-03 17:33:03 +03:00
|
|
|
|
{
|
2019-04-15 23:18:03 +03:00
|
|
|
|
await Task.Delay( 10 );
|
|
|
|
|
continue;
|
2016-11-03 17:33:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-15 23:18:03 +03:00
|
|
|
|
Assert.IsNotNull( ip );
|
|
|
|
|
Console.WriteLine( ip.ToString() );
|
|
|
|
|
break;
|
2016-11-03 17:33:03 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-03 14:06:30 +03:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2019-04-15 23:39:13 +03:00
|
|
|
|
public async Task BeginAuthSession()
|
2016-10-03 14:06:30 +03:00
|
|
|
|
{
|
2019-04-16 13:45:44 +03:00
|
|
|
|
var stopwatch = System.Diagnostics.Stopwatch.StartNew();
|
2019-04-15 23:39:13 +03:00
|
|
|
|
bool finished = false;
|
2019-04-16 17:25:35 +03:00
|
|
|
|
string failed = null;
|
2019-04-16 14:17:24 +03:00
|
|
|
|
AuthResponse response = AuthResponse.AuthTicketInvalidAlreadyUsed;
|
2019-04-15 23:39:13 +03:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Clientside calls this function, gets ticket
|
|
|
|
|
//
|
2023-05-15 15:37:19 +03:00
|
|
|
|
var clientTicket = SteamUser.GetAuthSessionTicket( SteamClient.SteamId );
|
2019-04-15 23:39:13 +03:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// The client sends this data to the server along with their steamid
|
|
|
|
|
//
|
|
|
|
|
var ticketData = clientTicket.Data;
|
2019-04-16 16:26:42 +03:00
|
|
|
|
var clientSteamId = SteamClient.SteamId;
|
2019-04-15 23:39:13 +03:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Server listens to auth responses from Gabe
|
|
|
|
|
//
|
2019-04-16 16:21:48 +03:00
|
|
|
|
SteamServer.OnValidateAuthTicketResponse += ( steamid, ownerid, rsponse ) =>
|
2019-04-15 23:39:13 +03:00
|
|
|
|
{
|
|
|
|
|
finished = true;
|
|
|
|
|
response = rsponse;
|
|
|
|
|
|
2019-04-16 17:25:35 +03:00
|
|
|
|
if ( steamid == 0 )
|
|
|
|
|
failed = $"steamid is 0! {steamid} != {ownerid} ({rsponse})";
|
2019-04-15 23:39:13 +03:00
|
|
|
|
|
2019-04-16 17:25:35 +03:00
|
|
|
|
if ( ownerid == 0 )
|
|
|
|
|
failed = $"ownerid is 0! {steamid} != {ownerid} ({rsponse})";
|
|
|
|
|
|
|
|
|
|
if ( steamid != ownerid )
|
|
|
|
|
failed = $"Steamid and Ownerid are different! {steamid} != {ownerid} ({rsponse})";
|
2019-04-15 23:39:13 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Server gets the ticket, starts authing
|
|
|
|
|
//
|
2019-04-16 16:21:48 +03:00
|
|
|
|
if ( !SteamServer.BeginAuthSession( ticketData, clientSteamId ) )
|
2019-04-15 23:39:13 +03:00
|
|
|
|
{
|
|
|
|
|
Assert.Fail( "BeginAuthSession returned false, called bullshit without even having to check with Gabe" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Wait for that to go through steam
|
|
|
|
|
//
|
|
|
|
|
while ( !finished )
|
2019-04-16 13:45:44 +03:00
|
|
|
|
{
|
|
|
|
|
if ( stopwatch.Elapsed.TotalSeconds > 5 )
|
|
|
|
|
throw new System.Exception( "Took too long waiting for AuthSessionResponse.OK" );
|
|
|
|
|
|
2019-04-15 23:39:13 +03:00
|
|
|
|
await Task.Delay( 10 );
|
2019-04-16 13:45:44 +03:00
|
|
|
|
}
|
2019-04-15 23:39:13 +03:00
|
|
|
|
|
2019-04-16 14:17:24 +03:00
|
|
|
|
Assert.AreEqual( response, AuthResponse.OK );
|
2019-04-15 23:39:13 +03:00
|
|
|
|
|
2019-04-16 17:25:35 +03:00
|
|
|
|
if ( failed != null )
|
|
|
|
|
Assert.Fail( failed );
|
|
|
|
|
|
2019-04-15 23:39:13 +03:00
|
|
|
|
finished = false;
|
2019-04-16 13:45:44 +03:00
|
|
|
|
stopwatch = System.Diagnostics.Stopwatch.StartNew();
|
2019-04-15 23:39:13 +03:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// The client is leaving, and now wants to cancel the ticket
|
|
|
|
|
//
|
|
|
|
|
|
2019-04-16 13:45:44 +03:00
|
|
|
|
Assert.AreNotEqual( 0, clientTicket.Handle );
|
2019-04-15 23:39:13 +03:00
|
|
|
|
clientTicket.Cancel();
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// We should get another callback
|
|
|
|
|
//
|
|
|
|
|
while ( !finished )
|
2019-04-16 13:45:44 +03:00
|
|
|
|
{
|
|
|
|
|
if ( stopwatch.Elapsed.TotalSeconds > 5 )
|
|
|
|
|
throw new System.Exception( "Took too long waiting for AuthSessionResponse.AuthTicketCanceled" );
|
|
|
|
|
|
2019-04-15 23:39:13 +03:00
|
|
|
|
await Task.Delay( 10 );
|
2019-04-16 13:45:44 +03:00
|
|
|
|
}
|
2019-04-15 23:39:13 +03:00
|
|
|
|
|
2019-04-16 17:25:35 +03:00
|
|
|
|
if ( failed != null )
|
|
|
|
|
Assert.Fail( failed );
|
|
|
|
|
|
|
|
|
|
//Assert.AreEqual( response, AuthResponse.AuthTicketCanceled );
|
2016-10-03 17:25:19 +03:00
|
|
|
|
|
2019-04-15 23:39:13 +03:00
|
|
|
|
}
|
2016-09-30 17:29:22 +03:00
|
|
|
|
}
|
|
|
|
|
}
|