mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Use IPAddress
This commit is contained in:
parent
c6bd69092a
commit
cc4bdcea8d
@ -47,7 +47,7 @@ public void InternetList()
|
|||||||
|
|
||||||
foreach ( var server in query.Responded.Take( 20 ) )
|
foreach ( var server in query.Responded.Take( 20 ) )
|
||||||
{
|
{
|
||||||
Console.WriteLine( "{0} {1}", server.AddressString, server.Name );
|
Console.WriteLine( "{0} {1}", server.Address, server.Name );
|
||||||
}
|
}
|
||||||
|
|
||||||
query.Dispose();
|
query.Dispose();
|
||||||
@ -370,7 +370,9 @@ public void CustomList()
|
|||||||
|
|
||||||
foreach ( var s in query.Responded )
|
foreach ( var s in query.Responded )
|
||||||
{
|
{
|
||||||
Console.WriteLine( "{0} - {1}", s.AddressString, s.Name );
|
Console.WriteLine( "{0} - {1}", s.Address, s.Name );
|
||||||
|
|
||||||
|
Assert.IsTrue( servers.Contains( $"{s.Address}:{s.QueryPort}" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
query.Dispose();
|
query.Dispose();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ public class Server
|
|||||||
public int Version { get; set; }
|
public int Version { get; set; }
|
||||||
public string[] Tags { get; set; }
|
public string[] Tags { get; set; }
|
||||||
public ulong SteamId { get; set; }
|
public ulong SteamId { get; set; }
|
||||||
public uint Address { get; set; }
|
public IPAddress Address { get; set; }
|
||||||
public int ConnectionPort { get; set; }
|
public int ConnectionPort { get; set; }
|
||||||
public int QueryPort { get; set; }
|
public int QueryPort { get; set; }
|
||||||
|
|
||||||
@ -42,27 +43,13 @@ public bool Favourite
|
|||||||
|
|
||||||
internal Client Client;
|
internal Client Client;
|
||||||
|
|
||||||
public string AddressString
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return string.Format( "{0}.{1}.{2}.{3}", ( Address >> 24 ) & 0xFFul, ( Address >> 16 ) & 0xFFul, ( Address >> 8 ) & 0xFFul, Address & 0xFFul );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public string ConnectionAddress
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return string.Format( "{0}.{1}.{2}.{3}:{4}", ( Address >> 24 ) & 0xFFul, ( Address >> 16 ) & 0xFFul, ( Address >> 8 ) & 0xFFul, Address & 0xFFul, ConnectionPort );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static Server FromSteam( Client client, SteamNative.gameserveritem_t item )
|
internal static Server FromSteam( Client client, SteamNative.gameserveritem_t item )
|
||||||
{
|
{
|
||||||
return new Server()
|
return new Server()
|
||||||
{
|
{
|
||||||
Client = client,
|
Client = client,
|
||||||
Address = item.NetAdr.IP,
|
Address = Utility.Int32ToIp( item.NetAdr.IP ),
|
||||||
ConnectionPort = item.NetAdr.ConnectionPort,
|
ConnectionPort = item.NetAdr.ConnectionPort,
|
||||||
QueryPort = item.NetAdr.QueryPort,
|
QueryPort = item.NetAdr.QueryPort,
|
||||||
Name = item.ServerName,
|
Name = item.ServerName,
|
||||||
@ -133,7 +120,7 @@ internal void OnServerRulesReceiveFinished( bool Success )
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void AddToHistory()
|
public void AddToHistory()
|
||||||
{
|
{
|
||||||
Client.native.matchmaking.AddFavoriteGame( AppId, Address, (ushort)ConnectionPort, (ushort)QueryPort, k_unFavoriteFlagHistory, (uint)Utility.Epoch.Current );
|
Client.native.matchmaking.AddFavoriteGame( AppId, Utility.IpToInt32( Address ), (ushort)ConnectionPort, (ushort)QueryPort, k_unFavoriteFlagHistory, (uint)Utility.Epoch.Current );
|
||||||
Client.ServerList.UpdateFavouriteList();
|
Client.ServerList.UpdateFavouriteList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +129,7 @@ public void AddToHistory()
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void RemoveFromHistory()
|
public void RemoveFromHistory()
|
||||||
{
|
{
|
||||||
Client.native.matchmaking.RemoveFavoriteGame( AppId, Address, (ushort)ConnectionPort, (ushort)QueryPort, k_unFavoriteFlagHistory );
|
Client.native.matchmaking.RemoveFavoriteGame( AppId, Utility.IpToInt32( Address ), (ushort)ConnectionPort, (ushort)QueryPort, k_unFavoriteFlagHistory );
|
||||||
Client.ServerList.UpdateFavouriteList();
|
Client.ServerList.UpdateFavouriteList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +138,7 @@ public void RemoveFromHistory()
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void AddToFavourites()
|
public void AddToFavourites()
|
||||||
{
|
{
|
||||||
Client.native.matchmaking.AddFavoriteGame( AppId, Address, (ushort)ConnectionPort, (ushort)QueryPort, k_unFavoriteFlagFavorite, (uint)Utility.Epoch.Current );
|
Client.native.matchmaking.AddFavoriteGame( AppId, Utility.IpToInt32( Address ), (ushort)ConnectionPort, (ushort)QueryPort, k_unFavoriteFlagFavorite, (uint)Utility.Epoch.Current );
|
||||||
Client.ServerList.UpdateFavouriteList();
|
Client.ServerList.UpdateFavouriteList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +147,7 @@ public void AddToFavourites()
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void RemoveFromFavourites()
|
public void RemoveFromFavourites()
|
||||||
{
|
{
|
||||||
Client.native.matchmaking.RemoveFavoriteGame( AppId, Address, (ushort)ConnectionPort, (ushort)QueryPort, k_unFavoriteFlagFavorite );
|
Client.native.matchmaking.RemoveFavoriteGame( AppId, Utility.IpToInt32( Address ), (ushort)ConnectionPort, (ushort)QueryPort, k_unFavoriteFlagFavorite );
|
||||||
Client.ServerList.UpdateFavouriteList();
|
Client.ServerList.UpdateFavouriteList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ public Request Local( Filter filter = null )
|
|||||||
|
|
||||||
internal bool IsFavourite( Server server )
|
internal bool IsFavourite( Server server )
|
||||||
{
|
{
|
||||||
ulong encoded = server.Address;
|
ulong encoded = Utility.IpToInt32( server.Address );
|
||||||
encoded = encoded << 32;
|
encoded = encoded << 32;
|
||||||
encoded = encoded | (uint)server.ConnectionPort;
|
encoded = encoded | (uint)server.ConnectionPort;
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ internal bool IsFavourite( Server server )
|
|||||||
|
|
||||||
internal bool IsHistory( Server server )
|
internal bool IsHistory( Server server )
|
||||||
{
|
{
|
||||||
ulong encoded = server.Address;
|
ulong encoded = Utility.IpToInt32( server.Address );
|
||||||
encoded = encoded << 32;
|
encoded = encoded << 32;
|
||||||
encoded = encoded | (uint)server.ConnectionPort;
|
encoded = encoded | (uint)server.ConnectionPort;
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ class ServerRules : IDisposable
|
|||||||
// The server that called us
|
// The server that called us
|
||||||
private ServerList.Server Server;
|
private ServerList.Server Server;
|
||||||
|
|
||||||
public ServerRules( ServerList.Server server, uint address, int queryPort )
|
public ServerRules( ServerList.Server server, IPAddress address, int queryPort )
|
||||||
{
|
{
|
||||||
Server = server;
|
Server = server;
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ public ServerRules( ServerList.Server server, uint address, int queryPort )
|
|||||||
//
|
//
|
||||||
// Ask Steam to get the server rules, respond to our fake vtable
|
// Ask Steam to get the server rules, respond to our fake vtable
|
||||||
//
|
//
|
||||||
Server.Client.native.servers.ServerRules( address, (ushort)queryPort, GetPtr() );
|
Server.Client.native.servers.ServerRules( Utility.IpToInt32( address ), (ushort)queryPort, GetPtr() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Facepunch.Steamworks
|
namespace Facepunch.Steamworks
|
||||||
@ -15,6 +16,17 @@ static internal uint SwapBytes( uint x )
|
|||||||
( ( x & 0xff000000 ) >> 24 );
|
( ( x & 0xff000000 ) >> 24 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static internal uint IpToInt32( this IPAddress ipAddress )
|
||||||
|
{
|
||||||
|
return BitConverter.ToUInt32( ipAddress.GetAddressBytes().Reverse().ToArray(), 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
static internal IPAddress Int32ToIp( uint ipAddress )
|
||||||
|
{
|
||||||
|
return new IPAddress( BitConverter.GetBytes( ipAddress ).Reverse().ToArray() );
|
||||||
|
}
|
||||||
|
|
||||||
static internal class Epoch
|
static internal class Epoch
|
||||||
{
|
{
|
||||||
private static readonly DateTime epoch = new DateTime( 1970, 1, 1, 0, 0, 0, DateTimeKind.Utc );
|
private static readonly DateTime epoch = new DateTime( 1970, 1, 1, 0, 0, 0, DateTimeKind.Utc );
|
||||||
|
Loading…
Reference in New Issue
Block a user