Facepunch.Steamworks/Facepunch.Steamworks.Test/Server/Server.cs

156 lines
4.8 KiB
C#
Raw Normal View History

2016-09-30 17:29:22 +03:00
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Facepunch.Steamworks.Test
{
2016-10-25 12:29:35 +03:00
[DeploymentItem( "steam_api.dll" )]
[DeploymentItem( "steam_api64.dll" )]
2016-09-30 17:29:22 +03:00
[DeploymentItem( "steam_appid.txt" )]
[DeploymentItem( "tier0_s.dll" )]
[DeploymentItem( "vstdlib_s.dll" )]
[DeploymentItem( "steamclient.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]
2016-10-04 01:09:11 +03:00
public partial class Server
2016-09-30 17:29:22 +03:00
{
[TestMethod]
public void Init()
{
var serverInit = new ServerInit( "rust", "Rust" );
serverInit.GamePort = 28015;
serverInit.Secure = true;
serverInit.QueryPort = 28016;
using ( var server = new Facepunch.Steamworks.Server( 252490, serverInit ) )
2016-09-30 17:29:22 +03:00
{
server.ServerName = "My Test Server";
server.LogOnAnonymous();
2016-10-05 14:44:01 +03:00
Assert.IsTrue( server.IsValid );
2016-09-30 17:29:22 +03:00
}
}
2016-11-03 17:33:03 +03:00
[TestMethod]
public void PublicIp()
{
using ( var server = new Facepunch.Steamworks.Server( 252490, new ServerInit( "rust", "Rust" ) ) )
2016-11-03 17:33:03 +03:00
{
server.LogOnAnonymous();
Assert.IsTrue( server.IsValid );
while ( true )
{
var ip = server.PublicIp;
if ( ip == null )
{
System.Threading.Thread.Sleep( 100 );
server.Update();
continue;
}
Assert.IsNotNull( ip );
Console.WriteLine( ip.ToString() );
break;
}
}
}
2016-10-03 14:06:30 +03:00
[TestMethod]
public void AuthCallback()
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{
2016-10-05 14:44:01 +03:00
Assert.IsTrue( client.IsValid );
2016-10-03 18:56:31 +03:00
var ticket = client.Auth.GetAuthSessionTicket();
var ticketBinary = ticket.Data;
using ( var server = new Facepunch.Steamworks.Server( 252490, new ServerInit( "rust", "Rust" ) ) )
2016-10-03 17:25:19 +03:00
{
2016-10-03 18:56:31 +03:00
server.LogOnAnonymous();
2016-10-05 14:44:01 +03:00
Assert.IsTrue( server.IsValid );
2016-10-03 14:06:30 +03:00
2016-10-03 17:25:19 +03:00
var auth = server.Auth;
var Authed = false;
server.Auth.OnAuthChange = ( steamid, ownerid, status ) =>
{
Authed = status == ServerAuth.Status.OK;
Assert.AreEqual( steamid, client.SteamId );
Assert.AreEqual( steamid, ownerid );
2016-10-03 17:25:19 +03:00
Console.WriteLine( "steamid: {0}", steamid );
Console.WriteLine( "ownerid: {0}", ownerid );
Console.WriteLine( "status: {0}", status );
};
2016-10-03 14:06:30 +03:00
for ( int i = 0; i < 16; i++ )
{
System.Threading.Thread.Sleep( 10 );
2016-10-03 17:25:19 +03:00
GC.Collect();
2016-10-03 14:06:30 +03:00
server.Update();
2016-10-03 17:25:19 +03:00
GC.Collect();
2016-10-03 14:06:30 +03:00
client.Update();
2016-10-03 17:25:19 +03:00
GC.Collect();
2016-10-03 14:06:30 +03:00
}
2016-10-03 17:25:19 +03:00
GC.Collect();
2016-10-03 14:06:30 +03:00
if ( !server.Auth.StartSession( ticketBinary, client.SteamId ) )
{
Assert.Fail( "Start Session returned false" );
}
2016-10-03 17:25:19 +03:00
GC.Collect();
//
// Server should receive a ServerAuth.Status.OK
// message via the OnAuthChange callback
//
2016-10-03 14:06:30 +03:00
2016-10-03 17:25:19 +03:00
for ( int i = 0; i< 100; i++ )
2016-10-03 14:06:30 +03:00
{
2016-10-03 17:25:19 +03:00
GC.Collect();
System.Threading.Thread.Sleep( 100 );
GC.Collect();
2016-10-03 14:06:30 +03:00
server.Update();
client.Update();
2016-10-03 17:25:19 +03:00
if ( Authed )
break;
2016-10-03 14:06:30 +03:00
}
2016-10-03 17:25:19 +03:00
Assert.IsTrue( Authed );
2016-10-03 14:06:30 +03:00
//
// Client cancels ticket
//
ticket.Cancel();
2016-10-03 17:25:19 +03:00
//
// Server should receive a ticket cancelled message
//
for ( int i = 0; i < 100; i++ )
{
System.Threading.Thread.Sleep( 100 );
server.Update();
client.Update();
if ( !Authed )
break;
}
Assert.IsTrue( !Authed );
2016-10-03 14:06:30 +03:00
}
}
}
2016-09-30 17:29:22 +03:00
}
}