mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-12 06:38:01 +03:00
Added Server.PublicIp
This commit is contained in:
parent
84e38601d6
commit
8bf391a300
@ -24,6 +24,34 @@ namespace Facepunch.Steamworks.Test
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PublicIp()
|
||||
{
|
||||
using ( var server = new Facepunch.Steamworks.Server( 252490, 30002, 30003, false, "VersionString" ) )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AuthCallback()
|
||||
{
|
||||
|
@ -180,6 +180,7 @@
|
||||
<Compile Include="SteamNative\SteamNative.Callback.cs" />
|
||||
<Compile Include="SteamNative\SteamNative.Structs.cs" />
|
||||
<Compile Include="SteamNative\SteamNative.Types.cs" />
|
||||
<Compile Include="Utility.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
@ -250,6 +250,9 @@ namespace Facepunch.Steamworks
|
||||
get { return native.gameServer.BLoggedOn(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shutdown interface, disconnect from Steam
|
||||
/// </summary>
|
||||
public override void Dispose()
|
||||
{
|
||||
if ( Query != null )
|
||||
@ -269,5 +272,23 @@ namespace Facepunch.Steamworks
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To the best of its ability this tries to get the server's
|
||||
/// current public ip address. Be aware that this is likely to return
|
||||
/// null for the first few seconds after initialization.
|
||||
/// </summary>
|
||||
public System.Net.IPAddress PublicIp
|
||||
{
|
||||
get
|
||||
{
|
||||
var ip = native.gameServer.GetPublicIP();
|
||||
if ( ip == 0 ) return null;
|
||||
|
||||
return new System.Net.IPAddress( Utility.SwapBytes( ip ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
18
Facepunch.Steamworks/Utility.cs
Normal file
18
Facepunch.Steamworks/Utility.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Facepunch.Steamworks
|
||||
{
|
||||
internal static class Utility
|
||||
{
|
||||
static internal uint SwapBytes( uint x )
|
||||
{
|
||||
return ( ( x & 0x000000ff ) << 24 ) +
|
||||
( ( x & 0x0000ff00 ) << 8 ) +
|
||||
( ( x & 0x00ff0000 ) >> 8 ) +
|
||||
( ( x & 0xff000000 ) >> 24 );
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user