Facepunch.Steamworks/Facepunch.Steamworks.Test/GameServerTest.cs

121 lines
2.9 KiB
C#
Raw Normal View History

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" )]
2016-10-26 18:10:20 +03:00
[DeploymentItem( "tier0_s64.dll" )]
[DeploymentItem( "vstdlib_s64.dll" )]
[DeploymentItem( "steamclient64.dll" )]
2016-09-30 17:29:22 +03:00
[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-15 23:18:03 +03:00
GameServer.DedicatedServer = true;
GameServer.DedicatedServer = false;
}
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-15 23:18:03 +03:00
var ip = GameServer.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;
AuthSessionResponse response = AuthSessionResponse.AuthTicketInvalidAlreadyUsed;
//
// Clientside calls this function, gets ticket
//
var clientTicket = User.GetAuthSessionTicket();
//
// The client sends this data to the server along with their steamid
//
var ticketData = clientTicket.Data;
2019-04-16 11:30:17 +03:00
var clientSteamId = User.SteamId;
2019-04-15 23:39:13 +03:00
//
// Server listens to auth responses from Gabe
//
GameServer.OnValidateAuthTicketResponse += ( steamid, ownerid, rsponse ) =>
{
finished = true;
response = rsponse;
Assert.AreEqual( steamid, clientSteamId );
Assert.AreEqual( steamid, ownerid );
Console.WriteLine( "steamid: {0}", steamid );
Console.WriteLine( "ownerid: {0}", ownerid );
Console.WriteLine( "status: {0}", response );
};
//
// Server gets the ticket, starts authing
//
if ( !GameServer.BeginAuthSession( ticketData, clientSteamId ) )
{
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
Assert.AreEqual( response, AuthSessionResponse.OK );
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
Assert.AreEqual( response, AuthSessionResponse.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
}
}